diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8353c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +env/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Adapter files +adapter/__pycache__/ +adapter/log.txt +adapter/finished.txt + +sublime_debugger.json \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..89de354 --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1673d19 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# A Debug Adapter for Debugging Python 2 within Autodesk 3DS Max + +This adapter serves as a "middleman" between the Sublime Debugger plugin +and a DAP implementation for python (ptvsd) injected into 3DS Max. + +It intercepts a few DAP requests to establish a connection between the debugger and 3DS Max, and +otherwise forwards all communications between the debugger and ptvsd normally. diff --git a/adapter/__main__.py b/adapter/__main__.py new file mode 100644 index 0000000..2e1e2b6 --- /dev/null +++ b/adapter/__main__.py @@ -0,0 +1,416 @@ + +""" + +This script creates a connection between the Debugger and 3DS Max for debugging Python 2. + +It is inspired by various packages, namely: + - https://github.com/daveleroy/sublime_debugger + - https://github.com/cb109/sublime3dsmax + +""" + +from tempfile import gettempdir +from interface import debugger_queue, start_response_thread, read_debugger_input +from queue import Queue +from util import * +import winapi +import socket +import json +import time +import sys +import os + + +# The 3DS Max window handle +window = None + +signal_location = join(dirname(abspath(__file__)), 'finished.txt') +last_seq = -1 + +processed_seqs = [] +run_code = "" + +ptvsd_send_queue = Queue() +ptvsd_socket: socket.socket + + +# Avoiding stalls +inv_seq = 9223372036854775806 # The maximum int value in Python 2, -1 (hopefully never gets reached) +artificial_seqs = [] # keeps track of which seqs we have sent +waiting_for_pause_event = False + +avoiding_continue_stall = False +stashed_event = None + +disconnecting = False + + +def main(): + """ + Finds the 3ds Max window, starts the thread to send information to debugger, + then remains in a loop reading messages from debugger. + """ + + find_max_window() + + if os.path.exists(signal_location): + os.remove(signal_location) + + start_response_thread() + + read_debugger_input(on_receive_from_debugger) + + +def on_receive_from_debugger(message): + """ + Intercept the initialize and attach requests from the debugger + while ptvsd is being set up + """ + + global last_seq, avoiding_continue_stall + + contents = json.loads(message) + last_seq = contents.get('seq') + + log('Received from Debugger:', message) + + cmd = contents['command'] + + if cmd == 'initialize': + # Run init request once max connection is established and send success response to the debugger + debugger_queue.put(json.dumps(json.loads(INITIALIZE_RESPONSE))) # load and dump to remove indents + processed_seqs.append(contents['seq']) + pass + + elif cmd == 'attach': + # time to attach to max + run(attach_to_max, (contents,)) + + # Change arguments to valid ones for ptvsd + config = contents['arguments'] + new_args = ATTACH_ARGS.format( + dir=dirname(config['program']).replace('\\', '\\\\'), + hostname=config['ptvsd']['host'], + port=int(config['ptvsd']['port']), + filepath=config['program'].replace('\\', '\\\\') + ) + + contents = contents.copy() + contents['arguments'] = json.loads(new_args) + message = json.dumps(contents) # update contents to reflect new args + + log("New attach arguments loaded:", new_args) + + elif cmd == 'continue': + avoiding_continue_stall = True + + # Then just put the message in the ptvsd queue + ptvsd_send_queue.put(message) + + +def find_max_window(): + """ + Finds the open 3DS Max window and keeps a handle to it. + + This function is strongly inspired by the contents of + https://github.com/cb109/sublime3dsmax/blob/master/sublime3dsmax.py + """ + + global window + + if window is None: + window = winapi.Window.find_window(TITLE_IDENTIFIER) + + if window is None: + raise Exception(""" + + + An Autodesk 3ds Max instance could not be found. + Please make sure it is open and running, then try again. + + """) + + try: + window.find_child(text=None, cls="MXS_Scintilla") + except OSError: + # Window handle is invalid, 3ds Max has probably been closed. + # Call this function again and try to find one automatically. + window = None + find_max_window() + + +def send_py_code_to_max(code): + """ + Sends a command to 3ds Max to run + + This function is strongly inspired by the contents of + https://github.com/cb109/sublime3dsmax/blob/master/sublime3dsmax.py + """ + + try: + # Make temporary file and set its contents to the code snippet + filepath = join(gettempdir(), 'temp.py') + with open(filepath, "w") as f: + f.write(code) + + # The command to run a python file within Max + cmd = f'python.ExecuteFile @"{filepath}";' + log("Sending " + cmd + " to 3ds Max") + + minimacrorecorder = window.find_child(text=None, cls="MXS_Scintilla") + + # If the mini macrorecorder was not found, there is still a chance + # we are targetting an ancient Max version (e.g. 9) where the + # listener was not Scintilla based, but instead a rich edit box. + if minimacrorecorder is None: + + statuspanel = window.find_child(text=None, cls="StatusPanel") + if statuspanel is None: + raise Exception(RECORDER_NOT_FOUND) + + minimacrorecorder = statuspanel.find_child(text=None, cls="RICHEDIT") + + # Verbatim strings (the @ at sign) are not supported in older Max versions. + cmd = cmd.replace("@", "") + cmd = cmd.replace("\\", "\\\\") + + if minimacrorecorder is None: + raise Exception(RECORDER_NOT_FOUND) + + cmd = cmd.encode("utf-8") # Needed for ST3! + minimacrorecorder.send(winapi.WM_SETTEXT, 0, cmd) + minimacrorecorder.send(winapi.WM_CHAR, winapi.VK_RETURN, 0) + minimacrorecorder = None + + except Exception as e: + + raise Exception("Could not send vital code to Max due to error:\n\n" + str(e)) + + +def attach_to_max(contents: dict): + """ + Defines commands to send to Max, establishes a connection to its commandPort, + then sends the code to inject ptvsd + """ + + global run_code + config = contents['arguments'] + + attach_code = ATTACH_TEMPLATE.format( + ptvsd_path=ptvsd_path, + hostname=config['ptvsd']['host'], + port=int(config['ptvsd']['port']) + ) + + run_code = RUN_TEMPLATE.format( + dir=dirname(config['program']), + file_name=split(config['program'])[1][:-3] or basename(split(config['program'])[0])[:-3], + signal_location=signal_location.replace('\\', '\\\\') + ) + + # then send attach code + log('Sending attach code to Max') + send_py_code_to_max(attach_code) + + log('Successfully attached to Max') + + # Then start the max debugging threads + run(start_debugging, ((config['ptvsd']['host'], int(config['ptvsd']['port'])),)) + + # And finally wait for the signal from ptvsd that debugging is done + run(wait_for_signal) + + +def wait_for_signal(): + """ + Waits for the signal location to exist, which means debugging is done. + Deletes the signal location and prepares this adapter for disconnect. + """ + + global disconnecting + + while True: + + if os.path.exists(signal_location): + log('--- FINISHED DEBUGGING ---') + + os.remove(signal_location) + run(disconnect) + + +def start_debugging(address): + """ + Connects to ptvsd in Max, then starts the threads needed to + send and receive information from it + """ + + log("Connecting to " + address[0] + ":" + str(address[1])) + + global ptvsd_socket + ptvsd_socket = socket.create_connection(address) + + log("Successfully connected to Max for debugging. Starting...") + + run(ptvsd_send_loop) # Start sending requests to ptvsd + + fstream = ptvsd_socket.makefile() + + while True: + try: + content_length = 0 + while True: + header = fstream.readline() + if header: + header = header.strip() + if not header: + break + if header.startswith(CONTENT_HEADER): + content_length = int(header[len(CONTENT_HEADER):]) + + if content_length > 0: + total_content = "" + while content_length > 0: + content = fstream.read(content_length) + content_length -= len(content) + total_content += content + + if content_length == 0: + message = total_content + on_receive_from_ptvsd(message) + + except Exception as e: + log("Failure reading Max's ptvsd output: \n" + str(e)) + ptvsd_socket.close() + break + + +def ptvsd_send_loop(): + """ + The loop that waits for items to show in the send queue and prints them. + Blocks until an item is present + """ + + while True: + msg = ptvsd_send_queue.get() + if msg is None: + return + else: + try: + ptvsd_socket.send(bytes('Content-Length: {}\r\n\r\n'.format(len(msg)), 'UTF-8')) + ptvsd_socket.send(bytes(msg, 'UTF-8')) + log('Sent to ptvsd:', msg) + except OSError: + log("Debug socket closed.") + return + + +def on_receive_from_ptvsd(message): + """ + Handles messages going from ptvsd to the debugger + """ + + global inv_seq, artificial_seqs, waiting_for_pause_event, avoiding_continue_stall, stashed_event + + c = json.loads(message) + seq = int(c.get('request_seq', -1)) # a negative seq will never occur + cmd = c.get('command', '') + + if cmd == 'configurationDone': + # When Debugger & ptvsd are done setting up, send the code to debug + send_py_code_to_max(run_code) + + elif cmd == "variables": + # Hide the __builtins__ variable (causes errors in the debugger gui) + vars = c['body'].get('variables') + if vars: + toremove = [] + for var in vars: + if var['name'] in ('__builtins__', '__doc__', '__file__', '__name__', '__package__'): + toremove.append(var) + for var in toremove: + vars.remove(var) + message = json.dumps(c) + + elif c.get('event', '') == 'stopped' and c['body'].get('reason', '') == 'step': + # Sometimes (often) ptvsd stops on steps, for an unknown reason. + # Respond to this with a forced pause to put things back on track. + log("Stall detected. Sending unblocking command to ptvsd.") + req = PAUSE_REQUEST.format(seq=inv_seq) + ptvsd_send_queue.put(req) + artificial_seqs.append(inv_seq) + inv_seq -= 1 + + # We don't want the debugger to know ptvsd stalled, so pretend it didn't. + return + + elif seq in artificial_seqs: + # Check for success, then do nothing and wait for pause event to show up + if c.get('success', False): + waiting_for_pause_event = True + else: + log("Stall could not be recovered.") + return + + elif waiting_for_pause_event and c.get('event', '') == 'stopped' and c['body'].get('reason', '') == 'pause': + # Set waiting for pause event to false and change the reason for the stop to be a step. + # Debugging can operate normally again + waiting_for_pause_event = False + c['body']['reason'] = 'step' + message = json.dumps(c) + + elif avoiding_continue_stall and c.get('event', '') == 'stopped' and c['body'].get('reason', '') == 'breakpoint': + # temporarily hold this message to send only after the continued event is received + log("Temporarily stashed: ", message) + stashed_event = message + return + + elif avoiding_continue_stall and c.get('event', '') == 'continued': + avoiding_continue_stall = False + + if stashed_event: + log('Received from ptvsd:', message) + debugger_queue.put(message) + + log('Sending stashed message:', stashed_event) + debugger_queue.put(stashed_event) + + stashed_event = None + return + + # Send responses and events to debugger + if seq in processed_seqs: + # Should only be the initialization request + log("Already processed, ptvsd response is:", message) + else: + log('Received from ptvsd:', message) + debugger_queue.put(message) + + +def disconnect(): + """ + Clean things up by unblocking (and killing) all threads, then exit + """ + + # Unblock and kill the send threads + debugger_queue.put(None) + while debugger_queue.qsize() != 0: + time.sleep(0.1) + + ptvsd_send_queue.put(None) + while ptvsd_send_queue.qsize() != 0: + time.sleep(0.1) + + # Close ptvsd socket and stdin so readline() functions unblock + ptvsd_socket.close() + sys.stdin.close() + + # exit all threads + os._exit(0) + + +if __name__ == '__main__': + try: + main() + except Exception as e: + log(str(e)) + raise e diff --git a/adapter/interface.py b/adapter/interface.py new file mode 100644 index 0000000..e2349c6 --- /dev/null +++ b/adapter/interface.py @@ -0,0 +1,71 @@ + +from sys import stdin, stdout +from queue import Queue +from util import CONTENT_HEADER, run_in_new_thread, log + + +debugger_queue = Queue() + + +def read_debugger_input(callback: function): + """ + Reads DAP messages sent from the debugger through stdin and calls the + function passed in as the callback with the message recieved. + """ + + while True: + try: + content_length = 0 + while True: + header = stdin.readline() + if header: + header = header.strip() + if not header: + break + if header.startswith(CONTENT_HEADER): + content_length = int(header[len(CONTENT_HEADER):]) + + if content_length > 0: + total_content = "" + while content_length > 0: + content = stdin.read(content_length) + content_length -= len(content) + total_content += content + + if content_length == 0: + message = total_content + callback(message) + + except Exception as e: + log("Failure reading stdin: " + str(e)) + return + + +def _debugger_send_loop(): + """ + Waits for items to show in the send queue and prints them. + Blocks until an item is present + """ + + while True: + msg: str = debugger_queue.get() + if msg is None: + return + else: + try: + stdout.write('Content-Length: {}\r\n\r\n'.format(len(msg))) + stdout.write(msg) + stdout.flush() + log('Sent to Debugger:', msg) + except Exception as e: + log("Failure writing to stdout (normal on exit):" + str(e)) + return + + +def start_response_thread(): + """ + Simple wrapper to start the debugger send loop below in a new thread + """ + + run_in_new_thread(_debugger_send_loop) + diff --git a/adapter/python/ptvsd/ThirdPartyNotices.txt b/adapter/python/ptvsd/ThirdPartyNotices.txt new file mode 100644 index 0000000..018bdb9 --- /dev/null +++ b/adapter/python/ptvsd/ThirdPartyNotices.txt @@ -0,0 +1,480 @@ + +THIRD-PARTY SOFTWARE NOTICES AND INFORMATION +Do Not Translate or Localize + +Ptvsd incorporates third party material from the projects listed below. + + +1. PyDev.Debugger (https://github.com/fabioz/PyDev.Debugger) + Includes:File copyright Brainwy Software Ltda. + Includes:File(s) related to Python, Cpython + Includes:File authored by Yuli Fitterman + Includes:File copyright Brainwy software Ltda + Includes:File with methods from Spyder + Includes:File(s) related to IPython + Includes:Files copyright Microsoft Corporation + Includes:six + Includes:WinAppDbg + Includes:XML-RPC client interface for Python + + +%% PyDev.Debugger NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +The source code for the PyDev.Debugger files are provided with ptvsd, or you may send a check or money order for US $5.00, including the product name (ptvsd), the open source component name (PyDev.Debugger) and version number, to: Source Code Compliance Team, Microsoft Corporation, One Microsoft Way, Redmond, WA 98052, USA. + +Eclipse Public License, Version 1.0 (EPL-1.0) +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. +1. DEFINITIONS +"Contribution" means: +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. +"Program" means the Contributions distributed in accordance with this Agreement. +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. +2. GRANT OF RIGHTS +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. +4. COMMERCIAL DISTRIBUTION +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. +5. NO WARRANTY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. +6. DISCLAIMER OF LIABILITY +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +7. GENERAL +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. +========================================= +Includes File copyright Brainwy Software Ltda. + +File includes the following notice: + +Copyright: Brainwy Software Ltda. + +License: EPL. + +========================================= +Includes file(s) from Python, Python xreload, Cpython and an ActiveState.com Recipe on "NULL OBJECT DESIGN PATTERN (PYTHON RECIPE)" + +PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +-------------------------------------------- + +1. This LICENSE AGREEMENT is between the Python Software Foundation +("PSF"), and the Individual or Organization ("Licensee") accessing and +otherwise using this software ("Python") in source or binary form and +its associated documentation. + +2. Subject to the terms and conditions of this License Agreement, PSF hereby +grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, +analyze, test, perform and/or display publicly, prepare derivative works, +distribute, and otherwise use Python alone or in any derivative version, +provided, however, that PSF's License Agreement and PSF's notice of copyright, +i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, +2011, 2012, 2013, 2014, 2015, 2016, 2017 Python Software Foundation; All Rights +Reserved" are retained in Python alone or in any derivative version prepared by +Licensee. + +3. In the event Licensee prepares a derivative work that is based on +or incorporates Python or any part thereof, and wants to make +the derivative work available to others as provided herein, then +Licensee hereby agrees to include in any such work a brief summary of +the changes made to Python. + +4. PSF is making Python available to Licensee on an "AS IS" +basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +6. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +7. Nothing in this License Agreement shall be deemed to create any +relationship of agency, partnership, or joint venture between PSF and +Licensee. This License Agreement does not grant permission to use PSF +trademarks or trade name in a trademark sense to endorse or promote +products or services of Licensee, or any third party. + +8. By copying, installing or otherwise using Python, Licensee +agrees to be bound by the terms and conditions of this License +Agreement. + + +BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0 +------------------------------------------- + +BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1 + +1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an +office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the +Individual or Organization ("Licensee") accessing and otherwise using +this software in source or binary form and its associated +documentation ("the Software"). + +2. Subject to the terms and conditions of this BeOpen Python License +Agreement, BeOpen hereby grants Licensee a non-exclusive, +royalty-free, world-wide license to reproduce, analyze, test, perform +and/or display publicly, prepare derivative works, distribute, and +otherwise use the Software alone or in any derivative version, +provided, however, that the BeOpen Python License is retained in the +Software, alone or in any derivative version prepared by Licensee. + +3. BeOpen is making the Software available to Licensee on an "AS IS" +basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE +SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS +AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY +DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +5. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +6. This License Agreement shall be governed by and interpreted in all +respects by the law of the State of California, excluding conflict of +law provisions. Nothing in this License Agreement shall be deemed to +create any relationship of agency, partnership, or joint venture +between BeOpen and Licensee. This License Agreement does not grant +permission to use BeOpen trademarks or trade names in a trademark +sense to endorse or promote products or services of Licensee, or any +third party. As an exception, the "BeOpen Python" logos available at +http://www.pythonlabs.com/logos.html may be used according to the +permissions granted on that web page. + +7. By copying, installing or otherwise using the software, Licensee +agrees to be bound by the terms and conditions of this License +Agreement. + + +CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1 +--------------------------------------- + +1. This LICENSE AGREEMENT is between the Corporation for National +Research Initiatives, having an office at 1895 Preston White Drive, +Reston, VA 20191 ("CNRI"), and the Individual or Organization +("Licensee") accessing and otherwise using Python 1.6.1 software in +source or binary form and its associated documentation. + +2. Subject to the terms and conditions of this License Agreement, CNRI +hereby grants Licensee a nonexclusive, royalty-free, world-wide +license to reproduce, analyze, test, perform and/or display publicly, +prepare derivative works, distribute, and otherwise use Python 1.6.1 +alone or in any derivative version, provided, however, that CNRI's +License Agreement and CNRI's notice of copyright, i.e., "Copyright (c) +1995-2001 Corporation for National Research Initiatives; All Rights +Reserved" are retained in Python 1.6.1 alone or in any derivative +version prepared by Licensee. Alternately, in lieu of CNRI's License +Agreement, Licensee may substitute the following text (omitting the +quotes): "Python 1.6.1 is made available subject to the terms and +conditions in CNRI's License Agreement. This Agreement together with +Python 1.6.1 may be located on the Internet using the following +unique, persistent identifier (known as a handle): 1895.22/1013. This +Agreement may also be obtained from a proxy server on the Internet +using the following URL: http://hdl.handle.net/1895.22/1013". + +3. In the event Licensee prepares a derivative work that is based on +or incorporates Python 1.6.1 or any part thereof, and wants to make +the derivative work available to others as provided herein, then +Licensee hereby agrees to include in any such work a brief summary of +the changes made to Python 1.6.1. + +4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" +basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +6. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +7. This License Agreement shall be governed by the federal +intellectual property law of the United States, including without +limitation the federal copyright law, and, to the extent such +U.S. federal law does not apply, by the law of the Commonwealth of +Virginia, excluding Virginia's conflict of law provisions. +Notwithstanding the foregoing, with regard to derivative works based +on Python 1.6.1 that incorporate non-separable material that was +previously distributed under the GNU General Public License (GPL), the +law of the Commonwealth of Virginia shall govern this License +Agreement only as to issues arising under or with respect to +Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this +License Agreement shall be deemed to create any relationship of +agency, partnership, or joint venture between CNRI and Licensee. This +License Agreement does not grant permission to use CNRI trademarks or +trade name in a trademark sense to endorse or promote products or +services of Licensee, or any third party. + +8. By clicking on the "ACCEPT" button where indicated, or by copying, +installing or otherwise using Python 1.6.1, Licensee agrees to be +bound by the terms and conditions of this License Agreement. + + ACCEPT + + +CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2 +-------------------------------------------------- + +Copyright (C) 2006-2010 Python Software Foundation + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Stichting Mathematisch +Centrum or CWI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +========================================= +Includes File authored by Yuli Fitterman + +Copyright (c) Yuli Fitterman + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +========================================= +Includes file(s): * Copyright (c) Brainwy software Ltda. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. +========================================= +Includes file(s): Copyright (c) 2009-2012 Pierre Raybaut + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +========================================= +Includes file(s) from Ipython + +Copyright (c) 2008-2010, IPython Development Team +Copyright (c) 2001-2007, Fernando Perez. +Copyright (c) 2001, Janko Hauser +Copyright (c) 2001, Nathaniel Gray + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +Neither the name of the IPython Development Team nor the names of its +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +========================================= +Includes file(s): * Copyright (c) Microsoft Corporation. +* +* This source code is subject to terms and conditions of the Apache License, Version 2.0. A +* copy of the license can be found in the License.html file at the root of this distribution. If +* you cannot locate the Apache License, Version 2.0, please send an email to +* vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound +* by the terms of the Apache License, Version 2.0. +* +* You must not remove this notice, or any other, from this software. +========================================= +Includes file(s) from https://pythonhosted.org/six/ + +Copyright (c) 2010-2018 Benjamin Peterson + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +Includes WinAppDbg + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +========================================= +Includes XML-RPC client interface for Python +# Copyright (c) 1999-2002 by Secret Labs AB +# Copyright (c) 1999-2002 by Fredrik Lundh +# +# By obtaining, using, and/or copying this software and/or its +# associated documentation, you agree that you have read, understood, +# and will comply with the following terms and conditions: +# +# Permission to use, copy, modify, and distribute this software and +# its associated documentation for any purpose and without fee is +# hereby granted, provided that the above copyright notice appears in +# all copies, and that both that copyright notice and this permission +# notice appear in supporting documentation, and that the name of +# Secret Labs AB or the author not be used in advertising or publicity +# pertaining to distribution of the software without specific, written +# prior permission. +# +# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD +# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- +# ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR +# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +========================================= +END OF PyDev.Debugger NOTICES, INFORMATION, AND LICENSE + +%% untangle NOTICES, INFORMATION, AND LICENSE BEGIN HERE +========================================= +# Author: Christian Stefanescu + +# Contributions from: + +Florian Idelberger +Apalala + +// Copyright (c) 2011 + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + +========================================= +END OF untangle NOTICES, INFORMATION, AND LICENSE + + diff --git a/adapter/python/ptvsd/__init__.py b/adapter/python/ptvsd/__init__.py new file mode 100644 index 0000000..5c5c861 --- /dev/null +++ b/adapter/python/ptvsd/__init__.py @@ -0,0 +1,24 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +__all__ = [ + '__version__', '__author__', + 'enable_attach', 'wait_for_attach', 'break_into_debugger', 'is_attached', +] + + +# "force_pydevd" must be imported first to ensure (via side effects) +# that the ptvsd-vendored copy of pydevd gets used. +from ._vendored import force_pydevd +from ptvsd.version import __version__, __author__ +from ptvsd.attach_server import ( # noqa + attach, + break_into_debugger, + debug_this_thread, + enable_attach, + is_attached, + wait_for_attach, +) +from ptvsd.tracing import tracing # noqa +del force_pydevd diff --git a/adapter/python/ptvsd/__main__.py b/adapter/python/ptvsd/__main__.py new file mode 100644 index 0000000..b25cfbb --- /dev/null +++ b/adapter/python/ptvsd/__main__.py @@ -0,0 +1,446 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import absolute_import, print_function, with_statement + +import numbers +import os.path +import runpy +import sys +import site +import sysconfig + +# ptvsd can also be invoked directly rather than via -m. In this case, the +# first entry on sys.path is the one added automatically by Python for the +# directory containing this file. This means that 1) import ptvsd will not +# work, since we need the parent directory of ptvsd/ to be on path, rather +# than ptvsd/ itself, and 2) many other absolute imports will break, because +# they will be resolved relative to ptvsd/ - e.g. import socket will then +# try to import ptvsd/socket.py! +# +# To fix this, we need to replace the automatically added entry such that it +# points at the parent directory instead, import ptvsd from that directory, +# and then remove than entry altogether so that it doesn't affect any further +# imports. For example, suppose the user did: +# +# python /foo/bar/ptvsd ... +# +# At the beginning of this script, sys.path will contain '/foo/bar/ptvsd' as +# the first entry. What we want is to replace it with '/foo/bar', then import +# ptvsd with that in effect, and then remove it before continuing execution. +if __name__ == '__main__' and 'ptvsd' not in sys.modules: + sys.path[0] = os.path.dirname(sys.path[0]) + import ptvsd # noqa + del sys.path[0] + +import pydevd + +import threading # Import after pydevd. + +import ptvsd._remote +import ptvsd.options +import ptvsd.runner +import ptvsd.version +from ptvsd.multiproc import listen_for_subprocesses + +# When forming the command line involving __main__.py, it might be tempting to +# import it as a module, and then use its __file__. However, that does not work +# reliably, because __file__ can be a relative path - and when it is relative, +# that's relative to the current directory at the time import was done, which +# may be different from the current directory at the time the path is used. +# +# So, to be able to correctly locate the script at any point, we compute the +# absolute path at import time. +__file__ = os.path.abspath(__file__) + +TARGET = ' | -m | -c | --pid ' + +HELP = ('''ptvsd %s +See https://aka.ms/ptvsd for documentation. + +Usage: ptvsd --host
[--port ] [--wait] [--multiprocess] + [--log-dir ] + ''' + TARGET + ''' +''') % (ptvsd.version.__version__,) + + +# In Python 2, arguments are passed as bytestrings in locale encoding +# For uniformity, parse them into Unicode strings. +def string(s): + if isinstance(s, bytes): + s = s.decode(sys.getfilesystemencoding()) + return s + + +def in_range(parser, start, stop): + + def parse(s): + n = parser(s) + if start is not None and n < start: + raise ValueError('must be >= %s' % start) + if stop is not None and n >= stop: + raise ValueError('must be < %s' % stop) + return n + + return parse + + +port = in_range(int, 0, 2 ** 16) + +pid = in_range(int, 0, None) + + +def print_help_and_exit(switch, it): + print(HELP, file=sys.stderr) + sys.exit(0) + + +def print_version_and_exit(switch, it): + print(ptvsd.version.__version__) + sys.exit(0) + + +def set_arg(varname, parser): + + def action(arg, it): + value = parser(next(it)) + setattr(ptvsd.options, varname, value) + + return action + + +def set_true(varname): + + def do(arg, it): + setattr(ptvsd.options, varname, True) + + return do + + +def set_target(kind, parser=None): + + def do(arg, it): + ptvsd.options.target_kind = kind + ptvsd.options.target = arg if parser is None else parser(next(it)) + + return do + + +def set_nodebug(arg, it): + # --nodebug implies --client + ptvsd.options.no_debug = True + ptvsd.options.client = True + + +switches = [ + # fmt: off + + # Switch Placeholder Action Required + # ====== =========== ====== ======== + + # Switches that are documented for use by end users. + (('-?', '-h', '--help'), None, print_help_and_exit, False), + (('-V', '--version'), None, print_version_and_exit, False), + ('--host', '
', set_arg('host', string), True), + ('--port', '', set_arg('port', port), False), + ('--wait', None, set_true('wait'), False), + ('--multiprocess', None, set_true('multiprocess'), False), + ('--log-dir', '', set_arg('log_dir', string), False), + + # Switches that are used internally by the IDE or ptvsd itself. + ('--nodebug', None, set_nodebug, False), + ('--client', None, set_true('client'), False), + ('--subprocess-of', '', set_arg('subprocess_of', pid), False), + ('--subprocess-notify', '', set_arg('subprocess_notify', port), False), + + # Targets. The '' entry corresponds to positional command line arguments, + # i.e. the ones not preceded by any switch name. + ('', '', set_target('file'), False), + ('-m', '', set_target('module', string), False), + ('-c', '', set_target('code', string), False), + ('--pid', '', set_target('pid', pid), False), + + # fmt: on +] + + +def parse(args): + unseen_switches = list(switches) + + it = iter(args) + while True: + try: + arg = next(it) + except StopIteration: + raise ValueError('missing target: ' + TARGET) + + switch = arg if arg.startswith('-') else '' + for i, (sw, placeholder, action, _) in enumerate(unseen_switches): + if isinstance(sw, str): + sw = (sw,) + if switch in sw: + del unseen_switches[i] + break + else: + raise ValueError('unrecognized switch ' + switch) + + try: + action(arg, it) + except StopIteration: + assert placeholder is not None + raise ValueError('%s: missing %s' % (switch, placeholder)) + except Exception as ex: + raise ValueError('invalid %s %s: %s' % (switch, placeholder, str(ex))) + + if ptvsd.options.target is not None: + break + + for sw, placeholder, _, required in unseen_switches: + if required: + if not isinstance(sw, str): + sw = sw[0] + message = 'missing required %s' % sw + if placeholder is not None: + message += ' ' + placeholder + raise ValueError(message) + + return it + + +daemon = None + + +def setup_connection(): + ptvsd.log.debug('sys.prefix: {0}', (sys.prefix,)) + + if hasattr(sys, 'base_prefix'): + ptvsd.log.debug('sys.base_prefix: {0}', sys.base_prefix) + + if hasattr(sys, 'real_prefix'): + ptvsd.log.debug('sys.real_prefix: {0}', sys.real_prefix) + + if hasattr(site, 'getusersitepackages'): + ptvsd.log.debug('site.getusersitepackages(): {0}', site.getusersitepackages()) + + if hasattr(site, 'getsitepackages'): + ptvsd.log.debug('site.getsitepackages(): {0}', site.getsitepackages()) + + for path in sys.path: + if os.path.exists(path) and os.path.basename(path) == 'site-packages': + ptvsd.log.debug('Folder with "site-packages" in sys.path: {0}', path) + + for path_name in {'stdlib', 'platstdlib', 'purelib', 'platlib'} & set( + sysconfig.get_path_names()): + ptvsd.log.debug('sysconfig {0}: {1}', path_name, sysconfig.get_path(path_name)) + + ptvsd.log.debug('os dir: {0}', os.path.dirname(os.__file__)) + ptvsd.log.debug('threading dir: {0}', os.path.dirname(threading.__file__)) + + opts = ptvsd.options + pydevd.apply_debugger_options({ + 'server': not opts.client, + 'client': opts.host, + 'port': opts.port, + 'multiprocess': opts.multiprocess, + }) + + if opts.multiprocess: + listen_for_subprocesses() + + # We need to set up sys.argv[0] before invoking attach() or enable_attach(), + # because they use it to report the 'process' event. Thus, we can't rely on + # run_path() and run_module() doing that, even though they will eventually. + + if opts.target_kind == 'code': + sys.argv[0] = '-c' + elif opts.target_kind == 'file': + sys.argv[0] = opts.target + elif opts.target_kind == 'module': + # Add current directory to path, like Python itself does for -m. This must + # be in place before trying to use find_spec below to resolve submodules. + sys.path.insert(0, '') + + # We want to do the same thing that run_module() would do here, without + # actually invoking it. On Python 3, it's exposed as a public API, but + # on Python 2, we have to invoke a private function in runpy for this. + # Either way, if it fails to resolve for any reason, just leave argv as is. + try: + if sys.version_info >= (3,): + from importlib.util import find_spec + spec = find_spec(opts.target) + if spec is not None: + sys.argv[0] = spec.origin + else: + _, _, _, sys.argv[0] = runpy._get_module_details(opts.target) + except Exception: + ptvsd.log.exception('Error determining module path for sys.argv') + else: + assert False + + ptvsd.log.debug('sys.argv after patching: {0!r}', sys.argv) + + addr = (opts.host, opts.port) + + global daemon + if opts.no_debug: + daemon = ptvsd.runner.Daemon() + if not daemon.wait_for_launch(addr): + return + elif opts.client: + daemon = ptvsd._remote.attach(addr) + else: + daemon = ptvsd._remote.enable_attach(addr) + + if opts.wait: + ptvsd.wait_for_attach() + + +def run_file(): + setup_connection() + + target = ptvsd.options.target + ptvsd.log.info('Running file {0}', target) + + # run_path has one difference with invoking Python from command-line: + # if the target is a file (rather than a directory), it does not add its + # parent directory to sys.path. Thus, importing other modules from the + # same directory is broken unless sys.path is patched here. + if os.path.isfile(target): + dir = os.path.dirname(target) + ptvsd.log.debug('Adding {0} to sys.path.', dir) + sys.path.insert(0, dir) + else: + ptvsd.log.debug('Not a file: {0}', target) + + runpy.run_path(target, run_name='__main__') + + +def run_module(): + setup_connection() + + # On Python 2, module name must be a non-Unicode string, because it ends up + # a part of module's __package__, and Python will refuse to run the module + # if __package__ is Unicode. + target = ptvsd.options.target + if sys.version_info < (3,) and not isinstance(target, bytes): + target = target.encode(sys.getfilesystemencoding()) + + ptvsd.log.info('Running module {0}', target) + + # Docs say that runpy.run_module is equivalent to -m, but it's not actually + # the case for packages - -m sets __name__ to '__main__', but run_module sets + # it to `pkg.__main__`. This breaks everything that uses the standard pattern + # __name__ == '__main__' to detect being run as a CLI app. On the other hand, + # runpy._run_module_as_main is a private function that actually implements -m. + try: + run_module_as_main = runpy._run_module_as_main + except AttributeError: + ptvsd.log.warning('runpy._run_module_as_main is missing, falling back to run_module.') + runpy.run_module(target, alter_sys=True) + else: + run_module_as_main(target, alter_argv=True) + + +def run_code(): + ptvsd.log.info('Running code:\n\n{0}', ptvsd.options.target) + + # Add current directory to path, like Python itself does for -c. + sys.path.insert(0, '') + code = compile(ptvsd.options.target, '', 'exec') + setup_connection() + eval(code, {}) + + +def attach_to_pid(): + + ptvsd.log.info('Attaching to process with ID {0}', ptvsd.options.target) + + pid = ptvsd.options.target + host = ptvsd.options.host + port = ptvsd.options.port + client = ptvsd.options.client + log_dir = ptvsd.options.log_dir + if log_dir is None: + log_dir = "" + + # pydevd requires injected code to not contain any single quotes nor new lines and + # double quotes must be escaped properly. + pydevd_attach_to_process_path = os.path.join( + os.path.dirname(pydevd.__file__), + 'pydevd_attach_to_process') + + sys.path.append(pydevd_attach_to_process_path) + + import add_code_to_python_process # noqa + show_debug_info_on_target_process = 0 # hard-coded (1 to debug) + + ptvsd_dirname = os.path.dirname(os.path.dirname(__file__)) + attach_script_ptvsd_pid_dirname = os.path.join(ptvsd_dirname, 'ptvsd') + assert os.path.exists(ptvsd_dirname) + assert os.path.exists(attach_script_ptvsd_pid_dirname) + log_dir = log_dir.replace('\\', '/') + setup = {'host': host, 'port': port, 'client': client, 'log_dir': log_dir, 'pid': pid} + + if sys.platform == 'win32': + setup['pythonpath'] = ptvsd_dirname.replace('\\', '/') + + # We need to be able to import attach_script_ptvsd_pid without importing ptvsd first. + setup['pythonpath2'] = attach_script_ptvsd_pid_dirname.replace('\\', '/') + + python_code = '''import sys; +sys.path.append("%(pythonpath)s"); +sys.path.append("%(pythonpath2)s"); +import attach_script_ptvsd_pid; +attach_script_ptvsd_pid.attach(port=%(port)s, host="%(host)s", client=%(client)s, log_dir="%(log_dir)s"); +'''.replace('\r\n', '').replace('\r', '').replace('\n', '') + else: + setup['pythonpath'] = ptvsd_dirname + setup['pythonpath2'] = attach_script_ptvsd_pid_dirname + # We have to pass it a bit differently for gdb + python_code = '''import sys; +sys.path.append(\\\"%(pythonpath)s\\\"); +sys.path.append(\\\"%(pythonpath2)s\\\"); +import attach_script_ptvsd_pid; +attach_script_ptvsd_pid.attach(port=%(port)s, host=\\\"%(host)s\\\", client=%(client)s, log_dir=\\\"%(log_dir)s\\\"); +'''.replace('\r\n', '').replace('\r', '').replace('\n', '') + + python_code = python_code % setup + add_code_to_python_process.run_python_code( + setup['pid'], python_code, connect_debugger_tracing=True, show_debug_info=show_debug_info_on_target_process) + + +def main(argv=sys.argv): + saved_argv = list(argv) + try: + sys.argv[:] = [argv[0]] + list(parse(argv[1:])) + except Exception as ex: + print(HELP + '\nError: ' + str(ex), file=sys.stderr) + sys.exit(2) + + ptvsd.log.to_file() + ptvsd.log.info('main({0!r})', saved_argv) + ptvsd.log.info('sys.argv after parsing: {0!r}', sys.argv) + + try: + run = { + 'file': run_file, + 'module': run_module, + 'code': run_code, + 'pid': attach_to_pid, + }[ptvsd.options.target_kind] + run() + except SystemExit as ex: + ptvsd.log.exception('Debuggee exited via SystemExit', category='D') + if daemon is not None: + if ex.code is None: + daemon.exitcode = 0 + elif isinstance(ex.code, numbers.Integral): + daemon.exitcode = int(ex.code) + else: + daemon.exitcode = 1 + raise + + +if __name__ == '__main__': + main(sys.argv) diff --git a/adapter/python/ptvsd/_local.py b/adapter/python/ptvsd/_local.py new file mode 100644 index 0000000..2330728 --- /dev/null +++ b/adapter/python/ptvsd/_local.py @@ -0,0 +1,149 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import numbers +import sys +import time + +import pydevd +from _pydevd_bundle.pydevd_comm import get_global_debugger + +from ptvsd.pydevd_hooks import install +from ptvsd.runner import run as no_debug_runner +from ptvsd.socket import Address +from ptvsd._util import new_hidden_thread + + +PYDEVD_DEFAULTS = { + '--json-dap', + '--qt-support=auto', +} + + +def _set_pydevd_defaults(pydevd_args): + args_to_append = [] + for arg in PYDEVD_DEFAULTS: + if arg not in pydevd_args: + args_to_append.append(arg) + return pydevd_args + args_to_append + + +######################## +# high-level functions + +def debug_main(address, name, kind, *extra, **kwargs): + if not kwargs.pop('wait', False) and address.isserver: + def unblock_debugger(): + debugger = get_global_debugger() + while debugger is None: + time.sleep(0.1) + debugger = get_global_debugger() + debugger.ready_to_run = True + new_hidden_thread('ptvsd.unblock_debugger', unblock_debugger).start() + if kind == 'module': + run_module(address, name, *extra, **kwargs) + else: + run_file(address, name, *extra, **kwargs) + + +def run_main(address, name, kind, *extra, **kwargs): + addr = Address.from_raw(address) + sys.argv[:] = _run_main_argv(name, extra) + runner = kwargs.pop('_runner', no_debug_runner) + runner(addr, name, kind == 'module', *extra, **kwargs) + + +######################## +# low-level functions + +def run_module(address, modname, *extra, **kwargs): + """Run pydevd for the given module.""" + addr = Address.from_raw(address) + if not addr.isserver: + kwargs['singlesession'] = True + run = kwargs.pop('_run', _run) + prog = kwargs.pop('_prog', sys.argv[0]) + filename = modname + ':' + argv = _run_argv(addr, filename, extra, _prog=prog) + argv.insert(argv.index('--file'), '--module') + run(argv, addr, **kwargs) + + +def run_file(address, filename, *extra, **kwargs): + """Run pydevd for the given Python file.""" + addr = Address.from_raw(address) + if not addr.isserver: + kwargs['singlesession'] = True + run = kwargs.pop('_run', _run) + prog = kwargs.pop('_prog', sys.argv[0]) + argv = _run_argv(addr, filename, extra, _prog=prog) + run(argv, addr, **kwargs) + + +def _run_argv(address, filename, extra, _prog=sys.argv[0]): + """Convert the given values to an argv that pydevd.main() supports.""" + if '--' in extra: + pydevd = list(extra[:extra.index('--')]) + extra = list(extra[len(pydevd) + 1:]) + else: + pydevd = [] + extra = list(extra) + + pydevd = _set_pydevd_defaults(pydevd) + host, port = address + argv = [ + _prog, + '--port', str(port), + ] + if not address.isserver: + argv.extend([ + '--client', host or 'localhost', + ]) + return argv + pydevd + [ + '--file', filename, + ] + extra + + +def _run_main_argv(filename, extra): + if '--' in extra: + pydevd = list(extra[:extra.index('--')]) + extra = list(extra[len(pydevd) + 1:]) + else: + extra = list(extra) + return [filename] + extra + + +def _run(argv, addr, _pydevd=pydevd, _install=install, **kwargs): + """Start pydevd with the given commandline args.""" + + # Pydevd assumes that the "__main__" module is the "pydevd" module + # and does some tricky stuff under that assumption. For example, + # when the debugger starts up it calls save_main_module() + # (in pydevd_bundle/pydevd_utils.py). That function explicitly sets + # sys.modules["pydevd"] to sys.modules["__main__"] and then sets + # the __main__ module to a new one. This makes some sense since + # it gives the debugged script a fresh __main__ module. + # + # This complicates things for us since we are running a different + # file (i.e. this one) as the __main__ module. Consequently, + # sys.modules["pydevd"] gets set to ptvsd/__main__.py. Subsequent + # imports of the "pydevd" module then return the wrong module. We + # work around this by avoiding lazy imports of the "pydevd" module. + # We also replace the __main__ module with the "pydevd" module here. + if sys.modules['__main__'].__file__ != _pydevd.__file__: + sys.modules['__main___orig'] = sys.modules['__main__'] + sys.modules['__main__'] = _pydevd + + daemon = _install(_pydevd, addr, **kwargs) + sys.argv[:] = argv + try: + _pydevd.main() + except SystemExit as ex: + if ex.code is None: + daemon.exitcode = 0 + elif isinstance(ex.code, numbers.Integral): + daemon.exitcode = int(ex.code) + else: + daemon.exitcode = 1 + raise diff --git a/adapter/python/ptvsd/_remote.py b/adapter/python/ptvsd/_remote.py new file mode 100644 index 0000000..de06146 --- /dev/null +++ b/adapter/python/ptvsd/_remote.py @@ -0,0 +1,115 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import pydevd +import time + +from _pydevd_bundle.pydevd_comm import get_global_debugger + +import ptvsd +import ptvsd.log +import ptvsd.options +from ptvsd._util import new_hidden_thread +from ptvsd.pydevd_hooks import install +from ptvsd.daemon import session_not_bound, DaemonClosedError + + +global_next_session = lambda: None + + +def enable_attach(address, on_attach=lambda: None, **kwargs): + + host, port = address + + def wait_for_connection(daemon, host, port, next_session=None): + ptvsd.log.debug('Waiting for pydevd ...') + debugger = get_global_debugger() + while debugger is None: + time.sleep(0.1) + debugger = get_global_debugger() + + ptvsd.log.debug('Unblocking pydevd.') + debugger.ready_to_run = True + + while True: + try: + session_not_bound.wait() + try: + global_next_session() + on_attach() + except DaemonClosedError: + return + except TypeError: + # May happen during interpreter shutdown + # (if some global -- such as global_next_session becomes None). + return + + def start_daemon(): + daemon._sock = daemon._start() + _, next_session = daemon.start_server(addr=(host, port)) + global global_next_session + global_next_session = next_session + if port == 0: + _, ptvsd.options.port = daemon._server.getsockname() + else: + ptvsd.options.port = port + return daemon._sock + + daemon = install(pydevd, + address, + start_server=None, + start_client=(lambda daemon, h, port: start_daemon()), + singlesession=False, + **kwargs) + + ptvsd.log.debug('Starting connection listener thread') + connection_thread = new_hidden_thread('ptvsd.listen_for_connection', + wait_for_connection, + args=(daemon, host, port)) + connection_thread.start() + + if ptvsd.options.no_debug: + _setup_nodebug() + else: + ptvsd.log.debug('pydevd.settrace()') + pydevd.settrace(host=host, + port=port, + suspend=False, + patch_multiprocessing=ptvsd.options.multiprocess) + + return daemon + + +def attach(address, **kwargs): + host, port = address + daemon = install(pydevd, address, singlesession=False, **kwargs) + + if ptvsd.options.no_debug: + _setup_nodebug() + else: + ptvsd.log.debug('pydevd.settrace()') + pydevd.settrace(host=host, + port=port, + suspend=False, + patch_multiprocessing=ptvsd.options.multiprocess) + + return daemon + + +def _setup_nodebug(): + ptvsd.log.debug('Running pydevd in nodebug mode.') + debugger = pydevd.PyDB() + debugger.init_matplotlib_support = lambda *arg: None + # We are invoking run() solely for side effects here - setting up the + # debugger and connecting to our socket - so the code run is a no-op. + debugger.run( + file='ptvsd._remote:_nop', + globals=None, + locals=None, + is_module=True, + set_trace=False) + + +def _nop(): + pass diff --git a/adapter/python/ptvsd/_util.py b/adapter/python/ptvsd/_util.py new file mode 100644 index 0000000..004388c --- /dev/null +++ b/adapter/python/ptvsd/_util.py @@ -0,0 +1,343 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function + +import contextlib +import threading +import time +import sys + +import ptvsd.log + + +@contextlib.contextmanager +def ignore_errors(log=None): + """A context manager that masks any raised exceptions.""" + try: + yield + except Exception: + if log is not None: + ptvsd.log.exception('Ignoring error', category='I') + + +def call_all(callables, *args, **kwargs): + """Return the result of calling every given object.""" + results = [] + for call in callables: + try: + call(*args, **kwargs) + except Exception as exc: + results.append((call, exc)) + else: + results.append((call, None)) + return results + + +######################## +# threading stuff + +try: + ThreadError = threading.ThreadError +except AttributeError: + ThreadError = RuntimeError + + +try: + base = __builtins__.TimeoutError +except AttributeError: + base = OSError +class TimeoutError(base): # noqa + """Timeout expired.""" + timeout = None + reason = None + + @classmethod + def from_timeout(cls, timeout, reason=None): + """Return a TimeoutError with the given timeout.""" + msg = 'timed out (after {} seconds)'.format(timeout) + if reason is not None: + msg += ' ' + reason + self = cls(msg) + self.timeout = timeout + self.reason = reason + return self +del base # noqa + + +def wait(check, timeout=None, reason=None): + """Wait for the given func to return True. + + If a timeout is given and reached then raise TimeoutError. + """ + if timeout is None or timeout <= 0: + while not check(): + time.sleep(0.01) + else: + if not _wait(check, timeout): + raise TimeoutError.from_timeout(timeout, reason) + + +def is_locked(lock): + """Return True if the lock is locked.""" + if lock is None: + return False + if not lock.acquire(False): + return True + lock_release(lock) + return False + + +def lock_release(lock): + """Ensure that the lock is released.""" + if lock is None: + return + try: + lock.release() + except ThreadError: # already unlocked + pass + + +def lock_wait(lock, timeout=None, reason='waiting for lock'): + """Wait until the lock is not locked.""" + if not _lock_acquire(lock, timeout): + raise TimeoutError.from_timeout(timeout, reason) + lock_release(lock) + + +if sys.version_info >= (3,): + def _lock_acquire(lock, timeout): + if timeout is None: + timeout = -1 + return lock.acquire(timeout=timeout) +else: + def _lock_acquire(lock, timeout): + if timeout is None or timeout <= 0: + return lock.acquire() + + def check(): + return lock.acquire(False) + return _wait(check, timeout) + + +def _wait(check, timeout): + if check(): + return True + for _ in range(int(timeout * 100)): + time.sleep(0.01) + if check(): + return True + else: + return False + + +def new_hidden_thread(name, target, prefix='ptvsd.', daemon=True, **kwargs): + """Return a thread that will be ignored by pydevd.""" + if prefix is not None and not name.startswith(prefix): + name = prefix + name + t = threading.Thread( + name=name, + target=target, + **kwargs + ) + t.pydev_do_not_trace = True + t.is_pydev_daemon_thread = True + if daemon: + t.daemon = True + return t + + +######################## +# closing stuff + +class ClosedError(RuntimeError): + """Indicates that the object is closed.""" + + +def close_all(closeables): + """Return the result of closing every given object.""" + results = [] + for obj in closeables: + try: + obj.close() + except Exception as exc: + results.append((obj, exc)) + else: + results.append((obj, None)) + return results + + +class Closeable(object): + """A base class for types that may be closed.""" + + NAME = None + FAIL_ON_ALREADY_CLOSED = True + + def __init__(self): + super(Closeable, self).__init__() + self._closed = False + self._closedlock = threading.Lock() + self._handlers = [] + + def __del__(self): + try: + self.close() + except ClosedError: + pass + + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + + @property + def closed(self): + return self._closed + + def add_resource_to_close(self, resource, before=False): + """Add a resource to be closed when closing.""" + close = resource.close + if before: + def handle_closing(before): + if not before: + return + close() + else: + def handle_closing(before): + if before: + return + close() + self.add_close_handler(handle_closing) + + def add_close_handler(self, handle_closing, nodupe=True): + """Add a func to be called when closing. + + The func takes one arg: True if it was called before the main + close func and False if after. + """ + with self._closedlock: + if self._closed: + if self.FAIL_ON_ALREADY_CLOSED: + raise ClosedError('already closed') + return + if nodupe and handle_closing in self._handlers: + raise ValueError('close func already added') + + self._handlers.append(handle_closing) + + def check_closed(self): + """Raise ClosedError if closed.""" + if self._closed: + if self.NAME: + raise ClosedError('{} closed'.format(self.NAME)) + else: + raise ClosedError('closed') + + @contextlib.contextmanager + def while_not_closed(self): + """A context manager under which the object will not be closed.""" + with self._closedlock: + self.check_closed() + yield + + def close(self): + """Release any owned resources and clean up.""" + with self._closedlock: + if self._closed: + if self.FAIL_ON_ALREADY_CLOSED: + raise ClosedError('already closed') + return + self._closed = True + handlers = list(self._handlers) + + results = call_all(handlers, True) + self._log_results(results) + self._close() + results = call_all(handlers, False) + self._log_results(results) + + # implemented by subclasses + + def _close(self): + pass + + # internal methods + + def _log_results(self, results, log=None): + if log is None: + return + for obj, exc in results: + if exc is None: + continue + log('failed to close {!r} ({!r})'.format(obj, exc)) + + +######################## +# running stuff + +class NotRunningError(RuntimeError): + """Something isn't currently running.""" + + +class AlreadyStartedError(RuntimeError): + """Something was already started.""" + + +class AlreadyRunningError(AlreadyStartedError): + """Something is already running.""" + + +class Startable(object): + """A base class for types that may be started.""" + + RESTARTABLE = False + FAIL_ON_ALREADY_STOPPED = True + + def __init__(self): + super(Startable, self).__init__() + self._is_running = None + self._startlock = threading.Lock() + self._numstarts = 0 + + def is_running(self, checkclosed=True): + """Return True if currently running.""" + if checkclosed and hasattr(self, 'check_closed'): + self.check_closed() + is_running = self._is_running + if is_running is None: + return False + return is_running() + + def start(self, *args, **kwargs): + """Begin internal execution.""" + with self._startlock: + if self.is_running(): + raise AlreadyRunningError() + if not self.RESTARTABLE and self._numstarts > 0: + raise AlreadyStartedError() + + self._is_running = self._start(*args, **kwargs) + self._numstarts += 1 + + def stop(self, *args, **kwargs): + """Stop execution and wait until done.""" + with self._startlock: + # TODO: Call self.check_closed() here? + if not self.is_running(checkclosed=False): + if not self.FAIL_ON_ALREADY_STOPPED: + return + raise NotRunningError() + self._is_running = None + + self._stop(*args, **kwargs) + + # implemented by subclasses + + def _start(self, *args, **kwargs): + """Return an "is_running()" func after starting.""" + raise NotImplementedError + + def _stop(self): + raise NotImplementedError diff --git a/adapter/python/ptvsd/_vendored/__init__.py b/adapter/python/ptvsd/_vendored/__init__.py new file mode 100644 index 0000000..f963e11 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/__init__.py @@ -0,0 +1,123 @@ +import contextlib +from importlib import import_module +import os +import os.path +import sys + +from . import _util + + +VENDORED_ROOT = os.path.dirname(os.path.abspath(__file__)) +# TODO: Move the "pydevd" git submodule to the ptvsd/_vendored directory +# and then drop the following fallback. +if 'pydevd' not in os.listdir(VENDORED_ROOT): + VENDORED_ROOT = os.path.dirname(VENDORED_ROOT) + + +def list_all(resolve=False): + """Return the list of vendored projects.""" + # TODO: Derive from os.listdir(VENDORED_ROOT)? + projects = [ + 'pydevd', + ] + if not resolve: + return projects + return [project_root(name) for name in projects] + + +def project_root(project): + """Return the path the root dir of the vendored project. + + If "project" is an empty string then the path prefix for vendored + projects (e.g. "ptvsd/_vendored/") will be returned. + """ + if not project: + project = '' + return os.path.join(VENDORED_ROOT, project) + + +def iter_project_files(project, relative=False, **kwargs): + """Yield (dirname, basename, filename) for all files in the project.""" + if relative: + with _util.cwd(VENDORED_ROOT): + for result in _util.iter_all_files(project, **kwargs): + yield result + else: + root = project_root(project) + for result in _util.iter_all_files(root, **kwargs): + yield result + + +def iter_packaging_files(project): + """Yield the filenames for all files in the project. + + The filenames are relative to "ptvsd/_vendored". This is most + useful for the "package data" in a setup.py. + """ + # TODO: Use default filters? __pycache__ and .pyc? + prune_dir = None + exclude_file = None + try: + mod = import_module('._{}_packaging'.format(project), __name__) + except ImportError: + pass + else: + prune_dir = getattr(mod, 'prune_dir', prune_dir) + exclude_file = getattr(mod, 'exclude_file', exclude_file) + results = iter_project_files( + project, + relative=True, + prune_dir=prune_dir, + exclude_file=exclude_file, + ) + for _, _, filename in results: + yield filename + + +def prefix_matcher(*prefixes): + """Return a module match func that matches any of the given prefixes.""" + assert prefixes + + def match(name, module): + for prefix in prefixes: + if name.startswith(prefix): + return True + else: + return False + return match + + +def check_modules(project, match, root=None): + """Verify that only vendored modules have been imported.""" + if root is None: + root = project_root(project) + extensions = [] + unvendored = {} + for modname, mod in sys.modules.items(): + if not match(modname, mod): + continue + if not hasattr(mod, '__file__'): # extension module + extensions.append(modname) + elif not mod.__file__.startswith(root): + unvendored[modname] = mod.__file__ + return unvendored, extensions + + +@contextlib.contextmanager +def vendored(project, root=None): + """A context manager under which the vendored project will be imported.""" + if root is None: + root = project_root(project) + # Add the vendored project directory, so that it gets tried first. + sys.path.insert(0, root) + try: + yield root + finally: + sys.path.remove(root) + + +def preimport(project, modules, **kwargs): + """Import each of the named modules out of the vendored project.""" + with vendored(project, **kwargs): + for name in modules: + import_module(name) diff --git a/adapter/python/ptvsd/_vendored/_pydevd_packaging.py b/adapter/python/ptvsd/_vendored/_pydevd_packaging.py new file mode 100644 index 0000000..2a71330 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/_pydevd_packaging.py @@ -0,0 +1,44 @@ +from . import VENDORED_ROOT +from ._util import cwd, iter_all_files + + +INCLUDES = [ + 'setup_cython.py', +] + + +def iter_files(): + # From the root of pydevd repo, we want only scripts and + # subdirectories that constitute the package itself (not helper + # scripts, tests etc). But when walking down into those + # subdirectories, we want everything below. + + with cwd(VENDORED_ROOT): + return iter_all_files('pydevd', prune_dir, exclude_file) + + +def prune_dir(dirname, basename): + if basename == '__pycache__': + return True + elif dirname != 'pydevd': + return False + elif basename.startswith('pydev'): + return False + elif basename.startswith('_pydev'): + return False + return True + + +def exclude_file(dirname, basename): + if dirname == 'pydevd': + if basename in INCLUDES: + return False + elif not basename.endswith('.py'): + return True + elif 'pydev' not in basename: + return True + return False + + if basename.endswith('.pyc'): + return True + return False diff --git a/adapter/python/ptvsd/_vendored/_util.py b/adapter/python/ptvsd/_vendored/_util.py new file mode 100644 index 0000000..7ac4d37 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/_util.py @@ -0,0 +1,56 @@ +import contextlib +import os +import os.path + + +@contextlib.contextmanager +def cwd(dirname): + """A context manager for operating in a different directory.""" + orig = os.getcwd() + os.chdir(dirname) + try: + yield orig + finally: + os.chdir(orig) + + +def iter_all_files(root, prune_dir=None, exclude_file=None): + """Yield (dirname, basename, filename) for each file in the tree. + + This is an alternative to os.walk() that flattens out the tree and + with filtering. + """ + pending = [root] + while pending: + dirname = pending.pop(0) + for result in _iter_files(dirname, pending, prune_dir, exclude_file): + yield result + + +def iter_tree(root, prune_dir=None, exclude_file=None): + """Yield (dirname, files) for each directory in the tree. + + The list of files is actually a list of (basename, filename). + + This is an alternative to os.walk() with filtering.""" + pending = [root] + while pending: + dirname = pending.pop(0) + files = [] + for _, b, f in _iter_files(dirname, pending, prune_dir, exclude_file): + files.append((b, f)) + yield dirname, files + + +def _iter_files(dirname, subdirs, prune_dir, exclude_file): + for basename in os.listdir(dirname): + filename = os.path.join(dirname, basename) + if os.path.isdir(filename): + if prune_dir is not None and prune_dir(dirname, basename): + continue + subdirs.append(filename) + else: + # TODO: Use os.path.isfile() to narrow it down? + if exclude_file is not None and exclude_file(dirname, basename): + continue + yield dirname, basename, filename diff --git a/adapter/python/ptvsd/_vendored/force_pydevd.py b/adapter/python/ptvsd/_vendored/force_pydevd.py new file mode 100644 index 0000000..8a2245a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/force_pydevd.py @@ -0,0 +1,57 @@ +from importlib import import_module +import warnings + +from . import check_modules, prefix_matcher, preimport, vendored + +# Ensure that pydevd is our vendored copy. +_unvendored, _ = check_modules('pydevd', + prefix_matcher('pydev', '_pydev')) +if _unvendored: + _unvendored = sorted(_unvendored.values()) + msg = 'incompatible copy of pydevd already imported' + # raise ImportError(msg) + warnings.warn(msg + ':\n {}'.format('\n '.join(_unvendored))) + +# Constants must be set before importing any other pydevd module +# # due to heavy use of "from" in them. +with vendored('pydevd'): + pydevd_constants = import_module('_pydevd_bundle.pydevd_constants') +# TODO: figure out what the appropriate setting is to work for both wheels and sdist. +pydevd_constants.CYTHON_SUPPORTED = False +# We limit representation size in our representation provider when needed. +pydevd_constants.MAXIMUM_VARIABLE_REPRESENTATION_SIZE = 2 ** 32 + +# Now make sure all the top-level modules and packages in pydevd are +# loaded. Any pydevd modules that aren't loaded at this point, will +# be loaded using their parent package's __path__ (i.e. one of the +# following). +preimport('pydevd', [ + '_pydev_bundle', + '_pydev_imps', + '_pydev_runfiles', + '_pydevd_bundle', + '_pydevd_frame_eval', + 'pydev_ipython', + 'pydevd_concurrency_analyser', + 'pydevd_plugins', + 'pydevd', +]) + +# When pydevd is imported it sets the breakpoint behavior, but it needs to be +# overridden because the pydevd version will connect to the remote debugger by +# default, but without using the ptvsd protocol (so, we need to use the ptvsd +# API to handle things as expected by the debug adapter). +import pydevd # noqa +import ptvsd # noqa + + +def ptvsd_breakpointhook(): + ptvsd.break_into_debugger() + + +pydevd.install_breakpointhook(ptvsd_breakpointhook) + +# Ensure that pydevd uses JSON protocol +from _pydevd_bundle.pydevd_constants import JSON_PROTOCOL +from _pydevd_bundle.pydevd_defaults import PydevdCustomization +PydevdCustomization.DEFAULT_PROTOCOL = JSON_PROTOCOL diff --git a/adapter/python/ptvsd/_vendored/pydevd/.gitignore b/adapter/python/ptvsd/_vendored/pydevd/.gitignore new file mode 100644 index 0000000..20bdddf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/.gitignore @@ -0,0 +1,37 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*.class +_pydevd_bundle/*.so +# Distribution / packaging +.Python +env/ +bin/ +build/temp.* +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +snippet.py +build/* +.pytest_cache \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/.travis.yml b/adapter/python/ptvsd/_vendored/pydevd/.travis.yml new file mode 100644 index 0000000..a726520 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/.travis.yml @@ -0,0 +1,134 @@ +language: python + +services: + - xvfb + +addons: + apt: + packages: + - gdb + +matrix: + include: + # Note: python is always 2.7 because it's the installed version + # in the travis system (so, faster to startup). + # We'll always use conda later on anyways to get what we want. + + # Note: some envs commented out to have a faster test suite. + + # Jython + - python: 2.7 + env: + - PYDEVD_USE_CYTHON=NO + - PYDEVD_TEST_VM=JYTHON + - JYTHON_URL=http://search.maven.org/remotecontent?filepath=org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar + + # PyPy + - python: 2.7 + env: + - PYDEVD_PYTHON_VERSION=3.6 + - PYDEVD_USE_CYTHON=NO + - PYDEVD_TEST_VM=PYPY + + # Python 2.6 (with and without cython) + - python: 2.7 + env: + - PYDEVD_PYTHON_VERSION=2.6 + - PYDEVD_USE_CYTHON=NO + - PYDEVD_TEST_VM=CPYTHON +# - python: 2.7 +# env: +# - PYDEVD_PYTHON_VERSION=2.6 +# - PYDEVD_USE_CYTHON=YES +# - PYDEVD_TEST_VM=CPYTHON + + # Python 2.7 (with and without cython) + - python: 2.7 +# env: +# - PYDEVD_PYTHON_VERSION=2.7 +# - PYDEVD_USE_CYTHON=NO +# - PYDEVD_TEST_VM=CPYTHON + - python: 2.7 + env: + - PYDEVD_PYTHON_VERSION=2.7 + - PYDEVD_USE_CYTHON=YES + - PYDEVD_TEST_VM=CPYTHON + + # Python 3.5 (with and without cython) +# - python: 2.7 +# env: +# - PYDEVD_PYTHON_VERSION=3.5 +# - PYDEVD_USE_CYTHON=NO +# - PYDEVD_TEST_VM=CPYTHON + - python: 2.7 + env: + - PYDEVD_PYTHON_VERSION=3.5 + - PYDEVD_USE_CYTHON=YES + - PYDEVD_TEST_VM=CPYTHON + + # Python 3.6 (with and without cython) + - python: 2.7 + env: + - PYDEVD_PYTHON_VERSION=3.6 + - PYDEVD_USE_CYTHON=NO + - PYDEVD_TEST_VM=CPYTHON +# - python: 2.7 +# env: +# - PYDEVD_PYTHON_VERSION=3.6 +# - PYDEVD_USE_CYTHON=YES +# - PYDEVD_TEST_VM=CPYTHON + + # Python 3.7 (with and without cython) +# - python: 2.7 +# env: +# - PYDEVD_PYTHON_VERSION=3.7 +# - PYDEVD_USE_CYTHON=NO +# - PYDEVD_TEST_VM=CPYTHON + - python: 2.7 + env: + - PYDEVD_PYTHON_VERSION=3.7 + - PYDEVD_USE_CYTHON=YES + - PYDEVD_TEST_VM=CPYTHON + +before_install: + # CPython / Pypy setup + - if [[ "$PYDEVD_TEST_VM" == "CPYTHON" || "$PYDEVD_TEST_VM" == "PYPY" ]]; then wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh; fi + - if [[ "$PYDEVD_TEST_VM" == "CPYTHON" || "$PYDEVD_TEST_VM" == "PYPY" ]]; then chmod +x miniconda.sh; fi + - if [[ "$PYDEVD_TEST_VM" == "CPYTHON" || "$PYDEVD_TEST_VM" == "PYPY" ]]; then ./miniconda.sh -b; fi + - if [[ "$PYDEVD_TEST_VM" == "CPYTHON" || "$PYDEVD_TEST_VM" == "PYPY" ]]; then export PATH=/home/travis/miniconda2/bin:$PATH; fi + - if [[ "$PYDEVD_TEST_VM" == "CPYTHON" || "$PYDEVD_TEST_VM" == "PYPY" ]]; then conda update --yes conda; fi + # Jython setup + - if [ "$PYDEVD_TEST_VM" == "JYTHON" ]; then wget $JYTHON_URL -O jython_installer.jar; java -jar jython_installer.jar -s -d $HOME/jython; export PATH=$HOME/jython:$HOME/jython/bin:$PATH; fi + - if [ "$PYDEVD_TEST_VM" == "JYTHON" ]; then jython -c "print('')"; fi + # Fix issue with testGui + - "export DISPLAY=:99.0" +# Install packages +install: + - sudo sysctl kernel.yama.ptrace_scope=0 + # Both + - export PYTHONPATH=. + # CPython setup + - if [ "$PYDEVD_TEST_VM" == "CPYTHON" ]; then conda create --yes -n build_env python=$PYDEVD_PYTHON_VERSION; fi + - if [ "$PYDEVD_TEST_VM" == "CPYTHON" ]; then source activate build_env; fi + - if [ "$PYDEVD_TEST_VM" == "CPYTHON" ]; then chmod +x ./.travis_install_python_deps.sh; fi + - if [ "$PYDEVD_TEST_VM" == "CPYTHON" ]; then ./.travis_install_python_deps.sh; fi + - if [ "$PYDEVD_TEST_VM" == "CPYTHON" ]; then source activate build_env; python build_tools/build.py; fi + # Pypy setup + - if [ "$PYDEVD_TEST_VM" == "PYPY" ]; then conda create --yes -n build_env -c conda-forge pypy3.6; fi + - if [ "$PYDEVD_TEST_VM" == "PYPY" ]; then source activate build_env; fi + - if [ "$PYDEVD_TEST_VM" == "PYPY" ]; then chmod +x ./.travis_install_pypy_deps.sh; fi + - if [ "$PYDEVD_TEST_VM" == "PYPY" ]; then ./.travis_install_pypy_deps.sh; fi + # Jython setup + - if [ "$PYDEVD_TEST_VM" == "JYTHON" ]; then chmod +x ./.travis_install_jython_deps.sh; fi + - if [ "$PYDEVD_TEST_VM" == "JYTHON" ]; then ./.travis_install_jython_deps.sh; fi + +# Run test +# On local machine with jython: c:\bin\jython2.7.0\bin\jython.exe -Dpython.path=.;jython_test_deps/ant.jar;jython_test_deps/junit.jar -m pytest +# On remove machine with python: c:\bin\python27\python.exe -m pytest +script: + # pytest-xdist not available for python == 2.6 and timing out without output with 2.7 + - if [[ ("$PYDEVD_TEST_VM" == "CPYTHON") && ("$PYDEVD_PYTHON_VERSION" == "2.6" || "$PYDEVD_PYTHON_VERSION" == "2.7") ]]; then source activate build_env; python -m pytest; fi + - if [[ ("$PYDEVD_TEST_VM" == "CPYTHON") && ("$PYDEVD_PYTHON_VERSION" != "2.6" && "$PYDEVD_PYTHON_VERSION" != "2.7") ]]; then source activate build_env; python -m pytest -n auto; fi + - if [ "$PYDEVD_TEST_VM" == "PYPY" ]; then source activate build_env; pypy3 -m pytest -n auto; fi + - if [ "$PYDEVD_TEST_VM" == "JYTHON" ]; then jython -Dpython.path=.:jython_test_deps/ant.jar:jython_test_deps/junit.jar -m pytest; fi + diff --git a/adapter/python/ptvsd/_vendored/pydevd/.travis_install_jython_deps.sh b/adapter/python/ptvsd/_vendored/pydevd/.travis_install_jython_deps.sh new file mode 100644 index 0000000..4aa9849 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/.travis_install_jython_deps.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -ev + +pip install pytest==4.4.2 untangle pathlib2 diff --git a/adapter/python/ptvsd/_vendored/pydevd/.travis_install_pypy_deps.sh b/adapter/python/ptvsd/_vendored/pydevd/.travis_install_pypy_deps.sh new file mode 100644 index 0000000..740c282 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/.travis_install_pypy_deps.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -ev + +source activate build_env + +pypy3 -m ensurepip + +pypy3 -m pip install pytest +pypy3 -m pip install pytest-xdist +pypy3 -m pip install pytest-timeout +pypy3 -m pip install colorama +pypy3 -m pip install psutil +pypy3 -m pip install numpy +pypy3 -m pip install ipython +pypy3 -m pip install untangle diff --git a/adapter/python/ptvsd/_vendored/pydevd/.travis_install_python_deps.sh b/adapter/python/ptvsd/_vendored/pydevd/.travis_install_python_deps.sh new file mode 100644 index 0000000..c86c969 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/.travis_install_python_deps.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -ev + +source activate build_env +conda install --yes numpy ipython pytest cython psutil + +if [ "$PYDEVD_PYTHON_VERSION" = "2.6" ]; then + conda install --yes pyqt=4 + pip install pympler==0.5 + pip install pathlib2 + # Django 1.7 does not support Python 2.6 +else + # pytest-xdist not available for python 2.6 + pip install pytest-xdist + pip install pympler +fi + +if [ "$PYDEVD_PYTHON_VERSION" = "2.7" ]; then + conda install --yes pyqt=4 gevent + pip install "django>=1.7,<1.8" + pip install pathlib2 + +fi + +if [ "$PYDEVD_PYTHON_VERSION" = "3.5" ]; then + conda install --yes pyqt=5 + pip install "django>=2.1,<2.2" +fi + +if [ "$PYDEVD_PYTHON_VERSION" = "3.6" ]; then + conda install --yes pyqt=5 gevent + pip install "django>=2.2,<2.3" +fi + +if [ "$PYDEVD_PYTHON_VERSION" = "3.7" ]; then + conda install --yes pyqt=5 matplotlib + # Note: track the latest web framework versions. + pip install "django" + pip install "cherrypy" +fi + +pip install untangle +pip install scapy==2.4.0 \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/LICENSE b/adapter/python/ptvsd/_vendored/pydevd/LICENSE new file mode 100644 index 0000000..5032843 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/LICENSE @@ -0,0 +1,203 @@ +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC +LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM +CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation + distributed under this Agreement, and +b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + + where such changes and/or additions to the Program originate from and are + distributed by that particular Contributor. A Contribution 'originates' + from a Contributor if it was added to the Program by such Contributor + itself or anyone acting on such Contributor's behalf. Contributions do not + include additions to the Program which: (i) are separate modules of + software distributed in conjunction with the Program under their own + license agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Program" means the Contributions distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including all Contributors. + +2. GRANT OF RIGHTS + a) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free copyright license to + reproduce, prepare derivative works of, publicly display, publicly + perform, distribute and sublicense the Contribution of such Contributor, + if any, and such derivative works, in source code and object code form. + b) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free patent license under + Licensed Patents to make, use, sell, offer to sell, import and otherwise + transfer the Contribution of such Contributor, if any, in source code and + object code form. This patent license shall apply to the combination of + the Contribution and the Program if, at the time the Contribution is + added by the Contributor, such addition of the Contribution causes such + combination to be covered by the Licensed Patents. The patent license + shall not apply to any other combinations which include the Contribution. + No hardware per se is licensed hereunder. + c) Recipient understands that although each Contributor grants the licenses + to its Contributions set forth herein, no assurances are provided by any + Contributor that the Program does not infringe the patent or other + intellectual property rights of any other entity. Each Contributor + disclaims any liability to Recipient for claims brought by any other + entity based on infringement of intellectual property rights or + otherwise. As a condition to exercising the rights and licenses granted + hereunder, each Recipient hereby assumes sole responsibility to secure + any other intellectual property rights needed, if any. For example, if a + third party patent license is required to allow Recipient to distribute + the Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + d) Each Contributor represents that to its knowledge it has sufficient + copyright rights in its Contribution, if any, to grant the copyright + license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under +its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + b) its license agreement: + i) effectively disclaims on behalf of all Contributors all warranties + and conditions, express and implied, including warranties or + conditions of title and non-infringement, and implied warranties or + conditions of merchantability and fitness for a particular purpose; + ii) effectively excludes on behalf of all Contributors all liability for + damages, including direct, indirect, special, incidental and + consequential damages, such as lost profits; + iii) states that any provisions which differ from this Agreement are + offered by that Contributor alone and not by any other party; and + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a reasonable + manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + b) a copy of this Agreement must be included with each copy of the Program. + Contributors may not remove or alter any copyright notices contained + within the Program. + +Each Contributor must identify itself as the originator of its Contribution, +if +any, in a manner that reasonably allows subsequent Recipients to identify the +originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with +respect to end users, business partners and the like. While this license is +intended to facilitate the commercial use of the Program, the Contributor who +includes the Program in a commercial product offering should do so in a manner +which does not create potential liability for other Contributors. Therefore, +if a Contributor includes the Program in a commercial product offering, such +Contributor ("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any losses, +damages and costs (collectively "Losses") arising from claims, lawsuits and +other legal actions brought by a third party against the Indemnified +Contributor to the extent caused by the acts or omissions of such Commercial +Contributor in connection with its distribution of the Program in a commercial +product offering. The obligations in this section do not apply to any claims +or Losses relating to any actual or alleged intellectual property +infringement. In order to qualify, an Indemnified Contributor must: +a) promptly notify the Commercial Contributor in writing of such claim, and +b) allow the Commercial Contributor to control, and cooperate with the +Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such claim at +its own expense. + +For example, a Contributor might include the Program in a commercial product +offering, Product X. That Contributor is then a Commercial Contributor. If +that Commercial Contributor then makes performance claims, or offers +warranties related to Product X, those performance claims and warranties are +such Commercial Contributor's responsibility alone. Under this section, the +Commercial Contributor would have to defend claims against the other +Contributors related to those performance claims and warranties, and if a +court requires any other Contributor to pay any damages as a result, the +Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, +NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each +Recipient is solely responsible for determining the appropriateness of using +and distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to the +risks and costs of program errors, compliance with applicable laws, damage to +or loss of data, programs or equipment, and unavailability or interruption of +operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY +CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION +LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE +EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of the +remainder of the terms of this Agreement, and without further action by the +parties hereto, such provision shall be reformed to the minimum extent +necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Program itself +(excluding combinations of the Program with other software or hardware) +infringes such Recipient's patent(s), then such Recipient's rights granted +under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient's rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient's obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue +and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in +order to avoid inconsistency the Agreement is copyrighted and may only be +modified in the following manner. The Agreement Steward reserves the right to +publish new versions (including revisions) of this Agreement from time to +time. No one other than the Agreement Steward has the right to modify this +Agreement. The Eclipse Foundation is the initial Agreement Steward. The +Eclipse Foundation may assign the responsibility to serve as the Agreement +Steward to a suitable separate entity. Each new version of the Agreement will +be given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version of the +Agreement is published, Contributor may elect to distribute the Program +(including its Contributions) under the new version. Except as expressly +stated in Sections 2(a) and 2(b) above, Recipient receives no rights or +licenses to the intellectual property of any Contributor under this Agreement, +whether expressly, by implication, estoppel or otherwise. All rights in the +Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the +intellectual property laws of the United States of America. No party to this +Agreement will bring a legal action under this Agreement more than one year +after the cause of action arose. Each party waives its rights to a jury trial in +any resulting litigation. \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/MANIFEST.in b/adapter/python/ptvsd/_vendored/pydevd/MANIFEST.in new file mode 100644 index 0000000..3f33e4e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/MANIFEST.in @@ -0,0 +1,8 @@ +include *.rst *.txt *.md LICENSE .travis.yml appveyor.yml *.pyx *.cpp *.hpp +recursive-include pydevd_attach_to_process *.py *.dll *.so *.dylib *.txt *.c *.h *.bat Makefile *.sh *.pyx *.cpp *.hpp +recursive-include pydevd_attach_to_process/common *.py *.dll *.so *.dylib *.txt *.c *.h *.bat Makefile *.sh *.pyx *.cpp *.hpp +recursive-include pydevd_attach_to_process/linux_and_mac *.py *.dll *.so *.dylib *.txt *.c *.h *.bat Makefile *.sh *.pyx *.cpp *.hpp +recursive-include pydevd_attach_to_process/winappdbg *.py *.dll *.so *.dylib *.txt *.c *.h *.bat Makefile *.sh *.pyx *.cpp *.hpp +recursive-include pydevd_attach_to_process/windows *.py *.dll *.so *.dylib *.txt *.c *.h *.bat Makefile *.sh *.pyx *.cpp *.hpp +recursive-include _pydevd_bundle *.pyx *.cpp *.hpp +recursive-include build_tools *.py \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/README.rst b/adapter/python/ptvsd/_vendored/pydevd/README.rst new file mode 100644 index 0000000..daf8185 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/README.rst @@ -0,0 +1,43 @@ +PyDev.Debugger +============== + +The sources for the PyDev.Debugger (used in PyDev & PyCharm) may be seen at: + +https://github.com/fabioz/PyDev.Debugger + +In general, the debugger backend should **NOT** be installed separately if you're using an IDE which already +bundles it (such as PyDev or PyCharm). + +It is however available in PyPi so that it can be installed for doing remote debugging with `pip` -- so, when +debugging a process which runs in another machine, it's possible to `pip install pydevd` and in the code use +`pydevd.settrace(host='10.1.1.1')` to connect the debugger backend to the debugger UI running in the IDE +(whereas previously the sources had to be manually copied from the IDE installation). + +It should be compatible with Python 2.6 onwards (as well as Jython 2.7, IronPython and PyPy -- and +any other variant which properly supports the Python structure for debuggers -- i.e.: sys.settrace/threading.settrace). + +Recent versions contain speedup modules using Cython, which are generated with a few changes in the regular files +to `cythonize` the files. To update and compile the cython sources (and generate some other auto-generated files), +`build_tools/build.py` should be run -- note that the resulting .pyx and .c files should be commited. + +To generate a distribution with the precompiled binaries for the IDE, `build_binaries_windows.py` should be run ( +note that the environments must be pre-created as specified in that file). + +To generate a distribution to upload to PyPi, `python setup.py sdist bdist_wheel` should be run for each python version +which should have a wheel and afterwards `twine upload -s dist/pydevd-*` should be run to actually upload the contents +to PyPi. + +Travis (Linux CI): + +.. |travis| image:: https://travis-ci.org/fabioz/PyDev.Debugger.png + :target: https://travis-ci.org/fabioz/PyDev.Debugger + +|travis| + +Appveyor (Windows CI): + +.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/j6vjq687brbk20ux?svg=true + :target: https://ci.appveyor.com/project/fabioz/pydev-debugger + +|appveyor| + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_calltip_util.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_calltip_util.py new file mode 100644 index 0000000..b846fb4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_calltip_util.py @@ -0,0 +1,158 @@ +''' +License: Apache 2.0 +Author: Yuli Fitterman +''' +# noinspection PyBroadException +import types + +from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_PY3K + +try: + import inspect +except: + try: + from _pydev_imps import _pydev_inspect as inspect + except: + import traceback; + + traceback.print_exc() # Ok, no inspect available (search will not work)from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_PY3K + +from _pydev_bundle._pydev_imports_tipper import signature_from_docstring + + +def is_bound_method(obj): + if isinstance(obj, types.MethodType): + return getattr(obj, '__self__', getattr(obj, 'im_self', None)) is not None + else: + return False + + +def get_class_name(instance): + return getattr(getattr(instance, "__class__", None), "__name__", None) + + +def get_bound_class_name(obj): + my_self = getattr(obj, '__self__', getattr(obj, 'im_self', None)) + if my_self is None: + return None + return get_class_name(my_self) + + +def get_description(obj): + try: + ob_call = obj.__call__ + except: + ob_call = None + + if isinstance(obj, type) or type(obj).__name__ == 'classobj': + fob = getattr(obj, '__init__', lambda: None) + if not isinstance(fob, (types.FunctionType, types.MethodType)): + fob = obj + elif is_bound_method(ob_call): + fob = ob_call + else: + fob = obj + + argspec = "" + fn_name = None + fn_class = None + if isinstance(fob, (types.FunctionType, types.MethodType)): + spec_info = inspect.getfullargspec(fob) if IS_PY3K else inspect.getargspec(fob) + argspec = inspect.formatargspec(*spec_info) + fn_name = getattr(fob, '__name__', None) + if isinstance(obj, type) or type(obj).__name__ == 'classobj': + fn_name = "__init__" + fn_class = getattr(obj, "__name__", "UnknownClass") + elif is_bound_method(obj) or is_bound_method(ob_call): + fn_class = get_bound_class_name(obj) or "UnknownClass" + + else: + fn_name = getattr(fob, '__name__', None) + fn_self = getattr(fob, '__self__', None) + if fn_self is not None and not isinstance(fn_self, types.ModuleType): + fn_class = get_class_name(fn_self) + + doc_string = get_docstring(ob_call) if is_bound_method(ob_call) else get_docstring(obj) + return create_method_stub(fn_name, fn_class, argspec, doc_string) + + +def create_method_stub(fn_name, fn_class, argspec, doc_string): + if fn_name and argspec: + doc_string = "" if doc_string is None else doc_string + fn_stub = create_function_stub(fn_name, argspec, doc_string, indent=1 if fn_class else 0) + if fn_class: + expr = fn_class if fn_name == '__init__' else fn_class + '().' + fn_name + return create_class_stub(fn_class, fn_stub) + "\n" + expr + else: + expr = fn_name + return fn_stub + "\n" + expr + elif doc_string: + if fn_name: + restored_signature, _ = signature_from_docstring(doc_string, fn_name) + if restored_signature: + return create_method_stub(fn_name, fn_class, restored_signature, doc_string) + return create_function_stub('unknown', '(*args, **kwargs)', doc_string) + '\nunknown' + + else: + return '' + + +def get_docstring(obj): + if obj is not None: + try: + if IS_JYTHON: + # Jython + doc = obj.__doc__ + if doc is not None: + return doc + + from _pydev_bundle import _pydev_jy_imports_tipper + + is_method, infos = _pydev_jy_imports_tipper.ismethod(obj) + ret = '' + if is_method: + for info in infos: + ret += info.get_as_doc() + return ret + + else: + + doc = inspect.getdoc(obj) + if doc is not None: + return doc + except: + pass + else: + return '' + try: + # if no attempt succeeded, try to return repr()... + return repr(obj) + except: + try: + # otherwise the class + return str(obj.__class__) + except: + # if all fails, go to an empty string + return '' + + +def create_class_stub(class_name, contents): + return "class %s(object):\n%s" % (class_name, contents) + + +def create_function_stub(fn_name, fn_argspec, fn_docstring, indent=0): + def shift_right(string, prefix): + return ''.join(prefix + line for line in string.splitlines(True)) + + fn_docstring = shift_right(inspect.cleandoc(fn_docstring), " " * (indent + 1)) + ret = ''' +def %s%s: + """%s""" + pass +''' % (fn_name, fn_argspec, fn_docstring) + ret = ret[1:] # remove first /n + ret = ret.replace('\t', " ") + if indent: + prefix = " " * indent + ret = shift_right(ret, prefix) + return ret diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_completer.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_completer.py new file mode 100644 index 0000000..1765d51 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_completer.py @@ -0,0 +1,291 @@ +from collections import namedtuple +from string import ascii_letters, digits + +from _pydevd_bundle import pydevd_xml +from _pydevd_bundle.pydevd_constants import IS_PY2 +import pydevconsole + +if IS_PY2: + import __builtin__ +else: + import builtins as __builtin__ # Py3 + +try: + import java.lang # @UnusedImport + from _pydev_bundle import _pydev_jy_imports_tipper + _pydev_imports_tipper = _pydev_jy_imports_tipper +except ImportError: + IS_JYTHON = False + from _pydev_bundle import _pydev_imports_tipper + +dir2 = _pydev_imports_tipper.generate_imports_tip_for_module + + +#======================================================================================================================= +# _StartsWithFilter +#======================================================================================================================= +class _StartsWithFilter: + ''' + Used because we can't create a lambda that'll use an outer scope in jython 2.1 + ''' + + def __init__(self, start_with): + self.start_with = start_with.lower() + + def __call__(self, name): + return name.lower().startswith(self.start_with) + + +#======================================================================================================================= +# Completer +# +# This class was gotten from IPython.completer (dir2 was replaced with the completer already in pydev) +#======================================================================================================================= +class Completer: + + def __init__(self, namespace=None, global_namespace=None): + """Create a new completer for the command line. + + Completer([namespace,global_namespace]) -> completer instance. + + If unspecified, the default namespace where completions are performed + is __main__ (technically, __main__.__dict__). Namespaces should be + given as dictionaries. + + An optional second namespace can be given. This allows the completer + to handle cases where both the local and global scopes need to be + distinguished. + + Completer instances should be used as the completion mechanism of + readline via the set_completer() call: + + readline.set_completer(Completer(my_namespace).complete) + """ + + # Don't bind to namespace quite yet, but flag whether the user wants a + # specific namespace or to use __main__.__dict__. This will allow us + # to bind to __main__.__dict__ at completion time, not now. + if namespace is None: + self.use_main_ns = 1 + else: + self.use_main_ns = 0 + self.namespace = namespace + + # The global namespace, if given, can be bound directly + if global_namespace is None: + self.global_namespace = {} + else: + self.global_namespace = global_namespace + + def complete(self, text): + """Return the next possible completion for 'text'. + + This is called successively with state == 0, 1, 2, ... until it + returns None. The completion should begin with 'text'. + + """ + if self.use_main_ns: + # In pydev this option should never be used + raise RuntimeError('Namespace must be provided!') + self.namespace = __main__.__dict__ # @UndefinedVariable + + if "." in text: + return self.attr_matches(text) + else: + return self.global_matches(text) + + def global_matches(self, text): + """Compute matches when text is a simple name. + + Return a list of all keywords, built-in functions and names currently + defined in self.namespace or self.global_namespace that match. + + """ + + def get_item(obj, attr): + return obj[attr] + + a = {} + + for dict_with_comps in [__builtin__.__dict__, self.namespace, self.global_namespace]: # @UndefinedVariable + a.update(dict_with_comps) + + filter = _StartsWithFilter(text) + + return dir2(a, a.keys(), get_item, filter) + + def attr_matches(self, text): + """Compute matches when text contains a dot. + + Assuming the text is of the form NAME.NAME....[NAME], and is + evaluatable in self.namespace or self.global_namespace, it will be + evaluated and its attributes (as revealed by dir()) are used as + possible completions. (For class instances, class members are are + also considered.) + + WARNING: this can still invoke arbitrary C code, if an object + with a __getattr__ hook is evaluated. + + """ + import re + + # Another option, seems to work great. Catches things like ''. + m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) # @UndefinedVariable + + if not m: + return [] + + expr, attr = m.group(1, 3) + try: + obj = eval(expr, self.namespace) + except: + try: + obj = eval(expr, self.global_namespace) + except: + return [] + + filter = _StartsWithFilter(attr) + + words = dir2(obj, filter=filter) + + return words + + +def generate_completions(frame, act_tok): + ''' + :return list(tuple(method_name, docstring, parameters, completion_type)) + + method_name: str + docstring: str + parameters: str -- i.e.: "(a, b)" + completion_type is an int + See: _pydev_bundle._pydev_imports_tipper for TYPE_ constants + ''' + if frame is None: + return [] + + # Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 + # (Names not resolved in generator expression in method) + # See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html + updated_globals = {} + updated_globals.update(frame.f_globals) + updated_globals.update(frame.f_locals) # locals later because it has precedence over the actual globals + + if pydevconsole.IPYTHON: + completions = pydevconsole.get_completions(act_tok, act_tok, updated_globals, frame.f_locals) + else: + completer = Completer(updated_globals, None) + # list(tuple(name, descr, parameters, type)) + completions = completer.complete(act_tok) + + return completions + + +def generate_completions_as_xml(frame, act_tok): + completions = generate_completions(frame, act_tok) + return completions_to_xml(completions) + + +def completions_to_xml(completions): + valid_xml = pydevd_xml.make_valid_xml_value + quote = pydevd_xml.quote + msg = [""] + + for comp in completions: + if IS_PY2: + comp = [(x.encode('utf-8') if x.__class__ == unicode else x) for x in comp] + msg.append('') + msg.append("") + + return ''.join(msg) + + +identifier_start = ascii_letters + '_' +identifier_part = ascii_letters + '_' + digits + +if IS_PY2: + identifier_start = identifier_start.decode('utf-8') + identifier_part = identifier_part.decode('utf-8') + +identifier_start = set(identifier_start) +identifier_part = set(identifier_part) + +if IS_PY2: + + # There's no string.isidentifier() on py2. + def isidentifier(s): + if not s: + return False + if s[0] not in identifier_start: + return False + + for c in s[1:]: + if c not in identifier_part: + return False + return True + +else: + + def isidentifier(s): + return s.isidentifier() + +TokenAndQualifier = namedtuple('TokenAndQualifier', 'token, qualifier') + + +def extract_token_and_qualifier(text, line=0, column=0): + ''' + Extracts the token a qualifier from the text given the line/colum + (see test_extract_token_and_qualifier for examples). + + :param unicode text: + :param int line: 0-based + :param int column: 0-based + ''' + # Note: not using the tokenize module because text should be unicode and + # line/column refer to the unicode text (otherwise we'd have to know + # those ranges after converted to bytes). + if line < 0: + line = 0 + if column < 0: + column = 0 + + if isinstance(text, bytes): + text = text.decode('utf-8') + + lines = text.splitlines() + try: + text = lines[line] + except IndexError: + return TokenAndQualifier(u'', u'') + + if column >= len(text): + column = len(text) + + text = text[:column] + token = u'' + qualifier = u'' + + temp_token = [] + for i in range(column - 1, -1, -1): + c = text[i] + if c in identifier_part or isidentifier(c) or c == u'.': + temp_token.append(c) + else: + break + temp_token = u''.join(reversed(temp_token)) + if u'.' in temp_token: + temp_token = temp_token.split(u'.') + token = u'.'.join(temp_token[:-1]) + qualifier = temp_token[-1] + else: + qualifier = temp_token + + return TokenAndQualifier(token, qualifier) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_filesystem_encoding.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_filesystem_encoding.py new file mode 100644 index 0000000..6264e3d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_filesystem_encoding.py @@ -0,0 +1,41 @@ +import sys + + +def __getfilesystemencoding(): + ''' + Note: there's a copy of this method in interpreterInfo.py + ''' + try: + ret = sys.getfilesystemencoding() + if not ret: + raise RuntimeError('Unable to get encoding.') + return ret + except: + try: + #Handle Jython + from java.lang import System # @UnresolvedImport + env = System.getProperty("os.name").lower() + if env.find('win') != -1: + return 'ISO-8859-1' #mbcs does not work on Jython, so, use a (hopefully) suitable replacement + return 'utf-8' + except: + pass + + #Only available from 2.3 onwards. + if sys.platform == 'win32': + return 'mbcs' + return 'utf-8' + +def getfilesystemencoding(): + try: + ret = __getfilesystemencoding() + + #Check if the encoding is actually there to be used! + if hasattr('', 'encode'): + ''.encode(ret) + if hasattr('', 'decode'): + ''.decode(ret) + + return ret + except: + return 'utf-8' diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_getopt.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_getopt.py new file mode 100644 index 0000000..5548651 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_getopt.py @@ -0,0 +1,130 @@ + +#======================================================================================================================= +# getopt code copied since gnu_getopt is not available on jython 2.1 +#======================================================================================================================= +class GetoptError(Exception): + opt = '' + msg = '' + def __init__(self, msg, opt=''): + self.msg = msg + self.opt = opt + Exception.__init__(self, msg, opt) + + def __str__(self): + return self.msg + + +def gnu_getopt(args, shortopts, longopts=[]): + """getopt(args, options[, long_options]) -> opts, args + + This function works like getopt(), except that GNU style scanning + mode is used by default. This means that option and non-option + arguments may be intermixed. The getopt() function stops + processing options as soon as a non-option argument is + encountered. + + If the first character of the option string is `+', or if the + environment variable POSIXLY_CORRECT is set, then option + processing stops as soon as a non-option argument is encountered. + """ + + opts = [] + prog_args = [] + if type('') == type(longopts): + longopts = [longopts] + else: + longopts = list(longopts) + + # Allow options after non-option arguments? + all_options_first = False + if shortopts.startswith('+'): + shortopts = shortopts[1:] + all_options_first = True + + while args: + if args[0] == '--': + prog_args += args[1:] + break + + if args[0][:2] == '--': + opts, args = do_longs(opts, args[0][2:], longopts, args[1:]) + elif args[0][:1] == '-': + opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:]) + else: + if all_options_first: + prog_args += args + break + else: + prog_args.append(args[0]) + args = args[1:] + + return opts, prog_args + +def do_longs(opts, opt, longopts, args): + try: + i = opt.index('=') + except ValueError: + optarg = None + else: + opt, optarg = opt[:i], opt[i + 1:] + + has_arg, opt = long_has_args(opt, longopts) + if has_arg: + if optarg is None: + if not args: + raise GetoptError('option --%s requires argument' % opt, opt) + optarg, args = args[0], args[1:] + elif optarg: + raise GetoptError('option --%s must not have an argument' % opt, opt) + opts.append(('--' + opt, optarg or '')) + return opts, args + +# Return: +# has_arg? +# full option name +def long_has_args(opt, longopts): + possibilities = [o for o in longopts if o.startswith(opt)] + if not possibilities: + raise GetoptError('option --%s not recognized' % opt, opt) + # Is there an exact match? + if opt in possibilities: + return False, opt + elif opt + '=' in possibilities: + return True, opt + # No exact match, so better be unique. + if len(possibilities) > 1: + # XXX since possibilities contains all valid continuations, might be + # nice to work them into the error msg + raise GetoptError('option --%s not a unique prefix' % opt, opt) + assert len(possibilities) == 1 + unique_match = possibilities[0] + has_arg = unique_match.endswith('=') + if has_arg: + unique_match = unique_match[:-1] + return has_arg, unique_match + +def do_shorts(opts, optstring, shortopts, args): + while optstring != '': + opt, optstring = optstring[0], optstring[1:] + if short_has_arg(opt, shortopts): + if optstring == '': + if not args: + raise GetoptError('option -%s requires argument' % opt, + opt) + optstring, args = args[0], args[1:] + optarg, optstring = optstring, '' + else: + optarg = '' + opts.append(('-' + opt, optarg)) + return opts, args + +def short_has_arg(opt, shortopts): + for i in range(len(shortopts)): + if opt == shortopts[i] != ':': + return shortopts.startswith(':', i + 1) + raise GetoptError('option -%s not recognized' % opt, opt) + + +#======================================================================================================================= +# End getopt code +#======================================================================================================================= diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_imports_tipper.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_imports_tipper.py new file mode 100644 index 0000000..af05b40 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_imports_tipper.py @@ -0,0 +1,372 @@ +import inspect +import os.path +import sys + +from _pydev_bundle._pydev_tipper_common import do_find +from _pydevd_bundle.pydevd_constants import IS_PY2 + +if IS_PY2: + from inspect import getargspec as _originalgetargspec + def getargspec(*args, **kwargs): + ret = list(_originalgetargspec(*args, **kwargs)) + ret.append([]) + ret.append({}) + return ret + +else: + from inspect import getfullargspec + + def getargspec(*args, **kwargs): + arg_spec = getfullargspec(*args, **kwargs) + return arg_spec.args, arg_spec.varargs, arg_spec.varkw, arg_spec.defaults, arg_spec.kwonlyargs or [], arg_spec.kwonlydefaults or {} + +try: + xrange +except: + xrange = range + +#completion types. +TYPE_IMPORT = '0' +TYPE_CLASS = '1' +TYPE_FUNCTION = '2' +TYPE_ATTR = '3' +TYPE_BUILTIN = '4' +TYPE_PARAM = '5' + +def _imp(name, log=None): + try: + return __import__(name) + except: + if '.' in name: + sub = name[0:name.rfind('.')] + + if log is not None: + log.add_content('Unable to import', name, 'trying with', sub) + log.add_exception() + + return _imp(sub, log) + else: + s = 'Unable to import module: %s - sys.path: %s' % (str(name), sys.path) + if log is not None: + log.add_content(s) + log.add_exception() + + raise ImportError(s) + + +IS_IPY = False +if sys.platform == 'cli': + IS_IPY = True + _old_imp = _imp + def _imp(name, log=None): + #We must add a reference in clr for .Net + import clr #@UnresolvedImport + initial_name = name + while '.' in name: + try: + clr.AddReference(name) + break #If it worked, that's OK. + except: + name = name[0:name.rfind('.')] + else: + try: + clr.AddReference(name) + except: + pass #That's OK (not dot net module). + + return _old_imp(initial_name, log) + + + +def get_file(mod): + f = None + try: + f = inspect.getsourcefile(mod) or inspect.getfile(mod) + except: + if hasattr(mod, '__file__'): + f = mod.__file__ + if f.lower(f[-4:]) in ['.pyc', '.pyo']: + filename = f[:-4] + '.py' + if os.path.exists(filename): + f = filename + + return f + +def Find(name, log=None): + f = None + + mod = _imp(name, log) + parent = mod + foundAs = '' + + if inspect.ismodule(mod): + f = get_file(mod) + + components = name.split('.') + + old_comp = None + for comp in components[1:]: + try: + #this happens in the following case: + #we have mx.DateTime.mxDateTime.mxDateTime.pyd + #but after importing it, mx.DateTime.mxDateTime shadows access to mxDateTime.pyd + mod = getattr(mod, comp) + except AttributeError: + if old_comp != comp: + raise + + if inspect.ismodule(mod): + f = get_file(mod) + else: + if len(foundAs) > 0: + foundAs = foundAs + '.' + foundAs = foundAs + comp + + old_comp = comp + + return f, mod, parent, foundAs + +def search_definition(data): + '''@return file, line, col + ''' + + data = data.replace('\n', '') + if data.endswith('.'): + data = data.rstrip('.') + f, mod, parent, foundAs = Find(data) + try: + return do_find(f, mod), foundAs + except: + return do_find(f, parent), foundAs + + +def generate_tip(data, log=None): + data = data.replace('\n', '') + if data.endswith('.'): + data = data.rstrip('.') + + f, mod, parent, foundAs = Find(data, log) + #print_ >> open('temp.txt', 'w'), f + tips = generate_imports_tip_for_module(mod) + return f, tips + + +def check_char(c): + if c == '-' or c == '.': + return '_' + return c + +_SENTINEL = object() + +def generate_imports_tip_for_module(obj_to_complete, dir_comps=None, getattr=getattr, filter=lambda name:True): + ''' + @param obj_to_complete: the object from where we should get the completions + @param dir_comps: if passed, we should not 'dir' the object and should just iterate those passed as kwonly_arg parameter + @param getattr: the way to get kwonly_arg given object from the obj_to_complete (used for the completer) + @param filter: kwonly_arg callable that receives the name and decides if it should be appended or not to the results + @return: list of tuples, so that each tuple represents kwonly_arg completion with: + name, doc, args, type (from the TYPE_* constants) + ''' + ret = [] + + if dir_comps is None: + dir_comps = dir(obj_to_complete) + if hasattr(obj_to_complete, '__dict__'): + dir_comps.append('__dict__') + if hasattr(obj_to_complete, '__class__'): + dir_comps.append('__class__') + + get_complete_info = True + + if len(dir_comps) > 1000: + #ok, we don't want to let our users wait forever... + #no complete info for you... + + get_complete_info = False + + dontGetDocsOn = (float, int, str, tuple, list) + for d in dir_comps: + + if d is None: + continue + + if not filter(d): + continue + + args = '' + + try: + try: + obj = getattr(obj_to_complete.__class__, d) + except: + obj = getattr(obj_to_complete, d) + except: #just ignore and get it without additional info + ret.append((d, '', args, TYPE_BUILTIN)) + else: + + if get_complete_info: + try: + retType = TYPE_BUILTIN + + #check if we have to get docs + getDoc = True + for class_ in dontGetDocsOn: + + if isinstance(obj, class_): + getDoc = False + break + + doc = '' + if getDoc: + #no need to get this info... too many constants are defined and + #makes things much slower (passing all that through sockets takes quite some time) + try: + doc = inspect.getdoc(obj) + if doc is None: + doc = '' + except: #may happen on jython when checking java classes (so, just ignore it) + doc = '' + + + if inspect.ismethod(obj) or inspect.isbuiltin(obj) or inspect.isfunction(obj) or inspect.isroutine(obj): + try: + args, vargs, kwargs, defaults, kwonly_args, kwonly_defaults = getargspec(obj) + + args = args[:] + + for kwonly_arg in kwonly_args: + default = kwonly_defaults.get(kwonly_arg, _SENTINEL) + if default is not _SENTINEL: + args.append('%s=%s' % (kwonly_arg, default)) + else: + args.append(str(kwonly_arg)) + + args = '(%s)' % (', '.join(args)) + except TypeError: + #ok, let's see if we can get the arguments from the doc + args, doc = signature_from_docstring(doc, getattr(obj, '__name__', None)) + + retType = TYPE_FUNCTION + + elif inspect.isclass(obj): + retType = TYPE_CLASS + + elif inspect.ismodule(obj): + retType = TYPE_IMPORT + + else: + retType = TYPE_ATTR + + + #add token and doc to return - assure only strings. + ret.append((d, doc, args, retType)) + + except: #just ignore and get it without aditional info + ret.append((d, '', args, TYPE_BUILTIN)) + + else: #get_complete_info == False + if inspect.ismethod(obj) or inspect.isbuiltin(obj) or inspect.isfunction(obj) or inspect.isroutine(obj): + retType = TYPE_FUNCTION + + elif inspect.isclass(obj): + retType = TYPE_CLASS + + elif inspect.ismodule(obj): + retType = TYPE_IMPORT + + else: + retType = TYPE_ATTR + #ok, no complete info, let's try to do this as fast and clean as possible + #so, no docs for this kind of information, only the signatures + ret.append((d, '', str(args), retType)) + + return ret + + +def signature_from_docstring(doc, obj_name): + args = '()' + try: + found = False + if len(doc) > 0: + if IS_IPY: + # Handle case where we have the situation below + # sort(self, object cmp, object key) + # sort(self, object cmp, object key, bool reverse) + # sort(self) + # sort(self, object cmp) + + # Or: sort(self: list, cmp: object, key: object) + # sort(self: list, cmp: object, key: object, reverse: bool) + # sort(self: list) + # sort(self: list, cmp: object) + if obj_name: + name = obj_name + '(' + + # Fix issue where it was appearing sort(aa)sort(bb)sort(cc) in the same line. + lines = doc.splitlines() + if len(lines) == 1: + c = doc.count(name) + if c > 1: + doc = ('\n' + name).join(doc.split(name)) + + major = '' + for line in doc.splitlines(): + if line.startswith(name) and line.endswith(')'): + if len(line) > len(major): + major = line + if major: + args = major[major.index('('):] + found = True + + if not found: + i = doc.find('->') + if i < 0: + i = doc.find('--') + if i < 0: + i = doc.find('\n') + if i < 0: + i = doc.find('\r') + + if i > 0: + s = doc[0:i] + s = s.strip() + + # let's see if we have a docstring in the first line + if s[-1] == ')': + start = s.find('(') + if start >= 0: + end = s.find('[') + if end <= 0: + end = s.find(')') + if end <= 0: + end = len(s) + + args = s[start:end] + if not args[-1] == ')': + args = args + ')' + + # now, get rid of unwanted chars + l = len(args) - 1 + r = [] + for i in xrange(len(args)): + if i == 0 or i == l: + r.append(args[i]) + else: + r.append(check_char(args[i])) + + args = ''.join(r) + + if IS_IPY: + if args.startswith('(self:'): + i = args.find(',') + if i >= 0: + args = '(self' + args[i:] + else: + args = '(self)' + i = args.find(')') + if i > 0: + args = args[:i + 1] + + except: + pass + return args, doc diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_jy_imports_tipper.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_jy_imports_tipper.py new file mode 100644 index 0000000..28d5f6b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_jy_imports_tipper.py @@ -0,0 +1,504 @@ +try: + import StringIO +except: + import io as StringIO + +import traceback +from java.lang import StringBuffer #@UnresolvedImport +from java.lang import String #@UnresolvedImport +import java.lang #@UnresolvedImport +import sys +from _pydev_bundle._pydev_tipper_common import do_find + + +from org.python.core import PyReflectedFunction #@UnresolvedImport + +from org.python import core #@UnresolvedImport +from org.python.core import PyClass #@UnresolvedImport + +try: + xrange +except: + xrange = range + + +#completion types. +TYPE_IMPORT = '0' +TYPE_CLASS = '1' +TYPE_FUNCTION = '2' +TYPE_ATTR = '3' +TYPE_BUILTIN = '4' +TYPE_PARAM = '5' + +def _imp(name): + try: + return __import__(name) + except: + if '.' in name: + sub = name[0:name.rfind('.')] + return _imp(sub) + else: + s = 'Unable to import module: %s - sys.path: %s' % (str(name), sys.path) + raise RuntimeError(s) + +import java.util +_java_rt_file = getattr(java.util, '__file__', None) + +def Find(name): + f = None + if name.startswith('__builtin__'): + if name == '__builtin__.str': + name = 'org.python.core.PyString' + elif name == '__builtin__.dict': + name = 'org.python.core.PyDictionary' + + mod = _imp(name) + parent = mod + foundAs = '' + + if hasattr(mod, '__file__'): + f = mod.__file__ + + + components = name.split('.') + old_comp = None + for comp in components[1:]: + try: + #this happens in the following case: + #we have mx.DateTime.mxDateTime.mxDateTime.pyd + #but after importing it, mx.DateTime.mxDateTime does shadows access to mxDateTime.pyd + mod = getattr(mod, comp) + except AttributeError: + if old_comp != comp: + raise + + if hasattr(mod, '__file__'): + f = mod.__file__ + else: + if len(foundAs) > 0: + foundAs = foundAs + '.' + foundAs = foundAs + comp + + old_comp = comp + + if f is None and name.startswith('java.lang'): + # Hack: java.lang.__file__ is None on Jython 2.7 (whereas it pointed to rt.jar on Jython 2.5). + f = _java_rt_file + + if f is not None: + if f.endswith('.pyc'): + f = f[:-1] + elif f.endswith('$py.class'): + f = f[:-len('$py.class')] + '.py' + return f, mod, parent, foundAs + +def format_param_class_name(paramClassName): + if paramClassName.startswith(''): + paramClassName = paramClassName[len(' + paramClassName = paramClassName.split('\'')[1] + except: + paramClassName = repr(paramTypesClass) #just in case something else happens... it will at least be visible + #if the parameter equals [C, it means it it a char array, so, let's change it + + a = format_param_class_name(paramClassName) + #a = a.replace('[]','Array') + #a = a.replace('Object', 'obj') + #a = a.replace('String', 's') + #a = a.replace('Integer', 'i') + #a = a.replace('Char', 'c') + #a = a.replace('Double', 'd') + args.append(a) #so we don't leave invalid code + + + info = Info(name, args=args, ret=ret) + #print_ info.basic_as_str() + infos.append(info) + + return 1, infos + except Exception: + s = StringIO.StringIO() + traceback.print_exc(file=s) + return 1, [Info(str('ERROR'), doc=s.getvalue())] + + return 0, None + +def ismodule(mod): + #java modules... do we have other way to know that? + if not hasattr(mod, 'getClass') and not hasattr(mod, '__class__') \ + and hasattr(mod, '__name__'): + return 1 + + return isinstance(mod, core.PyModule) + + +def dir_obj(obj): + ret = [] + found = java.util.HashMap() + original = obj + if hasattr(obj, '__class__'): + if obj.__class__ == java.lang.Class: + + #get info about superclasses + classes = [] + classes.append(obj) + try: + c = obj.getSuperclass() + except TypeError: + #may happen on jython when getting the java.lang.Class class + c = obj.getSuperclass(obj) + + while c != None: + classes.append(c) + c = c.getSuperclass() + + #get info about interfaces + interfs = [] + for obj in classes: + try: + interfs.extend(obj.getInterfaces()) + except TypeError: + interfs.extend(obj.getInterfaces(obj)) + classes.extend(interfs) + + #now is the time when we actually get info on the declared methods and fields + for obj in classes: + try: + declaredMethods = obj.getDeclaredMethods() + except TypeError: + declaredMethods = obj.getDeclaredMethods(obj) + + try: + declaredFields = obj.getDeclaredFields() + except TypeError: + declaredFields = obj.getDeclaredFields(obj) + + for i in xrange(len(declaredMethods)): + name = declaredMethods[i].getName() + ret.append(name) + found.put(name, 1) + + for i in xrange(len(declaredFields)): + name = declaredFields[i].getName() + ret.append(name) + found.put(name, 1) + + + elif isclass(obj.__class__): + d = dir(obj.__class__) + for name in d: + ret.append(name) + found.put(name, 1) + + + #this simple dir does not always get all the info, that's why we have the part before + #(e.g.: if we do a dir on String, some methods that are from other interfaces such as + #charAt don't appear) + d = dir(original) + for name in d: + if found.get(name) != 1: + ret.append(name) + + return ret + + +def format_arg(arg): + '''formats an argument to be shown + ''' + + s = str(arg) + dot = s.rfind('.') + if dot >= 0: + s = s[dot + 1:] + + s = s.replace(';', '') + s = s.replace('[]', 'Array') + if len(s) > 0: + c = s[0].lower() + s = c + s[1:] + + return s + + + +def search_definition(data): + '''@return file, line, col + ''' + + data = data.replace('\n', '') + if data.endswith('.'): + data = data.rstrip('.') + f, mod, parent, foundAs = Find(data) + try: + return do_find(f, mod), foundAs + except: + return do_find(f, parent), foundAs + + +def generate_imports_tip_for_module(obj_to_complete, dir_comps=None, getattr=getattr, filter=lambda name:True): + ''' + @param obj_to_complete: the object from where we should get the completions + @param dir_comps: if passed, we should not 'dir' the object and should just iterate those passed as a parameter + @param getattr: the way to get a given object from the obj_to_complete (used for the completer) + @param filter: a callable that receives the name and decides if it should be appended or not to the results + @return: list of tuples, so that each tuple represents a completion with: + name, doc, args, type (from the TYPE_* constants) + ''' + ret = [] + + if dir_comps is None: + dir_comps = dir_obj(obj_to_complete) + + for d in dir_comps: + + if d is None: + continue + + if not filter(d): + continue + + args = '' + doc = '' + retType = TYPE_BUILTIN + + try: + obj = getattr(obj_to_complete, d) + except (AttributeError, java.lang.NoClassDefFoundError): + #jython has a bug in its custom classloader that prevents some things from working correctly, so, let's see if + #we can fix that... (maybe fixing it in jython itself would be a better idea, as this is clearly a bug) + #for that we need a custom classloader... we have references from it in the below places: + # + #http://mindprod.com/jgloss/classloader.html + #http://www.javaworld.com/javaworld/jw-03-2000/jw-03-classload-p2.html + #http://freshmeat.net/articles/view/1643/ + # + #note: this only happens when we add things to the sys.path at runtime, if they are added to the classpath + #before the run, everything goes fine. + # + #The code below ilustrates what I mean... + # + #import sys + #sys.path.insert(1, r"C:\bin\eclipse310\plugins\org.junit_3.8.1\junit.jar" ) + # + #import junit.framework + #print_ dir(junit.framework) #shows the TestCase class here + # + #import junit.framework.TestCase + # + #raises the error: + #Traceback (innermost last): + # File "", line 1, in ? + #ImportError: No module named TestCase + # + #whereas if we had added the jar to the classpath before, everything would be fine by now... + + ret.append((d, '', '', retType)) + #that's ok, private things cannot be gotten... + continue + else: + + isMet = ismethod(obj) + if isMet[0] and isMet[1]: + info = isMet[1][0] + try: + args, vargs, kwargs = info.args, info.varargs, info.kwargs + doc = info.get_as_doc() + r = '' + for a in (args): + if len(r) > 0: + r += ', ' + r += format_arg(a) + args = '(%s)' % (r) + except TypeError: + traceback.print_exc() + args = '()' + + retType = TYPE_FUNCTION + + elif isclass(obj): + retType = TYPE_CLASS + + elif ismodule(obj): + retType = TYPE_IMPORT + + #add token and doc to return - assure only strings. + ret.append((d, doc, args, retType)) + + + return ret + + +if __name__ == "__main__": + sys.path.append(r'D:\dev_programs\eclipse_3\310\eclipse\plugins\org.junit_3.8.1\junit.jar') + sys.stdout.write('%s\n' % Find('junit.framework.TestCase')) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_log.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_log.py new file mode 100644 index 0000000..853348b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_log.py @@ -0,0 +1,28 @@ +import traceback +import sys +try: + import StringIO +except: + import io as StringIO #Python 3.0 + + +class Log: + + def __init__(self): + self._contents = [] + + def add_content(self, *content): + self._contents.append(' '.join(content)) + + def add_exception(self): + s = StringIO.StringIO() + exc_info = sys.exc_info() + traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) + self._contents.append(s.getvalue()) + + + def get_contents(self): + return '\n'.join(self._contents) + + def clear_log(self): + del self._contents[:] \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_tipper_common.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_tipper_common.py new file mode 100644 index 0000000..79ce498 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/_pydev_tipper_common.py @@ -0,0 +1,67 @@ +try: + import inspect +except: + try: + from _pydev_imps import _pydev_inspect as inspect + except: + import traceback;traceback.print_exc() #Ok, no inspect available (search will not work) + +try: + import re +except: + try: + import sre as re # for older versions + except: + import traceback;traceback.print_exc() #Ok, no inspect available (search will not work) + + +from _pydevd_bundle.pydevd_constants import xrange + +def do_find(f, mod): + import linecache + if inspect.ismodule(mod): + return f, 0, 0 + + lines = linecache.getlines(f) + + if inspect.isclass(mod): + name = mod.__name__ + pat = re.compile(r'^\s*class\s*' + name + r'\b') + for i in xrange(len(lines)): + if pat.match(lines[i]): + return f, i, 0 + + return f, 0, 0 + + if inspect.ismethod(mod): + mod = mod.im_func + + if inspect.isfunction(mod): + try: + mod = mod.func_code + except AttributeError: + mod = mod.__code__ #python 3k + + if inspect.istraceback(mod): + mod = mod.tb_frame + + if inspect.isframe(mod): + mod = mod.f_code + + if inspect.iscode(mod): + if not hasattr(mod, 'co_filename'): + return None, 0, 0 + + if not hasattr(mod, 'co_firstlineno'): + return mod.co_filename, 0, 0 + + lnum = mod.co_firstlineno + pat = re.compile(r'^(\s*def\s)|(.*(? 0: + if pat.match(lines[lnum]): + break + lnum -= 1 + + return f, lnum, 0 + + raise RuntimeError('Do not know about: ' + f + ' ' + str(mod)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_console_utils.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_console_utils.py new file mode 100644 index 0000000..f706435 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_console_utils.py @@ -0,0 +1,666 @@ +import os +import sys +import traceback +from _pydev_bundle.pydev_imports import xmlrpclib, _queue, Exec +from _pydev_bundle._pydev_calltip_util import get_description +from _pydev_imps._pydev_saved_modules import thread +from _pydevd_bundle import pydevd_vars +from _pydevd_bundle import pydevd_xml +from _pydevd_bundle.pydevd_constants import (IS_JYTHON, dict_iter_items, NEXT_VALUE_SEPARATOR, Null, + get_global_debugger) +import signal +from contextlib import contextmanager +from _pydev_bundle import pydev_log + +try: + import cStringIO as StringIO # may not always be available @UnusedImport +except: + try: + import StringIO # @Reimport + except: + import io as StringIO + + +# ======================================================================================================================= +# BaseStdIn +# ======================================================================================================================= +class BaseStdIn: + + def __init__(self, original_stdin=sys.stdin, *args, **kwargs): + try: + self.encoding = sys.stdin.encoding + except: + # Not sure if it's available in all Python versions... + pass + self.original_stdin = original_stdin + + try: + self.errors = sys.stdin.errors # Who knew? sys streams have an errors attribute! + except: + # Not sure if it's available in all Python versions... + pass + + def readline(self, *args, **kwargs): + # sys.stderr.write('Cannot readline out of the console evaluation\n') -- don't show anything + # This could happen if the user had done input('enter number).<-- upon entering this, that message would appear, + # which is not something we want. + return '\n' + + def write(self, *args, **kwargs): + pass # not available StdIn (but it can be expected to be in the stream interface) + + def flush(self, *args, **kwargs): + pass # not available StdIn (but it can be expected to be in the stream interface) + + def read(self, *args, **kwargs): + # in the interactive interpreter, a read and a readline are the same. + return self.readline() + + def close(self, *args, **kwargs): + pass # expected in StdIn + + def __iter__(self): + # BaseStdIn would not be considered as Iterable in Python 3 without explicit `__iter__` implementation + return self.original_stdin.__iter__() + + def __getattr__(self, item): + # it's called if the attribute wasn't found + if hasattr(self.original_stdin, item): + return getattr(self.original_stdin, item) + raise AttributeError("%s has no attribute %s" % (self.original_stdin, item)) + + +# ======================================================================================================================= +# StdIn +# ======================================================================================================================= +class StdIn(BaseStdIn): + ''' + Object to be added to stdin (to emulate it as non-blocking while the next line arrives) + ''' + + def __init__(self, interpreter, host, client_port, original_stdin=sys.stdin): + BaseStdIn.__init__(self, original_stdin) + self.interpreter = interpreter + self.client_port = client_port + self.host = host + + def readline(self, *args, **kwargs): + # Ok, callback into the client to get the new input + try: + server = xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port)) + requested_input = server.RequestInput() + if not requested_input: + return '\n' # Yes, a readline must return something (otherwise we can get an EOFError on the input() call). + else: + # readline should end with '\n' (not doing so makes IPython 5 remove the last *valid* character). + requested_input += '\n' + return requested_input + except KeyboardInterrupt: + raise # Let KeyboardInterrupt go through -- #PyDev-816: Interrupting infinite loop in the Interactive Console + except: + return '\n' + + def close(self, *args, **kwargs): + pass # expected in StdIn + + +#======================================================================================================================= +# DebugConsoleStdIn +#======================================================================================================================= +class DebugConsoleStdIn(BaseStdIn): + ''' + Object to be added to stdin (to emulate it as non-blocking while the next line arrives) + ''' + + def __init__(self, py_db, original_stdin): + ''' + :param py_db: + If None, get_global_debugger() is used. + ''' + BaseStdIn.__init__(self, original_stdin) + self._py_db = py_db + self._in_notification = 0 + + def __send_input_requested_message(self, is_started): + try: + py_db = self._py_db + if py_db is None: + py_db = get_global_debugger() + cmd = py_db.cmd_factory.make_input_requested_message(is_started) + py_db.writer.add_command(cmd) + except Exception: + pydev_log.exception() + + @contextmanager + def notify_input_requested(self): + self._in_notification += 1 + if self._in_notification == 1: + self.__send_input_requested_message(True) + try: + yield + finally: + self._in_notification -= 1 + if self._in_notification == 0: + self.__send_input_requested_message(False) + + def readline(self, *args, **kwargs): + with self.notify_input_requested(): + return self.original_stdin.readline(*args, **kwargs) + + def read(self, *args, **kwargs): + with self.notify_input_requested(): + return self.original_stdin.read(*args, **kwargs) + + +class CodeFragment: + + def __init__(self, text, is_single_line=True): + self.text = text + self.is_single_line = is_single_line + + def append(self, code_fragment): + self.text = self.text + "\n" + code_fragment.text + if not code_fragment.is_single_line: + self.is_single_line = False + + +# ======================================================================================================================= +# BaseInterpreterInterface +# ======================================================================================================================= +class BaseInterpreterInterface: + + def __init__(self, mainThread, connect_status_queue=None): + self.mainThread = mainThread + self.interruptable = False + self.exec_queue = _queue.Queue(0) + self.buffer = None + self.banner_shown = False + self.connect_status_queue = connect_status_queue + self.mpl_modules_for_patching = {} + self.init_mpl_modules_for_patching() + + def build_banner(self): + return 'print({0})\n'.format(repr(self.get_greeting_msg())) + + def get_greeting_msg(self): + return 'PyDev console: starting.\n' + + def init_mpl_modules_for_patching(self): + from pydev_ipython.matplotlibtools import activate_matplotlib, activate_pylab, activate_pyplot + self.mpl_modules_for_patching = { + "matplotlib": lambda: activate_matplotlib(self.enableGui), + "matplotlib.pyplot": activate_pyplot, + "pylab": activate_pylab + } + + def need_more_for_code(self, source): + # PyDev-502: PyDev 3.9 F2 doesn't support backslash continuations + + # Strangely even the IPython console is_complete said it was complete + # even with a continuation char at the end. + if source.endswith('\\'): + return True + + if hasattr(self.interpreter, 'is_complete'): + return not self.interpreter.is_complete(source) + try: + # At this point, it should always be single. + # If we don't do this, things as: + # + # for i in range(10): print(i) + # + # (in a single line) don't work. + # Note that it won't give an error and code will be None (so, it'll + # use execMultipleLines in the next call in this case). + symbol = 'single' + code = self.interpreter.compile(source, '', symbol) + except (OverflowError, SyntaxError, ValueError): + # Case 1 + return False + if code is None: + # Case 2 + return True + + # Case 3 + return False + + def need_more(self, code_fragment): + if self.buffer is None: + self.buffer = code_fragment + else: + self.buffer.append(code_fragment) + + return self.need_more_for_code(self.buffer.text) + + def create_std_in(self, debugger=None, original_std_in=None): + if debugger is None: + return StdIn(self, self.host, self.client_port, original_stdin=original_std_in) + else: + return DebugConsoleStdIn(py_db=debugger, original_stdin=original_std_in) + + def add_exec(self, code_fragment, debugger=None): + # In case sys.excepthook called, use original excepthook #PyDev-877: Debug console freezes with Python 3.5+ + # (showtraceback does it on python 3.5 onwards) + sys.excepthook = sys.__excepthook__ + try: + original_in = sys.stdin + try: + help = None + if 'pydoc' in sys.modules: + pydoc = sys.modules['pydoc'] # Don't import it if it still is not there. + + if hasattr(pydoc, 'help'): + # You never know how will the API be changed, so, let's code defensively here + help = pydoc.help + if not hasattr(help, 'input'): + help = None + except: + # Just ignore any error here + pass + + more = False + try: + sys.stdin = self.create_std_in(debugger, original_in) + try: + if help is not None: + # This will enable the help() function to work. + try: + try: + help.input = sys.stdin + except AttributeError: + help._input = sys.stdin + except: + help = None + if not self._input_error_printed: + self._input_error_printed = True + sys.stderr.write('\nError when trying to update pydoc.help.input\n') + sys.stderr.write('(help() may not work -- please report this as a bug in the pydev bugtracker).\n\n') + traceback.print_exc() + + try: + self.start_exec() + if hasattr(self, 'debugger'): + self.debugger.enable_tracing() + + more = self.do_add_exec(code_fragment) + + if hasattr(self, 'debugger'): + self.debugger.disable_tracing() + + self.finish_exec(more) + finally: + if help is not None: + try: + try: + help.input = original_in + except AttributeError: + help._input = original_in + except: + pass + + finally: + sys.stdin = original_in + except SystemExit: + raise + except: + traceback.print_exc() + finally: + sys.__excepthook__ = sys.excepthook + + return more + + def do_add_exec(self, codeFragment): + ''' + Subclasses should override. + + @return: more (True if more input is needed to complete the statement and False if the statement is complete). + ''' + raise NotImplementedError() + + def get_namespace(self): + ''' + Subclasses should override. + + @return: dict with namespace. + ''' + raise NotImplementedError() + + def __resolve_reference__(self, text): + """ + + :type text: str + """ + obj = None + if '.' not in text: + try: + obj = self.get_namespace()[text] + except KeyError: + pass + + if obj is None: + try: + obj = self.get_namespace()['__builtins__'][text] + except: + pass + + if obj is None: + try: + obj = getattr(self.get_namespace()['__builtins__'], text, None) + except: + pass + + else: + try: + last_dot = text.rindex('.') + parent_context = text[0:last_dot] + res = pydevd_vars.eval_in_context(parent_context, self.get_namespace(), self.get_namespace()) + obj = getattr(res, text[last_dot + 1:]) + except: + pass + return obj + + def getDescription(self, text): + try: + obj = self.__resolve_reference__(text) + if obj is None: + return '' + return get_description(obj) + except: + return '' + + def do_exec_code(self, code, is_single_line): + try: + code_fragment = CodeFragment(code, is_single_line) + more = self.need_more(code_fragment) + if not more: + code_fragment = self.buffer + self.buffer = None + self.exec_queue.put(code_fragment) + + return more + except: + traceback.print_exc() + return False + + def execLine(self, line): + return self.do_exec_code(line, True) + + def execMultipleLines(self, lines): + if IS_JYTHON: + more = False + for line in lines.split('\n'): + more = self.do_exec_code(line, True) + return more + else: + return self.do_exec_code(lines, False) + + def interrupt(self): + self.buffer = None # Also clear the buffer when it's interrupted. + try: + if self.interruptable: + called = False + try: + # Fix for #PyDev-500: Console interrupt can't interrupt on sleep + if os.name == 'posix': + # On Linux we can't interrupt 0 as in Windows because it's + # actually owned by a process -- on the good side, signals + # work much better on Linux! + os.kill(os.getpid(), signal.SIGINT) + called = True + + elif os.name == 'nt': + # Stupid windows: sending a Ctrl+C to a process given its pid + # is absurdly difficult. + # There are utilities to make it work such as + # http://www.latenighthacking.com/projects/2003/sendSignal/ + # but fortunately for us, it seems Python does allow a CTRL_C_EVENT + # for the current process in Windows if pid 0 is passed... if we needed + # to send a signal to another process the approach would be + # much more difficult. + # Still, note that CTRL_C_EVENT is only Python 2.7 onwards... + # Also, this doesn't seem to be documented anywhere!? (stumbled + # upon it by chance after digging quite a lot). + os.kill(0, signal.CTRL_C_EVENT) + called = True + except: + # Many things to go wrong (from CTRL_C_EVENT not being there + # to failing import signal)... if that's the case, ask for + # forgiveness and go on to the approach which will interrupt + # the main thread (but it'll only work when it's executing some Python + # code -- not on sleep() for instance). + pass + + if not called: + if hasattr(thread, 'interrupt_main'): # Jython doesn't have it + thread.interrupt_main() + else: + self.mainThread._thread.interrupt() # Jython + self.finish_exec(False) + return True + except: + traceback.print_exc() + return False + + def close(self): + sys.exit(0) + + def start_exec(self): + self.interruptable = True + + def get_server(self): + if getattr(self, 'host', None) is not None: + return xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port)) + else: + return None + + server = property(get_server) + + def ShowConsole(self): + server = self.get_server() + if server is not None: + server.ShowConsole() + + def finish_exec(self, more): + self.interruptable = False + + server = self.get_server() + + if server is not None: + return server.NotifyFinished(more) + else: + return True + + def getFrame(self): + xml = StringIO.StringIO() + hidden_ns = self.get_ipython_hidden_vars_dict() + xml.write("") + xml.write(pydevd_xml.frame_vars_to_xml(self.get_namespace(), hidden_ns)) + xml.write("") + + return xml.getvalue() + + def getVariable(self, attributes): + xml = StringIO.StringIO() + xml.write("") + val_dict = pydevd_vars.resolve_compound_var_object_fields(self.get_namespace(), attributes) + if val_dict is None: + val_dict = {} + + keys = val_dict.keys() + for k in keys: + val = val_dict[k] + evaluate_full_value = pydevd_xml.should_evaluate_full_value(val) + xml.write(pydevd_vars.var_to_xml(val, k, evaluate_full_value=evaluate_full_value)) + + xml.write("") + + return xml.getvalue() + + def getArray(self, attr, roffset, coffset, rows, cols, format): + name = attr.split("\t")[-1] + array = pydevd_vars.eval_in_context(name, self.get_namespace(), self.get_namespace()) + return pydevd_vars.table_like_struct_to_xml(array, name, roffset, coffset, rows, cols, format) + + def evaluate(self, expression): + xml = StringIO.StringIO() + xml.write("") + result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) + xml.write(pydevd_vars.var_to_xml(result, expression)) + xml.write("") + return xml.getvalue() + + def loadFullValue(self, seq, scope_attrs): + """ + Evaluate full value for async Console variables in a separate thread and send results to IDE side + :param seq: id of command + :param scope_attrs: a sequence of variables with their attributes separated by NEXT_VALUE_SEPARATOR + (i.e.: obj\tattr1\tattr2NEXT_VALUE_SEPARATORobj2\attr1\tattr2) + :return: + """ + frame_variables = self.get_namespace() + var_objects = [] + vars = scope_attrs.split(NEXT_VALUE_SEPARATOR) + for var_attrs in vars: + if '\t' in var_attrs: + name, attrs = var_attrs.split('\t', 1) + + else: + name = var_attrs + attrs = None + if name in frame_variables: + var_object = pydevd_vars.resolve_var_object(frame_variables[name], attrs) + var_objects.append((var_object, name)) + else: + var_object = pydevd_vars.eval_in_context(name, frame_variables, frame_variables) + var_objects.append((var_object, name)) + + from _pydevd_bundle.pydevd_comm import GetValueAsyncThreadConsole + t = GetValueAsyncThreadConsole(self.get_server(), seq, var_objects) + t.start() + + def changeVariable(self, attr, value): + + def do_change_variable(): + Exec('%s=%s' % (attr, value), self.get_namespace(), self.get_namespace()) + + # Important: it has to be really enabled in the main thread, so, schedule + # it to run in the main thread. + self.exec_queue.put(do_change_variable) + + def connectToDebugger(self, debuggerPort, debugger_options=None): + ''' + Used to show console with variables connection. + Mainly, monkey-patches things in the debugger structure so that the debugger protocol works. + ''' + + if debugger_options is None: + debugger_options = {} + env_key = "PYDEVD_EXTRA_ENVS" + if env_key in debugger_options: + for (env_name, value) in dict_iter_items(debugger_options[env_key]): + existing_value = os.environ.get(env_name, None) + if existing_value: + os.environ[env_name] = "%s%c%s" % (existing_value, os.path.pathsep, value) + else: + os.environ[env_name] = value + if env_name == "PYTHONPATH": + sys.path.append(value) + + del debugger_options[env_key] + + def do_connect_to_debugger(): + try: + # Try to import the packages needed to attach the debugger + import pydevd + from _pydev_imps._pydev_saved_modules import threading + except: + # This happens on Jython embedded in host eclipse + traceback.print_exc() + sys.stderr.write('pydevd is not available, cannot connect\n') + + from _pydevd_bundle.pydevd_constants import set_thread_id + from _pydev_bundle import pydev_localhost + set_thread_id(threading.currentThread(), "console_main") + + VIRTUAL_FRAME_ID = "1" # matches PyStackFrameConsole.java + VIRTUAL_CONSOLE_ID = "console_main" # matches PyThreadConsole.java + f = FakeFrame() + f.f_back = None + f.f_globals = {} # As globals=locals here, let's simply let it empty (and save a bit of network traffic). + f.f_locals = self.get_namespace() + + self.debugger = pydevd.PyDB() + self.debugger.add_fake_frame(thread_id=VIRTUAL_CONSOLE_ID, frame_id=VIRTUAL_FRAME_ID, frame=f) + try: + pydevd.apply_debugger_options(debugger_options) + self.debugger.connect(pydev_localhost.get_localhost(), debuggerPort) + self.debugger.prepare_to_run() + self.debugger.disable_tracing() + except: + traceback.print_exc() + sys.stderr.write('Failed to connect to target debugger.\n') + + # Register to process commands when idle + self.debugrunning = False + try: + import pydevconsole + pydevconsole.set_debug_hook(self.debugger.process_internal_commands) + except: + traceback.print_exc() + sys.stderr.write('Version of Python does not support debuggable Interactive Console.\n') + + # Important: it has to be really enabled in the main thread, so, schedule + # it to run in the main thread. + self.exec_queue.put(do_connect_to_debugger) + + return ('connect complete',) + + def handshake(self): + if self.connect_status_queue is not None: + self.connect_status_queue.put(True) + return "PyCharm" + + def get_connect_status_queue(self): + return self.connect_status_queue + + def hello(self, input_str): + # Don't care what the input string is + return ("Hello eclipse",) + + def enableGui(self, guiname): + ''' Enable the GUI specified in guiname (see inputhook for list). + As with IPython, enabling multiple GUIs isn't an error, but + only the last one's main loop runs and it may not work + ''' + + def do_enable_gui(): + from _pydev_bundle.pydev_versioncheck import versionok_for_gui + if versionok_for_gui(): + try: + from pydev_ipython.inputhook import enable_gui + enable_gui(guiname) + except: + sys.stderr.write("Failed to enable GUI event loop integration for '%s'\n" % guiname) + traceback.print_exc() + elif guiname not in ['none', '', None]: + # Only print a warning if the guiname was going to do something + sys.stderr.write("PyDev console: Python version does not support GUI event loop integration for '%s'\n" % guiname) + # Return value does not matter, so return back what was sent + return guiname + + # Important: it has to be really enabled in the main thread, so, schedule + # it to run in the main thread. + self.exec_queue.put(do_enable_gui) + + def get_ipython_hidden_vars_dict(self): + return None + + +# ======================================================================================================================= +# FakeFrame +# ======================================================================================================================= +class FakeFrame: + ''' + Used to show console with variables connection. + A class to be used as a mock of a frame. + ''' diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_import_hook.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_import_hook.py new file mode 100644 index 0000000..0c29044 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_import_hook.py @@ -0,0 +1,43 @@ + +import sys +import traceback +from types import ModuleType +from _pydevd_bundle.pydevd_constants import DebugInfoHolder + +if sys.version_info[0] >= 3: + import builtins # py3 +else: + import __builtin__ as builtins + + +class ImportHookManager(ModuleType): + + def __init__(self, name, system_import): + ModuleType.__init__(self, name) + self._system_import = system_import + self._modules_to_patch = {} + + def add_module_name(self, module_name, activate_function): + self._modules_to_patch[module_name] = activate_function + + def do_import(self, name, *args, **kwargs): + module = self._system_import(name, *args, **kwargs) + try: + activate_func = self._modules_to_patch.pop(name, None) + if activate_func: + activate_func() # call activate function + except: + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 2: + traceback.print_exc() + + # Restore normal system importer to reduce performance impact + # of calling this method every time an import statement is invoked + if not self._modules_to_patch: + builtins.__import__ = self._system_import + + return module + + +import_hook_manager = ImportHookManager(__name__ + '.import_hook', builtins.__import__) +builtins.__import__ = import_hook_manager.do_import +sys.modules[import_hook_manager.__name__] = import_hook_manager diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_imports.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_imports.py new file mode 100644 index 0000000..0e0f21f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_imports.py @@ -0,0 +1,53 @@ +from _pydevd_bundle.pydevd_constants import USE_LIB_COPY, izip + +try: + try: + if USE_LIB_COPY: + from _pydev_imps._pydev_saved_modules import xmlrpclib + else: + import xmlrpclib + except ImportError: + import xmlrpc.client as xmlrpclib +except ImportError: + from _pydev_imps import _pydev_xmlrpclib as xmlrpclib + +try: + try: + if USE_LIB_COPY: + from _pydev_imps._pydev_saved_modules import _pydev_SimpleXMLRPCServer + from _pydev_SimpleXMLRPCServer import SimpleXMLRPCServer + else: + from SimpleXMLRPCServer import SimpleXMLRPCServer + except ImportError: + from xmlrpc.server import SimpleXMLRPCServer +except ImportError: + from _pydev_imps._pydev_SimpleXMLRPCServer import SimpleXMLRPCServer + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + +try: + execfile = execfile # Not in Py3k +except NameError: + from _pydev_imps._pydev_execfile import execfile + +try: + if USE_LIB_COPY: + from _pydev_imps._pydev_saved_modules import _queue + else: + import Queue as _queue +except: + import queue as _queue # @UnresolvedImport + +try: + from _pydevd_bundle.pydevd_exec import Exec +except: + from _pydevd_bundle.pydevd_exec2 import Exec + +try: + from urllib import quote, quote_plus, unquote_plus +except: + from urllib.parse import quote, quote_plus, unquote_plus # @UnresolvedImport + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_ipython_console.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_ipython_console.py new file mode 100644 index 0000000..180f289 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_ipython_console.py @@ -0,0 +1,100 @@ +import sys +from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface + +import os +import traceback + +# Uncomment to force PyDev standard shell. +# raise ImportError() + +from _pydev_bundle.pydev_ipython_console_011 import get_pydev_frontend +from _pydevd_bundle.pydevd_constants import dict_iter_items + +#======================================================================================================================= +# InterpreterInterface +#======================================================================================================================= +class InterpreterInterface(BaseInterpreterInterface): + ''' + The methods in this class should be registered in the xml-rpc server. + ''' + + def __init__(self, host, client_port, main_thread, show_banner=True, connect_status_queue=None): + BaseInterpreterInterface.__init__(self, main_thread, connect_status_queue) + self.client_port = client_port + self.host = host + self.interpreter = get_pydev_frontend(host, client_port) + self._input_error_printed = False + self.notification_succeeded = False + self.notification_tries = 0 + self.notification_max_tries = 3 + self.show_banner = show_banner + + self.notify_about_magic() + + def get_greeting_msg(self): + if self.show_banner: + self.interpreter.show_banner() + return self.interpreter.get_greeting_msg() + + def do_add_exec(self, code_fragment): + self.notify_about_magic() + if code_fragment.text.rstrip().endswith('??'): + print('IPython-->') + try: + res = bool(self.interpreter.add_exec(code_fragment.text)) + finally: + if code_fragment.text.rstrip().endswith('??'): + print('<--IPython') + + return res + + + def get_namespace(self): + return self.interpreter.get_namespace() + + + def getCompletions(self, text, act_tok): + return self.interpreter.getCompletions(text, act_tok) + + def close(self): + sys.exit(0) + + def notify_about_magic(self): + if not self.notification_succeeded: + self.notification_tries+=1 + if self.notification_tries>self.notification_max_tries: + return + completions = self.getCompletions("%", "%") + magic_commands = [x[0] for x in completions] + + server = self.get_server() + + if server is not None: + try: + server.NotifyAboutMagic(magic_commands, self.interpreter.is_automagic()) + self.notification_succeeded = True + except : + self.notification_succeeded = False + + def get_ipython_hidden_vars_dict(self): + try: + if hasattr(self.interpreter, 'ipython') and hasattr(self.interpreter.ipython, 'user_ns_hidden'): + user_ns_hidden = self.interpreter.ipython.user_ns_hidden + if isinstance(user_ns_hidden, dict): + # Since IPython 2 dict `user_ns_hidden` contains hidden variables and values + user_hidden_dict = user_ns_hidden.copy() + else: + # In IPython 1.x `user_ns_hidden` used to be a set with names of hidden variables + user_hidden_dict = dict([(key, val) for key, val in dict_iter_items(self.interpreter.ipython.user_ns) + if key in user_ns_hidden]) + + # while `_`, `__` and `___` were not initialized, they are not presented in `user_ns_hidden` + user_hidden_dict.setdefault('_', '') + user_hidden_dict.setdefault('__', '') + user_hidden_dict.setdefault('___', '') + + return user_hidden_dict + except: + # Getting IPython variables shouldn't break loading frame variables + traceback.print_exc() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_ipython_console_011.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_ipython_console_011.py new file mode 100644 index 0000000..9681ddf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_ipython_console_011.py @@ -0,0 +1,507 @@ +# TODO that would make IPython integration better +# - show output other times then when enter was pressed +# - support proper exit to allow IPython to cleanup (e.g. temp files created with %edit) +# - support Ctrl-D (Ctrl-Z on Windows) +# - use IPython (numbered) prompts in PyDev +# - better integration of IPython and PyDev completions +# - some of the semantics on handling the code completion are not correct: +# eg: Start a line with % and then type c should give %cd as a completion by it doesn't +# however type %c and request completions and %cd is given as an option +# eg: Completing a magic when user typed it without the leading % causes the % to be inserted +# to the left of what should be the first colon. +"""Interface to TerminalInteractiveShell for PyDev Interactive Console frontend + for IPython 0.11 to 1.0+. +""" + +from __future__ import print_function + +import os +import sys +import codeop +import traceback + +from IPython.core.error import UsageError +from IPython.core.completer import IPCompleter +from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC +from IPython.core.usage import default_banner_parts +from IPython.utils.strdispatch import StrDispatch +import IPython.core.release as IPythonRelease +from IPython.terminal.interactiveshell import TerminalInteractiveShell +try: + from traitlets import CBool, Unicode +except ImportError: + from IPython.utils.traitlets import CBool, Unicode +from IPython.core import release + +from _pydev_bundle.pydev_imports import xmlrpclib +from _pydevd_bundle.pydevd_constants import dict_keys + +default_pydev_banner_parts = default_banner_parts + +default_pydev_banner = ''.join(default_pydev_banner_parts) + +def show_in_pager(self, strng, *args, **kwargs): + """ Run a string through pager """ + # On PyDev we just output the string, there are scroll bars in the console + # to handle "paging". This is the same behaviour as when TERM==dump (see + # page.py) + # for compatibility with mime-bundle form: + if isinstance(strng, dict): + strng = strng.get('text/plain', strng) + print(strng) + +def create_editor_hook(pydev_host, pydev_client_port): + + def call_editor(filename, line=0, wait=True): + """ Open an editor in PyDev """ + if line is None: + line = 0 + + # Make sure to send an absolution path because unlike most editor hooks + # we don't launch a process. This is more like what happens in the zmqshell + filename = os.path.abspath(filename) + + # import sys + # sys.__stderr__.write('Calling editor at: %s:%s\n' % (pydev_host, pydev_client_port)) + + # Tell PyDev to open the editor + server = xmlrpclib.Server('http://%s:%s' % (pydev_host, pydev_client_port)) + server.IPythonEditor(filename, str(line)) + + if wait: + try: + raw_input("Press Enter when done editing:") + except NameError: + input("Press Enter when done editing:") + return call_editor + + +class PyDevIPCompleter(IPCompleter): + + def __init__(self, *args, **kwargs): + """ Create a Completer that reuses the advanced completion support of PyDev + in addition to the completion support provided by IPython """ + IPCompleter.__init__(self, *args, **kwargs) + # Use PyDev for python matches, see getCompletions below + if self.python_matches in self.matchers: + # `self.python_matches` matches attributes or global python names + self.matchers.remove(self.python_matches) + +class PyDevIPCompleter6(IPCompleter): + + def __init__(self, *args, **kwargs): + """ Create a Completer that reuses the advanced completion support of PyDev + in addition to the completion support provided by IPython """ + IPCompleter.__init__(self, *args, **kwargs) + + @property + def matchers(self): + """All active matcher routines for completion""" + # To remove python_matches we now have to override it as it's now a property in the superclass. + return [ + self.file_matches, + self.magic_matches, + self.python_func_kw_matches, + self.dict_key_matches, + ] + +class PyDevTerminalInteractiveShell(TerminalInteractiveShell): + banner1 = Unicode(default_pydev_banner, config=True, + help="""The part of the banner to be printed before the profile""" + ) + + # TODO term_title: (can PyDev's title be changed???, see terminal.py for where to inject code, in particular set_term_title as used by %cd) + # for now, just disable term_title + term_title = CBool(False) + + # Note in version 0.11 there is no guard in the IPython code about displaying a + # warning, so with 0.11 you get: + # WARNING: Readline services not available or not loaded. + # WARNING: The auto-indent feature requires the readline library + # Disable readline, readline type code is all handled by PyDev (on Java side) + readline_use = CBool(False) + # autoindent has no meaning in PyDev (PyDev always handles that on the Java side), + # and attempting to enable it will print a warning in the absence of readline. + autoindent = CBool(False) + # Force console to not give warning about color scheme choice and default to NoColor. + # TODO It would be nice to enable colors in PyDev but: + # - The PyDev Console (Eclipse Console) does not support the full range of colors, so the + # effect isn't as nice anyway at the command line + # - If done, the color scheme should default to LightBG, but actually be dependent on + # any settings the user has (such as if a dark theme is in use, then Linux is probably + # a better theme). + colors_force = CBool(True) + colors = Unicode("NoColor") + # Since IPython 5 the terminal interface is not compatible with Emacs `inferior-shell` and + # the `simple_prompt` flag is needed + simple_prompt = CBool(True) + + # In the PyDev Console, GUI control is done via hookable XML-RPC server + @staticmethod + def enable_gui(gui=None, app=None): + """Switch amongst GUI input hooks by name. + """ + # Deferred import + from pydev_ipython.inputhook import enable_gui as real_enable_gui + try: + return real_enable_gui(gui, app) + except ValueError as e: + raise UsageError("%s" % e) + + #------------------------------------------------------------------------- + # Things related to hooks + #------------------------------------------------------------------------- + + def init_hooks(self): + super(PyDevTerminalInteractiveShell, self).init_hooks() + self.set_hook('show_in_pager', show_in_pager) + + #------------------------------------------------------------------------- + # Things related to exceptions + #------------------------------------------------------------------------- + + def showtraceback(self, exc_tuple=None, *args, **kwargs): + # IPython does a lot of clever stuff with Exceptions. However mostly + # it is related to IPython running in a terminal instead of an IDE. + # (e.g. it prints out snippets of code around the stack trace) + # PyDev does a lot of clever stuff too, so leave exception handling + # with default print_exc that PyDev can parse and do its clever stuff + # with (e.g. it puts links back to the original source code) + try: + if exc_tuple is None: + etype, value, tb = sys.exc_info() + else: + etype, value, tb = exc_tuple + except ValueError: + return + + if tb is not None: + traceback.print_exception(etype, value, tb) + + + + #------------------------------------------------------------------------- + # Things related to text completion + #------------------------------------------------------------------------- + + # The way to construct an IPCompleter changed in most versions, + # so we have a custom, per version implementation of the construction + + def _new_completer_100(self): + completer = PyDevIPCompleter(shell=self, + namespace=self.user_ns, + global_namespace=self.user_global_ns, + alias_table=self.alias_manager.alias_table, + use_readline=self.has_readline, + parent=self, + ) + return completer + + def _new_completer_234(self): + # correct for IPython versions 2.x, 3.x, 4.x + completer = PyDevIPCompleter(shell=self, + namespace=self.user_ns, + global_namespace=self.user_global_ns, + use_readline=self.has_readline, + parent=self, + ) + return completer + + def _new_completer_500(self): + completer = PyDevIPCompleter(shell=self, + namespace=self.user_ns, + global_namespace=self.user_global_ns, + use_readline=False, + parent=self + ) + return completer + + def _new_completer_600(self): + completer = PyDevIPCompleter6(shell=self, + namespace=self.user_ns, + global_namespace=self.user_global_ns, + use_readline=False, + parent=self + ) + return completer + + def add_completer_hooks(self): + from IPython.core.completerlib import module_completer, magic_run_completer, cd_completer + try: + from IPython.core.completerlib import reset_completer + except ImportError: + # reset_completer was added for rel-0.13 + reset_completer = None + self.configurables.append(self.Completer) + + # Add custom completers to the basic ones built into IPCompleter + sdisp = self.strdispatchers.get('complete_command', StrDispatch()) + self.strdispatchers['complete_command'] = sdisp + self.Completer.custom_completers = sdisp + + self.set_hook('complete_command', module_completer, str_key = 'import') + self.set_hook('complete_command', module_completer, str_key = 'from') + self.set_hook('complete_command', magic_run_completer, str_key = '%run') + self.set_hook('complete_command', cd_completer, str_key = '%cd') + if reset_completer: + self.set_hook('complete_command', reset_completer, str_key = '%reset') + + def init_completer(self): + """Initialize the completion machinery. + + This creates a completer that provides the completions that are + IPython specific. We use this to supplement PyDev's core code + completions. + """ + # PyDev uses its own completer and custom hooks so that it uses + # most completions from PyDev's core completer which provides + # extra information. + # See getCompletions for where the two sets of results are merged + + if IPythonRelease._version_major >= 6: + self.Completer = self._new_completer_600() + elif IPythonRelease._version_major >= 5: + self.Completer = self._new_completer_500() + elif IPythonRelease._version_major >= 2: + self.Completer = self._new_completer_234() + elif IPythonRelease._version_major >= 1: + self.Completer = self._new_completer_100() + + if hasattr(self.Completer, 'use_jedi'): + self.Completer.use_jedi = False + + self.add_completer_hooks() + + if IPythonRelease._version_major <= 3: + # Only configure readline if we truly are using readline. IPython can + # do tab-completion over the network, in GUIs, etc, where readline + # itself may be absent + if self.has_readline: + self.set_readline_completer() + + #------------------------------------------------------------------------- + # Things related to aliases + #------------------------------------------------------------------------- + + def init_alias(self): + # InteractiveShell defines alias's we want, but TerminalInteractiveShell defines + # ones we don't. So don't use super and instead go right to InteractiveShell + InteractiveShell.init_alias(self) + + #------------------------------------------------------------------------- + # Things related to exiting + #------------------------------------------------------------------------- + def ask_exit(self): + """ Ask the shell to exit. Can be overiden and used as a callback. """ + # TODO PyDev's console does not have support from the Python side to exit + # the console. If user forces the exit (with sys.exit()) then the console + # simply reports errors. e.g.: + # >>> import sys + # >>> sys.exit() + # Failed to create input stream: Connection refused + # >>> + # Console already exited with value: 0 while waiting for an answer. + # Error stream: + # Output stream: + # >>> + # + # Alternatively if you use the non-IPython shell this is what happens + # >>> exit() + # :None + # >>> + # :None + # >>> + # + super(PyDevTerminalInteractiveShell, self).ask_exit() + print('To exit the PyDev Console, terminate the console within IDE.') + + #------------------------------------------------------------------------- + # Things related to magics + #------------------------------------------------------------------------- + + def init_magics(self): + super(PyDevTerminalInteractiveShell, self).init_magics() + # TODO Any additional magics for PyDev? + +InteractiveShellABC.register(PyDevTerminalInteractiveShell) # @UndefinedVariable + +#======================================================================================================================= +# _PyDevFrontEnd +#======================================================================================================================= +class _PyDevFrontEnd: + + version = release.__version__ + + def __init__(self): + # Create and initialize our IPython instance. + if hasattr(PyDevTerminalInteractiveShell, '_instance') and PyDevTerminalInteractiveShell._instance is not None: + self.ipython = PyDevTerminalInteractiveShell._instance + else: + self.ipython = PyDevTerminalInteractiveShell.instance() + + self._curr_exec_line = 0 + self._curr_exec_lines = [] + + def show_banner(self): + self.ipython.show_banner() + + def update(self, globals, locals): + ns = self.ipython.user_ns + + for key in dict_keys(self.ipython.user_ns): + if key not in locals: + locals[key] = ns[key] + + self.ipython.user_global_ns.clear() + self.ipython.user_global_ns.update(globals) + self.ipython.user_ns = locals + + if hasattr(self.ipython, 'history_manager') and hasattr(self.ipython.history_manager, 'save_thread'): + self.ipython.history_manager.save_thread.pydev_do_not_trace = True #don't trace ipython history saving thread + + def complete(self, string): + try: + if string: + return self.ipython.complete(None, line=string, cursor_pos=string.__len__()) + else: + return self.ipython.complete(string, string, 0) + except: + # Silence completer exceptions + pass + + def is_complete(self, string): + #Based on IPython 0.10.1 + + if string in ('', '\n'): + # Prefiltering, eg through ipython0, may return an empty + # string although some operations have been accomplished. We + # thus want to consider an empty string as a complete + # statement. + return True + else: + try: + # Add line returns here, to make sure that the statement is + # complete (except if '\' was used). + # This should probably be done in a different place (like + # maybe 'prefilter_input' method? For now, this works. + clean_string = string.rstrip('\n') + if not clean_string.endswith('\\'): + clean_string += '\n\n' + + is_complete = codeop.compile_command( + clean_string, + "", + "exec" + ) + except Exception: + # XXX: Hack: return True so that the + # code gets executed and the error captured. + is_complete = True + return is_complete + + + def getCompletions(self, text, act_tok): + # Get completions from IPython and from PyDev and merge the results + # IPython only gives context free list of completions, while PyDev + # gives detailed information about completions. + try: + TYPE_IPYTHON = '11' + TYPE_IPYTHON_MAGIC = '12' + _line, ipython_completions = self.complete(text) + + from _pydev_bundle._pydev_completer import Completer + completer = Completer(self.get_namespace(), None) + ret = completer.complete(act_tok) + append = ret.append + ip = self.ipython + pydev_completions = set([f[0] for f in ret]) + for ipython_completion in ipython_completions: + + #PyCharm was not expecting completions with '%'... + #Could be fixed in the backend, but it's probably better + #fixing it at PyCharm. + #if ipython_completion.startswith('%'): + # ipython_completion = ipython_completion[1:] + + if ipython_completion not in pydev_completions: + pydev_completions.add(ipython_completion) + inf = ip.object_inspect(ipython_completion) + if inf['type_name'] == 'Magic function': + pydev_type = TYPE_IPYTHON_MAGIC + else: + pydev_type = TYPE_IPYTHON + pydev_doc = inf['docstring'] + if pydev_doc is None: + pydev_doc = '' + append((ipython_completion, pydev_doc, '', pydev_type)) + return ret + except: + import traceback;traceback.print_exc() + return [] + + + def get_namespace(self): + return self.ipython.user_ns + + def clear_buffer(self): + del self._curr_exec_lines[:] + + def add_exec(self, line): + if self._curr_exec_lines: + self._curr_exec_lines.append(line) + + buf = '\n'.join(self._curr_exec_lines) + + if self.is_complete(buf): + self._curr_exec_line += 1 + self.ipython.run_cell(buf) + del self._curr_exec_lines[:] + return False #execute complete (no more) + + return True #needs more + else: + + if not self.is_complete(line): + #Did not execute + self._curr_exec_lines.append(line) + return True #needs more + else: + self._curr_exec_line += 1 + self.ipython.run_cell(line, store_history=True) + #hist = self.ipython.history_manager.output_hist_reprs + #rep = hist.get(self._curr_exec_line, None) + #if rep is not None: + # print(rep) + return False #execute complete (no more) + + def is_automagic(self): + return self.ipython.automagic + + def get_greeting_msg(self): + return 'PyDev console: using IPython %s\n' % self.version + + +class _PyDevFrontEndContainer: + _instance = None + _last_host_port = None + + +def get_pydev_frontend(pydev_host, pydev_client_port): + if _PyDevFrontEndContainer._instance is None: + _PyDevFrontEndContainer._instance = _PyDevFrontEnd() + + if _PyDevFrontEndContainer._last_host_port != (pydev_host, pydev_client_port): + _PyDevFrontEndContainer._last_host_port = pydev_host, pydev_client_port + + # Back channel to PyDev to open editors (in the future other + # info may go back this way. This is the same channel that is + # used to get stdin, see StdIn in pydev_console_utils) + _PyDevFrontEndContainer._instance.ipython.hooks['editor'] = create_editor_hook(pydev_host, pydev_client_port) + + # Note: setting the callback directly because setting it with set_hook would actually create a chain instead + # of ovewriting at each new call). + # _PyDevFrontEndContainer._instance.ipython.set_hook('editor', create_editor_hook(pydev_host, pydev_client_port)) + + return _PyDevFrontEndContainer._instance + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_is_thread_alive.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_is_thread_alive.py new file mode 100644 index 0000000..f1bff3b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_is_thread_alive.py @@ -0,0 +1,23 @@ +from _pydev_imps._pydev_saved_modules import threading + +# Hack for https://www.brainwy.com/tracker/PyDev/363 (i.e.: calling is_alive() can throw AssertionError under some +# circumstances). +# It is required to debug threads started by start_new_thread in Python 3.4 +_temp = threading.Thread() +if hasattr(_temp, '_is_stopped'): # Python 3.x has this + + def is_thread_alive(t): + return not t._is_stopped + +elif hasattr(_temp, '_Thread__stopped'): # Python 2.x has this + + def is_thread_alive(t): + return not t._Thread__stopped + +else: + + # Jython wraps a native java thread and thus only obeys the public API. + def is_thread_alive(t): + return t.is_alive() + +del _temp diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_localhost.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_localhost.py new file mode 100644 index 0000000..27f6f5b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_localhost.py @@ -0,0 +1,64 @@ +from _pydevd_bundle import pydevd_constants +from _pydev_imps._pydev_saved_modules import socket +import sys + +IS_JYTHON = sys.platform.find('java') != -1 + +_cache = None +def get_localhost(): + ''' + Should return 127.0.0.1 in ipv4 and ::1 in ipv6 + + localhost is not used because on windows vista/windows 7, there can be issues where the resolving doesn't work + properly and takes a lot of time (had this issue on the pyunit server). + + Using the IP directly solves the problem. + ''' + # TODO: Needs better investigation! + + global _cache + if _cache is None: + try: + for addr_info in socket.getaddrinfo("localhost", 80, 0, 0, socket.SOL_TCP): + config = addr_info[4] + if config[0] == '127.0.0.1': + _cache = '127.0.0.1' + return _cache + except: + # Ok, some versions of Python don't have getaddrinfo or SOL_TCP... Just consider it 127.0.0.1 in this case. + _cache = '127.0.0.1' + else: + _cache = 'localhost' + + return _cache + + +def get_socket_names(n_sockets, close=False): + socket_names = [] + sockets = [] + for _ in range(n_sockets): + if IS_JYTHON: + # Although the option which would be pure java *should* work for Jython, the socket being returned is still 0 + # (i.e.: it doesn't give the local port bound, only the original port, which was 0). + from java.net import ServerSocket + sock = ServerSocket(0) + socket_name = get_localhost(), sock.getLocalPort() + else: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind((get_localhost(), 0)) + socket_name = sock.getsockname() + + sockets.append(sock) + socket_names.append(socket_name) + + if close: + for s in sockets: + s.close() + return socket_names + +def get_socket_name(close=False): + return get_socket_names(1, close)[0] + +if __name__ == '__main__': + print(get_socket_name()) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_log.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_log.py new file mode 100644 index 0000000..8077fd6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_log.py @@ -0,0 +1,126 @@ +from _pydevd_bundle.pydevd_constants import DebugInfoHolder, SHOW_COMPILE_CYTHON_COMMAND_LINE +from _pydev_imps._pydev_saved_modules import threading +from contextlib import contextmanager +import traceback +import os +import sys +currentThread = threading.currentThread + +WARN_ONCE_MAP = {} + + +@contextmanager +def log_context(trace_level, stream): + ''' + To be used to temporarily change the logging settings. + ''' + original_trace_level = DebugInfoHolder.DEBUG_TRACE_LEVEL + original_stream = DebugInfoHolder.DEBUG_STREAM + + DebugInfoHolder.DEBUG_TRACE_LEVEL = trace_level + DebugInfoHolder.DEBUG_STREAM = stream + try: + yield + finally: + DebugInfoHolder.DEBUG_TRACE_LEVEL = original_trace_level + DebugInfoHolder.DEBUG_STREAM = original_stream + + +def _pydevd_log(level, msg, *args): + ''' + Levels are: + + 0 most serious warnings/errors (always printed) + 1 warnings/significant events + 2 informational trace + 3 verbose mode + ''' + if level <= DebugInfoHolder.DEBUG_TRACE_LEVEL: + # yes, we can have errors printing if the console of the program has been finished (and we're still trying to print something) + try: + try: + if args: + msg = msg % args + except: + msg = '%s - %s' % (msg, args) + msg = '%s\n' % (msg,) + try: + DebugInfoHolder.DEBUG_STREAM.write(msg) + except TypeError: + if isinstance(msg, bytes): + # Depending on the StringIO flavor, it may only accept unicode. + msg = msg.decode('utf-8', 'replace') + DebugInfoHolder.DEBUG_STREAM.write(msg) + DebugInfoHolder.DEBUG_STREAM.flush() + except: + pass + return True + + +def _pydevd_log_exception(msg='', *args): + if msg or args: + _pydevd_log(0, msg, *args) + try: + traceback.print_exc(file=DebugInfoHolder.DEBUG_STREAM) + DebugInfoHolder.DEBUG_STREAM.flush() + except: + raise + + +def verbose(msg, *args): + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 3: + _pydevd_log(3, msg, *args) + + +def debug(msg, *args): + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 2: + _pydevd_log(2, msg, *args) + + +def info(msg, *args): + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: + _pydevd_log(1, msg, *args) + + +warn = info + + +def critical(msg, *args): + _pydevd_log(0, msg, *args) + + +def exception(msg='', *args): + try: + _pydevd_log_exception(msg, *args) + except: + pass # Should never fail (even at interpreter shutdown). + + +error = exception + + +def error_once(msg, *args): + try: + if args: + message = msg % args + else: + message = str(msg) + except: + message = '%s - %s' % (msg, args) + + if message not in WARN_ONCE_MAP: + WARN_ONCE_MAP[message] = True + critical(message) + + +def debug_once(msg, *args): + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 3: + error_once(msg, *args) + + +def show_compile_cython_command_line(): + if SHOW_COMPILE_CYTHON_COMMAND_LINE: + dirname = os.path.dirname(os.path.dirname(__file__)) + error_once("warning: Debugger speedups using cython not found. Run '\"%s\" \"%s\" build_ext --inplace' to build.", + sys.executable, os.path.join(dirname, 'setup_cython.py')) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py new file mode 100644 index 0000000..7009552 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py @@ -0,0 +1,791 @@ +# License: EPL +import os +import re +import sys +import traceback +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import get_global_debugger, IS_WINDOWS, IS_JYTHON, get_current_thread_id +from _pydev_bundle import pydev_log + +try: + xrange +except: + xrange = range + +#=============================================================================== +# Things that are dependent on having the pydevd debugger +#=============================================================================== + +pydev_src_dir = os.path.dirname(os.path.dirname(__file__)) + + +def _get_python_c_args(host, port, indC, args, setup): + host_literal = "'" + host + "'" if host is not None else 'None' + return ("import sys; sys.path.append(r'%s'); import pydevd; " + "pydevd.settrace(host=%s, port=%s, suspend=False, trace_only_current_thread=False, patch_multiprocessing=True); " + "from pydevd import SetupHolder; SetupHolder.setup = %s; %s" + ) % ( + pydev_src_dir, + host_literal, + port, + setup, + args[indC + 1]) + + +def _get_host_port(): + import pydevd + host, port = pydevd.dispatch() + return host, port + + +def _is_managed_arg(arg): + if arg.endswith('pydevd.py'): + return True + return False + + +def _on_forked_process(): + import pydevd + pydevd.threadingCurrentThread().__pydevd_main_thread = True + pydevd.settrace_forked() + + +def _on_set_trace_for_new_thread(global_debugger): + if global_debugger is not None: + global_debugger.enable_tracing() + + +#=============================================================================== +# Things related to monkey-patching +#=============================================================================== +def is_python(path): + if path.endswith("'") or path.endswith('"'): + path = path[1:len(path) - 1] + filename = os.path.basename(path).lower() + for name in ['python', 'jython', 'pypy']: + if filename.find(name) != -1: + return True + + return False + + +def remove_quotes_from_args(args): + if sys.platform == "win32": + new_args = [] + for x in args: + if x != '""': + if len(x) > 1 and x.startswith('"') and x.endswith('"'): + x = x[1:-1] + new_args.append(x) + return new_args + else: + return args + + +def quote_arg_win32(arg): + # See if we need to quote at all - empty strings need quoting, as do strings + # with whitespace or quotes in them. Backslashes do not need quoting. + if arg and not set(arg).intersection(' "\t\n\v'): + return arg + + # Per https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw, + # the standard way to interpret arguments in double quotes is as follows: + # + # 2N backslashes followed by a quotation mark produce N backslashes followed by + # begin/end quote. This does not become part of the parsed argument, but toggles + # the "in quotes" mode. + # + # 2N+1 backslashes followed by a quotation mark again produce N backslashes followed + # by a quotation mark literal ("). This does not toggle the "in quotes" mode. + # + # N backslashes not followed by a quotation mark simply produce N backslashes. + # + # This code needs to do the reverse transformation, thus: + # + # N backslashes followed by " produce 2N+1 backslashes followed by " + # + # N backslashes at the end (i.e. where the closing " goes) produce 2N backslashes. + # + # N backslashes in any other position remain as is. + + arg = re.sub(r'(\\*)\"', r'\1\1\\"', arg) + arg = re.sub(r'(\\*)$', r'\1\1', arg) + return '"' + arg + '"' + + +def quote_args(args): + if sys.platform == "win32": + return list(map(quote_arg_win32, args)) + else: + return args + + +def get_c_option_index(args): + """ + Get index of "-c" argument and check if it's interpreter's option + :param args: list of arguments + :return: index of "-c" if it's an interpreter's option and -1 if it doesn't exist or program's option + """ + try: + ind_c = args.index('-c') + except ValueError: + return -1 + else: + for i in range(1, ind_c): + if not args[i].startswith('-'): + # there is an arg without "-" before "-c", so it's not an interpreter's option + return -1 + return ind_c + + +def patch_args(args): + try: + pydev_log.debug("Patching args: %s", args) + args = remove_quotes_from_args(args) + + from pydevd import SetupHolder + new_args = [] + if len(args) == 0: + return args + + if is_python(args[0]): + ind_c = get_c_option_index(args) + + if ind_c != -1: + host, port = _get_host_port() + + if port is not None: + new_args.extend(args) + new_args[ind_c + 1] = _get_python_c_args(host, port, ind_c, args, SetupHolder.setup) + return quote_args(new_args) + else: + # Check for Python ZIP Applications and don't patch the args for them. + # Assumes the first non `-` argument is what we need to check. + # There's probably a better way to determine this but it works for most cases. + continue_next = False + for i in range(1, len(args)): + if continue_next: + continue_next = False + continue + + arg = args[i] + if arg.startswith('-'): + # Skip the next arg too if this flag expects a value. + continue_next = arg in ['-m', '-W', '-X'] + continue + + if arg.rsplit('.')[-1] in ['zip', 'pyz', 'pyzw']: + pydev_log.debug('Executing a PyZip, returning') + return args + break + + new_args.append(args[0]) + else: + pydev_log.debug("Process is not python, returning.") + return args + + i = 1 + # Original args should be something as: + # ['X:\\pysrc\\pydevd.py', '--multiprocess', '--print-in-debugger-startup', + # '--vm_type', 'python', '--client', '127.0.0.1', '--port', '56352', '--file', 'x:\\snippet1.py'] + from _pydevd_bundle.pydevd_command_line_handling import setup_to_argv + original = setup_to_argv(SetupHolder.setup) + ['--file'] + while i < len(args): + if args[i] == '-m': + # Always insert at pos == 1 (i.e.: pydevd "--module" --multiprocess ...) + original.insert(1, '--module') + else: + if args[i].startswith('-'): + new_args.append(args[i]) + else: + break + i += 1 + + # Note: undoing https://github.com/Elizaveta239/PyDev.Debugger/commit/053c9d6b1b455530bca267e7419a9f63bf51cddf + # (i >= len(args) instead of i < len(args)) + # in practice it'd raise an exception here and would return original args, which is not what we want... providing + # a proper fix for https://youtrack.jetbrains.com/issue/PY-9767 elsewhere. + if i < len(args) and _is_managed_arg(args[i]): # no need to add pydevd twice + return args + + for x in original: + new_args.append(x) + if x == '--file': + break + + while i < len(args): + new_args.append(args[i]) + i += 1 + + return quote_args(new_args) + except: + pydev_log.exception('Error patching args') + return args + + +def str_to_args_windows(args): + # See https://docs.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments. + # + # Implemetation ported from DebugPlugin.parseArgumentsWindows: + # https://github.com/eclipse/eclipse.platform.debug/blob/master/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java + + result = [] + + DEFAULT = 0 + ARG = 1 + IN_DOUBLE_QUOTE = 2 + + state = DEFAULT + backslashes = 0 + buf = '' + + args_len = len(args) + for i in xrange(args_len): + ch = args[i] + if (ch == '\\'): + backslashes += 1 + continue + elif (backslashes != 0): + if ch == '"': + while backslashes >= 2: + backslashes -= 2 + buf += '\\' + if (backslashes == 1): + if (state == DEFAULT): + state = ARG + + buf += '"' + backslashes = 0 + continue + # else fall through to switch + else: + # false alarm, treat passed backslashes literally... + if (state == DEFAULT): + state = ARG + + while backslashes > 0: + backslashes -= 1 + buf += '\\' + # fall through to switch + if ch in (' ', '\t'): + if (state == DEFAULT): + # skip + continue + elif (state == ARG): + state = DEFAULT + result.append(buf) + buf = '' + continue + + if state in (DEFAULT, ARG): + if ch == '"': + state = IN_DOUBLE_QUOTE + else: + state = ARG + buf += ch + + elif state == IN_DOUBLE_QUOTE: + if ch == '"': + if (i + 1 < args_len and args[i + 1] == '"'): + # Undocumented feature in Windows: + # Two consecutive double quotes inside a double-quoted argument are interpreted as + # a single double quote. + buf += '"' + i += 1 + else: + state = ARG + else: + buf += ch + + else: + raise RuntimeError('Illegal condition') + + if len(buf) > 0 or state != DEFAULT: + result.append(buf) + + return result + + +def patch_arg_str_win(arg_str): + args = str_to_args_windows(arg_str) + # Fix https://youtrack.jetbrains.com/issue/PY-9767 (args may be empty) + if not args or not is_python(args[0]): + return arg_str + arg_str = ' '.join(patch_args(args)) + pydev_log.debug("New args: %s", arg_str) + return arg_str + + +def monkey_patch_module(module, funcname, create_func): + if hasattr(module, funcname): + original_name = 'original_' + funcname + if not hasattr(module, original_name): + setattr(module, original_name, getattr(module, funcname)) + setattr(module, funcname, create_func(original_name)) + + +def monkey_patch_os(funcname, create_func): + monkey_patch_module(os, funcname, create_func) + + +def warn_multiproc(): + pass # TODO: Provide logging as messages to the IDE. + # pydev_log.error_once( + # "pydev debugger: New process is launching (breakpoints won't work in the new process).\n" + # "pydev debugger: To debug that process please enable 'Attach to subprocess automatically while debugging?' option in the debugger settings.\n") + # + + +def create_warn_multiproc(original_name): + + def new_warn_multiproc(*args): + import os + + warn_multiproc() + + return getattr(os, original_name)(*args) + + return new_warn_multiproc + + +def create_execl(original_name): + + def new_execl(path, *args): + """ + os.execl(path, arg0, arg1, ...) + os.execle(path, arg0, arg1, ..., env) + os.execlp(file, arg0, arg1, ...) + os.execlpe(file, arg0, arg1, ..., env) + """ + import os + args = patch_args(args) + send_process_created_message() + return getattr(os, original_name)(path, *args) + + return new_execl + + +def create_execv(original_name): + + def new_execv(path, args): + """ + os.execv(path, args) + os.execvp(file, args) + """ + import os + send_process_created_message() + return getattr(os, original_name)(path, patch_args(args)) + + return new_execv + + +def create_execve(original_name): + """ + os.execve(path, args, env) + os.execvpe(file, args, env) + """ + + def new_execve(path, args, env): + import os + send_process_created_message() + return getattr(os, original_name)(path, patch_args(args), env) + + return new_execve + + +def create_spawnl(original_name): + + def new_spawnl(mode, path, *args): + """ + os.spawnl(mode, path, arg0, arg1, ...) + os.spawnlp(mode, file, arg0, arg1, ...) + """ + import os + args = patch_args(args) + send_process_created_message() + return getattr(os, original_name)(mode, path, *args) + + return new_spawnl + + +def create_spawnv(original_name): + + def new_spawnv(mode, path, args): + """ + os.spawnv(mode, path, args) + os.spawnvp(mode, file, args) + """ + import os + send_process_created_message() + return getattr(os, original_name)(mode, path, patch_args(args)) + + return new_spawnv + + +def create_spawnve(original_name): + """ + os.spawnve(mode, path, args, env) + os.spawnvpe(mode, file, args, env) + """ + + def new_spawnve(mode, path, args, env): + import os + send_process_created_message() + return getattr(os, original_name)(mode, path, patch_args(args), env) + + return new_spawnve + + +def create_fork_exec(original_name): + """ + _posixsubprocess.fork_exec(args, executable_list, close_fds, ... (13 more)) + """ + + def new_fork_exec(args, *other_args): + import _posixsubprocess # @UnresolvedImport + args = patch_args(args) + send_process_created_message() + return getattr(_posixsubprocess, original_name)(args, *other_args) + + return new_fork_exec + + +def create_warn_fork_exec(original_name): + """ + _posixsubprocess.fork_exec(args, executable_list, close_fds, ... (13 more)) + """ + + def new_warn_fork_exec(*args): + try: + import _posixsubprocess + warn_multiproc() + return getattr(_posixsubprocess, original_name)(*args) + except: + pass + + return new_warn_fork_exec + + +def create_CreateProcess(original_name): + """ + CreateProcess(*args, **kwargs) + """ + + def new_CreateProcess(app_name, cmd_line, *args): + try: + import _subprocess + except ImportError: + import _winapi as _subprocess + send_process_created_message() + return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args) + + return new_CreateProcess + + +def create_CreateProcessWarnMultiproc(original_name): + """ + CreateProcess(*args, **kwargs) + """ + + def new_CreateProcess(*args): + try: + import _subprocess + except ImportError: + import _winapi as _subprocess + warn_multiproc() + return getattr(_subprocess, original_name)(*args) + + return new_CreateProcess + + +def create_fork(original_name): + + def new_fork(): + import os + + # A simple fork will result in a new python process + is_new_python_process = True + frame = sys._getframe() + + while frame is not None: + if frame.f_code.co_name == '_execute_child' and 'subprocess' in frame.f_code.co_filename: + # If we're actually in subprocess.Popen creating a child, it may + # result in something which is not a Python process, (so, we + # don't want to connect with it in the forked version). + executable = frame.f_locals.get('executable') + if executable is not None: + is_new_python_process = False + if is_python(executable): + is_new_python_process = True + break + + frame = frame.f_back + frame = None # Just make sure we don't hold on to it. + + child_process = getattr(os, original_name)() # fork + if not child_process: + if is_new_python_process: + _on_forked_process() + else: + if is_new_python_process: + send_process_created_message() + return child_process + + return new_fork + + +def send_process_created_message(): + debugger = get_global_debugger() + if debugger is not None: + debugger.send_process_created_message() + + +def patch_new_process_functions(): + # os.execl(path, arg0, arg1, ...) + # os.execle(path, arg0, arg1, ..., env) + # os.execlp(file, arg0, arg1, ...) + # os.execlpe(file, arg0, arg1, ..., env) + # os.execv(path, args) + # os.execve(path, args, env) + # os.execvp(file, args) + # os.execvpe(file, args, env) + monkey_patch_os('execl', create_execl) + monkey_patch_os('execle', create_execl) + monkey_patch_os('execlp', create_execl) + monkey_patch_os('execlpe', create_execl) + monkey_patch_os('execv', create_execv) + monkey_patch_os('execve', create_execve) + monkey_patch_os('execvp', create_execv) + monkey_patch_os('execvpe', create_execve) + + # os.spawnl(mode, path, ...) + # os.spawnle(mode, path, ..., env) + # os.spawnlp(mode, file, ...) + # os.spawnlpe(mode, file, ..., env) + # os.spawnv(mode, path, args) + # os.spawnve(mode, path, args, env) + # os.spawnvp(mode, file, args) + # os.spawnvpe(mode, file, args, env) + + monkey_patch_os('spawnl', create_spawnl) + monkey_patch_os('spawnle', create_spawnl) + monkey_patch_os('spawnlp', create_spawnl) + monkey_patch_os('spawnlpe', create_spawnl) + monkey_patch_os('spawnv', create_spawnv) + monkey_patch_os('spawnve', create_spawnve) + monkey_patch_os('spawnvp', create_spawnv) + monkey_patch_os('spawnvpe', create_spawnve) + + if not IS_JYTHON: + if not IS_WINDOWS: + monkey_patch_os('fork', create_fork) + try: + import _posixsubprocess + monkey_patch_module(_posixsubprocess, 'fork_exec', create_fork_exec) + except ImportError: + pass + else: + # Windows + try: + import _subprocess + except ImportError: + import _winapi as _subprocess + monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcess) + + +def patch_new_process_functions_with_warning(): + monkey_patch_os('execl', create_warn_multiproc) + monkey_patch_os('execle', create_warn_multiproc) + monkey_patch_os('execlp', create_warn_multiproc) + monkey_patch_os('execlpe', create_warn_multiproc) + monkey_patch_os('execv', create_warn_multiproc) + monkey_patch_os('execve', create_warn_multiproc) + monkey_patch_os('execvp', create_warn_multiproc) + monkey_patch_os('execvpe', create_warn_multiproc) + monkey_patch_os('spawnl', create_warn_multiproc) + monkey_patch_os('spawnle', create_warn_multiproc) + monkey_patch_os('spawnlp', create_warn_multiproc) + monkey_patch_os('spawnlpe', create_warn_multiproc) + monkey_patch_os('spawnv', create_warn_multiproc) + monkey_patch_os('spawnve', create_warn_multiproc) + monkey_patch_os('spawnvp', create_warn_multiproc) + monkey_patch_os('spawnvpe', create_warn_multiproc) + + if not IS_JYTHON: + if not IS_WINDOWS: + monkey_patch_os('fork', create_warn_multiproc) + try: + import _posixsubprocess + monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec) + except ImportError: + pass + else: + # Windows + try: + import _subprocess + except ImportError: + import _winapi as _subprocess + monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc) + + +class _NewThreadStartupWithTrace: + + def __init__(self, original_func, args, kwargs): + self.original_func = original_func + self.args = args + self.kwargs = kwargs + + def __call__(self): + # We monkey-patch the thread creation so that this function is called in the new thread. At this point + # we notify of its creation and start tracing it. + global_debugger = get_global_debugger() + + thread_id = None + if global_debugger is not None: + # Note: if this is a thread from threading.py, we're too early in the boostrap process (because we mocked + # the start_new_thread internal machinery and thread._bootstrap has not finished), so, the code below needs + # to make sure that we use the current thread bound to the original function and not use + # threading.currentThread() unless we're sure it's a dummy thread. + t = getattr(self.original_func, '__self__', getattr(self.original_func, 'im_self', None)) + if not isinstance(t, threading.Thread): + # This is not a threading.Thread but a Dummy thread (so, get it as a dummy thread using + # currentThread). + t = threading.currentThread() + + if not getattr(t, 'is_pydev_daemon_thread', False): + thread_id = get_current_thread_id(t) + global_debugger.notify_thread_created(thread_id, t) + _on_set_trace_for_new_thread(global_debugger) + + if getattr(global_debugger, 'thread_analyser', None) is not None: + try: + from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread + log_new_thread(global_debugger, t) + except: + sys.stderr.write("Failed to detect new thread for visualization") + try: + ret = self.original_func(*self.args, **self.kwargs) + finally: + if thread_id is not None: + global_debugger.notify_thread_not_alive(thread_id) + + return ret + + +class _NewThreadStartupWithoutTrace: + + def __init__(self, original_func, args, kwargs): + self.original_func = original_func + self.args = args + self.kwargs = kwargs + + def __call__(self): + return self.original_func(*self.args, **self.kwargs) + + +_UseNewThreadStartup = _NewThreadStartupWithTrace + + +def _get_threading_modules_to_patch(): + threading_modules_to_patch = [] + + try: + import thread as _thread + except: + import _thread + threading_modules_to_patch.append(_thread) + threading_modules_to_patch.append(threading) + + return threading_modules_to_patch + + +threading_modules_to_patch = _get_threading_modules_to_patch() + + +def patch_thread_module(thread_module): + + if getattr(thread_module, '_original_start_new_thread', None) is None: + if thread_module is threading: + if not hasattr(thread_module, '_start_new_thread'): + return # Jython doesn't have it. + _original_start_new_thread = thread_module._original_start_new_thread = thread_module._start_new_thread + else: + _original_start_new_thread = thread_module._original_start_new_thread = thread_module.start_new_thread + else: + _original_start_new_thread = thread_module._original_start_new_thread + + class ClassWithPydevStartNewThread: + + def pydev_start_new_thread(self, function, args=(), kwargs={}): + ''' + We need to replace the original thread_module.start_new_thread with this function so that threads started + through it and not through the threading module are properly traced. + ''' + return _original_start_new_thread(_UseNewThreadStartup(function, args, kwargs), ()) + + # This is a hack for the situation where the thread_module.start_new_thread is declared inside a class, such as the one below + # class F(object): + # start_new_thread = thread_module.start_new_thread + # + # def start_it(self): + # self.start_new_thread(self.function, args, kwargs) + # So, if it's an already bound method, calling self.start_new_thread won't really receive a different 'self' -- it + # does work in the default case because in builtins self isn't passed either. + pydev_start_new_thread = ClassWithPydevStartNewThread().pydev_start_new_thread + + try: + # We need to replace the original thread_module.start_new_thread with this function so that threads started through + # it and not through the threading module are properly traced. + if thread_module is threading: + thread_module._start_new_thread = pydev_start_new_thread + else: + thread_module.start_new_thread = pydev_start_new_thread + thread_module.start_new = pydev_start_new_thread + except: + pass + + +def patch_thread_modules(): + for t in threading_modules_to_patch: + patch_thread_module(t) + + +def undo_patch_thread_modules(): + for t in threading_modules_to_patch: + try: + t.start_new_thread = t._original_start_new_thread + except: + pass + + try: + t.start_new = t._original_start_new_thread + except: + pass + + try: + t._start_new_thread = t._original_start_new_thread + except: + pass + + +def disable_trace_thread_modules(): + ''' + Can be used to temporarily stop tracing threads created with thread.start_new_thread. + ''' + global _UseNewThreadStartup + _UseNewThreadStartup = _NewThreadStartupWithoutTrace + + +def enable_trace_thread_modules(): + ''' + Can be used to start tracing threads created with thread.start_new_thread again. + ''' + global _UseNewThreadStartup + _UseNewThreadStartup = _NewThreadStartupWithTrace + + +def get_original_start_new_thread(threading_module): + try: + return threading_module._original_start_new_thread + except: + return threading_module.start_new_thread diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey_qt.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey_qt.py new file mode 100644 index 0000000..75d5fbf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey_qt.py @@ -0,0 +1,208 @@ +from __future__ import nested_scopes + +from _pydev_imps._pydev_saved_modules import threading +import os + +def set_trace_in_qt(): + from _pydevd_bundle.pydevd_comm import get_global_debugger + debugger = get_global_debugger() + if debugger is not None: + threading.current_thread() # Create the dummy thread for qt. + debugger.enable_tracing() + + +_patched_qt = False +def patch_qt(qt_support_mode): + ''' + This method patches qt (PySide, PyQt4, PyQt5) so that we have hooks to set the tracing for QThread. + ''' + if not qt_support_mode: + return + + if qt_support_mode is True or qt_support_mode == 'True': + # do not break backward compatibility + qt_support_mode = 'auto' + + if qt_support_mode == 'auto': + qt_support_mode = os.getenv('PYDEVD_PYQT_MODE', 'auto') + + # Avoid patching more than once + global _patched_qt + if _patched_qt: + return + + _patched_qt = True + + if qt_support_mode == 'auto': + + patch_qt_on_import = None + try: + import PySide2 # @UnresolvedImport @UnusedImport + qt_support_mode = 'pyside2' + except: + try: + import Pyside # @UnresolvedImport @UnusedImport + qt_support_mode = 'pyside' + except: + try: + import PyQt5 # @UnresolvedImport @UnusedImport + qt_support_mode = 'pyqt5' + except: + try: + import PyQt4 # @UnresolvedImport @UnusedImport + qt_support_mode = 'pyqt4' + except: + return + + if qt_support_mode == 'pyside2': + try: + import PySide2.QtCore # @UnresolvedImport + _internal_patch_qt(PySide2.QtCore, qt_support_mode) + except: + return + + elif qt_support_mode == 'pyside': + try: + import PySide.QtCore # @UnresolvedImport + _internal_patch_qt(PySide.QtCore, qt_support_mode) + except: + return + + elif qt_support_mode == 'pyqt5': + try: + import PyQt5.QtCore # @UnresolvedImport + _internal_patch_qt(PyQt5.QtCore) + except: + return + + elif qt_support_mode == 'pyqt4': + # Ok, we have an issue here: + # PyDev-452: Selecting PyQT API version using sip.setapi fails in debug mode + # http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html + # Mostly, if the user uses a different API version (i.e.: v2 instead of v1), + # that has to be done before importing PyQt4 modules (PySide/PyQt5 don't have this issue + # as they only implements v2). + patch_qt_on_import = 'PyQt4' + def get_qt_core_module(): + import PyQt4.QtCore # @UnresolvedImport + return PyQt4.QtCore + _patch_import_to_patch_pyqt_on_import(patch_qt_on_import, get_qt_core_module) + + else: + raise ValueError('Unexpected qt support mode: %s' % (qt_support_mode,)) + + +def _patch_import_to_patch_pyqt_on_import(patch_qt_on_import, get_qt_core_module): + # I don't like this approach very much as we have to patch __import__, but I like even less + # asking the user to configure something in the client side... + # So, our approach is to patch PyQt4 right before the user tries to import it (at which + # point he should've set the sip api version properly already anyways). + + dotted = patch_qt_on_import + '.' + original_import = __import__ + + from _pydev_imps._pydev_sys_patch import patch_sys_module, patch_reload, cancel_patches_in_sys_module + + patch_sys_module() + patch_reload() + + def patched_import(name, *args, **kwargs): + if patch_qt_on_import == name or name.startswith(dotted): + builtins.__import__ = original_import + cancel_patches_in_sys_module() + _internal_patch_qt(get_qt_core_module()) # Patch it only when the user would import the qt module + return original_import(name, *args, **kwargs) + + import sys + if sys.version_info[0] >= 3: + import builtins # Py3 + else: + import __builtin__ as builtins + + builtins.__import__ = patched_import + + +def _internal_patch_qt(QtCore, qt_support_mode='auto'): + _original_thread_init = QtCore.QThread.__init__ + _original_runnable_init = QtCore.QRunnable.__init__ + _original_QThread = QtCore.QThread + + class FuncWrapper: + def __init__(self, original): + self._original = original + + def __call__(self, *args, **kwargs): + set_trace_in_qt() + return self._original(*args, **kwargs) + + class StartedSignalWrapper(QtCore.QObject): # Wrapper for the QThread.started signal + + try: + _signal = QtCore.Signal() # @UndefinedVariable + except: + _signal = QtCore.pyqtSignal() # @UndefinedVariable + + def __init__(self, thread, original_started): + QtCore.QObject.__init__(self) + self.thread = thread + self.original_started = original_started + if qt_support_mode in ('pyside', 'pyside2'): + self._signal = original_started + else: + self._signal.connect(self._on_call) + self.original_started.connect(self._signal) + + def connect(self, func, *args, **kwargs): + if qt_support_mode in ('pyside', 'pyside2'): + return self._signal.connect(FuncWrapper(func), *args, **kwargs) + else: + return self._signal.connect(func, *args, **kwargs) + + def disconnect(self, *args, **kwargs): + return self._signal.disconnect(*args, **kwargs) + + def emit(self, *args, **kwargs): + return self._signal.emit(*args, **kwargs) + + def _on_call(self, *args, **kwargs): + set_trace_in_qt() + + class ThreadWrapper(QtCore.QThread): # Wrapper for QThread + + def __init__(self, *args, **kwargs): + _original_thread_init(self, *args, **kwargs) + + # In PyQt5 the program hangs when we try to call original run method of QThread class. + # So we need to distinguish instances of QThread class and instances of QThread inheritors. + if self.__class__.run == _original_QThread.run: + self.run = self._exec_run + else: + self._original_run = self.run + self.run = self._new_run + self._original_started = self.started + self.started = StartedSignalWrapper(self, self.started) + + def _exec_run(self): + set_trace_in_qt() + self.exec_() + return None + + def _new_run(self): + set_trace_in_qt() + return self._original_run() + + class RunnableWrapper(QtCore.QRunnable): # Wrapper for QRunnable + + def __init__(self, *args, **kwargs): + _original_runnable_init(self, *args, **kwargs) + + self._original_run = self.run + self.run = self._new_run + + + def _new_run(self): + set_trace_in_qt() + return self._original_run() + + QtCore.QThread = ThreadWrapper + QtCore.QRunnable = RunnableWrapper diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_override.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_override.py new file mode 100644 index 0000000..d7581d2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_override.py @@ -0,0 +1,35 @@ +def overrides(method): + ''' + Meant to be used as + + class B: + @overrides(A.m1) + def m1(self): + pass + ''' + def wrapper(func): + if func.__name__ != method.__name__: + msg = "Wrong @override: %r expected, but overwriting %r." + msg = msg % (func.__name__, method.__name__) + raise AssertionError(msg) + + if func.__doc__ is None: + func.__doc__ = method.__doc__ + + return func + + return wrapper + +def implements(method): + def wrapper(func): + if func.__name__ != method.__name__: + msg = "Wrong @implements: %r expected, but implementing %r." + msg = msg % (func.__name__, method.__name__) + raise AssertionError(msg) + + if func.__doc__ is None: + func.__doc__ = method.__doc__ + + return func + + return wrapper \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_umd.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_umd.py new file mode 100644 index 0000000..0bfeda7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_umd.py @@ -0,0 +1,172 @@ +""" +The UserModuleDeleter and runfile methods are copied from +Spyder and carry their own license agreement. +http://code.google.com/p/spyderlib/source/browse/spyderlib/widgets/externalshell/sitecustomize.py + +Spyder License Agreement (MIT License) +-------------------------------------- + +Copyright (c) 2009-2012 Pierre Raybaut + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + +import sys +import os + +# The following classes and functions are mainly intended to be used from +# an interactive Python session +class UserModuleDeleter: + """ + User Module Deleter (UMD) aims at deleting user modules + to force Python to deeply reload them during import + + pathlist [list]: blacklist in terms of module path + namelist [list]: blacklist in terms of module name + """ + def __init__(self, namelist=None, pathlist=None): + if namelist is None: + namelist = [] + self.namelist = namelist + if pathlist is None: + pathlist = [] + self.pathlist = pathlist + try: + # blacklist all files in org.python.pydev/pysrc + import pydev_pysrc, inspect + self.pathlist.append(os.path.dirname(pydev_pysrc.__file__)) + except: + pass + self.previous_modules = list(sys.modules.keys()) + + def is_module_blacklisted(self, modname, modpath): + for path in [sys.prefix] + self.pathlist: + if modpath.startswith(path): + return True + else: + return set(modname.split('.')) & set(self.namelist) + + def run(self, verbose=False): + """ + Del user modules to force Python to deeply reload them + + Do not del modules which are considered as system modules, i.e. + modules installed in subdirectories of Python interpreter's binary + Do not del C modules + """ + log = [] + modules_copy = dict(sys.modules) + for modname, module in modules_copy.items(): + if modname == 'aaaaa': + print(modname, module) + print(self.previous_modules) + if modname not in self.previous_modules: + modpath = getattr(module, '__file__', None) + if modpath is None: + # *module* is a C module that is statically linked into the + # interpreter. There is no way to know its path, so we + # choose to ignore it. + continue + if not self.is_module_blacklisted(modname, modpath): + log.append(modname) + del sys.modules[modname] + if verbose and log: + print("\x1b[4;33m%s\x1b[24m%s\x1b[0m" % ("UMD has deleted", + ": " + ", ".join(log))) + +__umd__ = None + +_get_globals_callback = None +def _set_globals_function(get_globals): + global _get_globals_callback + _get_globals_callback = get_globals +def _get_globals(): + """Return current Python interpreter globals namespace""" + if _get_globals_callback is not None: + return _get_globals_callback() + else: + try: + from __main__ import __dict__ as namespace + except ImportError: + try: + # The import fails on IronPython + import __main__ + namespace = __main__.__dict__ + except: + namespace + shell = namespace.get('__ipythonshell__') + if shell is not None and hasattr(shell, 'user_ns'): + # IPython 0.12+ kernel + return shell.user_ns + else: + # Python interpreter + return namespace + return namespace + + +def runfile(filename, args=None, wdir=None, namespace=None): + """ + Run filename + args: command line arguments (string) + wdir: working directory + """ + try: + if hasattr(filename, 'decode'): + filename = filename.decode('utf-8') + except (UnicodeError, TypeError): + pass + global __umd__ + if os.environ.get("PYDEV_UMD_ENABLED", "").lower() == "true": + if __umd__ is None: + namelist = os.environ.get("PYDEV_UMD_NAMELIST", None) + if namelist is not None: + namelist = namelist.split(',') + __umd__ = UserModuleDeleter(namelist=namelist) + else: + verbose = os.environ.get("PYDEV_UMD_VERBOSE", "").lower() == "true" + __umd__.run(verbose=verbose) + if args is not None and not isinstance(args, basestring): + raise TypeError("expected a character buffer object") + if namespace is None: + namespace = _get_globals() + if '__file__' in namespace: + old_file = namespace['__file__'] + else: + old_file = None + namespace['__file__'] = filename + sys.argv = [filename] + if args is not None: + for arg in args.split(): + sys.argv.append(arg) + if wdir is not None: + try: + if hasattr(wdir, 'decode'): + wdir = wdir.decode('utf-8') + except (UnicodeError, TypeError): + pass + os.chdir(wdir) + execfile(filename, namespace) + sys.argv = [''] + if old_file is None: + del namespace['__file__'] + else: + namespace['__file__'] = old_file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_versioncheck.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_versioncheck.py new file mode 100644 index 0000000..70bf765 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_versioncheck.py @@ -0,0 +1,16 @@ +import sys + +def versionok_for_gui(): + ''' Return True if running Python is suitable for GUI Event Integration and deeper IPython integration ''' + # We require Python 2.6+ ... + if sys.hexversion < 0x02060000: + return False + # Or Python 3.2+ + if sys.hexversion >= 0x03000000 and sys.hexversion < 0x03020000: + return False + # Not supported under Jython nor IronPython + if sys.platform.startswith("java") or sys.platform.startswith('cli'): + return False + + return True + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_BaseHTTPServer.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_BaseHTTPServer.py new file mode 100644 index 0000000..f8dd911 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_BaseHTTPServer.py @@ -0,0 +1,604 @@ +"""HTTP server base class. + +Note: the class in this module doesn't implement any HTTP request; see +SimpleHTTPServer for simple implementations of GET, HEAD and POST +(including CGI scripts). It does, however, optionally implement HTTP/1.1 +persistent connections, as of version 0.3. + +Contents: + +- BaseHTTPRequestHandler: HTTP request handler base class +- test: test function + +XXX To do: + +- log requests even later (to capture byte count) +- log user-agent header and other interesting goodies +- send error log to separate file +""" + + +# See also: +# +# HTTP Working Group T. Berners-Lee +# INTERNET-DRAFT R. T. Fielding +# H. Frystyk Nielsen +# Expires September 8, 1995 March 8, 1995 +# +# URL: http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt +# +# and +# +# Network Working Group R. Fielding +# Request for Comments: 2616 et al +# Obsoletes: 2068 June 1999 +# Category: Standards Track +# +# URL: http://www.faqs.org/rfcs/rfc2616.html + +# Log files +# --------- +# +# Here's a quote from the NCSA httpd docs about log file format. +# +# | The logfile format is as follows. Each line consists of: +# | +# | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb +# | +# | host: Either the DNS name or the IP number of the remote client +# | rfc931: Any information returned by identd for this person, +# | - otherwise. +# | authuser: If user sent a userid for authentication, the user name, +# | - otherwise. +# | DD: Day +# | Mon: Month (calendar name) +# | YYYY: Year +# | hh: hour (24-hour format, the machine's timezone) +# | mm: minutes +# | ss: seconds +# | request: The first line of the HTTP request as sent by the client. +# | ddd: the status code returned by the server, - if not available. +# | bbbb: the total number of bytes sent, +# | *not including the HTTP/1.0 header*, - if not available +# | +# | You can determine the name of the file accessed through request. +# +# (Actually, the latter is only true if you know the server configuration +# at the time the request was made!) + +__version__ = "0.3" + +__all__ = ["HTTPServer", "BaseHTTPRequestHandler"] + +import sys +from _pydev_imps._pydev_saved_modules import time +from _pydev_imps._pydev_saved_modules import socket +from warnings import filterwarnings, catch_warnings +with catch_warnings(): + if sys.py3kwarning: + filterwarnings("ignore", ".*mimetools has been removed", + DeprecationWarning) + import mimetools + +from _pydev_imps import _pydev_SocketServer as SocketServer + +# Default error message template +DEFAULT_ERROR_MESSAGE = """\ + +Error response + + +

Error response

+

Error code %(code)d. +

Message: %(message)s. +

Error code explanation: %(code)s = %(explain)s. + +""" + +DEFAULT_ERROR_CONTENT_TYPE = "text/html" + +def _quote_html(html): + return html.replace("&", "&").replace("<", "<").replace(">", ">") + +class HTTPServer(SocketServer.TCPServer): + + allow_reuse_address = 1 # Seems to make sense in testing environment + + def server_bind(self): + """Override server_bind to store the server name.""" + SocketServer.TCPServer.server_bind(self) + host, port = self.socket.getsockname()[:2] + self.server_name = socket.getfqdn(host) + self.server_port = port + + +class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): + + """HTTP request handler base class. + + The following explanation of HTTP serves to guide you through the + code as well as to expose any misunderstandings I may have about + HTTP (so you don't need to read the code to figure out I'm wrong + :-). + + HTTP (HyperText Transfer Protocol) is an extensible protocol on + top of a reliable stream transport (e.g. TCP/IP). The protocol + recognizes three parts to a request: + + 1. One line identifying the request type and path + 2. An optional set of RFC-822-style headers + 3. An optional data part + + The headers and data are separated by a blank line. + + The first line of the request has the form + + + + where is a (case-sensitive) keyword such as GET or POST, + is a string containing path information for the request, + and should be the string "HTTP/1.0" or "HTTP/1.1". + is encoded using the URL encoding scheme (using %xx to signify + the ASCII character with hex code xx). + + The specification specifies that lines are separated by CRLF but + for compatibility with the widest range of clients recommends + servers also handle LF. Similarly, whitespace in the request line + is treated sensibly (allowing multiple spaces between components + and allowing trailing whitespace). + + Similarly, for output, lines ought to be separated by CRLF pairs + but most clients grok LF characters just fine. + + If the first line of the request has the form + + + + (i.e. is left out) then this is assumed to be an HTTP + 0.9 request; this form has no optional headers and data part and + the reply consists of just the data. + + The reply form of the HTTP 1.x protocol again has three parts: + + 1. One line giving the response code + 2. An optional set of RFC-822-style headers + 3. The data + + Again, the headers and data are separated by a blank line. + + The response code line has the form + + + + where is the protocol version ("HTTP/1.0" or "HTTP/1.1"), + is a 3-digit response code indicating success or + failure of the request, and is an optional + human-readable string explaining what the response code means. + + This server parses the request and the headers, and then calls a + function specific to the request type (). Specifically, + a request SPAM will be handled by a method do_SPAM(). If no + such method exists the server sends an error response to the + client. If it exists, it is called with no arguments: + + do_SPAM() + + Note that the request name is case sensitive (i.e. SPAM and spam + are different requests). + + The various request details are stored in instance variables: + + - client_address is the client IP address in the form (host, + port); + + - command, path and version are the broken-down request line; + + - headers is an instance of mimetools.Message (or a derived + class) containing the header information; + + - rfile is a file object open for reading positioned at the + start of the optional input data part; + + - wfile is a file object open for writing. + + IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING! + + The first thing to be written must be the response line. Then + follow 0 or more header lines, then a blank line, and then the + actual data (if any). The meaning of the header lines depends on + the command executed by the server; in most cases, when data is + returned, there should be at least one header line of the form + + Content-type: / + + where and should be registered MIME types, + e.g. "text/html" or "text/plain". + + """ + + # The Python system version, truncated to its first component. + sys_version = "Python/" + sys.version.split()[0] + + # The server software version. You may want to override this. + # The format is multiple whitespace-separated strings, + # where each string is of the form name[/version]. + server_version = "BaseHTTP/" + __version__ + + # The default request version. This only affects responses up until + # the point where the request line is parsed, so it mainly decides what + # the client gets back when sending a malformed request line. + # Most web servers default to HTTP 0.9, i.e. don't send a status line. + default_request_version = "HTTP/0.9" + + def parse_request(self): + """Parse a request (internal). + + The request should be stored in self.raw_requestline; the results + are in self.command, self.path, self.request_version and + self.headers. + + Return True for success, False for failure; on failure, an + error is sent back. + + """ + self.command = None # set in case of error on the first line + self.request_version = version = self.default_request_version + self.close_connection = 1 + requestline = self.raw_requestline + requestline = requestline.rstrip('\r\n') + self.requestline = requestline + words = requestline.split() + if len(words) == 3: + command, path, version = words + if version[:5] != 'HTTP/': + self.send_error(400, "Bad request version (%r)" % version) + return False + try: + base_version_number = version.split('/', 1)[1] + version_number = base_version_number.split(".") + # RFC 2145 section 3.1 says there can be only one "." and + # - major and minor numbers MUST be treated as + # separate integers; + # - HTTP/2.4 is a lower version than HTTP/2.13, which in + # turn is lower than HTTP/12.3; + # - Leading zeros MUST be ignored by recipients. + if len(version_number) != 2: + raise ValueError + version_number = int(version_number[0]), int(version_number[1]) + except (ValueError, IndexError): + self.send_error(400, "Bad request version (%r)" % version) + return False + if version_number >= (1, 1) and self.protocol_version >= "HTTP/1.1": + self.close_connection = 0 + if version_number >= (2, 0): + self.send_error(505, + "Invalid HTTP Version (%s)" % base_version_number) + return False + elif len(words) == 2: + command, path = words + self.close_connection = 1 + if command != 'GET': + self.send_error(400, + "Bad HTTP/0.9 request type (%r)" % command) + return False + elif not words: + return False + else: + self.send_error(400, "Bad request syntax (%r)" % requestline) + return False + self.command, self.path, self.request_version = command, path, version + + # Examine the headers and look for a Connection directive + self.headers = self.MessageClass(self.rfile, 0) + + conntype = self.headers.get('Connection', "") + if conntype.lower() == 'close': + self.close_connection = 1 + elif (conntype.lower() == 'keep-alive' and + self.protocol_version >= "HTTP/1.1"): + self.close_connection = 0 + return True + + def handle_one_request(self): + """Handle a single HTTP request. + + You normally don't need to override this method; see the class + __doc__ string for information on how to handle specific HTTP + commands such as GET and POST. + + """ + try: + self.raw_requestline = self.rfile.readline(65537) + if len(self.raw_requestline) > 65536: + self.requestline = '' + self.request_version = '' + self.command = '' + self.send_error(414) + return + if not self.raw_requestline: + self.close_connection = 1 + return + if not self.parse_request(): + # An error code has been sent, just exit + return + mname = 'do_' + self.command + if not hasattr(self, mname): + self.send_error(501, "Unsupported method (%r)" % self.command) + return + method = getattr(self, mname) + method() + self.wfile.flush() #actually send the response if not already done. + except socket.timeout: + #a read or a write timed out. Discard this connection + self.log_error("Request timed out: %r", sys.exc_info()[1]) + self.close_connection = 1 + return + + def handle(self): + """Handle multiple requests if necessary.""" + self.close_connection = 1 + + self.handle_one_request() + while not self.close_connection: + self.handle_one_request() + + def send_error(self, code, message=None): + """Send and log an error reply. + + Arguments are the error code, and a detailed message. + The detailed message defaults to the short entry matching the + response code. + + This sends an error response (so it must be called before any + output has been generated), logs the error, and finally sends + a piece of HTML explaining the error to the user. + + """ + + try: + short, long = self.responses[code] + except KeyError: + short, long = '???', '???' + if message is None: + message = short + explain = long + self.log_error("code %d, message %s", code, message) + # using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201) + content = (self.error_message_format % + {'code': code, 'message': _quote_html(message), 'explain': explain}) + self.send_response(code, message) + self.send_header("Content-Type", self.error_content_type) + self.send_header('Connection', 'close') + self.end_headers() + if self.command != 'HEAD' and code >= 200 and code not in (204, 304): + self.wfile.write(content) + + error_message_format = DEFAULT_ERROR_MESSAGE + error_content_type = DEFAULT_ERROR_CONTENT_TYPE + + def send_response(self, code, message=None): + """Send the response header and log the response code. + + Also send two standard headers with the server software + version and the current date. + + """ + self.log_request(code) + if message is None: + if code in self.responses: + message = self.responses[code][0] + else: + message = '' + if self.request_version != 'HTTP/0.9': + self.wfile.write("%s %d %s\r\n" % + (self.protocol_version, code, message)) + # print (self.protocol_version, code, message) + self.send_header('Server', self.version_string()) + self.send_header('Date', self.date_time_string()) + + def send_header(self, keyword, value): + """Send a MIME header.""" + if self.request_version != 'HTTP/0.9': + self.wfile.write("%s: %s\r\n" % (keyword, value)) + + if keyword.lower() == 'connection': + if value.lower() == 'close': + self.close_connection = 1 + elif value.lower() == 'keep-alive': + self.close_connection = 0 + + def end_headers(self): + """Send the blank line ending the MIME headers.""" + if self.request_version != 'HTTP/0.9': + self.wfile.write("\r\n") + + def log_request(self, code='-', size='-'): + """Log an accepted request. + + This is called by send_response(). + + """ + + self.log_message('"%s" %s %s', + self.requestline, str(code), str(size)) + + def log_error(self, format, *args): + """Log an error. + + This is called when a request cannot be fulfilled. By + default it passes the message on to log_message(). + + Arguments are the same as for log_message(). + + XXX This should go to the separate error log. + + """ + + self.log_message(format, *args) + + def log_message(self, format, *args): + """Log an arbitrary message. + + This is used by all other logging functions. Override + it if you have specific logging wishes. + + The first argument, FORMAT, is a format string for the + message to be logged. If the format string contains + any % escapes requiring parameters, they should be + specified as subsequent arguments (it's just like + printf!). + + The client host and current date/time are prefixed to + every message. + + """ + + sys.stderr.write("%s - - [%s] %s\n" % + (self.address_string(), + self.log_date_time_string(), + format%args)) + + def version_string(self): + """Return the server software version string.""" + return self.server_version + ' ' + self.sys_version + + def date_time_string(self, timestamp=None): + """Return the current date and time formatted for a message header.""" + if timestamp is None: + timestamp = time.time() + year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp) + s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % ( + self.weekdayname[wd], + day, self.monthname[month], year, + hh, mm, ss) + return s + + def log_date_time_string(self): + """Return the current time formatted for logging.""" + now = time.time() + year, month, day, hh, mm, ss, x, y, z = time.localtime(now) + s = "%02d/%3s/%04d %02d:%02d:%02d" % ( + day, self.monthname[month], year, hh, mm, ss) + return s + + weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] + + monthname = [None, + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] + + def address_string(self): + """Return the client address formatted for logging. + + This version looks up the full hostname using gethostbyaddr(), + and tries to find a name that contains at least one dot. + + """ + + host, port = self.client_address[:2] + return socket.getfqdn(host) + + # Essentially static class variables + + # The version of the HTTP protocol we support. + # Set this to HTTP/1.1 to enable automatic keepalive + protocol_version = "HTTP/1.0" + + # The Message-like class used to parse headers + MessageClass = mimetools.Message + + # Table mapping response codes to messages; entries have the + # form {code: (shortmessage, longmessage)}. + # See RFC 2616. + responses = { + 100: ('Continue', 'Request received, please continue'), + 101: ('Switching Protocols', + 'Switching to new protocol; obey Upgrade header'), + + 200: ('OK', 'Request fulfilled, document follows'), + 201: ('Created', 'Document created, URL follows'), + 202: ('Accepted', + 'Request accepted, processing continues off-line'), + 203: ('Non-Authoritative Information', 'Request fulfilled from cache'), + 204: ('No Content', 'Request fulfilled, nothing follows'), + 205: ('Reset Content', 'Clear input form for further input.'), + 206: ('Partial Content', 'Partial content follows.'), + + 300: ('Multiple Choices', + 'Object has several resources -- see URI list'), + 301: ('Moved Permanently', 'Object moved permanently -- see URI list'), + 302: ('Found', 'Object moved temporarily -- see URI list'), + 303: ('See Other', 'Object moved -- see Method and URL list'), + 304: ('Not Modified', + 'Document has not changed since given time'), + 305: ('Use Proxy', + 'You must use proxy specified in Location to access this ' + 'resource.'), + 307: ('Temporary Redirect', + 'Object moved temporarily -- see URI list'), + + 400: ('Bad Request', + 'Bad request syntax or unsupported method'), + 401: ('Unauthorized', + 'No permission -- see authorization schemes'), + 402: ('Payment Required', + 'No payment -- see charging schemes'), + 403: ('Forbidden', + 'Request forbidden -- authorization will not help'), + 404: ('Not Found', 'Nothing matches the given URI'), + 405: ('Method Not Allowed', + 'Specified method is invalid for this resource.'), + 406: ('Not Acceptable', 'URI not available in preferred format.'), + 407: ('Proxy Authentication Required', 'You must authenticate with ' + 'this proxy before proceeding.'), + 408: ('Request Timeout', 'Request timed out; try again later.'), + 409: ('Conflict', 'Request conflict.'), + 410: ('Gone', + 'URI no longer exists and has been permanently removed.'), + 411: ('Length Required', 'Client must specify Content-Length.'), + 412: ('Precondition Failed', 'Precondition in headers is false.'), + 413: ('Request Entity Too Large', 'Entity is too large.'), + 414: ('Request-URI Too Long', 'URI is too long.'), + 415: ('Unsupported Media Type', 'Entity body in unsupported format.'), + 416: ('Requested Range Not Satisfiable', + 'Cannot satisfy request range.'), + 417: ('Expectation Failed', + 'Expect condition could not be satisfied.'), + + 500: ('Internal Server Error', 'Server got itself in trouble'), + 501: ('Not Implemented', + 'Server does not support this operation'), + 502: ('Bad Gateway', 'Invalid responses from another server/proxy.'), + 503: ('Service Unavailable', + 'The server cannot process the request due to a high load'), + 504: ('Gateway Timeout', + 'The gateway server did not receive a timely response'), + 505: ('HTTP Version Not Supported', 'Cannot fulfill request.'), + } + + +def test(HandlerClass = BaseHTTPRequestHandler, + ServerClass = HTTPServer, protocol="HTTP/1.0"): + """Test the HTTP request handler class. + + This runs an HTTP server on port 8000 (or the first command line + argument). + + """ + + if sys.argv[1:]: + port = int(sys.argv[1]) + else: + port = 8000 + server_address = ('', port) + + HandlerClass.protocol_version = protocol + httpd = ServerClass(server_address, HandlerClass) + + sa = httpd.socket.getsockname() + print ("Serving HTTP on", sa[0], "port", sa[1], "...") + httpd.serve_forever() + + +if __name__ == '__main__': + test() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_SimpleXMLRPCServer.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_SimpleXMLRPCServer.py new file mode 100644 index 0000000..c5f7742 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_SimpleXMLRPCServer.py @@ -0,0 +1,601 @@ +#Just a copy of the version in python 2.5 to be used if it's not available in jython 2.1 + +"""Simple XML-RPC Server. + +This module can be used to create simple XML-RPC servers +by creating a server and either installing functions, a +class instance, or by extending the SimpleXMLRPCServer +class. + +It can also be used to handle XML-RPC requests in a CGI +environment using CGIXMLRPCRequestHandler. + +A list of possible usage patterns follows: + +1. Install functions: + +server = SimpleXMLRPCServer(("localhost", 8000)) +server.register_function(pow) +server.register_function(lambda x,y: x+y, 'add') +server.serve_forever() + +2. Install an instance: + +class MyFuncs: + def __init__(self): + # make all of the string functions available through + # string.func_name + import string + self.string = string + def _listMethods(self): + # implement this method so that system.listMethods + # knows to advertise the strings methods + return list_public_methods(self) + \ + ['string.' + method for method in list_public_methods(self.string)] + def pow(self, x, y): return pow(x, y) + def add(self, x, y) : return x + y + +server = SimpleXMLRPCServer(("localhost", 8000)) +server.register_introspection_functions() +server.register_instance(MyFuncs()) +server.serve_forever() + +3. Install an instance with custom dispatch method: + +class Math: + def _listMethods(self): + # this method must be present for system.listMethods + # to work + return ['add', 'pow'] + def _methodHelp(self, method): + # this method must be present for system.methodHelp + # to work + if method == 'add': + return "add(2,3) => 5" + elif method == 'pow': + return "pow(x, y[, z]) => number" + else: + # By convention, return empty + # string if no help is available + return "" + def _dispatch(self, method, params): + if method == 'pow': + return pow(*params) + elif method == 'add': + return params[0] + params[1] + else: + raise 'bad method' + +server = SimpleXMLRPCServer(("localhost", 8000)) +server.register_introspection_functions() +server.register_instance(Math()) +server.serve_forever() + +4. Subclass SimpleXMLRPCServer: + +class MathServer(SimpleXMLRPCServer): + def _dispatch(self, method, params): + try: + # We are forcing the 'export_' prefix on methods that are + # callable through XML-RPC to prevent potential security + # problems + func = getattr(self, 'export_' + method) + except AttributeError: + raise Exception('method "%s" is not supported' % method) + else: + return func(*params) + + def export_add(self, x, y): + return x + y + +server = MathServer(("localhost", 8000)) +server.serve_forever() + +5. CGI script: + +server = CGIXMLRPCRequestHandler() +server.register_function(pow) +server.handle_request() +""" + +# Written by Brian Quinlan (brian@sweetapp.com). +# Based on code written by Fredrik Lundh. + +from _pydev_imps import _pydev_xmlrpclib as xmlrpclib +from _pydev_imps._pydev_xmlrpclib import Fault +from _pydev_imps import _pydev_SocketServer as SocketServer +from _pydev_imps import _pydev_BaseHTTPServer as BaseHTTPServer +import sys +import os +try: + import fcntl +except ImportError: + fcntl = None + +def resolve_dotted_attribute(obj, attr, allow_dotted_names=True): + """resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d + + Resolves a dotted attribute name to an object. Raises + an AttributeError if any attribute in the chain starts with a '_'. + + If the optional allow_dotted_names argument is false, dots are not + supported and this function operates similar to getattr(obj, attr). + """ + + if allow_dotted_names: + attrs = attr.split('.') + else: + attrs = [attr] + + for i in attrs: + if i.startswith('_'): + raise AttributeError( + 'attempt to access private attribute "%s"' % i + ) + else: + obj = getattr(obj, i) + return obj + +def list_public_methods(obj): + """Returns a list of attribute strings, found in the specified + object, which represent callable attributes""" + + return [member for member in dir(obj) + if not member.startswith('_') and + callable(getattr(obj, member))] + +def remove_duplicates(lst): + """remove_duplicates([2,2,2,1,3,3]) => [3,1,2] + + Returns a copy of a list without duplicates. Every list + item must be hashable and the order of the items in the + resulting list is not defined. + """ + u = {} + for x in lst: + u[x] = 1 + + return u.keys() + +class SimpleXMLRPCDispatcher: + """Mix-in class that dispatches XML-RPC requests. + + This class is used to register XML-RPC method handlers + and then to dispatch them. There should never be any + reason to instantiate this class directly. + """ + + def __init__(self, allow_none, encoding): + self.funcs = {} + self.instance = None + self.allow_none = allow_none + self.encoding = encoding + + def register_instance(self, instance, allow_dotted_names=False): + """Registers an instance to respond to XML-RPC requests. + + Only one instance can be installed at a time. + + If the registered instance has a _dispatch method then that + method will be called with the name of the XML-RPC method and + its parameters as a tuple + e.g. instance._dispatch('add',(2,3)) + + If the registered instance does not have a _dispatch method + then the instance will be searched to find a matching method + and, if found, will be called. Methods beginning with an '_' + are considered private and will not be called by + SimpleXMLRPCServer. + + If a registered function matches a XML-RPC request, then it + will be called instead of the registered instance. + + If the optional allow_dotted_names argument is true and the + instance does not have a _dispatch method, method names + containing dots are supported and resolved, as long as none of + the name segments start with an '_'. + + *** SECURITY WARNING: *** + + Enabling the allow_dotted_names options allows intruders + to access your module's global variables and may allow + intruders to execute arbitrary code on your machine. Only + use this option on a secure, closed network. + + """ + + self.instance = instance + self.allow_dotted_names = allow_dotted_names + + def register_function(self, function, name=None): + """Registers a function to respond to XML-RPC requests. + + The optional name argument can be used to set a Unicode name + for the function. + """ + + if name is None: + name = function.__name__ + self.funcs[name] = function + + def register_introspection_functions(self): + """Registers the XML-RPC introspection methods in the system + namespace. + + see http://xmlrpc.usefulinc.com/doc/reserved.html + """ + + self.funcs.update({'system.listMethods' : self.system_listMethods, + 'system.methodSignature' : self.system_methodSignature, + 'system.methodHelp' : self.system_methodHelp}) + + def register_multicall_functions(self): + """Registers the XML-RPC multicall method in the system + namespace. + + see http://www.xmlrpc.com/discuss/msgReader$1208""" + + self.funcs.update({'system.multicall' : self.system_multicall}) + + def _marshaled_dispatch(self, data, dispatch_method=None): + """Dispatches an XML-RPC method from marshalled (XML) data. + + XML-RPC methods are dispatched from the marshalled (XML) data + using the _dispatch method and the result is returned as + marshalled data. For backwards compatibility, a dispatch + function can be provided as an argument (see comment in + SimpleXMLRPCRequestHandler.do_POST) but overriding the + existing method through subclassing is the prefered means + of changing method dispatch behavior. + """ + try: + params, method = xmlrpclib.loads(data) + + # generate response + if dispatch_method is not None: + response = dispatch_method(method, params) + else: + response = self._dispatch(method, params) + # wrap response in a singleton tuple + response = (response,) + response = xmlrpclib.dumps(response, methodresponse=1, + allow_none=self.allow_none, encoding=self.encoding) + except Fault, fault: + response = xmlrpclib.dumps(fault, allow_none=self.allow_none, + encoding=self.encoding) + except: + # report exception back to server + response = xmlrpclib.dumps( + xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value)), #@UndefinedVariable exc_value only available when we actually have an exception + encoding=self.encoding, allow_none=self.allow_none, + ) + + return response + + def system_listMethods(self): + """system.listMethods() => ['add', 'subtract', 'multiple'] + + Returns a list of the methods supported by the server.""" + + methods = self.funcs.keys() + if self.instance is not None: + # Instance can implement _listMethod to return a list of + # methods + if hasattr(self.instance, '_listMethods'): + methods = remove_duplicates( + methods + self.instance._listMethods() + ) + # if the instance has a _dispatch method then we + # don't have enough information to provide a list + # of methods + elif not hasattr(self.instance, '_dispatch'): + methods = remove_duplicates( + methods + list_public_methods(self.instance) + ) + methods.sort() + return methods + + def system_methodSignature(self, method_name): + """system.methodSignature('add') => [double, int, int] + + Returns a list describing the signature of the method. In the + above example, the add method takes two integers as arguments + and returns a double result. + + This server does NOT support system.methodSignature.""" + + # See http://xmlrpc.usefulinc.com/doc/sysmethodsig.html + + return 'signatures not supported' + + def system_methodHelp(self, method_name): + """system.methodHelp('add') => "Adds two integers together" + + Returns a string containing documentation for the specified method.""" + + method = None + if self.funcs.has_key(method_name): + method = self.funcs[method_name] + elif self.instance is not None: + # Instance can implement _methodHelp to return help for a method + if hasattr(self.instance, '_methodHelp'): + return self.instance._methodHelp(method_name) + # if the instance has a _dispatch method then we + # don't have enough information to provide help + elif not hasattr(self.instance, '_dispatch'): + try: + method = resolve_dotted_attribute( + self.instance, + method_name, + self.allow_dotted_names + ) + except AttributeError: + pass + + # Note that we aren't checking that the method actually + # be a callable object of some kind + if method is None: + return "" + else: + try: + import pydoc + except ImportError: + return "" #not there for jython + else: + return pydoc.getdoc(method) + + def system_multicall(self, call_list): + """system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => \ +[[4], ...] + + Allows the caller to package multiple XML-RPC calls into a single + request. + + See http://www.xmlrpc.com/discuss/msgReader$1208 + """ + + results = [] + for call in call_list: + method_name = call['methodName'] + params = call['params'] + + try: + # XXX A marshalling error in any response will fail the entire + # multicall. If someone cares they should fix this. + results.append([self._dispatch(method_name, params)]) + except Fault, fault: + results.append( + {'faultCode' : fault.faultCode, + 'faultString' : fault.faultString} + ) + except: + results.append( + {'faultCode' : 1, + 'faultString' : "%s:%s" % (sys.exc_type, sys.exc_value)} #@UndefinedVariable exc_value only available when we actually have an exception + ) + return results + + def _dispatch(self, method, params): + """Dispatches the XML-RPC method. + + XML-RPC calls are forwarded to a registered function that + matches the called XML-RPC method name. If no such function + exists then the call is forwarded to the registered instance, + if available. + + If the registered instance has a _dispatch method then that + method will be called with the name of the XML-RPC method and + its parameters as a tuple + e.g. instance._dispatch('add',(2,3)) + + If the registered instance does not have a _dispatch method + then the instance will be searched to find a matching method + and, if found, will be called. + + Methods beginning with an '_' are considered private and will + not be called. + """ + + func = None + try: + # check to see if a matching function has been registered + func = self.funcs[method] + except KeyError: + if self.instance is not None: + # check for a _dispatch method + if hasattr(self.instance, '_dispatch'): + return self.instance._dispatch(method, params) + else: + # call instance method directly + try: + func = resolve_dotted_attribute( + self.instance, + method, + self.allow_dotted_names + ) + except AttributeError: + pass + + if func is not None: + return func(*params) + else: + raise Exception('method "%s" is not supported' % method) + +class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + """Simple XML-RPC request handler class. + + Handles all HTTP POST requests and attempts to decode them as + XML-RPC requests. + """ + + # Class attribute listing the accessible path components; + # paths not on this list will result in a 404 error. + rpc_paths = ('/', '/RPC2') + + def is_rpc_path_valid(self): + if self.rpc_paths: + return self.path in self.rpc_paths + else: + # If .rpc_paths is empty, just assume all paths are legal + return True + + def do_POST(self): + """Handles the HTTP POST request. + + Attempts to interpret all HTTP POST requests as XML-RPC calls, + which are forwarded to the server's _dispatch method for handling. + """ + + # Check that the path is legal + if not self.is_rpc_path_valid(): + self.report_404() + return + + try: + # Get arguments by reading body of request. + # We read this in chunks to avoid straining + # socket.read(); around the 10 or 15Mb mark, some platforms + # begin to have problems (bug #792570). + max_chunk_size = 10 * 1024 * 1024 + size_remaining = int(self.headers["content-length"]) + L = [] + while size_remaining: + chunk_size = min(size_remaining, max_chunk_size) + L.append(self.rfile.read(chunk_size)) + size_remaining -= len(L[-1]) + data = ''.join(L) + + # In previous versions of SimpleXMLRPCServer, _dispatch + # could be overridden in this class, instead of in + # SimpleXMLRPCDispatcher. To maintain backwards compatibility, + # check to see if a subclass implements _dispatch and dispatch + # using that method if present. + response = self.server._marshaled_dispatch( + data, getattr(self, '_dispatch', None) + ) + except: # This should only happen if the module is buggy + # internal error, report as HTTP server error + self.send_response(500) + self.end_headers() + else: + # got a valid XML RPC response + self.send_response(200) + self.send_header("Content-type", "text/xml") + self.send_header("Content-length", str(len(response))) + self.end_headers() + self.wfile.write(response) + + # shut down the connection + self.wfile.flush() + self.connection.shutdown(1) + + def report_404 (self): + # Report a 404 error + self.send_response(404) + response = 'No such page' + self.send_header("Content-type", "text/plain") + self.send_header("Content-length", str(len(response))) + self.end_headers() + self.wfile.write(response) + # shut down the connection + self.wfile.flush() + self.connection.shutdown(1) + + def log_request(self, code='-', size='-'): + """Selectively log an accepted request.""" + + if self.server.logRequests: + BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size) + +class SimpleXMLRPCServer(SocketServer.TCPServer, + SimpleXMLRPCDispatcher): + """Simple XML-RPC server. + + Simple XML-RPC server that allows functions and a single instance + to be installed to handle requests. The default implementation + attempts to dispatch XML-RPC calls to the functions or instance + installed in the server. Override the _dispatch method inhereted + from SimpleXMLRPCDispatcher to change this behavior. + """ + + allow_reuse_address = True + + def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler, + logRequests=True, allow_none=False, encoding=None): + self.logRequests = logRequests + + SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding) + SocketServer.TCPServer.__init__(self, addr, requestHandler) + + # [Bug #1222790] If possible, set close-on-exec flag; if a + # method spawns a subprocess, the subprocess shouldn't have + # the listening socket open. + if fcntl is not None and hasattr(fcntl, 'FD_CLOEXEC'): + flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD) + flags |= fcntl.FD_CLOEXEC + fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags) + +class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): + """Simple handler for XML-RPC data passed through CGI.""" + + def __init__(self, allow_none=False, encoding=None): + SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding) + + def handle_xmlrpc(self, request_text): + """Handle a single XML-RPC request""" + + response = self._marshaled_dispatch(request_text) + + sys.stdout.write('Content-Type: text/xml\n') + sys.stdout.write('Content-Length: %d\n' % len(response)) + sys.stdout.write('\n') + + sys.stdout.write(response) + + def handle_get(self): + """Handle a single HTTP GET request. + + Default implementation indicates an error because + XML-RPC uses the POST method. + """ + + code = 400 + message, explain = \ + BaseHTTPServer.BaseHTTPRequestHandler.responses[code] + + response = BaseHTTPServer.DEFAULT_ERROR_MESSAGE % { #@UndefinedVariable + 'code' : code, + 'message' : message, + 'explain' : explain + } + sys.stdout.write('Status: %d %s\n' % (code, message)) + sys.stdout.write('Content-Type: text/html\n') + sys.stdout.write('Content-Length: %d\n' % len(response)) + sys.stdout.write('\n') + + sys.stdout.write(response) + + def handle_request(self, request_text=None): + """Handle a single XML-RPC request passed through a CGI post method. + + If no XML data is given then it is read from stdin. The resulting + XML-RPC response is printed to stdout along with the correct HTTP + headers. + """ + + if request_text is None and \ + os.environ.get('REQUEST_METHOD', None) == 'GET': + self.handle_get() + else: + # POST data is normally available through stdin + if request_text is None: + request_text = sys.stdin.read() + + self.handle_xmlrpc(request_text) + +if __name__ == '__main__': + sys.stdout.write('Running XML-RPC server on port 8000\n') + server = SimpleXMLRPCServer(("localhost", 8000)) + server.register_function(pow) + server.register_function(lambda x, y: x + y, 'add') + server.serve_forever() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_SocketServer.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_SocketServer.py new file mode 100644 index 0000000..7af2777 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_SocketServer.py @@ -0,0 +1,715 @@ +"""Generic socket server classes. + +This module tries to capture the various aspects of defining a server: + +For socket-based servers: + +- address family: + - AF_INET{,6}: IP (Internet Protocol) sockets (default) + - AF_UNIX: Unix domain sockets + - others, e.g. AF_DECNET are conceivable (see +- socket type: + - SOCK_STREAM (reliable stream, e.g. TCP) + - SOCK_DGRAM (datagrams, e.g. UDP) + +For request-based servers (including socket-based): + +- client address verification before further looking at the request + (This is actually a hook for any processing that needs to look + at the request before anything else, e.g. logging) +- how to handle multiple requests: + - synchronous (one request is handled at a time) + - forking (each request is handled by a new process) + - threading (each request is handled by a new thread) + +The classes in this module favor the server type that is simplest to +write: a synchronous TCP/IP server. This is bad class design, but +save some typing. (There's also the issue that a deep class hierarchy +slows down method lookups.) + +There are five classes in an inheritance diagram, four of which represent +synchronous servers of four types: + + +------------+ + | BaseServer | + +------------+ + | + v + +-----------+ +------------------+ + | TCPServer |------->| UnixStreamServer | + +-----------+ +------------------+ + | + v + +-----------+ +--------------------+ + | UDPServer |------->| UnixDatagramServer | + +-----------+ +--------------------+ + +Note that UnixDatagramServer derives from UDPServer, not from +UnixStreamServer -- the only difference between an IP and a Unix +stream server is the address family, which is simply repeated in both +unix server classes. + +Forking and threading versions of each type of server can be created +using the ForkingMixIn and ThreadingMixIn mix-in classes. For +instance, a threading UDP server class is created as follows: + + class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass + +The Mix-in class must come first, since it overrides a method defined +in UDPServer! Setting the various member variables also changes +the behavior of the underlying server mechanism. + +To implement a service, you must derive a class from +BaseRequestHandler and redefine its handle() method. You can then run +various versions of the service by combining one of the server classes +with your request handler class. + +The request handler class must be different for datagram or stream +services. This can be hidden by using the request handler +subclasses StreamRequestHandler or DatagramRequestHandler. + +Of course, you still have to use your head! + +For instance, it makes no sense to use a forking server if the service +contains state in memory that can be modified by requests (since the +modifications in the child process would never reach the initial state +kept in the parent process and passed to each child). In this case, +you can use a threading server, but you will probably have to use +locks to avoid two requests that come in nearly simultaneous to apply +conflicting changes to the server state. + +On the other hand, if you are building e.g. an HTTP server, where all +data is stored externally (e.g. in the file system), a synchronous +class will essentially render the service "deaf" while one request is +being handled -- which may be for a very long time if a client is slow +to read all the data it has requested. Here a threading or forking +server is appropriate. + +In some cases, it may be appropriate to process part of a request +synchronously, but to finish processing in a forked child depending on +the request data. This can be implemented by using a synchronous +server and doing an explicit fork in the request handler class +handle() method. + +Another approach to handling multiple simultaneous requests in an +environment that supports neither threads nor fork (or where these are +too expensive or inappropriate for the service) is to maintain an +explicit table of partially finished requests and to use select() to +decide which request to work on next (or whether to handle a new +incoming request). This is particularly important for stream services +where each client can potentially be connected for a long time (if +threads or subprocesses cannot be used). + +Future work: +- Standard classes for Sun RPC (which uses either UDP or TCP) +- Standard mix-in classes to implement various authentication + and encryption schemes +- Standard framework for select-based multiplexing + +XXX Open problems: +- What to do with out-of-band data? + +BaseServer: +- split generic "request" functionality out into BaseServer class. + Copyright (C) 2000 Luke Kenneth Casson Leighton + + example: read entries from a SQL database (requires overriding + get_request() to return a table entry from the database). + entry is processed by a RequestHandlerClass. + +""" + +# Author of the BaseServer patch: Luke Kenneth Casson Leighton + +# XXX Warning! +# There is a test suite for this module, but it cannot be run by the +# standard regression test. +# To run it manually, run Lib/test/test_socketserver.py. + +__version__ = "0.4" + + +from _pydev_imps._pydev_saved_modules import socket +from _pydev_imps._pydev_saved_modules import select +import sys +import os +try: + from _pydev_imps._pydev_saved_modules import threading +except ImportError: + import dummy_threading as threading + +__all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer", + "ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler", + "StreamRequestHandler","DatagramRequestHandler", + "ThreadingMixIn", "ForkingMixIn"] +if hasattr(socket, "AF_UNIX"): + __all__.extend(["UnixStreamServer","UnixDatagramServer", + "ThreadingUnixStreamServer", + "ThreadingUnixDatagramServer"]) + +class BaseServer: + + """Base class for server classes. + + Methods for the caller: + + - __init__(server_address, RequestHandlerClass) + - serve_forever(poll_interval=0.5) + - shutdown() + - handle_request() # if you do not use serve_forever() + - fileno() -> int # for select() + + Methods that may be overridden: + + - server_bind() + - server_activate() + - get_request() -> request, client_address + - handle_timeout() + - verify_request(request, client_address) + - server_close() + - process_request(request, client_address) + - shutdown_request(request) + - close_request(request) + - handle_error() + + Methods for derived classes: + + - finish_request(request, client_address) + + Class variables that may be overridden by derived classes or + instances: + + - timeout + - address_family + - socket_type + - allow_reuse_address + + Instance variables: + + - RequestHandlerClass + - socket + + """ + + timeout = None + + def __init__(self, server_address, RequestHandlerClass): + """Constructor. May be extended, do not override.""" + self.server_address = server_address + self.RequestHandlerClass = RequestHandlerClass + self.__is_shut_down = threading.Event() # @UndefinedVariable + self.__shutdown_request = False + + def server_activate(self): + """Called by constructor to activate the server. + + May be overridden. + + """ + pass + + def serve_forever(self, poll_interval=0.5): + """Handle one request at a time until shutdown. + + Polls for shutdown every poll_interval seconds. Ignores + self.timeout. If you need to do periodic tasks, do them in + another thread. + """ + self.__is_shut_down.clear() + try: + while not self.__shutdown_request: + # XXX: Consider using another file descriptor or + # connecting to the socket to wake this up instead of + # polling. Polling reduces our responsiveness to a + # shutdown request and wastes cpu at all other times. + r, w, e = select.select([self], [], [], poll_interval) + if self in r: + self._handle_request_noblock() + finally: + self.__shutdown_request = False + self.__is_shut_down.set() + + def shutdown(self): + """Stops the serve_forever loop. + + Blocks until the loop has finished. This must be called while + serve_forever() is running in another thread, or it will + deadlock. + """ + self.__shutdown_request = True + self.__is_shut_down.wait() + + # The distinction between handling, getting, processing and + # finishing a request is fairly arbitrary. Remember: + # + # - handle_request() is the top-level call. It calls + # select, get_request(), verify_request() and process_request() + # - get_request() is different for stream or datagram sockets + # - process_request() is the place that may fork a new process + # or create a new thread to finish the request + # - finish_request() instantiates the request handler class; + # this constructor will handle the request all by itself + + def handle_request(self): + """Handle one request, possibly blocking. + + Respects self.timeout. + """ + # Support people who used socket.settimeout() to escape + # handle_request before self.timeout was available. + timeout = self.socket.gettimeout() + if timeout is None: + timeout = self.timeout + elif self.timeout is not None: + timeout = min(timeout, self.timeout) + fd_sets = select.select([self], [], [], timeout) + if not fd_sets[0]: + self.handle_timeout() + return + self._handle_request_noblock() + + def _handle_request_noblock(self): + """Handle one request, without blocking. + + I assume that select.select has returned that the socket is + readable before this function was called, so there should be + no risk of blocking in get_request(). + """ + try: + request, client_address = self.get_request() + except socket.error: + return + if self.verify_request(request, client_address): + try: + self.process_request(request, client_address) + except: + self.handle_error(request, client_address) + self.shutdown_request(request) + + def handle_timeout(self): + """Called if no new request arrives within self.timeout. + + Overridden by ForkingMixIn. + """ + pass + + def verify_request(self, request, client_address): + """Verify the request. May be overridden. + + Return True if we should proceed with this request. + + """ + return True + + def process_request(self, request, client_address): + """Call finish_request. + + Overridden by ForkingMixIn and ThreadingMixIn. + + """ + self.finish_request(request, client_address) + self.shutdown_request(request) + + def server_close(self): + """Called to clean-up the server. + + May be overridden. + + """ + pass + + def finish_request(self, request, client_address): + """Finish one request by instantiating RequestHandlerClass.""" + self.RequestHandlerClass(request, client_address, self) + + def shutdown_request(self, request): + """Called to shutdown and close an individual request.""" + self.close_request(request) + + def close_request(self, request): + """Called to clean up an individual request.""" + pass + + def handle_error(self, request, client_address): + """Handle an error gracefully. May be overridden. + + The default is to print a traceback and continue. + + """ + print '-'*40 + print 'Exception happened during processing of request from', + print client_address + import traceback + traceback.print_exc() # XXX But this goes to stderr! + print '-'*40 + + +class TCPServer(BaseServer): + + """Base class for various socket-based server classes. + + Defaults to synchronous IP stream (i.e., TCP). + + Methods for the caller: + + - __init__(server_address, RequestHandlerClass, bind_and_activate=True) + - serve_forever(poll_interval=0.5) + - shutdown() + - handle_request() # if you don't use serve_forever() + - fileno() -> int # for select() + + Methods that may be overridden: + + - server_bind() + - server_activate() + - get_request() -> request, client_address + - handle_timeout() + - verify_request(request, client_address) + - process_request(request, client_address) + - shutdown_request(request) + - close_request(request) + - handle_error() + + Methods for derived classes: + + - finish_request(request, client_address) + + Class variables that may be overridden by derived classes or + instances: + + - timeout + - address_family + - socket_type + - request_queue_size (only for stream sockets) + - allow_reuse_address + + Instance variables: + + - server_address + - RequestHandlerClass + - socket + + """ + + address_family = socket.AF_INET + + socket_type = socket.SOCK_STREAM + + request_queue_size = 5 + + allow_reuse_address = False + + def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True): + """Constructor. May be extended, do not override.""" + BaseServer.__init__(self, server_address, RequestHandlerClass) + self.socket = socket.socket(self.address_family, + self.socket_type) + if bind_and_activate: + self.server_bind() + self.server_activate() + + def server_bind(self): + """Called by constructor to bind the socket. + + May be overridden. + + """ + if self.allow_reuse_address: + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.bind(self.server_address) + self.server_address = self.socket.getsockname() + + def server_activate(self): + """Called by constructor to activate the server. + + May be overridden. + + """ + self.socket.listen(self.request_queue_size) + + def server_close(self): + """Called to clean-up the server. + + May be overridden. + + """ + self.socket.close() + + def fileno(self): + """Return socket file number. + + Interface required by select(). + + """ + return self.socket.fileno() + + def get_request(self): + """Get the request and client address from the socket. + + May be overridden. + + """ + return self.socket.accept() + + def shutdown_request(self, request): + """Called to shutdown and close an individual request.""" + try: + #explicitly shutdown. socket.close() merely releases + #the socket and waits for GC to perform the actual close. + request.shutdown(socket.SHUT_WR) + except socket.error: + pass #some platforms may raise ENOTCONN here + self.close_request(request) + + def close_request(self, request): + """Called to clean up an individual request.""" + request.close() + + +class UDPServer(TCPServer): + + """UDP server class.""" + + allow_reuse_address = False + + socket_type = socket.SOCK_DGRAM + + max_packet_size = 8192 + + def get_request(self): + data, client_addr = self.socket.recvfrom(self.max_packet_size) + return (data, self.socket), client_addr + + def server_activate(self): + # No need to call listen() for UDP. + pass + + def shutdown_request(self, request): + # No need to shutdown anything. + self.close_request(request) + + def close_request(self, request): + # No need to close anything. + pass + +class ForkingMixIn: + + """Mix-in class to handle each request in a new process.""" + + timeout = 300 + active_children = None + max_children = 40 + + def collect_children(self): + """Internal routine to wait for children that have exited.""" + if self.active_children is None: return + while len(self.active_children) >= self.max_children: + # XXX: This will wait for any child process, not just ones + # spawned by this library. This could confuse other + # libraries that expect to be able to wait for their own + # children. + try: + pid, status = os.waitpid(0, 0) + except os.error: + pid = None + if pid not in self.active_children: continue + self.active_children.remove(pid) + + # XXX: This loop runs more system calls than it ought + # to. There should be a way to put the active_children into a + # process group and then use os.waitpid(-pgid) to wait for any + # of that set, but I couldn't find a way to allocate pgids + # that couldn't collide. + for child in self.active_children: + try: + pid, status = os.waitpid(child, os.WNOHANG) # @UndefinedVariable + except os.error: + pid = None + if not pid: continue + try: + self.active_children.remove(pid) + except ValueError, e: + raise ValueError('%s. x=%d and list=%r' % (e.message, pid, + self.active_children)) + + def handle_timeout(self): + """Wait for zombies after self.timeout seconds of inactivity. + + May be extended, do not override. + """ + self.collect_children() + + def process_request(self, request, client_address): + """Fork a new subprocess to process the request.""" + self.collect_children() + pid = os.fork() # @UndefinedVariable + if pid: + # Parent process + if self.active_children is None: + self.active_children = [] + self.active_children.append(pid) + self.close_request(request) #close handle in parent process + return + else: + # Child process. + # This must never return, hence os._exit()! + try: + self.finish_request(request, client_address) + self.shutdown_request(request) + os._exit(0) + except: + try: + self.handle_error(request, client_address) + self.shutdown_request(request) + finally: + os._exit(1) + + +class ThreadingMixIn: + """Mix-in class to handle each request in a new thread.""" + + # Decides how threads will act upon termination of the + # main process + daemon_threads = False + + def process_request_thread(self, request, client_address): + """Same as in BaseServer but as a thread. + + In addition, exception handling is done here. + + """ + try: + self.finish_request(request, client_address) + self.shutdown_request(request) + except: + self.handle_error(request, client_address) + self.shutdown_request(request) + + def process_request(self, request, client_address): + """Start a new thread to process the request.""" + t = threading.Thread(target = self.process_request_thread, # @UndefinedVariable + args = (request, client_address)) + t.daemon = self.daemon_threads + t.start() + + +class ForkingUDPServer(ForkingMixIn, UDPServer): pass +class ForkingTCPServer(ForkingMixIn, TCPServer): pass + +class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass +class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass + +if hasattr(socket, 'AF_UNIX'): + + class UnixStreamServer(TCPServer): + address_family = socket.AF_UNIX # @UndefinedVariable + + class UnixDatagramServer(UDPServer): + address_family = socket.AF_UNIX # @UndefinedVariable + + class ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer): pass + + class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer): pass + +class BaseRequestHandler: + + """Base class for request handler classes. + + This class is instantiated for each request to be handled. The + constructor sets the instance variables request, client_address + and server, and then calls the handle() method. To implement a + specific service, all you need to do is to derive a class which + defines a handle() method. + + The handle() method can find the request as self.request, the + client address as self.client_address, and the server (in case it + needs access to per-server information) as self.server. Since a + separate instance is created for each request, the handle() method + can define arbitrary other instance variariables. + + """ + + def __init__(self, request, client_address, server): + self.request = request + self.client_address = client_address + self.server = server + self.setup() + try: + self.handle() + finally: + self.finish() + + def setup(self): + pass + + def handle(self): + pass + + def finish(self): + pass + + +# The following two classes make it possible to use the same service +# class for stream or datagram servers. +# Each class sets up these instance variables: +# - rfile: a file object from which receives the request is read +# - wfile: a file object to which the reply is written +# When the handle() method returns, wfile is flushed properly + + +class StreamRequestHandler(BaseRequestHandler): + + """Define self.rfile and self.wfile for stream sockets.""" + + # Default buffer sizes for rfile, wfile. + # We default rfile to buffered because otherwise it could be + # really slow for large data (a getc() call per byte); we make + # wfile unbuffered because (a) often after a write() we want to + # read and we need to flush the line; (b) big writes to unbuffered + # files are typically optimized by stdio even when big reads + # aren't. + rbufsize = -1 + wbufsize = 0 + + # A timeout to apply to the request socket, if not None. + timeout = None + + # Disable nagle algorithm for this socket, if True. + # Use only when wbufsize != 0, to avoid small packets. + disable_nagle_algorithm = False + + def setup(self): + self.connection = self.request + if self.timeout is not None: + self.connection.settimeout(self.timeout) + if self.disable_nagle_algorithm: + self.connection.setsockopt(socket.IPPROTO_TCP, + socket.TCP_NODELAY, True) + self.rfile = self.connection.makefile('rb', self.rbufsize) + self.wfile = self.connection.makefile('wb', self.wbufsize) + + def finish(self): + if not self.wfile.closed: + self.wfile.flush() + self.wfile.close() + self.rfile.close() + + +class DatagramRequestHandler(BaseRequestHandler): + + # XXX Regrettably, I cannot get this working on Linux; + # s.recvfrom() doesn't return a meaningful client address. + + """Define self.rfile and self.wfile for datagram sockets.""" + + def setup(self): + try: + from cStringIO import StringIO + except ImportError: + from StringIO import StringIO + self.packet, self.socket = self.request + self.rfile = StringIO(self.packet) + self.wfile = StringIO() + + def finish(self): + self.socket.sendto(self.wfile.getvalue(), self.client_address) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_execfile.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_execfile.py new file mode 100644 index 0000000..c02f8ec --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_execfile.py @@ -0,0 +1,25 @@ +#We must redefine it in Py3k if it's not already there +def execfile(file, glob=None, loc=None): + if glob is None: + import sys + glob = sys._getframe().f_back.f_globals + if loc is None: + loc = glob + + # It seems that the best way is using tokenize.open(): http://code.activestate.com/lists/python-dev/131251/ + # (but tokenize.open() is only available for python 3.2) + import tokenize + if hasattr(tokenize, 'open'): + # version 3.2 + stream = tokenize.open(file) # @UndefinedVariable + else: + # version 3.0 or 3.1 + detect_encoding = tokenize.detect_encoding(open(file, mode="rb" ).readline) + stream = open(file, encoding=detect_encoding[0]) + try: + contents = stream.read() + finally: + stream.close() + + #execute the script (note: it's important to compile first to have the filename set in debug mode) + exec(compile(contents+"\n", file, 'exec'), glob, loc) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_inspect.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_inspect.py new file mode 100644 index 0000000..5fd33d8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_inspect.py @@ -0,0 +1,788 @@ +"""Get useful information from live Python objects. + +This module encapsulates the interface provided by the internal special +attributes (func_*, co_*, im_*, tb_*, etc.) in a friendlier fashion. +It also provides some help for examining source code and class layout. + +Here are some of the useful functions provided by this module: + + ismodule(), isclass(), ismethod(), isfunction(), istraceback(), + isframe(), iscode(), isbuiltin(), isroutine() - check object types + getmembers() - get members of an object that satisfy a given condition + + getfile(), getsourcefile(), getsource() - find an object's source code + getdoc(), getcomments() - get documentation on an object + getmodule() - determine the module that an object came from + getclasstree() - arrange classes so as to represent their hierarchy + + getargspec(), getargvalues() - get info about function arguments + formatargspec(), formatargvalues() - format an argument spec + getouterframes(), getinnerframes() - get info about frames + currentframe() - get the current stack frame + stack(), trace() - get info about frames on the stack or in a traceback +""" + +# This module is in the public domain. No warranties. + +__author__ = 'Ka-Ping Yee ' +__date__ = '1 Jan 2001' + +import sys, os, types, string, re, imp, tokenize + +# ----------------------------------------------------------- type-checking +def ismodule(object): + """Return true if the object is a module. + + Module objects provide these attributes: + __doc__ documentation string + __file__ filename (missing for built-in modules)""" + return isinstance(object, types.ModuleType) + +def isclass(object): + """Return true if the object is a class. + + Class objects provide these attributes: + __doc__ documentation string + __module__ name of module in which this class was defined""" + return isinstance(object, types.ClassType) or hasattr(object, '__bases__') + +def ismethod(object): + """Return true if the object is an instance method. + + Instance method objects provide these attributes: + __doc__ documentation string + __name__ name with which this method was defined + im_class class object in which this method belongs + im_func function object containing implementation of method + im_self instance to which this method is bound, or None""" + return isinstance(object, types.MethodType) + +def ismethoddescriptor(object): + """Return true if the object is a method descriptor. + + But not if ismethod() or isclass() or isfunction() are true. + + This is new in Python 2.2, and, for example, is true of int.__add__. + An object passing this test has a __get__ attribute but not a __set__ + attribute, but beyond that the set of attributes varies. __name__ is + usually sensible, and __doc__ often is. + + Methods implemented via descriptors that also pass one of the other + tests return false from the ismethoddescriptor() test, simply because + the other tests promise more -- you can, e.g., count on having the + im_func attribute (etc) when an object passes ismethod().""" + return (hasattr(object, "__get__") + and not hasattr(object, "__set__") # else it's a data descriptor + and not ismethod(object) # mutual exclusion + and not isfunction(object) + and not isclass(object)) + +def isfunction(object): + """Return true if the object is a user-defined function. + + Function objects provide these attributes: + __doc__ documentation string + __name__ name with which this function was defined + func_code code object containing compiled function bytecode + func_defaults tuple of any default values for arguments + func_doc (same as __doc__) + func_globals global namespace in which this function was defined + func_name (same as __name__)""" + return isinstance(object, types.FunctionType) + +def istraceback(object): + """Return true if the object is a traceback. + + Traceback objects provide these attributes: + tb_frame frame object at this level + tb_lasti index of last attempted instruction in bytecode + tb_lineno current line number in Python source code + tb_next next inner traceback object (called by this level)""" + return isinstance(object, types.TracebackType) + +def isframe(object): + """Return true if the object is a frame object. + + Frame objects provide these attributes: + f_back next outer frame object (this frame's caller) + f_builtins built-in namespace seen by this frame + f_code code object being executed in this frame + f_exc_traceback traceback if raised in this frame, or None + f_exc_type exception type if raised in this frame, or None + f_exc_value exception value if raised in this frame, or None + f_globals global namespace seen by this frame + f_lasti index of last attempted instruction in bytecode + f_lineno current line number in Python source code + f_locals local namespace seen by this frame + f_restricted 0 or 1 if frame is in restricted execution mode + f_trace tracing function for this frame, or None""" + return isinstance(object, types.FrameType) + +def iscode(object): + """Return true if the object is a code object. + + Code objects provide these attributes: + co_argcount number of arguments (not including * or ** args) + co_code string of raw compiled bytecode + co_consts tuple of constants used in the bytecode + co_filename name of file in which this code object was created + co_firstlineno number of first line in Python source code + co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8=**arg + co_lnotab encoded mapping of line numbers to bytecode indices + co_name name with which this code object was defined + co_names tuple of names of local variables + co_nlocals number of local variables + co_stacksize virtual machine stack space required + co_varnames tuple of names of arguments and local variables""" + return isinstance(object, types.CodeType) + +def isbuiltin(object): + """Return true if the object is a built-in function or method. + + Built-in functions and methods provide these attributes: + __doc__ documentation string + __name__ original name of this function or method + __self__ instance to which a method is bound, or None""" + return isinstance(object, types.BuiltinFunctionType) + +def isroutine(object): + """Return true if the object is any kind of function or method.""" + return (isbuiltin(object) + or isfunction(object) + or ismethod(object) + or ismethoddescriptor(object)) + +def getmembers(object, predicate=None): + """Return all members of an object as (name, value) pairs sorted by name. + Optionally, only return members that satisfy a given predicate.""" + results = [] + for key in dir(object): + value = getattr(object, key) + if not predicate or predicate(value): + results.append((key, value)) + results.sort() + return results + +def classify_class_attrs(cls): + """Return list of attribute-descriptor tuples. + + For each name in dir(cls), the return list contains a 4-tuple + with these elements: + + 0. The name (a string). + + 1. The kind of attribute this is, one of these strings: + 'class method' created via classmethod() + 'static method' created via staticmethod() + 'property' created via property() + 'method' any other flavor of method + 'data' not a method + + 2. The class which defined this attribute (a class). + + 3. The object as obtained directly from the defining class's + __dict__, not via getattr. This is especially important for + data attributes: C.data is just a data object, but + C.__dict__['data'] may be a data descriptor with additional + info, like a __doc__ string. + """ + + mro = getmro(cls) + names = dir(cls) + result = [] + for name in names: + # Get the object associated with the name. + # Getting an obj from the __dict__ sometimes reveals more than + # using getattr. Static and class methods are dramatic examples. + if name in cls.__dict__: + obj = cls.__dict__[name] + else: + obj = getattr(cls, name) + + # Figure out where it was defined. + homecls = getattr(obj, "__objclass__", None) + if homecls is None: + # search the dicts. + for base in mro: + if name in base.__dict__: + homecls = base + break + + # Get the object again, in order to get it from the defining + # __dict__ instead of via getattr (if possible). + if homecls is not None and name in homecls.__dict__: + obj = homecls.__dict__[name] + + # Also get the object via getattr. + obj_via_getattr = getattr(cls, name) + + # Classify the object. + if isinstance(obj, staticmethod): + kind = "static method" + elif isinstance(obj, classmethod): + kind = "class method" + elif isinstance(obj, property): + kind = "property" + elif (ismethod(obj_via_getattr) or + ismethoddescriptor(obj_via_getattr)): + kind = "method" + else: + kind = "data" + + result.append((name, kind, homecls, obj)) + + return result + +# ----------------------------------------------------------- class helpers +def _searchbases(cls, accum): + # Simulate the "classic class" search order. + if cls in accum: + return + accum.append(cls) + for base in cls.__bases__: + _searchbases(base, accum) + +def getmro(cls): + "Return tuple of base classes (including cls) in method resolution order." + if hasattr(cls, "__mro__"): + return cls.__mro__ + else: + result = [] + _searchbases(cls, result) + return tuple(result) + +# -------------------------------------------------- source code extraction +def indentsize(line): + """Return the indent size, in spaces, at the start of a line of text.""" + expline = string.expandtabs(line) + return len(expline) - len(string.lstrip(expline)) + +def getdoc(object): + """Get the documentation string for an object. + + All tabs are expanded to spaces. To clean up docstrings that are + indented to line up with blocks of code, any whitespace than can be + uniformly removed from the second line onwards is removed.""" + try: + doc = object.__doc__ + except AttributeError: + return None + if not isinstance(doc, (str, unicode)): + return None + try: + lines = string.split(string.expandtabs(doc), '\n') + except UnicodeError: + return None + else: + margin = None + for line in lines[1:]: + content = len(string.lstrip(line)) + if not content: continue + indent = len(line) - content + if margin is None: margin = indent + else: margin = min(margin, indent) + if margin is not None: + for i in range(1, len(lines)): lines[i] = lines[i][margin:] + return string.join(lines, '\n') + +def getfile(object): + """Work out which source or compiled file an object was defined in.""" + if ismodule(object): + if hasattr(object, '__file__'): + return object.__file__ + raise TypeError, 'arg is a built-in module' + if isclass(object): + object = sys.modules.get(object.__module__) + if hasattr(object, '__file__'): + return object.__file__ + raise TypeError, 'arg is a built-in class' + if ismethod(object): + object = object.im_func + if isfunction(object): + object = object.func_code + if istraceback(object): + object = object.tb_frame + if isframe(object): + object = object.f_code + if iscode(object): + return object.co_filename + raise TypeError, 'arg is not a module, class, method, ' \ + 'function, traceback, frame, or code object' + +def getmoduleinfo(path): + """Get the module name, suffix, mode, and module type for a given file.""" + filename = os.path.basename(path) + suffixes = map(lambda (suffix, mode, mtype): + (-len(suffix), suffix, mode, mtype), imp.get_suffixes()) + suffixes.sort() # try longest suffixes first, in case they overlap + for neglen, suffix, mode, mtype in suffixes: + if filename[neglen:] == suffix: + return filename[:neglen], suffix, mode, mtype + +def getmodulename(path): + """Return the module name for a given file, or None.""" + info = getmoduleinfo(path) + if info: return info[0] + +def getsourcefile(object): + """Return the Python source file an object was defined in, if it exists.""" + filename = getfile(object) + if string.lower(filename[-4:]) in ['.pyc', '.pyo']: + filename = filename[:-4] + '.py' + for suffix, mode, kind in imp.get_suffixes(): + if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix: + # Looks like a binary file. We want to only return a text file. + return None + if os.path.exists(filename): + return filename + +def getabsfile(object): + """Return an absolute path to the source or compiled file for an object. + + The idea is for each object to have a unique origin, so this routine + normalizes the result as much as possible.""" + return os.path.normcase( + os.path.abspath(getsourcefile(object) or getfile(object))) + +modulesbyfile = {} + +def getmodule(object): + """Return the module an object was defined in, or None if not found.""" + if ismodule(object): + return object + if isclass(object): + return sys.modules.get(object.__module__) + try: + file = getabsfile(object) + except TypeError: + return None + if modulesbyfile.has_key(file): + return sys.modules[modulesbyfile[file]] + for module in sys.modules.values(): + if hasattr(module, '__file__'): + modulesbyfile[getabsfile(module)] = module.__name__ + if modulesbyfile.has_key(file): + return sys.modules[modulesbyfile[file]] + main = sys.modules['__main__'] + if hasattr(main, object.__name__): + mainobject = getattr(main, object.__name__) + if mainobject is object: + return main + builtin = sys.modules['__builtin__'] + if hasattr(builtin, object.__name__): + builtinobject = getattr(builtin, object.__name__) + if builtinobject is object: + return builtin + +def findsource(object): + """Return the entire source file and starting line number for an object. + + The argument may be a module, class, method, function, traceback, frame, + or code object. The source code is returned as a list of all the lines + in the file and the line number indexes a line in that list. An IOError + is raised if the source code cannot be retrieved.""" + try: + file = open(getsourcefile(object)) + except (TypeError, IOError): + raise IOError, 'could not get source code' + lines = file.readlines() + file.close() + + if ismodule(object): + return lines, 0 + + if isclass(object): + name = object.__name__ + pat = re.compile(r'^\s*class\s*' + name + r'\b') + for i in range(len(lines)): + if pat.match(lines[i]): return lines, i + else: raise IOError, 'could not find class definition' + + if ismethod(object): + object = object.im_func + if isfunction(object): + object = object.func_code + if istraceback(object): + object = object.tb_frame + if isframe(object): + object = object.f_code + if iscode(object): + if not hasattr(object, 'co_firstlineno'): + raise IOError, 'could not find function definition' + lnum = object.co_firstlineno - 1 + pat = re.compile(r'^(\s*def\s)|(.*\slambda(:|\s))') + while lnum > 0: + if pat.match(lines[lnum]): break + lnum = lnum - 1 + return lines, lnum + raise IOError, 'could not find code object' + +def getcomments(object): + """Get lines of comments immediately preceding an object's source code.""" + try: lines, lnum = findsource(object) + except IOError: return None + + if ismodule(object): + # Look for a comment block at the top of the file. + start = 0 + if lines and lines[0][:2] == '#!': start = 1 + while start < len(lines) and string.strip(lines[start]) in ['', '#']: + start = start + 1 + if start < len(lines) and lines[start][:1] == '#': + comments = [] + end = start + while end < len(lines) and lines[end][:1] == '#': + comments.append(string.expandtabs(lines[end])) + end = end + 1 + return string.join(comments, '') + + # Look for a preceding block of comments at the same indentation. + elif lnum > 0: + indent = indentsize(lines[lnum]) + end = lnum - 1 + if end >= 0 and string.lstrip(lines[end])[:1] == '#' and \ + indentsize(lines[end]) == indent: + comments = [string.lstrip(string.expandtabs(lines[end]))] + if end > 0: + end = end - 1 + comment = string.lstrip(string.expandtabs(lines[end])) + while comment[:1] == '#' and indentsize(lines[end]) == indent: + comments[:0] = [comment] + end = end - 1 + if end < 0: break + comment = string.lstrip(string.expandtabs(lines[end])) + while comments and string.strip(comments[0]) == '#': + comments[:1] = [] + while comments and string.strip(comments[-1]) == '#': + comments[-1:] = [] + return string.join(comments, '') + +class ListReader: + """Provide a readline() method to return lines from a list of strings.""" + def __init__(self, lines): + self.lines = lines + self.index = 0 + + def readline(self): + i = self.index + if i < len(self.lines): + self.index = i + 1 + return self.lines[i] + else: return '' + +class EndOfBlock(Exception): pass + +class BlockFinder: + """Provide a tokeneater() method to detect the end of a code block.""" + def __init__(self): + self.indent = 0 + self.started = 0 + self.last = 0 + + def tokeneater(self, type, token, (srow, scol), (erow, ecol), line): + if not self.started: + if type == tokenize.NAME: self.started = 1 + elif type == tokenize.NEWLINE: + self.last = srow + elif type == tokenize.INDENT: + self.indent = self.indent + 1 + elif type == tokenize.DEDENT: + self.indent = self.indent - 1 + if self.indent == 0: raise EndOfBlock, self.last + elif type == tokenize.NAME and scol == 0: + raise EndOfBlock, self.last + +def getblock(lines): + """Extract the block of code at the top of the given list of lines.""" + try: + tokenize.tokenize(ListReader(lines).readline, BlockFinder().tokeneater) + except EndOfBlock, eob: + return lines[:eob.args[0]] + # Fooling the indent/dedent logic implies a one-line definition + return lines[:1] + +def getsourcelines(object): + """Return a list of source lines and starting line number for an object. + + The argument may be a module, class, method, function, traceback, frame, + or code object. The source code is returned as a list of the lines + corresponding to the object and the line number indicates where in the + original source file the first line of code was found. An IOError is + raised if the source code cannot be retrieved.""" + lines, lnum = findsource(object) + + if ismodule(object): return lines, 0 + else: return getblock(lines[lnum:]), lnum + 1 + +def getsource(object): + """Return the text of the source code for an object. + + The argument may be a module, class, method, function, traceback, frame, + or code object. The source code is returned as a single string. An + IOError is raised if the source code cannot be retrieved.""" + lines, lnum = getsourcelines(object) + return string.join(lines, '') + +# --------------------------------------------------- class tree extraction +def walktree(classes, children, parent): + """Recursive helper function for getclasstree().""" + results = [] + classes.sort(lambda a, b: cmp(a.__name__, b.__name__)) + for c in classes: + results.append((c, c.__bases__)) + if children.has_key(c): + results.append(walktree(children[c], children, c)) + return results + +def getclasstree(classes, unique=0): + """Arrange the given list of classes into a hierarchy of nested lists. + + Where a nested list appears, it contains classes derived from the class + whose entry immediately precedes the list. Each entry is a 2-tuple + containing a class and a tuple of its base classes. If the 'unique' + argument is true, exactly one entry appears in the returned structure + for each class in the given list. Otherwise, classes using multiple + inheritance and their descendants will appear multiple times.""" + children = {} + roots = [] + for c in classes: + if c.__bases__: + for parent in c.__bases__: + if not children.has_key(parent): + children[parent] = [] + children[parent].append(c) + if unique and parent in classes: break + elif c not in roots: + roots.append(c) + for parent in children.keys(): + if parent not in classes: + roots.append(parent) + return walktree(roots, children, None) + +# ------------------------------------------------ argument list extraction +# These constants are from Python's compile.h. +CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 1, 2, 4, 8 + +def getargs(co): + """Get information about the arguments accepted by a code object. + + Three things are returned: (args, varargs, varkw), where 'args' is + a list of argument names (possibly containing nested lists), and + 'varargs' and 'varkw' are the names of the * and ** arguments or None.""" + if not iscode(co): raise TypeError, 'arg is not a code object' + + nargs = co.co_argcount + names = co.co_varnames + args = list(names[:nargs]) + step = 0 + + # The following acrobatics are for anonymous (tuple) arguments. + if not sys.platform.startswith('java'):#Jython doesn't have co_code + code = co.co_code + import dis + for i in range(nargs): + if args[i][:1] in ['', '.']: + stack, remain, count = [], [], [] + while step < len(code): + op = ord(code[step]) + step = step + 1 + if op >= dis.HAVE_ARGUMENT: + opname = dis.opname[op] + value = ord(code[step]) + ord(code[step + 1]) * 256 + step = step + 2 + if opname in ['UNPACK_TUPLE', 'UNPACK_SEQUENCE']: + remain.append(value) + count.append(value) + elif opname == 'STORE_FAST': + stack.append(names[value]) + remain[-1] = remain[-1] - 1 + while remain[-1] == 0: + remain.pop() + size = count.pop() + stack[-size:] = [stack[-size:]] + if not remain: break + remain[-1] = remain[-1] - 1 + if not remain: break + args[i] = stack[0] + + varargs = None + if co.co_flags & CO_VARARGS: + varargs = co.co_varnames[nargs] + nargs = nargs + 1 + varkw = None + if co.co_flags & CO_VARKEYWORDS: + varkw = co.co_varnames[nargs] + return args, varargs, varkw + +def getargspec(func): + """Get the names and default values of a function's arguments. + + A tuple of four things is returned: (args, varargs, varkw, defaults). + 'args' is a list of the argument names (it may contain nested lists). + 'varargs' and 'varkw' are the names of the * and ** arguments or None. + 'defaults' is an n-tuple of the default values of the last n arguments.""" + if ismethod(func): + func = func.im_func + if not isfunction(func): raise TypeError, 'arg is not a Python function' + args, varargs, varkw = getargs(func.func_code) + return args, varargs, varkw, func.func_defaults + +def getargvalues(frame): + """Get information about arguments passed into a particular frame. + + A tuple of four things is returned: (args, varargs, varkw, locals). + 'args' is a list of the argument names (it may contain nested lists). + 'varargs' and 'varkw' are the names of the * and ** arguments or None. + 'locals' is the locals dictionary of the given frame.""" + args, varargs, varkw = getargs(frame.f_code) + return args, varargs, varkw, frame.f_locals + +def joinseq(seq): + if len(seq) == 1: + return '(' + seq[0] + ',)' + else: + return '(' + string.join(seq, ', ') + ')' + +def strseq(object, convert, join=joinseq): + """Recursively walk a sequence, stringifying each element.""" + if type(object) in [types.ListType, types.TupleType]: + return join(map(lambda o, c=convert, j=join: strseq(o, c, j), object)) + else: + return convert(object) + +def formatargspec(args, varargs=None, varkw=None, defaults=None, + formatarg=str, + formatvarargs=lambda name: '*' + name, + formatvarkw=lambda name: '**' + name, + formatvalue=lambda value: '=' + repr(value), + join=joinseq): + """Format an argument spec from the 4 values returned by getargspec. + + The first four arguments are (args, varargs, varkw, defaults). The + other four arguments are the corresponding optional formatting functions + that are called to turn names and values into strings. The ninth + argument is an optional function to format the sequence of arguments.""" + specs = [] + if defaults: + firstdefault = len(args) - len(defaults) + for i in range(len(args)): + spec = strseq(args[i], formatarg, join) + if defaults and i >= firstdefault: + spec = spec + formatvalue(defaults[i - firstdefault]) + specs.append(spec) + if varargs: + specs.append(formatvarargs(varargs)) + if varkw: + specs.append(formatvarkw(varkw)) + return '(' + string.join(specs, ', ') + ')' + +def formatargvalues(args, varargs, varkw, locals, + formatarg=str, + formatvarargs=lambda name: '*' + name, + formatvarkw=lambda name: '**' + name, + formatvalue=lambda value: '=' + repr(value), + join=joinseq): + """Format an argument spec from the 4 values returned by getargvalues. + + The first four arguments are (args, varargs, varkw, locals). The + next four arguments are the corresponding optional formatting functions + that are called to turn names and values into strings. The ninth + argument is an optional function to format the sequence of arguments.""" + def convert(name, locals=locals, + formatarg=formatarg, formatvalue=formatvalue): + return formatarg(name) + formatvalue(locals[name]) + specs = [] + for i in range(len(args)): + specs.append(strseq(args[i], convert, join)) + if varargs: + specs.append(formatvarargs(varargs) + formatvalue(locals[varargs])) + if varkw: + specs.append(formatvarkw(varkw) + formatvalue(locals[varkw])) + return '(' + string.join(specs, ', ') + ')' + +# -------------------------------------------------- stack frame extraction +def getframeinfo(frame, context=1): + """Get information about a frame or traceback object. + + A tuple of five things is returned: the filename, the line number of + the current line, the function name, a list of lines of context from + the source code, and the index of the current line within that list. + The optional second argument specifies the number of lines of context + to return, which are centered around the current line.""" + raise NotImplementedError +# if istraceback(frame): +# frame = frame.tb_frame +# if not isframe(frame): +# raise TypeError, 'arg is not a frame or traceback object' +# +# filename = getsourcefile(frame) +# lineno = getlineno(frame) +# if context > 0: +# start = lineno - 1 - context//2 +# try: +# lines, lnum = findsource(frame) +# except IOError: +# lines = index = None +# else: +# start = max(start, 1) +# start = min(start, len(lines) - context) +# lines = lines[start:start+context] +# index = lineno - 1 - start +# else: +# lines = index = None +# +# return (filename, lineno, frame.f_code.co_name, lines, index) + +def getlineno(frame): + """Get the line number from a frame object, allowing for optimization.""" + # Written by Marc-Andr Lemburg; revised by Jim Hugunin and Fredrik Lundh. + lineno = frame.f_lineno + code = frame.f_code + if hasattr(code, 'co_lnotab'): + table = code.co_lnotab + lineno = code.co_firstlineno + addr = 0 + for i in range(0, len(table), 2): + addr = addr + ord(table[i]) + if addr > frame.f_lasti: break + lineno = lineno + ord(table[i + 1]) + return lineno + +def getouterframes(frame, context=1): + """Get a list of records for a frame and all higher (calling) frames. + + Each record contains a frame object, filename, line number, function + name, a list of lines of context, and index within the context.""" + framelist = [] + while frame: + framelist.append((frame,) + getframeinfo(frame, context)) + frame = frame.f_back + return framelist + +def getinnerframes(tb, context=1): + """Get a list of records for a traceback's frame and all lower frames. + + Each record contains a frame object, filename, line number, function + name, a list of lines of context, and index within the context.""" + framelist = [] + while tb: + framelist.append((tb.tb_frame,) + getframeinfo(tb, context)) + tb = tb.tb_next + return framelist + +def currentframe(): + """Return the frame object for the caller's stack frame.""" + try: + raise 'catch me' + except: + return sys.exc_traceback.tb_frame.f_back #@UndefinedVariable + +if hasattr(sys, '_getframe'): currentframe = sys._getframe + +def stack(context=1): + """Return a list of records for the stack above the caller's frame.""" + return getouterframes(currentframe().f_back, context) + +def trace(context=1): + """Return a list of records for the stack below the current exception.""" + return getinnerframes(sys.exc_traceback, context) #@UndefinedVariable diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_pkgutil_old.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_pkgutil_old.py new file mode 100644 index 0000000..ce072ec --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_pkgutil_old.py @@ -0,0 +1,591 @@ +"""Utilities to support packages.""" + +# NOTE: This module must remain compatible with Python 2.3, as it is shared +# by setuptools for distribution with Python 2.3 and up. + +import os +import sys +import imp +import os.path +from types import ModuleType + +__all__ = [ + 'get_importer', 'iter_importers', 'get_loader', 'find_loader', + 'walk_packages', 'iter_modules', 'get_data', + 'ImpImporter', 'ImpLoader', 'read_code', 'extend_path', +] + +def read_code(stream): + # This helper is needed in order for the PEP 302 emulation to + # correctly handle compiled files + import marshal + + magic = stream.read(4) + if magic != imp.get_magic(): + return None + + stream.read(4) # Skip timestamp + return marshal.load(stream) + + +def simplegeneric(func): + """Make a trivial single-dispatch generic function""" + registry = {} + def wrapper(*args, **kw): + ob = args[0] + try: + cls = ob.__class__ + except AttributeError: + cls = type(ob) + try: + mro = cls.__mro__ + except AttributeError: + try: + class cls(cls, object): + pass + mro = cls.__mro__[1:] + except TypeError: + mro = object, # must be an ExtensionClass or some such :( + for t in mro: + if t in registry: + return registry[t](*args, **kw) + else: + return func(*args, **kw) + try: + wrapper.__name__ = func.__name__ + except (TypeError, AttributeError): + pass # Python 2.3 doesn't allow functions to be renamed + + def register(typ, func=None): + if func is None: + return lambda f: register(typ, f) + registry[typ] = func + return func + + wrapper.__dict__ = func.__dict__ + wrapper.__doc__ = func.__doc__ + wrapper.register = register + return wrapper + + +def walk_packages(path=None, prefix='', onerror=None): + """Yields (module_loader, name, ispkg) for all modules recursively + on path, or, if path is None, all accessible modules. + + 'path' should be either None or a list of paths to look for + modules in. + + 'prefix' is a string to output on the front of every module name + on output. + + Note that this function must import all *packages* (NOT all + modules!) on the given path, in order to access the __path__ + attribute to find submodules. + + 'onerror' is a function which gets called with one argument (the + name of the package which was being imported) if any exception + occurs while trying to import a package. If no onerror function is + supplied, ImportErrors are caught and ignored, while all other + exceptions are propagated, terminating the search. + + Examples: + + # list all modules python can access + walk_packages() + + # list all submodules of ctypes + walk_packages(ctypes.__path__, ctypes.__name__+'.') + """ + + def seen(p, m={}): + if p in m: + return True + m[p] = True + + for importer, name, ispkg in iter_modules(path, prefix): + yield importer, name, ispkg + + if ispkg: + try: + __import__(name) + except ImportError: + if onerror is not None: + onerror(name) + except Exception: + if onerror is not None: + onerror(name) + else: + raise + else: + path = getattr(sys.modules[name], '__path__', None) or [] + + # don't traverse path items we've seen before + path = [p for p in path if not seen(p)] + + for item in walk_packages(path, name+'.', onerror): + yield item + + +def iter_modules(path=None, prefix=''): + """Yields (module_loader, name, ispkg) for all submodules on path, + or, if path is None, all top-level modules on sys.path. + + 'path' should be either None or a list of paths to look for + modules in. + + 'prefix' is a string to output on the front of every module name + on output. + """ + + if path is None: + importers = iter_importers() + else: + importers = map(get_importer, path) + + yielded = {} + for i in importers: + for name, ispkg in iter_importer_modules(i, prefix): + if name not in yielded: + yielded[name] = 1 + yield i, name, ispkg + + +#@simplegeneric +def iter_importer_modules(importer, prefix=''): + if not hasattr(importer, 'iter_modules'): + return [] + return importer.iter_modules(prefix) + +iter_importer_modules = simplegeneric(iter_importer_modules) + + +class ImpImporter: + """PEP 302 Importer that wraps Python's "classic" import algorithm + + ImpImporter(dirname) produces a PEP 302 importer that searches that + directory. ImpImporter(None) produces a PEP 302 importer that searches + the current sys.path, plus any modules that are frozen or built-in. + + Note that ImpImporter does not currently support being used by placement + on sys.meta_path. + """ + + def __init__(self, path=None): + self.path = path + + def find_module(self, fullname, path=None): + # Note: we ignore 'path' argument since it is only used via meta_path + subname = fullname.split(".")[-1] + if subname != fullname and self.path is None: + return None + if self.path is None: + path = None + else: + path = [os.path.realpath(self.path)] + try: + file, filename, etc = imp.find_module(subname, path) + except ImportError: + return None + return ImpLoader(fullname, file, filename, etc) + + def iter_modules(self, prefix=''): + if self.path is None or not os.path.isdir(self.path): + return + + yielded = {} + import inspect + try: + filenames = os.listdir(self.path) + except OSError: + # ignore unreadable directories like import does + filenames = [] + filenames.sort() # handle packages before same-named modules + + for fn in filenames: + modname = inspect.getmodulename(fn) + if modname=='__init__' or modname in yielded: + continue + + path = os.path.join(self.path, fn) + ispkg = False + + if not modname and os.path.isdir(path) and '.' not in fn: + modname = fn + try: + dircontents = os.listdir(path) + except OSError: + # ignore unreadable directories like import does + dircontents = [] + for fn in dircontents: + subname = inspect.getmodulename(fn) + if subname=='__init__': + ispkg = True + break + else: + continue # not a package + + if modname and '.' not in modname: + yielded[modname] = 1 + yield prefix + modname, ispkg + + +class ImpLoader: + """PEP 302 Loader that wraps Python's "classic" import algorithm + """ + code = source = None + + def __init__(self, fullname, file, filename, etc): + self.file = file + self.filename = filename + self.fullname = fullname + self.etc = etc + + def load_module(self, fullname): + self._reopen() + try: + mod = imp.load_module(fullname, self.file, self.filename, self.etc) + finally: + if self.file: + self.file.close() + # Note: we don't set __loader__ because we want the module to look + # normal; i.e. this is just a wrapper for standard import machinery + return mod + + def get_data(self, pathname): + return open(pathname, "rb").read() + + def _reopen(self): + if self.file and self.file.closed: + mod_type = self.etc[2] + if mod_type==imp.PY_SOURCE: + self.file = open(self.filename, 'rU') + elif mod_type in (imp.PY_COMPILED, imp.C_EXTENSION): + self.file = open(self.filename, 'rb') + + def _fix_name(self, fullname): + if fullname is None: + fullname = self.fullname + elif fullname != self.fullname: + raise ImportError("Loader for module %s cannot handle " + "module %s" % (self.fullname, fullname)) + return fullname + + def is_package(self, fullname): + fullname = self._fix_name(fullname) + return self.etc[2]==imp.PKG_DIRECTORY + + def get_code(self, fullname=None): + fullname = self._fix_name(fullname) + if self.code is None: + mod_type = self.etc[2] + if mod_type==imp.PY_SOURCE: + source = self.get_source(fullname) + self.code = compile(source, self.filename, 'exec') + elif mod_type==imp.PY_COMPILED: + self._reopen() + try: + self.code = read_code(self.file) + finally: + self.file.close() + elif mod_type==imp.PKG_DIRECTORY: + self.code = self._get_delegate().get_code() + return self.code + + def get_source(self, fullname=None): + fullname = self._fix_name(fullname) + if self.source is None: + mod_type = self.etc[2] + if mod_type==imp.PY_SOURCE: + self._reopen() + try: + self.source = self.file.read() + finally: + self.file.close() + elif mod_type==imp.PY_COMPILED: + if os.path.exists(self.filename[:-1]): + f = open(self.filename[:-1], 'rU') + self.source = f.read() + f.close() + elif mod_type==imp.PKG_DIRECTORY: + self.source = self._get_delegate().get_source() + return self.source + + + def _get_delegate(self): + return ImpImporter(self.filename).find_module('__init__') + + def get_filename(self, fullname=None): + fullname = self._fix_name(fullname) + mod_type = self.etc[2] + if self.etc[2]==imp.PKG_DIRECTORY: + return self._get_delegate().get_filename() + elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION): + return self.filename + return None + + +try: + import zipimport + from zipimport import zipimporter + + def iter_zipimport_modules(importer, prefix=''): + dirlist = zipimport._zip_directory_cache[importer.archive].keys() + dirlist.sort() + _prefix = importer.prefix + plen = len(_prefix) + yielded = {} + import inspect + for fn in dirlist: + if not fn.startswith(_prefix): + continue + + fn = fn[plen:].split(os.sep) + + if len(fn)==2 and fn[1].startswith('__init__.py'): + if fn[0] not in yielded: + yielded[fn[0]] = 1 + yield fn[0], True + + if len(fn)!=1: + continue + + modname = inspect.getmodulename(fn[0]) + if modname=='__init__': + continue + + if modname and '.' not in modname and modname not in yielded: + yielded[modname] = 1 + yield prefix + modname, False + + iter_importer_modules.register(zipimporter, iter_zipimport_modules) + +except ImportError: + pass + + +def get_importer(path_item): + """Retrieve a PEP 302 importer for the given path item + + The returned importer is cached in sys.path_importer_cache + if it was newly created by a path hook. + + If there is no importer, a wrapper around the basic import + machinery is returned. This wrapper is never inserted into + the importer cache (None is inserted instead). + + The cache (or part of it) can be cleared manually if a + rescan of sys.path_hooks is necessary. + """ + try: + importer = sys.path_importer_cache[path_item] + except KeyError: + for path_hook in sys.path_hooks: + try: + importer = path_hook(path_item) + break + except ImportError: + pass + else: + importer = None + sys.path_importer_cache.setdefault(path_item, importer) + + if importer is None: + try: + importer = ImpImporter(path_item) + except ImportError: + importer = None + return importer + + +def iter_importers(fullname=""): + """Yield PEP 302 importers for the given module name + + If fullname contains a '.', the importers will be for the package + containing fullname, otherwise they will be importers for sys.meta_path, + sys.path, and Python's "classic" import machinery, in that order. If + the named module is in a package, that package is imported as a side + effect of invoking this function. + + Non PEP 302 mechanisms (e.g. the Windows registry) used by the + standard import machinery to find files in alternative locations + are partially supported, but are searched AFTER sys.path. Normally, + these locations are searched BEFORE sys.path, preventing sys.path + entries from shadowing them. + + For this to cause a visible difference in behaviour, there must + be a module or package name that is accessible via both sys.path + and one of the non PEP 302 file system mechanisms. In this case, + the emulation will find the former version, while the builtin + import mechanism will find the latter. + + Items of the following types can be affected by this discrepancy: + imp.C_EXTENSION, imp.PY_SOURCE, imp.PY_COMPILED, imp.PKG_DIRECTORY + """ + if fullname.startswith('.'): + raise ImportError("Relative module names not supported") + if '.' in fullname: + # Get the containing package's __path__ + pkg = '.'.join(fullname.split('.')[:-1]) + if pkg not in sys.modules: + __import__(pkg) + path = getattr(sys.modules[pkg], '__path__', None) or [] + else: + for importer in sys.meta_path: + yield importer + path = sys.path + for item in path: + yield get_importer(item) + if '.' not in fullname: + yield ImpImporter() + +def get_loader(module_or_name): + """Get a PEP 302 "loader" object for module_or_name + + If the module or package is accessible via the normal import + mechanism, a wrapper around the relevant part of that machinery + is returned. Returns None if the module cannot be found or imported. + If the named module is not already imported, its containing package + (if any) is imported, in order to establish the package __path__. + + This function uses iter_importers(), and is thus subject to the same + limitations regarding platform-specific special import locations such + as the Windows registry. + """ + if module_or_name in sys.modules: + module_or_name = sys.modules[module_or_name] + if isinstance(module_or_name, ModuleType): + module = module_or_name + loader = getattr(module, '__loader__', None) + if loader is not None: + return loader + fullname = module.__name__ + else: + fullname = module_or_name + return find_loader(fullname) + +def find_loader(fullname): + """Find a PEP 302 "loader" object for fullname + + If fullname contains dots, path must be the containing package's __path__. + Returns None if the module cannot be found or imported. This function uses + iter_importers(), and is thus subject to the same limitations regarding + platform-specific special import locations such as the Windows registry. + """ + for importer in iter_importers(fullname): + loader = importer.find_module(fullname) + if loader is not None: + return loader + + return None + + +def extend_path(path, name): + """Extend a package's path. + + Intended use is to place the following code in a package's __init__.py: + + from pkgutil import extend_path + __path__ = extend_path(__path__, __name__) + + This will add to the package's __path__ all subdirectories of + directories on sys.path named after the package. This is useful + if one wants to distribute different parts of a single logical + package as multiple directories. + + It also looks for *.pkg files beginning where * matches the name + argument. This feature is similar to *.pth files (see site.py), + except that it doesn't special-case lines starting with 'import'. + A *.pkg file is trusted at face value: apart from checking for + duplicates, all entries found in a *.pkg file are added to the + path, regardless of whether they are exist the filesystem. (This + is a feature.) + + If the input path is not a list (as is the case for frozen + packages) it is returned unchanged. The input path is not + modified; an extended copy is returned. Items are only appended + to the copy at the end. + + It is assumed that sys.path is a sequence. Items of sys.path that + are not (unicode or 8-bit) strings referring to existing + directories are ignored. Unicode items of sys.path that cause + errors when used as filenames may cause this function to raise an + exception (in line with os.path.isdir() behavior). + """ + + if not isinstance(path, list): + # This could happen e.g. when this is called from inside a + # frozen package. Return the path unchanged in that case. + return path + + pname = os.path.join(*name.split('.')) # Reconstitute as relative path + # Just in case os.extsep != '.' + sname = os.extsep.join(name.split('.')) + sname_pkg = sname + os.extsep + "pkg" + init_py = "__init__" + os.extsep + "py" + + path = path[:] # Start with a copy of the existing path + + for dir in sys.path: + if not isinstance(dir, basestring) or not os.path.isdir(dir): + continue + subdir = os.path.join(dir, pname) + # XXX This may still add duplicate entries to path on + # case-insensitive filesystems + initfile = os.path.join(subdir, init_py) + if subdir not in path and os.path.isfile(initfile): + path.append(subdir) + # XXX Is this the right thing for subpackages like zope.app? + # It looks for a file named "zope.app.pkg" + pkgfile = os.path.join(dir, sname_pkg) + if os.path.isfile(pkgfile): + try: + f = open(pkgfile) + except IOError, msg: + sys.stderr.write("Can't open %s: %s\n" % + (pkgfile, msg)) + else: + for line in f: + line = line.rstrip('\n') + if not line or line.startswith('#'): + continue + path.append(line) # Don't check for existence! + f.close() + + return path + +def get_data(package, resource): + """Get a resource from a package. + + This is a wrapper round the PEP 302 loader get_data API. The package + argument should be the name of a package, in standard module format + (foo.bar). The resource argument should be in the form of a relative + filename, using '/' as the path separator. The parent directory name '..' + is not allowed, and nor is a rooted name (starting with a '/'). + + The function returns a binary string, which is the contents of the + specified resource. + + For packages located in the filesystem, which have already been imported, + this is the rough equivalent of + + d = os.path.dirname(sys.modules[package].__file__) + data = open(os.path.join(d, resource), 'rb').read() + + If the package cannot be located or loaded, or it uses a PEP 302 loader + which does not support get_data(), then None is returned. + """ + + loader = get_loader(package) + if loader is None or not hasattr(loader, 'get_data'): + return None + mod = sys.modules.get(package) or loader.load_module(package) + if mod is None or not hasattr(mod, '__file__'): + return None + + # Modify the resource name to be compatible with the loader.get_data + # signature - an os.path format "filename" starting with the dirname of + # the package's __file__ + parts = resource.split('/') + parts.insert(0, os.path.dirname(mod.__file__)) + resource_name = os.path.join(*parts) + return loader.get_data(resource_name) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_saved_modules.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_saved_modules.py new file mode 100644 index 0000000..6ff3939 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_saved_modules.py @@ -0,0 +1,23 @@ +import sys +IS_PY2 = sys.version_info < (3,) + +import threading + +import time + +import socket + +import select + +if IS_PY2: + import thread + import Queue as _queue + import xmlrpclib + import SimpleXMLRPCServer as _pydev_SimpleXMLRPCServer + import BaseHTTPServer +else: + import _thread as thread + import queue as _queue + import xmlrpc.client as xmlrpclib + import xmlrpc.server as _pydev_SimpleXMLRPCServer + import http.server as BaseHTTPServer \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_sys_patch.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_sys_patch.py new file mode 100644 index 0000000..0220ad0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_sys_patch.py @@ -0,0 +1,75 @@ + +import sys + + +def patch_sys_module(): + def patched_exc_info(fun): + def pydev_debugger_exc_info(): + type, value, traceback = fun() + if type == ImportError: + #we should not show frame added by plugin_import call + if traceback and hasattr(traceback, "tb_next"): + return type, value, traceback.tb_next + return type, value, traceback + return pydev_debugger_exc_info + + system_exc_info = sys.exc_info + sys.exc_info = patched_exc_info(system_exc_info) + if not hasattr(sys, "system_exc_info"): + sys.system_exc_info = system_exc_info + + +def patched_reload(orig_reload): + def pydev_debugger_reload(module): + orig_reload(module) + if module.__name__ == "sys": + # if sys module was reloaded we should patch it again + patch_sys_module() + return pydev_debugger_reload + + +def patch_reload(): + if sys.version_info[0] >= 3: + import builtins # Py3 + else: + import __builtin__ as builtins + + if hasattr(builtins, "reload"): + sys.builtin_orig_reload = builtins.reload + builtins.reload = patched_reload(sys.builtin_orig_reload) # @UndefinedVariable + try: + import imp + sys.imp_orig_reload = imp.reload + imp.reload = patched_reload(sys.imp_orig_reload) # @UndefinedVariable + except: + pass + else: + try: + import importlib + sys.importlib_orig_reload = importlib.reload # @UndefinedVariable + importlib.reload = patched_reload(sys.importlib_orig_reload) # @UndefinedVariable + except: + pass + + del builtins + + +def cancel_patches_in_sys_module(): + sys.exc_info = sys.system_exc_info # @UndefinedVariable + if sys.version_info[0] >= 3: + import builtins # Py3 + else: + import __builtin__ as builtins + + if hasattr(sys, "builtin_orig_reload"): + builtins.reload = sys.builtin_orig_reload + + if hasattr(sys, "imp_orig_reload"): + import imp + imp.reload = sys.imp_orig_reload + + if hasattr(sys, "importlib_orig_reload"): + import importlib + importlib.reload = sys.importlib_orig_reload + + del builtins diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_uuid_old.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_uuid_old.py new file mode 100644 index 0000000..20bc43b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_uuid_old.py @@ -0,0 +1,541 @@ +r"""UUID objects (universally unique identifiers) according to RFC 4122. + +This module provides immutable UUID objects (class UUID) and the functions +uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 +UUIDs as specified in RFC 4122. + +If all you want is a unique ID, you should probably call uuid1() or uuid4(). +Note that uuid1() may compromise privacy since it creates a UUID containing +the computer's network address. uuid4() creates a random UUID. + +Typical usage: + + >>> import uuid + + # make a UUID based on the host ID and current time + >>> uuid.uuid1() + UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') + + # make a UUID using an MD5 hash of a namespace UUID and a name + >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') + UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') + + # make a random UUID + >>> uuid.uuid4() + UUID('16fd2706-8baf-433b-82eb-8c7fada847da') + + # make a UUID using a SHA-1 hash of a namespace UUID and a name + >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') + UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') + + # make a UUID from a string of hex digits (braces and hyphens ignored) + >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') + + # convert a UUID to a string of hex digits in standard form + >>> str(x) + '00010203-0405-0607-0809-0a0b0c0d0e0f' + + # get the raw 16 bytes of the UUID + >>> x.bytes + '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f' + + # make a UUID from a 16-byte string + >>> uuid.UUID(bytes=x.bytes) + UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') +""" + +__author__ = 'Ka-Ping Yee ' + +RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [ + 'reserved for NCS compatibility', 'specified in RFC 4122', + 'reserved for Microsoft compatibility', 'reserved for future definition'] + +class UUID(object): + """Instances of the UUID class represent UUIDs as specified in RFC 4122. + UUID objects are immutable, hashable, and usable as dictionary keys. + Converting a UUID to a string with str() yields something in the form + '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts + five possible forms: a similar string of hexadecimal digits, or a tuple + of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and + 48-bit values respectively) as an argument named 'fields', or a string + of 16 bytes (with all the integer fields in big-endian order) as an + argument named 'bytes', or a string of 16 bytes (with the first three + fields in little-endian order) as an argument named 'bytes_le', or a + single 128-bit integer as an argument named 'int'. + + UUIDs have these read-only attributes: + + bytes the UUID as a 16-byte string (containing the six + integer fields in big-endian byte order) + + bytes_le the UUID as a 16-byte string (with time_low, time_mid, + and time_hi_version in little-endian byte order) + + fields a tuple of the six integer fields of the UUID, + which are also available as six individual attributes + and two derived attributes: + + time_low the first 32 bits of the UUID + time_mid the next 16 bits of the UUID + time_hi_version the next 16 bits of the UUID + clock_seq_hi_variant the next 8 bits of the UUID + clock_seq_low the next 8 bits of the UUID + node the last 48 bits of the UUID + + time the 60-bit timestamp + clock_seq the 14-bit sequence number + + hex the UUID as a 32-character hexadecimal string + + int the UUID as a 128-bit integer + + urn the UUID as a URN as specified in RFC 4122 + + variant the UUID variant (one of the constants RESERVED_NCS, + RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE) + + version the UUID version number (1 through 5, meaningful only + when the variant is RFC_4122) + """ + + def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, + int=None, version=None): + r"""Create a UUID from either a string of 32 hexadecimal digits, + a string of 16 bytes as the 'bytes' argument, a string of 16 bytes + in little-endian order as the 'bytes_le' argument, a tuple of six + integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version, + 8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as + the 'fields' argument, or a single 128-bit integer as the 'int' + argument. When a string of hex digits is given, curly braces, + hyphens, and a URN prefix are all optional. For example, these + expressions all yield the same UUID: + + UUID('{12345678-1234-5678-1234-567812345678}') + UUID('12345678123456781234567812345678') + UUID('urn:uuid:12345678-1234-5678-1234-567812345678') + UUID(bytes='\x12\x34\x56\x78'*4) + UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' + + '\x12\x34\x56\x78\x12\x34\x56\x78') + UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678)) + UUID(int=0x12345678123456781234567812345678) + + Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must + be given. The 'version' argument is optional; if given, the resulting + UUID will have its variant and version set according to RFC 4122, + overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'. + """ + + if [hex, bytes, bytes_le, fields, int].count(None) != 4: + raise TypeError('need one of hex, bytes, bytes_le, fields, or int') + if hex is not None: + hex = hex.replace('urn:', '').replace('uuid:', '') + hex = hex.strip('{}').replace('-', '') + if len(hex) != 32: + raise ValueError('badly formed hexadecimal UUID string') + int = long(hex, 16) + if bytes_le is not None: + if len(bytes_le) != 16: + raise ValueError('bytes_le is not a 16-char string') + bytes = (bytes_le[3] + bytes_le[2] + bytes_le[1] + bytes_le[0] + + bytes_le[5] + bytes_le[4] + bytes_le[7] + bytes_le[6] + + bytes_le[8:]) + if bytes is not None: + if len(bytes) != 16: + raise ValueError('bytes is not a 16-char string') + int = long(('%02x'*16) % tuple(map(ord, bytes)), 16) + if fields is not None: + if len(fields) != 6: + raise ValueError('fields is not a 6-tuple') + (time_low, time_mid, time_hi_version, + clock_seq_hi_variant, clock_seq_low, node) = fields + if not 0 <= time_low < 1<<32L: + raise ValueError('field 1 out of range (need a 32-bit value)') + if not 0 <= time_mid < 1<<16L: + raise ValueError('field 2 out of range (need a 16-bit value)') + if not 0 <= time_hi_version < 1<<16L: + raise ValueError('field 3 out of range (need a 16-bit value)') + if not 0 <= clock_seq_hi_variant < 1<<8L: + raise ValueError('field 4 out of range (need an 8-bit value)') + if not 0 <= clock_seq_low < 1<<8L: + raise ValueError('field 5 out of range (need an 8-bit value)') + if not 0 <= node < 1<<48L: + raise ValueError('field 6 out of range (need a 48-bit value)') + clock_seq = (clock_seq_hi_variant << 8L) | clock_seq_low + int = ((time_low << 96L) | (time_mid << 80L) | + (time_hi_version << 64L) | (clock_seq << 48L) | node) + if int is not None: + if not 0 <= int < 1<<128L: + raise ValueError('int is out of range (need a 128-bit value)') + if version is not None: + if not 1 <= version <= 5: + raise ValueError('illegal version number') + # Set the variant to RFC 4122. + int &= ~(0xc000 << 48L) + int |= 0x8000 << 48L + # Set the version number. + int &= ~(0xf000 << 64L) + int |= version << 76L + self.__dict__['int'] = int + + def __cmp__(self, other): + if isinstance(other, UUID): + return cmp(self.int, other.int) + return NotImplemented + + def __hash__(self): + return hash(self.int) + + def __int__(self): + return self.int + + def __repr__(self): + return 'UUID(%r)' % str(self) + + def __setattr__(self, name, value): + raise TypeError('UUID objects are immutable') + + def __str__(self): + hex = '%032x' % self.int + return '%s-%s-%s-%s-%s' % ( + hex[:8], hex[8:12], hex[12:16], hex[16:20], hex[20:]) + + def get_bytes(self): + bytes = '' + for shift in range(0, 128, 8): + bytes = chr((self.int >> shift) & 0xff) + bytes + return bytes + + bytes = property(get_bytes) + + def get_bytes_le(self): + bytes = self.bytes + return (bytes[3] + bytes[2] + bytes[1] + bytes[0] + + bytes[5] + bytes[4] + bytes[7] + bytes[6] + bytes[8:]) + + bytes_le = property(get_bytes_le) + + def get_fields(self): + return (self.time_low, self.time_mid, self.time_hi_version, + self.clock_seq_hi_variant, self.clock_seq_low, self.node) + + fields = property(get_fields) + + def get_time_low(self): + return self.int >> 96L + + time_low = property(get_time_low) + + def get_time_mid(self): + return (self.int >> 80L) & 0xffff + + time_mid = property(get_time_mid) + + def get_time_hi_version(self): + return (self.int >> 64L) & 0xffff + + time_hi_version = property(get_time_hi_version) + + def get_clock_seq_hi_variant(self): + return (self.int >> 56L) & 0xff + + clock_seq_hi_variant = property(get_clock_seq_hi_variant) + + def get_clock_seq_low(self): + return (self.int >> 48L) & 0xff + + clock_seq_low = property(get_clock_seq_low) + + def get_time(self): + return (((self.time_hi_version & 0x0fffL) << 48L) | + (self.time_mid << 32L) | self.time_low) + + time = property(get_time) + + def get_clock_seq(self): + return (((self.clock_seq_hi_variant & 0x3fL) << 8L) | + self.clock_seq_low) + + clock_seq = property(get_clock_seq) + + def get_node(self): + return self.int & 0xffffffffffff + + node = property(get_node) + + def get_hex(self): + return '%032x' % self.int + + hex = property(get_hex) + + def get_urn(self): + return 'urn:uuid:' + str(self) + + urn = property(get_urn) + + def get_variant(self): + if not self.int & (0x8000 << 48L): + return RESERVED_NCS + elif not self.int & (0x4000 << 48L): + return RFC_4122 + elif not self.int & (0x2000 << 48L): + return RESERVED_MICROSOFT + else: + return RESERVED_FUTURE + + variant = property(get_variant) + + def get_version(self): + # The version bits are only meaningful for RFC 4122 UUIDs. + if self.variant == RFC_4122: + return int((self.int >> 76L) & 0xf) + + version = property(get_version) + +def _find_mac(command, args, hw_identifiers, get_index): + import os + for dir in ['', '/sbin/', '/usr/sbin']: + executable = os.path.join(dir, command) + if not os.path.exists(executable): + continue + + try: + # LC_ALL to get English output, 2>/dev/null to + # prevent output on stderr + cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) + pipe = os.popen(cmd) + except IOError: + continue + + for line in pipe: + words = line.lower().split() + for i in range(len(words)): + if words[i] in hw_identifiers: + return int(words[get_index(i)].replace(':', ''), 16) + return None + +def _ifconfig_getnode(): + """Get the hardware address on Unix by running ifconfig.""" + + # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes. + for args in ('', '-a', '-av'): + mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i+1) + if mac: + return mac + + import socket + ip_addr = socket.gethostbyname(socket.gethostname()) + + # Try getting the MAC addr from arp based on our IP address (Solaris). + mac = _find_mac('arp', '-an', [ip_addr], lambda i: -1) + if mac: + return mac + + # This might work on HP-UX. + mac = _find_mac('lanscan', '-ai', ['lan0'], lambda i: 0) + if mac: + return mac + + return None + +def _ipconfig_getnode(): + """Get the hardware address on Windows by running ipconfig.exe.""" + import os, re + dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] + try: + import ctypes + buffer = ctypes.create_string_buffer(300) + ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300) # @UndefinedVariable + dirs.insert(0, buffer.value.decode('mbcs')) + except: + pass + for dir in dirs: + try: + pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') + except IOError: + continue + for line in pipe: + value = line.split(':')[-1].strip().lower() + if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): + return int(value.replace('-', ''), 16) + +def _netbios_getnode(): + """Get the hardware address on Windows using NetBIOS calls. + See http://support.microsoft.com/kb/118623 for details.""" + import win32wnet, netbios + ncb = netbios.NCB() + ncb.Command = netbios.NCBENUM + ncb.Buffer = adapters = netbios.LANA_ENUM() + adapters._pack() + if win32wnet.Netbios(ncb) != 0: + return + adapters._unpack() + for i in range(adapters.length): + ncb.Reset() + ncb.Command = netbios.NCBRESET + ncb.Lana_num = ord(adapters.lana[i]) + if win32wnet.Netbios(ncb) != 0: + continue + ncb.Reset() + ncb.Command = netbios.NCBASTAT + ncb.Lana_num = ord(adapters.lana[i]) + ncb.Callname = '*'.ljust(16) + ncb.Buffer = status = netbios.ADAPTER_STATUS() + if win32wnet.Netbios(ncb) != 0: + continue + status._unpack() + bytes = map(ord, status.adapter_address) + return ((bytes[0]<<40L) + (bytes[1]<<32L) + (bytes[2]<<24L) + + (bytes[3]<<16L) + (bytes[4]<<8L) + bytes[5]) + +# Thanks to Thomas Heller for ctypes and for his help with its use here. + +# If ctypes is available, use it to find system routines for UUID generation. +_uuid_generate_random = _uuid_generate_time = _UuidCreate = None +try: + import ctypes, ctypes.util + _buffer = ctypes.create_string_buffer(16) + + # The uuid_generate_* routines are provided by libuuid on at least + # Linux and FreeBSD, and provided by libc on Mac OS X. + for libname in ['uuid', 'c']: + try: + lib = ctypes.CDLL(ctypes.util.find_library(libname)) + except: + continue + if hasattr(lib, 'uuid_generate_random'): + _uuid_generate_random = lib.uuid_generate_random + if hasattr(lib, 'uuid_generate_time'): + _uuid_generate_time = lib.uuid_generate_time + + # On Windows prior to 2000, UuidCreate gives a UUID containing the + # hardware address. On Windows 2000 and later, UuidCreate makes a + # random UUID and UuidCreateSequential gives a UUID containing the + # hardware address. These routines are provided by the RPC runtime. + # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last + # 6 bytes returned by UuidCreateSequential are fixed, they don't appear + # to bear any relationship to the MAC address of any network device + # on the box. + try: + lib = ctypes.windll.rpcrt4 + except: + lib = None + _UuidCreate = getattr(lib, 'UuidCreateSequential', + getattr(lib, 'UuidCreate', None)) +except: + pass + +def _unixdll_getnode(): + """Get the hardware address on Unix using ctypes.""" + _uuid_generate_time(_buffer) + return UUID(bytes=_buffer.raw).node + +def _windll_getnode(): + """Get the hardware address on Windows using ctypes.""" + if _UuidCreate(_buffer) == 0: + return UUID(bytes=_buffer.raw).node + +def _random_getnode(): + """Get a random node ID, with eighth bit set as suggested by RFC 4122.""" + import random + return random.randrange(0, 1<<48L) | 0x010000000000L + +_node = None + +def getnode(): + """Get the hardware address as a 48-bit positive integer. + + The first time this runs, it may launch a separate program, which could + be quite slow. If all attempts to obtain the hardware address fail, we + choose a random 48-bit number with its eighth bit set to 1 as recommended + in RFC 4122. + """ + + global _node + if _node is not None: + return _node + + import sys + if sys.platform == 'win32': + getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode] + else: + getters = [_unixdll_getnode, _ifconfig_getnode] + + for getter in getters + [_random_getnode]: + try: + _node = getter() + except: + continue + if _node is not None: + return _node + +_last_timestamp = None + +def uuid1(node=None, clock_seq=None): + """Generate a UUID from a host ID, sequence number, and the current time. + If 'node' is not given, getnode() is used to obtain the hardware + address. If 'clock_seq' is given, it is used as the sequence number; + otherwise a random 14-bit sequence number is chosen.""" + + # When the system provides a version-1 UUID generator, use it (but don't + # use UuidCreate here because its UUIDs don't conform to RFC 4122). + if _uuid_generate_time and node is clock_seq is None: + _uuid_generate_time(_buffer) + return UUID(bytes=_buffer.raw) + + global _last_timestamp + import time + nanoseconds = int(time.time() * 1e9) + # 0x01b21dd213814000 is the number of 100-ns intervals between the + # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. + timestamp = int(nanoseconds/100) + 0x01b21dd213814000L + if timestamp <= _last_timestamp: + timestamp = _last_timestamp + 1 + _last_timestamp = timestamp + if clock_seq is None: + import random + clock_seq = random.randrange(1<<14L) # instead of stable storage + time_low = timestamp & 0xffffffffL + time_mid = (timestamp >> 32L) & 0xffffL + time_hi_version = (timestamp >> 48L) & 0x0fffL + clock_seq_low = clock_seq & 0xffL + clock_seq_hi_variant = (clock_seq >> 8L) & 0x3fL + if node is None: + node = getnode() + return UUID(fields=(time_low, time_mid, time_hi_version, + clock_seq_hi_variant, clock_seq_low, node), version=1) + +def uuid3(namespace, name): + """Generate a UUID from the MD5 hash of a namespace UUID and a name.""" + import md5 + hash = md5.md5(namespace.bytes + name).digest() + return UUID(bytes=hash[:16], version=3) + +def uuid4(): + """Generate a random UUID.""" + + # When the system provides a version-4 UUID generator, use it. + if _uuid_generate_random: + _uuid_generate_random(_buffer) + return UUID(bytes=_buffer.raw) + + # Otherwise, get randomness from urandom or the 'random' module. + try: + import os + return UUID(bytes=os.urandom(16), version=4) + except: + import random + bytes = [chr(random.randrange(256)) for i in range(16)] + return UUID(bytes=bytes, version=4) + +def uuid5(namespace, name): + """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" + import sha + hash = sha.sha(namespace.bytes + name).digest() + return UUID(bytes=hash[:16], version=5) + +# The following standard UUIDs are for use with uuid3() or uuid5(). + +NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8') +NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8') +NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8') +NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8') diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_xmlrpclib.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_xmlrpclib.py new file mode 100644 index 0000000..5f6e2b7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_imps/_pydev_xmlrpclib.py @@ -0,0 +1,1493 @@ +#Just a copy of the version in python 2.5 to be used if it's not available in jython 2.1 +import sys + +# +# XML-RPC CLIENT LIBRARY +# +# an XML-RPC client interface for Python. +# +# the marshalling and response parser code can also be used to +# implement XML-RPC servers. +# +# Notes: +# this version is designed to work with Python 2.1 or newer. +# +# History: +# 1999-01-14 fl Created +# 1999-01-15 fl Changed dateTime to use localtime +# 1999-01-16 fl Added Binary/base64 element, default to RPC2 service +# 1999-01-19 fl Fixed array data element (from Skip Montanaro) +# 1999-01-21 fl Fixed dateTime constructor, etc. +# 1999-02-02 fl Added fault handling, handle empty sequences, etc. +# 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro) +# 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8) +# 2000-11-28 fl Changed boolean to check the truth value of its argument +# 2001-02-24 fl Added encoding/Unicode/SafeTransport patches +# 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1) +# 2001-03-28 fl Make sure response tuple is a singleton +# 2001-03-29 fl Don't require empty params element (from Nicholas Riley) +# 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2) +# 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from Paul Prescod) +# 2001-09-03 fl Allow Transport subclass to override getparser +# 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup) +# 2001-10-01 fl Remove containers from memo cache when done with them +# 2001-10-01 fl Use faster escape method (80% dumps speedup) +# 2001-10-02 fl More dumps microtuning +# 2001-10-04 fl Make sure import expat gets a parser (from Guido van Rossum) +# 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow +# 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems) +# 2001-11-12 fl Use repr() to marshal doubles (from Paul Felix) +# 2002-03-17 fl Avoid buffered read when possible (from James Rucker) +# 2002-04-07 fl Added pythondoc comments +# 2002-04-16 fl Added __str__ methods to datetime/binary wrappers +# 2002-05-15 fl Added error constants (from Andrew Kuchling) +# 2002-06-27 fl Merged with Python CVS version +# 2002-10-22 fl Added basic authentication (based on code from Phillip Eby) +# 2003-01-22 sm Add support for the bool type +# 2003-02-27 gvr Remove apply calls +# 2003-04-24 sm Use cStringIO if available +# 2003-04-25 ak Add support for nil +# 2003-06-15 gn Add support for time.struct_time +# 2003-07-12 gp Correct marshalling of Faults +# 2003-10-31 mvl Add multicall support +# 2004-08-20 mvl Bump minimum supported Python version to 2.1 +# +# Copyright (c) 1999-2002 by Secret Labs AB. +# Copyright (c) 1999-2002 by Fredrik Lundh. +# +# info@pythonware.com +# http://www.pythonware.com +# +# -------------------------------------------------------------------- +# The XML-RPC client interface is +# +# Copyright (c) 1999-2002 by Secret Labs AB +# Copyright (c) 1999-2002 by Fredrik Lundh +# +# By obtaining, using, and/or copying this software and/or its +# associated documentation, you agree that you have read, understood, +# and will comply with the following terms and conditions: +# +# Permission to use, copy, modify, and distribute this software and +# its associated documentation for any purpose and without fee is +# hereby granted, provided that the above copyright notice appears in +# all copies, and that both that copyright notice and this permission +# notice appear in supporting documentation, and that the name of +# Secret Labs AB or the author not be used in advertising or publicity +# pertaining to distribution of the software without specific, written +# prior permission. +# +# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD +# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- +# ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR +# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# -------------------------------------------------------------------- + +# +# things to look into some day: + +# TODO: sort out True/False/boolean issues for Python 2.3 + +""" +An XML-RPC client interface for Python. + +The marshalling and response parser code can also be used to +implement XML-RPC servers. + +Exported exceptions: + + Error Base class for client errors + ProtocolError Indicates an HTTP protocol error + ResponseError Indicates a broken response package + Fault Indicates an XML-RPC fault package + +Exported classes: + + ServerProxy Represents a logical connection to an XML-RPC server + + MultiCall Executor of boxcared xmlrpc requests + Boolean boolean wrapper to generate a "boolean" XML-RPC value + DateTime dateTime wrapper for an ISO 8601 string or time tuple or + localtime integer value to generate a "dateTime.iso8601" + XML-RPC value + Binary binary data wrapper + + SlowParser Slow but safe standard parser (based on xmllib) + Marshaller Generate an XML-RPC params chunk from a Python data structure + Unmarshaller Unmarshal an XML-RPC response from incoming XML event message + Transport Handles an HTTP transaction to an XML-RPC server + SafeTransport Handles an HTTPS transaction to an XML-RPC server + +Exported constants: + + True + False + +Exported functions: + + boolean Convert any Python value to an XML-RPC boolean + getparser Create instance of the fastest available parser & attach + to an unmarshalling object + dumps Convert an argument tuple or a Fault instance to an XML-RPC + request (or response, if the methodresponse option is used). + loads Convert an XML-RPC packet to unmarshalled data plus a method + name (None if not present). +""" + +import re, string, time, operator + +from types import * + +# -------------------------------------------------------------------- +# Internal stuff + +try: + unicode +except NameError: + unicode = None # unicode support not available + +try: + import datetime +except ImportError: + datetime = None + +try: + _bool_is_builtin = False.__class__.__name__ == "bool" +except (NameError, AttributeError): + _bool_is_builtin = 0 + +def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search): + # decode non-ascii string (if possible) + if unicode and encoding and is8bit(data): + data = unicode(data, encoding) + return data + +def escape(s, replace=string.replace): + s = replace(s, "&", "&") + s = replace(s, "<", "<") + return replace(s, ">", ">",) + +if unicode: + def _stringify(string): + # convert to 7-bit ascii if possible + try: + return string.encode("ascii") + except UnicodeError: + return string +else: + def _stringify(string): + return string + +__version__ = "1.0.1" + +# xmlrpc integer limits +try: + long +except NameError: + long = int +MAXINT = long(2) ** 31 - 1 +MININT = long(-2) ** 31 + +# -------------------------------------------------------------------- +# Error constants (from Dan Libby's specification at +# http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php) + +# Ranges of errors +PARSE_ERROR = -32700 +SERVER_ERROR = -32600 +APPLICATION_ERROR = -32500 +SYSTEM_ERROR = -32400 +TRANSPORT_ERROR = -32300 + +# Specific errors +NOT_WELLFORMED_ERROR = -32700 +UNSUPPORTED_ENCODING = -32701 +INVALID_ENCODING_CHAR = -32702 +INVALID_XMLRPC = -32600 +METHOD_NOT_FOUND = -32601 +INVALID_METHOD_PARAMS = -32602 +INTERNAL_ERROR = -32603 + +# -------------------------------------------------------------------- +# Exceptions + +## +# Base class for all kinds of client-side errors. + +class Error(Exception): + """Base class for client errors.""" + def __str__(self): + return repr(self) + +## +# Indicates an HTTP-level protocol error. This is raised by the HTTP +# transport layer, if the server returns an error code other than 200 +# (OK). +# +# @param url The target URL. +# @param errcode The HTTP error code. +# @param errmsg The HTTP error message. +# @param headers The HTTP header dictionary. + +class ProtocolError(Error): + """Indicates an HTTP protocol error.""" + def __init__(self, url, errcode, errmsg, headers): + Error.__init__(self) + self.url = url + self.errcode = errcode + self.errmsg = errmsg + self.headers = headers + def __repr__(self): + return ( + "" % + (self.url, self.errcode, self.errmsg) + ) + +## +# Indicates a broken XML-RPC response package. This exception is +# raised by the unmarshalling layer, if the XML-RPC response is +# malformed. + +class ResponseError(Error): + """Indicates a broken response package.""" + pass + +## +# Indicates an XML-RPC fault response package. This exception is +# raised by the unmarshalling layer, if the XML-RPC response contains +# a fault string. This exception can also used as a class, to +# generate a fault XML-RPC message. +# +# @param faultCode The XML-RPC fault code. +# @param faultString The XML-RPC fault string. + +class Fault(Error): + """Indicates an XML-RPC fault package.""" + def __init__(self, faultCode, faultString, **extra): + Error.__init__(self) + self.faultCode = faultCode + self.faultString = faultString + def __repr__(self): + return ( + "" % + (self.faultCode, repr(self.faultString)) + ) + +# -------------------------------------------------------------------- +# Special values + +## +# Wrapper for XML-RPC boolean values. Use the xmlrpclib.True and +# xmlrpclib.False constants, or the xmlrpclib.boolean() function, to +# generate boolean XML-RPC values. +# +# @param value A boolean value. Any true value is interpreted as True, +# all other values are interpreted as False. + +if _bool_is_builtin: + boolean = Boolean = bool #@UndefinedVariable + # to avoid breaking code which references xmlrpclib.{True,False} + True, False = True, False +else: + class Boolean: + """Boolean-value wrapper. + + Use True or False to generate a "boolean" XML-RPC value. + """ + + def __init__(self, value=0): + self.value = operator.truth(value) + + def encode(self, out): + out.write("%d\n" % self.value) + + def __cmp__(self, other): + if isinstance(other, Boolean): + other = other.value + return cmp(self.value, other) + + def __repr__(self): + if self.value: + return "" % id(self) + else: + return "" % id(self) + + def __int__(self): + return self.value + + def __nonzero__(self): + return self.value + + True, False = Boolean(1), Boolean(0) + + ## + # Map true or false value to XML-RPC boolean values. + # + # @def boolean(value) + # @param value A boolean value. Any true value is mapped to True, + # all other values are mapped to False. + # @return xmlrpclib.True or xmlrpclib.False. + # @see Boolean + # @see True + # @see False + + def boolean(value, _truefalse=(False, True)): + """Convert any Python value to XML-RPC 'boolean'.""" + return _truefalse[operator.truth(value)] + +## +# Wrapper for XML-RPC DateTime values. This converts a time value to +# the format used by XML-RPC. +#

+# The value can be given as a string in the format +# "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by +# time.localtime()), or an integer value (as returned by time.time()). +# The wrapper uses time.localtime() to convert an integer to a time +# tuple. +# +# @param value The time, given as an ISO 8601 string, a time +# tuple, or a integer time value. + +class DateTime: + """DateTime wrapper for an ISO 8601 string or time tuple or + localtime integer value to generate 'dateTime.iso8601' XML-RPC + value. + """ + + def __init__(self, value=0): + if not isinstance(value, StringType): + if datetime and isinstance(value, datetime.datetime): + self.value = value.strftime("%Y%m%dT%H:%M:%S") + return + if datetime and isinstance(value, datetime.date): + self.value = value.strftime("%Y%m%dT%H:%M:%S") + return + if datetime and isinstance(value, datetime.time): + today = datetime.datetime.now().strftime("%Y%m%d") + self.value = value.strftime(today + "T%H:%M:%S") + return + if not isinstance(value, (TupleType, time.struct_time)): #@UndefinedVariable + if value == 0: + value = time.time() + value = time.localtime(value) + value = time.strftime("%Y%m%dT%H:%M:%S", value) + self.value = value + + def __cmp__(self, other): + if isinstance(other, DateTime): + other = other.value + return cmp(self.value, other) + + ## + # Get date/time value. + # + # @return Date/time value, as an ISO 8601 string. + + def __str__(self): + return self.value + + def __repr__(self): + return "" % (repr(self.value), id(self)) + + def decode(self, data): + data = str(data) + self.value = string.strip(data) + + def encode(self, out): + out.write("") + out.write(self.value) + out.write("\n") + +def _datetime(data): + # decode xml element contents into a DateTime structure. + value = DateTime() + value.decode(data) + return value + +def _datetime_type(data): + t = time.strptime(data, "%Y%m%dT%H:%M:%S") #@UndefinedVariable + return datetime.datetime(*tuple(t)[:6]) + +## +# Wrapper for binary data. This can be used to transport any kind +# of binary data over XML-RPC, using BASE64 encoding. +# +# @param data An 8-bit string containing arbitrary data. + +import base64 +try: + import cStringIO as StringIO +except ImportError: + import StringIO + +class Binary: + """Wrapper for binary data.""" + + def __init__(self, data=None): + self.data = data + + ## + # Get buffer contents. + # + # @return Buffer contents, as an 8-bit string. + + def __str__(self): + return self.data or "" + + def __cmp__(self, other): + if isinstance(other, Binary): + other = other.data + return cmp(self.data, other) + + def decode(self, data): + self.data = base64.decodestring(data) + + def encode(self, out): + out.write("\n") + base64.encode(StringIO.StringIO(self.data), out) + out.write("\n") + +def _binary(data): + # decode xml element contents into a Binary structure + value = Binary() + value.decode(data) + return value + +WRAPPERS = (DateTime, Binary) +if not _bool_is_builtin: + WRAPPERS = WRAPPERS + (Boolean,) + +# -------------------------------------------------------------------- +# XML parsers + +try: + # optional xmlrpclib accelerator + import _xmlrpclib #@UnresolvedImport + FastParser = _xmlrpclib.Parser + FastUnmarshaller = _xmlrpclib.Unmarshaller +except (AttributeError, ImportError): + FastParser = FastUnmarshaller = None + +try: + import _xmlrpclib #@UnresolvedImport + FastMarshaller = _xmlrpclib.Marshaller +except (AttributeError, ImportError): + FastMarshaller = None + +# +# the SGMLOP parser is about 15x faster than Python's builtin +# XML parser. SGMLOP sources can be downloaded from: +# +# http://www.pythonware.com/products/xml/sgmlop.htm +# + +try: + import sgmlop + if not hasattr(sgmlop, "XMLParser"): + raise ImportError() +except ImportError: + SgmlopParser = None # sgmlop accelerator not available +else: + class SgmlopParser: + def __init__(self, target): + + # setup callbacks + self.finish_starttag = target.start + self.finish_endtag = target.end + self.handle_data = target.data + self.handle_xml = target.xml + + # activate parser + self.parser = sgmlop.XMLParser() + self.parser.register(self) + self.feed = self.parser.feed + self.entity = { + "amp": "&", "gt": ">", "lt": "<", + "apos": "'", "quot": '"' + } + + def close(self): + try: + self.parser.close() + finally: + self.parser = self.feed = None # nuke circular reference + + def handle_proc(self, tag, attr): + m = re.search("encoding\s*=\s*['\"]([^\"']+)[\"']", attr) #@UndefinedVariable + if m: + self.handle_xml(m.group(1), 1) + + def handle_entityref(self, entity): + # entity + try: + self.handle_data(self.entity[entity]) + except KeyError: + self.handle_data("&%s;" % entity) + +try: + from xml.parsers import expat + if not hasattr(expat, "ParserCreate"): + raise ImportError() +except ImportError: + ExpatParser = None # expat not available +else: + class ExpatParser: + # fast expat parser for Python 2.0 and later. this is about + # 50% slower than sgmlop, on roundtrip testing + def __init__(self, target): + self._parser = parser = expat.ParserCreate(None, None) + self._target = target + parser.StartElementHandler = target.start + parser.EndElementHandler = target.end + parser.CharacterDataHandler = target.data + encoding = None + if not parser.returns_unicode: + encoding = "utf-8" + target.xml(encoding, None) + + def feed(self, data): + self._parser.Parse(data, 0) + + def close(self): + self._parser.Parse("", 1) # end of data + del self._target, self._parser # get rid of circular references + +class SlowParser: + """Default XML parser (based on xmllib.XMLParser).""" + # this is about 10 times slower than sgmlop, on roundtrip + # testing. + def __init__(self, target): + import xmllib # lazy subclassing (!) + if xmllib.XMLParser not in SlowParser.__bases__: + SlowParser.__bases__ = (xmllib.XMLParser,) + self.handle_xml = target.xml + self.unknown_starttag = target.start + self.handle_data = target.data + self.handle_cdata = target.data + self.unknown_endtag = target.end + try: + xmllib.XMLParser.__init__(self, accept_utf8=1) + except TypeError: + xmllib.XMLParser.__init__(self) # pre-2.0 + +# -------------------------------------------------------------------- +# XML-RPC marshalling and unmarshalling code + +## +# XML-RPC marshaller. +# +# @param encoding Default encoding for 8-bit strings. The default +# value is None (interpreted as UTF-8). +# @see dumps + +class Marshaller: + """Generate an XML-RPC params chunk from a Python data structure. + + Create a Marshaller instance for each set of parameters, and use + the "dumps" method to convert your data (represented as a tuple) + to an XML-RPC params chunk. To write a fault response, pass a + Fault instance instead. You may prefer to use the "dumps" module + function for this purpose. + """ + + # by the way, if you don't understand what's going on in here, + # that's perfectly ok. + + def __init__(self, encoding=None, allow_none=0): + self.memo = {} + self.data = None + self.encoding = encoding + self.allow_none = allow_none + + dispatch = {} + + def dumps(self, values): + out = [] + write = out.append + dump = self.__dump + if isinstance(values, Fault): + # fault instance + write("\n") + dump({'faultCode': values.faultCode, + 'faultString': values.faultString}, + write) + write("\n") + else: + # parameter block + # FIXME: the xml-rpc specification allows us to leave out + # the entire block if there are no parameters. + # however, changing this may break older code (including + # old versions of xmlrpclib.py), so this is better left as + # is for now. See @XMLRPC3 for more information. /F + write("\n") + for v in values: + write("\n") + dump(v, write) + write("\n") + write("\n") + result = string.join(out, "") + return result + + def __dump(self, value, write): + try: + f = self.dispatch[type(value)] + except KeyError: + raise TypeError("cannot marshal %s objects" % type(value)) + else: + f(self, value, write) + + def dump_nil (self, value, write): + if not self.allow_none: + raise TypeError("cannot marshal None unless allow_none is enabled") + write("") + dispatch[NoneType] = dump_nil + + def dump_int(self, value, write): + # in case ints are > 32 bits + if value > MAXINT or value < MININT: + raise OverflowError("int exceeds XML-RPC limits") + write("") + write(str(value)) + write("\n") + dispatch[IntType] = dump_int + + if _bool_is_builtin: + def dump_bool(self, value, write): + write("") + write(value and "1" or "0") + write("\n") + dispatch[bool] = dump_bool #@UndefinedVariable + + def dump_long(self, value, write): + if value > MAXINT or value < MININT: + raise OverflowError("long int exceeds XML-RPC limits") + write("") + write(str(int(value))) + write("\n") + dispatch[LongType] = dump_long + + def dump_double(self, value, write): + write("") + write(repr(value)) + write("\n") + dispatch[FloatType] = dump_double + + def dump_string(self, value, write, escape=escape): + write("") + write(escape(value)) + write("\n") + dispatch[StringType] = dump_string + + if unicode: + def dump_unicode(self, value, write, escape=escape): + value = value.encode(self.encoding) + write("") + write(escape(value)) + write("\n") + dispatch[UnicodeType] = dump_unicode + + def dump_array(self, value, write): + i = id(value) + if self.memo.has_key(i): + raise TypeError("cannot marshal recursive sequences") + self.memo[i] = None + dump = self.__dump + write("\n") + for v in value: + dump(v, write) + write("\n") + del self.memo[i] + dispatch[TupleType] = dump_array + dispatch[ListType] = dump_array + + def dump_struct(self, value, write, escape=escape): + i = id(value) + if self.memo.has_key(i): + raise TypeError("cannot marshal recursive dictionaries") + self.memo[i] = None + dump = self.__dump + write("\n") + for k, v in value.items(): + write("\n") + if type(k) is not StringType: + if unicode and type(k) is UnicodeType: + k = k.encode(self.encoding) + else: + raise TypeError("dictionary key must be string") + write("%s\n" % escape(k)) + dump(v, write) + write("\n") + write("\n") + del self.memo[i] + dispatch[DictType] = dump_struct + + if datetime: + def dump_datetime(self, value, write): + write("") + write(value.strftime("%Y%m%dT%H:%M:%S")) + write("\n") + dispatch[datetime.datetime] = dump_datetime + + def dump_date(self, value, write): + write("") + write(value.strftime("%Y%m%dT00:00:00")) + write("\n") + dispatch[datetime.date] = dump_date + + def dump_time(self, value, write): + write("") + write(datetime.datetime.now().date().strftime("%Y%m%dT")) + write(value.strftime("%H:%M:%S")) + write("\n") + dispatch[datetime.time] = dump_time + + def dump_instance(self, value, write): + # check for special wrappers + if value.__class__ in WRAPPERS: + self.write = write + value.encode(self) + del self.write + else: + # store instance attributes as a struct (really?) + self.dump_struct(value.__dict__, write) + dispatch[InstanceType] = dump_instance + +## +# XML-RPC unmarshaller. +# +# @see loads + +class Unmarshaller: + """Unmarshal an XML-RPC response, based on incoming XML event + messages (start, data, end). Call close() to get the resulting + data structure. + + Note that this reader is fairly tolerant, and gladly accepts bogus + XML-RPC data without complaining (but not bogus XML). + """ + + # and again, if you don't understand what's going on in here, + # that's perfectly ok. + + def __init__(self, use_datetime=0): + self._type = None + self._stack = [] + self._marks = [] + self._data = [] + self._methodname = None + self._encoding = "utf-8" + self.append = self._stack.append + self._use_datetime = use_datetime + if use_datetime and not datetime: + raise ValueError("the datetime module is not available") + + def close(self): + # return response tuple and target method + if self._type is None or self._marks: + raise ResponseError() + if self._type == "fault": + raise Fault(**self._stack[0]) + return tuple(self._stack) + + def getmethodname(self): + return self._methodname + + # + # event handlers + + def xml(self, encoding, standalone): + self._encoding = encoding + # FIXME: assert standalone == 1 ??? + + def start(self, tag, attrs): + # prepare to handle this element + if tag == "array" or tag == "struct": + self._marks.append(len(self._stack)) + self._data = [] + self._value = (tag == "value") + + def data(self, text): + self._data.append(text) + + def end(self, tag, join=string.join): + # call the appropriate end tag handler + try: + f = self.dispatch[tag] + except KeyError: + pass # unknown tag ? + else: + return f(self, join(self._data, "")) + + # + # accelerator support + + def end_dispatch(self, tag, data): + # dispatch data + try: + f = self.dispatch[tag] + except KeyError: + pass # unknown tag ? + else: + return f(self, data) + + # + # element decoders + + dispatch = {} + + def end_nil (self, data): + self.append(None) + self._value = 0 + dispatch["nil"] = end_nil + + def end_boolean(self, data): + if data == "0": + self.append(False) + elif data == "1": + self.append(True) + else: + raise TypeError("bad boolean value") + self._value = 0 + dispatch["boolean"] = end_boolean + + def end_int(self, data): + self.append(int(data)) + self._value = 0 + dispatch["i4"] = end_int + dispatch["int"] = end_int + + def end_double(self, data): + self.append(float(data)) + self._value = 0 + dispatch["double"] = end_double + + def end_string(self, data): + if self._encoding: + data = _decode(data, self._encoding) + self.append(_stringify(data)) + self._value = 0 + dispatch["string"] = end_string + dispatch["name"] = end_string # struct keys are always strings + + def end_array(self, data): + mark = self._marks.pop() + # map arrays to Python lists + self._stack[mark:] = [self._stack[mark:]] + self._value = 0 + dispatch["array"] = end_array + + def end_struct(self, data): + mark = self._marks.pop() + # map structs to Python dictionaries + dict = {} + items = self._stack[mark:] + for i in range(0, len(items), 2): + dict[_stringify(items[i])] = items[i + 1] + self._stack[mark:] = [dict] + self._value = 0 + dispatch["struct"] = end_struct + + def end_base64(self, data): + value = Binary() + value.decode(data) + self.append(value) + self._value = 0 + dispatch["base64"] = end_base64 + + def end_dateTime(self, data): + value = DateTime() + value.decode(data) + if self._use_datetime: + value = _datetime_type(data) + self.append(value) + dispatch["dateTime.iso8601"] = end_dateTime + + def end_value(self, data): + # if we stumble upon a value element with no internal + # elements, treat it as a string element + if self._value: + self.end_string(data) + dispatch["value"] = end_value + + def end_params(self, data): + self._type = "params" + dispatch["params"] = end_params + + def end_fault(self, data): + self._type = "fault" + dispatch["fault"] = end_fault + + def end_methodName(self, data): + if self._encoding: + data = _decode(data, self._encoding) + self._methodname = data + self._type = "methodName" # no params + dispatch["methodName"] = end_methodName + +## Multicall support +# + +class _MultiCallMethod: + # some lesser magic to store calls made to a MultiCall object + # for batch execution + def __init__(self, call_list, name): + self.__call_list = call_list + self.__name = name + def __getattr__(self, name): + return _MultiCallMethod(self.__call_list, "%s.%s" % (self.__name, name)) + def __call__(self, *args): + self.__call_list.append((self.__name, args)) + +class MultiCallIterator: + """Iterates over the results of a multicall. Exceptions are + thrown in response to xmlrpc faults.""" + + def __init__(self, results): + self.results = results + + def __getitem__(self, i): + item = self.results[i] + if type(item) == type({}): + raise Fault(item['faultCode'], item['faultString']) + elif type(item) == type([]): + return item[0] + else: + raise ValueError("unexpected type in multicall result") + +class MultiCall: + """server -> a object used to boxcar method calls + + server should be a ServerProxy object. + + Methods can be added to the MultiCall using normal + method call syntax e.g.: + + multicall = MultiCall(server_proxy) + multicall.add(2,3) + multicall.get_address("Guido") + + To execute the multicall, call the MultiCall object e.g.: + + add_result, address = multicall() + """ + + def __init__(self, server): + self.__server = server + self.__call_list = [] + + def __repr__(self): + return "" % id(self) + + __str__ = __repr__ + + def __getattr__(self, name): + return _MultiCallMethod(self.__call_list, name) + + def __call__(self): + marshalled_list = [] + for name, args in self.__call_list: + marshalled_list.append({'methodName' : name, 'params' : args}) + + return MultiCallIterator(self.__server.system.multicall(marshalled_list)) + +# -------------------------------------------------------------------- +# convenience functions + +## +# Create a parser object, and connect it to an unmarshalling instance. +# This function picks the fastest available XML parser. +# +# return A (parser, unmarshaller) tuple. + +def getparser(use_datetime=0): + """getparser() -> parser, unmarshaller + + Create an instance of the fastest available parser, and attach it + to an unmarshalling object. Return both objects. + """ + if use_datetime and not datetime: + raise ValueError("the datetime module is not available") + if FastParser and FastUnmarshaller: + if use_datetime: + mkdatetime = _datetime_type + else: + mkdatetime = _datetime + target = FastUnmarshaller(True, False, _binary, mkdatetime, Fault) + parser = FastParser(target) + else: + target = Unmarshaller(use_datetime=use_datetime) + if FastParser: + parser = FastParser(target) + elif SgmlopParser: + parser = SgmlopParser(target) + elif ExpatParser: + parser = ExpatParser(target) + else: + parser = SlowParser(target) + return parser, target + +## +# Convert a Python tuple or a Fault instance to an XML-RPC packet. +# +# @def dumps(params, **options) +# @param params A tuple or Fault instance. +# @keyparam methodname If given, create a methodCall request for +# this method name. +# @keyparam methodresponse If given, create a methodResponse packet. +# If used with a tuple, the tuple must be a singleton (that is, +# it must contain exactly one element). +# @keyparam encoding The packet encoding. +# @return A string containing marshalled data. + +def dumps(params, methodname=None, methodresponse=None, encoding=None, + allow_none=0): + """data [,options] -> marshalled data + + Convert an argument tuple or a Fault instance to an XML-RPC + request (or response, if the methodresponse option is used). + + In addition to the data object, the following options can be given + as keyword arguments: + + methodname: the method name for a methodCall packet + + methodresponse: true to create a methodResponse packet. + If this option is used with a tuple, the tuple must be + a singleton (i.e. it can contain only one element). + + encoding: the packet encoding (default is UTF-8) + + All 8-bit strings in the data structure are assumed to use the + packet encoding. Unicode strings are automatically converted, + where necessary. + """ + + assert isinstance(params, TupleType) or isinstance(params, Fault), \ + "argument must be tuple or Fault instance" + + if isinstance(params, Fault): + methodresponse = 1 + elif methodresponse and isinstance(params, TupleType): + assert len(params) == 1, "response tuple must be a singleton" + + if not encoding: + encoding = "utf-8" + + if FastMarshaller: + m = FastMarshaller(encoding) + else: + m = Marshaller(encoding, allow_none) + + data = m.dumps(params) + + if encoding != "utf-8": + xmlheader = "\n" % str(encoding) + else: + xmlheader = "\n" # utf-8 is default + + # standard XML-RPC wrappings + if methodname: + # a method call + if not isinstance(methodname, StringType): + methodname = methodname.encode(encoding) + data = ( + xmlheader, + "\n" + "", methodname, "\n", + data, + "\n" + ) + elif methodresponse: + # a method response, or a fault structure + data = ( + xmlheader, + "\n", + data, + "\n" + ) + else: + return data # return as is + return string.join(data, "") + +## +# Convert an XML-RPC packet to a Python object. If the XML-RPC packet +# represents a fault condition, this function raises a Fault exception. +# +# @param data An XML-RPC packet, given as an 8-bit string. +# @return A tuple containing the unpacked data, and the method name +# (None if not present). +# @see Fault + +def loads(data, use_datetime=0): + """data -> unmarshalled data, method name + + Convert an XML-RPC packet to unmarshalled data plus a method + name (None if not present). + + If the XML-RPC packet represents a fault condition, this function + raises a Fault exception. + """ + p, u = getparser(use_datetime=use_datetime) + p.feed(data) + p.close() + return u.close(), u.getmethodname() + + +# -------------------------------------------------------------------- +# request dispatcher + +class _Method: + # some magic to bind an XML-RPC method to an RPC server. + # supports "nested" methods (e.g. examples.getStateName) + def __init__(self, send, name): + self.__send = send + self.__name = name + def __getattr__(self, name): + return _Method(self.__send, "%s.%s" % (self.__name, name)) + def __call__(self, *args): + return self.__send(self.__name, args) + +## +# Standard transport class for XML-RPC over HTTP. +#

+# You can create custom transports by subclassing this method, and +# overriding selected methods. + +class Transport: + """Handles an HTTP transaction to an XML-RPC server.""" + + # client identifier (may be overridden) + user_agent = "xmlrpclib.py/%s (by www.pythonware.com)" % __version__ + + def __init__(self, use_datetime=0): + self._use_datetime = use_datetime + + ## + # Send a complete request, and parse the response. + # + # @param host Target host. + # @param handler Target PRC handler. + # @param request_body XML-RPC request body. + # @param verbose Debugging flag. + # @return Parsed response. + + def request(self, host, handler, request_body, verbose=0): + # issue XML-RPC request + + h = self.make_connection(host) + if verbose: + h.set_debuglevel(1) + + self.send_request(h, handler, request_body) + self.send_host(h, host) + self.send_user_agent(h) + self.send_content(h, request_body) + + errcode, errmsg, headers = h.getreply() + + if errcode != 200: + raise ProtocolError( + host + handler, + errcode, errmsg, + headers + ) + + self.verbose = verbose + + try: + sock = h._conn.sock + except AttributeError: + sock = None + + return self._parse_response(h.getfile(), sock) + + ## + # Create parser. + # + # @return A 2-tuple containing a parser and a unmarshaller. + + def getparser(self): + # get parser and unmarshaller + return getparser(use_datetime=self._use_datetime) + + ## + # Get authorization info from host parameter + # Host may be a string, or a (host, x509-dict) tuple; if a string, + # it is checked for a "user:pw@host" format, and a "Basic + # Authentication" header is added if appropriate. + # + # @param host Host descriptor (URL or (URL, x509 info) tuple). + # @return A 3-tuple containing (actual host, extra headers, + # x509 info). The header and x509 fields may be None. + + def get_host_info(self, host): + + x509 = {} + if isinstance(host, TupleType): + host, x509 = host + + import urllib + auth, host = urllib.splituser(host) + + if auth: + import base64 + auth = base64.encodestring(urllib.unquote(auth)) + auth = string.join(string.split(auth), "") # get rid of whitespace + extra_headers = [ + ("Authorization", "Basic " + auth) + ] + else: + extra_headers = None + + return host, extra_headers, x509 + + ## + # Connect to server. + # + # @param host Target host. + # @return A connection handle. + + def make_connection(self, host): + # create a HTTP connection object from a host descriptor + import httplib + host, extra_headers, x509 = self.get_host_info(host) + return httplib.HTTP(host) + + ## + # Send request header. + # + # @param connection Connection handle. + # @param handler Target RPC handler. + # @param request_body XML-RPC body. + + def send_request(self, connection, handler, request_body): + connection.putrequest("POST", handler) + + ## + # Send host name. + # + # @param connection Connection handle. + # @param host Host name. + + def send_host(self, connection, host): + host, extra_headers, x509 = self.get_host_info(host) + connection.putheader("Host", host) + if extra_headers: + if isinstance(extra_headers, DictType): + extra_headers = extra_headers.items() + for key, value in extra_headers: + connection.putheader(key, value) + + ## + # Send user-agent identifier. + # + # @param connection Connection handle. + + def send_user_agent(self, connection): + connection.putheader("User-Agent", self.user_agent) + + ## + # Send request body. + # + # @param connection Connection handle. + # @param request_body XML-RPC request body. + + def send_content(self, connection, request_body): + connection.putheader("Content-Type", "text/xml") + connection.putheader("Content-Length", str(len(request_body))) + connection.endheaders() + if request_body: + connection.send(request_body) + + ## + # Parse response. + # + # @param file Stream. + # @return Response tuple and target method. + + def parse_response(self, file): + # compatibility interface + return self._parse_response(file, None) + + ## + # Parse response (alternate interface). This is similar to the + # parse_response method, but also provides direct access to the + # underlying socket object (where available). + # + # @param file Stream. + # @param sock Socket handle (or None, if the socket object + # could not be accessed). + # @return Response tuple and target method. + + def _parse_response(self, file, sock): + # read response from input file/socket, and parse it + + p, u = self.getparser() + + while 1: + if sock: + response = sock.recv(1024) + else: + response = file.read(1024) + if not response: + break + if self.verbose: + sys.stdout.write("body: %s\n" % repr(response)) + p.feed(response) + + file.close() + p.close() + + return u.close() + +## +# Standard transport class for XML-RPC over HTTPS. + +class SafeTransport(Transport): + """Handles an HTTPS transaction to an XML-RPC server.""" + + # FIXME: mostly untested + + def make_connection(self, host): + # create a HTTPS connection object from a host descriptor + # host may be a string, or a (host, x509-dict) tuple + import httplib + host, extra_headers, x509 = self.get_host_info(host) + try: + HTTPS = httplib.HTTPS + except AttributeError: + raise NotImplementedError( + "your version of httplib doesn't support HTTPS" + ) + else: + return HTTPS(host, None, **(x509 or {})) + +## +# Standard server proxy. This class establishes a virtual connection +# to an XML-RPC server. +#

+# This class is available as ServerProxy and Server. New code should +# use ServerProxy, to avoid confusion. +# +# @def ServerProxy(uri, **options) +# @param uri The connection point on the server. +# @keyparam transport A transport factory, compatible with the +# standard transport class. +# @keyparam encoding The default encoding used for 8-bit strings +# (default is UTF-8). +# @keyparam verbose Use a true value to enable debugging output. +# (printed to standard output). +# @see Transport + +class ServerProxy: + """uri [,options] -> a logical connection to an XML-RPC server + + uri is the connection point on the server, given as + scheme://host/target. + + The standard implementation always supports the "http" scheme. If + SSL socket support is available (Python 2.0), it also supports + "https". + + If the target part and the slash preceding it are both omitted, + "/RPC2" is assumed. + + The following options can be given as keyword arguments: + + transport: a transport factory + encoding: the request encoding (default is UTF-8) + + All 8-bit strings passed to the server proxy are assumed to use + the given encoding. + """ + + def __init__(self, uri, transport=None, encoding=None, verbose=0, + allow_none=0, use_datetime=0): + # establish a "logical" server connection + + # get the url + import urllib + type, uri = urllib.splittype(uri) + if type not in ("http", "https"): + raise IOError("unsupported XML-RPC protocol") + self.__host, self.__handler = urllib.splithost(uri) + if not self.__handler: + self.__handler = "/RPC2" + + if transport is None: + if type == "https": + transport = SafeTransport(use_datetime=use_datetime) + else: + transport = Transport(use_datetime=use_datetime) + self.__transport = transport + + self.__encoding = encoding + self.__verbose = verbose + self.__allow_none = allow_none + + def __request(self, methodname, params): + # call a method on the remote server + + request = dumps(params, methodname, encoding=self.__encoding, + allow_none=self.__allow_none) + + response = self.__transport.request( + self.__host, + self.__handler, + request, + verbose=self.__verbose + ) + + if len(response) == 1: + response = response[0] + + return response + + def __repr__(self): + return ( + "" % + (self.__host, self.__handler) + ) + + __str__ = __repr__ + + def __getattr__(self, name): + # magic method dispatcher + return _Method(self.__request, name) + + # note: to call a remote object with an non-standard name, use + # result getattr(server, "strange-python-name")(args) + +# compatibility + +Server = ServerProxy + +# -------------------------------------------------------------------- +# test code + +if __name__ == "__main__": + + # simple test program (from the XML-RPC specification) + + # server = ServerProxy("http://localhost:8000") # local server + server = ServerProxy("http://time.xmlrpc.com/RPC2") + + sys.stdout.write('%s\n' % server) + + try: + sys.stdout.write('%s\n' % (server.currentTime.getCurrentTime(),)) + except Error: + import traceback;traceback.print_exc() + + multi = MultiCall(server) + multi.currentTime.getCurrentTime() + multi.currentTime.getCurrentTime() + try: + for response in multi(): + sys.stdout.write('%s\n' % (response,)) + except Error: + import traceback;traceback.print_exc() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles.py new file mode 100644 index 0000000..66e646d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles.py @@ -0,0 +1,874 @@ +from __future__ import nested_scopes + +import fnmatch +import os.path +from _pydev_runfiles.pydev_runfiles_coverage import start_coverage_support +from _pydevd_bundle.pydevd_constants import * #@UnusedWildImport +import re +import time + + +#======================================================================================================================= +# Configuration +#======================================================================================================================= +class Configuration: + + def __init__( + self, + files_or_dirs='', + verbosity=2, + include_tests=None, + tests=None, + port=None, + files_to_tests=None, + jobs=1, + split_jobs='tests', + coverage_output_dir=None, + coverage_include=None, + coverage_output_file=None, + exclude_files=None, + exclude_tests=None, + include_files=None, + django=False, + ): + self.files_or_dirs = files_or_dirs + self.verbosity = verbosity + self.include_tests = include_tests + self.tests = tests + self.port = port + self.files_to_tests = files_to_tests + self.jobs = jobs + self.split_jobs = split_jobs + self.django = django + + if include_tests: + assert isinstance(include_tests, (list, tuple)) + + if exclude_files: + assert isinstance(exclude_files, (list, tuple)) + + if exclude_tests: + assert isinstance(exclude_tests, (list, tuple)) + + self.exclude_files = exclude_files + self.include_files = include_files + self.exclude_tests = exclude_tests + + self.coverage_output_dir = coverage_output_dir + self.coverage_include = coverage_include + self.coverage_output_file = coverage_output_file + + def __str__(self): + return '''Configuration + - files_or_dirs: %s + - verbosity: %s + - tests: %s + - port: %s + - files_to_tests: %s + - jobs: %s + - split_jobs: %s + + - include_files: %s + - include_tests: %s + + - exclude_files: %s + - exclude_tests: %s + + - coverage_output_dir: %s + - coverage_include_dir: %s + - coverage_output_file: %s + + - django: %s +''' % ( + self.files_or_dirs, + self.verbosity, + self.tests, + self.port, + self.files_to_tests, + self.jobs, + self.split_jobs, + + self.include_files, + self.include_tests, + + self.exclude_files, + self.exclude_tests, + + self.coverage_output_dir, + self.coverage_include, + self.coverage_output_file, + + self.django, + ) + + +#======================================================================================================================= +# parse_cmdline +#======================================================================================================================= +def parse_cmdline(argv=None): + """ + Parses command line and returns test directories, verbosity, test filter and test suites + + usage: + runfiles.py -v|--verbosity -t|--tests dirs|files + + Multiprocessing options: + jobs=number (with the number of jobs to be used to run the tests) + split_jobs='module'|'tests' + if == module, a given job will always receive all the tests from a module + if == tests, the tests will be split independently of their originating module (default) + + --exclude_files = comma-separated list of patterns with files to exclude (fnmatch style) + --include_files = comma-separated list of patterns with files to include (fnmatch style) + --exclude_tests = comma-separated list of patterns with test names to exclude (fnmatch style) + + Note: if --tests is given, --exclude_files, --include_files and --exclude_tests are ignored! + """ + if argv is None: + argv = sys.argv + + verbosity = 2 + include_tests = None + tests = None + port = None + jobs = 1 + split_jobs = 'tests' + files_to_tests = {} + coverage_output_dir = None + coverage_include = None + exclude_files = None + exclude_tests = None + include_files = None + django = False + + from _pydev_bundle._pydev_getopt import gnu_getopt + optlist, dirs = gnu_getopt( + argv[1:], "", + [ + "verbosity=", + "tests=", + + "port=", + "config_file=", + + "jobs=", + "split_jobs=", + + "include_tests=", + "include_files=", + + "exclude_files=", + "exclude_tests=", + + "coverage_output_dir=", + "coverage_include=", + + "django=" + ] + ) + + for opt, value in optlist: + if opt in ("-v", "--verbosity"): + verbosity = value + + elif opt in ("-p", "--port"): + port = int(value) + + elif opt in ("-j", "--jobs"): + jobs = int(value) + + elif opt in ("-s", "--split_jobs"): + split_jobs = value + if split_jobs not in ('module', 'tests'): + raise AssertionError('Expected split to be either "module" or "tests". Was :%s' % (split_jobs,)) + + elif opt in ("-d", "--coverage_output_dir",): + coverage_output_dir = value.strip() + + elif opt in ("-i", "--coverage_include",): + coverage_include = value.strip() + + elif opt in ("-I", "--include_tests"): + include_tests = value.split(',') + + elif opt in ("-E", "--exclude_files"): + exclude_files = value.split(',') + + elif opt in ("-F", "--include_files"): + include_files = value.split(',') + + elif opt in ("-e", "--exclude_tests"): + exclude_tests = value.split(',') + + elif opt in ("-t", "--tests"): + tests = value.split(',') + + elif opt in ("--django",): + django = value.strip() in ['true', 'True', '1'] + + elif opt in ("-c", "--config_file"): + config_file = value.strip() + if os.path.exists(config_file): + f = open(config_file, 'rU') + try: + config_file_contents = f.read() + finally: + f.close() + + if config_file_contents: + config_file_contents = config_file_contents.strip() + + if config_file_contents: + for line in config_file_contents.splitlines(): + file_and_test = line.split('|') + if len(file_and_test) == 2: + file, test = file_and_test + if file in files_to_tests: + files_to_tests[file].append(test) + else: + files_to_tests[file] = [test] + + else: + sys.stderr.write('Could not find config file: %s\n' % (config_file,)) + + if type([]) != type(dirs): + dirs = [dirs] + + ret_dirs = [] + for d in dirs: + if '|' in d: + #paths may come from the ide separated by | + ret_dirs.extend(d.split('|')) + else: + ret_dirs.append(d) + + verbosity = int(verbosity) + + if tests: + if verbosity > 4: + sys.stdout.write('--tests provided. Ignoring --exclude_files, --exclude_tests and --include_files\n') + exclude_files = exclude_tests = include_files = None + + config = Configuration( + ret_dirs, + verbosity, + include_tests, + tests, + port, + files_to_tests, + jobs, + split_jobs, + coverage_output_dir, + coverage_include, + exclude_files=exclude_files, + exclude_tests=exclude_tests, + include_files=include_files, + django=django, + ) + + if verbosity > 5: + sys.stdout.write(str(config) + '\n') + return config + + +#======================================================================================================================= +# PydevTestRunner +#======================================================================================================================= +class PydevTestRunner(object): + """ finds and runs a file or directory of files as a unit test """ + + __py_extensions = ["*.py", "*.pyw"] + __exclude_files = ["__init__.*"] + + #Just to check that only this attributes will be written to this file + __slots__ = [ + 'verbosity', #Always used + + 'files_to_tests', #If this one is given, the ones below are not used + + 'files_or_dirs', #Files or directories received in the command line + 'include_tests', #The filter used to collect the tests + 'tests', #Strings with the tests to be run + + 'jobs', #Integer with the number of jobs that should be used to run the test cases + 'split_jobs', #String with 'tests' or 'module' (how should the jobs be split) + + 'configuration', + 'coverage', + ] + + def __init__(self, configuration): + self.verbosity = configuration.verbosity + + self.jobs = configuration.jobs + self.split_jobs = configuration.split_jobs + + files_to_tests = configuration.files_to_tests + if files_to_tests: + self.files_to_tests = files_to_tests + self.files_or_dirs = list(files_to_tests.keys()) + self.tests = None + else: + self.files_to_tests = {} + self.files_or_dirs = configuration.files_or_dirs + self.tests = configuration.tests + + self.configuration = configuration + self.__adjust_path() + + + def __adjust_path(self): + """ add the current file or directory to the python path """ + path_to_append = None + for n in xrange(len(self.files_or_dirs)): + dir_name = self.__unixify(self.files_or_dirs[n]) + if os.path.isdir(dir_name): + if not dir_name.endswith("/"): + self.files_or_dirs[n] = dir_name + "/" + path_to_append = os.path.normpath(dir_name) + elif os.path.isfile(dir_name): + path_to_append = os.path.dirname(dir_name) + else: + if not os.path.exists(dir_name): + block_line = '*' * 120 + sys.stderr.write('\n%s\n* PyDev test runner error: %s does not exist.\n%s\n' % (block_line, dir_name, block_line)) + return + msg = ("unknown type. \n%s\nshould be file or a directory.\n" % (dir_name)) + raise RuntimeError(msg) + if path_to_append is not None: + #Add it as the last one (so, first things are resolved against the default dirs and + #if none resolves, then we try a relative import). + sys.path.append(path_to_append) + + def __is_valid_py_file(self, fname): + """ tests that a particular file contains the proper file extension + and is not in the list of files to exclude """ + is_valid_fname = 0 + for invalid_fname in self.__class__.__exclude_files: + is_valid_fname += int(not fnmatch.fnmatch(fname, invalid_fname)) + if_valid_ext = 0 + for ext in self.__class__.__py_extensions: + if_valid_ext += int(fnmatch.fnmatch(fname, ext)) + return is_valid_fname > 0 and if_valid_ext > 0 + + def __unixify(self, s): + """ stupid windows. converts the backslash to forwardslash for consistency """ + return os.path.normpath(s).replace(os.sep, "/") + + def __importify(self, s, dir=False): + """ turns directory separators into dots and removes the ".py*" extension + so the string can be used as import statement """ + if not dir: + dirname, fname = os.path.split(s) + + if fname.count('.') > 1: + #if there's a file named xxx.xx.py, it is not a valid module, so, let's not load it... + return + + imp_stmt_pieces = [dirname.replace("\\", "/").replace("/", "."), os.path.splitext(fname)[0]] + + if len(imp_stmt_pieces[0]) == 0: + imp_stmt_pieces = imp_stmt_pieces[1:] + + return ".".join(imp_stmt_pieces) + + else: #handle dir + return s.replace("\\", "/").replace("/", ".") + + def __add_files(self, pyfiles, root, files): + """ if files match, appends them to pyfiles. used by os.path.walk fcn """ + for fname in files: + if self.__is_valid_py_file(fname): + name_without_base_dir = self.__unixify(os.path.join(root, fname)) + pyfiles.append(name_without_base_dir) + + + def find_import_files(self): + """ return a list of files to import """ + if self.files_to_tests: + pyfiles = self.files_to_tests.keys() + else: + pyfiles = [] + + for base_dir in self.files_or_dirs: + if os.path.isdir(base_dir): + if hasattr(os, 'walk'): + for root, dirs, files in os.walk(base_dir): + + #Note: handling directories that should be excluded from the search because + #they don't have __init__.py + exclude = {} + for d in dirs: + for init in ['__init__.py', '__init__.pyo', '__init__.pyc', '__init__.pyw', '__init__$py.class']: + if os.path.exists(os.path.join(root, d, init).replace('\\', '/')): + break + else: + exclude[d] = 1 + + if exclude: + new = [] + for d in dirs: + if d not in exclude: + new.append(d) + + dirs[:] = new + + self.__add_files(pyfiles, root, files) + else: + # jython2.1 is too old for os.walk! + os.path.walk(base_dir, self.__add_files, pyfiles) + + elif os.path.isfile(base_dir): + pyfiles.append(base_dir) + + if self.configuration.exclude_files or self.configuration.include_files: + ret = [] + for f in pyfiles: + add = True + basename = os.path.basename(f) + if self.configuration.include_files: + add = False + + for pat in self.configuration.include_files: + if fnmatch.fnmatchcase(basename, pat): + add = True + break + + if not add: + if self.verbosity > 3: + sys.stdout.write('Skipped file: %s (did not match any include_files pattern: %s)\n' % (f, self.configuration.include_files)) + + elif self.configuration.exclude_files: + for pat in self.configuration.exclude_files: + if fnmatch.fnmatchcase(basename, pat): + if self.verbosity > 3: + sys.stdout.write('Skipped file: %s (matched exclude_files pattern: %s)\n' % (f, pat)) + + elif self.verbosity > 2: + sys.stdout.write('Skipped file: %s\n' % (f,)) + + add = False + break + + if add: + if self.verbosity > 3: + sys.stdout.write('Adding file: %s for test discovery.\n' % (f,)) + ret.append(f) + + pyfiles = ret + + + return pyfiles + + def __get_module_from_str(self, modname, print_exception, pyfile): + """ Import the module in the given import path. + * Returns the "final" module, so importing "coilib40.subject.visu" + returns the "visu" module, not the "coilib40" as returned by __import__ """ + try: + mod = __import__(modname) + for part in modname.split('.')[1:]: + mod = getattr(mod, part) + return mod + except: + if print_exception: + from _pydev_runfiles import pydev_runfiles_xml_rpc + from _pydevd_bundle import pydevd_io + buf_err = pydevd_io.start_redirect(keep_original_redirection=True, std='stderr') + buf_out = pydevd_io.start_redirect(keep_original_redirection=True, std='stdout') + try: + import traceback;traceback.print_exc() + sys.stderr.write('ERROR: Module: %s could not be imported (file: %s).\n' % (modname, pyfile)) + finally: + pydevd_io.end_redirect('stderr') + pydevd_io.end_redirect('stdout') + + pydev_runfiles_xml_rpc.notifyTest( + 'error', buf_out.getvalue(), buf_err.getvalue(), pyfile, modname, 0) + + return None + + def remove_duplicates_keeping_order(self, seq): + seen = set() + seen_add = seen.add + return [x for x in seq if not (x in seen or seen_add(x))] + + def find_modules_from_files(self, pyfiles): + """ returns a list of modules given a list of files """ + #let's make sure that the paths we want are in the pythonpath... + imports = [(s, self.__importify(s)) for s in pyfiles] + + sys_path = [os.path.normpath(path) for path in sys.path] + sys_path = self.remove_duplicates_keeping_order(sys_path) + + system_paths = [] + for s in sys_path: + system_paths.append(self.__importify(s, True)) + + ret = [] + for pyfile, imp in imports: + if imp is None: + continue #can happen if a file is not a valid module + choices = [] + for s in system_paths: + if imp.startswith(s): + add = imp[len(s) + 1:] + if add: + choices.append(add) + #sys.stdout.write(' ' + add + ' ') + + if not choices: + sys.stdout.write('PYTHONPATH not found for file: %s\n' % imp) + else: + for i, import_str in enumerate(choices): + print_exception = i == len(choices) - 1 + mod = self.__get_module_from_str(import_str, print_exception, pyfile) + if mod is not None: + ret.append((pyfile, mod, import_str)) + break + + + return ret + + #=================================================================================================================== + # GetTestCaseNames + #=================================================================================================================== + class GetTestCaseNames: + """Yes, we need a class for that (cannot use outer context on jython 2.1)""" + + def __init__(self, accepted_classes, accepted_methods): + self.accepted_classes = accepted_classes + self.accepted_methods = accepted_methods + + def __call__(self, testCaseClass): + """Return a sorted sequence of method names found within testCaseClass""" + testFnNames = [] + className = testCaseClass.__name__ + + if className in self.accepted_classes: + for attrname in dir(testCaseClass): + #If a class is chosen, we select all the 'test' methods' + if attrname.startswith('test') and hasattr(getattr(testCaseClass, attrname), '__call__'): + testFnNames.append(attrname) + + else: + for attrname in dir(testCaseClass): + #If we have the class+method name, we must do a full check and have an exact match. + if className + '.' + attrname in self.accepted_methods: + if hasattr(getattr(testCaseClass, attrname), '__call__'): + testFnNames.append(attrname) + + #sorted() is not available in jython 2.1 + testFnNames.sort() + return testFnNames + + + def _decorate_test_suite(self, suite, pyfile, module_name): + import unittest + if isinstance(suite, unittest.TestSuite): + add = False + suite.__pydev_pyfile__ = pyfile + suite.__pydev_module_name__ = module_name + + for t in suite._tests: + t.__pydev_pyfile__ = pyfile + t.__pydev_module_name__ = module_name + if self._decorate_test_suite(t, pyfile, module_name): + add = True + + return add + + elif isinstance(suite, unittest.TestCase): + return True + + else: + return False + + + + def find_tests_from_modules(self, file_and_modules_and_module_name): + """ returns the unittests given a list of modules """ + #Use our own suite! + from _pydev_runfiles import pydev_runfiles_unittest + import unittest + unittest.TestLoader.suiteClass = pydev_runfiles_unittest.PydevTestSuite + loader = unittest.TestLoader() + + ret = [] + if self.files_to_tests: + for pyfile, m, module_name in file_and_modules_and_module_name: + accepted_classes = {} + accepted_methods = {} + tests = self.files_to_tests[pyfile] + for t in tests: + accepted_methods[t] = t + + loader.getTestCaseNames = self.GetTestCaseNames(accepted_classes, accepted_methods) + + suite = loader.loadTestsFromModule(m) + if self._decorate_test_suite(suite, pyfile, module_name): + ret.append(suite) + return ret + + + if self.tests: + accepted_classes = {} + accepted_methods = {} + + for t in self.tests: + splitted = t.split('.') + if len(splitted) == 1: + accepted_classes[t] = t + + elif len(splitted) == 2: + accepted_methods[t] = t + + loader.getTestCaseNames = self.GetTestCaseNames(accepted_classes, accepted_methods) + + + for pyfile, m, module_name in file_and_modules_and_module_name: + suite = loader.loadTestsFromModule(m) + if self._decorate_test_suite(suite, pyfile, module_name): + ret.append(suite) + + return ret + + + def filter_tests(self, test_objs, internal_call=False): + """ based on a filter name, only return those tests that have + the test case names that match """ + import unittest + if not internal_call: + if not self.configuration.include_tests and not self.tests and not self.configuration.exclude_tests: + #No need to filter if we have nothing to filter! + return test_objs + + if self.verbosity > 1: + if self.configuration.include_tests: + sys.stdout.write('Tests to include: %s\n' % (self.configuration.include_tests,)) + + if self.tests: + sys.stdout.write('Tests to run: %s\n' % (self.tests,)) + + if self.configuration.exclude_tests: + sys.stdout.write('Tests to exclude: %s\n' % (self.configuration.exclude_tests,)) + + test_suite = [] + for test_obj in test_objs: + + if isinstance(test_obj, unittest.TestSuite): + #Note: keep the suites as they are and just 'fix' the tests (so, don't use the iter_tests). + if test_obj._tests: + test_obj._tests = self.filter_tests(test_obj._tests, True) + if test_obj._tests: #Only add the suite if we still have tests there. + test_suite.append(test_obj) + + elif isinstance(test_obj, unittest.TestCase): + try: + testMethodName = test_obj._TestCase__testMethodName + except AttributeError: + #changed in python 2.5 + testMethodName = test_obj._testMethodName + + add = True + if self.configuration.exclude_tests: + for pat in self.configuration.exclude_tests: + if fnmatch.fnmatchcase(testMethodName, pat): + if self.verbosity > 3: + sys.stdout.write('Skipped test: %s (matched exclude_tests pattern: %s)\n' % (testMethodName, pat)) + + elif self.verbosity > 2: + sys.stdout.write('Skipped test: %s\n' % (testMethodName,)) + + add = False + break + + if add: + if self.__match_tests(self.tests, test_obj, testMethodName): + include = True + if self.configuration.include_tests: + include = False + for pat in self.configuration.include_tests: + if fnmatch.fnmatchcase(testMethodName, pat): + include = True + break + if include: + test_suite.append(test_obj) + else: + if self.verbosity > 3: + sys.stdout.write('Skipped test: %s (did not match any include_tests pattern %s)\n' % ( + testMethodName, self.configuration.include_tests,)) + return test_suite + + + def iter_tests(self, test_objs): + #Note: not using yield because of Jython 2.1. + import unittest + tests = [] + for test_obj in test_objs: + if isinstance(test_obj, unittest.TestSuite): + tests.extend(self.iter_tests(test_obj._tests)) + + elif isinstance(test_obj, unittest.TestCase): + tests.append(test_obj) + return tests + + + def list_test_names(self, test_objs): + names = [] + for tc in self.iter_tests(test_objs): + try: + testMethodName = tc._TestCase__testMethodName + except AttributeError: + #changed in python 2.5 + testMethodName = tc._testMethodName + names.append(testMethodName) + return names + + + def __match_tests(self, tests, test_case, test_method_name): + if not tests: + return 1 + + for t in tests: + class_and_method = t.split('.') + if len(class_and_method) == 1: + #only class name + if class_and_method[0] == test_case.__class__.__name__: + return 1 + + elif len(class_and_method) == 2: + if class_and_method[0] == test_case.__class__.__name__ and class_and_method[1] == test_method_name: + return 1 + + return 0 + + + def __match(self, filter_list, name): + """ returns whether a test name matches the test filter """ + if filter_list is None: + return 1 + for f in filter_list: + if re.match(f, name): + return 1 + return 0 + + + def run_tests(self, handle_coverage=True): + """ runs all tests """ + sys.stdout.write("Finding files... ") + files = self.find_import_files() + if self.verbosity > 3: + sys.stdout.write('%s ... done.\n' % (self.files_or_dirs)) + else: + sys.stdout.write('done.\n') + sys.stdout.write("Importing test modules ... ") + + + if handle_coverage: + coverage_files, coverage = start_coverage_support(self.configuration) + + file_and_modules_and_module_name = self.find_modules_from_files(files) + sys.stdout.write("done.\n") + + all_tests = self.find_tests_from_modules(file_and_modules_and_module_name) + all_tests = self.filter_tests(all_tests) + + from _pydev_runfiles import pydev_runfiles_unittest + test_suite = pydev_runfiles_unittest.PydevTestSuite(all_tests) + from _pydev_runfiles import pydev_runfiles_xml_rpc + pydev_runfiles_xml_rpc.notifyTestsCollected(test_suite.countTestCases()) + + start_time = time.time() + + def run_tests(): + executed_in_parallel = False + if self.jobs > 1: + from _pydev_runfiles import pydev_runfiles_parallel + + #What may happen is that the number of jobs needed is lower than the number of jobs requested + #(e.g.: 2 jobs were requested for running 1 test) -- in which case execute_tests_in_parallel will + #return False and won't run any tests. + executed_in_parallel = pydev_runfiles_parallel.execute_tests_in_parallel( + all_tests, self.jobs, self.split_jobs, self.verbosity, coverage_files, self.configuration.coverage_include) + + if not executed_in_parallel: + #If in coverage, we don't need to pass anything here (coverage is already enabled for this execution). + runner = pydev_runfiles_unittest.PydevTextTestRunner(stream=sys.stdout, descriptions=1, verbosity=self.verbosity) + sys.stdout.write('\n') + runner.run(test_suite) + + if self.configuration.django: + get_django_test_suite_runner()(run_tests).run_tests([]) + else: + run_tests() + + if handle_coverage: + coverage.stop() + coverage.save() + + total_time = 'Finished in: %.2f secs.' % (time.time() - start_time,) + pydev_runfiles_xml_rpc.notifyTestRunFinished(total_time) + + +DJANGO_TEST_SUITE_RUNNER = None + +def get_django_test_suite_runner(): + global DJANGO_TEST_SUITE_RUNNER + if DJANGO_TEST_SUITE_RUNNER: + return DJANGO_TEST_SUITE_RUNNER + try: + # django >= 1.8 + import django + from django.test.runner import DiscoverRunner + + class MyDjangoTestSuiteRunner(DiscoverRunner): + + def __init__(self, on_run_suite): + django.setup() + DiscoverRunner.__init__(self) + self.on_run_suite = on_run_suite + + def build_suite(self, *args, **kwargs): + pass + + def suite_result(self, *args, **kwargs): + pass + + def run_suite(self, *args, **kwargs): + self.on_run_suite() + except: + # django < 1.8 + try: + from django.test.simple import DjangoTestSuiteRunner + except: + class DjangoTestSuiteRunner: + def __init__(self): + pass + + def run_tests(self, *args, **kwargs): + raise AssertionError("Unable to run suite with django.test.runner.DiscoverRunner nor django.test.simple.DjangoTestSuiteRunner because it couldn't be imported.") + + class MyDjangoTestSuiteRunner(DjangoTestSuiteRunner): + + def __init__(self, on_run_suite): + DjangoTestSuiteRunner.__init__(self) + self.on_run_suite = on_run_suite + + def build_suite(self, *args, **kwargs): + pass + + def suite_result(self, *args, **kwargs): + pass + + def run_suite(self, *args, **kwargs): + self.on_run_suite() + + DJANGO_TEST_SUITE_RUNNER = MyDjangoTestSuiteRunner + return DJANGO_TEST_SUITE_RUNNER + + +#======================================================================================================================= +# main +#======================================================================================================================= +def main(configuration): + PydevTestRunner(configuration).run_tests() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_coverage.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_coverage.py new file mode 100644 index 0000000..a835925 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_coverage.py @@ -0,0 +1,76 @@ +import os.path +import sys +from _pydevd_bundle.pydevd_constants import Null + + +#======================================================================================================================= +# get_coverage_files +#======================================================================================================================= +def get_coverage_files(coverage_output_dir, number_of_files): + base_dir = coverage_output_dir + ret = [] + i = 0 + while len(ret) < number_of_files: + while True: + f = os.path.join(base_dir, '.coverage.%s' % i) + i += 1 + if not os.path.exists(f): + ret.append(f) + break #Break only inner for. + return ret + + +#======================================================================================================================= +# start_coverage_support +#======================================================================================================================= +def start_coverage_support(configuration): + return start_coverage_support_from_params( + configuration.coverage_output_dir, + configuration.coverage_output_file, + configuration.jobs, + configuration.coverage_include, + ) + + +#======================================================================================================================= +# start_coverage_support_from_params +#======================================================================================================================= +def start_coverage_support_from_params(coverage_output_dir, coverage_output_file, jobs, coverage_include): + coverage_files = [] + coverage_instance = Null() + if coverage_output_dir or coverage_output_file: + try: + import coverage #@UnresolvedImport + except: + sys.stderr.write('Error: coverage module could not be imported\n') + sys.stderr.write('Please make sure that the coverage module (http://nedbatchelder.com/code/coverage/)\n') + sys.stderr.write('is properly installed in your interpreter: %s\n' % (sys.executable,)) + + import traceback;traceback.print_exc() + else: + if coverage_output_dir: + if not os.path.exists(coverage_output_dir): + sys.stderr.write('Error: directory for coverage output (%s) does not exist.\n' % (coverage_output_dir,)) + + elif not os.path.isdir(coverage_output_dir): + sys.stderr.write('Error: expected (%s) to be a directory.\n' % (coverage_output_dir,)) + + else: + n = jobs + if n <= 0: + n += 1 + n += 1 #Add 1 more for the current process (which will do the initial import). + coverage_files = get_coverage_files(coverage_output_dir, n) + os.environ['COVERAGE_FILE'] = coverage_files.pop(0) + + coverage_instance = coverage.coverage(source=[coverage_include]) + coverage_instance.start() + + elif coverage_output_file: + #Client of parallel run. + os.environ['COVERAGE_FILE'] = coverage_output_file + coverage_instance = coverage.coverage(source=[coverage_include]) + coverage_instance.start() + + return coverage_files, coverage_instance + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_nose.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_nose.py new file mode 100644 index 0000000..1cee0ff --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_nose.py @@ -0,0 +1,182 @@ +from nose.plugins.multiprocess import MultiProcessTestRunner # @UnresolvedImport +from nose.plugins.base import Plugin # @UnresolvedImport +import sys +from _pydev_runfiles import pydev_runfiles_xml_rpc +import time +from _pydev_runfiles.pydev_runfiles_coverage import start_coverage_support + +#======================================================================================================================= +# PydevPlugin +#======================================================================================================================= +class PydevPlugin(Plugin): + + def __init__(self, configuration): + self.configuration = configuration + Plugin.__init__(self) + + + def begin(self): + # Called before any test is run (it's always called, with multiprocess or not) + self.start_time = time.time() + self.coverage_files, self.coverage = start_coverage_support(self.configuration) + + + def finalize(self, result): + # Called after all tests are run (it's always called, with multiprocess or not) + self.coverage.stop() + self.coverage.save() + + pydev_runfiles_xml_rpc.notifyTestRunFinished('Finished in: %.2f secs.' % (time.time() - self.start_time,)) + + + + #=================================================================================================================== + # Methods below are not called with multiprocess (so, we monkey-patch MultiProcessTestRunner.consolidate + # so that they're called, but unfortunately we loose some info -- i.e.: the time for each test in this + # process). + #=================================================================================================================== + + + def report_cond(self, cond, test, captured_output, error=''): + ''' + @param cond: fail, error, ok + ''' + + # test.address() is something as: + # ('D:\\workspaces\\temp\\test_workspace\\pytesting1\\src\\mod1\\hello.py', 'mod1.hello', 'TestCase.testMet1') + # + # and we must pass: location, test + # E.g.: ['D:\\src\\mod1\\hello.py', 'TestCase.testMet1'] + try: + if hasattr(test, 'address'): + address = test.address() + address = address[0], address[2] + else: + # multiprocess + try: + address = test[0], test[1] + except TypeError: + # It may be an error at setup, in which case it's not really a test, but a Context object. + f = test.context.__file__ + if f.endswith('.pyc'): + f = f[:-1] + elif f.endswith('$py.class'): + f = f[:-len('$py.class')] + '.py' + address = f, '?' + except: + sys.stderr.write("PyDev: Internal pydev error getting test address. Please report at the pydev bug tracker\n") + import traceback;traceback.print_exc() + sys.stderr.write("\n\n\n") + address = '?', '?' + + error_contents = self.get_io_from_error(error) + try: + time_str = '%.2f' % (time.time() - test._pydev_start_time) + except: + time_str = '?' + + pydev_runfiles_xml_rpc.notifyTest(cond, captured_output, error_contents, address[0], address[1], time_str) + + + def startTest(self, test): + test._pydev_start_time = time.time() + if hasattr(test, 'address'): + address = test.address() + file, test = address[0], address[2] + else: + # multiprocess + file, test = test + pydev_runfiles_xml_rpc.notifyStartTest(file, test) + + + def get_io_from_error(self, err): + if type(err) == type(()): + if len(err) != 3: + if len(err) == 2: + return err[1] # multiprocess + try: + from StringIO import StringIO + except: + from io import StringIO + s = StringIO() + etype, value, tb = err + import traceback;traceback.print_exception(etype, value, tb, file=s) + return s.getvalue() + return err + + + def get_captured_output(self, test): + if hasattr(test, 'capturedOutput') and test.capturedOutput: + return test.capturedOutput + return '' + + + def addError(self, test, err): + self.report_cond( + 'error', + test, + self.get_captured_output(test), + err, + ) + + + def addFailure(self, test, err): + self.report_cond( + 'fail', + test, + self.get_captured_output(test), + err, + ) + + + def addSuccess(self, test): + self.report_cond( + 'ok', + test, + self.get_captured_output(test), + '', + ) + + +PYDEV_NOSE_PLUGIN_SINGLETON = None +def start_pydev_nose_plugin_singleton(configuration): + global PYDEV_NOSE_PLUGIN_SINGLETON + PYDEV_NOSE_PLUGIN_SINGLETON = PydevPlugin(configuration) + return PYDEV_NOSE_PLUGIN_SINGLETON + + + + +original = MultiProcessTestRunner.consolidate +#======================================================================================================================= +# new_consolidate +#======================================================================================================================= +def new_consolidate(self, result, batch_result): + ''' + Used so that it can work with the multiprocess plugin. + Monkeypatched because nose seems a bit unsupported at this time (ideally + the plugin would have this support by default). + ''' + ret = original(self, result, batch_result) + + parent_frame = sys._getframe().f_back + # addr is something as D:\pytesting1\src\mod1\hello.py:TestCase.testMet4 + # so, convert it to what report_cond expects + addr = parent_frame.f_locals['addr'] + i = addr.rindex(':') + addr = [addr[:i], addr[i + 1:]] + + output, testsRun, failures, errors, errorClasses = batch_result + if failures or errors: + for failure in failures: + PYDEV_NOSE_PLUGIN_SINGLETON.report_cond('fail', addr, output, failure) + + for error in errors: + PYDEV_NOSE_PLUGIN_SINGLETON.report_cond('error', addr, output, error) + else: + PYDEV_NOSE_PLUGIN_SINGLETON.report_cond('ok', addr, output) + + + return ret + +MultiProcessTestRunner.consolidate = new_consolidate diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel.py new file mode 100644 index 0000000..34009ca --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel.py @@ -0,0 +1,296 @@ +import unittest +from _pydev_imps._pydev_saved_modules import thread +try: + import Queue +except: + import queue as Queue #@UnresolvedImport +from _pydev_runfiles import pydev_runfiles_xml_rpc +import time +import os +import threading +import sys + +#======================================================================================================================= +# flatten_test_suite +#======================================================================================================================= +def flatten_test_suite(test_suite, ret): + if isinstance(test_suite, unittest.TestSuite): + for t in test_suite._tests: + flatten_test_suite(t, ret) + + elif isinstance(test_suite, unittest.TestCase): + ret.append(test_suite) + + +#======================================================================================================================= +# execute_tests_in_parallel +#======================================================================================================================= +def execute_tests_in_parallel(tests, jobs, split, verbosity, coverage_files, coverage_include): + ''' + @param tests: list(PydevTestSuite) + A list with the suites to be run + + @param split: str + Either 'module' or the number of tests that should be run in each batch + + @param coverage_files: list(file) + A list with the files that should be used for giving coverage information (if empty, coverage information + should not be gathered). + + @param coverage_include: str + The pattern that should be included in the coverage. + + @return: bool + Returns True if the tests were actually executed in parallel. If the tests were not executed because only 1 + should be used (e.g.: 2 jobs were requested for running 1 test), False will be returned and no tests will be + run. + + It may also return False if in debug mode (in which case, multi-processes are not accepted) + ''' + try: + from _pydevd_bundle.pydevd_comm import get_global_debugger + if get_global_debugger() is not None: + return False + except: + pass #Ignore any error here. + + #This queue will receive the tests to be run. Each entry in a queue is a list with the tests to be run together When + #split == 'tests', each list will have a single element, when split == 'module', each list will have all the tests + #from a given module. + tests_queue = [] + + queue_elements = [] + if split == 'module': + module_to_tests = {} + for test in tests: + lst = [] + flatten_test_suite(test, lst) + for test in lst: + key = (test.__pydev_pyfile__, test.__pydev_module_name__) + module_to_tests.setdefault(key, []).append(test) + + for key, tests in module_to_tests.items(): + queue_elements.append(tests) + + if len(queue_elements) < jobs: + #Don't create jobs we will never use. + jobs = len(queue_elements) + + elif split == 'tests': + for test in tests: + lst = [] + flatten_test_suite(test, lst) + for test in lst: + queue_elements.append([test]) + + if len(queue_elements) < jobs: + #Don't create jobs we will never use. + jobs = len(queue_elements) + + else: + raise AssertionError('Do not know how to handle: %s' % (split,)) + + for test_cases in queue_elements: + test_queue_elements = [] + for test_case in test_cases: + try: + test_name = test_case.__class__.__name__+"."+test_case._testMethodName + except AttributeError: + #Support for jython 2.1 (__testMethodName is pseudo-private in the test case) + test_name = test_case.__class__.__name__+"."+test_case._TestCase__testMethodName + + test_queue_elements.append(test_case.__pydev_pyfile__+'|'+test_name) + + tests_queue.append(test_queue_elements) + + if jobs < 2: + return False + + sys.stdout.write('Running tests in parallel with: %s jobs.\n' %(jobs,)) + + + queue = Queue.Queue() + for item in tests_queue: + queue.put(item, block=False) + + + providers = [] + clients = [] + for i in range(jobs): + test_cases_provider = CommunicationThread(queue) + providers.append(test_cases_provider) + + test_cases_provider.start() + port = test_cases_provider.port + + if coverage_files: + clients.append(ClientThread(i, port, verbosity, coverage_files.pop(0), coverage_include)) + else: + clients.append(ClientThread(i, port, verbosity)) + + for client in clients: + client.start() + + client_alive = True + while client_alive: + client_alive = False + for client in clients: + #Wait for all the clients to exit. + if not client.finished: + client_alive = True + time.sleep(.2) + break + + for provider in providers: + provider.shutdown() + + return True + + + +#======================================================================================================================= +# CommunicationThread +#======================================================================================================================= +class CommunicationThread(threading.Thread): + + def __init__(self, tests_queue): + threading.Thread.__init__(self) + self.setDaemon(True) + self.queue = tests_queue + self.finished = False + from _pydev_bundle.pydev_imports import SimpleXMLRPCServer + + + # This is a hack to patch slow socket.getfqdn calls that + # BaseHTTPServer (and its subclasses) make. + # See: http://bugs.python.org/issue6085 + # See: http://www.answermysearches.com/xmlrpc-server-slow-in-python-how-to-fix/2140/ + try: + import BaseHTTPServer + def _bare_address_string(self): + host, port = self.client_address[:2] + return '%s' % host + BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string + + except: + pass + # End hack. + + + # Create server + + from _pydev_bundle import pydev_localhost + server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), 0), logRequests=False) + server.register_function(self.GetTestsToRun) + server.register_function(self.notifyStartTest) + server.register_function(self.notifyTest) + server.register_function(self.notifyCommands) + self.port = server.socket.getsockname()[1] + self.server = server + + + def GetTestsToRun(self, job_id): + ''' + @param job_id: + + @return: list(str) + Each entry is a string in the format: filename|Test.testName + ''' + try: + ret = self.queue.get(block=False) + return ret + except: #Any exception getting from the queue (empty or not) means we finished our work on providing the tests. + self.finished = True + return [] + + + def notifyCommands(self, job_id, commands): + #Batch notification. + for command in commands: + getattr(self, command[0])(job_id, *command[1], **command[2]) + + return True + + def notifyStartTest(self, job_id, *args, **kwargs): + pydev_runfiles_xml_rpc.notifyStartTest(*args, **kwargs) + return True + + + def notifyTest(self, job_id, *args, **kwargs): + pydev_runfiles_xml_rpc.notifyTest(*args, **kwargs) + return True + + def shutdown(self): + if hasattr(self.server, 'shutdown'): + self.server.shutdown() + else: + self._shutdown = True + + def run(self): + if hasattr(self.server, 'shutdown'): + self.server.serve_forever() + else: + self._shutdown = False + while not self._shutdown: + self.server.handle_request() + + + +#======================================================================================================================= +# Client +#======================================================================================================================= +class ClientThread(threading.Thread): + + def __init__(self, job_id, port, verbosity, coverage_output_file=None, coverage_include=None): + threading.Thread.__init__(self) + self.setDaemon(True) + self.port = port + self.job_id = job_id + self.verbosity = verbosity + self.finished = False + self.coverage_output_file = coverage_output_file + self.coverage_include = coverage_include + + + def _reader_thread(self, pipe, target): + while True: + target.write(pipe.read(1)) + + + def run(self): + try: + from _pydev_runfiles import pydev_runfiles_parallel_client + #TODO: Support Jython: + # + #For jython, instead of using sys.executable, we should use: + #r'D:\bin\jdk_1_5_09\bin\java.exe', + #'-classpath', + #'D:/bin/jython-2.2.1/jython.jar', + #'org.python.util.jython', + + args = [ + sys.executable, + pydev_runfiles_parallel_client.__file__, + str(self.job_id), + str(self.port), + str(self.verbosity), + ] + + if self.coverage_output_file and self.coverage_include: + args.append(self.coverage_output_file) + args.append(self.coverage_include) + + import subprocess + if False: + proc = subprocess.Popen(args, env=os.environ, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + thread.start_new_thread(self._reader_thread,(proc.stdout, sys.stdout)) + + thread.start_new_thread(target=self._reader_thread,args=(proc.stderr, sys.stderr)) + else: + proc = subprocess.Popen(args, env=os.environ, shell=False) + proc.wait() + + finally: + self.finished = True + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel_client.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel_client.py new file mode 100644 index 0000000..3d81dd5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_parallel_client.py @@ -0,0 +1,214 @@ +from _pydev_bundle.pydev_imports import xmlrpclib, _queue +Queue = _queue.Queue +import traceback +import sys +from _pydev_runfiles.pydev_runfiles_coverage import start_coverage_support_from_params +import threading + + +#======================================================================================================================= +# ParallelNotification +#======================================================================================================================= +class ParallelNotification(object): + + def __init__(self, method, args, kwargs): + self.method = method + self.args = args + self.kwargs = kwargs + + def to_tuple(self): + return self.method, self.args, self.kwargs + + +#======================================================================================================================= +# KillServer +#======================================================================================================================= +class KillServer(object): + pass + + + +#======================================================================================================================= +# ServerComm +#======================================================================================================================= +class ServerComm(threading.Thread): + + + + def __init__(self, job_id, server): + self.notifications_queue = Queue() + threading.Thread.__init__(self) + self.setDaemon(False) #Wait for all the notifications to be passed before exiting! + assert job_id is not None + assert port is not None + self.job_id = job_id + + self.finished = False + self.server = server + + + def run(self): + while True: + kill_found = False + commands = [] + command = self.notifications_queue.get(block=True) + if isinstance(command, KillServer): + kill_found = True + else: + assert isinstance(command, ParallelNotification) + commands.append(command.to_tuple()) + + try: + while True: + command = self.notifications_queue.get(block=False) #No block to create a batch. + if isinstance(command, KillServer): + kill_found = True + else: + assert isinstance(command, ParallelNotification) + commands.append(command.to_tuple()) + except: + pass #That's OK, we're getting it until it becomes empty so that we notify multiple at once. + + + if commands: + try: + #Batch notification. + self.server.lock.acquire() + try: + self.server.notifyCommands(self.job_id, commands) + finally: + self.server.lock.release() + except: + traceback.print_exc() + + if kill_found: + self.finished = True + return + + + +#======================================================================================================================= +# ServerFacade +#======================================================================================================================= +class ServerFacade(object): + + + def __init__(self, notifications_queue): + self.notifications_queue = notifications_queue + + + def notifyTestsCollected(self, *args, **kwargs): + pass #This notification won't be passed + + + def notifyTestRunFinished(self, *args, **kwargs): + pass #This notification won't be passed + + + def notifyStartTest(self, *args, **kwargs): + self.notifications_queue.put_nowait(ParallelNotification('notifyStartTest', args, kwargs)) + + + def notifyTest(self, *args, **kwargs): + self.notifications_queue.put_nowait(ParallelNotification('notifyTest', args, kwargs)) + + + +#======================================================================================================================= +# run_client +#======================================================================================================================= +def run_client(job_id, port, verbosity, coverage_output_file, coverage_include): + job_id = int(job_id) + + from _pydev_bundle import pydev_localhost + server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), port)) + server.lock = threading.Lock() + + + server_comm = ServerComm(job_id, server) + server_comm.start() + + try: + server_facade = ServerFacade(server_comm.notifications_queue) + from _pydev_runfiles import pydev_runfiles + from _pydev_runfiles import pydev_runfiles_xml_rpc + pydev_runfiles_xml_rpc.set_server(server_facade) + + #Starts None and when the 1st test is gotten, it's started (because a server may be initiated and terminated + #before receiving any test -- which would mean a different process got all the tests to run). + coverage = None + + try: + tests_to_run = [1] + while tests_to_run: + #Investigate: is it dangerous to use the same xmlrpclib server from different threads? + #It seems it should be, as it creates a new connection for each request... + server.lock.acquire() + try: + tests_to_run = server.GetTestsToRun(job_id) + finally: + server.lock.release() + + if not tests_to_run: + break + + if coverage is None: + _coverage_files, coverage = start_coverage_support_from_params( + None, coverage_output_file, 1, coverage_include) + + + files_to_tests = {} + for test in tests_to_run: + filename_and_test = test.split('|') + if len(filename_and_test) == 2: + files_to_tests.setdefault(filename_and_test[0], []).append(filename_and_test[1]) + + configuration = pydev_runfiles.Configuration( + '', + verbosity, + None, + None, + None, + files_to_tests, + 1, #Always single job here + None, + + #The coverage is handled in this loop. + coverage_output_file=None, + coverage_include=None, + ) + test_runner = pydev_runfiles.PydevTestRunner(configuration) + sys.stdout.flush() + test_runner.run_tests(handle_coverage=False) + finally: + if coverage is not None: + coverage.stop() + coverage.save() + + + except: + traceback.print_exc() + server_comm.notifications_queue.put_nowait(KillServer()) + + + +#======================================================================================================================= +# main +#======================================================================================================================= +if __name__ == '__main__': + if len(sys.argv) -1 == 3: + job_id, port, verbosity = sys.argv[1:] + coverage_output_file, coverage_include = None, None + + elif len(sys.argv) -1 == 5: + job_id, port, verbosity, coverage_output_file, coverage_include = sys.argv[1:] + + else: + raise AssertionError('Could not find out how to handle the parameters: '+sys.argv[1:]) + + job_id = int(job_id) + port = int(port) + verbosity = int(verbosity) + run_client(job_id, port, verbosity, coverage_output_file, coverage_include) + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_pytest2.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_pytest2.py new file mode 100644 index 0000000..3e38d71 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_pytest2.py @@ -0,0 +1,287 @@ +from _pydev_runfiles import pydev_runfiles_xml_rpc +import pickle +import zlib +import base64 +import os +import py +from pydevd_file_utils import _NormFile +import pytest +import sys +import time + +#========================================================================= +# Load filters with tests we should skip +#========================================================================= +py_test_accept_filter = None + + +def _load_filters(): + global py_test_accept_filter + if py_test_accept_filter is None: + py_test_accept_filter = os.environ.get('PYDEV_PYTEST_SKIP') + if py_test_accept_filter: + py_test_accept_filter = pickle.loads( + zlib.decompress(base64.b64decode(py_test_accept_filter))) + else: + py_test_accept_filter = {} + + +def is_in_xdist_node(): + main_pid = os.environ.get('PYDEV_MAIN_PID') + if main_pid and main_pid != str(os.getpid()): + return True + return False + + +connected = False + + +def connect_to_server_for_communication_to_xml_rpc_on_xdist(): + global connected + if connected: + return + connected = True + if is_in_xdist_node(): + port = os.environ.get('PYDEV_PYTEST_SERVER') + if not port: + sys.stderr.write( + 'Error: no PYDEV_PYTEST_SERVER environment variable defined.\n') + else: + pydev_runfiles_xml_rpc.initialize_server(int(port), daemon=True) + + +PY2 = sys.version_info[0] <= 2 +PY3 = not PY2 + + +class State: + start_time = time.time() + buf_err = None + buf_out = None + + +def start_redirect(): + if State.buf_out is not None: + return + from _pydevd_bundle import pydevd_io + State.buf_err = pydevd_io.start_redirect(keep_original_redirection=True, std='stderr') + State.buf_out = pydevd_io.start_redirect(keep_original_redirection=True, std='stdout') + + +def get_curr_output(): + buf_out = State.buf_out + buf_err = State.buf_err + return buf_out.getvalue() if buf_out is not None else '', buf_err.getvalue() if buf_err is not None else '' + + +def pytest_unconfigure(): + if is_in_xdist_node(): + return + # Only report that it finished when on the main node (we don't want to report + # the finish on each separate node). + pydev_runfiles_xml_rpc.notifyTestRunFinished( + 'Finished in: %.2f secs.' % (time.time() - State.start_time,)) + + +def pytest_collection_modifyitems(session, config, items): + # A note: in xdist, this is not called on the main process, only in the + # secondary nodes, so, we'll actually make the filter and report it multiple + # times. + connect_to_server_for_communication_to_xml_rpc_on_xdist() + + _load_filters() + if not py_test_accept_filter: + pydev_runfiles_xml_rpc.notifyTestsCollected(len(items)) + return # Keep on going (nothing to filter) + + new_items = [] + for item in items: + f = _NormFile(str(item.parent.fspath)) + name = item.name + + if f not in py_test_accept_filter: + # print('Skip file: %s' % (f,)) + continue # Skip the file + + accept_tests = py_test_accept_filter[f] + + if item.cls is not None: + class_name = item.cls.__name__ + else: + class_name = None + for test in accept_tests: + # This happens when parameterizing pytest tests. + i = name.find('[') + if i > 0: + name = name[:i] + if test == name: + # Direct match of the test (just go on with the default + # loading) + new_items.append(item) + break + + if class_name is not None: + if test == class_name + '.' + name: + new_items.append(item) + break + + if class_name == test: + new_items.append(item) + break + else: + pass + # print('Skip test: %s.%s. Accept: %s' % (class_name, name, accept_tests)) + + # Modify the original list + items[:] = new_items + pydev_runfiles_xml_rpc.notifyTestsCollected(len(items)) + + +from py.io import TerminalWriter + + +def _get_error_contents_from_report(report): + if report.longrepr is not None: + tw = TerminalWriter(stringio=True) + tw.hasmarkup = False + report.toterminal(tw) + exc = tw.stringio.getvalue() + s = exc.strip() + if s: + return s + + return '' + + +def pytest_collectreport(report): + error_contents = _get_error_contents_from_report(report) + if error_contents: + report_test('fail', '', '', '', error_contents, 0.0) + + +def append_strings(s1, s2): + if s1.__class__ == s2.__class__: + return s1 + s2 + + if sys.version_info[0] == 2: + if not isinstance(s1, basestring): + s1 = str(s1) + + if not isinstance(s2, basestring): + s2 = str(s2) + + # Prefer bytes + if isinstance(s1, unicode): + s1 = s1.encode('utf-8') + + if isinstance(s2, unicode): + s2 = s2.encode('utf-8') + + return s1 + s2 + else: + # Prefer str + if isinstance(s1, bytes): + s1 = s1.decode('utf-8', 'replace') + + if isinstance(s2, bytes): + s2 = s2.decode('utf-8', 'replace') + + return s1 + s2 + + +def pytest_runtest_logreport(report): + if is_in_xdist_node(): + # When running with xdist, we don't want the report to be called from the node, only + # from the main process. + return + report_duration = report.duration + report_when = report.when + report_outcome = report.outcome + + if hasattr(report, 'wasxfail'): + if report_outcome != 'skipped': + report_outcome = 'passed' + + if report_outcome == 'passed': + # passed on setup/teardown: no need to report if in setup or teardown + # (only on the actual test if it passed). + if report_when in ('setup', 'teardown'): + return + + status = 'ok' + + elif report_outcome == 'skipped': + status = 'skip' + + else: + # It has only passed, skipped and failed (no error), so, let's consider + # error if not on call. + if report_when in ('setup', 'teardown'): + status = 'error' + + else: + # any error in the call (not in setup or teardown) is considered a + # regular failure. + status = 'fail' + + # This will work if pytest is not capturing it, if it is, nothing will + # come from here... + captured_output, error_contents = getattr(report, 'pydev_captured_output', ''), getattr(report, 'pydev_error_contents', '') + for type_section, value in report.sections: + if value: + if type_section in ('err', 'stderr', 'Captured stderr call'): + error_contents = append_strings(error_contents, value) + else: + captured_output = append_strings(error_contents, value) + + filename = getattr(report, 'pydev_fspath_strpath', '') + test = report.location[2] + + if report_outcome != 'skipped': + # On skipped, we'll have a traceback for the skip, which is not what we + # want. + exc = _get_error_contents_from_report(report) + if exc: + if error_contents: + error_contents = append_strings(error_contents, '----------------------------- Exceptions -----------------------------\n') + error_contents = append_strings(error_contents, exc) + + report_test(status, filename, test, captured_output, error_contents, report_duration) + + +def report_test(status, filename, test, captured_output, error_contents, duration): + ''' + @param filename: 'D:\\src\\mod1\\hello.py' + @param test: 'TestCase.testMet1' + @param status: fail, error, ok + ''' + time_str = '%.2f' % (duration,) + pydev_runfiles_xml_rpc.notifyTest( + status, captured_output, error_contents, filename, test, time_str) + + +if not hasattr(pytest, 'hookimpl'): + raise AssertionError('Please upgrade pytest (the current version of pytest: %s is unsupported)' % (pytest.__version__,)) + + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_makereport(item, call): + outcome = yield + report = outcome.get_result() + report.pydev_fspath_strpath = item.fspath.strpath + report.pydev_captured_output, report.pydev_error_contents = get_curr_output() + + +@pytest.mark.tryfirst +def pytest_runtest_setup(item): + ''' + Note: with xdist will be on a secondary process. + ''' + # We have our own redirection: if xdist does its redirection, we'll have + # nothing in our contents (which is OK), but if it does, we'll get nothing + # from pytest but will get our own here. + start_redirect() + filename = item.fspath.strpath + test = item.location[2] + + pydev_runfiles_xml_rpc.notifyStartTest(filename, test) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_unittest.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_unittest.py new file mode 100644 index 0000000..f0ad9ef --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_unittest.py @@ -0,0 +1,185 @@ +try: + import unittest2 as python_unittest # @UnresolvedImport +except: + import unittest as python_unittest + +from _pydev_runfiles import pydev_runfiles_xml_rpc +import time +from _pydevd_bundle import pydevd_io +import traceback +from _pydevd_bundle.pydevd_constants import * #@UnusedWildImport + + +#======================================================================================================================= +# PydevTextTestRunner +#======================================================================================================================= +class PydevTextTestRunner(python_unittest.TextTestRunner): + + def _makeResult(self): + return PydevTestResult(self.stream, self.descriptions, self.verbosity) + + +_PythonTextTestResult = python_unittest.TextTestRunner()._makeResult().__class__ + +#======================================================================================================================= +# PydevTestResult +#======================================================================================================================= +class PydevTestResult(_PythonTextTestResult): + + def addSubTest(self, test, subtest, err): + """Called at the end of a subtest. + 'err' is None if the subtest ended successfully, otherwise it's a + tuple of values as returned by sys.exc_info(). + """ + _PythonTextTestResult.addSubTest(self, test, subtest, err) + if err is not None: + subdesc = subtest._subDescription() + error = (test, self._exc_info_to_string(err, test)) + self._reportErrors([error], [], '', '%s %s' % (self.get_test_name(test), subdesc)) + + + def startTest(self, test): + _PythonTextTestResult.startTest(self, test) + self.buf = pydevd_io.start_redirect(keep_original_redirection=True, std='both') + self.start_time = time.time() + self._current_errors_stack = [] + self._current_failures_stack = [] + + try: + test_name = test.__class__.__name__+"."+test._testMethodName + except AttributeError: + #Support for jython 2.1 (__testMethodName is pseudo-private in the test case) + test_name = test.__class__.__name__+"."+test._TestCase__testMethodName + + pydev_runfiles_xml_rpc.notifyStartTest( + test.__pydev_pyfile__, test_name) + + + + + def get_test_name(self, test): + try: + try: + test_name = test.__class__.__name__ + "." + test._testMethodName + except AttributeError: + #Support for jython 2.1 (__testMethodName is pseudo-private in the test case) + try: + test_name = test.__class__.__name__ + "." + test._TestCase__testMethodName + #Support for class/module exceptions (test is instance of _ErrorHolder) + except: + test_name = test.description.split()[1][1:-1] + ' <' + test.description.split()[0] + '>' + except: + traceback.print_exc() + return '' + return test_name + + + def stopTest(self, test): + end_time = time.time() + pydevd_io.end_redirect(std='both') + + _PythonTextTestResult.stopTest(self, test) + + captured_output = self.buf.getvalue() + del self.buf + error_contents = '' + test_name = self.get_test_name(test) + + + diff_time = '%.2f' % (end_time - self.start_time) + if not self._current_errors_stack and not self._current_failures_stack: + pydev_runfiles_xml_rpc.notifyTest( + 'ok', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time) + else: + self._reportErrors(self._current_errors_stack, self._current_failures_stack, captured_output, test_name) + + + def _reportErrors(self, errors, failures, captured_output, test_name, diff_time=''): + error_contents = [] + for test, s in errors+failures: + if type(s) == type((1,)): #If it's a tuple (for jython 2.1) + sio = StringIO() + traceback.print_exception(s[0], s[1], s[2], file=sio) + s = sio.getvalue() + error_contents.append(s) + + sep = '\n'+self.separator1 + error_contents = sep.join(error_contents) + + if errors and not failures: + try: + pydev_runfiles_xml_rpc.notifyTest( + 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time) + except: + file_start = error_contents.find('File "') + file_end = error_contents.find('", ', file_start) + if file_start != -1 and file_end != -1: + file = error_contents[file_start+6:file_end] + else: + file = '' + pydev_runfiles_xml_rpc.notifyTest( + 'error', captured_output, error_contents, file, test_name, diff_time) + + elif failures and not errors: + pydev_runfiles_xml_rpc.notifyTest( + 'fail', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time) + + else: #Ok, we got both, errors and failures. Let's mark it as an error in the end. + pydev_runfiles_xml_rpc.notifyTest( + 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time) + + + + def addError(self, test, err): + _PythonTextTestResult.addError(self, test, err) + #Support for class/module exceptions (test is instance of _ErrorHolder) + if not hasattr(self, '_current_errors_stack') or test.__class__.__name__ == '_ErrorHolder': + #Not in start...end, so, report error now (i.e.: django pre/post-setup) + self._reportErrors([self.errors[-1]], [], '', self.get_test_name(test)) + else: + self._current_errors_stack.append(self.errors[-1]) + + + def addFailure(self, test, err): + _PythonTextTestResult.addFailure(self, test, err) + if not hasattr(self, '_current_failures_stack'): + #Not in start...end, so, report error now (i.e.: django pre/post-setup) + self._reportErrors([], [self.failures[-1]], '', self.get_test_name(test)) + else: + self._current_failures_stack.append(self.failures[-1]) + + +try: + #Version 2.7 onwards has a different structure... Let's not make any changes in it for now + #(waiting for bug: http://bugs.python.org/issue11798) + try: + from unittest2 import suite + except ImportError: + from unittest import suite + #=================================================================================================================== + # PydevTestSuite + #=================================================================================================================== + class PydevTestSuite(python_unittest.TestSuite): + pass + + +except ImportError: + + #=================================================================================================================== + # PydevTestSuite + #=================================================================================================================== + class PydevTestSuite(python_unittest.TestSuite): + + + def run(self, result): + for index, test in enumerate(self._tests): + if result.shouldStop: + break + test(result) + + # Let the memory be released! + self._tests[index] = None + + return result + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_xml_rpc.py b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_xml_rpc.py new file mode 100644 index 0000000..ff8e4b3 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydev_runfiles/pydev_runfiles_xml_rpc.py @@ -0,0 +1,283 @@ +import sys +import threading +import traceback +import warnings + +from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding +from _pydev_bundle.pydev_imports import xmlrpclib, _queue +from _pydevd_bundle.pydevd_constants import Null, IS_PY3K + +Queue = _queue.Queue + +#This may happen in IronPython (in Python it shouldn't happen as there are +#'fast' replacements that are used in xmlrpclib.py) +warnings.filterwarnings( + 'ignore', 'The xmllib module is obsolete.*', DeprecationWarning) + + +file_system_encoding = getfilesystemencoding() + +#======================================================================================================================= +# _ServerHolder +#======================================================================================================================= +class _ServerHolder: + ''' + Helper so that we don't have to use a global here. + ''' + SERVER = None + + +#======================================================================================================================= +# set_server +#======================================================================================================================= +def set_server(server): + _ServerHolder.SERVER = server + + + +#======================================================================================================================= +# ParallelNotification +#======================================================================================================================= +class ParallelNotification(object): + + def __init__(self, method, args): + self.method = method + self.args = args + + def to_tuple(self): + return self.method, self.args + + + +#======================================================================================================================= +# KillServer +#======================================================================================================================= +class KillServer(object): + pass + + +#======================================================================================================================= +# ServerFacade +#======================================================================================================================= +class ServerFacade(object): + + + def __init__(self, notifications_queue): + self.notifications_queue = notifications_queue + + + def notifyTestsCollected(self, *args): + self.notifications_queue.put_nowait(ParallelNotification('notifyTestsCollected', args)) + + def notifyConnected(self, *args): + self.notifications_queue.put_nowait(ParallelNotification('notifyConnected', args)) + + + def notifyTestRunFinished(self, *args): + self.notifications_queue.put_nowait(ParallelNotification('notifyTestRunFinished', args)) + + + def notifyStartTest(self, *args): + self.notifications_queue.put_nowait(ParallelNotification('notifyStartTest', args)) + + + def notifyTest(self, *args): + new_args = [] + for arg in args: + new_args.append(_encode_if_needed(arg)) + args = tuple(new_args) + self.notifications_queue.put_nowait(ParallelNotification('notifyTest', args)) + + + + + +#======================================================================================================================= +# ServerComm +#======================================================================================================================= +class ServerComm(threading.Thread): + + + + def __init__(self, notifications_queue, port, daemon=False): + threading.Thread.__init__(self) + self.setDaemon(daemon) # If False, wait for all the notifications to be passed before exiting! + self.finished = False + self.notifications_queue = notifications_queue + + from _pydev_bundle import pydev_localhost + + # It is necessary to specify an encoding, that matches + # the encoding of all bytes-strings passed into an + # XMLRPC call: "All 8-bit strings in the data structure are assumed to use the + # packet encoding. Unicode strings are automatically converted, + # where necessary." + # Byte strings most likely come from file names. + encoding = file_system_encoding + if encoding == "mbcs": + # Windos symbolic name for the system encoding CP_ACP. + # We need to convert it into a encoding that is recognized by Java. + # Unfortunately this is not always possible. You could use + # GetCPInfoEx and get a name similar to "windows-1251". Then + # you need a table to translate on a best effort basis. Much to complicated. + # ISO-8859-1 is good enough. + encoding = "ISO-8859-1" + + self.server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), port), + encoding=encoding) + + + def run(self): + while True: + kill_found = False + commands = [] + command = self.notifications_queue.get(block=True) + if isinstance(command, KillServer): + kill_found = True + else: + assert isinstance(command, ParallelNotification) + commands.append(command.to_tuple()) + + try: + while True: + command = self.notifications_queue.get(block=False) #No block to create a batch. + if isinstance(command, KillServer): + kill_found = True + else: + assert isinstance(command, ParallelNotification) + commands.append(command.to_tuple()) + except: + pass #That's OK, we're getting it until it becomes empty so that we notify multiple at once. + + + if commands: + try: + self.server.notifyCommands(commands) + except: + traceback.print_exc() + + if kill_found: + self.finished = True + return + + + +#======================================================================================================================= +# initialize_server +#======================================================================================================================= +def initialize_server(port, daemon=False): + if _ServerHolder.SERVER is None: + if port is not None: + notifications_queue = Queue() + _ServerHolder.SERVER = ServerFacade(notifications_queue) + _ServerHolder.SERVER_COMM = ServerComm(notifications_queue, port, daemon) + _ServerHolder.SERVER_COMM.start() + else: + #Create a null server, so that we keep the interface even without any connection. + _ServerHolder.SERVER = Null() + _ServerHolder.SERVER_COMM = Null() + + try: + _ServerHolder.SERVER.notifyConnected() + except: + traceback.print_exc() + + + +#======================================================================================================================= +# notifyTest +#======================================================================================================================= +def notifyTestsCollected(tests_count): + assert tests_count is not None + try: + _ServerHolder.SERVER.notifyTestsCollected(tests_count) + except: + traceback.print_exc() + + +#======================================================================================================================= +# notifyStartTest +#======================================================================================================================= +def notifyStartTest(file, test): + ''' + @param file: the tests file (c:/temp/test.py) + @param test: the test ran (i.e.: TestCase.test1) + ''' + assert file is not None + if test is None: + test = '' #Could happen if we have an import error importing module. + + try: + _ServerHolder.SERVER.notifyStartTest(file, test) + except: + traceback.print_exc() + + +def _encode_if_needed(obj): + # In the java side we expect strings to be ISO-8859-1 (org.python.pydev.debug.pyunit.PyUnitServer.initializeDispatches().new Dispatch() {...}.getAsStr(Object)) + if not IS_PY3K: + if isinstance(obj, str): + try: + return xmlrpclib.Binary(obj.decode(sys.stdin.encoding).encode('ISO-8859-1', 'xmlcharrefreplace')) + except: + return xmlrpclib.Binary(obj) + + elif isinstance(obj, unicode): + return xmlrpclib.Binary(obj.encode('ISO-8859-1', 'xmlcharrefreplace')) + + else: + if isinstance(obj, str): # Unicode in py3 + return xmlrpclib.Binary(obj.encode('ISO-8859-1', 'xmlcharrefreplace')) + + elif isinstance(obj, bytes): + try: + return xmlrpclib.Binary(obj.decode(sys.stdin.encoding).encode('ISO-8859-1', 'xmlcharrefreplace')) + except: + return xmlrpclib.Binary(obj) #bytes already + + return obj + + +#======================================================================================================================= +# notifyTest +#======================================================================================================================= +def notifyTest(cond, captured_output, error_contents, file, test, time): + ''' + @param cond: ok, fail, error + @param captured_output: output captured from stdout + @param captured_output: output captured from stderr + @param file: the tests file (c:/temp/test.py) + @param test: the test ran (i.e.: TestCase.test1) + @param time: float with the number of seconds elapsed + ''' + assert cond is not None + assert captured_output is not None + assert error_contents is not None + assert file is not None + if test is None: + test = '' #Could happen if we have an import error importing module. + assert time is not None + try: + captured_output = _encode_if_needed(captured_output) + error_contents = _encode_if_needed(error_contents) + + _ServerHolder.SERVER.notifyTest(cond, captured_output, error_contents, file, test, time) + except: + traceback.print_exc() + +#======================================================================================================================= +# notifyTestRunFinished +#======================================================================================================================= +def notifyTestRunFinished(total_time): + assert total_time is not None + try: + _ServerHolder.SERVER.notifyTestRunFinished(total_time) + except: + traceback.print_exc() + + +#======================================================================================================================= +# force_server_kill +#======================================================================================================================= +def force_server_kill(): + _ServerHolder.SERVER_COMM.notifications_queue.put_nowait(KillServer()) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__main__pydevd_gen_debug_adapter_protocol.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__main__pydevd_gen_debug_adapter_protocol.py new file mode 100644 index 0000000..042478e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/__main__pydevd_gen_debug_adapter_protocol.py @@ -0,0 +1,580 @@ +''' +Run this module to regenerate the `pydevd_schema.py` file. + +Note that it'll generate it based on the current debugProtocol.json. Erase it and rerun +to download the latest version. +''' + + +def is_variable_to_translate(cls_name, var_name): + if var_name in ('variablesReference', 'frameId', 'threadId'): + return True + + if cls_name == 'StackFrame' and var_name == 'id': + # It's frameId everywhere except on StackFrame. + return True + + if cls_name == 'Thread' and var_name == 'id': + # It's threadId everywhere except on Thread. + return True + + return False + + +def _get_noqa_for_var(prop_name): + return ' # noqa (assign to builtin)' if prop_name in ('type', 'format', 'id', 'hex', 'breakpoint', 'filter') else '' + + +class _OrderedSet(object): + # Not a good ordered set (just something to be small without adding any deps) + + def __init__(self, initial_contents=None): + self._contents = [] + self._contents_as_set = set() + if initial_contents is not None: + for x in initial_contents: + self.add(x) + + def add(self, x): + if x not in self._contents_as_set: + self._contents_as_set.add(x) + self._contents.append(x) + + def copy(self): + return _OrderedSet(self._contents) + + def update(self, contents): + for x in contents: + self.add(x) + + def __iter__(self): + return iter(self._contents) + + def __contains__(self, item): + return item in self._contents_as_set + + def __len__(self): + return len(self._contents) + + def set_repr(self): + if len(self) == 0: + return 'set()' + + lst = [repr(x) for x in self] + return 'set([' + ', '.join(lst) + '])' + + +class Ref(object): + + def __init__(self, ref, ref_data): + self.ref = ref + self.ref_data = ref_data + + def __str__(self): + return self.ref + + +def load_schema_data(): + import os.path + import json + + json_file = os.path.join(os.path.dirname(__file__), 'debugProtocol.json') + if not os.path.exists(json_file): + import requests + req = requests.get('https://raw.githubusercontent.com/Microsoft/vscode-debugadapter-node/master/debugProtocol.json') + assert req.status_code == 200 + with open(json_file, 'wb') as stream: + stream.write(req.content) + + with open(json_file, 'rb') as json_contents: + json_schema_data = json.loads(json_contents.read()) + return json_schema_data + + +def load_custom_schema_data(): + import os.path + import json + + json_file = os.path.join(os.path.dirname(__file__), 'debugProtocolCustom.json') + + with open(json_file, 'rb') as json_contents: + json_schema_data = json.loads(json_contents.read()) + return json_schema_data + + +def create_classes_to_generate_structure(json_schema_data): + definitions = json_schema_data['definitions'] + + class_to_generatees = {} + + for name, definition in definitions.items(): + all_of = definition.get('allOf') + description = definition.get('description') + is_enum = definition.get('type') == 'string' and 'enum' in definition + enum_values = None + if is_enum: + enum_values = definition['enum'] + properties = {} + properties.update(definition.get('properties', {})) + required = _OrderedSet(definition.get('required', _OrderedSet())) + base_definitions = [] + + if all_of is not None: + for definition in all_of: + ref = definition.get('$ref') + if ref is not None: + assert ref.startswith('#/definitions/') + ref = ref[len('#/definitions/'):] + base_definitions.append(ref) + else: + if not description: + description = definition.get('description') + properties.update(definition.get('properties', {})) + required.update(_OrderedSet(definition.get('required', _OrderedSet()))) + + if isinstance(description, (list, tuple)): + description = '\n'.join(description) + + class_to_generatees[name] = dict( + name=name, + properties=properties, + base_definitions=base_definitions, + description=description, + required=required, + is_enum=is_enum, + enum_values=enum_values + ) + return class_to_generatees + + +def collect_bases(curr_class, classes_to_generate, memo=None): + ret = [] + if memo is None: + memo = {} + + base_definitions = curr_class['base_definitions'] + for base_definition in base_definitions: + if base_definition not in memo: + ret.append(base_definition) + ret.extend(collect_bases(classes_to_generate[base_definition], classes_to_generate, memo)) + + return ret + + +def fill_properties_and_required_from_base(classes_to_generate): + # Now, resolve properties based on refs + for class_to_generate in classes_to_generate.values(): + dct = {} + s = _OrderedSet() + + for base_definition in reversed(collect_bases(class_to_generate, classes_to_generate)): + # Note: go from base to current so that the initial order of the properties has that + # same order. + dct.update(classes_to_generate[base_definition].get('properties', {})) + s.update(classes_to_generate[base_definition].get('required', _OrderedSet())) + + dct.update(class_to_generate['properties']) + class_to_generate['properties'] = dct + + s.update(class_to_generate['required']) + class_to_generate['required'] = s + + return class_to_generate + + +def update_class_to_generate_description(class_to_generate): + import textwrap + description = class_to_generate['description'] + lines = [] + for line in description.splitlines(): + wrapped = textwrap.wrap(line.strip(), 100) + lines.extend(wrapped) + lines.append('') + + while lines and lines[-1] == '': + lines = lines[:-1] + + class_to_generate['description'] = ' ' + ('\n '.join(lines)) + + +def update_class_to_generate_type(classes_to_generate, class_to_generate): + properties = class_to_generate.get('properties') + for _prop_name, prop_val in properties.items(): + prop_type = prop_val.get('type', '') + if not prop_type: + prop_type = prop_val.pop('$ref', '') + if prop_type: + assert prop_type.startswith('#/definitions/') + prop_type = prop_type[len('#/definitions/'):] + prop_val['type'] = Ref(prop_type, classes_to_generate[prop_type]) + + +def update_class_to_generate_register_dec(classes_to_generate, class_to_generate): + # Default + class_to_generate['register_request'] = '' + class_to_generate['register_dec'] = '@register' + + properties = class_to_generate.get('properties') + enum_type = properties.get('type', {}).get('enum') + command = None + event = None + if enum_type and len(enum_type) == 1 and next(iter(enum_type)) in ("request", "response", "event"): + msg_type = next(iter(enum_type)) + if msg_type == 'response': + # The actual command is typed in the request + response_name = class_to_generate['name'] + request_name = response_name[:-len('Response')] + 'Request' + if request_name in classes_to_generate: + command = classes_to_generate[request_name]['properties'].get('command') + else: + if response_name == 'ErrorResponse': + command = {'enum' : ['error']} + else: + raise AssertionError('Unhandled: %s' % (response_name,)) + + elif msg_type == 'request': + command = properties.get('command') + + elif msg_type == 'event': + command = properties.get('event') + + else: + raise AssertionError('Unexpected condition.') + + if command: + enum = command.get('enum') + if enum and len(enum) == 1: + class_to_generate['register_request'] = '@register_%s(%r)\n' % (msg_type, enum[0]) + + +def extract_prop_name_and_prop(class_to_generate): + properties = class_to_generate.get('properties') + required = _OrderedSet(class_to_generate.get('required', _OrderedSet())) + + # Sort so that required come first + prop_name_and_prop = list(properties.items()) + + def compute_sort_key(x): + key = x[0] + if key in required: + if key == 'seq': + return 0.5 # seq when required is after the other required keys (to have a default of -1). + return 0 + return 1 + + prop_name_and_prop.sort(key=compute_sort_key) + + return prop_name_and_prop + + +def update_class_to_generate_to_json(class_to_generate): + required = _OrderedSet(class_to_generate.get('required', _OrderedSet())) + prop_name_and_prop = extract_prop_name_and_prop(class_to_generate) + + to_dict_body = ['def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused)'] + + translate_prop_names = [] + for prop_name, prop in prop_name_and_prop: + if is_variable_to_translate(class_to_generate['name'], prop_name): + translate_prop_names.append(prop_name) + + for prop_name, prop in prop_name_and_prop: + namespace = dict(prop_name=prop_name, noqa=_get_noqa_for_var(prop_name)) + to_dict_body.append(' %(prop_name)s = self.%(prop_name)s%(noqa)s' % namespace) + + if prop.get('type') == 'array': + to_dict_body.append(' if %(prop_name)s and hasattr(%(prop_name)s[0], "to_dict"):' % namespace) + to_dict_body.append(' %(prop_name)s = [x.to_dict() for x in %(prop_name)s]' % namespace) + + if translate_prop_names: + to_dict_body.append(' if update_ids_to_dap:') + for prop_name in translate_prop_names: + namespace = dict(prop_name=prop_name, noqa=_get_noqa_for_var(prop_name)) + to_dict_body.append(' if %(prop_name)s is not None:' % namespace) + to_dict_body.append(' %(prop_name)s = self._translate_id_to_dap(%(prop_name)s)%(noqa)s' % namespace) + + if not translate_prop_names: + update_dict_ids_from_dap_body = [] + else: + update_dict_ids_from_dap_body = ['', '', '@classmethod', 'def update_dict_ids_from_dap(cls, dct):'] + for prop_name in translate_prop_names: + namespace = dict(prop_name=prop_name) + update_dict_ids_from_dap_body.append(' if %(prop_name)r in dct:' % namespace) + update_dict_ids_from_dap_body.append(' dct[%(prop_name)r] = cls._translate_id_from_dap(dct[%(prop_name)r])' % namespace) + update_dict_ids_from_dap_body.append(' return dct') + + class_to_generate['update_dict_ids_from_dap'] = _indent_lines('\n'.join(update_dict_ids_from_dap_body)) + + to_dict_body.append(' dct = {') + first_not_required = False + + for prop_name, prop in prop_name_and_prop: + use_to_dict = prop['type'].__class__ == Ref and not prop['type'].ref_data.get('is_enum', False) + is_array = prop['type'] == 'array' + ref_array_cls_name = '' + if is_array: + ref = prop['items'].get('$ref') + if ref is not None: + ref_array_cls_name = ref.split('/')[-1] + + namespace = dict(prop_name=prop_name, ref_array_cls_name=ref_array_cls_name) + if prop_name in required: + if use_to_dict: + to_dict_body.append(' %(prop_name)r: %(prop_name)s.to_dict(update_ids_to_dap=update_ids_to_dap),' % namespace) + else: + if ref_array_cls_name: + to_dict_body.append(' %(prop_name)r: [%(ref_array_cls_name)s.update_dict_ids_to_dap(o) for o in %(prop_name)s] if (update_ids_to_dap and %(prop_name)s) else %(prop_name)s,' % namespace) + else: + to_dict_body.append(' %(prop_name)r: %(prop_name)s,' % namespace) + else: + if not first_not_required: + first_not_required = True + to_dict_body.append(' }') + + to_dict_body.append(' if %(prop_name)s is not None:' % namespace) + if use_to_dict: + to_dict_body.append(' dct[%(prop_name)r] = %(prop_name)s.to_dict(update_ids_to_dap=update_ids_to_dap)' % namespace) + else: + if ref_array_cls_name: + to_dict_body.append(' dct[%(prop_name)r] = [%(ref_array_cls_name)s.update_dict_ids_to_dap(o) for o in %(prop_name)s] if (update_ids_to_dap and %(prop_name)s) else %(prop_name)s' % namespace) + else: + to_dict_body.append(' dct[%(prop_name)r] = %(prop_name)s' % namespace) + + if not first_not_required: + first_not_required = True + to_dict_body.append(' }') + + to_dict_body.append(' dct.update(self.kwargs)') + to_dict_body.append(' return dct') + + class_to_generate['to_dict'] = _indent_lines('\n'.join(to_dict_body)) + + if not translate_prop_names: + update_dict_ids_to_dap_body = [] + else: + update_dict_ids_to_dap_body = ['', '', '@classmethod', 'def update_dict_ids_to_dap(cls, dct):'] + for prop_name in translate_prop_names: + namespace = dict(prop_name=prop_name) + update_dict_ids_to_dap_body.append(' if %(prop_name)r in dct:' % namespace) + update_dict_ids_to_dap_body.append(' dct[%(prop_name)r] = cls._translate_id_to_dap(dct[%(prop_name)r])' % namespace) + update_dict_ids_to_dap_body.append(' return dct') + + class_to_generate['update_dict_ids_to_dap'] = _indent_lines('\n'.join(update_dict_ids_to_dap_body)) + + +def update_class_to_generate_init(class_to_generate): + args = [] + init_body = [] + docstring = [] + + required = _OrderedSet(class_to_generate.get('required', _OrderedSet())) + prop_name_and_prop = extract_prop_name_and_prop(class_to_generate) + + translate_prop_names = [] + for prop_name, prop in prop_name_and_prop: + if is_variable_to_translate(class_to_generate['name'], prop_name): + translate_prop_names.append(prop_name) + + enum = prop.get('enum') + if enum and len(enum) == 1: + init_body.append(' self.%(prop_name)s = %(enum)r' % dict(prop_name=prop_name, enum=next(iter(enum)))) + else: + if prop_name in required: + if prop_name == 'seq': + args.append(prop_name + '=-1') + else: + args.append(prop_name) + else: + args.append(prop_name + '=None') + + if prop['type'].__class__ == Ref: + ref = prop['type'] + ref_data = ref.ref_data + if ref_data.get('is_enum', False): + init_body.append(' assert %s in %s.VALID_VALUES' % (prop_name, str(ref))) + init_body.append(' self.%(prop_name)s = %(prop_name)s' % dict( + prop_name=prop_name)) + else: + namespace = dict( + prop_name=prop_name, + ref_name=str(ref) + ) + init_body.append(' if %(prop_name)s is None:' % namespace) + init_body.append(' self.%(prop_name)s = %(ref_name)s()' % namespace) + init_body.append(' else:') + init_body.append(' self.%(prop_name)s = %(ref_name)s(update_ids_from_dap=update_ids_from_dap, **%(prop_name)s) if %(prop_name)s.__class__ != %(ref_name)s else %(prop_name)s' % namespace + ) + + else: + init_body.append(' self.%(prop_name)s = %(prop_name)s' % dict(prop_name=prop_name)) + + if prop['type'] == 'array': + ref = prop['items'].get('$ref') + if ref is not None: + ref_array_cls_name = ref.split('/')[-1] + init_body.append(' if update_ids_from_dap and self.%(prop_name)s:' % dict(prop_name=prop_name)) + init_body.append(' for o in self.%(prop_name)s:' % dict(prop_name=prop_name)) + init_body.append(' %(ref_array_cls_name)s.update_dict_ids_from_dap(o)' % dict(ref_array_cls_name=ref_array_cls_name)) + + prop_type = prop['type'] + prop_description = prop.get('description', '') + + if isinstance(prop_description, (list, tuple)): + prop_description = '\n '.join(prop_description) + + docstring.append(':param %(prop_type)s %(prop_name)s: %(prop_description)s' % dict( + prop_type=prop_type, prop_name=prop_name, prop_description=prop_description)) + + if translate_prop_names: + init_body.append(' if update_ids_from_dap:') + for prop_name in translate_prop_names: + init_body.append(' self.%(prop_name)s = self._translate_id_from_dap(self.%(prop_name)s)' % dict(prop_name=prop_name)) + + docstring = _indent_lines('\n'.join(docstring)) + init_body = '\n'.join(init_body) + + # Actually bundle the whole __init__ from the parts. + args = ', '.join(args) + if args: + args = ', ' + args + + # Note: added kwargs because some messages are expected to be extended by the user (so, we'll actually + # make all extendable so that we don't have to worry about which ones -- we loose a little on typing, + # but may be better than doing a whitelist based on something only pointed out in the documentation). + class_to_generate['init'] = '''def __init__(self%(args)s, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ +%(docstring)s + """ +%(init_body)s + self.kwargs = kwargs +''' % dict(args=args, init_body=init_body, docstring=docstring) + + class_to_generate['init'] = _indent_lines(class_to_generate['init']) + + +def update_class_to_generate_props(class_to_generate): + import json + + def default(o): + if isinstance(o, Ref): + return o.ref + raise AssertionError('Unhandled: %s' % (o,)) + + properties = class_to_generate['properties'] + class_to_generate['props'] = ' __props__ = %s' % _indent_lines( + json.dumps(properties, indent=4, default=default)).strip() + + +def update_class_to_generate_refs(class_to_generate): + properties = class_to_generate['properties'] + class_to_generate['refs'] = ' __refs__ = %s' % _OrderedSet( + key for (key, val) in properties.items() if val['type'].__class__ == Ref).set_repr() + + +def update_class_to_generate_enums(class_to_generate): + class_to_generate['enums'] = '' + if class_to_generate.get('is_enum', False): + enums = '' + for enum in class_to_generate['enum_values']: + enums += ' %s = %r\n' % (enum.upper(), enum) + enums += '\n' + enums += ' VALID_VALUES = %s\n\n' % _OrderedSet(class_to_generate['enum_values']).set_repr() + class_to_generate['enums'] = enums + + +def update_class_to_generate_objects(classes_to_generate, class_to_generate): + properties = class_to_generate['properties'] + for key, val in properties.items(): + if val['type'] == 'object': + create_new = val.copy() + create_new.update({ + 'name': '%s%s' % (class_to_generate['name'], key.title()), + 'description': ' "%s" of %s' % (key, class_to_generate['name']) + }) + if 'properties' not in create_new: + create_new['properties'] = {} + + assert create_new['name'] not in classes_to_generate + classes_to_generate[create_new['name']] = create_new + + update_class_to_generate_type(classes_to_generate, create_new) + update_class_to_generate_props(create_new) + + # Update nested object types + update_class_to_generate_objects(classes_to_generate, create_new) + + val['type'] = Ref(create_new['name'], classes_to_generate[create_new['name']]) + val.pop('properties', None) + + +def gen_debugger_protocol(): + import os.path + import sys + + if sys.version_info[:2] < (3, 6): + raise AssertionError('Must be run with Python 3.6 onwards (to keep dict order).') + + classes_to_generate = create_classes_to_generate_structure(load_schema_data()) + classes_to_generate.update(create_classes_to_generate_structure(load_custom_schema_data())) + + class_to_generate = fill_properties_and_required_from_base(classes_to_generate) + + for class_to_generate in list(classes_to_generate.values()): + update_class_to_generate_description(class_to_generate) + update_class_to_generate_type(classes_to_generate, class_to_generate) + update_class_to_generate_props(class_to_generate) + update_class_to_generate_objects(classes_to_generate, class_to_generate) + + for class_to_generate in classes_to_generate.values(): + update_class_to_generate_refs(class_to_generate) + update_class_to_generate_init(class_to_generate) + update_class_to_generate_enums(class_to_generate) + update_class_to_generate_to_json(class_to_generate) + update_class_to_generate_register_dec(classes_to_generate, class_to_generate) + + class_template = ''' +%(register_request)s%(register_dec)s +class %(name)s(BaseSchema): + """ +%(description)s + + Note: automatically generated code. Do not edit manually. + """ + +%(enums)s%(props)s +%(refs)s + + __slots__ = list(__props__.keys()) + ['kwargs'] + +%(init)s%(update_dict_ids_from_dap)s + +%(to_dict)s%(update_dict_ids_to_dap)s +''' + + contents = [] + contents.append('# coding: utf-8') + contents.append('# Automatically generated code.') + contents.append('# Do not edit manually.') + contents.append('# Generated by running: %s' % os.path.basename(__file__)) + contents.append('from .pydevd_base_schema import BaseSchema, register, register_request, register_response, register_event') + contents.append('') + for class_to_generate in classes_to_generate.values(): + contents.append(class_template % class_to_generate) + + parent_dir = os.path.dirname(__file__) + schema = os.path.join(parent_dir, 'pydevd_schema.py') + with open(schema, 'w', encoding='utf-8') as stream: + stream.write('\n'.join(contents)) + + +def _indent_lines(lines, indent=' '): + out_lines = [] + for line in lines.splitlines(keepends=True): + out_lines.append(indent + line) + + return ''.join(out_lines) + + +if __name__ == '__main__': + + gen_debugger_protocol() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocol.json b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocol.json new file mode 100644 index 0000000..3b45056 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocol.json @@ -0,0 +1,3409 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Debug Adapter Protocol", + "description": "The Debug Adapter Protocol defines the protocol used between an editor or IDE and a debugger or runtime.", + "type": "object", + + + "definitions": { + + "ProtocolMessage": { + "type": "object", + "title": "Base Protocol", + "description": "Base class of requests, responses, and events.", + "properties": { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "description": "Message type.", + "_enum": [ "request", "response", "event" ] + } + }, + "required": [ "seq", "type" ] + }, + + "Request": { + "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, { + "type": "object", + "description": "A client or debug adapter initiated request.", + "properties": { + "type": { + "type": "string", + "enum": [ "request" ] + }, + "command": { + "type": "string", + "description": "The command to execute." + }, + "arguments": { + "type": [ "array", "boolean", "integer", "null", "number" , "object", "string" ], + "description": "Object containing arguments for the command." + } + }, + "required": [ "type", "command" ] + }] + }, + + "Event": { + "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, { + "type": "object", + "description": "A debug adapter initiated event.", + "properties": { + "type": { + "type": "string", + "enum": [ "event" ] + }, + "event": { + "type": "string", + "description": "Type of event." + }, + "body": { + "type": [ "array", "boolean", "integer", "null", "number" , "object", "string" ], + "description": "Event-specific information." + } + }, + "required": [ "type", "event" ] + }] + }, + + "Response": { + "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, { + "type": "object", + "description": "Response for a request.", + "properties": { + "type": { + "type": "string", + "enum": [ "response" ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ "array", "boolean", "integer", "null", "number" , "object", "string" ], + "description": "Contains request result if success is true and optional error details if success is false." + } + }, + "required": [ "type", "request_seq", "success", "command" ] + }] + }, + + "ErrorResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "On error (whenever 'success' is false), the body can provide more details.", + "properties": { + "body": { + "type": "object", + "properties": { + "error": { + "$ref": "#/definitions/Message", + "description": "An optional, structured error message." + } + } + } + }, + "required": [ "body" ] + }] + }, + + "InitializedEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "title": "Events", + "description": "This event indicates that the debug adapter is ready to accept configuration requests (e.g. SetBreakpointsRequest, SetExceptionBreakpointsRequest).\nA debug adapter is expected to send this event when it is ready to accept configuration requests (but not before the 'initialize' request has finished).\nThe sequence of events/requests is as follows:\n- adapters sends 'initialized' event (after the 'initialize' request has returned)\n- frontend sends zero or more 'setBreakpoints' requests\n- frontend sends one 'setFunctionBreakpoints' request\n- frontend sends a 'setExceptionBreakpoints' request if one or more 'exceptionBreakpointFilters' have been defined (or if 'supportsConfigurationDoneRequest' is not defined or false)\n- frontend sends other future configuration requests\n- frontend sends one 'configurationDone' request to indicate the end of the configuration.", + "properties": { + "event": { + "type": "string", + "enum": [ "initialized" ] + } + }, + "required": [ "event" ] + }] + }, + + "StoppedEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that the execution of the debuggee has stopped due to some condition.\nThis can be caused by a break point previously set, a stepping action has completed, by executing a debugger statement etc.", + "properties": { + "event": { + "type": "string", + "enum": [ "stopped" ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.\nFor backward compatibility this string is shown in the UI if the 'description' attribute is missing (but it must not be translated).", + "_enum": [ "step", "breakpoint", "exception", "pause", "entry", "goto", "function breakpoint", "data breakpoint" ] + }, + "description": { + "type": "string", + "description": "The full reason for the event, e.g. 'Paused on exception'. This string is shown in the UI as is and must be translated." + }, + "threadId": { + "type": "integer", + "description": "The thread which was stopped." + }, + "preserveFocusHint": { + "type": "boolean", + "description": "A value of true hints to the frontend that this event should not change the focus." + }, + "text": { + "type": "string", + "description": "Additional information. E.g. if reason is 'exception', text contains the exception name. This string is shown in the UI." + }, + "allThreadsStopped": { + "type": "boolean", + "description": "If 'allThreadsStopped' is true, a debug adapter can announce that all threads have stopped.\n- The client should use this information to enable that all threads can be expanded to access their stacktraces.\n- If the attribute is missing or false, only the thread with the given threadId can be expanded." + } + }, + "required": [ "reason" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "ContinuedEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that the execution of the debuggee has continued.\nPlease note: a debug adapter is not expected to send this event in response to a request that implies that execution continues, e.g. 'launch' or 'continue'.\nIt is only necessary to send a 'continued' event if there was no previous request that implied this.", + "properties": { + "event": { + "type": "string", + "enum": [ "continued" ] + }, + "body": { + "type": "object", + "properties": { + "threadId": { + "type": "integer", + "description": "The thread which was continued." + }, + "allThreadsContinued": { + "type": "boolean", + "description": "If 'allThreadsContinued' is true, a debug adapter can announce that all threads have continued." + } + }, + "required": [ "threadId" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "ExitedEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that the debuggee has exited and returns its exit code.", + "properties": { + "event": { + "type": "string", + "enum": [ "exited" ] + }, + "body": { + "type": "object", + "properties": { + "exitCode": { + "type": "integer", + "description": "The exit code returned from the debuggee." + } + }, + "required": [ "exitCode" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "TerminatedEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that debugging of the debuggee has terminated. This does **not** mean that the debuggee itself has exited.", + "properties": { + "event": { + "type": "string", + "enum": [ "terminated" ] + }, + "body": { + "type": "object", + "properties": { + "restart": { + "type": [ "array", "boolean", "integer", "null", "number", "object", "string" ], + "description": "A debug adapter may set 'restart' to true (or to an arbitrary object) to request that the front end restarts the session.\nThe value is not interpreted by the client and passed unmodified as an attribute '__restart' to the 'launch' and 'attach' requests." + } + } + } + }, + "required": [ "event" ] + }] + }, + + "ThreadEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that a thread has started or exited.", + "properties": { + "event": { + "type": "string", + "enum": [ "thread" ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "_enum": [ "started", "exited" ] + }, + "threadId": { + "type": "integer", + "description": "The identifier of the thread." + } + }, + "required": ["reason", "threadId"] + } + }, + "required": [ "event", "body" ] + }] + }, + + "OutputEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that the target has produced some output.", + "properties": { + "event": { + "type": "string", + "enum": [ "output" ] + }, + "body": { + "type": "object", + "properties": { + "category": { + "type": "string", + "description": "The output category. If not specified, 'console' is assumed.", + "_enum": [ "console", "stdout", "stderr", "telemetry" ] + }, + "output": { + "type": "string", + "description": "The output to report." + }, + "variablesReference": { + "type": "number", + "description": "If an attribute 'variablesReference' exists and its value is > 0, the output contains objects which can be retrieved by passing 'variablesReference' to the 'variables' request." + }, + "source": { + "$ref": "#/definitions/Source", + "description": "An optional source location where the output was produced." + }, + "line": { + "type": "integer", + "description": "An optional source location line where the output was produced." + }, + "column": { + "type": "integer", + "description": "An optional source location column where the output was produced." + }, + "data": { + "type": [ "array", "boolean", "integer", "null", "number" , "object", "string" ], + "description": "Optional data to report. For the 'telemetry' category the data will be sent to telemetry, for the other categories the data is shown in JSON format." + } + }, + "required": ["output"] + } + }, + "required": [ "event", "body" ] + }] + }, + + "BreakpointEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that some information about a breakpoint has changed.", + "properties": { + "event": { + "type": "string", + "enum": [ "breakpoint" ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "_enum": [ "changed", "new", "removed" ] + }, + "breakpoint": { + "$ref": "#/definitions/Breakpoint", + "description": "The 'id' attribute is used to find the target breakpoint and the other attributes are used as the new values." + } + }, + "required": [ "reason", "breakpoint" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "ModuleEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that some information about a module has changed.", + "properties": { + "event": { + "type": "string", + "enum": [ "module" ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "enum": [ "new", "changed", "removed" ] + }, + "module": { + "$ref": "#/definitions/Module", + "description": "The new, changed, or removed module. In case of 'removed' only the module id is used." + } + }, + "required": [ "reason", "module" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "LoadedSourceEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that some source has been added, changed, or removed from the set of all loaded sources.", + "properties": { + "event": { + "type": "string", + "enum": [ "loadedSource" ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "enum": [ "new", "changed", "removed" ] + }, + "source": { + "$ref": "#/definitions/Source", + "description": "The new, changed, or removed source." + } + }, + "required": [ "reason", "source" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "ProcessEvent": { + "allOf": [ + { "$ref": "#/definitions/Event" }, + { + "type": "object", + "description": "The event indicates that the debugger has begun debugging a new process. Either one that it has launched, or one that it has attached to.", + "properties": { + "event": { + "type": "string", + "enum": [ "process" ] + }, + "body": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The logical name of the process. This is usually the full path to process's executable file. Example: /home/example/myproj/program.js." + }, + "systemProcessId": { + "type": "integer", + "description": "The system process id of the debugged process. This property will be missing for non-system processes." + }, + "isLocalProcess": { + "type": "boolean", + "description": "If true, the process is running on the same computer as the debug adapter." + }, + "startMethod": { + "type": "string", + "enum": [ "launch", "attach", "attachForSuspendedLaunch" ], + "description": "Describes how the debug engine started debugging this process.", + "enumDescriptions": [ + "Process was launched under the debugger.", + "Debugger attached to an existing process.", + "A project launcher component has launched a new process in a suspended state and then asked the debugger to attach." + ] + }, + "pointerSize": { + "type": "integer", + "description": "The size of a pointer or address for this process, in bits. This value may be used by clients when formatting addresses for display." + } + }, + "required": [ "name" ] + } + }, + "required": [ "event", "body" ] + } + ] + }, + + "CapabilitiesEvent": { + "allOf": [ { "$ref": "#/definitions/Event" }, { + "type": "object", + "description": "The event indicates that one or more capabilities have changed.\nSince the capabilities are dependent on the frontend and its UI, it might not be possible to change that at random times (or too late).\nConsequently this event has a hint characteristic: a frontend can only be expected to make a 'best effort' in honouring individual capabilities but there are no guarantees.\nOnly changed capabilities need to be included, all other capabilities keep their values.", + "properties": { + "event": { + "type": "string", + "enum": [ "capabilities" ] + }, + "body": { + "type": "object", + "properties": { + "capabilities": { + "$ref": "#/definitions/Capabilities", + "description": "The set of updated capabilities." + } + }, + "required": [ "capabilities" ] + } + }, + "required": [ "event", "body" ] + }] + }, + + "RunInTerminalRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "title": "Reverse Requests", + "description": "This request is sent from the debug adapter to the client to run a command in a terminal. This is typically used to launch the debuggee in a terminal provided by the client.", + "properties": { + "command": { + "type": "string", + "enum": [ "runInTerminal" ] + }, + "arguments": { + "$ref": "#/definitions/RunInTerminalRequestArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "RunInTerminalRequestArguments": { + "type": "object", + "description": "Arguments for 'runInTerminal' request.", + "properties": { + "kind": { + "type": "string", + "enum": [ "integrated", "external" ], + "description": "What kind of terminal to launch." + }, + "title": { + "type": "string", + "description": "Optional title of the terminal." + }, + "cwd": { + "type": "string", + "description": "Working directory of the command." + }, + "args": { + "type": "array", + "items": { + "type": "string" + }, + "description": "List of arguments. The first argument is the command to run." + }, + "env": { + "type": "object", + "description": "Environment key-value pairs that are added to or removed from the default environment.", + "additionalProperties": { + "type": [ "string", "null" ], + "description": "Proper values must be strings. A value of 'null' removes the variable from the environment." + } + } + }, + "required": [ "args", "cwd" ] + }, + "RunInTerminalResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'runInTerminal' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "processId": { + "type": "number", + "description": "The process ID." + }, + "shellProcessId": { + "type": "number", + "description": "The process ID of the terminal shell." + } + } + } + }, + "required": [ "body" ] + }] + }, + + "InitializeRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "title": "Requests", + "description": "The 'initialize' request is sent as the first request from the client to the debug adapter in order to configure it with client capabilities and to retrieve capabilities from the debug adapter.\nUntil the debug adapter has responded to with an 'initialize' response, the client must not send any additional requests or events to the debug adapter. In addition the debug adapter is not allowed to send any requests or events to the client until it has responded with an 'initialize' response.\nThe 'initialize' request may only be sent once.", + "properties": { + "command": { + "type": "string", + "enum": [ "initialize" ] + }, + "arguments": { + "$ref": "#/definitions/InitializeRequestArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "InitializeRequestArguments": { + "type": "object", + "description": "Arguments for 'initialize' request.", + "properties": { + "clientID": { + "type": "string", + "description": "The ID of the (frontend) client using this adapter." + }, + "clientName": { + "type": "string", + "description": "The human readable name of the (frontend) client using this adapter." + }, + "adapterID": { + "type": "string", + "description": "The ID of the debug adapter." + }, + "locale": { + "type": "string", + "description": "The ISO-639 locale of the (frontend) client using this adapter, e.g. en-US or de-CH." + }, + "linesStartAt1": { + "type": "boolean", + "description": "If true all line numbers are 1-based (default)." + }, + "columnsStartAt1": { + "type": "boolean", + "description": "If true all column numbers are 1-based (default)." + }, + "pathFormat": { + "type": "string", + "_enum": [ "path", "uri" ], + "description": "Determines in what format paths are specified. The default is 'path', which is the native format." + }, + "supportsVariableType": { + "type": "boolean", + "description": "Client supports the optional type attribute for variables." + }, + "supportsVariablePaging": { + "type": "boolean", + "description": "Client supports the paging of variables." + }, + "supportsRunInTerminalRequest": { + "type": "boolean", + "description": "Client supports the runInTerminal request." + }, + "supportsMemoryReferences": { + "type": "boolean", + "description": "Client supports memory references." + } + }, + "required": [ "adapterID" ] + }, + "InitializeResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'initialize' request.", + "properties": { + "body": { + "$ref": "#/definitions/Capabilities", + "description": "The capabilities of this debug adapter." + } + } + }] + }, + + "ConfigurationDoneRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The client of the debug protocol must send this request at the end of the sequence of configuration requests (which was started by the 'initialized' event).", + "properties": { + "command": { + "type": "string", + "enum": [ "configurationDone" ] + }, + "arguments": { + "$ref": "#/definitions/ConfigurationDoneArguments" + } + }, + "required": [ "command" ] + }] + }, + "ConfigurationDoneArguments": { + "type": "object", + "description": "Arguments for 'configurationDone' request." + }, + "ConfigurationDoneResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'configurationDone' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "LaunchRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The launch request is sent from the client to the debug adapter to start the debuggee with or without debugging (if 'noDebug' is true). Since launching is debugger/runtime specific, the arguments for this request are not part of this specification.", + "properties": { + "command": { + "type": "string", + "enum": [ "launch" ] + }, + "arguments": { + "$ref": "#/definitions/LaunchRequestArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "LaunchRequestArguments": { + "type": "object", + "description": "Arguments for 'launch' request. Additional attributes are implementation specific.", + "properties": { + "noDebug": { + "type": "boolean", + "description": "If noDebug is true the launch request should launch the program without enabling debugging." + }, + "__restart": { + "type": [ "array", "boolean", "integer", "null", "number", "object", "string" ], + "description": "Optional data from the previous, restarted session.\nThe data is sent as the 'restart' attribute of the 'terminated' event.\nThe client should leave the data intact." + } + } + }, + "LaunchResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'launch' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "AttachRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The attach request is sent from the client to the debug adapter to attach to a debuggee that is already running. Since attaching is debugger/runtime specific, the arguments for this request are not part of this specification.", + "properties": { + "command": { + "type": "string", + "enum": [ "attach" ] + }, + "arguments": { + "$ref": "#/definitions/AttachRequestArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "AttachRequestArguments": { + "type": "object", + "description": "Arguments for 'attach' request. Additional attributes are implementation specific.", + "properties": { + "__restart": { + "type": [ "array", "boolean", "integer", "null", "number", "object", "string" ], + "description": "Optional data from the previous, restarted session.\nThe data is sent as the 'restart' attribute of the 'terminated' event.\nThe client should leave the data intact." + } + } + }, + "AttachResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'attach' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "RestartRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Restarts a debug session. If the capability 'supportsRestartRequest' is missing or has the value false,\nthe client will implement 'restart' by terminating the debug adapter first and then launching it anew.\nA debug adapter can override this default behaviour by implementing a restart request\nand setting the capability 'supportsRestartRequest' to true.", + "properties": { + "command": { + "type": "string", + "enum": [ "restart" ] + }, + "arguments": { + "$ref": "#/definitions/RestartArguments" + } + }, + "required": [ "command" ] + }] + }, + "RestartArguments": { + "type": "object", + "description": "Arguments for 'restart' request." + }, + "RestartResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'restart' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "DisconnectRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The 'disconnect' request is sent from the client to the debug adapter in order to stop debugging. It asks the debug adapter to disconnect from the debuggee and to terminate the debug adapter. If the debuggee has been started with the 'launch' request, the 'disconnect' request terminates the debuggee. If the 'attach' request was used to connect to the debuggee, 'disconnect' does not terminate the debuggee. This behavior can be controlled with the 'terminateDebuggee' argument (if supported by the debug adapter).", + "properties": { + "command": { + "type": "string", + "enum": [ "disconnect" ] + }, + "arguments": { + "$ref": "#/definitions/DisconnectArguments" + } + }, + "required": [ "command" ] + }] + }, + "DisconnectArguments": { + "type": "object", + "description": "Arguments for 'disconnect' request.", + "properties": { + "restart": { + "type": "boolean", + "description": "A value of true indicates that this 'disconnect' request is part of a restart sequence." + }, + "terminateDebuggee": { + "type": "boolean", + "description": "Indicates whether the debuggee should be terminated when the debugger is disconnected.\nIf unspecified, the debug adapter is free to do whatever it thinks is best.\nA client can only rely on this attribute being properly honored if a debug adapter returns true for the 'supportTerminateDebuggee' capability." + } + } + }, + "DisconnectResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'disconnect' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "TerminateRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The 'terminate' request is sent from the client to the debug adapter in order to give the debuggee a chance for terminating itself.", + "properties": { + "command": { + "type": "string", + "enum": [ "terminate" ] + }, + "arguments": { + "$ref": "#/definitions/TerminateArguments" + } + }, + "required": [ "command" ] + }] + }, + "TerminateArguments": { + "type": "object", + "description": "Arguments for 'terminate' request.", + "properties": { + "restart": { + "type": "boolean", + "description": "A value of true indicates that this 'terminate' request is part of a restart sequence." + } + } + }, + "TerminateResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'terminate' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "SetBreakpointsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Sets multiple breakpoints for a single source and clears all previous breakpoints in that source.\nTo clear all breakpoint for a source, specify an empty array.\nWhen a breakpoint is hit, a 'stopped' event (with reason 'breakpoint') is generated.", + "properties": { + "command": { + "type": "string", + "enum": [ "setBreakpoints" ] + }, + "arguments": { + "$ref": "#/definitions/SetBreakpointsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetBreakpointsArguments": { + "type": "object", + "description": "Arguments for 'setBreakpoints' request.", + "properties": { + "source": { + "$ref": "#/definitions/Source", + "description": "The source location of the breakpoints; either 'source.path' or 'source.reference' must be specified." + }, + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/SourceBreakpoint" + }, + "description": "The code locations of the breakpoints." + }, + "lines": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "Deprecated: The code locations of the breakpoints." + }, + "sourceModified": { + "type": "boolean", + "description": "A value of true indicates that the underlying source has been modified which results in new breakpoint locations." + } + }, + "required": [ "source" ] + }, + "SetBreakpointsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setBreakpoints' request.\nReturned is information about each breakpoint created by this request.\nThis includes the actual code location and whether the breakpoint could be verified.\nThe breakpoints returned are in the same order as the elements of the 'breakpoints'\n(or the deprecated 'lines') array in the arguments.", + "properties": { + "body": { + "type": "object", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the breakpoints. The array elements are in the same order as the elements of the 'breakpoints' (or the deprecated 'lines') array in the arguments." + } + }, + "required": [ "breakpoints" ] + } + }, + "required": [ "body" ] + }] + }, + + "SetFunctionBreakpointsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Replaces all existing function breakpoints with new function breakpoints.\nTo clear all function breakpoints, specify an empty array.\nWhen a function breakpoint is hit, a 'stopped' event (with reason 'function breakpoint') is generated.", + "properties": { + "command": { + "type": "string", + "enum": [ "setFunctionBreakpoints" ] + }, + "arguments": { + "$ref": "#/definitions/SetFunctionBreakpointsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetFunctionBreakpointsArguments": { + "type": "object", + "description": "Arguments for 'setFunctionBreakpoints' request.", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/FunctionBreakpoint" + }, + "description": "The function names of the breakpoints." + } + }, + "required": [ "breakpoints" ] + }, + "SetFunctionBreakpointsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setFunctionBreakpoints' request.\nReturned is information about each breakpoint created by this request.", + "properties": { + "body": { + "type": "object", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the breakpoints. The array elements correspond to the elements of the 'breakpoints' array." + } + }, + "required": [ "breakpoints" ] + } + }, + "required": [ "body" ] + }] + }, + + "SetExceptionBreakpointsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request configures the debuggers response to thrown exceptions. If an exception is configured to break, a 'stopped' event is fired (with reason 'exception').", + "properties": { + "command": { + "type": "string", + "enum": [ "setExceptionBreakpoints" ] + }, + "arguments": { + "$ref": "#/definitions/SetExceptionBreakpointsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetExceptionBreakpointsArguments": { + "type": "object", + "description": "Arguments for 'setExceptionBreakpoints' request.", + "properties": { + "filters": { + "type": "array", + "items": { + "type": "string" + }, + "description": "IDs of checked exception options. The set of IDs is returned via the 'exceptionBreakpointFilters' capability." + }, + "exceptionOptions": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionOptions" + }, + "description": "Configuration options for selected exceptions." + } + }, + "required": [ "filters" ] + }, + "SetExceptionBreakpointsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setExceptionBreakpoints' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "DataBreakpointInfoRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Obtains information on a possible data breakpoint that could be set on an expression or variable.", + "properties": { + "command": { + "type": "string", + "enum": [ "dataBreakpointInfo" ] + }, + "arguments": { + "$ref": "#/definitions/DataBreakpointInfoArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "DataBreakpointInfoArguments": { + "type": "object", + "description": "Arguments for 'dataBreakpointInfo' request.", + "properties": { + "variablesReference": { + "type": "integer", + "description": "Reference to the Variable container if the data breakpoint is requested for a child of the container." + }, + "name": { + "type": "string", + "description": "The name of the Variable's child to obtain data breakpoint information for. If variableReference isn’t provided, this can be an expression." + } + }, + "required": [ "name" ] + }, + "DataBreakpointInfoResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'dataBreakpointInfo' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "dataId": { + "type": [ "string", "null" ], + "description": "An identifier for the data on which a data breakpoint can be registered with the setDataBreakpoints request or null if no data breakpoint is available." + }, + "description": { + "type": "string", + "description": "UI string that describes on what data the breakpoint is set on or why a data breakpoint is not available." + }, + "accessTypes": { + "type": "array", + "items": { + "$ref": "#/definitions/DataBreakpointAccessType" + }, + "description": "Optional attribute listing the available access types for a potential data breakpoint. A UI frontend could surface this information." + }, + "canPersist": { + "type": "boolean", + "description": "Optional attribute indicating that a potential data breakpoint could be persisted across sessions." + } + }, + "required": [ "dataId", "description" ] + } + }, + "required": [ "body" ] + }] + }, + + "SetDataBreakpointsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Replaces all existing data breakpoints with new data breakpoints.\nTo clear all data breakpoints, specify an empty array.\nWhen a data breakpoint is hit, a 'stopped' event (with reason 'data breakpoint') is generated.", + "properties": { + "command": { + "type": "string", + "enum": [ "setDataBreakpoints" ] + }, + "arguments": { + "$ref": "#/definitions/SetDataBreakpointsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetDataBreakpointsArguments": { + "type": "object", + "description": "Arguments for 'setDataBreakpoints' request.", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/DataBreakpoint" + }, + "description": "The contents of this array replaces all existing data breakpoints. An empty array clears all data breakpoints." + } + }, + "required": [ "breakpoints" ] + }, + "SetDataBreakpointsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setDataBreakpoints' request.\nReturned is information about each breakpoint created by this request.", + "properties": { + "body": { + "type": "object", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the data breakpoints. The array elements correspond to the elements of the input argument 'breakpoints' array." + } + }, + "required": [ "breakpoints" ] + } + }, + "required": [ "body" ] + }] + }, + + "ContinueRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request starts the debuggee to run again.", + "properties": { + "command": { + "type": "string", + "enum": [ "continue" ] + }, + "arguments": { + "$ref": "#/definitions/ContinueArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "ContinueArguments": { + "type": "object", + "description": "Arguments for 'continue' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Continue execution for the specified thread (if possible). If the backend cannot continue on a single thread but will continue on all threads, it should set the 'allThreadsContinued' attribute in the response to true." + } + }, + "required": [ "threadId" ] + }, + "ContinueResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'continue' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "allThreadsContinued": { + "type": "boolean", + "description": "If true, the 'continue' request has ignored the specified thread and continued all threads instead. If this attribute is missing a value of 'true' is assumed for backward compatibility." + } + } + } + }, + "required": [ "body" ] + }] + }, + + "NextRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request starts the debuggee to run again for one step.\nThe debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the step has completed.", + "properties": { + "command": { + "type": "string", + "enum": [ "next" ] + }, + "arguments": { + "$ref": "#/definitions/NextArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "NextArguments": { + "type": "object", + "description": "Arguments for 'next' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Execute 'next' for this thread." + } + }, + "required": [ "threadId" ] + }, + "NextResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'next' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "StepInRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request starts the debuggee to step into a function/method if possible.\nIf it cannot step into a target, 'stepIn' behaves like 'next'.\nThe debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the step has completed.\nIf there are multiple function/method calls (or other targets) on the source line,\nthe optional argument 'targetId' can be used to control into which target the 'stepIn' should occur.\nThe list of possible targets for a given source line can be retrieved via the 'stepInTargets' request.", + "properties": { + "command": { + "type": "string", + "enum": [ "stepIn" ] + }, + "arguments": { + "$ref": "#/definitions/StepInArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "StepInArguments": { + "type": "object", + "description": "Arguments for 'stepIn' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Execute 'stepIn' for this thread." + }, + "targetId": { + "type": "integer", + "description": "Optional id of the target to step into." + } + }, + "required": [ "threadId" ] + }, + "StepInResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'stepIn' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "StepOutRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request starts the debuggee to run again for one step.\nThe debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the step has completed.", + "properties": { + "command": { + "type": "string", + "enum": [ "stepOut" ] + }, + "arguments": { + "$ref": "#/definitions/StepOutArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "StepOutArguments": { + "type": "object", + "description": "Arguments for 'stepOut' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Execute 'stepOut' for this thread." + } + }, + "required": [ "threadId" ] + }, + "StepOutResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'stepOut' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "StepBackRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request starts the debuggee to run one step backwards.\nThe debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the step has completed. Clients should only call this request if the capability 'supportsStepBack' is true.", + "properties": { + "command": { + "type": "string", + "enum": [ "stepBack" ] + }, + "arguments": { + "$ref": "#/definitions/StepBackArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "StepBackArguments": { + "type": "object", + "description": "Arguments for 'stepBack' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Execute 'stepBack' for this thread." + } + }, + "required": [ "threadId" ] + }, + "StepBackResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'stepBack' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "ReverseContinueRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request starts the debuggee to run backward. Clients should only call this request if the capability 'supportsStepBack' is true.", + "properties": { + "command": { + "type": "string", + "enum": [ "reverseContinue" ] + }, + "arguments": { + "$ref": "#/definitions/ReverseContinueArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "ReverseContinueArguments": { + "type": "object", + "description": "Arguments for 'reverseContinue' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Execute 'reverseContinue' for this thread." + } + }, + "required": [ "threadId" ] + }, + "ReverseContinueResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'reverseContinue' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "RestartFrameRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request restarts execution of the specified stackframe.\nThe debug adapter first sends the response and then a 'stopped' event (with reason 'restart') after the restart has completed.", + "properties": { + "command": { + "type": "string", + "enum": [ "restartFrame" ] + }, + "arguments": { + "$ref": "#/definitions/RestartFrameArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "RestartFrameArguments": { + "type": "object", + "description": "Arguments for 'restartFrame' request.", + "properties": { + "frameId": { + "type": "integer", + "description": "Restart this stackframe." + } + }, + "required": [ "frameId" ] + }, + "RestartFrameResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'restartFrame' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "GotoRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request sets the location where the debuggee will continue to run.\nThis makes it possible to skip the execution of code or to executed code again.\nThe code between the current location and the goto target is not executed but skipped.\nThe debug adapter first sends the response and then a 'stopped' event with reason 'goto'.", + "properties": { + "command": { + "type": "string", + "enum": [ "goto" ] + }, + "arguments": { + "$ref": "#/definitions/GotoArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "GotoArguments": { + "type": "object", + "description": "Arguments for 'goto' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Set the goto target for this thread." + }, + "targetId": { + "type": "integer", + "description": "The location where the debuggee will continue to run." + } + }, + "required": [ "threadId", "targetId" ] + }, + "GotoResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'goto' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "PauseRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request suspenses the debuggee.\nThe debug adapter first sends the response and then a 'stopped' event (with reason 'pause') after the thread has been paused successfully.", + "properties": { + "command": { + "type": "string", + "enum": [ "pause" ] + }, + "arguments": { + "$ref": "#/definitions/PauseArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "PauseArguments": { + "type": "object", + "description": "Arguments for 'pause' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Pause execution for this thread." + } + }, + "required": [ "threadId" ] + }, + "PauseResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'pause' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "StackTraceRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request returns a stacktrace from the current execution state.", + "properties": { + "command": { + "type": "string", + "enum": [ "stackTrace" ] + }, + "arguments": { + "$ref": "#/definitions/StackTraceArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "StackTraceArguments": { + "type": "object", + "description": "Arguments for 'stackTrace' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Retrieve the stacktrace for this thread." + }, + "startFrame": { + "type": "integer", + "description": "The index of the first frame to return; if omitted frames start at 0." + }, + "levels": { + "type": "integer", + "description": "The maximum number of frames to return. If levels is not specified or 0, all frames are returned." + }, + "format": { + "$ref": "#/definitions/StackFrameFormat", + "description": "Specifies details on how to format the stack frames." + } + }, + "required": [ "threadId" ] + }, + "StackTraceResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'stackTrace' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "stackFrames": { + "type": "array", + "items": { + "$ref": "#/definitions/StackFrame" + }, + "description": "The frames of the stackframe. If the array has length zero, there are no stackframes available.\nThis means that there is no location information available." + }, + "totalFrames": { + "type": "integer", + "description": "The total number of frames available." + } + }, + "required": [ "stackFrames" ] + } + }, + "required": [ "body" ] + }] + }, + + "ScopesRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request returns the variable scopes for a given stackframe ID.", + "properties": { + "command": { + "type": "string", + "enum": [ "scopes" ] + }, + "arguments": { + "$ref": "#/definitions/ScopesArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "ScopesArguments": { + "type": "object", + "description": "Arguments for 'scopes' request.", + "properties": { + "frameId": { + "type": "integer", + "description": "Retrieve the scopes for this stackframe." + } + }, + "required": [ "frameId" ] + }, + "ScopesResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'scopes' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "scopes": { + "type": "array", + "items": { + "$ref": "#/definitions/Scope" + }, + "description": "The scopes of the stackframe. If the array has length zero, there are no scopes available." + } + }, + "required": [ "scopes" ] + } + }, + "required": [ "body" ] + }] + }, + + "VariablesRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Retrieves all child variables for the given variable reference.\nAn optional filter can be used to limit the fetched children to either named or indexed children.", + "properties": { + "command": { + "type": "string", + "enum": [ "variables" ] + }, + "arguments": { + "$ref": "#/definitions/VariablesArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "VariablesArguments": { + "type": "object", + "description": "Arguments for 'variables' request.", + "properties": { + "variablesReference": { + "type": "integer", + "description": "The Variable reference." + }, + "filter": { + "type": "string", + "enum": [ "indexed", "named" ], + "description": "Optional filter to limit the child variables to either named or indexed. If ommited, both types are fetched." + }, + "start": { + "type": "integer", + "description": "The index of the first variable to return; if omitted children start at 0." + }, + "count": { + "type": "integer", + "description": "The number of variables to return. If count is missing or 0, all variables are returned." + }, + "format": { + "$ref": "#/definitions/ValueFormat", + "description": "Specifies details on how to format the Variable values." + } + }, + "required": [ "variablesReference" ] + }, + "VariablesResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'variables' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "variables": { + "type": "array", + "items": { + "$ref": "#/definitions/Variable" + }, + "description": "All (or a range) of variables for the given variable reference." + } + }, + "required": [ "variables" ] + } + }, + "required": [ "body" ] + }] + }, + + "SetVariableRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Set the variable with the given name in the variable container to a new value.", + "properties": { + "command": { + "type": "string", + "enum": [ "setVariable" ] + }, + "arguments": { + "$ref": "#/definitions/SetVariableArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetVariableArguments": { + "type": "object", + "description": "Arguments for 'setVariable' request.", + "properties": { + "variablesReference": { + "type": "integer", + "description": "The reference of the variable container." + }, + "name": { + "type": "string", + "description": "The name of the variable in the container." + }, + "value": { + "type": "string", + "description": "The value of the variable." + }, + "format": { + "$ref": "#/definitions/ValueFormat", + "description": "Specifies details on how to format the response value." + } + }, + "required": [ "variablesReference", "name", "value" ] + }, + "SetVariableResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setVariable' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "value": { + "type": "string", + "description": "The new value of the variable." + }, + "type": { + "type": "string", + "description": "The type of the new value. Typically shown in the UI when hovering over the value." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the new value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + } + }, + "required": [ "value" ] + } + }, + "required": [ "body" ] + }] + }, + + "SourceRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request retrieves the source code for a given source reference.", + "properties": { + "command": { + "type": "string", + "enum": [ "source" ] + }, + "arguments": { + "$ref": "#/definitions/SourceArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SourceArguments": { + "type": "object", + "description": "Arguments for 'source' request.", + "properties": { + "source": { + "$ref": "#/definitions/Source", + "description": "Specifies the source content to load. Either source.path or source.sourceReference must be specified." + }, + "sourceReference": { + "type": "integer", + "description": "The reference to the source. This is the same as source.sourceReference. This is provided for backward compatibility since old backends do not understand the 'source' attribute." + } + }, + "required": [ "sourceReference" ] + }, + "SourceResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'source' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "content": { + "type": "string", + "description": "Content of the source reference." + }, + "mimeType": { + "type": "string", + "description": "Optional content type (mime type) of the source." + } + }, + "required": [ "content" ] + } + }, + "required": [ "body" ] + }] + }, + + "ThreadsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request retrieves a list of all threads.", + "properties": { + "command": { + "type": "string", + "enum": [ "threads" ] + } + }, + "required": [ "command" ] + }] + }, + "ThreadsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'threads' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "threads": { + "type": "array", + "items": { + "$ref": "#/definitions/Thread" + }, + "description": "All threads." + } + }, + "required": [ "threads" ] + } + }, + "required": [ "body" ] + }] + }, + + "TerminateThreadsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request terminates the threads with the given ids.", + "properties": { + "command": { + "type": "string", + "enum": [ "terminateThreads" ] + }, + "arguments": { + "$ref": "#/definitions/TerminateThreadsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "TerminateThreadsArguments": { + "type": "object", + "description": "Arguments for 'terminateThreads' request.", + "properties": { + "threadIds": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "Ids of threads to be terminated." + } + } + }, + "TerminateThreadsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'terminateThreads' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "ModulesRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Modules can be retrieved from the debug adapter with the ModulesRequest which can either return all modules or a range of modules to support paging.", + "properties": { + "command": { + "type": "string", + "enum": [ "modules" ] + }, + "arguments": { + "$ref": "#/definitions/ModulesArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "ModulesArguments": { + "type": "object", + "description": "Arguments for 'modules' request.", + "properties": { + "startModule": { + "type": "integer", + "description": "The index of the first module to return; if omitted modules start at 0." + }, + "moduleCount": { + "type": "integer", + "description": "The number of modules to return. If moduleCount is not specified or 0, all modules are returned." + } + } + }, + "ModulesResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'modules' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "modules": { + "type": "array", + "items": { + "$ref": "#/definitions/Module" + }, + "description": "All modules or range of modules." + }, + "totalModules": { + "type": "integer", + "description": "The total number of modules available." + } + }, + "required": [ "modules" ] + } + }, + "required": [ "body" ] + }] + }, + + "LoadedSourcesRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Retrieves the set of all sources currently loaded by the debugged process.", + "properties": { + "command": { + "type": "string", + "enum": [ "loadedSources" ] + }, + "arguments": { + "$ref": "#/definitions/LoadedSourcesArguments" + } + }, + "required": [ "command" ] + }] + }, + "LoadedSourcesArguments": { + "type": "object", + "description": "Arguments for 'loadedSources' request." + }, + "LoadedSourcesResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'loadedSources' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "sources": { + "type": "array", + "items": { + "$ref": "#/definitions/Source" + }, + "description": "Set of loaded sources." + } + }, + "required": [ "sources" ] + } + }, + "required": [ "body" ] + }] + }, + + "EvaluateRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Evaluates the given expression in the context of the top most stack frame.\nThe expression has access to any variables and arguments that are in scope.", + "properties": { + "command": { + "type": "string", + "enum": [ "evaluate" ] + }, + "arguments": { + "$ref": "#/definitions/EvaluateArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "EvaluateArguments": { + "type": "object", + "description": "Arguments for 'evaluate' request.", + "properties": { + "expression": { + "type": "string", + "description": "The expression to evaluate." + }, + "frameId": { + "type": "integer", + "description": "Evaluate the expression in the scope of this stack frame. If not specified, the expression is evaluated in the global scope." + }, + "context": { + "type": "string", + "_enum": [ "watch", "repl", "hover" ], + "enumDescriptions": [ + "evaluate is run in a watch.", + "evaluate is run from REPL console.", + "evaluate is run from a data hover." + ], + "description": "The context in which the evaluate request is run." + }, + "format": { + "$ref": "#/definitions/ValueFormat", + "description": "Specifies details on how to format the Evaluate result." + } + }, + "required": [ "expression" ] + }, + "EvaluateResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'evaluate' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "result": { + "type": "string", + "description": "The result of the evaluate request." + }, + "type": { + "type": "string", + "description": "The optional type of the evaluate result." + }, + "presentationHint": { + "$ref": "#/definitions/VariablePresentationHint", + "description": "Properties of a evaluate result that can be used to determine how to render the result in the UI." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the evaluate result is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "memoryReference": { + "type": "string", + "description": "Memory reference to a location appropriate for this result. For pointer type eval results, this is generally a reference to the memory address contained in the pointer." + } + }, + "required": [ "result", "variablesReference" ] + } + }, + "required": [ "body" ] + }] + }, + + "SetExpressionRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Evaluates the given 'value' expression and assigns it to the 'expression' which must be a modifiable l-value.\nThe expressions have access to any variables and arguments that are in scope of the specified frame.", + "properties": { + "command": { + "type": "string", + "enum": [ "setExpression" ] + }, + "arguments": { + "$ref": "#/definitions/SetExpressionArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetExpressionArguments": { + "type": "object", + "description": "Arguments for 'setExpression' request.", + "properties": { + "expression": { + "type": "string", + "description": "The l-value expression to assign to." + }, + "value": { + "type": "string", + "description": "The value expression to assign to the l-value expression." + }, + "frameId": { + "type": "integer", + "description": "Evaluate the expressions in the scope of this stack frame. If not specified, the expressions are evaluated in the global scope." + }, + "format": { + "$ref": "#/definitions/ValueFormat", + "description": "Specifies how the resulting value should be formatted." + } + }, + "required": [ "expression", "value" ] + }, + "SetExpressionResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setExpression' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "value": { + "type": "string", + "description": "The new value of the expression." + }, + "type": { + "type": "string", + "description": "The optional type of the value." + }, + "presentationHint": { + "$ref": "#/definitions/VariablePresentationHint", + "description": "Properties of a value that can be used to determine how to render the result in the UI." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + } + }, + "required": [ "value" ] + } + }, + "required": [ "body" ] + }] + }, + + "StepInTargetsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "This request retrieves the possible stepIn targets for the specified stack frame.\nThese targets can be used in the 'stepIn' request.\nThe StepInTargets may only be called if the 'supportsStepInTargetsRequest' capability exists and is true.", + "properties": { + "command": { + "type": "string", + "enum": [ "stepInTargets" ] + }, + "arguments": { + "$ref": "#/definitions/StepInTargetsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "StepInTargetsArguments": { + "type": "object", + "description": "Arguments for 'stepInTargets' request.", + "properties": { + "frameId": { + "type": "integer", + "description": "The stack frame for which to retrieve the possible stepIn targets." + } + }, + "required": [ "frameId" ] + }, + "StepInTargetsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'stepInTargets' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/StepInTarget" + }, + "description": "The possible stepIn targets of the specified source location." + } + }, + "required": [ "targets" ] + } + }, + "required": [ "body" ] + }] + }, + + "GotoTargetsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "This request retrieves the possible goto targets for the specified source location.\nThese targets can be used in the 'goto' request.\nThe GotoTargets request may only be called if the 'supportsGotoTargetsRequest' capability exists and is true.", + "properties": { + "command": { + "type": "string", + "enum": [ "gotoTargets" ] + }, + "arguments": { + "$ref": "#/definitions/GotoTargetsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "GotoTargetsArguments": { + "type": "object", + "description": "Arguments for 'gotoTargets' request.", + "properties": { + "source": { + "$ref": "#/definitions/Source", + "description": "The source location for which the goto targets are determined." + }, + "line": { + "type": "integer", + "description": "The line location for which the goto targets are determined." + }, + "column": { + "type": "integer", + "description": "An optional column location for which the goto targets are determined." + } + }, + "required": [ "source", "line" ] + }, + "GotoTargetsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'gotoTargets' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/GotoTarget" + }, + "description": "The possible goto targets of the specified location." + } + }, + "required": [ "targets" ] + } + }, + "required": [ "body" ] + }] + }, + + "CompletionsRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Returns a list of possible completions for a given caret position and text.\nThe CompletionsRequest may only be called if the 'supportsCompletionsRequest' capability exists and is true.", + "properties": { + "command": { + "type": "string", + "enum": [ "completions" ] + }, + "arguments": { + "$ref": "#/definitions/CompletionsArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "CompletionsArguments": { + "type": "object", + "description": "Arguments for 'completions' request.", + "properties": { + "frameId": { + "type": "integer", + "description": "Returns completions in the scope of this stack frame. If not specified, the completions are returned for the global scope." + }, + "text": { + "type": "string", + "description": "One or more source lines. Typically this is the text a user has typed into the debug console before he asked for completion." + }, + "column": { + "type": "integer", + "description": "The character position for which to determine the completion proposals." + }, + "line": { + "type": "integer", + "description": "An optional line for which to determine the completion proposals. If missing the first line of the text is assumed." + } + }, + "required": [ "text", "column" ] + }, + "CompletionsResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'completions' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/CompletionItem" + }, + "description": "The possible completions for ." + } + }, + "required": [ "targets" ] + } + }, + "required": [ "body" ] + }] + }, + + "ExceptionInfoRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Retrieves the details of the exception that caused this event to be raised.", + "properties": { + "command": { + "type": "string", + "enum": [ "exceptionInfo" ] + }, + "arguments": { + "$ref": "#/definitions/ExceptionInfoArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "ExceptionInfoArguments": { + "type": "object", + "description": "Arguments for 'exceptionInfo' request.", + "properties": { + "threadId": { + "type": "integer", + "description": "Thread for which exception information should be retrieved." + } + }, + "required": [ "threadId" ] + }, + "ExceptionInfoResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'exceptionInfo' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "exceptionId": { + "type": "string", + "description": "ID of the exception that was thrown." + }, + "description": { + "type": "string", + "description": "Descriptive text for the exception provided by the debug adapter." + }, + "breakMode": { + "$ref": "#/definitions/ExceptionBreakMode", + "description": "Mode that caused the exception notification to be raised." + }, + "details": { + "$ref": "#/definitions/ExceptionDetails", + "description": "Detailed information about the exception." + } + }, + "required": [ "exceptionId", "breakMode" ] + } + }, + "required": [ "body" ] + }] + }, + + "ReadMemoryRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Reads bytes from memory at the provided location.", + "properties": { + "command": { + "type": "string", + "enum": [ "readMemory" ] + }, + "arguments": { + "$ref": "#/definitions/ReadMemoryArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "ReadMemoryArguments": { + "type": "object", + "description": "Arguments for 'readMemory' request.", + "properties": { + "memoryReference": { + "type": "string", + "description": "Memory reference to the base location from which data should be read." + }, + "offset": { + "type": "integer", + "description": "Optional offset (in bytes) to be applied to the reference location before reading data. Can be negative." + }, + "count": { + "type": "integer", + "description": "Number of bytes to read at the specified location and offset." + } + }, + "required": [ "memoryReference", "count" ] + }, + "ReadMemoryResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'readMemory' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "address": { + "type": "string", + "description": "The address of the first byte of data returned. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise." + }, + "unreadableBytes": { + "type": "integer", + "description": "The number of unreadable bytes encountered after the last successfully read byte. This can be used to determine the number of bytes that must be skipped before a subsequent 'readMemory' request will succeed." + }, + "data": { + "type": "string", + "description": "The bytes read from memory, encoded using base64." + } + }, + "required": [ "address" ] + } + } + }] + }, + + "DisassembleRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "Disassembles code stored at the provided location.", + "properties": { + "command": { + "type": "string", + "enum": [ "disassemble" ] + }, + "arguments": { + "$ref": "#/definitions/DisassembleArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "DisassembleArguments": { + "type": "object", + "description": "Arguments for 'disassemble' request.", + "properties": { + "memoryReference": { + "type": "string", + "description": "Memory reference to the base location containing the instructions to disassemble." + }, + "offset": { + "type": "integer", + "description": "Optional offset (in bytes) to be applied to the reference location before disassembling. Can be negative." + }, + "instructionOffset": { + "type": "integer", + "description": "Optional offset (in instructions) to be applied after the byte offset (if any) before disassembling. Can be negative." + }, + "instructionCount": { + "type": "integer", + "description": "Number of instructions to disassemble starting at the specified location and offset. An adapter must return exactly this number of instructions - any unavailable instructions should be replaced with an implementation-defined 'invalid instruction' value." + }, + "resolveSymbols": { + "type": "boolean", + "description": "If true, the adapter should attempt to resolve memory addresses and other values to symbolic names." + } + }, + "required": [ "memoryReference", "instructionCount" ] + }, + "DisassembleResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'disassemble' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "instructions": { + "type": "array", + "items": { + "$ref": "#/definitions/DisassembledInstruction" + }, + "description": "The list of disassembled instructions." + } + }, + "required": [ "instructions" ] + } + } + }] + }, + + "Capabilities": { + "type": "object", + "title": "Types", + "description": "Information about the capabilities of a debug adapter.", + "properties": { + "supportsConfigurationDoneRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'configurationDone' request." + }, + "supportsFunctionBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports function breakpoints." + }, + "supportsConditionalBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports conditional breakpoints." + }, + "supportsHitConditionalBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports breakpoints that break execution after a specified number of hits." + }, + "supportsEvaluateForHovers": { + "type": "boolean", + "description": "The debug adapter supports a (side effect free) evaluate request for data hovers." + }, + "exceptionBreakpointFilters": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionBreakpointsFilter" + }, + "description": "Available filters or options for the setExceptionBreakpoints request." + }, + "supportsStepBack": { + "type": "boolean", + "description": "The debug adapter supports stepping back via the 'stepBack' and 'reverseContinue' requests." + }, + "supportsSetVariable": { + "type": "boolean", + "description": "The debug adapter supports setting a variable to a value." + }, + "supportsRestartFrame": { + "type": "boolean", + "description": "The debug adapter supports restarting a frame." + }, + "supportsGotoTargetsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'gotoTargets' request." + }, + "supportsStepInTargetsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'stepInTargets' request." + }, + "supportsCompletionsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'completions' request." + }, + "supportsModulesRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'modules' request." + }, + "additionalModuleColumns": { + "type": "array", + "items": { + "$ref": "#/definitions/ColumnDescriptor" + }, + "description": "The set of additional module information exposed by the debug adapter." + }, + "supportedChecksumAlgorithms": { + "type": "array", + "items": { + "$ref": "#/definitions/ChecksumAlgorithm" + }, + "description": "Checksum algorithms supported by the debug adapter." + }, + "supportsRestartRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'restart' request. In this case a client should not implement 'restart' by terminating and relaunching the adapter but by calling the RestartRequest." + }, + "supportsExceptionOptions": { + "type": "boolean", + "description": "The debug adapter supports 'exceptionOptions' on the setExceptionBreakpoints request." + }, + "supportsValueFormattingOptions": { + "type": "boolean", + "description": "The debug adapter supports a 'format' attribute on the stackTraceRequest, variablesRequest, and evaluateRequest." + }, + "supportsExceptionInfoRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'exceptionInfo' request." + }, + "supportTerminateDebuggee": { + "type": "boolean", + "description": "The debug adapter supports the 'terminateDebuggee' attribute on the 'disconnect' request." + }, + "supportsDelayedStackTraceLoading": { + "type": "boolean", + "description": "The debug adapter supports the delayed loading of parts of the stack, which requires that both the 'startFrame' and 'levels' arguments and the 'totalFrames' result of the 'StackTrace' request are supported." + }, + "supportsLoadedSourcesRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'loadedSources' request." + }, + "supportsLogPoints": { + "type": "boolean", + "description": "The debug adapter supports logpoints by interpreting the 'logMessage' attribute of the SourceBreakpoint." + }, + "supportsTerminateThreadsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'terminateThreads' request." + }, + "supportsSetExpression": { + "type": "boolean", + "description": "The debug adapter supports the 'setExpression' request." + }, + "supportsTerminateRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'terminate' request." + }, + "supportsDataBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports data breakpoints." + }, + "supportsReadMemoryRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'readMemory' request." + }, + "supportsDisassembleRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'disassemble' request." + } + } + }, + + "ExceptionBreakpointsFilter": { + "type": "object", + "description": "An ExceptionBreakpointsFilter is shown in the UI as an option for configuring how exceptions are dealt with.", + "properties": { + "filter": { + "type": "string", + "description": "The internal ID of the filter. This value is passed to the setExceptionBreakpoints request." + }, + "label": { + "type": "string", + "description": "The name of the filter. This will be shown in the UI." + }, + "default": { + "type": "boolean", + "description": "Initial value of the filter. If not specified a value 'false' is assumed." + } + }, + "required": [ "filter", "label" ] + }, + + "Message": { + "type": "object", + "description": "A structured message object. Used to return errors from requests.", + "properties": { + "id": { + "type": "integer", + "description": "Unique identifier for the message." + }, + "format": { + "type": "string", + "description": "A format string for the message. Embedded variables have the form '{name}'.\nIf variable name starts with an underscore character, the variable does not contain user data (PII) and can be safely used for telemetry purposes." + }, + "variables": { + "type": "object", + "description": "An object used as a dictionary for looking up the variables in the format string.", + "additionalProperties": { + "type": "string", + "description": "Values must be strings." + } + }, + "sendTelemetry": { + "type": "boolean", + "description": "If true send to telemetry." + }, + "showUser": { + "type": "boolean", + "description": "If true show user." + }, + "url": { + "type": "string", + "description": "An optional url where additional information about this message can be found." + }, + "urlLabel": { + "type": "string", + "description": "An optional label that is presented to the user as the UI for opening the url." + } + }, + "required": [ "id", "format" ] + }, + + "Module": { + "type": "object", + "description": "A Module object represents a row in the modules view.\nTwo attributes are mandatory: an id identifies a module in the modules view and is used in a ModuleEvent for identifying a module for adding, updating or deleting.\nThe name is used to minimally render the module in the UI.\n\nAdditional attributes can be added to the module. They will show up in the module View if they have a corresponding ColumnDescriptor.\n\nTo avoid an unnecessary proliferation of additional attributes with similar semantics but different names\nwe recommend to re-use attributes from the 'recommended' list below first, and only introduce new attributes if nothing appropriate could be found.", + "properties": { + "id": { + "type": ["integer", "string"], + "description": "Unique identifier for the module." + }, + "name": { + "type": "string", + "description": "A name of the module." + }, + "path": { + "type": "string", + "description": "optional but recommended attributes.\nalways try to use these first before introducing additional attributes.\n\nLogical full path to the module. The exact definition is implementation defined, but usually this would be a full path to the on-disk file for the module." + }, + "isOptimized": { + "type": "boolean", + "description": "True if the module is optimized." + }, + "isUserCode": { + "type": "boolean", + "description": "True if the module is considered 'user code' by a debugger that supports 'Just My Code'." + }, + "version": { + "type": "string", + "description": "Version of Module." + }, + "symbolStatus": { + "type": "string", + "description": "User understandable description of if symbols were found for the module (ex: 'Symbols Loaded', 'Symbols not found', etc." + }, + "symbolFilePath": { + "type": "string", + "description": "Logical full path to the symbol file. The exact definition is implementation defined." + }, + "dateTimeStamp": { + "type": "string", + "description": "Module created or modified." + }, + "addressRange": { + "type": "string", + "description": "Address range covered by this module." + } + }, + "required": [ "id", "name" ] + }, + + "ColumnDescriptor": { + "type": "object", + "description": "A ColumnDescriptor specifies what module attribute to show in a column of the ModulesView, how to format it, and what the column's label should be.\nIt is only used if the underlying UI actually supports this level of customization.", + "properties": { + "attributeName": { + "type": "string", + "description": "Name of the attribute rendered in this column." + }, + "label": { + "type": "string", + "description": "Header UI label of column." + }, + "format": { + "type": "string", + "description": "Format to use for the rendered values in this column. TBD how the format strings looks like." + }, + "type": { + "type": "string", + "enum": [ "string", "number", "boolean", "unixTimestampUTC" ], + "description": "Datatype of values in this column. Defaults to 'string' if not specified." + }, + "width": { + "type": "integer", + "description": "Width of this column in characters (hint only)." + } + }, + "required": [ "attributeName", "label"] + }, + + "ModulesViewDescriptor": { + "type": "object", + "description": "The ModulesViewDescriptor is the container for all declarative configuration options of a ModuleView.\nFor now it only specifies the columns to be shown in the modules view.", + "properties": { + "columns": { + "type": "array", + "items": { + "$ref": "#/definitions/ColumnDescriptor" + } + } + }, + "required": [ "columns" ] + }, + + "Thread": { + "type": "object", + "description": "A Thread", + "properties": { + "id": { + "type": "integer", + "description": "Unique identifier for the thread." + }, + "name": { + "type": "string", + "description": "A name of the thread." + } + }, + "required": [ "id", "name" ] + }, + + "Source": { + "type": "object", + "description": "A Source is a descriptor for source code. It is returned from the debug adapter as part of a StackFrame and it is used by clients when specifying breakpoints.", + "properties": { + "name": { + "type": "string", + "description": "The short name of the source. Every source returned from the debug adapter has a name. When sending a source to the debug adapter this name is optional." + }, + "path": { + "type": "string", + "description": "The path of the source to be shown in the UI. It is only used to locate and load the content of the source if no sourceReference is specified (or its value is 0)." + }, + "sourceReference": { + "type": "number", + "description": "If sourceReference > 0 the contents of the source must be retrieved through the SourceRequest (even if a path is specified). A sourceReference is only valid for a session, so it must not be used to persist a source." + }, + "presentationHint": { + "type": "string", + "description": "An optional hint for how to present the source in the UI. A value of 'deemphasize' can be used to indicate that the source is not available or that it is skipped on stepping.", + "enum": [ "normal", "emphasize", "deemphasize" ] + }, + "origin": { + "type": "string", + "description": "The (optional) origin of this source: possible values 'internal module', 'inlined content from source map', etc." + }, + "sources": { + "type": "array", + "items": { + "$ref": "#/definitions/Source" + }, + "description": "An optional list of sources that are related to this source. These may be the source that generated this source." + }, + "adapterData": { + "type": [ "array", "boolean", "integer", "null", "number", "object", "string" ], + "description": "Optional data that a debug adapter might want to loop through the client. The client should leave the data intact and persist it across sessions. The client should not interpret the data." + }, + "checksums": { + "type": "array", + "items": { + "$ref": "#/definitions/Checksum" + }, + "description": "The checksums associated with this file." + } + } + }, + + "StackFrame": { + "type": "object", + "description": "A Stackframe contains the source location.", + "properties": { + "id": { + "type": "integer", + "description": "An identifier for the stack frame. It must be unique across all threads. This id can be used to retrieve the scopes of the frame with the 'scopesRequest' or to restart the execution of a stackframe." + }, + "name": { + "type": "string", + "description": "The name of the stack frame, typically a method name." + }, + "source": { + "$ref": "#/definitions/Source", + "description": "The optional source of the frame." + }, + "line": { + "type": "integer", + "description": "The line within the file of the frame. If source is null or doesn't exist, line is 0 and must be ignored." + }, + "column": { + "type": "integer", + "description": "The column within the line. If source is null or doesn't exist, column is 0 and must be ignored." + }, + "endLine": { + "type": "integer", + "description": "An optional end line of the range covered by the stack frame." + }, + "endColumn": { + "type": "integer", + "description": "An optional end column of the range covered by the stack frame." + }, + "instructionPointerReference": { + "type": "string", + "description": "Optional memory reference for the current instruction pointer in this frame." + }, + "moduleId": { + "type": ["integer", "string"], + "description": "The module associated with this frame, if any." + }, + "presentationHint": { + "type": "string", + "enum": [ "normal", "label", "subtle" ], + "description": "An optional hint for how to present this frame in the UI. A value of 'label' can be used to indicate that the frame is an artificial frame that is used as a visual label or separator. A value of 'subtle' can be used to change the appearance of a frame in a 'subtle' way." + } + }, + "required": [ "id", "name", "line", "column" ] + }, + + "Scope": { + "type": "object", + "description": "A Scope is a named container for variables. Optionally a scope can map to a source or a range within a source.", + "properties": { + "name": { + "type": "string", + "description": "Name of the scope such as 'Arguments', 'Locals', or 'Registers'. This string is shown in the UI as is and can be translated." + }, + "presentationHint": { + "type": "string", + "description": "An optional hint for how to present this scope in the UI. If this attribute is missing, the scope is shown with a generic UI.", + "_enum": [ "arguments", "locals", "registers" ], + "enumDescriptions": [ + "Scope contains method arguments.", + "Scope contains local variables.", + "Scope contains registers. Only a single 'registers' scope should be returned from a 'scopes' request." + ] + }, + "variablesReference": { + "type": "integer", + "description": "The variables of this scope can be retrieved by passing the value of variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "integer", + "description": "The number of named variables in this scope.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "integer", + "description": "The number of indexed variables in this scope.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "expensive": { + "type": "boolean", + "description": "If true, the number of variables in this scope is large or expensive to retrieve." + }, + "source": { + "$ref": "#/definitions/Source", + "description": "Optional source for this scope." + }, + "line": { + "type": "integer", + "description": "Optional start line of the range covered by this scope." + }, + "column": { + "type": "integer", + "description": "Optional start column of the range covered by this scope." + }, + "endLine": { + "type": "integer", + "description": "Optional end line of the range covered by this scope." + }, + "endColumn": { + "type": "integer", + "description": "Optional end column of the range covered by this scope." + } + }, + "required": [ "name", "variablesReference", "expensive" ] + }, + + "Variable": { + "type": "object", + "description": "A Variable is a name/value pair.\nOptionally a variable can have a 'type' that is shown if space permits or when hovering over the variable's name.\nAn optional 'kind' is used to render additional properties of the variable, e.g. different icons can be used to indicate that a variable is public or private.\nIf the value is structured (has children), a handle is provided to retrieve the children with the VariablesRequest.\nIf the number of named or indexed children is large, the numbers should be returned via the optional 'namedVariables' and 'indexedVariables' attributes.\nThe client can use this optional information to present the children in a paged UI and fetch them in chunks.", + "properties": { + "name": { + "type": "string", + "description": "The variable's name." + }, + "value": { + "type": "string", + "description": "The variable's value. This can be a multi-line text, e.g. for a function the body of a function." + }, + "type": { + "type": "string", + "description": "The type of the variable's value. Typically shown in the UI when hovering over the value." + }, + "presentationHint": { + "$ref": "#/definitions/VariablePresentationHint", + "description": "Properties of a variable that can be used to determine how to render the variable in the UI." + }, + "evaluateName": { + "type": "string", + "description": "Optional evaluatable name of this variable which can be passed to the 'EvaluateRequest' to fetch the variable's value." + }, + "variablesReference": { + "type": "integer", + "description": "If variablesReference is > 0, the variable is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "integer", + "description": "The number of named child variables.\nThe client can use this optional information to present the children in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "integer", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the children in a paged UI and fetch them in chunks." + }, + "memoryReference": { + "type": "string", + "description": "Optional memory reference for the variable if the variable represents executable code, such as a function pointer." + } + }, + "required": [ "name", "value", "variablesReference" ] + }, + + "VariablePresentationHint": { + "type": "object", + "description": "Optional properties of a variable that can be used to determine how to render the variable in the UI.", + "properties": { + "kind": { + "description": "The kind of variable. Before introducing additional values, try to use the listed values.", + "type": "string", + "_enum": [ "property", "method", "class", "data", "event", "baseClass", "innerClass", "interface", "mostDerivedClass", "virtual", "dataBreakpoint" ], + "enumDescriptions": [ + "Indicates that the object is a property.", + "Indicates that the object is a method.", + "Indicates that the object is a class.", + "Indicates that the object is data.", + "Indicates that the object is an event.", + "Indicates that the object is a base class.", + "Indicates that the object is an inner class.", + "Indicates that the object is an interface.", + "Indicates that the object is the most derived class.", + "Indicates that the object is virtual, that means it is a synthetic object introduced by the adapter for rendering purposes, e.g. an index range for large arrays.", + "Indicates that a data breakpoint is registered for the object." + ] + }, + "attributes": { + "description": "Set of attributes represented as an array of strings. Before introducing additional values, try to use the listed values.", + "type": "array", + "items": { + "type": "string", + "_enum": [ "static", "constant", "readOnly", "rawString", "hasObjectId", "canHaveObjectId", "hasSideEffects" ], + "enumDescriptions": [ + "Indicates that the object is static.", + "Indicates that the object is a constant.", + "Indicates that the object is read only.", + "Indicates that the object is a raw string.", + "Indicates that the object can have an Object ID created for it.", + "Indicates that the object has an Object ID associated with it.", + "Indicates that the evaluation had side effects." + ] + } + }, + "visibility": { + "description": "Visibility of variable. Before introducing additional values, try to use the listed values.", + "type": "string", + "_enum": [ "public", "private", "protected", "internal", "final" ] + } + } + }, + + "SourceBreakpoint": { + "type": "object", + "description": "Properties of a breakpoint or logpoint passed to the setBreakpoints request.", + "properties": { + "line": { + "type": "integer", + "description": "The source line of the breakpoint or logpoint." + }, + "column": { + "type": "integer", + "description": "An optional source column of the breakpoint." + }, + "condition": { + "type": "string", + "description": "An optional expression for conditional breakpoints." + }, + "hitCondition": { + "type": "string", + "description": "An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed." + }, + "logMessage": { + "type": "string", + "description": "If this attribute exists and is non-empty, the backend must not 'break' (stop) but log the message instead. Expressions within {} are interpolated." + } + }, + "required": [ "line" ] + }, + + "FunctionBreakpoint": { + "type": "object", + "description": "Properties of a breakpoint passed to the setFunctionBreakpoints request.", + "properties": { + "name": { + "type": "string", + "description": "The name of the function." + }, + "condition": { + "type": "string", + "description": "An optional expression for conditional breakpoints." + }, + "hitCondition": { + "type": "string", + "description": "An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed." + } + }, + "required": [ "name" ] + }, + + "DataBreakpointAccessType": { + "type": "string", + "description": "This enumeration defines all possible access types for data breakpoints.", + "enum": [ "read", "write", "readWrite" ] + }, + + "DataBreakpoint": { + "type": "object", + "description": "Properties of a data breakpoint passed to the setDataBreakpoints request.", + "properties": { + "dataId": { + "type": "string", + "description": "An id representing the data. This id is returned from the dataBreakpointInfo request." + }, + "accessType": { + "$ref": "#/definitions/DataBreakpointAccessType", + "description": "The access type of the data." + }, + "condition": { + "type": "string", + "description": "An optional expression for conditional breakpoints." + }, + "hitCondition": { + "type": "string", + "description": "An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed." + } + }, + "required": [ "dataId" ] + }, + + "Breakpoint": { + "type": "object", + "description": "Information about a Breakpoint created in setBreakpoints or setFunctionBreakpoints.", + "properties": { + "id": { + "type": "integer", + "description": "An optional identifier for the breakpoint. It is needed if breakpoint events are used to update or remove breakpoints." + }, + "verified": { + "type": "boolean", + "description": "If true breakpoint could be set (but not necessarily at the desired location)." + }, + "message": { + "type": "string", + "description": "An optional message about the state of the breakpoint. This is shown to the user and can be used to explain why a breakpoint could not be verified." + }, + "source": { + "$ref": "#/definitions/Source", + "description": "The source where the breakpoint is located." + }, + "line": { + "type": "integer", + "description": "The start line of the actual range covered by the breakpoint." + }, + "column": { + "type": "integer", + "description": "An optional start column of the actual range covered by the breakpoint." + }, + "endLine": { + "type": "integer", + "description": "An optional end line of the actual range covered by the breakpoint." + }, + "endColumn": { + "type": "integer", + "description": "An optional end column of the actual range covered by the breakpoint. If no end line is given, then the end column is assumed to be in the start line." + } + }, + "required": [ "verified" ] + }, + + "StepInTarget": { + "type": "object", + "description": "A StepInTarget can be used in the 'stepIn' request and determines into which single target the stepIn request should step.", + "properties": { + "id": { + "type": "integer", + "description": "Unique identifier for a stepIn target." + }, + "label": { + "type": "string", + "description": "The name of the stepIn target (shown in the UI)." + } + }, + "required": [ "id", "label" ] + }, + + "GotoTarget": { + "type": "object", + "description": "A GotoTarget describes a code location that can be used as a target in the 'goto' request.\nThe possible goto targets can be determined via the 'gotoTargets' request.", + "properties": { + "id": { + "type": "integer", + "description": "Unique identifier for a goto target. This is used in the goto request." + }, + "label": { + "type": "string", + "description": "The name of the goto target (shown in the UI)." + }, + "line": { + "type": "integer", + "description": "The line of the goto target." + }, + "column": { + "type": "integer", + "description": "An optional column of the goto target." + }, + "endLine": { + "type": "integer", + "description": "An optional end line of the range covered by the goto target." + }, + "endColumn": { + "type": "integer", + "description": "An optional end column of the range covered by the goto target." + }, + "instructionPointerReference": { + "type": "string", + "description": "Optional memory reference for the instruction pointer value represented by this target." + } + }, + "required": [ "id", "label", "line" ] + }, + + "CompletionItem": { + "type": "object", + "description": "CompletionItems are the suggestions returned from the CompletionsRequest.", + "properties": { + "label": { + "type": "string", + "description": "The label of this completion item. By default this is also the text that is inserted when selecting this completion." + }, + "text": { + "type": "string", + "description": "If text is not falsy then it is inserted instead of the label." + }, + "type": { + "$ref": "#/definitions/CompletionItemType", + "description": "The item's type. Typically the client uses this information to render the item in the UI with an icon." + }, + "start": { + "type": "integer", + "description": "This value determines the location (in the CompletionsRequest's 'text' attribute) where the completion text is added.\nIf missing the text is added at the location specified by the CompletionsRequest's 'column' attribute." + }, + "length": { + "type": "integer", + "description": "This value determines how many characters are overwritten by the completion text.\nIf missing the value 0 is assumed which results in the completion text being inserted." + } + }, + "required": [ "label" ] + }, + + "CompletionItemType": { + "type": "string", + "description": "Some predefined types for the CompletionItem. Please note that not all clients have specific icons for all of them.", + "enum": [ "method", "function", "constructor", "field", "variable", "class", "interface", "module", "property", "unit", "value", "enum", "keyword", "snippet", "text", "color", "file", "reference", "customcolor" ] + }, + + "ChecksumAlgorithm": { + "type": "string", + "description": "Names of checksum algorithms that may be supported by a debug adapter.", + "enum": [ "MD5", "SHA1", "SHA256", "timestamp" ] + }, + + "Checksum": { + "type": "object", + "description": "The checksum of an item calculated by the specified algorithm.", + "properties": { + "algorithm": { + "$ref": "#/definitions/ChecksumAlgorithm", + "description": "The algorithm used to calculate this checksum." + }, + "checksum": { + "type": "string", + "description": "Value of the checksum." + } + }, + "required": [ "algorithm", "checksum" ] + }, + + "ValueFormat": { + "type": "object", + "description": "Provides formatting information for a value.", + "properties": { + "hex": { + "type": "boolean", + "description": "Display the value in hex." + } + } + }, + + "StackFrameFormat": { + "allOf": [ { "$ref": "#/definitions/ValueFormat" }, { + "type": "object", + "description": "Provides formatting information for a stack frame.", + "properties": { + "parameters": { + "type": "boolean", + "description": "Displays parameters for the stack frame." + }, + "parameterTypes": { + "type": "boolean", + "description": "Displays the types of parameters for the stack frame." + }, + "parameterNames": { + "type": "boolean", + "description": "Displays the names of parameters for the stack frame." + }, + "parameterValues": { + "type": "boolean", + "description": "Displays the values of parameters for the stack frame." + }, + "line": { + "type": "boolean", + "description": "Displays the line number of the stack frame." + }, + "module": { + "type": "boolean", + "description": "Displays the module of the stack frame." + }, + "includeAll": { + "type": "boolean", + "description": "Includes all stack frames, including those the debug adapter might otherwise hide." + } + } + }] + }, + + "ExceptionOptions": { + "type": "object", + "description": "An ExceptionOptions assigns configuration options to a set of exceptions.", + "properties": { + "path": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionPathSegment" + }, + "description": "A path that selects a single or multiple exceptions in a tree. If 'path' is missing, the whole tree is selected. By convention the first segment of the path is a category that is used to group exceptions in the UI." + }, + "breakMode": { + "$ref": "#/definitions/ExceptionBreakMode", + "description": "Condition when a thrown exception should result in a break." + } + }, + "required": [ "breakMode" ] + }, + + "ExceptionBreakMode": { + "type": "string", + "description": "This enumeration defines all possible conditions when a thrown exception should result in a break.\nnever: never breaks,\nalways: always breaks,\nunhandled: breaks when excpetion unhandled,\nuserUnhandled: breaks if the exception is not handled by user code.", + "enum": [ "never", "always", "unhandled", "userUnhandled" ] + }, + + "ExceptionPathSegment": { + "type": "object", + "description": "An ExceptionPathSegment represents a segment in a path that is used to match leafs or nodes in a tree of exceptions. If a segment consists of more than one name, it matches the names provided if 'negate' is false or missing or it matches anything except the names provided if 'negate' is true.", + "properties": { + "negate": { + "type": "boolean", + "description": "If false or missing this segment matches the names provided, otherwise it matches anything except the names provided." + }, + "names": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Depending on the value of 'negate' the names that should match or not match." + } + }, + "required": [ "names" ] + }, + + "ExceptionDetails": { + "type": "object", + "description": "Detailed information about an exception that has occurred.", + "properties": { + "message": { + "type": "string", + "description": "Message contained in the exception." + }, + "typeName": { + "type": "string", + "description": "Short type name of the exception object." + }, + "fullTypeName": { + "type": "string", + "description": "Fully-qualified type name of the exception object." + }, + "evaluateName": { + "type": "string", + "description": "Optional expression that can be evaluated in the current scope to obtain the exception object." + }, + "stackTrace": { + "type": "string", + "description": "Stack trace at the time the exception was thrown." + }, + "innerException": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionDetails" + }, + "description": "Details of the exception contained by this exception, if any." + } + } + }, + + "DisassembledInstruction": { + "type": "object", + "description": "Represents a single disassembled instruction.", + "properties": { + "address": { + "type": "string", + "description": "The address of the instruction. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise." + }, + "instructionBytes": { + "type": "string", + "description": "Optional raw bytes representing the instruction and its operands, in an implementation-defined format." + }, + "instruction": { + "type": "string", + "description": "Text representing the instruction and its operands, in an implementation-defined format." + }, + "symbol": { + "type": "string", + "description": "Name of the symbol that correponds with the location of this instruction, if any." + }, + "location": { + "$ref": "#/definitions/Source", + "description": "Source location that corresponds to this instruction, if any. Should always be set (if available) on the first instruction returned, but can be omitted afterwards if this instruction maps to the same source file as the previous instruction." + }, + "line": { + "type": "integer", + "description": "The line within the source location that corresponds to this instruction, if any." + }, + "column": { + "type": "integer", + "description": "The column within the line that corresponds to this instruction, if any." + }, + "endLine": { + "type": "integer", + "description": "The end line of the range that corresponds to this instruction, if any." + }, + "endColumn": { + "type": "integer", + "description": "The end column of the range that corresponds to this instruction, if any." + } + }, + "required": [ "address", "instruction" ] + } + + } +} diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocolCustom.json b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocolCustom.json new file mode 100644 index 0000000..09297cd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/debugProtocolCustom.json @@ -0,0 +1,243 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Custom Debug Adapter Protocol", + "description": "Extension to the DAP to support additional features.", + "type": "object", + + + "definitions": { + + "SetDebuggerPropertyRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request can be used to enable or disable debugger features.", + "properties": { + "command": { + "type": "string", + "enum": [ "setDebuggerProperty" ] + }, + "arguments": { + "$ref": "#/definitions/SetDebuggerPropertyArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetDebuggerPropertyArguments": { + "type": "object", + "description": "Arguments for 'setDebuggerProperty' request.", + "properties": { + "ideOS": { + "type": [ "string" ], + "description": "OS where the ide is running. Supported values [Windows, Linux]" + }, + "dontTraceStartPatterns": { + "type": [ "array" ], + "description": "Patterns to match with the start of the file paths. Matching paths will be added to a list of file where trace is ignored." + }, + "dontTraceEndPatterns": { + "type": [ "array" ], + "description": "Patterns to match with the end of the file paths. Matching paths will be added to a list of file where trace is ignored." + }, + "skipSuspendOnBreakpointException": { + "type": [ "array" ], + "description": "List of exceptions that should be skipped when doing condition evaluations." + }, + "skipPrintBreakpointException": { + "type": [ "array" ], + "description": "List of exceptions that should skip printing to stderr when doing condition evaluations." + }, + "multiThreadsSingleNotification": { + "type": [ "boolean" ], + "description": "If false then a notification is generated for each thread event. If true a single event is gnenerated, and all threads follow that behavior." + } + } + }, + "SetDebuggerPropertyResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setDebuggerProperty' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "SetPydevdSourceMapRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": [ + "Sets multiple PydevdSourceMap for a single source and clears all previous PydevdSourceMap in that source.", + "i.e.: Maps paths and lines in a 1:N mapping (use case: map a single file in the IDE to multiple IPython cells).", + "To clear all PydevdSourceMap for a source, specify an empty array.", + "Interaction with breakpoints: When a new mapping is sent, breakpoints that match the source (or previously matched a source) are reapplied.", + "Interaction with launch pathMapping: both mappings are independent. This mapping is applied after the launch pathMapping." + ], + "properties": { + "command": { + "type": "string", + "enum": [ "setPydevdSourceMap" ] + }, + "arguments": { + "$ref": "#/definitions/SetPydevdSourceMapArguments" + } + }, + "required": [ "command", "arguments" ] + }] + }, + "SetPydevdSourceMapArguments": { + "type": "object", + "description": "Arguments for 'setPydevdSourceMap' request.", + "properties": { + "source": { + "$ref": "#/definitions/Source", + "description": "The source location of the PydevdSourceMap; 'source.path' must be specified (e.g.: for an ipython notebook this could be something as /home/notebook/note.py)." + }, + "pydevdSourceMaps": { + "type": "array", + "items": { + "$ref": "#/definitions/PydevdSourceMap" + }, + "description": "The PydevdSourceMaps to be set to the given source (provide an empty array to clear the source mappings for a given path)." + } + }, + "required": [ "source", "pydevdSourceMap" ] + }, + "SetPydevdSourceMapResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'setPydevdSourceMap' request. This is just an acknowledgement, so no body field is required." + }] + }, + + "PydevdSourceMap": { + "type": "object", + "description": "Information that allows mapping a local line to a remote source/line.", + "properties": { + "line": { + "type": "integer", + "description": "The local line to which the mapping should map to (e.g.: for an ipython notebook this would be the first line of the cell in the file)." + }, + "endLine": { + "type": "integer", + "description": "The end line." + }, + "runtimeSource": { + "$ref": "#/definitions/Source", + "description": "The path that the user has remotely -- 'source.path' must be specified (e.g.: for an ipython notebook this could be something as '')" + }, + "runtimeLine": { + "type": "integer", + "description": "The remote line to which the mapping should map to (e.g.: for an ipython notebook this would be always 1 as it'd map the start of the cell)." + } + }, + "required": ["line", "endLine", "runtimeSource", "runtimeLine"] + }, + + "PydevdSystemInfoRequest": { + "allOf": [ { "$ref": "#/definitions/Request" }, { + "type": "object", + "description": "The request can be used retrieve system information, python version, etc.", + "properties": { + "command": { + "type": "string", + "enum": [ "pydevdSystemInfo" ] + }, + "arguments": { + "$ref": "#/definitions/PydevdSystemInfoArguments" + } + }, + "required": [ "command" ] + }] + }, + "PydevdSystemInfoArguments": { + "type": "object", + "description": "Arguments for 'pydevdSystemInfo' request." + }, + "PydevdSystemInfoResponse": { + "allOf": [ { "$ref": "#/definitions/Response" }, { + "type": "object", + "description": "Response to 'pydevdSystemInfo' request.", + "properties": { + "body": { + "type": "object", + "properties": { + "python": { + "$ref": "#/definitions/PydevdPythonInfo", + "description": "Information about the python version running in the current process." + }, + "platform": { + "$ref": "#/definitions/PydevdPlatformInfo", + "description": "Information about the plarforn on which the current process is running." + }, + "process": { + "$ref": "#/definitions/PydevdProcessInfo", + "description": "Information about the current process." + } + }, + "required": [ "python", "platform", "process" ] + } + }, + "required": [ "body" ] + }] + }, + + "PydevdPythonInfo": { + "type": "object", + "description": "This object contains python version and implementation details.", + "properties": { + "version": { + "type": "string", + "description": "Python version as a string in semver format: ..." + }, + "implementation": { + "$ref": "#/definitions/PydevdPythonImplementationInfo", + "description": "Python version as a string in this format ..." + } + } + }, + "PydevdPythonImplementationInfo": { + "type": "object", + "description": "This object contains python implementation details.", + "properties": { + "name": { + "type": "string", + "description": "Python implementation name." + }, + "version": { + "type": "string", + "description": "Python version as a string in semver format: ..." + }, + "description": { + "type": "string", + "description": "Optional description for this python implementation." + } + } + }, + "PydevdPlatformInfo": { + "type": "object", + "description": "This object contains python version and implementation details.", + "properties": { + "name": { + "type": "string", + "description": "Name of the platform as returned by 'sys.platform'." + } + } + }, + "PydevdProcessInfo": { + "type": "object", + "description": "This object contains python process details.", + "properties": { + "pid": { + "type": "integer", + "description": "Process ID for the current process." + }, + "executable": { + "type": "string", + "description": "Path to the executable as returned by 'sys.executable'." + }, + "bitness": { + "type": "integer", + "description": "Integer value indicating the bitness of the current process." + } + } + } + } +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_base_schema.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_base_schema.py new file mode 100644 index 0000000..536fcad --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_base_schema.py @@ -0,0 +1,146 @@ +from _pydevd_bundle._debug_adapter.pydevd_schema_log import debug_exception +import json +import itertools +from functools import partial + + +class BaseSchema(object): + + @staticmethod + def initialize_ids_translation(): + BaseSchema._dap_id_to_obj_id = {0:0, None:None} + BaseSchema._obj_id_to_dap_id = {0:0, None:None} + BaseSchema._next_dap_id = partial(next, itertools.count(1)) + + def to_json(self): + return json.dumps(self.to_dict()) + + @staticmethod + def _translate_id_to_dap(obj_id): + if obj_id == '*': + return '*' + # Note: we don't invalidate ids, so, if some object starts using the same id + # of another object, the same id will be used. + dap_id = BaseSchema._obj_id_to_dap_id.get(obj_id) + if dap_id is None: + dap_id = BaseSchema._obj_id_to_dap_id[obj_id] = BaseSchema._next_dap_id() + BaseSchema._dap_id_to_obj_id[dap_id] = obj_id + return dap_id + + @staticmethod + def _translate_id_from_dap(dap_id): + if dap_id == '*': + return '*' + try: + return BaseSchema._dap_id_to_obj_id[dap_id] + except: + raise KeyError('Wrong ID sent from the client: %s' % (dap_id,)) + + @staticmethod + def update_dict_ids_to_dap(dct): + return dct + + @staticmethod + def update_dict_ids_from_dap(dct): + return dct + + +BaseSchema.initialize_ids_translation() + +_requests_to_types = {} +_responses_to_types = {} +_event_to_types = {} +_all_messages = {} + + +def register(cls): + _all_messages[cls.__name__] = cls + return cls + + +def register_request(command): + + def do_register(cls): + _requests_to_types[command] = cls + return cls + + return do_register + + +def register_response(command): + + def do_register(cls): + _responses_to_types[command] = cls + return cls + + return do_register + + +def register_event(event): + + def do_register(cls): + _event_to_types[event] = cls + return cls + + return do_register + + +def from_dict(dct, update_ids_from_dap=False): + msg_type = dct.get('type') + if msg_type is None: + raise ValueError('Unable to make sense of message: %s' % (dct,)) + + if msg_type == 'request': + to_type = _requests_to_types + use = dct['command'] + + elif msg_type == 'response': + to_type = _responses_to_types + use = dct['command'] + + else: + to_type = _event_to_types + use = dct['event'] + + cls = to_type.get(use) + if cls is None: + raise ValueError('Unable to create message from dict: %s. %s not in %s' % (dct, use, sorted(to_type.keys()))) + try: + return cls(update_ids_from_dap=update_ids_from_dap, **dct) + except: + msg = 'Error creating %s from %s' % (cls, dct) + debug_exception(msg) + raise + + +def from_json(json_msg, update_ids_from_dap=False): + if isinstance(json_msg, bytes): + json_msg = json_msg.decode('utf-8') + + as_dict = json.loads(json_msg) + try: + return from_dict(as_dict, update_ids_from_dap=update_ids_from_dap) + except: + if as_dict.get('type') == 'response' and not as_dict.get('success'): + # Error messages may not have required body (return as a generic Response). + Response = _all_messages['Response'] + return Response(**as_dict) + else: + raise + + +def get_response_class(request): + if request.__class__ == dict: + return _responses_to_types[request['command']] + return _responses_to_types[request.command] + + +def build_response(request, kwargs=None): + if kwargs is None: + kwargs = {'success':True} + else: + if 'success' not in kwargs: + kwargs['success'] = True + response_class = _responses_to_types[request.command] + kwargs.setdefault('seq', -1) # To be overwritten before sending + return response_class(command=request.command, request_seq=request.seq, **kwargs) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py new file mode 100644 index 0000000..70cc152 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py @@ -0,0 +1,15926 @@ +# coding: utf-8 +# Automatically generated code. +# Do not edit manually. +# Generated by running: __main__pydevd_gen_debug_adapter_protocol.py +from .pydevd_base_schema import BaseSchema, register, register_request, register_response, register_event + + +@register +class ProtocolMessage(BaseSchema): + """ + Base class of requests, responses, and events. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "description": "Message type.", + "_enum": [ + "request", + "response", + "event" + ] + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, type, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: Message type. + :param integer seq: Sequence number. + """ + self.type = type + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + seq = self.seq + dct = { + 'type': type, + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class Request(BaseSchema): + """ + A client or debug adapter initiated request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "description": "The command to execute." + }, + "arguments": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Object containing arguments for the command." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, command, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: The command to execute. + :param integer seq: Sequence number. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] arguments: Object containing arguments for the command. + """ + self.type = 'request' + self.command = command + self.seq = seq + self.arguments = arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments + dct.update(self.kwargs) + return dct + + +@register +class Event(BaseSchema): + """ + A debug adapter initiated event. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "description": "Type of event." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Event-specific information." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, event, seq=-1, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: Type of event. + :param integer seq: Sequence number. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Event-specific information. + """ + self.type = 'event' + self.event = event + self.seq = seq + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + seq = self.seq + body = self.body + dct = { + 'type': type, + 'event': event, + 'seq': seq, + } + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register +class Response(BaseSchema): + """ + Response for a request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_response('error') +@register +class ErrorResponse(BaseSchema): + """ + On error (whenever 'success' is false), the body can provide more details. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "error": { + "$ref": "#/definitions/Message", + "description": "An optional, structured error message." + } + } + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param ErrorResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = ErrorResponseBody() + else: + self.body = ErrorResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ErrorResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_event('initialized') +@register +class InitializedEvent(BaseSchema): + """ + This event indicates that the debug adapter is ready to accept configuration requests (e.g. + SetBreakpointsRequest, SetExceptionBreakpointsRequest). + + A debug adapter is expected to send this event when it is ready to accept configuration requests + (but not before the 'initialize' request has finished). + + The sequence of events/requests is as follows: + + - adapters sends 'initialized' event (after the 'initialize' request has returned) + + - frontend sends zero or more 'setBreakpoints' requests + + - frontend sends one 'setFunctionBreakpoints' request + + - frontend sends a 'setExceptionBreakpoints' request if one or more 'exceptionBreakpointFilters' + have been defined (or if 'supportsConfigurationDoneRequest' is not defined or false) + + - frontend sends other future configuration requests + + - frontend sends one 'configurationDone' request to indicate the end of the configuration. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "initialized" + ] + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Event-specific information." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param integer seq: Sequence number. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Event-specific information. + """ + self.type = 'event' + self.event = 'initialized' + self.seq = seq + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + seq = self.seq + body = self.body + dct = { + 'type': type, + 'event': event, + 'seq': seq, + } + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_event('stopped') +@register +class StoppedEvent(BaseSchema): + """ + The event indicates that the execution of the debuggee has stopped due to some condition. + + This can be caused by a break point previously set, a stepping action has completed, by executing a + debugger statement etc. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "stopped" + ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.\nFor backward compatibility this string is shown in the UI if the 'description' attribute is missing (but it must not be translated).", + "_enum": [ + "step", + "breakpoint", + "exception", + "pause", + "entry", + "goto", + "function breakpoint", + "data breakpoint" + ] + }, + "description": { + "type": "string", + "description": "The full reason for the event, e.g. 'Paused on exception'. This string is shown in the UI as is and must be translated." + }, + "threadId": { + "type": "integer", + "description": "The thread which was stopped." + }, + "preserveFocusHint": { + "type": "boolean", + "description": "A value of true hints to the frontend that this event should not change the focus." + }, + "text": { + "type": "string", + "description": "Additional information. E.g. if reason is 'exception', text contains the exception name. This string is shown in the UI." + }, + "allThreadsStopped": { + "type": "boolean", + "description": "If 'allThreadsStopped' is true, a debug adapter can announce that all threads have stopped.\n- The client should use this information to enable that all threads can be expanded to access their stacktraces.\n- If the attribute is missing or false, only the thread with the given threadId can be expanded." + } + }, + "required": [ + "reason" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param StoppedEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'stopped' + if body is None: + self.body = StoppedEventBody() + else: + self.body = StoppedEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != StoppedEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('continued') +@register +class ContinuedEvent(BaseSchema): + """ + The event indicates that the execution of the debuggee has continued. + + Please note: a debug adapter is not expected to send this event in response to a request that + implies that execution continues, e.g. 'launch' or 'continue'. + + It is only necessary to send a 'continued' event if there was no previous request that implied this. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "continued" + ] + }, + "body": { + "type": "object", + "properties": { + "threadId": { + "type": "integer", + "description": "The thread which was continued." + }, + "allThreadsContinued": { + "type": "boolean", + "description": "If 'allThreadsContinued' is true, a debug adapter can announce that all threads have continued." + } + }, + "required": [ + "threadId" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param ContinuedEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'continued' + if body is None: + self.body = ContinuedEventBody() + else: + self.body = ContinuedEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ContinuedEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('exited') +@register +class ExitedEvent(BaseSchema): + """ + The event indicates that the debuggee has exited and returns its exit code. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "exited" + ] + }, + "body": { + "type": "object", + "properties": { + "exitCode": { + "type": "integer", + "description": "The exit code returned from the debuggee." + } + }, + "required": [ + "exitCode" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param ExitedEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'exited' + if body is None: + self.body = ExitedEventBody() + else: + self.body = ExitedEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ExitedEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('terminated') +@register +class TerminatedEvent(BaseSchema): + """ + The event indicates that debugging of the debuggee has terminated. This does **not** mean that the + debuggee itself has exited. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "terminated" + ] + }, + "body": { + "type": "object", + "properties": { + "restart": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "A debug adapter may set 'restart' to true (or to an arbitrary object) to request that the front end restarts the session.\nThe value is not interpreted by the client and passed unmodified as an attribute '__restart' to the 'launch' and 'attach' requests." + } + } + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param integer seq: Sequence number. + :param TerminatedEventBody body: + """ + self.type = 'event' + self.event = 'terminated' + self.seq = seq + if body is None: + self.body = TerminatedEventBody() + else: + self.body = TerminatedEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != TerminatedEventBody else body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + seq = self.seq + body = self.body + dct = { + 'type': type, + 'event': event, + 'seq': seq, + } + if body is not None: + dct['body'] = body.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register_event('thread') +@register +class ThreadEvent(BaseSchema): + """ + The event indicates that a thread has started or exited. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "thread" + ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "_enum": [ + "started", + "exited" + ] + }, + "threadId": { + "type": "integer", + "description": "The identifier of the thread." + } + }, + "required": [ + "reason", + "threadId" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param ThreadEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'thread' + if body is None: + self.body = ThreadEventBody() + else: + self.body = ThreadEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ThreadEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('output') +@register +class OutputEvent(BaseSchema): + """ + The event indicates that the target has produced some output. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "output" + ] + }, + "body": { + "type": "object", + "properties": { + "category": { + "type": "string", + "description": "The output category. If not specified, 'console' is assumed.", + "_enum": [ + "console", + "stdout", + "stderr", + "telemetry" + ] + }, + "output": { + "type": "string", + "description": "The output to report." + }, + "variablesReference": { + "type": "number", + "description": "If an attribute 'variablesReference' exists and its value is > 0, the output contains objects which can be retrieved by passing 'variablesReference' to the 'variables' request." + }, + "source": { + "$ref": "#/definitions/Source", + "description": "An optional source location where the output was produced." + }, + "line": { + "type": "integer", + "description": "An optional source location line where the output was produced." + }, + "column": { + "type": "integer", + "description": "An optional source location column where the output was produced." + }, + "data": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Optional data to report. For the 'telemetry' category the data will be sent to telemetry, for the other categories the data is shown in JSON format." + } + }, + "required": [ + "output" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param OutputEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'output' + if body is None: + self.body = OutputEventBody() + else: + self.body = OutputEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != OutputEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('breakpoint') +@register +class BreakpointEvent(BaseSchema): + """ + The event indicates that some information about a breakpoint has changed. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "breakpoint" + ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "_enum": [ + "changed", + "new", + "removed" + ] + }, + "breakpoint": { + "$ref": "#/definitions/Breakpoint", + "description": "The 'id' attribute is used to find the target breakpoint and the other attributes are used as the new values." + } + }, + "required": [ + "reason", + "breakpoint" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param BreakpointEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'breakpoint' + if body is None: + self.body = BreakpointEventBody() + else: + self.body = BreakpointEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != BreakpointEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('module') +@register +class ModuleEvent(BaseSchema): + """ + The event indicates that some information about a module has changed. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "module" + ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "enum": [ + "new", + "changed", + "removed" + ] + }, + "module": { + "$ref": "#/definitions/Module", + "description": "The new, changed, or removed module. In case of 'removed' only the module id is used." + } + }, + "required": [ + "reason", + "module" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param ModuleEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'module' + if body is None: + self.body = ModuleEventBody() + else: + self.body = ModuleEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ModuleEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('loadedSource') +@register +class LoadedSourceEvent(BaseSchema): + """ + The event indicates that some source has been added, changed, or removed from the set of all loaded + sources. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "loadedSource" + ] + }, + "body": { + "type": "object", + "properties": { + "reason": { + "type": "string", + "description": "The reason for the event.", + "enum": [ + "new", + "changed", + "removed" + ] + }, + "source": { + "$ref": "#/definitions/Source", + "description": "The new, changed, or removed source." + } + }, + "required": [ + "reason", + "source" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param LoadedSourceEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'loadedSource' + if body is None: + self.body = LoadedSourceEventBody() + else: + self.body = LoadedSourceEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != LoadedSourceEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('process') +@register +class ProcessEvent(BaseSchema): + """ + The event indicates that the debugger has begun debugging a new process. Either one that it has + launched, or one that it has attached to. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "process" + ] + }, + "body": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The logical name of the process. This is usually the full path to process's executable file. Example: /home/example/myproj/program.js." + }, + "systemProcessId": { + "type": "integer", + "description": "The system process id of the debugged process. This property will be missing for non-system processes." + }, + "isLocalProcess": { + "type": "boolean", + "description": "If true, the process is running on the same computer as the debug adapter." + }, + "startMethod": { + "type": "string", + "enum": [ + "launch", + "attach", + "attachForSuspendedLaunch" + ], + "description": "Describes how the debug engine started debugging this process.", + "enumDescriptions": [ + "Process was launched under the debugger.", + "Debugger attached to an existing process.", + "A project launcher component has launched a new process in a suspended state and then asked the debugger to attach." + ] + }, + "pointerSize": { + "type": "integer", + "description": "The size of a pointer or address for this process, in bits. This value may be used by clients when formatting addresses for display." + } + }, + "required": [ + "name" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param ProcessEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'process' + if body is None: + self.body = ProcessEventBody() + else: + self.body = ProcessEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ProcessEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_event('capabilities') +@register +class CapabilitiesEvent(BaseSchema): + """ + The event indicates that one or more capabilities have changed. + + Since the capabilities are dependent on the frontend and its UI, it might not be possible to change + that at random times (or too late). + + Consequently this event has a hint characteristic: a frontend can only be expected to make a 'best + effort' in honouring individual capabilities but there are no guarantees. + + Only changed capabilities need to be included, all other capabilities keep their values. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "event" + ] + }, + "event": { + "type": "string", + "enum": [ + "capabilities" + ] + }, + "body": { + "type": "object", + "properties": { + "capabilities": { + "$ref": "#/definitions/Capabilities", + "description": "The set of updated capabilities." + } + }, + "required": [ + "capabilities" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, body, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string event: + :param CapabilitiesEventBody body: + :param integer seq: Sequence number. + """ + self.type = 'event' + self.event = 'capabilities' + if body is None: + self.body = CapabilitiesEventBody() + else: + self.body = CapabilitiesEventBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != CapabilitiesEventBody else body + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + event = self.event + body = self.body + seq = self.seq + dct = { + 'type': type, + 'event': event, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register_request('runInTerminal') +@register +class RunInTerminalRequest(BaseSchema): + """ + This request is sent from the debug adapter to the client to run a command in a terminal. This is + typically used to launch the debuggee in a terminal provided by the client. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "runInTerminal" + ] + }, + "arguments": { + "type": "RunInTerminalRequestArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param RunInTerminalRequestArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'runInTerminal' + if arguments is None: + self.arguments = RunInTerminalRequestArguments() + else: + self.arguments = RunInTerminalRequestArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != RunInTerminalRequestArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class RunInTerminalRequestArguments(BaseSchema): + """ + Arguments for 'runInTerminal' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "kind": { + "type": "string", + "enum": [ + "integrated", + "external" + ], + "description": "What kind of terminal to launch." + }, + "title": { + "type": "string", + "description": "Optional title of the terminal." + }, + "cwd": { + "type": "string", + "description": "Working directory of the command." + }, + "args": { + "type": "array", + "items": { + "type": "string" + }, + "description": "List of arguments. The first argument is the command to run." + }, + "env": { + "type": "object", + "description": "Environment key-value pairs that are added to or removed from the default environment.", + "additionalProperties": { + "type": [ + "string", + "null" + ], + "description": "Proper values must be strings. A value of 'null' removes the variable from the environment." + } + } + } + __refs__ = set(['env']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, cwd, args, kind=None, title=None, env=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string cwd: Working directory of the command. + :param array args: List of arguments. The first argument is the command to run. + :param string kind: What kind of terminal to launch. + :param string title: Optional title of the terminal. + :param RunInTerminalRequestArgumentsEnv env: Environment key-value pairs that are added to or removed from the default environment. + """ + self.cwd = cwd + self.args = args + self.kind = kind + self.title = title + if env is None: + self.env = RunInTerminalRequestArgumentsEnv() + else: + self.env = RunInTerminalRequestArgumentsEnv(update_ids_from_dap=update_ids_from_dap, **env) if env.__class__ != RunInTerminalRequestArgumentsEnv else env + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + cwd = self.cwd + args = self.args + if args and hasattr(args[0], "to_dict"): + args = [x.to_dict() for x in args] + kind = self.kind + title = self.title + env = self.env + dct = { + 'cwd': cwd, + 'args': args, + } + if kind is not None: + dct['kind'] = kind + if title is not None: + dct['title'] = title + if env is not None: + dct['env'] = env.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register_response('runInTerminal') +@register +class RunInTerminalResponse(BaseSchema): + """ + Response to 'runInTerminal' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "processId": { + "type": "number", + "description": "The process ID." + }, + "shellProcessId": { + "type": "number", + "description": "The process ID of the terminal shell." + } + } + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param RunInTerminalResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = RunInTerminalResponseBody() + else: + self.body = RunInTerminalResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != RunInTerminalResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('initialize') +@register +class InitializeRequest(BaseSchema): + """ + The 'initialize' request is sent as the first request from the client to the debug adapter in order + to configure it with client capabilities and to retrieve capabilities from the debug adapter. + + Until the debug adapter has responded to with an 'initialize' response, the client must not send any + additional requests or events to the debug adapter. In addition the debug adapter is not allowed to + send any requests or events to the client until it has responded with an 'initialize' response. + + The 'initialize' request may only be sent once. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "initialize" + ] + }, + "arguments": { + "type": "InitializeRequestArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param InitializeRequestArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'initialize' + if arguments is None: + self.arguments = InitializeRequestArguments() + else: + self.arguments = InitializeRequestArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != InitializeRequestArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class InitializeRequestArguments(BaseSchema): + """ + Arguments for 'initialize' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "clientID": { + "type": "string", + "description": "The ID of the (frontend) client using this adapter." + }, + "clientName": { + "type": "string", + "description": "The human readable name of the (frontend) client using this adapter." + }, + "adapterID": { + "type": "string", + "description": "The ID of the debug adapter." + }, + "locale": { + "type": "string", + "description": "The ISO-639 locale of the (frontend) client using this adapter, e.g. en-US or de-CH." + }, + "linesStartAt1": { + "type": "boolean", + "description": "If true all line numbers are 1-based (default)." + }, + "columnsStartAt1": { + "type": "boolean", + "description": "If true all column numbers are 1-based (default)." + }, + "pathFormat": { + "type": "string", + "_enum": [ + "path", + "uri" + ], + "description": "Determines in what format paths are specified. The default is 'path', which is the native format." + }, + "supportsVariableType": { + "type": "boolean", + "description": "Client supports the optional type attribute for variables." + }, + "supportsVariablePaging": { + "type": "boolean", + "description": "Client supports the paging of variables." + }, + "supportsRunInTerminalRequest": { + "type": "boolean", + "description": "Client supports the runInTerminal request." + }, + "supportsMemoryReferences": { + "type": "boolean", + "description": "Client supports memory references." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, adapterID, clientID=None, clientName=None, locale=None, linesStartAt1=None, columnsStartAt1=None, pathFormat=None, supportsVariableType=None, supportsVariablePaging=None, supportsRunInTerminalRequest=None, supportsMemoryReferences=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string adapterID: The ID of the debug adapter. + :param string clientID: The ID of the (frontend) client using this adapter. + :param string clientName: The human readable name of the (frontend) client using this adapter. + :param string locale: The ISO-639 locale of the (frontend) client using this adapter, e.g. en-US or de-CH. + :param boolean linesStartAt1: If true all line numbers are 1-based (default). + :param boolean columnsStartAt1: If true all column numbers are 1-based (default). + :param string pathFormat: Determines in what format paths are specified. The default is 'path', which is the native format. + :param boolean supportsVariableType: Client supports the optional type attribute for variables. + :param boolean supportsVariablePaging: Client supports the paging of variables. + :param boolean supportsRunInTerminalRequest: Client supports the runInTerminal request. + :param boolean supportsMemoryReferences: Client supports memory references. + """ + self.adapterID = adapterID + self.clientID = clientID + self.clientName = clientName + self.locale = locale + self.linesStartAt1 = linesStartAt1 + self.columnsStartAt1 = columnsStartAt1 + self.pathFormat = pathFormat + self.supportsVariableType = supportsVariableType + self.supportsVariablePaging = supportsVariablePaging + self.supportsRunInTerminalRequest = supportsRunInTerminalRequest + self.supportsMemoryReferences = supportsMemoryReferences + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + adapterID = self.adapterID + clientID = self.clientID + clientName = self.clientName + locale = self.locale + linesStartAt1 = self.linesStartAt1 + columnsStartAt1 = self.columnsStartAt1 + pathFormat = self.pathFormat + supportsVariableType = self.supportsVariableType + supportsVariablePaging = self.supportsVariablePaging + supportsRunInTerminalRequest = self.supportsRunInTerminalRequest + supportsMemoryReferences = self.supportsMemoryReferences + dct = { + 'adapterID': adapterID, + } + if clientID is not None: + dct['clientID'] = clientID + if clientName is not None: + dct['clientName'] = clientName + if locale is not None: + dct['locale'] = locale + if linesStartAt1 is not None: + dct['linesStartAt1'] = linesStartAt1 + if columnsStartAt1 is not None: + dct['columnsStartAt1'] = columnsStartAt1 + if pathFormat is not None: + dct['pathFormat'] = pathFormat + if supportsVariableType is not None: + dct['supportsVariableType'] = supportsVariableType + if supportsVariablePaging is not None: + dct['supportsVariablePaging'] = supportsVariablePaging + if supportsRunInTerminalRequest is not None: + dct['supportsRunInTerminalRequest'] = supportsRunInTerminalRequest + if supportsMemoryReferences is not None: + dct['supportsMemoryReferences'] = supportsMemoryReferences + dct.update(self.kwargs) + return dct + + +@register_response('initialize') +@register +class InitializeResponse(BaseSchema): + """ + Response to 'initialize' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "description": "The capabilities of this debug adapter.", + "type": "Capabilities" + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param Capabilities body: The capabilities of this debug adapter. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + if body is None: + self.body = Capabilities() + else: + self.body = Capabilities(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != Capabilities else body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register_request('configurationDone') +@register +class ConfigurationDoneRequest(BaseSchema): + """ + The client of the debug protocol must send this request at the end of the sequence of configuration + requests (which was started by the 'initialized' event). + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "configurationDone" + ] + }, + "arguments": { + "type": "ConfigurationDoneArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param ConfigurationDoneArguments arguments: + """ + self.type = 'request' + self.command = 'configurationDone' + self.seq = seq + if arguments is None: + self.arguments = ConfigurationDoneArguments() + else: + self.arguments = ConfigurationDoneArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ConfigurationDoneArguments else arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class ConfigurationDoneArguments(BaseSchema): + """ + Arguments for 'configurationDone' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register_response('configurationDone') +@register +class ConfigurationDoneResponse(BaseSchema): + """ + Response to 'configurationDone' request. This is just an acknowledgement, so no body field is + required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('launch') +@register +class LaunchRequest(BaseSchema): + """ + The launch request is sent from the client to the debug adapter to start the debuggee with or + without debugging (if 'noDebug' is true). Since launching is debugger/runtime specific, the + arguments for this request are not part of this specification. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "launch" + ] + }, + "arguments": { + "type": "LaunchRequestArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param LaunchRequestArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'launch' + if arguments is None: + self.arguments = LaunchRequestArguments() + else: + self.arguments = LaunchRequestArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != LaunchRequestArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class LaunchRequestArguments(BaseSchema): + """ + Arguments for 'launch' request. Additional attributes are implementation specific. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "noDebug": { + "type": "boolean", + "description": "If noDebug is true the launch request should launch the program without enabling debugging." + }, + "__restart": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Optional data from the previous, restarted session.\nThe data is sent as the 'restart' attribute of the 'terminated' event.\nThe client should leave the data intact." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, noDebug=None, __restart=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean noDebug: If noDebug is true the launch request should launch the program without enabling debugging. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] __restart: Optional data from the previous, restarted session. + The data is sent as the 'restart' attribute of the 'terminated' event. + The client should leave the data intact. + """ + self.noDebug = noDebug + self.__restart = __restart + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + noDebug = self.noDebug + __restart = self.__restart + dct = { + } + if noDebug is not None: + dct['noDebug'] = noDebug + if __restart is not None: + dct['__restart'] = __restart + dct.update(self.kwargs) + return dct + + +@register_response('launch') +@register +class LaunchResponse(BaseSchema): + """ + Response to 'launch' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('attach') +@register +class AttachRequest(BaseSchema): + """ + The attach request is sent from the client to the debug adapter to attach to a debuggee that is + already running. Since attaching is debugger/runtime specific, the arguments for this request are + not part of this specification. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "attach" + ] + }, + "arguments": { + "type": "AttachRequestArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param AttachRequestArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'attach' + if arguments is None: + self.arguments = AttachRequestArguments() + else: + self.arguments = AttachRequestArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != AttachRequestArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class AttachRequestArguments(BaseSchema): + """ + Arguments for 'attach' request. Additional attributes are implementation specific. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "__restart": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Optional data from the previous, restarted session.\nThe data is sent as the 'restart' attribute of the 'terminated' event.\nThe client should leave the data intact." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, __restart=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] __restart: Optional data from the previous, restarted session. + The data is sent as the 'restart' attribute of the 'terminated' event. + The client should leave the data intact. + """ + self.__restart = __restart + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + __restart = self.__restart + dct = { + } + if __restart is not None: + dct['__restart'] = __restart + dct.update(self.kwargs) + return dct + + +@register_response('attach') +@register +class AttachResponse(BaseSchema): + """ + Response to 'attach' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('restart') +@register +class RestartRequest(BaseSchema): + """ + Restarts a debug session. If the capability 'supportsRestartRequest' is missing or has the value + false, + + the client will implement 'restart' by terminating the debug adapter first and then launching it + anew. + + A debug adapter can override this default behaviour by implementing a restart request + + and setting the capability 'supportsRestartRequest' to true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "restart" + ] + }, + "arguments": { + "type": "RestartArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param RestartArguments arguments: + """ + self.type = 'request' + self.command = 'restart' + self.seq = seq + if arguments is None: + self.arguments = RestartArguments() + else: + self.arguments = RestartArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != RestartArguments else arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class RestartArguments(BaseSchema): + """ + Arguments for 'restart' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register_response('restart') +@register +class RestartResponse(BaseSchema): + """ + Response to 'restart' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('disconnect') +@register +class DisconnectRequest(BaseSchema): + """ + The 'disconnect' request is sent from the client to the debug adapter in order to stop debugging. It + asks the debug adapter to disconnect from the debuggee and to terminate the debug adapter. If the + debuggee has been started with the 'launch' request, the 'disconnect' request terminates the + debuggee. If the 'attach' request was used to connect to the debuggee, 'disconnect' does not + terminate the debuggee. This behavior can be controlled with the 'terminateDebuggee' argument (if + supported by the debug adapter). + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "disconnect" + ] + }, + "arguments": { + "type": "DisconnectArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param DisconnectArguments arguments: + """ + self.type = 'request' + self.command = 'disconnect' + self.seq = seq + if arguments is None: + self.arguments = DisconnectArguments() + else: + self.arguments = DisconnectArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != DisconnectArguments else arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class DisconnectArguments(BaseSchema): + """ + Arguments for 'disconnect' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "restart": { + "type": "boolean", + "description": "A value of true indicates that this 'disconnect' request is part of a restart sequence." + }, + "terminateDebuggee": { + "type": "boolean", + "description": "Indicates whether the debuggee should be terminated when the debugger is disconnected.\nIf unspecified, the debug adapter is free to do whatever it thinks is best.\nA client can only rely on this attribute being properly honored if a debug adapter returns true for the 'supportTerminateDebuggee' capability." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, restart=None, terminateDebuggee=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean restart: A value of true indicates that this 'disconnect' request is part of a restart sequence. + :param boolean terminateDebuggee: Indicates whether the debuggee should be terminated when the debugger is disconnected. + If unspecified, the debug adapter is free to do whatever it thinks is best. + A client can only rely on this attribute being properly honored if a debug adapter returns true for the 'supportTerminateDebuggee' capability. + """ + self.restart = restart + self.terminateDebuggee = terminateDebuggee + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + restart = self.restart + terminateDebuggee = self.terminateDebuggee + dct = { + } + if restart is not None: + dct['restart'] = restart + if terminateDebuggee is not None: + dct['terminateDebuggee'] = terminateDebuggee + dct.update(self.kwargs) + return dct + + +@register_response('disconnect') +@register +class DisconnectResponse(BaseSchema): + """ + Response to 'disconnect' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('terminate') +@register +class TerminateRequest(BaseSchema): + """ + The 'terminate' request is sent from the client to the debug adapter in order to give the debuggee a + chance for terminating itself. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "terminate" + ] + }, + "arguments": { + "type": "TerminateArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param TerminateArguments arguments: + """ + self.type = 'request' + self.command = 'terminate' + self.seq = seq + if arguments is None: + self.arguments = TerminateArguments() + else: + self.arguments = TerminateArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != TerminateArguments else arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class TerminateArguments(BaseSchema): + """ + Arguments for 'terminate' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "restart": { + "type": "boolean", + "description": "A value of true indicates that this 'terminate' request is part of a restart sequence." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, restart=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean restart: A value of true indicates that this 'terminate' request is part of a restart sequence. + """ + self.restart = restart + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + restart = self.restart + dct = { + } + if restart is not None: + dct['restart'] = restart + dct.update(self.kwargs) + return dct + + +@register_response('terminate') +@register +class TerminateResponse(BaseSchema): + """ + Response to 'terminate' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('setBreakpoints') +@register +class SetBreakpointsRequest(BaseSchema): + """ + Sets multiple breakpoints for a single source and clears all previous breakpoints in that source. + + To clear all breakpoint for a source, specify an empty array. + + When a breakpoint is hit, a 'stopped' event (with reason 'breakpoint') is generated. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setBreakpoints" + ] + }, + "arguments": { + "type": "SetBreakpointsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetBreakpointsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setBreakpoints' + if arguments is None: + self.arguments = SetBreakpointsArguments() + else: + self.arguments = SetBreakpointsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetBreakpointsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetBreakpointsArguments(BaseSchema): + """ + Arguments for 'setBreakpoints' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "source": { + "description": "The source location of the breakpoints; either 'source.path' or 'source.reference' must be specified.", + "type": "Source" + }, + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/SourceBreakpoint" + }, + "description": "The code locations of the breakpoints." + }, + "lines": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "Deprecated: The code locations of the breakpoints." + }, + "sourceModified": { + "type": "boolean", + "description": "A value of true indicates that the underlying source has been modified which results in new breakpoint locations." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, source, breakpoints=None, lines=None, sourceModified=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param Source source: The source location of the breakpoints; either 'source.path' or 'source.reference' must be specified. + :param array breakpoints: The code locations of the breakpoints. + :param array lines: Deprecated: The code locations of the breakpoints. + :param boolean sourceModified: A value of true indicates that the underlying source has been modified which results in new breakpoint locations. + """ + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.breakpoints = breakpoints + if update_ids_from_dap and self.breakpoints: + for o in self.breakpoints: + SourceBreakpoint.update_dict_ids_from_dap(o) + self.lines = lines + self.sourceModified = sourceModified + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + source = self.source + breakpoints = self.breakpoints + if breakpoints and hasattr(breakpoints[0], "to_dict"): + breakpoints = [x.to_dict() for x in breakpoints] + lines = self.lines + if lines and hasattr(lines[0], "to_dict"): + lines = [x.to_dict() for x in lines] + sourceModified = self.sourceModified + dct = { + 'source': source.to_dict(update_ids_to_dap=update_ids_to_dap), + } + if breakpoints is not None: + dct['breakpoints'] = [SourceBreakpoint.update_dict_ids_to_dap(o) for o in breakpoints] if (update_ids_to_dap and breakpoints) else breakpoints + if lines is not None: + dct['lines'] = lines + if sourceModified is not None: + dct['sourceModified'] = sourceModified + dct.update(self.kwargs) + return dct + + +@register_response('setBreakpoints') +@register +class SetBreakpointsResponse(BaseSchema): + """ + Response to 'setBreakpoints' request. + + Returned is information about each breakpoint created by this request. + + This includes the actual code location and whether the breakpoint could be verified. + + The breakpoints returned are in the same order as the elements of the 'breakpoints' + + (or the deprecated 'lines') array in the arguments. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the breakpoints. The array elements are in the same order as the elements of the 'breakpoints' (or the deprecated 'lines') array in the arguments." + } + }, + "required": [ + "breakpoints" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param SetBreakpointsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = SetBreakpointsResponseBody() + else: + self.body = SetBreakpointsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != SetBreakpointsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('setFunctionBreakpoints') +@register +class SetFunctionBreakpointsRequest(BaseSchema): + """ + Replaces all existing function breakpoints with new function breakpoints. + + To clear all function breakpoints, specify an empty array. + + When a function breakpoint is hit, a 'stopped' event (with reason 'function breakpoint') is + generated. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setFunctionBreakpoints" + ] + }, + "arguments": { + "type": "SetFunctionBreakpointsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetFunctionBreakpointsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setFunctionBreakpoints' + if arguments is None: + self.arguments = SetFunctionBreakpointsArguments() + else: + self.arguments = SetFunctionBreakpointsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetFunctionBreakpointsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetFunctionBreakpointsArguments(BaseSchema): + """ + Arguments for 'setFunctionBreakpoints' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/FunctionBreakpoint" + }, + "description": "The function names of the breakpoints." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, breakpoints, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array breakpoints: The function names of the breakpoints. + """ + self.breakpoints = breakpoints + if update_ids_from_dap and self.breakpoints: + for o in self.breakpoints: + FunctionBreakpoint.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + breakpoints = self.breakpoints + if breakpoints and hasattr(breakpoints[0], "to_dict"): + breakpoints = [x.to_dict() for x in breakpoints] + dct = { + 'breakpoints': [FunctionBreakpoint.update_dict_ids_to_dap(o) for o in breakpoints] if (update_ids_to_dap and breakpoints) else breakpoints, + } + dct.update(self.kwargs) + return dct + + +@register_response('setFunctionBreakpoints') +@register +class SetFunctionBreakpointsResponse(BaseSchema): + """ + Response to 'setFunctionBreakpoints' request. + + Returned is information about each breakpoint created by this request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the breakpoints. The array elements correspond to the elements of the 'breakpoints' array." + } + }, + "required": [ + "breakpoints" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param SetFunctionBreakpointsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = SetFunctionBreakpointsResponseBody() + else: + self.body = SetFunctionBreakpointsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != SetFunctionBreakpointsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('setExceptionBreakpoints') +@register +class SetExceptionBreakpointsRequest(BaseSchema): + """ + The request configures the debuggers response to thrown exceptions. If an exception is configured to + break, a 'stopped' event is fired (with reason 'exception'). + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setExceptionBreakpoints" + ] + }, + "arguments": { + "type": "SetExceptionBreakpointsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetExceptionBreakpointsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setExceptionBreakpoints' + if arguments is None: + self.arguments = SetExceptionBreakpointsArguments() + else: + self.arguments = SetExceptionBreakpointsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetExceptionBreakpointsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetExceptionBreakpointsArguments(BaseSchema): + """ + Arguments for 'setExceptionBreakpoints' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "filters": { + "type": "array", + "items": { + "type": "string" + }, + "description": "IDs of checked exception options. The set of IDs is returned via the 'exceptionBreakpointFilters' capability." + }, + "exceptionOptions": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionOptions" + }, + "description": "Configuration options for selected exceptions." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, filters, exceptionOptions=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array filters: IDs of checked exception options. The set of IDs is returned via the 'exceptionBreakpointFilters' capability. + :param array exceptionOptions: Configuration options for selected exceptions. + """ + self.filters = filters + self.exceptionOptions = exceptionOptions + if update_ids_from_dap and self.exceptionOptions: + for o in self.exceptionOptions: + ExceptionOptions.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + filters = self.filters + if filters and hasattr(filters[0], "to_dict"): + filters = [x.to_dict() for x in filters] + exceptionOptions = self.exceptionOptions + if exceptionOptions and hasattr(exceptionOptions[0], "to_dict"): + exceptionOptions = [x.to_dict() for x in exceptionOptions] + dct = { + 'filters': filters, + } + if exceptionOptions is not None: + dct['exceptionOptions'] = [ExceptionOptions.update_dict_ids_to_dap(o) for o in exceptionOptions] if (update_ids_to_dap and exceptionOptions) else exceptionOptions + dct.update(self.kwargs) + return dct + + +@register_response('setExceptionBreakpoints') +@register +class SetExceptionBreakpointsResponse(BaseSchema): + """ + Response to 'setExceptionBreakpoints' request. This is just an acknowledgement, so no body field is + required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('dataBreakpointInfo') +@register +class DataBreakpointInfoRequest(BaseSchema): + """ + Obtains information on a possible data breakpoint that could be set on an expression or variable. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "dataBreakpointInfo" + ] + }, + "arguments": { + "type": "DataBreakpointInfoArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param DataBreakpointInfoArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'dataBreakpointInfo' + if arguments is None: + self.arguments = DataBreakpointInfoArguments() + else: + self.arguments = DataBreakpointInfoArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != DataBreakpointInfoArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class DataBreakpointInfoArguments(BaseSchema): + """ + Arguments for 'dataBreakpointInfo' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "variablesReference": { + "type": "integer", + "description": "Reference to the Variable container if the data breakpoint is requested for a child of the container." + }, + "name": { + "type": "string", + "description": "The name of the Variable's child to obtain data breakpoint information for. If variableReference isn\u2019t provided, this can be an expression." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name, variablesReference=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: The name of the Variable's child to obtain data breakpoint information for. If variableReference isn’t provided, this can be an expression. + :param integer variablesReference: Reference to the Variable container if the data breakpoint is requested for a child of the container. + """ + self.name = name + self.variablesReference = variablesReference + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + variablesReference = self.variablesReference + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'name': name, + } + if variablesReference is not None: + dct['variablesReference'] = variablesReference + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register_response('dataBreakpointInfo') +@register +class DataBreakpointInfoResponse(BaseSchema): + """ + Response to 'dataBreakpointInfo' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "dataId": { + "type": [ + "string", + "null" + ], + "description": "An identifier for the data on which a data breakpoint can be registered with the setDataBreakpoints request or null if no data breakpoint is available." + }, + "description": { + "type": "string", + "description": "UI string that describes on what data the breakpoint is set on or why a data breakpoint is not available." + }, + "accessTypes": { + "type": "array", + "items": { + "$ref": "#/definitions/DataBreakpointAccessType" + }, + "description": "Optional attribute listing the available access types for a potential data breakpoint. A UI frontend could surface this information." + }, + "canPersist": { + "type": "boolean", + "description": "Optional attribute indicating that a potential data breakpoint could be persisted across sessions." + } + }, + "required": [ + "dataId", + "description" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param DataBreakpointInfoResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = DataBreakpointInfoResponseBody() + else: + self.body = DataBreakpointInfoResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != DataBreakpointInfoResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('setDataBreakpoints') +@register +class SetDataBreakpointsRequest(BaseSchema): + """ + Replaces all existing data breakpoints with new data breakpoints. + + To clear all data breakpoints, specify an empty array. + + When a data breakpoint is hit, a 'stopped' event (with reason 'data breakpoint') is generated. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setDataBreakpoints" + ] + }, + "arguments": { + "type": "SetDataBreakpointsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetDataBreakpointsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setDataBreakpoints' + if arguments is None: + self.arguments = SetDataBreakpointsArguments() + else: + self.arguments = SetDataBreakpointsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetDataBreakpointsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetDataBreakpointsArguments(BaseSchema): + """ + Arguments for 'setDataBreakpoints' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/DataBreakpoint" + }, + "description": "The contents of this array replaces all existing data breakpoints. An empty array clears all data breakpoints." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, breakpoints, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array breakpoints: The contents of this array replaces all existing data breakpoints. An empty array clears all data breakpoints. + """ + self.breakpoints = breakpoints + if update_ids_from_dap and self.breakpoints: + for o in self.breakpoints: + DataBreakpoint.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + breakpoints = self.breakpoints + if breakpoints and hasattr(breakpoints[0], "to_dict"): + breakpoints = [x.to_dict() for x in breakpoints] + dct = { + 'breakpoints': [DataBreakpoint.update_dict_ids_to_dap(o) for o in breakpoints] if (update_ids_to_dap and breakpoints) else breakpoints, + } + dct.update(self.kwargs) + return dct + + +@register_response('setDataBreakpoints') +@register +class SetDataBreakpointsResponse(BaseSchema): + """ + Response to 'setDataBreakpoints' request. + + Returned is information about each breakpoint created by this request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the data breakpoints. The array elements correspond to the elements of the input argument 'breakpoints' array." + } + }, + "required": [ + "breakpoints" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param SetDataBreakpointsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = SetDataBreakpointsResponseBody() + else: + self.body = SetDataBreakpointsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != SetDataBreakpointsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('continue') +@register +class ContinueRequest(BaseSchema): + """ + The request starts the debuggee to run again. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "continue" + ] + }, + "arguments": { + "type": "ContinueArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param ContinueArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'continue' + if arguments is None: + self.arguments = ContinueArguments() + else: + self.arguments = ContinueArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ContinueArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class ContinueArguments(BaseSchema): + """ + Arguments for 'continue' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Continue execution for the specified thread (if possible). If the backend cannot continue on a single thread but will continue on all threads, it should set the 'allThreadsContinued' attribute in the response to true." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Continue execution for the specified thread (if possible). If the backend cannot continue on a single thread but will continue on all threads, it should set the 'allThreadsContinued' attribute in the response to true. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('continue') +@register +class ContinueResponse(BaseSchema): + """ + Response to 'continue' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "allThreadsContinued": { + "type": "boolean", + "description": "If true, the 'continue' request has ignored the specified thread and continued all threads instead. If this attribute is missing a value of 'true' is assumed for backward compatibility." + } + } + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param ContinueResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = ContinueResponseBody() + else: + self.body = ContinueResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ContinueResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('next') +@register +class NextRequest(BaseSchema): + """ + The request starts the debuggee to run again for one step. + + The debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the + step has completed. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "next" + ] + }, + "arguments": { + "type": "NextArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param NextArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'next' + if arguments is None: + self.arguments = NextArguments() + else: + self.arguments = NextArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != NextArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class NextArguments(BaseSchema): + """ + Arguments for 'next' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Execute 'next' for this thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Execute 'next' for this thread. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('next') +@register +class NextResponse(BaseSchema): + """ + Response to 'next' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('stepIn') +@register +class StepInRequest(BaseSchema): + """ + The request starts the debuggee to step into a function/method if possible. + + If it cannot step into a target, 'stepIn' behaves like 'next'. + + The debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the + step has completed. + + If there are multiple function/method calls (or other targets) on the source line, + + the optional argument 'targetId' can be used to control into which target the 'stepIn' should occur. + + The list of possible targets for a given source line can be retrieved via the 'stepInTargets' + request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "stepIn" + ] + }, + "arguments": { + "type": "StepInArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param StepInArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'stepIn' + if arguments is None: + self.arguments = StepInArguments() + else: + self.arguments = StepInArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != StepInArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class StepInArguments(BaseSchema): + """ + Arguments for 'stepIn' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Execute 'stepIn' for this thread." + }, + "targetId": { + "type": "integer", + "description": "Optional id of the target to step into." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, targetId=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Execute 'stepIn' for this thread. + :param integer targetId: Optional id of the target to step into. + """ + self.threadId = threadId + self.targetId = targetId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + targetId = self.targetId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + if targetId is not None: + dct['targetId'] = targetId + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('stepIn') +@register +class StepInResponse(BaseSchema): + """ + Response to 'stepIn' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('stepOut') +@register +class StepOutRequest(BaseSchema): + """ + The request starts the debuggee to run again for one step. + + The debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the + step has completed. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "stepOut" + ] + }, + "arguments": { + "type": "StepOutArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param StepOutArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'stepOut' + if arguments is None: + self.arguments = StepOutArguments() + else: + self.arguments = StepOutArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != StepOutArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class StepOutArguments(BaseSchema): + """ + Arguments for 'stepOut' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Execute 'stepOut' for this thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Execute 'stepOut' for this thread. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('stepOut') +@register +class StepOutResponse(BaseSchema): + """ + Response to 'stepOut' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('stepBack') +@register +class StepBackRequest(BaseSchema): + """ + The request starts the debuggee to run one step backwards. + + The debug adapter first sends the response and then a 'stopped' event (with reason 'step') after the + step has completed. Clients should only call this request if the capability 'supportsStepBack' is + true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "stepBack" + ] + }, + "arguments": { + "type": "StepBackArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param StepBackArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'stepBack' + if arguments is None: + self.arguments = StepBackArguments() + else: + self.arguments = StepBackArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != StepBackArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class StepBackArguments(BaseSchema): + """ + Arguments for 'stepBack' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Execute 'stepBack' for this thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Execute 'stepBack' for this thread. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('stepBack') +@register +class StepBackResponse(BaseSchema): + """ + Response to 'stepBack' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('reverseContinue') +@register +class ReverseContinueRequest(BaseSchema): + """ + The request starts the debuggee to run backward. Clients should only call this request if the + capability 'supportsStepBack' is true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "reverseContinue" + ] + }, + "arguments": { + "type": "ReverseContinueArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param ReverseContinueArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'reverseContinue' + if arguments is None: + self.arguments = ReverseContinueArguments() + else: + self.arguments = ReverseContinueArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ReverseContinueArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class ReverseContinueArguments(BaseSchema): + """ + Arguments for 'reverseContinue' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Execute 'reverseContinue' for this thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Execute 'reverseContinue' for this thread. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('reverseContinue') +@register +class ReverseContinueResponse(BaseSchema): + """ + Response to 'reverseContinue' request. This is just an acknowledgement, so no body field is + required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('restartFrame') +@register +class RestartFrameRequest(BaseSchema): + """ + The request restarts execution of the specified stackframe. + + The debug adapter first sends the response and then a 'stopped' event (with reason 'restart') after + the restart has completed. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "restartFrame" + ] + }, + "arguments": { + "type": "RestartFrameArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param RestartFrameArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'restartFrame' + if arguments is None: + self.arguments = RestartFrameArguments() + else: + self.arguments = RestartFrameArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != RestartFrameArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class RestartFrameArguments(BaseSchema): + """ + Arguments for 'restartFrame' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "frameId": { + "type": "integer", + "description": "Restart this stackframe." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, frameId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer frameId: Restart this stackframe. + """ + self.frameId = frameId + if update_ids_from_dap: + self.frameId = self._translate_id_from_dap(self.frameId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_from_dap(dct['frameId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + frameId = self.frameId + if update_ids_to_dap: + if frameId is not None: + frameId = self._translate_id_to_dap(frameId) + dct = { + 'frameId': frameId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_to_dap(dct['frameId']) + return dct + + +@register_response('restartFrame') +@register +class RestartFrameResponse(BaseSchema): + """ + Response to 'restartFrame' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('goto') +@register +class GotoRequest(BaseSchema): + """ + The request sets the location where the debuggee will continue to run. + + This makes it possible to skip the execution of code or to executed code again. + + The code between the current location and the goto target is not executed but skipped. + + The debug adapter first sends the response and then a 'stopped' event with reason 'goto'. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "goto" + ] + }, + "arguments": { + "type": "GotoArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param GotoArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'goto' + if arguments is None: + self.arguments = GotoArguments() + else: + self.arguments = GotoArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != GotoArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class GotoArguments(BaseSchema): + """ + Arguments for 'goto' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Set the goto target for this thread." + }, + "targetId": { + "type": "integer", + "description": "The location where the debuggee will continue to run." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, targetId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Set the goto target for this thread. + :param integer targetId: The location where the debuggee will continue to run. + """ + self.threadId = threadId + self.targetId = targetId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + targetId = self.targetId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + 'targetId': targetId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('goto') +@register +class GotoResponse(BaseSchema): + """ + Response to 'goto' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('pause') +@register +class PauseRequest(BaseSchema): + """ + The request suspenses the debuggee. + + The debug adapter first sends the response and then a 'stopped' event (with reason 'pause') after + the thread has been paused successfully. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "pause" + ] + }, + "arguments": { + "type": "PauseArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param PauseArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'pause' + if arguments is None: + self.arguments = PauseArguments() + else: + self.arguments = PauseArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != PauseArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class PauseArguments(BaseSchema): + """ + Arguments for 'pause' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Pause execution for this thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Pause execution for this thread. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('pause') +@register +class PauseResponse(BaseSchema): + """ + Response to 'pause' request. This is just an acknowledgement, so no body field is required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('stackTrace') +@register +class StackTraceRequest(BaseSchema): + """ + The request returns a stacktrace from the current execution state. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "stackTrace" + ] + }, + "arguments": { + "type": "StackTraceArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param StackTraceArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'stackTrace' + if arguments is None: + self.arguments = StackTraceArguments() + else: + self.arguments = StackTraceArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != StackTraceArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class StackTraceArguments(BaseSchema): + """ + Arguments for 'stackTrace' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Retrieve the stacktrace for this thread." + }, + "startFrame": { + "type": "integer", + "description": "The index of the first frame to return; if omitted frames start at 0." + }, + "levels": { + "type": "integer", + "description": "The maximum number of frames to return. If levels is not specified or 0, all frames are returned." + }, + "format": { + "description": "Specifies details on how to format the stack frames.", + "type": "StackFrameFormat" + } + } + __refs__ = set(['format']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, startFrame=None, levels=None, format=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Retrieve the stacktrace for this thread. + :param integer startFrame: The index of the first frame to return; if omitted frames start at 0. + :param integer levels: The maximum number of frames to return. If levels is not specified or 0, all frames are returned. + :param StackFrameFormat format: Specifies details on how to format the stack frames. + """ + self.threadId = threadId + self.startFrame = startFrame + self.levels = levels + if format is None: + self.format = StackFrameFormat() + else: + self.format = StackFrameFormat(update_ids_from_dap=update_ids_from_dap, **format) if format.__class__ != StackFrameFormat else format + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + startFrame = self.startFrame + levels = self.levels + format = self.format # noqa (assign to builtin) + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + if startFrame is not None: + dct['startFrame'] = startFrame + if levels is not None: + dct['levels'] = levels + if format is not None: + dct['format'] = format.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('stackTrace') +@register +class StackTraceResponse(BaseSchema): + """ + Response to 'stackTrace' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "stackFrames": { + "type": "array", + "items": { + "$ref": "#/definitions/StackFrame" + }, + "description": "The frames of the stackframe. If the array has length zero, there are no stackframes available.\nThis means that there is no location information available." + }, + "totalFrames": { + "type": "integer", + "description": "The total number of frames available." + } + }, + "required": [ + "stackFrames" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param StackTraceResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = StackTraceResponseBody() + else: + self.body = StackTraceResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != StackTraceResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('scopes') +@register +class ScopesRequest(BaseSchema): + """ + The request returns the variable scopes for a given stackframe ID. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "scopes" + ] + }, + "arguments": { + "type": "ScopesArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param ScopesArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'scopes' + if arguments is None: + self.arguments = ScopesArguments() + else: + self.arguments = ScopesArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ScopesArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class ScopesArguments(BaseSchema): + """ + Arguments for 'scopes' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "frameId": { + "type": "integer", + "description": "Retrieve the scopes for this stackframe." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, frameId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer frameId: Retrieve the scopes for this stackframe. + """ + self.frameId = frameId + if update_ids_from_dap: + self.frameId = self._translate_id_from_dap(self.frameId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_from_dap(dct['frameId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + frameId = self.frameId + if update_ids_to_dap: + if frameId is not None: + frameId = self._translate_id_to_dap(frameId) + dct = { + 'frameId': frameId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_to_dap(dct['frameId']) + return dct + + +@register_response('scopes') +@register +class ScopesResponse(BaseSchema): + """ + Response to 'scopes' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "scopes": { + "type": "array", + "items": { + "$ref": "#/definitions/Scope" + }, + "description": "The scopes of the stackframe. If the array has length zero, there are no scopes available." + } + }, + "required": [ + "scopes" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param ScopesResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = ScopesResponseBody() + else: + self.body = ScopesResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ScopesResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('variables') +@register +class VariablesRequest(BaseSchema): + """ + Retrieves all child variables for the given variable reference. + + An optional filter can be used to limit the fetched children to either named or indexed children. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "variables" + ] + }, + "arguments": { + "type": "VariablesArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param VariablesArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'variables' + if arguments is None: + self.arguments = VariablesArguments() + else: + self.arguments = VariablesArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != VariablesArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class VariablesArguments(BaseSchema): + """ + Arguments for 'variables' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "variablesReference": { + "type": "integer", + "description": "The Variable reference." + }, + "filter": { + "type": "string", + "enum": [ + "indexed", + "named" + ], + "description": "Optional filter to limit the child variables to either named or indexed. If ommited, both types are fetched." + }, + "start": { + "type": "integer", + "description": "The index of the first variable to return; if omitted children start at 0." + }, + "count": { + "type": "integer", + "description": "The number of variables to return. If count is missing or 0, all variables are returned." + }, + "format": { + "description": "Specifies details on how to format the Variable values.", + "type": "ValueFormat" + } + } + __refs__ = set(['format']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, variablesReference, filter=None, start=None, count=None, format=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer variablesReference: The Variable reference. + :param string filter: Optional filter to limit the child variables to either named or indexed. If ommited, both types are fetched. + :param integer start: The index of the first variable to return; if omitted children start at 0. + :param integer count: The number of variables to return. If count is missing or 0, all variables are returned. + :param ValueFormat format: Specifies details on how to format the Variable values. + """ + self.variablesReference = variablesReference + self.filter = filter + self.start = start + self.count = count + if format is None: + self.format = ValueFormat() + else: + self.format = ValueFormat(update_ids_from_dap=update_ids_from_dap, **format) if format.__class__ != ValueFormat else format + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + variablesReference = self.variablesReference + filter = self.filter # noqa (assign to builtin) + start = self.start + count = self.count + format = self.format # noqa (assign to builtin) + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'variablesReference': variablesReference, + } + if filter is not None: + dct['filter'] = filter + if start is not None: + dct['start'] = start + if count is not None: + dct['count'] = count + if format is not None: + dct['format'] = format.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register_response('variables') +@register +class VariablesResponse(BaseSchema): + """ + Response to 'variables' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "variables": { + "type": "array", + "items": { + "$ref": "#/definitions/Variable" + }, + "description": "All (or a range) of variables for the given variable reference." + } + }, + "required": [ + "variables" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param VariablesResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = VariablesResponseBody() + else: + self.body = VariablesResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != VariablesResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('setVariable') +@register +class SetVariableRequest(BaseSchema): + """ + Set the variable with the given name in the variable container to a new value. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setVariable" + ] + }, + "arguments": { + "type": "SetVariableArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetVariableArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setVariable' + if arguments is None: + self.arguments = SetVariableArguments() + else: + self.arguments = SetVariableArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetVariableArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetVariableArguments(BaseSchema): + """ + Arguments for 'setVariable' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "variablesReference": { + "type": "integer", + "description": "The reference of the variable container." + }, + "name": { + "type": "string", + "description": "The name of the variable in the container." + }, + "value": { + "type": "string", + "description": "The value of the variable." + }, + "format": { + "description": "Specifies details on how to format the response value.", + "type": "ValueFormat" + } + } + __refs__ = set(['format']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, variablesReference, name, value, format=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer variablesReference: The reference of the variable container. + :param string name: The name of the variable in the container. + :param string value: The value of the variable. + :param ValueFormat format: Specifies details on how to format the response value. + """ + self.variablesReference = variablesReference + self.name = name + self.value = value + if format is None: + self.format = ValueFormat() + else: + self.format = ValueFormat(update_ids_from_dap=update_ids_from_dap, **format) if format.__class__ != ValueFormat else format + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + variablesReference = self.variablesReference + name = self.name + value = self.value + format = self.format # noqa (assign to builtin) + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'variablesReference': variablesReference, + 'name': name, + 'value': value, + } + if format is not None: + dct['format'] = format.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register_response('setVariable') +@register +class SetVariableResponse(BaseSchema): + """ + Response to 'setVariable' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "value": { + "type": "string", + "description": "The new value of the variable." + }, + "type": { + "type": "string", + "description": "The type of the new value. Typically shown in the UI when hovering over the value." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the new value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + } + }, + "required": [ + "value" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param SetVariableResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = SetVariableResponseBody() + else: + self.body = SetVariableResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != SetVariableResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('source') +@register +class SourceRequest(BaseSchema): + """ + The request retrieves the source code for a given source reference. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "source" + ] + }, + "arguments": { + "type": "SourceArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SourceArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'source' + if arguments is None: + self.arguments = SourceArguments() + else: + self.arguments = SourceArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SourceArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SourceArguments(BaseSchema): + """ + Arguments for 'source' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "source": { + "description": "Specifies the source content to load. Either source.path or source.sourceReference must be specified.", + "type": "Source" + }, + "sourceReference": { + "type": "integer", + "description": "The reference to the source. This is the same as source.sourceReference. This is provided for backward compatibility since old backends do not understand the 'source' attribute." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, sourceReference, source=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer sourceReference: The reference to the source. This is the same as source.sourceReference. This is provided for backward compatibility since old backends do not understand the 'source' attribute. + :param Source source: Specifies the source content to load. Either source.path or source.sourceReference must be specified. + """ + self.sourceReference = sourceReference + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + sourceReference = self.sourceReference + source = self.source + dct = { + 'sourceReference': sourceReference, + } + if source is not None: + dct['source'] = source.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register_response('source') +@register +class SourceResponse(BaseSchema): + """ + Response to 'source' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "content": { + "type": "string", + "description": "Content of the source reference." + }, + "mimeType": { + "type": "string", + "description": "Optional content type (mime type) of the source." + } + }, + "required": [ + "content" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param SourceResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = SourceResponseBody() + else: + self.body = SourceResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != SourceResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('threads') +@register +class ThreadsRequest(BaseSchema): + """ + The request retrieves a list of all threads. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "threads" + ] + }, + "arguments": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Object containing arguments for the command." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] arguments: Object containing arguments for the command. + """ + self.type = 'request' + self.command = 'threads' + self.seq = seq + self.arguments = arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments + dct.update(self.kwargs) + return dct + + +@register_response('threads') +@register +class ThreadsResponse(BaseSchema): + """ + Response to 'threads' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "threads": { + "type": "array", + "items": { + "$ref": "#/definitions/Thread" + }, + "description": "All threads." + } + }, + "required": [ + "threads" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param ThreadsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = ThreadsResponseBody() + else: + self.body = ThreadsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ThreadsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('terminateThreads') +@register +class TerminateThreadsRequest(BaseSchema): + """ + The request terminates the threads with the given ids. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "terminateThreads" + ] + }, + "arguments": { + "type": "TerminateThreadsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param TerminateThreadsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'terminateThreads' + if arguments is None: + self.arguments = TerminateThreadsArguments() + else: + self.arguments = TerminateThreadsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != TerminateThreadsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class TerminateThreadsArguments(BaseSchema): + """ + Arguments for 'terminateThreads' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadIds": { + "type": "array", + "items": { + "type": "integer" + }, + "description": "Ids of threads to be terminated." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadIds=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array threadIds: Ids of threads to be terminated. + """ + self.threadIds = threadIds + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadIds = self.threadIds + if threadIds and hasattr(threadIds[0], "to_dict"): + threadIds = [x.to_dict() for x in threadIds] + dct = { + } + if threadIds is not None: + dct['threadIds'] = threadIds + dct.update(self.kwargs) + return dct + + +@register_response('terminateThreads') +@register +class TerminateThreadsResponse(BaseSchema): + """ + Response to 'terminateThreads' request. This is just an acknowledgement, so no body field is + required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('modules') +@register +class ModulesRequest(BaseSchema): + """ + Modules can be retrieved from the debug adapter with the ModulesRequest which can either return all + modules or a range of modules to support paging. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "modules" + ] + }, + "arguments": { + "type": "ModulesArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param ModulesArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'modules' + if arguments is None: + self.arguments = ModulesArguments() + else: + self.arguments = ModulesArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ModulesArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class ModulesArguments(BaseSchema): + """ + Arguments for 'modules' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "startModule": { + "type": "integer", + "description": "The index of the first module to return; if omitted modules start at 0." + }, + "moduleCount": { + "type": "integer", + "description": "The number of modules to return. If moduleCount is not specified or 0, all modules are returned." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, startModule=None, moduleCount=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer startModule: The index of the first module to return; if omitted modules start at 0. + :param integer moduleCount: The number of modules to return. If moduleCount is not specified or 0, all modules are returned. + """ + self.startModule = startModule + self.moduleCount = moduleCount + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + startModule = self.startModule + moduleCount = self.moduleCount + dct = { + } + if startModule is not None: + dct['startModule'] = startModule + if moduleCount is not None: + dct['moduleCount'] = moduleCount + dct.update(self.kwargs) + return dct + + +@register_response('modules') +@register +class ModulesResponse(BaseSchema): + """ + Response to 'modules' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "modules": { + "type": "array", + "items": { + "$ref": "#/definitions/Module" + }, + "description": "All modules or range of modules." + }, + "totalModules": { + "type": "integer", + "description": "The total number of modules available." + } + }, + "required": [ + "modules" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param ModulesResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = ModulesResponseBody() + else: + self.body = ModulesResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ModulesResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('loadedSources') +@register +class LoadedSourcesRequest(BaseSchema): + """ + Retrieves the set of all sources currently loaded by the debugged process. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "loadedSources" + ] + }, + "arguments": { + "type": "LoadedSourcesArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param LoadedSourcesArguments arguments: + """ + self.type = 'request' + self.command = 'loadedSources' + self.seq = seq + if arguments is None: + self.arguments = LoadedSourcesArguments() + else: + self.arguments = LoadedSourcesArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != LoadedSourcesArguments else arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class LoadedSourcesArguments(BaseSchema): + """ + Arguments for 'loadedSources' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register_response('loadedSources') +@register +class LoadedSourcesResponse(BaseSchema): + """ + Response to 'loadedSources' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "sources": { + "type": "array", + "items": { + "$ref": "#/definitions/Source" + }, + "description": "Set of loaded sources." + } + }, + "required": [ + "sources" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param LoadedSourcesResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = LoadedSourcesResponseBody() + else: + self.body = LoadedSourcesResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != LoadedSourcesResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('evaluate') +@register +class EvaluateRequest(BaseSchema): + """ + Evaluates the given expression in the context of the top most stack frame. + + The expression has access to any variables and arguments that are in scope. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "evaluate" + ] + }, + "arguments": { + "type": "EvaluateArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param EvaluateArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'evaluate' + if arguments is None: + self.arguments = EvaluateArguments() + else: + self.arguments = EvaluateArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != EvaluateArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class EvaluateArguments(BaseSchema): + """ + Arguments for 'evaluate' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "expression": { + "type": "string", + "description": "The expression to evaluate." + }, + "frameId": { + "type": "integer", + "description": "Evaluate the expression in the scope of this stack frame. If not specified, the expression is evaluated in the global scope." + }, + "context": { + "type": "string", + "_enum": [ + "watch", + "repl", + "hover" + ], + "enumDescriptions": [ + "evaluate is run in a watch.", + "evaluate is run from REPL console.", + "evaluate is run from a data hover." + ], + "description": "The context in which the evaluate request is run." + }, + "format": { + "description": "Specifies details on how to format the Evaluate result.", + "type": "ValueFormat" + } + } + __refs__ = set(['format']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, expression, frameId=None, context=None, format=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string expression: The expression to evaluate. + :param integer frameId: Evaluate the expression in the scope of this stack frame. If not specified, the expression is evaluated in the global scope. + :param string context: The context in which the evaluate request is run. + :param ValueFormat format: Specifies details on how to format the Evaluate result. + """ + self.expression = expression + self.frameId = frameId + self.context = context + if format is None: + self.format = ValueFormat() + else: + self.format = ValueFormat(update_ids_from_dap=update_ids_from_dap, **format) if format.__class__ != ValueFormat else format + if update_ids_from_dap: + self.frameId = self._translate_id_from_dap(self.frameId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_from_dap(dct['frameId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + expression = self.expression + frameId = self.frameId + context = self.context + format = self.format # noqa (assign to builtin) + if update_ids_to_dap: + if frameId is not None: + frameId = self._translate_id_to_dap(frameId) + dct = { + 'expression': expression, + } + if frameId is not None: + dct['frameId'] = frameId + if context is not None: + dct['context'] = context + if format is not None: + dct['format'] = format.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_to_dap(dct['frameId']) + return dct + + +@register_response('evaluate') +@register +class EvaluateResponse(BaseSchema): + """ + Response to 'evaluate' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "result": { + "type": "string", + "description": "The result of the evaluate request." + }, + "type": { + "type": "string", + "description": "The optional type of the evaluate result." + }, + "presentationHint": { + "$ref": "#/definitions/VariablePresentationHint", + "description": "Properties of a evaluate result that can be used to determine how to render the result in the UI." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the evaluate result is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "memoryReference": { + "type": "string", + "description": "Memory reference to a location appropriate for this result. For pointer type eval results, this is generally a reference to the memory address contained in the pointer." + } + }, + "required": [ + "result", + "variablesReference" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param EvaluateResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = EvaluateResponseBody() + else: + self.body = EvaluateResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != EvaluateResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('setExpression') +@register +class SetExpressionRequest(BaseSchema): + """ + Evaluates the given 'value' expression and assigns it to the 'expression' which must be a modifiable + l-value. + + The expressions have access to any variables and arguments that are in scope of the specified frame. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setExpression" + ] + }, + "arguments": { + "type": "SetExpressionArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetExpressionArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setExpression' + if arguments is None: + self.arguments = SetExpressionArguments() + else: + self.arguments = SetExpressionArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetExpressionArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetExpressionArguments(BaseSchema): + """ + Arguments for 'setExpression' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "expression": { + "type": "string", + "description": "The l-value expression to assign to." + }, + "value": { + "type": "string", + "description": "The value expression to assign to the l-value expression." + }, + "frameId": { + "type": "integer", + "description": "Evaluate the expressions in the scope of this stack frame. If not specified, the expressions are evaluated in the global scope." + }, + "format": { + "description": "Specifies how the resulting value should be formatted.", + "type": "ValueFormat" + } + } + __refs__ = set(['format']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, expression, value, frameId=None, format=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string expression: The l-value expression to assign to. + :param string value: The value expression to assign to the l-value expression. + :param integer frameId: Evaluate the expressions in the scope of this stack frame. If not specified, the expressions are evaluated in the global scope. + :param ValueFormat format: Specifies how the resulting value should be formatted. + """ + self.expression = expression + self.value = value + self.frameId = frameId + if format is None: + self.format = ValueFormat() + else: + self.format = ValueFormat(update_ids_from_dap=update_ids_from_dap, **format) if format.__class__ != ValueFormat else format + if update_ids_from_dap: + self.frameId = self._translate_id_from_dap(self.frameId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_from_dap(dct['frameId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + expression = self.expression + value = self.value + frameId = self.frameId + format = self.format # noqa (assign to builtin) + if update_ids_to_dap: + if frameId is not None: + frameId = self._translate_id_to_dap(frameId) + dct = { + 'expression': expression, + 'value': value, + } + if frameId is not None: + dct['frameId'] = frameId + if format is not None: + dct['format'] = format.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_to_dap(dct['frameId']) + return dct + + +@register_response('setExpression') +@register +class SetExpressionResponse(BaseSchema): + """ + Response to 'setExpression' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "value": { + "type": "string", + "description": "The new value of the expression." + }, + "type": { + "type": "string", + "description": "The optional type of the value." + }, + "presentationHint": { + "$ref": "#/definitions/VariablePresentationHint", + "description": "Properties of a value that can be used to determine how to render the result in the UI." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + } + }, + "required": [ + "value" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param SetExpressionResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = SetExpressionResponseBody() + else: + self.body = SetExpressionResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != SetExpressionResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('stepInTargets') +@register +class StepInTargetsRequest(BaseSchema): + """ + This request retrieves the possible stepIn targets for the specified stack frame. + + These targets can be used in the 'stepIn' request. + + The StepInTargets may only be called if the 'supportsStepInTargetsRequest' capability exists and is + true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "stepInTargets" + ] + }, + "arguments": { + "type": "StepInTargetsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param StepInTargetsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'stepInTargets' + if arguments is None: + self.arguments = StepInTargetsArguments() + else: + self.arguments = StepInTargetsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != StepInTargetsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class StepInTargetsArguments(BaseSchema): + """ + Arguments for 'stepInTargets' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "frameId": { + "type": "integer", + "description": "The stack frame for which to retrieve the possible stepIn targets." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, frameId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer frameId: The stack frame for which to retrieve the possible stepIn targets. + """ + self.frameId = frameId + if update_ids_from_dap: + self.frameId = self._translate_id_from_dap(self.frameId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_from_dap(dct['frameId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + frameId = self.frameId + if update_ids_to_dap: + if frameId is not None: + frameId = self._translate_id_to_dap(frameId) + dct = { + 'frameId': frameId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_to_dap(dct['frameId']) + return dct + + +@register_response('stepInTargets') +@register +class StepInTargetsResponse(BaseSchema): + """ + Response to 'stepInTargets' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/StepInTarget" + }, + "description": "The possible stepIn targets of the specified source location." + } + }, + "required": [ + "targets" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param StepInTargetsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = StepInTargetsResponseBody() + else: + self.body = StepInTargetsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != StepInTargetsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('gotoTargets') +@register +class GotoTargetsRequest(BaseSchema): + """ + This request retrieves the possible goto targets for the specified source location. + + These targets can be used in the 'goto' request. + + The GotoTargets request may only be called if the 'supportsGotoTargetsRequest' capability exists and + is true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "gotoTargets" + ] + }, + "arguments": { + "type": "GotoTargetsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param GotoTargetsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'gotoTargets' + if arguments is None: + self.arguments = GotoTargetsArguments() + else: + self.arguments = GotoTargetsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != GotoTargetsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class GotoTargetsArguments(BaseSchema): + """ + Arguments for 'gotoTargets' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "source": { + "description": "The source location for which the goto targets are determined.", + "type": "Source" + }, + "line": { + "type": "integer", + "description": "The line location for which the goto targets are determined." + }, + "column": { + "type": "integer", + "description": "An optional column location for which the goto targets are determined." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, source, line, column=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param Source source: The source location for which the goto targets are determined. + :param integer line: The line location for which the goto targets are determined. + :param integer column: An optional column location for which the goto targets are determined. + """ + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.line = line + self.column = column + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + source = self.source + line = self.line + column = self.column + dct = { + 'source': source.to_dict(update_ids_to_dap=update_ids_to_dap), + 'line': line, + } + if column is not None: + dct['column'] = column + dct.update(self.kwargs) + return dct + + +@register_response('gotoTargets') +@register +class GotoTargetsResponse(BaseSchema): + """ + Response to 'gotoTargets' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/GotoTarget" + }, + "description": "The possible goto targets of the specified location." + } + }, + "required": [ + "targets" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param GotoTargetsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = GotoTargetsResponseBody() + else: + self.body = GotoTargetsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != GotoTargetsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('completions') +@register +class CompletionsRequest(BaseSchema): + """ + Returns a list of possible completions for a given caret position and text. + + The CompletionsRequest may only be called if the 'supportsCompletionsRequest' capability exists and + is true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "completions" + ] + }, + "arguments": { + "type": "CompletionsArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param CompletionsArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'completions' + if arguments is None: + self.arguments = CompletionsArguments() + else: + self.arguments = CompletionsArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != CompletionsArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class CompletionsArguments(BaseSchema): + """ + Arguments for 'completions' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "frameId": { + "type": "integer", + "description": "Returns completions in the scope of this stack frame. If not specified, the completions are returned for the global scope." + }, + "text": { + "type": "string", + "description": "One or more source lines. Typically this is the text a user has typed into the debug console before he asked for completion." + }, + "column": { + "type": "integer", + "description": "The character position for which to determine the completion proposals." + }, + "line": { + "type": "integer", + "description": "An optional line for which to determine the completion proposals. If missing the first line of the text is assumed." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, text, column, frameId=None, line=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string text: One or more source lines. Typically this is the text a user has typed into the debug console before he asked for completion. + :param integer column: The character position for which to determine the completion proposals. + :param integer frameId: Returns completions in the scope of this stack frame. If not specified, the completions are returned for the global scope. + :param integer line: An optional line for which to determine the completion proposals. If missing the first line of the text is assumed. + """ + self.text = text + self.column = column + self.frameId = frameId + self.line = line + if update_ids_from_dap: + self.frameId = self._translate_id_from_dap(self.frameId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_from_dap(dct['frameId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + text = self.text + column = self.column + frameId = self.frameId + line = self.line + if update_ids_to_dap: + if frameId is not None: + frameId = self._translate_id_to_dap(frameId) + dct = { + 'text': text, + 'column': column, + } + if frameId is not None: + dct['frameId'] = frameId + if line is not None: + dct['line'] = line + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'frameId' in dct: + dct['frameId'] = cls._translate_id_to_dap(dct['frameId']) + return dct + + +@register_response('completions') +@register +class CompletionsResponse(BaseSchema): + """ + Response to 'completions' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/CompletionItem" + }, + "description": "The possible completions for ." + } + }, + "required": [ + "targets" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param CompletionsResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = CompletionsResponseBody() + else: + self.body = CompletionsResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != CompletionsResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('exceptionInfo') +@register +class ExceptionInfoRequest(BaseSchema): + """ + Retrieves the details of the exception that caused this event to be raised. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "exceptionInfo" + ] + }, + "arguments": { + "type": "ExceptionInfoArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param ExceptionInfoArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'exceptionInfo' + if arguments is None: + self.arguments = ExceptionInfoArguments() + else: + self.arguments = ExceptionInfoArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ExceptionInfoArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class ExceptionInfoArguments(BaseSchema): + """ + Arguments for 'exceptionInfo' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "Thread for which exception information should be retrieved." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: Thread for which exception information should be retrieved. + """ + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register_response('exceptionInfo') +@register +class ExceptionInfoResponse(BaseSchema): + """ + Response to 'exceptionInfo' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "exceptionId": { + "type": "string", + "description": "ID of the exception that was thrown." + }, + "description": { + "type": "string", + "description": "Descriptive text for the exception provided by the debug adapter." + }, + "breakMode": { + "$ref": "#/definitions/ExceptionBreakMode", + "description": "Mode that caused the exception notification to be raised." + }, + "details": { + "$ref": "#/definitions/ExceptionDetails", + "description": "Detailed information about the exception." + } + }, + "required": [ + "exceptionId", + "breakMode" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param ExceptionInfoResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = ExceptionInfoResponseBody() + else: + self.body = ExceptionInfoResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ExceptionInfoResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register_request('readMemory') +@register +class ReadMemoryRequest(BaseSchema): + """ + Reads bytes from memory at the provided location. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "readMemory" + ] + }, + "arguments": { + "type": "ReadMemoryArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param ReadMemoryArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'readMemory' + if arguments is None: + self.arguments = ReadMemoryArguments() + else: + self.arguments = ReadMemoryArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != ReadMemoryArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class ReadMemoryArguments(BaseSchema): + """ + Arguments for 'readMemory' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "memoryReference": { + "type": "string", + "description": "Memory reference to the base location from which data should be read." + }, + "offset": { + "type": "integer", + "description": "Optional offset (in bytes) to be applied to the reference location before reading data. Can be negative." + }, + "count": { + "type": "integer", + "description": "Number of bytes to read at the specified location and offset." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, memoryReference, count, offset=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string memoryReference: Memory reference to the base location from which data should be read. + :param integer count: Number of bytes to read at the specified location and offset. + :param integer offset: Optional offset (in bytes) to be applied to the reference location before reading data. Can be negative. + """ + self.memoryReference = memoryReference + self.count = count + self.offset = offset + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + memoryReference = self.memoryReference + count = self.count + offset = self.offset + dct = { + 'memoryReference': memoryReference, + 'count': count, + } + if offset is not None: + dct['offset'] = offset + dct.update(self.kwargs) + return dct + + +@register_response('readMemory') +@register +class ReadMemoryResponse(BaseSchema): + """ + Response to 'readMemory' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "address": { + "type": "string", + "description": "The address of the first byte of data returned. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise." + }, + "unreadableBytes": { + "type": "integer", + "description": "The number of unreadable bytes encountered after the last successfully read byte. This can be used to determine the number of bytes that must be skipped before a subsequent 'readMemory' request will succeed." + }, + "data": { + "type": "string", + "description": "The bytes read from memory, encoded using base64." + } + }, + "required": [ + "address" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ReadMemoryResponseBody body: + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + if body is None: + self.body = ReadMemoryResponseBody() + else: + self.body = ReadMemoryResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != ReadMemoryResponseBody else body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register_request('disassemble') +@register +class DisassembleRequest(BaseSchema): + """ + Disassembles code stored at the provided location. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "disassemble" + ] + }, + "arguments": { + "type": "DisassembleArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param DisassembleArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'disassemble' + if arguments is None: + self.arguments = DisassembleArguments() + else: + self.arguments = DisassembleArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != DisassembleArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class DisassembleArguments(BaseSchema): + """ + Arguments for 'disassemble' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "memoryReference": { + "type": "string", + "description": "Memory reference to the base location containing the instructions to disassemble." + }, + "offset": { + "type": "integer", + "description": "Optional offset (in bytes) to be applied to the reference location before disassembling. Can be negative." + }, + "instructionOffset": { + "type": "integer", + "description": "Optional offset (in instructions) to be applied after the byte offset (if any) before disassembling. Can be negative." + }, + "instructionCount": { + "type": "integer", + "description": "Number of instructions to disassemble starting at the specified location and offset. An adapter must return exactly this number of instructions - any unavailable instructions should be replaced with an implementation-defined 'invalid instruction' value." + }, + "resolveSymbols": { + "type": "boolean", + "description": "If true, the adapter should attempt to resolve memory addresses and other values to symbolic names." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, memoryReference, instructionCount, offset=None, instructionOffset=None, resolveSymbols=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string memoryReference: Memory reference to the base location containing the instructions to disassemble. + :param integer instructionCount: Number of instructions to disassemble starting at the specified location and offset. An adapter must return exactly this number of instructions - any unavailable instructions should be replaced with an implementation-defined 'invalid instruction' value. + :param integer offset: Optional offset (in bytes) to be applied to the reference location before disassembling. Can be negative. + :param integer instructionOffset: Optional offset (in instructions) to be applied after the byte offset (if any) before disassembling. Can be negative. + :param boolean resolveSymbols: If true, the adapter should attempt to resolve memory addresses and other values to symbolic names. + """ + self.memoryReference = memoryReference + self.instructionCount = instructionCount + self.offset = offset + self.instructionOffset = instructionOffset + self.resolveSymbols = resolveSymbols + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + memoryReference = self.memoryReference + instructionCount = self.instructionCount + offset = self.offset + instructionOffset = self.instructionOffset + resolveSymbols = self.resolveSymbols + dct = { + 'memoryReference': memoryReference, + 'instructionCount': instructionCount, + } + if offset is not None: + dct['offset'] = offset + if instructionOffset is not None: + dct['instructionOffset'] = instructionOffset + if resolveSymbols is not None: + dct['resolveSymbols'] = resolveSymbols + dct.update(self.kwargs) + return dct + + +@register_response('disassemble') +@register +class DisassembleResponse(BaseSchema): + """ + Response to 'disassemble' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "instructions": { + "type": "array", + "items": { + "$ref": "#/definitions/DisassembledInstruction" + }, + "description": "The list of disassembled instructions." + } + }, + "required": [ + "instructions" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param DisassembleResponseBody body: + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + if body is None: + self.body = DisassembleResponseBody() + else: + self.body = DisassembleResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != DisassembleResponseBody else body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class Capabilities(BaseSchema): + """ + Information about the capabilities of a debug adapter. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "supportsConfigurationDoneRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'configurationDone' request." + }, + "supportsFunctionBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports function breakpoints." + }, + "supportsConditionalBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports conditional breakpoints." + }, + "supportsHitConditionalBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports breakpoints that break execution after a specified number of hits." + }, + "supportsEvaluateForHovers": { + "type": "boolean", + "description": "The debug adapter supports a (side effect free) evaluate request for data hovers." + }, + "exceptionBreakpointFilters": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionBreakpointsFilter" + }, + "description": "Available filters or options for the setExceptionBreakpoints request." + }, + "supportsStepBack": { + "type": "boolean", + "description": "The debug adapter supports stepping back via the 'stepBack' and 'reverseContinue' requests." + }, + "supportsSetVariable": { + "type": "boolean", + "description": "The debug adapter supports setting a variable to a value." + }, + "supportsRestartFrame": { + "type": "boolean", + "description": "The debug adapter supports restarting a frame." + }, + "supportsGotoTargetsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'gotoTargets' request." + }, + "supportsStepInTargetsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'stepInTargets' request." + }, + "supportsCompletionsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'completions' request." + }, + "supportsModulesRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'modules' request." + }, + "additionalModuleColumns": { + "type": "array", + "items": { + "$ref": "#/definitions/ColumnDescriptor" + }, + "description": "The set of additional module information exposed by the debug adapter." + }, + "supportedChecksumAlgorithms": { + "type": "array", + "items": { + "$ref": "#/definitions/ChecksumAlgorithm" + }, + "description": "Checksum algorithms supported by the debug adapter." + }, + "supportsRestartRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'restart' request. In this case a client should not implement 'restart' by terminating and relaunching the adapter but by calling the RestartRequest." + }, + "supportsExceptionOptions": { + "type": "boolean", + "description": "The debug adapter supports 'exceptionOptions' on the setExceptionBreakpoints request." + }, + "supportsValueFormattingOptions": { + "type": "boolean", + "description": "The debug adapter supports a 'format' attribute on the stackTraceRequest, variablesRequest, and evaluateRequest." + }, + "supportsExceptionInfoRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'exceptionInfo' request." + }, + "supportTerminateDebuggee": { + "type": "boolean", + "description": "The debug adapter supports the 'terminateDebuggee' attribute on the 'disconnect' request." + }, + "supportsDelayedStackTraceLoading": { + "type": "boolean", + "description": "The debug adapter supports the delayed loading of parts of the stack, which requires that both the 'startFrame' and 'levels' arguments and the 'totalFrames' result of the 'StackTrace' request are supported." + }, + "supportsLoadedSourcesRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'loadedSources' request." + }, + "supportsLogPoints": { + "type": "boolean", + "description": "The debug adapter supports logpoints by interpreting the 'logMessage' attribute of the SourceBreakpoint." + }, + "supportsTerminateThreadsRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'terminateThreads' request." + }, + "supportsSetExpression": { + "type": "boolean", + "description": "The debug adapter supports the 'setExpression' request." + }, + "supportsTerminateRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'terminate' request." + }, + "supportsDataBreakpoints": { + "type": "boolean", + "description": "The debug adapter supports data breakpoints." + }, + "supportsReadMemoryRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'readMemory' request." + }, + "supportsDisassembleRequest": { + "type": "boolean", + "description": "The debug adapter supports the 'disassemble' request." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, supportsConfigurationDoneRequest=None, supportsFunctionBreakpoints=None, supportsConditionalBreakpoints=None, supportsHitConditionalBreakpoints=None, supportsEvaluateForHovers=None, exceptionBreakpointFilters=None, supportsStepBack=None, supportsSetVariable=None, supportsRestartFrame=None, supportsGotoTargetsRequest=None, supportsStepInTargetsRequest=None, supportsCompletionsRequest=None, supportsModulesRequest=None, additionalModuleColumns=None, supportedChecksumAlgorithms=None, supportsRestartRequest=None, supportsExceptionOptions=None, supportsValueFormattingOptions=None, supportsExceptionInfoRequest=None, supportTerminateDebuggee=None, supportsDelayedStackTraceLoading=None, supportsLoadedSourcesRequest=None, supportsLogPoints=None, supportsTerminateThreadsRequest=None, supportsSetExpression=None, supportsTerminateRequest=None, supportsDataBreakpoints=None, supportsReadMemoryRequest=None, supportsDisassembleRequest=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean supportsConfigurationDoneRequest: The debug adapter supports the 'configurationDone' request. + :param boolean supportsFunctionBreakpoints: The debug adapter supports function breakpoints. + :param boolean supportsConditionalBreakpoints: The debug adapter supports conditional breakpoints. + :param boolean supportsHitConditionalBreakpoints: The debug adapter supports breakpoints that break execution after a specified number of hits. + :param boolean supportsEvaluateForHovers: The debug adapter supports a (side effect free) evaluate request for data hovers. + :param array exceptionBreakpointFilters: Available filters or options for the setExceptionBreakpoints request. + :param boolean supportsStepBack: The debug adapter supports stepping back via the 'stepBack' and 'reverseContinue' requests. + :param boolean supportsSetVariable: The debug adapter supports setting a variable to a value. + :param boolean supportsRestartFrame: The debug adapter supports restarting a frame. + :param boolean supportsGotoTargetsRequest: The debug adapter supports the 'gotoTargets' request. + :param boolean supportsStepInTargetsRequest: The debug adapter supports the 'stepInTargets' request. + :param boolean supportsCompletionsRequest: The debug adapter supports the 'completions' request. + :param boolean supportsModulesRequest: The debug adapter supports the 'modules' request. + :param array additionalModuleColumns: The set of additional module information exposed by the debug adapter. + :param array supportedChecksumAlgorithms: Checksum algorithms supported by the debug adapter. + :param boolean supportsRestartRequest: The debug adapter supports the 'restart' request. In this case a client should not implement 'restart' by terminating and relaunching the adapter but by calling the RestartRequest. + :param boolean supportsExceptionOptions: The debug adapter supports 'exceptionOptions' on the setExceptionBreakpoints request. + :param boolean supportsValueFormattingOptions: The debug adapter supports a 'format' attribute on the stackTraceRequest, variablesRequest, and evaluateRequest. + :param boolean supportsExceptionInfoRequest: The debug adapter supports the 'exceptionInfo' request. + :param boolean supportTerminateDebuggee: The debug adapter supports the 'terminateDebuggee' attribute on the 'disconnect' request. + :param boolean supportsDelayedStackTraceLoading: The debug adapter supports the delayed loading of parts of the stack, which requires that both the 'startFrame' and 'levels' arguments and the 'totalFrames' result of the 'StackTrace' request are supported. + :param boolean supportsLoadedSourcesRequest: The debug adapter supports the 'loadedSources' request. + :param boolean supportsLogPoints: The debug adapter supports logpoints by interpreting the 'logMessage' attribute of the SourceBreakpoint. + :param boolean supportsTerminateThreadsRequest: The debug adapter supports the 'terminateThreads' request. + :param boolean supportsSetExpression: The debug adapter supports the 'setExpression' request. + :param boolean supportsTerminateRequest: The debug adapter supports the 'terminate' request. + :param boolean supportsDataBreakpoints: The debug adapter supports data breakpoints. + :param boolean supportsReadMemoryRequest: The debug adapter supports the 'readMemory' request. + :param boolean supportsDisassembleRequest: The debug adapter supports the 'disassemble' request. + """ + self.supportsConfigurationDoneRequest = supportsConfigurationDoneRequest + self.supportsFunctionBreakpoints = supportsFunctionBreakpoints + self.supportsConditionalBreakpoints = supportsConditionalBreakpoints + self.supportsHitConditionalBreakpoints = supportsHitConditionalBreakpoints + self.supportsEvaluateForHovers = supportsEvaluateForHovers + self.exceptionBreakpointFilters = exceptionBreakpointFilters + if update_ids_from_dap and self.exceptionBreakpointFilters: + for o in self.exceptionBreakpointFilters: + ExceptionBreakpointsFilter.update_dict_ids_from_dap(o) + self.supportsStepBack = supportsStepBack + self.supportsSetVariable = supportsSetVariable + self.supportsRestartFrame = supportsRestartFrame + self.supportsGotoTargetsRequest = supportsGotoTargetsRequest + self.supportsStepInTargetsRequest = supportsStepInTargetsRequest + self.supportsCompletionsRequest = supportsCompletionsRequest + self.supportsModulesRequest = supportsModulesRequest + self.additionalModuleColumns = additionalModuleColumns + if update_ids_from_dap and self.additionalModuleColumns: + for o in self.additionalModuleColumns: + ColumnDescriptor.update_dict_ids_from_dap(o) + self.supportedChecksumAlgorithms = supportedChecksumAlgorithms + if update_ids_from_dap and self.supportedChecksumAlgorithms: + for o in self.supportedChecksumAlgorithms: + ChecksumAlgorithm.update_dict_ids_from_dap(o) + self.supportsRestartRequest = supportsRestartRequest + self.supportsExceptionOptions = supportsExceptionOptions + self.supportsValueFormattingOptions = supportsValueFormattingOptions + self.supportsExceptionInfoRequest = supportsExceptionInfoRequest + self.supportTerminateDebuggee = supportTerminateDebuggee + self.supportsDelayedStackTraceLoading = supportsDelayedStackTraceLoading + self.supportsLoadedSourcesRequest = supportsLoadedSourcesRequest + self.supportsLogPoints = supportsLogPoints + self.supportsTerminateThreadsRequest = supportsTerminateThreadsRequest + self.supportsSetExpression = supportsSetExpression + self.supportsTerminateRequest = supportsTerminateRequest + self.supportsDataBreakpoints = supportsDataBreakpoints + self.supportsReadMemoryRequest = supportsReadMemoryRequest + self.supportsDisassembleRequest = supportsDisassembleRequest + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + supportsConfigurationDoneRequest = self.supportsConfigurationDoneRequest + supportsFunctionBreakpoints = self.supportsFunctionBreakpoints + supportsConditionalBreakpoints = self.supportsConditionalBreakpoints + supportsHitConditionalBreakpoints = self.supportsHitConditionalBreakpoints + supportsEvaluateForHovers = self.supportsEvaluateForHovers + exceptionBreakpointFilters = self.exceptionBreakpointFilters + if exceptionBreakpointFilters and hasattr(exceptionBreakpointFilters[0], "to_dict"): + exceptionBreakpointFilters = [x.to_dict() for x in exceptionBreakpointFilters] + supportsStepBack = self.supportsStepBack + supportsSetVariable = self.supportsSetVariable + supportsRestartFrame = self.supportsRestartFrame + supportsGotoTargetsRequest = self.supportsGotoTargetsRequest + supportsStepInTargetsRequest = self.supportsStepInTargetsRequest + supportsCompletionsRequest = self.supportsCompletionsRequest + supportsModulesRequest = self.supportsModulesRequest + additionalModuleColumns = self.additionalModuleColumns + if additionalModuleColumns and hasattr(additionalModuleColumns[0], "to_dict"): + additionalModuleColumns = [x.to_dict() for x in additionalModuleColumns] + supportedChecksumAlgorithms = self.supportedChecksumAlgorithms + if supportedChecksumAlgorithms and hasattr(supportedChecksumAlgorithms[0], "to_dict"): + supportedChecksumAlgorithms = [x.to_dict() for x in supportedChecksumAlgorithms] + supportsRestartRequest = self.supportsRestartRequest + supportsExceptionOptions = self.supportsExceptionOptions + supportsValueFormattingOptions = self.supportsValueFormattingOptions + supportsExceptionInfoRequest = self.supportsExceptionInfoRequest + supportTerminateDebuggee = self.supportTerminateDebuggee + supportsDelayedStackTraceLoading = self.supportsDelayedStackTraceLoading + supportsLoadedSourcesRequest = self.supportsLoadedSourcesRequest + supportsLogPoints = self.supportsLogPoints + supportsTerminateThreadsRequest = self.supportsTerminateThreadsRequest + supportsSetExpression = self.supportsSetExpression + supportsTerminateRequest = self.supportsTerminateRequest + supportsDataBreakpoints = self.supportsDataBreakpoints + supportsReadMemoryRequest = self.supportsReadMemoryRequest + supportsDisassembleRequest = self.supportsDisassembleRequest + dct = { + } + if supportsConfigurationDoneRequest is not None: + dct['supportsConfigurationDoneRequest'] = supportsConfigurationDoneRequest + if supportsFunctionBreakpoints is not None: + dct['supportsFunctionBreakpoints'] = supportsFunctionBreakpoints + if supportsConditionalBreakpoints is not None: + dct['supportsConditionalBreakpoints'] = supportsConditionalBreakpoints + if supportsHitConditionalBreakpoints is not None: + dct['supportsHitConditionalBreakpoints'] = supportsHitConditionalBreakpoints + if supportsEvaluateForHovers is not None: + dct['supportsEvaluateForHovers'] = supportsEvaluateForHovers + if exceptionBreakpointFilters is not None: + dct['exceptionBreakpointFilters'] = [ExceptionBreakpointsFilter.update_dict_ids_to_dap(o) for o in exceptionBreakpointFilters] if (update_ids_to_dap and exceptionBreakpointFilters) else exceptionBreakpointFilters + if supportsStepBack is not None: + dct['supportsStepBack'] = supportsStepBack + if supportsSetVariable is not None: + dct['supportsSetVariable'] = supportsSetVariable + if supportsRestartFrame is not None: + dct['supportsRestartFrame'] = supportsRestartFrame + if supportsGotoTargetsRequest is not None: + dct['supportsGotoTargetsRequest'] = supportsGotoTargetsRequest + if supportsStepInTargetsRequest is not None: + dct['supportsStepInTargetsRequest'] = supportsStepInTargetsRequest + if supportsCompletionsRequest is not None: + dct['supportsCompletionsRequest'] = supportsCompletionsRequest + if supportsModulesRequest is not None: + dct['supportsModulesRequest'] = supportsModulesRequest + if additionalModuleColumns is not None: + dct['additionalModuleColumns'] = [ColumnDescriptor.update_dict_ids_to_dap(o) for o in additionalModuleColumns] if (update_ids_to_dap and additionalModuleColumns) else additionalModuleColumns + if supportedChecksumAlgorithms is not None: + dct['supportedChecksumAlgorithms'] = [ChecksumAlgorithm.update_dict_ids_to_dap(o) for o in supportedChecksumAlgorithms] if (update_ids_to_dap and supportedChecksumAlgorithms) else supportedChecksumAlgorithms + if supportsRestartRequest is not None: + dct['supportsRestartRequest'] = supportsRestartRequest + if supportsExceptionOptions is not None: + dct['supportsExceptionOptions'] = supportsExceptionOptions + if supportsValueFormattingOptions is not None: + dct['supportsValueFormattingOptions'] = supportsValueFormattingOptions + if supportsExceptionInfoRequest is not None: + dct['supportsExceptionInfoRequest'] = supportsExceptionInfoRequest + if supportTerminateDebuggee is not None: + dct['supportTerminateDebuggee'] = supportTerminateDebuggee + if supportsDelayedStackTraceLoading is not None: + dct['supportsDelayedStackTraceLoading'] = supportsDelayedStackTraceLoading + if supportsLoadedSourcesRequest is not None: + dct['supportsLoadedSourcesRequest'] = supportsLoadedSourcesRequest + if supportsLogPoints is not None: + dct['supportsLogPoints'] = supportsLogPoints + if supportsTerminateThreadsRequest is not None: + dct['supportsTerminateThreadsRequest'] = supportsTerminateThreadsRequest + if supportsSetExpression is not None: + dct['supportsSetExpression'] = supportsSetExpression + if supportsTerminateRequest is not None: + dct['supportsTerminateRequest'] = supportsTerminateRequest + if supportsDataBreakpoints is not None: + dct['supportsDataBreakpoints'] = supportsDataBreakpoints + if supportsReadMemoryRequest is not None: + dct['supportsReadMemoryRequest'] = supportsReadMemoryRequest + if supportsDisassembleRequest is not None: + dct['supportsDisassembleRequest'] = supportsDisassembleRequest + dct.update(self.kwargs) + return dct + + +@register +class ExceptionBreakpointsFilter(BaseSchema): + """ + An ExceptionBreakpointsFilter is shown in the UI as an option for configuring how exceptions are + dealt with. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "filter": { + "type": "string", + "description": "The internal ID of the filter. This value is passed to the setExceptionBreakpoints request." + }, + "label": { + "type": "string", + "description": "The name of the filter. This will be shown in the UI." + }, + "default": { + "type": "boolean", + "description": "Initial value of the filter. If not specified a value 'false' is assumed." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, filter, label, default=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string filter: The internal ID of the filter. This value is passed to the setExceptionBreakpoints request. + :param string label: The name of the filter. This will be shown in the UI. + :param boolean default: Initial value of the filter. If not specified a value 'false' is assumed. + """ + self.filter = filter + self.label = label + self.default = default + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + filter = self.filter # noqa (assign to builtin) + label = self.label + default = self.default + dct = { + 'filter': filter, + 'label': label, + } + if default is not None: + dct['default'] = default + dct.update(self.kwargs) + return dct + + +@register +class Message(BaseSchema): + """ + A structured message object. Used to return errors from requests. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": "integer", + "description": "Unique identifier for the message." + }, + "format": { + "type": "string", + "description": "A format string for the message. Embedded variables have the form '{name}'.\nIf variable name starts with an underscore character, the variable does not contain user data (PII) and can be safely used for telemetry purposes." + }, + "variables": { + "type": "object", + "description": "An object used as a dictionary for looking up the variables in the format string.", + "additionalProperties": { + "type": "string", + "description": "Values must be strings." + } + }, + "sendTelemetry": { + "type": "boolean", + "description": "If true send to telemetry." + }, + "showUser": { + "type": "boolean", + "description": "If true show user." + }, + "url": { + "type": "string", + "description": "An optional url where additional information about this message can be found." + }, + "urlLabel": { + "type": "string", + "description": "An optional label that is presented to the user as the UI for opening the url." + } + } + __refs__ = set(['variables']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, id, format, variables=None, sendTelemetry=None, showUser=None, url=None, urlLabel=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer id: Unique identifier for the message. + :param string format: A format string for the message. Embedded variables have the form '{name}'. + If variable name starts with an underscore character, the variable does not contain user data (PII) and can be safely used for telemetry purposes. + :param MessageVariables variables: An object used as a dictionary for looking up the variables in the format string. + :param boolean sendTelemetry: If true send to telemetry. + :param boolean showUser: If true show user. + :param string url: An optional url where additional information about this message can be found. + :param string urlLabel: An optional label that is presented to the user as the UI for opening the url. + """ + self.id = id + self.format = format + if variables is None: + self.variables = MessageVariables() + else: + self.variables = MessageVariables(update_ids_from_dap=update_ids_from_dap, **variables) if variables.__class__ != MessageVariables else variables + self.sendTelemetry = sendTelemetry + self.showUser = showUser + self.url = url + self.urlLabel = urlLabel + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + id = self.id # noqa (assign to builtin) + format = self.format # noqa (assign to builtin) + variables = self.variables + sendTelemetry = self.sendTelemetry + showUser = self.showUser + url = self.url + urlLabel = self.urlLabel + dct = { + 'id': id, + 'format': format, + } + if variables is not None: + dct['variables'] = variables.to_dict(update_ids_to_dap=update_ids_to_dap) + if sendTelemetry is not None: + dct['sendTelemetry'] = sendTelemetry + if showUser is not None: + dct['showUser'] = showUser + if url is not None: + dct['url'] = url + if urlLabel is not None: + dct['urlLabel'] = urlLabel + dct.update(self.kwargs) + return dct + + +@register +class Module(BaseSchema): + """ + A Module object represents a row in the modules view. + + Two attributes are mandatory: an id identifies a module in the modules view and is used in a + ModuleEvent for identifying a module for adding, updating or deleting. + + The name is used to minimally render the module in the UI. + + + Additional attributes can be added to the module. They will show up in the module View if they have + a corresponding ColumnDescriptor. + + + To avoid an unnecessary proliferation of additional attributes with similar semantics but different + names + + we recommend to re-use attributes from the 'recommended' list below first, and only introduce new + attributes if nothing appropriate could be found. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": [ + "integer", + "string" + ], + "description": "Unique identifier for the module." + }, + "name": { + "type": "string", + "description": "A name of the module." + }, + "path": { + "type": "string", + "description": "optional but recommended attributes.\nalways try to use these first before introducing additional attributes.\n\nLogical full path to the module. The exact definition is implementation defined, but usually this would be a full path to the on-disk file for the module." + }, + "isOptimized": { + "type": "boolean", + "description": "True if the module is optimized." + }, + "isUserCode": { + "type": "boolean", + "description": "True if the module is considered 'user code' by a debugger that supports 'Just My Code'." + }, + "version": { + "type": "string", + "description": "Version of Module." + }, + "symbolStatus": { + "type": "string", + "description": "User understandable description of if symbols were found for the module (ex: 'Symbols Loaded', 'Symbols not found', etc." + }, + "symbolFilePath": { + "type": "string", + "description": "Logical full path to the symbol file. The exact definition is implementation defined." + }, + "dateTimeStamp": { + "type": "string", + "description": "Module created or modified." + }, + "addressRange": { + "type": "string", + "description": "Address range covered by this module." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, id, name, path=None, isOptimized=None, isUserCode=None, version=None, symbolStatus=None, symbolFilePath=None, dateTimeStamp=None, addressRange=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ['integer', 'string'] id: Unique identifier for the module. + :param string name: A name of the module. + :param string path: optional but recommended attributes. + always try to use these first before introducing additional attributes. + + Logical full path to the module. The exact definition is implementation defined, but usually this would be a full path to the on-disk file for the module. + :param boolean isOptimized: True if the module is optimized. + :param boolean isUserCode: True if the module is considered 'user code' by a debugger that supports 'Just My Code'. + :param string version: Version of Module. + :param string symbolStatus: User understandable description of if symbols were found for the module (ex: 'Symbols Loaded', 'Symbols not found', etc. + :param string symbolFilePath: Logical full path to the symbol file. The exact definition is implementation defined. + :param string dateTimeStamp: Module created or modified. + :param string addressRange: Address range covered by this module. + """ + self.id = id + self.name = name + self.path = path + self.isOptimized = isOptimized + self.isUserCode = isUserCode + self.version = version + self.symbolStatus = symbolStatus + self.symbolFilePath = symbolFilePath + self.dateTimeStamp = dateTimeStamp + self.addressRange = addressRange + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + id = self.id # noqa (assign to builtin) + name = self.name + path = self.path + isOptimized = self.isOptimized + isUserCode = self.isUserCode + version = self.version + symbolStatus = self.symbolStatus + symbolFilePath = self.symbolFilePath + dateTimeStamp = self.dateTimeStamp + addressRange = self.addressRange + dct = { + 'id': id, + 'name': name, + } + if path is not None: + dct['path'] = path + if isOptimized is not None: + dct['isOptimized'] = isOptimized + if isUserCode is not None: + dct['isUserCode'] = isUserCode + if version is not None: + dct['version'] = version + if symbolStatus is not None: + dct['symbolStatus'] = symbolStatus + if symbolFilePath is not None: + dct['symbolFilePath'] = symbolFilePath + if dateTimeStamp is not None: + dct['dateTimeStamp'] = dateTimeStamp + if addressRange is not None: + dct['addressRange'] = addressRange + dct.update(self.kwargs) + return dct + + +@register +class ColumnDescriptor(BaseSchema): + """ + A ColumnDescriptor specifies what module attribute to show in a column of the ModulesView, how to + format it, and what the column's label should be. + + It is only used if the underlying UI actually supports this level of customization. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "attributeName": { + "type": "string", + "description": "Name of the attribute rendered in this column." + }, + "label": { + "type": "string", + "description": "Header UI label of column." + }, + "format": { + "type": "string", + "description": "Format to use for the rendered values in this column. TBD how the format strings looks like." + }, + "type": { + "type": "string", + "enum": [ + "string", + "number", + "boolean", + "unixTimestampUTC" + ], + "description": "Datatype of values in this column. Defaults to 'string' if not specified." + }, + "width": { + "type": "integer", + "description": "Width of this column in characters (hint only)." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, attributeName, label, format=None, type=None, width=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string attributeName: Name of the attribute rendered in this column. + :param string label: Header UI label of column. + :param string format: Format to use for the rendered values in this column. TBD how the format strings looks like. + :param string type: Datatype of values in this column. Defaults to 'string' if not specified. + :param integer width: Width of this column in characters (hint only). + """ + self.attributeName = attributeName + self.label = label + self.format = format + self.type = type + self.width = width + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + attributeName = self.attributeName + label = self.label + format = self.format # noqa (assign to builtin) + type = self.type # noqa (assign to builtin) + width = self.width + dct = { + 'attributeName': attributeName, + 'label': label, + } + if format is not None: + dct['format'] = format + if type is not None: + dct['type'] = type + if width is not None: + dct['width'] = width + dct.update(self.kwargs) + return dct + + +@register +class ModulesViewDescriptor(BaseSchema): + """ + The ModulesViewDescriptor is the container for all declarative configuration options of a + ModuleView. + + For now it only specifies the columns to be shown in the modules view. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "columns": { + "type": "array", + "items": { + "$ref": "#/definitions/ColumnDescriptor" + } + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, columns, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array columns: + """ + self.columns = columns + if update_ids_from_dap and self.columns: + for o in self.columns: + ColumnDescriptor.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + columns = self.columns + if columns and hasattr(columns[0], "to_dict"): + columns = [x.to_dict() for x in columns] + dct = { + 'columns': [ColumnDescriptor.update_dict_ids_to_dap(o) for o in columns] if (update_ids_to_dap and columns) else columns, + } + dct.update(self.kwargs) + return dct + + +@register +class Thread(BaseSchema): + """ + A Thread + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": "integer", + "description": "Unique identifier for the thread." + }, + "name": { + "type": "string", + "description": "A name of the thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, id, name, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer id: Unique identifier for the thread. + :param string name: A name of the thread. + """ + self.id = id + self.name = name + if update_ids_from_dap: + self.id = self._translate_id_from_dap(self.id) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'id' in dct: + dct['id'] = cls._translate_id_from_dap(dct['id']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + id = self.id # noqa (assign to builtin) + name = self.name + if update_ids_to_dap: + if id is not None: + id = self._translate_id_to_dap(id) # noqa (assign to builtin) + dct = { + 'id': id, + 'name': name, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'id' in dct: + dct['id'] = cls._translate_id_to_dap(dct['id']) + return dct + + +@register +class Source(BaseSchema): + """ + A Source is a descriptor for source code. It is returned from the debug adapter as part of a + StackFrame and it is used by clients when specifying breakpoints. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "The short name of the source. Every source returned from the debug adapter has a name. When sending a source to the debug adapter this name is optional." + }, + "path": { + "type": "string", + "description": "The path of the source to be shown in the UI. It is only used to locate and load the content of the source if no sourceReference is specified (or its value is 0)." + }, + "sourceReference": { + "type": "number", + "description": "If sourceReference > 0 the contents of the source must be retrieved through the SourceRequest (even if a path is specified). A sourceReference is only valid for a session, so it must not be used to persist a source." + }, + "presentationHint": { + "type": "string", + "description": "An optional hint for how to present the source in the UI. A value of 'deemphasize' can be used to indicate that the source is not available or that it is skipped on stepping.", + "enum": [ + "normal", + "emphasize", + "deemphasize" + ] + }, + "origin": { + "type": "string", + "description": "The (optional) origin of this source: possible values 'internal module', 'inlined content from source map', etc." + }, + "sources": { + "type": "array", + "items": { + "$ref": "#/definitions/Source" + }, + "description": "An optional list of sources that are related to this source. These may be the source that generated this source." + }, + "adapterData": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Optional data that a debug adapter might want to loop through the client. The client should leave the data intact and persist it across sessions. The client should not interpret the data." + }, + "checksums": { + "type": "array", + "items": { + "$ref": "#/definitions/Checksum" + }, + "description": "The checksums associated with this file." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name=None, path=None, sourceReference=None, presentationHint=None, origin=None, sources=None, adapterData=None, checksums=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: The short name of the source. Every source returned from the debug adapter has a name. When sending a source to the debug adapter this name is optional. + :param string path: The path of the source to be shown in the UI. It is only used to locate and load the content of the source if no sourceReference is specified (or its value is 0). + :param number sourceReference: If sourceReference > 0 the contents of the source must be retrieved through the SourceRequest (even if a path is specified). A sourceReference is only valid for a session, so it must not be used to persist a source. + :param string presentationHint: An optional hint for how to present the source in the UI. A value of 'deemphasize' can be used to indicate that the source is not available or that it is skipped on stepping. + :param string origin: The (optional) origin of this source: possible values 'internal module', 'inlined content from source map', etc. + :param array sources: An optional list of sources that are related to this source. These may be the source that generated this source. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] adapterData: Optional data that a debug adapter might want to loop through the client. The client should leave the data intact and persist it across sessions. The client should not interpret the data. + :param array checksums: The checksums associated with this file. + """ + self.name = name + self.path = path + self.sourceReference = sourceReference + self.presentationHint = presentationHint + self.origin = origin + self.sources = sources + if update_ids_from_dap and self.sources: + for o in self.sources: + Source.update_dict_ids_from_dap(o) + self.adapterData = adapterData + self.checksums = checksums + if update_ids_from_dap and self.checksums: + for o in self.checksums: + Checksum.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + path = self.path + sourceReference = self.sourceReference + presentationHint = self.presentationHint + origin = self.origin + sources = self.sources + if sources and hasattr(sources[0], "to_dict"): + sources = [x.to_dict() for x in sources] + adapterData = self.adapterData + checksums = self.checksums + if checksums and hasattr(checksums[0], "to_dict"): + checksums = [x.to_dict() for x in checksums] + dct = { + } + if name is not None: + dct['name'] = name + if path is not None: + dct['path'] = path + if sourceReference is not None: + dct['sourceReference'] = sourceReference + if presentationHint is not None: + dct['presentationHint'] = presentationHint + if origin is not None: + dct['origin'] = origin + if sources is not None: + dct['sources'] = [Source.update_dict_ids_to_dap(o) for o in sources] if (update_ids_to_dap and sources) else sources + if adapterData is not None: + dct['adapterData'] = adapterData + if checksums is not None: + dct['checksums'] = [Checksum.update_dict_ids_to_dap(o) for o in checksums] if (update_ids_to_dap and checksums) else checksums + dct.update(self.kwargs) + return dct + + +@register +class StackFrame(BaseSchema): + """ + A Stackframe contains the source location. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": "integer", + "description": "An identifier for the stack frame. It must be unique across all threads. This id can be used to retrieve the scopes of the frame with the 'scopesRequest' or to restart the execution of a stackframe." + }, + "name": { + "type": "string", + "description": "The name of the stack frame, typically a method name." + }, + "source": { + "description": "The optional source of the frame.", + "type": "Source" + }, + "line": { + "type": "integer", + "description": "The line within the file of the frame. If source is null or doesn't exist, line is 0 and must be ignored." + }, + "column": { + "type": "integer", + "description": "The column within the line. If source is null or doesn't exist, column is 0 and must be ignored." + }, + "endLine": { + "type": "integer", + "description": "An optional end line of the range covered by the stack frame." + }, + "endColumn": { + "type": "integer", + "description": "An optional end column of the range covered by the stack frame." + }, + "instructionPointerReference": { + "type": "string", + "description": "Optional memory reference for the current instruction pointer in this frame." + }, + "moduleId": { + "type": [ + "integer", + "string" + ], + "description": "The module associated with this frame, if any." + }, + "presentationHint": { + "type": "string", + "enum": [ + "normal", + "label", + "subtle" + ], + "description": "An optional hint for how to present this frame in the UI. A value of 'label' can be used to indicate that the frame is an artificial frame that is used as a visual label or separator. A value of 'subtle' can be used to change the appearance of a frame in a 'subtle' way." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, id, name, line, column, source=None, endLine=None, endColumn=None, instructionPointerReference=None, moduleId=None, presentationHint=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer id: An identifier for the stack frame. It must be unique across all threads. This id can be used to retrieve the scopes of the frame with the 'scopesRequest' or to restart the execution of a stackframe. + :param string name: The name of the stack frame, typically a method name. + :param integer line: The line within the file of the frame. If source is null or doesn't exist, line is 0 and must be ignored. + :param integer column: The column within the line. If source is null or doesn't exist, column is 0 and must be ignored. + :param Source source: The optional source of the frame. + :param integer endLine: An optional end line of the range covered by the stack frame. + :param integer endColumn: An optional end column of the range covered by the stack frame. + :param string instructionPointerReference: Optional memory reference for the current instruction pointer in this frame. + :param ['integer', 'string'] moduleId: The module associated with this frame, if any. + :param string presentationHint: An optional hint for how to present this frame in the UI. A value of 'label' can be used to indicate that the frame is an artificial frame that is used as a visual label or separator. A value of 'subtle' can be used to change the appearance of a frame in a 'subtle' way. + """ + self.id = id + self.name = name + self.line = line + self.column = column + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.endLine = endLine + self.endColumn = endColumn + self.instructionPointerReference = instructionPointerReference + self.moduleId = moduleId + self.presentationHint = presentationHint + if update_ids_from_dap: + self.id = self._translate_id_from_dap(self.id) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'id' in dct: + dct['id'] = cls._translate_id_from_dap(dct['id']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + id = self.id # noqa (assign to builtin) + name = self.name + line = self.line + column = self.column + source = self.source + endLine = self.endLine + endColumn = self.endColumn + instructionPointerReference = self.instructionPointerReference + moduleId = self.moduleId + presentationHint = self.presentationHint + if update_ids_to_dap: + if id is not None: + id = self._translate_id_to_dap(id) # noqa (assign to builtin) + dct = { + 'id': id, + 'name': name, + 'line': line, + 'column': column, + } + if source is not None: + dct['source'] = source.to_dict(update_ids_to_dap=update_ids_to_dap) + if endLine is not None: + dct['endLine'] = endLine + if endColumn is not None: + dct['endColumn'] = endColumn + if instructionPointerReference is not None: + dct['instructionPointerReference'] = instructionPointerReference + if moduleId is not None: + dct['moduleId'] = moduleId + if presentationHint is not None: + dct['presentationHint'] = presentationHint + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'id' in dct: + dct['id'] = cls._translate_id_to_dap(dct['id']) + return dct + + +@register +class Scope(BaseSchema): + """ + A Scope is a named container for variables. Optionally a scope can map to a source or a range within + a source. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "Name of the scope such as 'Arguments', 'Locals', or 'Registers'. This string is shown in the UI as is and can be translated." + }, + "presentationHint": { + "type": "string", + "description": "An optional hint for how to present this scope in the UI. If this attribute is missing, the scope is shown with a generic UI.", + "_enum": [ + "arguments", + "locals", + "registers" + ], + "enumDescriptions": [ + "Scope contains method arguments.", + "Scope contains local variables.", + "Scope contains registers. Only a single 'registers' scope should be returned from a 'scopes' request." + ] + }, + "variablesReference": { + "type": "integer", + "description": "The variables of this scope can be retrieved by passing the value of variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "integer", + "description": "The number of named variables in this scope.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "integer", + "description": "The number of indexed variables in this scope.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "expensive": { + "type": "boolean", + "description": "If true, the number of variables in this scope is large or expensive to retrieve." + }, + "source": { + "description": "Optional source for this scope.", + "type": "Source" + }, + "line": { + "type": "integer", + "description": "Optional start line of the range covered by this scope." + }, + "column": { + "type": "integer", + "description": "Optional start column of the range covered by this scope." + }, + "endLine": { + "type": "integer", + "description": "Optional end line of the range covered by this scope." + }, + "endColumn": { + "type": "integer", + "description": "Optional end column of the range covered by this scope." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name, variablesReference, expensive, presentationHint=None, namedVariables=None, indexedVariables=None, source=None, line=None, column=None, endLine=None, endColumn=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: Name of the scope such as 'Arguments', 'Locals', or 'Registers'. This string is shown in the UI as is and can be translated. + :param integer variablesReference: The variables of this scope can be retrieved by passing the value of variablesReference to the VariablesRequest. + :param boolean expensive: If true, the number of variables in this scope is large or expensive to retrieve. + :param string presentationHint: An optional hint for how to present this scope in the UI. If this attribute is missing, the scope is shown with a generic UI. + :param integer namedVariables: The number of named variables in this scope. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + :param integer indexedVariables: The number of indexed variables in this scope. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + :param Source source: Optional source for this scope. + :param integer line: Optional start line of the range covered by this scope. + :param integer column: Optional start column of the range covered by this scope. + :param integer endLine: Optional end line of the range covered by this scope. + :param integer endColumn: Optional end column of the range covered by this scope. + """ + self.name = name + self.variablesReference = variablesReference + self.expensive = expensive + self.presentationHint = presentationHint + self.namedVariables = namedVariables + self.indexedVariables = indexedVariables + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.line = line + self.column = column + self.endLine = endLine + self.endColumn = endColumn + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + variablesReference = self.variablesReference + expensive = self.expensive + presentationHint = self.presentationHint + namedVariables = self.namedVariables + indexedVariables = self.indexedVariables + source = self.source + line = self.line + column = self.column + endLine = self.endLine + endColumn = self.endColumn + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'name': name, + 'variablesReference': variablesReference, + 'expensive': expensive, + } + if presentationHint is not None: + dct['presentationHint'] = presentationHint + if namedVariables is not None: + dct['namedVariables'] = namedVariables + if indexedVariables is not None: + dct['indexedVariables'] = indexedVariables + if source is not None: + dct['source'] = source.to_dict(update_ids_to_dap=update_ids_to_dap) + if line is not None: + dct['line'] = line + if column is not None: + dct['column'] = column + if endLine is not None: + dct['endLine'] = endLine + if endColumn is not None: + dct['endColumn'] = endColumn + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register +class Variable(BaseSchema): + """ + A Variable is a name/value pair. + + Optionally a variable can have a 'type' that is shown if space permits or when hovering over the + variable's name. + + An optional 'kind' is used to render additional properties of the variable, e.g. different icons can + be used to indicate that a variable is public or private. + + If the value is structured (has children), a handle is provided to retrieve the children with the + VariablesRequest. + + If the number of named or indexed children is large, the numbers should be returned via the optional + 'namedVariables' and 'indexedVariables' attributes. + + The client can use this optional information to present the children in a paged UI and fetch them in + chunks. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "The variable's name." + }, + "value": { + "type": "string", + "description": "The variable's value. This can be a multi-line text, e.g. for a function the body of a function." + }, + "type": { + "type": "string", + "description": "The type of the variable's value. Typically shown in the UI when hovering over the value." + }, + "presentationHint": { + "description": "Properties of a variable that can be used to determine how to render the variable in the UI.", + "type": "VariablePresentationHint" + }, + "evaluateName": { + "type": "string", + "description": "Optional evaluatable name of this variable which can be passed to the 'EvaluateRequest' to fetch the variable's value." + }, + "variablesReference": { + "type": "integer", + "description": "If variablesReference is > 0, the variable is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "integer", + "description": "The number of named child variables.\nThe client can use this optional information to present the children in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "integer", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the children in a paged UI and fetch them in chunks." + }, + "memoryReference": { + "type": "string", + "description": "Optional memory reference for the variable if the variable represents executable code, such as a function pointer." + } + } + __refs__ = set(['presentationHint']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name, value, variablesReference, type=None, presentationHint=None, evaluateName=None, namedVariables=None, indexedVariables=None, memoryReference=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: The variable's name. + :param string value: The variable's value. This can be a multi-line text, e.g. for a function the body of a function. + :param integer variablesReference: If variablesReference is > 0, the variable is structured and its children can be retrieved by passing variablesReference to the VariablesRequest. + :param string type: The type of the variable's value. Typically shown in the UI when hovering over the value. + :param VariablePresentationHint presentationHint: Properties of a variable that can be used to determine how to render the variable in the UI. + :param string evaluateName: Optional evaluatable name of this variable which can be passed to the 'EvaluateRequest' to fetch the variable's value. + :param integer namedVariables: The number of named child variables. + The client can use this optional information to present the children in a paged UI and fetch them in chunks. + :param integer indexedVariables: The number of indexed child variables. + The client can use this optional information to present the children in a paged UI and fetch them in chunks. + :param string memoryReference: Optional memory reference for the variable if the variable represents executable code, such as a function pointer. + """ + self.name = name + self.value = value + self.variablesReference = variablesReference + self.type = type + if presentationHint is None: + self.presentationHint = VariablePresentationHint() + else: + self.presentationHint = VariablePresentationHint(update_ids_from_dap=update_ids_from_dap, **presentationHint) if presentationHint.__class__ != VariablePresentationHint else presentationHint + self.evaluateName = evaluateName + self.namedVariables = namedVariables + self.indexedVariables = indexedVariables + self.memoryReference = memoryReference + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + value = self.value + variablesReference = self.variablesReference + type = self.type # noqa (assign to builtin) + presentationHint = self.presentationHint + evaluateName = self.evaluateName + namedVariables = self.namedVariables + indexedVariables = self.indexedVariables + memoryReference = self.memoryReference + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'name': name, + 'value': value, + 'variablesReference': variablesReference, + } + if type is not None: + dct['type'] = type + if presentationHint is not None: + dct['presentationHint'] = presentationHint.to_dict(update_ids_to_dap=update_ids_to_dap) + if evaluateName is not None: + dct['evaluateName'] = evaluateName + if namedVariables is not None: + dct['namedVariables'] = namedVariables + if indexedVariables is not None: + dct['indexedVariables'] = indexedVariables + if memoryReference is not None: + dct['memoryReference'] = memoryReference + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register +class VariablePresentationHint(BaseSchema): + """ + Optional properties of a variable that can be used to determine how to render the variable in the + UI. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "kind": { + "description": "The kind of variable. Before introducing additional values, try to use the listed values.", + "type": "string", + "_enum": [ + "property", + "method", + "class", + "data", + "event", + "baseClass", + "innerClass", + "interface", + "mostDerivedClass", + "virtual", + "dataBreakpoint" + ], + "enumDescriptions": [ + "Indicates that the object is a property.", + "Indicates that the object is a method.", + "Indicates that the object is a class.", + "Indicates that the object is data.", + "Indicates that the object is an event.", + "Indicates that the object is a base class.", + "Indicates that the object is an inner class.", + "Indicates that the object is an interface.", + "Indicates that the object is the most derived class.", + "Indicates that the object is virtual, that means it is a synthetic object introduced by the adapter for rendering purposes, e.g. an index range for large arrays.", + "Indicates that a data breakpoint is registered for the object." + ] + }, + "attributes": { + "description": "Set of attributes represented as an array of strings. Before introducing additional values, try to use the listed values.", + "type": "array", + "items": { + "type": "string", + "_enum": [ + "static", + "constant", + "readOnly", + "rawString", + "hasObjectId", + "canHaveObjectId", + "hasSideEffects" + ], + "enumDescriptions": [ + "Indicates that the object is static.", + "Indicates that the object is a constant.", + "Indicates that the object is read only.", + "Indicates that the object is a raw string.", + "Indicates that the object can have an Object ID created for it.", + "Indicates that the object has an Object ID associated with it.", + "Indicates that the evaluation had side effects." + ] + } + }, + "visibility": { + "description": "Visibility of variable. Before introducing additional values, try to use the listed values.", + "type": "string", + "_enum": [ + "public", + "private", + "protected", + "internal", + "final" + ] + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, kind=None, attributes=None, visibility=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string kind: The kind of variable. Before introducing additional values, try to use the listed values. + :param array attributes: Set of attributes represented as an array of strings. Before introducing additional values, try to use the listed values. + :param string visibility: Visibility of variable. Before introducing additional values, try to use the listed values. + """ + self.kind = kind + self.attributes = attributes + self.visibility = visibility + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + kind = self.kind + attributes = self.attributes + if attributes and hasattr(attributes[0], "to_dict"): + attributes = [x.to_dict() for x in attributes] + visibility = self.visibility + dct = { + } + if kind is not None: + dct['kind'] = kind + if attributes is not None: + dct['attributes'] = attributes + if visibility is not None: + dct['visibility'] = visibility + dct.update(self.kwargs) + return dct + + +@register +class SourceBreakpoint(BaseSchema): + """ + Properties of a breakpoint or logpoint passed to the setBreakpoints request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "line": { + "type": "integer", + "description": "The source line of the breakpoint or logpoint." + }, + "column": { + "type": "integer", + "description": "An optional source column of the breakpoint." + }, + "condition": { + "type": "string", + "description": "An optional expression for conditional breakpoints." + }, + "hitCondition": { + "type": "string", + "description": "An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed." + }, + "logMessage": { + "type": "string", + "description": "If this attribute exists and is non-empty, the backend must not 'break' (stop) but log the message instead. Expressions within {} are interpolated." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, line, column=None, condition=None, hitCondition=None, logMessage=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer line: The source line of the breakpoint or logpoint. + :param integer column: An optional source column of the breakpoint. + :param string condition: An optional expression for conditional breakpoints. + :param string hitCondition: An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed. + :param string logMessage: If this attribute exists and is non-empty, the backend must not 'break' (stop) but log the message instead. Expressions within {} are interpolated. + """ + self.line = line + self.column = column + self.condition = condition + self.hitCondition = hitCondition + self.logMessage = logMessage + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + line = self.line + column = self.column + condition = self.condition + hitCondition = self.hitCondition + logMessage = self.logMessage + dct = { + 'line': line, + } + if column is not None: + dct['column'] = column + if condition is not None: + dct['condition'] = condition + if hitCondition is not None: + dct['hitCondition'] = hitCondition + if logMessage is not None: + dct['logMessage'] = logMessage + dct.update(self.kwargs) + return dct + + +@register +class FunctionBreakpoint(BaseSchema): + """ + Properties of a breakpoint passed to the setFunctionBreakpoints request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "The name of the function." + }, + "condition": { + "type": "string", + "description": "An optional expression for conditional breakpoints." + }, + "hitCondition": { + "type": "string", + "description": "An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name, condition=None, hitCondition=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: The name of the function. + :param string condition: An optional expression for conditional breakpoints. + :param string hitCondition: An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed. + """ + self.name = name + self.condition = condition + self.hitCondition = hitCondition + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + condition = self.condition + hitCondition = self.hitCondition + dct = { + 'name': name, + } + if condition is not None: + dct['condition'] = condition + if hitCondition is not None: + dct['hitCondition'] = hitCondition + dct.update(self.kwargs) + return dct + + +@register +class DataBreakpointAccessType(BaseSchema): + """ + This enumeration defines all possible access types for data breakpoints. + + Note: automatically generated code. Do not edit manually. + """ + + READ = 'read' + WRITE = 'write' + READWRITE = 'readWrite' + + VALID_VALUES = set(['read', 'write', 'readWrite']) + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register +class DataBreakpoint(BaseSchema): + """ + Properties of a data breakpoint passed to the setDataBreakpoints request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "dataId": { + "type": "string", + "description": "An id representing the data. This id is returned from the dataBreakpointInfo request." + }, + "accessType": { + "description": "The access type of the data.", + "type": "DataBreakpointAccessType" + }, + "condition": { + "type": "string", + "description": "An optional expression for conditional breakpoints." + }, + "hitCondition": { + "type": "string", + "description": "An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed." + } + } + __refs__ = set(['accessType']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, dataId, accessType=None, condition=None, hitCondition=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string dataId: An id representing the data. This id is returned from the dataBreakpointInfo request. + :param DataBreakpointAccessType accessType: The access type of the data. + :param string condition: An optional expression for conditional breakpoints. + :param string hitCondition: An optional expression that controls how many hits of the breakpoint are ignored. The backend is expected to interpret the expression as needed. + """ + self.dataId = dataId + assert accessType in DataBreakpointAccessType.VALID_VALUES + self.accessType = accessType + self.condition = condition + self.hitCondition = hitCondition + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dataId = self.dataId + accessType = self.accessType + condition = self.condition + hitCondition = self.hitCondition + dct = { + 'dataId': dataId, + } + if accessType is not None: + dct['accessType'] = accessType + if condition is not None: + dct['condition'] = condition + if hitCondition is not None: + dct['hitCondition'] = hitCondition + dct.update(self.kwargs) + return dct + + +@register +class Breakpoint(BaseSchema): + """ + Information about a Breakpoint created in setBreakpoints or setFunctionBreakpoints. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": "integer", + "description": "An optional identifier for the breakpoint. It is needed if breakpoint events are used to update or remove breakpoints." + }, + "verified": { + "type": "boolean", + "description": "If true breakpoint could be set (but not necessarily at the desired location)." + }, + "message": { + "type": "string", + "description": "An optional message about the state of the breakpoint. This is shown to the user and can be used to explain why a breakpoint could not be verified." + }, + "source": { + "description": "The source where the breakpoint is located.", + "type": "Source" + }, + "line": { + "type": "integer", + "description": "The start line of the actual range covered by the breakpoint." + }, + "column": { + "type": "integer", + "description": "An optional start column of the actual range covered by the breakpoint." + }, + "endLine": { + "type": "integer", + "description": "An optional end line of the actual range covered by the breakpoint." + }, + "endColumn": { + "type": "integer", + "description": "An optional end column of the actual range covered by the breakpoint. If no end line is given, then the end column is assumed to be in the start line." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, verified, id=None, message=None, source=None, line=None, column=None, endLine=None, endColumn=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean verified: If true breakpoint could be set (but not necessarily at the desired location). + :param integer id: An optional identifier for the breakpoint. It is needed if breakpoint events are used to update or remove breakpoints. + :param string message: An optional message about the state of the breakpoint. This is shown to the user and can be used to explain why a breakpoint could not be verified. + :param Source source: The source where the breakpoint is located. + :param integer line: The start line of the actual range covered by the breakpoint. + :param integer column: An optional start column of the actual range covered by the breakpoint. + :param integer endLine: An optional end line of the actual range covered by the breakpoint. + :param integer endColumn: An optional end column of the actual range covered by the breakpoint. If no end line is given, then the end column is assumed to be in the start line. + """ + self.verified = verified + self.id = id + self.message = message + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.line = line + self.column = column + self.endLine = endLine + self.endColumn = endColumn + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + verified = self.verified + id = self.id # noqa (assign to builtin) + message = self.message + source = self.source + line = self.line + column = self.column + endLine = self.endLine + endColumn = self.endColumn + dct = { + 'verified': verified, + } + if id is not None: + dct['id'] = id + if message is not None: + dct['message'] = message + if source is not None: + dct['source'] = source.to_dict(update_ids_to_dap=update_ids_to_dap) + if line is not None: + dct['line'] = line + if column is not None: + dct['column'] = column + if endLine is not None: + dct['endLine'] = endLine + if endColumn is not None: + dct['endColumn'] = endColumn + dct.update(self.kwargs) + return dct + + +@register +class StepInTarget(BaseSchema): + """ + A StepInTarget can be used in the 'stepIn' request and determines into which single target the + stepIn request should step. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": "integer", + "description": "Unique identifier for a stepIn target." + }, + "label": { + "type": "string", + "description": "The name of the stepIn target (shown in the UI)." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, id, label, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer id: Unique identifier for a stepIn target. + :param string label: The name of the stepIn target (shown in the UI). + """ + self.id = id + self.label = label + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + id = self.id # noqa (assign to builtin) + label = self.label + dct = { + 'id': id, + 'label': label, + } + dct.update(self.kwargs) + return dct + + +@register +class GotoTarget(BaseSchema): + """ + A GotoTarget describes a code location that can be used as a target in the 'goto' request. + + The possible goto targets can be determined via the 'gotoTargets' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "id": { + "type": "integer", + "description": "Unique identifier for a goto target. This is used in the goto request." + }, + "label": { + "type": "string", + "description": "The name of the goto target (shown in the UI)." + }, + "line": { + "type": "integer", + "description": "The line of the goto target." + }, + "column": { + "type": "integer", + "description": "An optional column of the goto target." + }, + "endLine": { + "type": "integer", + "description": "An optional end line of the range covered by the goto target." + }, + "endColumn": { + "type": "integer", + "description": "An optional end column of the range covered by the goto target." + }, + "instructionPointerReference": { + "type": "string", + "description": "Optional memory reference for the instruction pointer value represented by this target." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, id, label, line, column=None, endLine=None, endColumn=None, instructionPointerReference=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer id: Unique identifier for a goto target. This is used in the goto request. + :param string label: The name of the goto target (shown in the UI). + :param integer line: The line of the goto target. + :param integer column: An optional column of the goto target. + :param integer endLine: An optional end line of the range covered by the goto target. + :param integer endColumn: An optional end column of the range covered by the goto target. + :param string instructionPointerReference: Optional memory reference for the instruction pointer value represented by this target. + """ + self.id = id + self.label = label + self.line = line + self.column = column + self.endLine = endLine + self.endColumn = endColumn + self.instructionPointerReference = instructionPointerReference + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + id = self.id # noqa (assign to builtin) + label = self.label + line = self.line + column = self.column + endLine = self.endLine + endColumn = self.endColumn + instructionPointerReference = self.instructionPointerReference + dct = { + 'id': id, + 'label': label, + 'line': line, + } + if column is not None: + dct['column'] = column + if endLine is not None: + dct['endLine'] = endLine + if endColumn is not None: + dct['endColumn'] = endColumn + if instructionPointerReference is not None: + dct['instructionPointerReference'] = instructionPointerReference + dct.update(self.kwargs) + return dct + + +@register +class CompletionItem(BaseSchema): + """ + CompletionItems are the suggestions returned from the CompletionsRequest. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "label": { + "type": "string", + "description": "The label of this completion item. By default this is also the text that is inserted when selecting this completion." + }, + "text": { + "type": "string", + "description": "If text is not falsy then it is inserted instead of the label." + }, + "type": { + "description": "The item's type. Typically the client uses this information to render the item in the UI with an icon.", + "type": "CompletionItemType" + }, + "start": { + "type": "integer", + "description": "This value determines the location (in the CompletionsRequest's 'text' attribute) where the completion text is added.\nIf missing the text is added at the location specified by the CompletionsRequest's 'column' attribute." + }, + "length": { + "type": "integer", + "description": "This value determines how many characters are overwritten by the completion text.\nIf missing the value 0 is assumed which results in the completion text being inserted." + } + } + __refs__ = set(['type']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, label, text=None, type=None, start=None, length=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string label: The label of this completion item. By default this is also the text that is inserted when selecting this completion. + :param string text: If text is not falsy then it is inserted instead of the label. + :param CompletionItemType type: The item's type. Typically the client uses this information to render the item in the UI with an icon. + :param integer start: This value determines the location (in the CompletionsRequest's 'text' attribute) where the completion text is added. + If missing the text is added at the location specified by the CompletionsRequest's 'column' attribute. + :param integer length: This value determines how many characters are overwritten by the completion text. + If missing the value 0 is assumed which results in the completion text being inserted. + """ + self.label = label + self.text = text + assert type in CompletionItemType.VALID_VALUES + self.type = type + self.start = start + self.length = length + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + label = self.label + text = self.text + type = self.type # noqa (assign to builtin) + start = self.start + length = self.length + dct = { + 'label': label, + } + if text is not None: + dct['text'] = text + if type is not None: + dct['type'] = type + if start is not None: + dct['start'] = start + if length is not None: + dct['length'] = length + dct.update(self.kwargs) + return dct + + +@register +class CompletionItemType(BaseSchema): + """ + Some predefined types for the CompletionItem. Please note that not all clients have specific icons + for all of them. + + Note: automatically generated code. Do not edit manually. + """ + + METHOD = 'method' + FUNCTION = 'function' + CONSTRUCTOR = 'constructor' + FIELD = 'field' + VARIABLE = 'variable' + CLASS = 'class' + INTERFACE = 'interface' + MODULE = 'module' + PROPERTY = 'property' + UNIT = 'unit' + VALUE = 'value' + ENUM = 'enum' + KEYWORD = 'keyword' + SNIPPET = 'snippet' + TEXT = 'text' + COLOR = 'color' + FILE = 'file' + REFERENCE = 'reference' + CUSTOMCOLOR = 'customcolor' + + VALID_VALUES = set(['method', 'function', 'constructor', 'field', 'variable', 'class', 'interface', 'module', 'property', 'unit', 'value', 'enum', 'keyword', 'snippet', 'text', 'color', 'file', 'reference', 'customcolor']) + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register +class ChecksumAlgorithm(BaseSchema): + """ + Names of checksum algorithms that may be supported by a debug adapter. + + Note: automatically generated code. Do not edit manually. + """ + + MD5 = 'MD5' + SHA1 = 'SHA1' + SHA256 = 'SHA256' + TIMESTAMP = 'timestamp' + + VALID_VALUES = set(['MD5', 'SHA1', 'SHA256', 'timestamp']) + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register +class Checksum(BaseSchema): + """ + The checksum of an item calculated by the specified algorithm. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "algorithm": { + "description": "The algorithm used to calculate this checksum.", + "type": "ChecksumAlgorithm" + }, + "checksum": { + "type": "string", + "description": "Value of the checksum." + } + } + __refs__ = set(['algorithm']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, algorithm, checksum, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ChecksumAlgorithm algorithm: The algorithm used to calculate this checksum. + :param string checksum: Value of the checksum. + """ + assert algorithm in ChecksumAlgorithm.VALID_VALUES + self.algorithm = algorithm + self.checksum = checksum + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + algorithm = self.algorithm + checksum = self.checksum + dct = { + 'algorithm': algorithm, + 'checksum': checksum, + } + dct.update(self.kwargs) + return dct + + +@register +class ValueFormat(BaseSchema): + """ + Provides formatting information for a value. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "hex": { + "type": "boolean", + "description": "Display the value in hex." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, hex=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean hex: Display the value in hex. + """ + self.hex = hex + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + hex = self.hex # noqa (assign to builtin) + dct = { + } + if hex is not None: + dct['hex'] = hex + dct.update(self.kwargs) + return dct + + +@register +class StackFrameFormat(BaseSchema): + """ + Provides formatting information for a stack frame. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "hex": { + "type": "boolean", + "description": "Display the value in hex." + }, + "parameters": { + "type": "boolean", + "description": "Displays parameters for the stack frame." + }, + "parameterTypes": { + "type": "boolean", + "description": "Displays the types of parameters for the stack frame." + }, + "parameterNames": { + "type": "boolean", + "description": "Displays the names of parameters for the stack frame." + }, + "parameterValues": { + "type": "boolean", + "description": "Displays the values of parameters for the stack frame." + }, + "line": { + "type": "boolean", + "description": "Displays the line number of the stack frame." + }, + "module": { + "type": "boolean", + "description": "Displays the module of the stack frame." + }, + "includeAll": { + "type": "boolean", + "description": "Includes all stack frames, including those the debug adapter might otherwise hide." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, hex=None, parameters=None, parameterTypes=None, parameterNames=None, parameterValues=None, line=None, module=None, includeAll=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean hex: Display the value in hex. + :param boolean parameters: Displays parameters for the stack frame. + :param boolean parameterTypes: Displays the types of parameters for the stack frame. + :param boolean parameterNames: Displays the names of parameters for the stack frame. + :param boolean parameterValues: Displays the values of parameters for the stack frame. + :param boolean line: Displays the line number of the stack frame. + :param boolean module: Displays the module of the stack frame. + :param boolean includeAll: Includes all stack frames, including those the debug adapter might otherwise hide. + """ + self.hex = hex + self.parameters = parameters + self.parameterTypes = parameterTypes + self.parameterNames = parameterNames + self.parameterValues = parameterValues + self.line = line + self.module = module + self.includeAll = includeAll + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + hex = self.hex # noqa (assign to builtin) + parameters = self.parameters + parameterTypes = self.parameterTypes + parameterNames = self.parameterNames + parameterValues = self.parameterValues + line = self.line + module = self.module + includeAll = self.includeAll + dct = { + } + if hex is not None: + dct['hex'] = hex + if parameters is not None: + dct['parameters'] = parameters + if parameterTypes is not None: + dct['parameterTypes'] = parameterTypes + if parameterNames is not None: + dct['parameterNames'] = parameterNames + if parameterValues is not None: + dct['parameterValues'] = parameterValues + if line is not None: + dct['line'] = line + if module is not None: + dct['module'] = module + if includeAll is not None: + dct['includeAll'] = includeAll + dct.update(self.kwargs) + return dct + + +@register +class ExceptionOptions(BaseSchema): + """ + An ExceptionOptions assigns configuration options to a set of exceptions. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "path": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionPathSegment" + }, + "description": "A path that selects a single or multiple exceptions in a tree. If 'path' is missing, the whole tree is selected. By convention the first segment of the path is a category that is used to group exceptions in the UI." + }, + "breakMode": { + "description": "Condition when a thrown exception should result in a break.", + "type": "ExceptionBreakMode" + } + } + __refs__ = set(['breakMode']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, breakMode, path=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ExceptionBreakMode breakMode: Condition when a thrown exception should result in a break. + :param array path: A path that selects a single or multiple exceptions in a tree. If 'path' is missing, the whole tree is selected. By convention the first segment of the path is a category that is used to group exceptions in the UI. + """ + assert breakMode in ExceptionBreakMode.VALID_VALUES + self.breakMode = breakMode + self.path = path + if update_ids_from_dap and self.path: + for o in self.path: + ExceptionPathSegment.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + breakMode = self.breakMode + path = self.path + if path and hasattr(path[0], "to_dict"): + path = [x.to_dict() for x in path] + dct = { + 'breakMode': breakMode, + } + if path is not None: + dct['path'] = [ExceptionPathSegment.update_dict_ids_to_dap(o) for o in path] if (update_ids_to_dap and path) else path + dct.update(self.kwargs) + return dct + + +@register +class ExceptionBreakMode(BaseSchema): + """ + This enumeration defines all possible conditions when a thrown exception should result in a break. + + never: never breaks, + + always: always breaks, + + unhandled: breaks when excpetion unhandled, + + userUnhandled: breaks if the exception is not handled by user code. + + Note: automatically generated code. Do not edit manually. + """ + + NEVER = 'never' + ALWAYS = 'always' + UNHANDLED = 'unhandled' + USERUNHANDLED = 'userUnhandled' + + VALID_VALUES = set(['never', 'always', 'unhandled', 'userUnhandled']) + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register +class ExceptionPathSegment(BaseSchema): + """ + An ExceptionPathSegment represents a segment in a path that is used to match leafs or nodes in a + tree of exceptions. If a segment consists of more than one name, it matches the names provided if + 'negate' is false or missing or it matches anything except the names provided if 'negate' is true. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "negate": { + "type": "boolean", + "description": "If false or missing this segment matches the names provided, otherwise it matches anything except the names provided." + }, + "names": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Depending on the value of 'negate' the names that should match or not match." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, names, negate=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array names: Depending on the value of 'negate' the names that should match or not match. + :param boolean negate: If false or missing this segment matches the names provided, otherwise it matches anything except the names provided. + """ + self.names = names + self.negate = negate + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + names = self.names + if names and hasattr(names[0], "to_dict"): + names = [x.to_dict() for x in names] + negate = self.negate + dct = { + 'names': names, + } + if negate is not None: + dct['negate'] = negate + dct.update(self.kwargs) + return dct + + +@register +class ExceptionDetails(BaseSchema): + """ + Detailed information about an exception that has occurred. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "message": { + "type": "string", + "description": "Message contained in the exception." + }, + "typeName": { + "type": "string", + "description": "Short type name of the exception object." + }, + "fullTypeName": { + "type": "string", + "description": "Fully-qualified type name of the exception object." + }, + "evaluateName": { + "type": "string", + "description": "Optional expression that can be evaluated in the current scope to obtain the exception object." + }, + "stackTrace": { + "type": "string", + "description": "Stack trace at the time the exception was thrown." + }, + "innerException": { + "type": "array", + "items": { + "$ref": "#/definitions/ExceptionDetails" + }, + "description": "Details of the exception contained by this exception, if any." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, message=None, typeName=None, fullTypeName=None, evaluateName=None, stackTrace=None, innerException=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string message: Message contained in the exception. + :param string typeName: Short type name of the exception object. + :param string fullTypeName: Fully-qualified type name of the exception object. + :param string evaluateName: Optional expression that can be evaluated in the current scope to obtain the exception object. + :param string stackTrace: Stack trace at the time the exception was thrown. + :param array innerException: Details of the exception contained by this exception, if any. + """ + self.message = message + self.typeName = typeName + self.fullTypeName = fullTypeName + self.evaluateName = evaluateName + self.stackTrace = stackTrace + self.innerException = innerException + if update_ids_from_dap and self.innerException: + for o in self.innerException: + ExceptionDetails.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + message = self.message + typeName = self.typeName + fullTypeName = self.fullTypeName + evaluateName = self.evaluateName + stackTrace = self.stackTrace + innerException = self.innerException + if innerException and hasattr(innerException[0], "to_dict"): + innerException = [x.to_dict() for x in innerException] + dct = { + } + if message is not None: + dct['message'] = message + if typeName is not None: + dct['typeName'] = typeName + if fullTypeName is not None: + dct['fullTypeName'] = fullTypeName + if evaluateName is not None: + dct['evaluateName'] = evaluateName + if stackTrace is not None: + dct['stackTrace'] = stackTrace + if innerException is not None: + dct['innerException'] = [ExceptionDetails.update_dict_ids_to_dap(o) for o in innerException] if (update_ids_to_dap and innerException) else innerException + dct.update(self.kwargs) + return dct + + +@register +class DisassembledInstruction(BaseSchema): + """ + Represents a single disassembled instruction. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "address": { + "type": "string", + "description": "The address of the instruction. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise." + }, + "instructionBytes": { + "type": "string", + "description": "Optional raw bytes representing the instruction and its operands, in an implementation-defined format." + }, + "instruction": { + "type": "string", + "description": "Text representing the instruction and its operands, in an implementation-defined format." + }, + "symbol": { + "type": "string", + "description": "Name of the symbol that correponds with the location of this instruction, if any." + }, + "location": { + "description": "Source location that corresponds to this instruction, if any. Should always be set (if available) on the first instruction returned, but can be omitted afterwards if this instruction maps to the same source file as the previous instruction.", + "type": "Source" + }, + "line": { + "type": "integer", + "description": "The line within the source location that corresponds to this instruction, if any." + }, + "column": { + "type": "integer", + "description": "The column within the line that corresponds to this instruction, if any." + }, + "endLine": { + "type": "integer", + "description": "The end line of the range that corresponds to this instruction, if any." + }, + "endColumn": { + "type": "integer", + "description": "The end column of the range that corresponds to this instruction, if any." + } + } + __refs__ = set(['location']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, address, instruction, instructionBytes=None, symbol=None, location=None, line=None, column=None, endLine=None, endColumn=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string address: The address of the instruction. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise. + :param string instruction: Text representing the instruction and its operands, in an implementation-defined format. + :param string instructionBytes: Optional raw bytes representing the instruction and its operands, in an implementation-defined format. + :param string symbol: Name of the symbol that correponds with the location of this instruction, if any. + :param Source location: Source location that corresponds to this instruction, if any. Should always be set (if available) on the first instruction returned, but can be omitted afterwards if this instruction maps to the same source file as the previous instruction. + :param integer line: The line within the source location that corresponds to this instruction, if any. + :param integer column: The column within the line that corresponds to this instruction, if any. + :param integer endLine: The end line of the range that corresponds to this instruction, if any. + :param integer endColumn: The end column of the range that corresponds to this instruction, if any. + """ + self.address = address + self.instruction = instruction + self.instructionBytes = instructionBytes + self.symbol = symbol + if location is None: + self.location = Source() + else: + self.location = Source(update_ids_from_dap=update_ids_from_dap, **location) if location.__class__ != Source else location + self.line = line + self.column = column + self.endLine = endLine + self.endColumn = endColumn + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + address = self.address + instruction = self.instruction + instructionBytes = self.instructionBytes + symbol = self.symbol + location = self.location + line = self.line + column = self.column + endLine = self.endLine + endColumn = self.endColumn + dct = { + 'address': address, + 'instruction': instruction, + } + if instructionBytes is not None: + dct['instructionBytes'] = instructionBytes + if symbol is not None: + dct['symbol'] = symbol + if location is not None: + dct['location'] = location.to_dict(update_ids_to_dap=update_ids_to_dap) + if line is not None: + dct['line'] = line + if column is not None: + dct['column'] = column + if endLine is not None: + dct['endLine'] = endLine + if endColumn is not None: + dct['endColumn'] = endColumn + dct.update(self.kwargs) + return dct + + +@register_request('setDebuggerProperty') +@register +class SetDebuggerPropertyRequest(BaseSchema): + """ + The request can be used to enable or disable debugger features. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setDebuggerProperty" + ] + }, + "arguments": { + "type": "SetDebuggerPropertyArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetDebuggerPropertyArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setDebuggerProperty' + if arguments is None: + self.arguments = SetDebuggerPropertyArguments() + else: + self.arguments = SetDebuggerPropertyArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetDebuggerPropertyArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetDebuggerPropertyArguments(BaseSchema): + """ + Arguments for 'setDebuggerProperty' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "ideOS": { + "type": [ + "string" + ], + "description": "OS where the ide is running. Supported values [Windows, Linux]" + }, + "dontTraceStartPatterns": { + "type": [ + "array" + ], + "description": "Patterns to match with the start of the file paths. Matching paths will be added to a list of file where trace is ignored." + }, + "dontTraceEndPatterns": { + "type": [ + "array" + ], + "description": "Patterns to match with the end of the file paths. Matching paths will be added to a list of file where trace is ignored." + }, + "skipSuspendOnBreakpointException": { + "type": [ + "array" + ], + "description": "List of exceptions that should be skipped when doing condition evaluations." + }, + "skipPrintBreakpointException": { + "type": [ + "array" + ], + "description": "List of exceptions that should skip printing to stderr when doing condition evaluations." + }, + "multiThreadsSingleNotification": { + "type": [ + "boolean" + ], + "description": "If false then a notification is generated for each thread event. If true a single event is gnenerated, and all threads follow that behavior." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, ideOS=None, dontTraceStartPatterns=None, dontTraceEndPatterns=None, skipSuspendOnBreakpointException=None, skipPrintBreakpointException=None, multiThreadsSingleNotification=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ['string'] ideOS: OS where the ide is running. Supported values [Windows, Linux] + :param ['array'] dontTraceStartPatterns: Patterns to match with the start of the file paths. Matching paths will be added to a list of file where trace is ignored. + :param ['array'] dontTraceEndPatterns: Patterns to match with the end of the file paths. Matching paths will be added to a list of file where trace is ignored. + :param ['array'] skipSuspendOnBreakpointException: List of exceptions that should be skipped when doing condition evaluations. + :param ['array'] skipPrintBreakpointException: List of exceptions that should skip printing to stderr when doing condition evaluations. + :param ['boolean'] multiThreadsSingleNotification: If false then a notification is generated for each thread event. If true a single event is gnenerated, and all threads follow that behavior. + """ + self.ideOS = ideOS + self.dontTraceStartPatterns = dontTraceStartPatterns + self.dontTraceEndPatterns = dontTraceEndPatterns + self.skipSuspendOnBreakpointException = skipSuspendOnBreakpointException + self.skipPrintBreakpointException = skipPrintBreakpointException + self.multiThreadsSingleNotification = multiThreadsSingleNotification + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + ideOS = self.ideOS + dontTraceStartPatterns = self.dontTraceStartPatterns + dontTraceEndPatterns = self.dontTraceEndPatterns + skipSuspendOnBreakpointException = self.skipSuspendOnBreakpointException + skipPrintBreakpointException = self.skipPrintBreakpointException + multiThreadsSingleNotification = self.multiThreadsSingleNotification + dct = { + } + if ideOS is not None: + dct['ideOS'] = ideOS + if dontTraceStartPatterns is not None: + dct['dontTraceStartPatterns'] = dontTraceStartPatterns + if dontTraceEndPatterns is not None: + dct['dontTraceEndPatterns'] = dontTraceEndPatterns + if skipSuspendOnBreakpointException is not None: + dct['skipSuspendOnBreakpointException'] = skipSuspendOnBreakpointException + if skipPrintBreakpointException is not None: + dct['skipPrintBreakpointException'] = skipPrintBreakpointException + if multiThreadsSingleNotification is not None: + dct['multiThreadsSingleNotification'] = multiThreadsSingleNotification + dct.update(self.kwargs) + return dct + + +@register_response('setDebuggerProperty') +@register +class SetDebuggerPropertyResponse(BaseSchema): + """ + Response to 'setDebuggerProperty' request. This is just an acknowledgement, so no body field is + required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register_request('setPydevdSourceMap') +@register +class SetPydevdSourceMapRequest(BaseSchema): + """ + Sets multiple PydevdSourceMap for a single source and clears all previous PydevdSourceMap in that + source. + + i.e.: Maps paths and lines in a 1:N mapping (use case: map a single file in the IDE to multiple + IPython cells). + + To clear all PydevdSourceMap for a source, specify an empty array. + + Interaction with breakpoints: When a new mapping is sent, breakpoints that match the source (or + previously matched a source) are reapplied. + + Interaction with launch pathMapping: both mappings are independent. This mapping is applied after + the launch pathMapping. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "setPydevdSourceMap" + ] + }, + "arguments": { + "type": "SetPydevdSourceMapArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, arguments, seq=-1, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param SetPydevdSourceMapArguments arguments: + :param integer seq: Sequence number. + """ + self.type = 'request' + self.command = 'setPydevdSourceMap' + if arguments is None: + self.arguments = SetPydevdSourceMapArguments() + else: + self.arguments = SetPydevdSourceMapArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != SetPydevdSourceMapArguments else arguments + self.seq = seq + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + arguments = self.arguments + seq = self.seq + dct = { + 'type': type, + 'command': command, + 'arguments': arguments.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + dct.update(self.kwargs) + return dct + + +@register +class SetPydevdSourceMapArguments(BaseSchema): + """ + Arguments for 'setPydevdSourceMap' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "source": { + "description": "The source location of the PydevdSourceMap; 'source.path' must be specified (e.g.: for an ipython notebook this could be something as /home/notebook/note.py).", + "type": "Source" + }, + "pydevdSourceMaps": { + "type": "array", + "items": { + "$ref": "#/definitions/PydevdSourceMap" + }, + "description": "The PydevdSourceMaps to be set to the given source (provide an empty array to clear the source mappings for a given path)." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, source, pydevdSourceMaps=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param Source source: The source location of the PydevdSourceMap; 'source.path' must be specified (e.g.: for an ipython notebook this could be something as /home/notebook/note.py). + :param array pydevdSourceMaps: The PydevdSourceMaps to be set to the given source (provide an empty array to clear the source mappings for a given path). + """ + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.pydevdSourceMaps = pydevdSourceMaps + if update_ids_from_dap and self.pydevdSourceMaps: + for o in self.pydevdSourceMaps: + PydevdSourceMap.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + source = self.source + pydevdSourceMaps = self.pydevdSourceMaps + if pydevdSourceMaps and hasattr(pydevdSourceMaps[0], "to_dict"): + pydevdSourceMaps = [x.to_dict() for x in pydevdSourceMaps] + dct = { + 'source': source.to_dict(update_ids_to_dap=update_ids_to_dap), + } + if pydevdSourceMaps is not None: + dct['pydevdSourceMaps'] = [PydevdSourceMap.update_dict_ids_to_dap(o) for o in pydevdSourceMaps] if (update_ids_to_dap and pydevdSourceMaps) else pydevdSourceMaps + dct.update(self.kwargs) + return dct + + +@register_response('setPydevdSourceMap') +@register +class SetPydevdSourceMapResponse(BaseSchema): + """ + Response to 'setPydevdSourceMap' request. This is just an acknowledgement, so no body field is + required. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Contains request result if success is true and optional error details if success is false." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, seq=-1, message=None, body=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] body: Contains request result if success is true and optional error details if success is false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + self.seq = seq + self.message = message + self.body = body + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + seq = self.seq + message = self.message + body = self.body + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'seq': seq, + } + if message is not None: + dct['message'] = message + if body is not None: + dct['body'] = body + dct.update(self.kwargs) + return dct + + +@register +class PydevdSourceMap(BaseSchema): + """ + Information that allows mapping a local line to a remote source/line. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "line": { + "type": "integer", + "description": "The local line to which the mapping should map to (e.g.: for an ipython notebook this would be the first line of the cell in the file)." + }, + "endLine": { + "type": "integer", + "description": "The end line." + }, + "runtimeSource": { + "description": "The path that the user has remotely -- 'source.path' must be specified (e.g.: for an ipython notebook this could be something as '')", + "type": "Source" + }, + "runtimeLine": { + "type": "integer", + "description": "The remote line to which the mapping should map to (e.g.: for an ipython notebook this would be always 1 as it'd map the start of the cell)." + } + } + __refs__ = set(['runtimeSource']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, line, endLine, runtimeSource, runtimeLine, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer line: The local line to which the mapping should map to (e.g.: for an ipython notebook this would be the first line of the cell in the file). + :param integer endLine: The end line. + :param Source runtimeSource: The path that the user has remotely -- 'source.path' must be specified (e.g.: for an ipython notebook this could be something as '') + :param integer runtimeLine: The remote line to which the mapping should map to (e.g.: for an ipython notebook this would be always 1 as it'd map the start of the cell). + """ + self.line = line + self.endLine = endLine + if runtimeSource is None: + self.runtimeSource = Source() + else: + self.runtimeSource = Source(update_ids_from_dap=update_ids_from_dap, **runtimeSource) if runtimeSource.__class__ != Source else runtimeSource + self.runtimeLine = runtimeLine + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + line = self.line + endLine = self.endLine + runtimeSource = self.runtimeSource + runtimeLine = self.runtimeLine + dct = { + 'line': line, + 'endLine': endLine, + 'runtimeSource': runtimeSource.to_dict(update_ids_to_dap=update_ids_to_dap), + 'runtimeLine': runtimeLine, + } + dct.update(self.kwargs) + return dct + + +@register_request('pydevdSystemInfo') +@register +class PydevdSystemInfoRequest(BaseSchema): + """ + The request can be used retrieve system information, python version, etc. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "request" + ] + }, + "command": { + "type": "string", + "enum": [ + "pydevdSystemInfo" + ] + }, + "arguments": { + "type": "PydevdSystemInfoArguments" + } + } + __refs__ = set(['arguments']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, seq=-1, arguments=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param string command: + :param integer seq: Sequence number. + :param PydevdSystemInfoArguments arguments: + """ + self.type = 'request' + self.command = 'pydevdSystemInfo' + self.seq = seq + if arguments is None: + self.arguments = PydevdSystemInfoArguments() + else: + self.arguments = PydevdSystemInfoArguments(update_ids_from_dap=update_ids_from_dap, **arguments) if arguments.__class__ != PydevdSystemInfoArguments else arguments + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + command = self.command + seq = self.seq + arguments = self.arguments + dct = { + 'type': type, + 'command': command, + 'seq': seq, + } + if arguments is not None: + dct['arguments'] = arguments.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class PydevdSystemInfoArguments(BaseSchema): + """ + Arguments for 'pydevdSystemInfo' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register_response('pydevdSystemInfo') +@register +class PydevdSystemInfoResponse(BaseSchema): + """ + Response to 'pydevdSystemInfo' request. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "seq": { + "type": "integer", + "description": "Sequence number." + }, + "type": { + "type": "string", + "enum": [ + "response" + ] + }, + "request_seq": { + "type": "integer", + "description": "Sequence number of the corresponding request." + }, + "success": { + "type": "boolean", + "description": "Outcome of the request." + }, + "command": { + "type": "string", + "description": "The command requested." + }, + "message": { + "type": "string", + "description": "Contains error message if success == false." + }, + "body": { + "type": "object", + "properties": { + "python": { + "$ref": "#/definitions/PydevdPythonInfo", + "description": "Information about the python version running in the current process." + }, + "platform": { + "$ref": "#/definitions/PydevdPlatformInfo", + "description": "Information about the plarforn on which the current process is running." + }, + "process": { + "$ref": "#/definitions/PydevdProcessInfo", + "description": "Information about the current process." + } + }, + "required": [ + "python", + "platform", + "process" + ] + } + } + __refs__ = set(['body']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, request_seq, success, command, body, seq=-1, message=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string type: + :param integer request_seq: Sequence number of the corresponding request. + :param boolean success: Outcome of the request. + :param string command: The command requested. + :param PydevdSystemInfoResponseBody body: + :param integer seq: Sequence number. + :param string message: Contains error message if success == false. + """ + self.type = 'response' + self.request_seq = request_seq + self.success = success + self.command = command + if body is None: + self.body = PydevdSystemInfoResponseBody() + else: + self.body = PydevdSystemInfoResponseBody(update_ids_from_dap=update_ids_from_dap, **body) if body.__class__ != PydevdSystemInfoResponseBody else body + self.seq = seq + self.message = message + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + type = self.type # noqa (assign to builtin) + request_seq = self.request_seq + success = self.success + command = self.command + body = self.body + seq = self.seq + message = self.message + dct = { + 'type': type, + 'request_seq': request_seq, + 'success': success, + 'command': command, + 'body': body.to_dict(update_ids_to_dap=update_ids_to_dap), + 'seq': seq, + } + if message is not None: + dct['message'] = message + dct.update(self.kwargs) + return dct + + +@register +class PydevdPythonInfo(BaseSchema): + """ + This object contains python version and implementation details. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "version": { + "type": "string", + "description": "Python version as a string in semver format: ..." + }, + "implementation": { + "description": "Python version as a string in this format ...", + "type": "PydevdPythonImplementationInfo" + } + } + __refs__ = set(['implementation']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, version=None, implementation=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string version: Python version as a string in semver format: ... + :param PydevdPythonImplementationInfo implementation: Python version as a string in this format ... + """ + self.version = version + if implementation is None: + self.implementation = PydevdPythonImplementationInfo() + else: + self.implementation = PydevdPythonImplementationInfo(update_ids_from_dap=update_ids_from_dap, **implementation) if implementation.__class__ != PydevdPythonImplementationInfo else implementation + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + version = self.version + implementation = self.implementation + dct = { + } + if version is not None: + dct['version'] = version + if implementation is not None: + dct['implementation'] = implementation.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class PydevdPythonImplementationInfo(BaseSchema): + """ + This object contains python implementation details. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "Python implementation name." + }, + "version": { + "type": "string", + "description": "Python version as a string in semver format: ..." + }, + "description": { + "type": "string", + "description": "Optional description for this python implementation." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name=None, version=None, description=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: Python implementation name. + :param string version: Python version as a string in semver format: ... + :param string description: Optional description for this python implementation. + """ + self.name = name + self.version = version + self.description = description + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + version = self.version + description = self.description + dct = { + } + if name is not None: + dct['name'] = name + if version is not None: + dct['version'] = version + if description is not None: + dct['description'] = description + dct.update(self.kwargs) + return dct + + +@register +class PydevdPlatformInfo(BaseSchema): + """ + This object contains python version and implementation details. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "Name of the platform as returned by 'sys.platform'." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: Name of the platform as returned by 'sys.platform'. + """ + self.name = name + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + dct = { + } + if name is not None: + dct['name'] = name + dct.update(self.kwargs) + return dct + + +@register +class PydevdProcessInfo(BaseSchema): + """ + This object contains python process details. + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "pid": { + "type": "integer", + "description": "Process ID for the current process." + }, + "executable": { + "type": "string", + "description": "Path to the executable as returned by 'sys.executable'." + }, + "bitness": { + "type": "integer", + "description": "Integer value indicating the bitness of the current process." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, pid=None, executable=None, bitness=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer pid: Process ID for the current process. + :param string executable: Path to the executable as returned by 'sys.executable'. + :param integer bitness: Integer value indicating the bitness of the current process. + """ + self.pid = pid + self.executable = executable + self.bitness = bitness + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + pid = self.pid + executable = self.executable + bitness = self.bitness + dct = { + } + if pid is not None: + dct['pid'] = pid + if executable is not None: + dct['executable'] = executable + if bitness is not None: + dct['bitness'] = bitness + dct.update(self.kwargs) + return dct + + +@register +class ErrorResponseBody(BaseSchema): + """ + "body" of ErrorResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "error": { + "description": "An optional, structured error message.", + "type": "Message" + } + } + __refs__ = set(['error']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, error=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param Message error: An optional, structured error message. + """ + if error is None: + self.error = Message() + else: + self.error = Message(update_ids_from_dap=update_ids_from_dap, **error) if error.__class__ != Message else error + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + error = self.error + dct = { + } + if error is not None: + dct['error'] = error.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class StoppedEventBody(BaseSchema): + """ + "body" of StoppedEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "reason": { + "type": "string", + "description": "The reason for the event.\nFor backward compatibility this string is shown in the UI if the 'description' attribute is missing (but it must not be translated).", + "_enum": [ + "step", + "breakpoint", + "exception", + "pause", + "entry", + "goto", + "function breakpoint", + "data breakpoint" + ] + }, + "description": { + "type": "string", + "description": "The full reason for the event, e.g. 'Paused on exception'. This string is shown in the UI as is and must be translated." + }, + "threadId": { + "type": "integer", + "description": "The thread which was stopped." + }, + "preserveFocusHint": { + "type": "boolean", + "description": "A value of true hints to the frontend that this event should not change the focus." + }, + "text": { + "type": "string", + "description": "Additional information. E.g. if reason is 'exception', text contains the exception name. This string is shown in the UI." + }, + "allThreadsStopped": { + "type": "boolean", + "description": "If 'allThreadsStopped' is true, a debug adapter can announce that all threads have stopped.\n- The client should use this information to enable that all threads can be expanded to access their stacktraces.\n- If the attribute is missing or false, only the thread with the given threadId can be expanded." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, reason, description=None, threadId=None, preserveFocusHint=None, text=None, allThreadsStopped=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string reason: The reason for the event. + For backward compatibility this string is shown in the UI if the 'description' attribute is missing (but it must not be translated). + :param string description: The full reason for the event, e.g. 'Paused on exception'. This string is shown in the UI as is and must be translated. + :param integer threadId: The thread which was stopped. + :param boolean preserveFocusHint: A value of true hints to the frontend that this event should not change the focus. + :param string text: Additional information. E.g. if reason is 'exception', text contains the exception name. This string is shown in the UI. + :param boolean allThreadsStopped: If 'allThreadsStopped' is true, a debug adapter can announce that all threads have stopped. + - The client should use this information to enable that all threads can be expanded to access their stacktraces. + - If the attribute is missing or false, only the thread with the given threadId can be expanded. + """ + self.reason = reason + self.description = description + self.threadId = threadId + self.preserveFocusHint = preserveFocusHint + self.text = text + self.allThreadsStopped = allThreadsStopped + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + reason = self.reason + description = self.description + threadId = self.threadId + preserveFocusHint = self.preserveFocusHint + text = self.text + allThreadsStopped = self.allThreadsStopped + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'reason': reason, + } + if description is not None: + dct['description'] = description + if threadId is not None: + dct['threadId'] = threadId + if preserveFocusHint is not None: + dct['preserveFocusHint'] = preserveFocusHint + if text is not None: + dct['text'] = text + if allThreadsStopped is not None: + dct['allThreadsStopped'] = allThreadsStopped + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register +class ContinuedEventBody(BaseSchema): + """ + "body" of ContinuedEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threadId": { + "type": "integer", + "description": "The thread which was continued." + }, + "allThreadsContinued": { + "type": "boolean", + "description": "If 'allThreadsContinued' is true, a debug adapter can announce that all threads have continued." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threadId, allThreadsContinued=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer threadId: The thread which was continued. + :param boolean allThreadsContinued: If 'allThreadsContinued' is true, a debug adapter can announce that all threads have continued. + """ + self.threadId = threadId + self.allThreadsContinued = allThreadsContinued + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threadId = self.threadId + allThreadsContinued = self.allThreadsContinued + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'threadId': threadId, + } + if allThreadsContinued is not None: + dct['allThreadsContinued'] = allThreadsContinued + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register +class ExitedEventBody(BaseSchema): + """ + "body" of ExitedEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "exitCode": { + "type": "integer", + "description": "The exit code returned from the debuggee." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, exitCode, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param integer exitCode: The exit code returned from the debuggee. + """ + self.exitCode = exitCode + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + exitCode = self.exitCode + dct = { + 'exitCode': exitCode, + } + dct.update(self.kwargs) + return dct + + +@register +class TerminatedEventBody(BaseSchema): + """ + "body" of TerminatedEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "restart": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "A debug adapter may set 'restart' to true (or to an arbitrary object) to request that the front end restarts the session.\nThe value is not interpreted by the client and passed unmodified as an attribute '__restart' to the 'launch' and 'attach' requests." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, restart=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] restart: A debug adapter may set 'restart' to true (or to an arbitrary object) to request that the front end restarts the session. + The value is not interpreted by the client and passed unmodified as an attribute '__restart' to the 'launch' and 'attach' requests. + """ + self.restart = restart + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + restart = self.restart + dct = { + } + if restart is not None: + dct['restart'] = restart + dct.update(self.kwargs) + return dct + + +@register +class ThreadEventBody(BaseSchema): + """ + "body" of ThreadEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "reason": { + "type": "string", + "description": "The reason for the event.", + "_enum": [ + "started", + "exited" + ] + }, + "threadId": { + "type": "integer", + "description": "The identifier of the thread." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, reason, threadId, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string reason: The reason for the event. + :param integer threadId: The identifier of the thread. + """ + self.reason = reason + self.threadId = threadId + if update_ids_from_dap: + self.threadId = self._translate_id_from_dap(self.threadId) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_from_dap(dct['threadId']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + reason = self.reason + threadId = self.threadId + if update_ids_to_dap: + if threadId is not None: + threadId = self._translate_id_to_dap(threadId) + dct = { + 'reason': reason, + 'threadId': threadId, + } + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'threadId' in dct: + dct['threadId'] = cls._translate_id_to_dap(dct['threadId']) + return dct + + +@register +class OutputEventBody(BaseSchema): + """ + "body" of OutputEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "category": { + "type": "string", + "description": "The output category. If not specified, 'console' is assumed.", + "_enum": [ + "console", + "stdout", + "stderr", + "telemetry" + ] + }, + "output": { + "type": "string", + "description": "The output to report." + }, + "variablesReference": { + "type": "number", + "description": "If an attribute 'variablesReference' exists and its value is > 0, the output contains objects which can be retrieved by passing 'variablesReference' to the 'variables' request." + }, + "source": { + "description": "An optional source location where the output was produced.", + "type": "Source" + }, + "line": { + "type": "integer", + "description": "An optional source location line where the output was produced." + }, + "column": { + "type": "integer", + "description": "An optional source location column where the output was produced." + }, + "data": { + "type": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ], + "description": "Optional data to report. For the 'telemetry' category the data will be sent to telemetry, for the other categories the data is shown in JSON format." + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, output, category=None, variablesReference=None, source=None, line=None, column=None, data=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string output: The output to report. + :param string category: The output category. If not specified, 'console' is assumed. + :param number variablesReference: If an attribute 'variablesReference' exists and its value is > 0, the output contains objects which can be retrieved by passing 'variablesReference' to the 'variables' request. + :param Source source: An optional source location where the output was produced. + :param integer line: An optional source location line where the output was produced. + :param integer column: An optional source location column where the output was produced. + :param ['array', 'boolean', 'integer', 'null', 'number', 'object', 'string'] data: Optional data to report. For the 'telemetry' category the data will be sent to telemetry, for the other categories the data is shown in JSON format. + """ + self.output = output + self.category = category + self.variablesReference = variablesReference + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.line = line + self.column = column + self.data = data + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + output = self.output + category = self.category + variablesReference = self.variablesReference + source = self.source + line = self.line + column = self.column + data = self.data + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'output': output, + } + if category is not None: + dct['category'] = category + if variablesReference is not None: + dct['variablesReference'] = variablesReference + if source is not None: + dct['source'] = source.to_dict(update_ids_to_dap=update_ids_to_dap) + if line is not None: + dct['line'] = line + if column is not None: + dct['column'] = column + if data is not None: + dct['data'] = data + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register +class BreakpointEventBody(BaseSchema): + """ + "body" of BreakpointEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "reason": { + "type": "string", + "description": "The reason for the event.", + "_enum": [ + "changed", + "new", + "removed" + ] + }, + "breakpoint": { + "description": "The 'id' attribute is used to find the target breakpoint and the other attributes are used as the new values.", + "type": "Breakpoint" + } + } + __refs__ = set(['breakpoint']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, reason, breakpoint, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string reason: The reason for the event. + :param Breakpoint breakpoint: The 'id' attribute is used to find the target breakpoint and the other attributes are used as the new values. + """ + self.reason = reason + if breakpoint is None: + self.breakpoint = Breakpoint() + else: + self.breakpoint = Breakpoint(update_ids_from_dap=update_ids_from_dap, **breakpoint) if breakpoint.__class__ != Breakpoint else breakpoint + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + reason = self.reason + breakpoint = self.breakpoint # noqa (assign to builtin) + dct = { + 'reason': reason, + 'breakpoint': breakpoint.to_dict(update_ids_to_dap=update_ids_to_dap), + } + dct.update(self.kwargs) + return dct + + +@register +class ModuleEventBody(BaseSchema): + """ + "body" of ModuleEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "reason": { + "type": "string", + "description": "The reason for the event.", + "enum": [ + "new", + "changed", + "removed" + ] + }, + "module": { + "description": "The new, changed, or removed module. In case of 'removed' only the module id is used.", + "type": "Module" + } + } + __refs__ = set(['module']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, reason, module, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string reason: The reason for the event. + :param Module module: The new, changed, or removed module. In case of 'removed' only the module id is used. + """ + self.reason = reason + if module is None: + self.module = Module() + else: + self.module = Module(update_ids_from_dap=update_ids_from_dap, **module) if module.__class__ != Module else module + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + reason = self.reason + module = self.module + dct = { + 'reason': reason, + 'module': module.to_dict(update_ids_to_dap=update_ids_to_dap), + } + dct.update(self.kwargs) + return dct + + +@register +class LoadedSourceEventBody(BaseSchema): + """ + "body" of LoadedSourceEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "reason": { + "type": "string", + "description": "The reason for the event.", + "enum": [ + "new", + "changed", + "removed" + ] + }, + "source": { + "description": "The new, changed, or removed source.", + "type": "Source" + } + } + __refs__ = set(['source']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, reason, source, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string reason: The reason for the event. + :param Source source: The new, changed, or removed source. + """ + self.reason = reason + if source is None: + self.source = Source() + else: + self.source = Source(update_ids_from_dap=update_ids_from_dap, **source) if source.__class__ != Source else source + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + reason = self.reason + source = self.source + dct = { + 'reason': reason, + 'source': source.to_dict(update_ids_to_dap=update_ids_to_dap), + } + dct.update(self.kwargs) + return dct + + +@register +class ProcessEventBody(BaseSchema): + """ + "body" of ProcessEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "name": { + "type": "string", + "description": "The logical name of the process. This is usually the full path to process's executable file. Example: /home/example/myproj/program.js." + }, + "systemProcessId": { + "type": "integer", + "description": "The system process id of the debugged process. This property will be missing for non-system processes." + }, + "isLocalProcess": { + "type": "boolean", + "description": "If true, the process is running on the same computer as the debug adapter." + }, + "startMethod": { + "type": "string", + "enum": [ + "launch", + "attach", + "attachForSuspendedLaunch" + ], + "description": "Describes how the debug engine started debugging this process.", + "enumDescriptions": [ + "Process was launched under the debugger.", + "Debugger attached to an existing process.", + "A project launcher component has launched a new process in a suspended state and then asked the debugger to attach." + ] + }, + "pointerSize": { + "type": "integer", + "description": "The size of a pointer or address for this process, in bits. This value may be used by clients when formatting addresses for display." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, name, systemProcessId=None, isLocalProcess=None, startMethod=None, pointerSize=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string name: The logical name of the process. This is usually the full path to process's executable file. Example: /home/example/myproj/program.js. + :param integer systemProcessId: The system process id of the debugged process. This property will be missing for non-system processes. + :param boolean isLocalProcess: If true, the process is running on the same computer as the debug adapter. + :param string startMethod: Describes how the debug engine started debugging this process. + :param integer pointerSize: The size of a pointer or address for this process, in bits. This value may be used by clients when formatting addresses for display. + """ + self.name = name + self.systemProcessId = systemProcessId + self.isLocalProcess = isLocalProcess + self.startMethod = startMethod + self.pointerSize = pointerSize + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + name = self.name + systemProcessId = self.systemProcessId + isLocalProcess = self.isLocalProcess + startMethod = self.startMethod + pointerSize = self.pointerSize + dct = { + 'name': name, + } + if systemProcessId is not None: + dct['systemProcessId'] = systemProcessId + if isLocalProcess is not None: + dct['isLocalProcess'] = isLocalProcess + if startMethod is not None: + dct['startMethod'] = startMethod + if pointerSize is not None: + dct['pointerSize'] = pointerSize + dct.update(self.kwargs) + return dct + + +@register +class CapabilitiesEventBody(BaseSchema): + """ + "body" of CapabilitiesEvent + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "capabilities": { + "description": "The set of updated capabilities.", + "type": "Capabilities" + } + } + __refs__ = set(['capabilities']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, capabilities, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param Capabilities capabilities: The set of updated capabilities. + """ + if capabilities is None: + self.capabilities = Capabilities() + else: + self.capabilities = Capabilities(update_ids_from_dap=update_ids_from_dap, **capabilities) if capabilities.__class__ != Capabilities else capabilities + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + capabilities = self.capabilities + dct = { + 'capabilities': capabilities.to_dict(update_ids_to_dap=update_ids_to_dap), + } + dct.update(self.kwargs) + return dct + + +@register +class RunInTerminalRequestArgumentsEnv(BaseSchema): + """ + "env" of RunInTerminalRequestArguments + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register +class RunInTerminalResponseBody(BaseSchema): + """ + "body" of RunInTerminalResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "processId": { + "type": "number", + "description": "The process ID." + }, + "shellProcessId": { + "type": "number", + "description": "The process ID of the terminal shell." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, processId=None, shellProcessId=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param number processId: The process ID. + :param number shellProcessId: The process ID of the terminal shell. + """ + self.processId = processId + self.shellProcessId = shellProcessId + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + processId = self.processId + shellProcessId = self.shellProcessId + dct = { + } + if processId is not None: + dct['processId'] = processId + if shellProcessId is not None: + dct['shellProcessId'] = shellProcessId + dct.update(self.kwargs) + return dct + + +@register +class SetBreakpointsResponseBody(BaseSchema): + """ + "body" of SetBreakpointsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the breakpoints. The array elements are in the same order as the elements of the 'breakpoints' (or the deprecated 'lines') array in the arguments." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, breakpoints, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array breakpoints: Information about the breakpoints. The array elements are in the same order as the elements of the 'breakpoints' (or the deprecated 'lines') array in the arguments. + """ + self.breakpoints = breakpoints + if update_ids_from_dap and self.breakpoints: + for o in self.breakpoints: + Breakpoint.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + breakpoints = self.breakpoints + if breakpoints and hasattr(breakpoints[0], "to_dict"): + breakpoints = [x.to_dict() for x in breakpoints] + dct = { + 'breakpoints': [Breakpoint.update_dict_ids_to_dap(o) for o in breakpoints] if (update_ids_to_dap and breakpoints) else breakpoints, + } + dct.update(self.kwargs) + return dct + + +@register +class SetFunctionBreakpointsResponseBody(BaseSchema): + """ + "body" of SetFunctionBreakpointsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the breakpoints. The array elements correspond to the elements of the 'breakpoints' array." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, breakpoints, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array breakpoints: Information about the breakpoints. The array elements correspond to the elements of the 'breakpoints' array. + """ + self.breakpoints = breakpoints + if update_ids_from_dap and self.breakpoints: + for o in self.breakpoints: + Breakpoint.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + breakpoints = self.breakpoints + if breakpoints and hasattr(breakpoints[0], "to_dict"): + breakpoints = [x.to_dict() for x in breakpoints] + dct = { + 'breakpoints': [Breakpoint.update_dict_ids_to_dap(o) for o in breakpoints] if (update_ids_to_dap and breakpoints) else breakpoints, + } + dct.update(self.kwargs) + return dct + + +@register +class DataBreakpointInfoResponseBody(BaseSchema): + """ + "body" of DataBreakpointInfoResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "dataId": { + "type": [ + "string", + "null" + ], + "description": "An identifier for the data on which a data breakpoint can be registered with the setDataBreakpoints request or null if no data breakpoint is available." + }, + "description": { + "type": "string", + "description": "UI string that describes on what data the breakpoint is set on or why a data breakpoint is not available." + }, + "accessTypes": { + "type": "array", + "items": { + "$ref": "#/definitions/DataBreakpointAccessType" + }, + "description": "Optional attribute listing the available access types for a potential data breakpoint. A UI frontend could surface this information." + }, + "canPersist": { + "type": "boolean", + "description": "Optional attribute indicating that a potential data breakpoint could be persisted across sessions." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, dataId, description, accessTypes=None, canPersist=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param ['string', 'null'] dataId: An identifier for the data on which a data breakpoint can be registered with the setDataBreakpoints request or null if no data breakpoint is available. + :param string description: UI string that describes on what data the breakpoint is set on or why a data breakpoint is not available. + :param array accessTypes: Optional attribute listing the available access types for a potential data breakpoint. A UI frontend could surface this information. + :param boolean canPersist: Optional attribute indicating that a potential data breakpoint could be persisted across sessions. + """ + self.dataId = dataId + self.description = description + self.accessTypes = accessTypes + if update_ids_from_dap and self.accessTypes: + for o in self.accessTypes: + DataBreakpointAccessType.update_dict_ids_from_dap(o) + self.canPersist = canPersist + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dataId = self.dataId + description = self.description + accessTypes = self.accessTypes + if accessTypes and hasattr(accessTypes[0], "to_dict"): + accessTypes = [x.to_dict() for x in accessTypes] + canPersist = self.canPersist + dct = { + 'dataId': dataId, + 'description': description, + } + if accessTypes is not None: + dct['accessTypes'] = [DataBreakpointAccessType.update_dict_ids_to_dap(o) for o in accessTypes] if (update_ids_to_dap and accessTypes) else accessTypes + if canPersist is not None: + dct['canPersist'] = canPersist + dct.update(self.kwargs) + return dct + + +@register +class SetDataBreakpointsResponseBody(BaseSchema): + """ + "body" of SetDataBreakpointsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "breakpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/Breakpoint" + }, + "description": "Information about the data breakpoints. The array elements correspond to the elements of the input argument 'breakpoints' array." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, breakpoints, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array breakpoints: Information about the data breakpoints. The array elements correspond to the elements of the input argument 'breakpoints' array. + """ + self.breakpoints = breakpoints + if update_ids_from_dap and self.breakpoints: + for o in self.breakpoints: + Breakpoint.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + breakpoints = self.breakpoints + if breakpoints and hasattr(breakpoints[0], "to_dict"): + breakpoints = [x.to_dict() for x in breakpoints] + dct = { + 'breakpoints': [Breakpoint.update_dict_ids_to_dap(o) for o in breakpoints] if (update_ids_to_dap and breakpoints) else breakpoints, + } + dct.update(self.kwargs) + return dct + + +@register +class ContinueResponseBody(BaseSchema): + """ + "body" of ContinueResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "allThreadsContinued": { + "type": "boolean", + "description": "If true, the 'continue' request has ignored the specified thread and continued all threads instead. If this attribute is missing a value of 'true' is assumed for backward compatibility." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, allThreadsContinued=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param boolean allThreadsContinued: If true, the 'continue' request has ignored the specified thread and continued all threads instead. If this attribute is missing a value of 'true' is assumed for backward compatibility. + """ + self.allThreadsContinued = allThreadsContinued + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + allThreadsContinued = self.allThreadsContinued + dct = { + } + if allThreadsContinued is not None: + dct['allThreadsContinued'] = allThreadsContinued + dct.update(self.kwargs) + return dct + + +@register +class StackTraceResponseBody(BaseSchema): + """ + "body" of StackTraceResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "stackFrames": { + "type": "array", + "items": { + "$ref": "#/definitions/StackFrame" + }, + "description": "The frames of the stackframe. If the array has length zero, there are no stackframes available.\nThis means that there is no location information available." + }, + "totalFrames": { + "type": "integer", + "description": "The total number of frames available." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, stackFrames, totalFrames=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array stackFrames: The frames of the stackframe. If the array has length zero, there are no stackframes available. + This means that there is no location information available. + :param integer totalFrames: The total number of frames available. + """ + self.stackFrames = stackFrames + if update_ids_from_dap and self.stackFrames: + for o in self.stackFrames: + StackFrame.update_dict_ids_from_dap(o) + self.totalFrames = totalFrames + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + stackFrames = self.stackFrames + if stackFrames and hasattr(stackFrames[0], "to_dict"): + stackFrames = [x.to_dict() for x in stackFrames] + totalFrames = self.totalFrames + dct = { + 'stackFrames': [StackFrame.update_dict_ids_to_dap(o) for o in stackFrames] if (update_ids_to_dap and stackFrames) else stackFrames, + } + if totalFrames is not None: + dct['totalFrames'] = totalFrames + dct.update(self.kwargs) + return dct + + +@register +class ScopesResponseBody(BaseSchema): + """ + "body" of ScopesResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "scopes": { + "type": "array", + "items": { + "$ref": "#/definitions/Scope" + }, + "description": "The scopes of the stackframe. If the array has length zero, there are no scopes available." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, scopes, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array scopes: The scopes of the stackframe. If the array has length zero, there are no scopes available. + """ + self.scopes = scopes + if update_ids_from_dap and self.scopes: + for o in self.scopes: + Scope.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + scopes = self.scopes + if scopes and hasattr(scopes[0], "to_dict"): + scopes = [x.to_dict() for x in scopes] + dct = { + 'scopes': [Scope.update_dict_ids_to_dap(o) for o in scopes] if (update_ids_to_dap and scopes) else scopes, + } + dct.update(self.kwargs) + return dct + + +@register +class VariablesResponseBody(BaseSchema): + """ + "body" of VariablesResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "variables": { + "type": "array", + "items": { + "$ref": "#/definitions/Variable" + }, + "description": "All (or a range) of variables for the given variable reference." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, variables, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array variables: All (or a range) of variables for the given variable reference. + """ + self.variables = variables + if update_ids_from_dap and self.variables: + for o in self.variables: + Variable.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + variables = self.variables + if variables and hasattr(variables[0], "to_dict"): + variables = [x.to_dict() for x in variables] + dct = { + 'variables': [Variable.update_dict_ids_to_dap(o) for o in variables] if (update_ids_to_dap and variables) else variables, + } + dct.update(self.kwargs) + return dct + + +@register +class SetVariableResponseBody(BaseSchema): + """ + "body" of SetVariableResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "value": { + "type": "string", + "description": "The new value of the variable." + }, + "type": { + "type": "string", + "description": "The type of the new value. Typically shown in the UI when hovering over the value." + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the new value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, value, type=None, variablesReference=None, namedVariables=None, indexedVariables=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string value: The new value of the variable. + :param string type: The type of the new value. Typically shown in the UI when hovering over the value. + :param number variablesReference: If variablesReference is > 0, the new value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest. + :param number namedVariables: The number of named child variables. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + :param number indexedVariables: The number of indexed child variables. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + """ + self.value = value + self.type = type + self.variablesReference = variablesReference + self.namedVariables = namedVariables + self.indexedVariables = indexedVariables + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + value = self.value + type = self.type # noqa (assign to builtin) + variablesReference = self.variablesReference + namedVariables = self.namedVariables + indexedVariables = self.indexedVariables + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'value': value, + } + if type is not None: + dct['type'] = type + if variablesReference is not None: + dct['variablesReference'] = variablesReference + if namedVariables is not None: + dct['namedVariables'] = namedVariables + if indexedVariables is not None: + dct['indexedVariables'] = indexedVariables + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register +class SourceResponseBody(BaseSchema): + """ + "body" of SourceResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "content": { + "type": "string", + "description": "Content of the source reference." + }, + "mimeType": { + "type": "string", + "description": "Optional content type (mime type) of the source." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, content, mimeType=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string content: Content of the source reference. + :param string mimeType: Optional content type (mime type) of the source. + """ + self.content = content + self.mimeType = mimeType + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + content = self.content + mimeType = self.mimeType + dct = { + 'content': content, + } + if mimeType is not None: + dct['mimeType'] = mimeType + dct.update(self.kwargs) + return dct + + +@register +class ThreadsResponseBody(BaseSchema): + """ + "body" of ThreadsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "threads": { + "type": "array", + "items": { + "$ref": "#/definitions/Thread" + }, + "description": "All threads." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, threads, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array threads: All threads. + """ + self.threads = threads + if update_ids_from_dap and self.threads: + for o in self.threads: + Thread.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + threads = self.threads + if threads and hasattr(threads[0], "to_dict"): + threads = [x.to_dict() for x in threads] + dct = { + 'threads': [Thread.update_dict_ids_to_dap(o) for o in threads] if (update_ids_to_dap and threads) else threads, + } + dct.update(self.kwargs) + return dct + + +@register +class ModulesResponseBody(BaseSchema): + """ + "body" of ModulesResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "modules": { + "type": "array", + "items": { + "$ref": "#/definitions/Module" + }, + "description": "All modules or range of modules." + }, + "totalModules": { + "type": "integer", + "description": "The total number of modules available." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, modules, totalModules=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array modules: All modules or range of modules. + :param integer totalModules: The total number of modules available. + """ + self.modules = modules + if update_ids_from_dap and self.modules: + for o in self.modules: + Module.update_dict_ids_from_dap(o) + self.totalModules = totalModules + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + modules = self.modules + if modules and hasattr(modules[0], "to_dict"): + modules = [x.to_dict() for x in modules] + totalModules = self.totalModules + dct = { + 'modules': [Module.update_dict_ids_to_dap(o) for o in modules] if (update_ids_to_dap and modules) else modules, + } + if totalModules is not None: + dct['totalModules'] = totalModules + dct.update(self.kwargs) + return dct + + +@register +class LoadedSourcesResponseBody(BaseSchema): + """ + "body" of LoadedSourcesResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "sources": { + "type": "array", + "items": { + "$ref": "#/definitions/Source" + }, + "description": "Set of loaded sources." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, sources, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array sources: Set of loaded sources. + """ + self.sources = sources + if update_ids_from_dap and self.sources: + for o in self.sources: + Source.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + sources = self.sources + if sources and hasattr(sources[0], "to_dict"): + sources = [x.to_dict() for x in sources] + dct = { + 'sources': [Source.update_dict_ids_to_dap(o) for o in sources] if (update_ids_to_dap and sources) else sources, + } + dct.update(self.kwargs) + return dct + + +@register +class EvaluateResponseBody(BaseSchema): + """ + "body" of EvaluateResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "result": { + "type": "string", + "description": "The result of the evaluate request." + }, + "type": { + "type": "string", + "description": "The optional type of the evaluate result." + }, + "presentationHint": { + "description": "Properties of a evaluate result that can be used to determine how to render the result in the UI.", + "type": "VariablePresentationHint" + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the evaluate result is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "memoryReference": { + "type": "string", + "description": "Memory reference to a location appropriate for this result. For pointer type eval results, this is generally a reference to the memory address contained in the pointer." + } + } + __refs__ = set(['presentationHint']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, result, variablesReference, type=None, presentationHint=None, namedVariables=None, indexedVariables=None, memoryReference=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string result: The result of the evaluate request. + :param number variablesReference: If variablesReference is > 0, the evaluate result is structured and its children can be retrieved by passing variablesReference to the VariablesRequest. + :param string type: The optional type of the evaluate result. + :param VariablePresentationHint presentationHint: Properties of a evaluate result that can be used to determine how to render the result in the UI. + :param number namedVariables: The number of named child variables. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + :param number indexedVariables: The number of indexed child variables. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + :param string memoryReference: Memory reference to a location appropriate for this result. For pointer type eval results, this is generally a reference to the memory address contained in the pointer. + """ + self.result = result + self.variablesReference = variablesReference + self.type = type + if presentationHint is None: + self.presentationHint = VariablePresentationHint() + else: + self.presentationHint = VariablePresentationHint(update_ids_from_dap=update_ids_from_dap, **presentationHint) if presentationHint.__class__ != VariablePresentationHint else presentationHint + self.namedVariables = namedVariables + self.indexedVariables = indexedVariables + self.memoryReference = memoryReference + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + result = self.result + variablesReference = self.variablesReference + type = self.type # noqa (assign to builtin) + presentationHint = self.presentationHint + namedVariables = self.namedVariables + indexedVariables = self.indexedVariables + memoryReference = self.memoryReference + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'result': result, + 'variablesReference': variablesReference, + } + if type is not None: + dct['type'] = type + if presentationHint is not None: + dct['presentationHint'] = presentationHint.to_dict(update_ids_to_dap=update_ids_to_dap) + if namedVariables is not None: + dct['namedVariables'] = namedVariables + if indexedVariables is not None: + dct['indexedVariables'] = indexedVariables + if memoryReference is not None: + dct['memoryReference'] = memoryReference + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register +class SetExpressionResponseBody(BaseSchema): + """ + "body" of SetExpressionResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "value": { + "type": "string", + "description": "The new value of the expression." + }, + "type": { + "type": "string", + "description": "The optional type of the value." + }, + "presentationHint": { + "description": "Properties of a value that can be used to determine how to render the result in the UI.", + "type": "VariablePresentationHint" + }, + "variablesReference": { + "type": "number", + "description": "If variablesReference is > 0, the value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest." + }, + "namedVariables": { + "type": "number", + "description": "The number of named child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + }, + "indexedVariables": { + "type": "number", + "description": "The number of indexed child variables.\nThe client can use this optional information to present the variables in a paged UI and fetch them in chunks." + } + } + __refs__ = set(['presentationHint']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, value, type=None, presentationHint=None, variablesReference=None, namedVariables=None, indexedVariables=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string value: The new value of the expression. + :param string type: The optional type of the value. + :param VariablePresentationHint presentationHint: Properties of a value that can be used to determine how to render the result in the UI. + :param number variablesReference: If variablesReference is > 0, the value is structured and its children can be retrieved by passing variablesReference to the VariablesRequest. + :param number namedVariables: The number of named child variables. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + :param number indexedVariables: The number of indexed child variables. + The client can use this optional information to present the variables in a paged UI and fetch them in chunks. + """ + self.value = value + self.type = type + if presentationHint is None: + self.presentationHint = VariablePresentationHint() + else: + self.presentationHint = VariablePresentationHint(update_ids_from_dap=update_ids_from_dap, **presentationHint) if presentationHint.__class__ != VariablePresentationHint else presentationHint + self.variablesReference = variablesReference + self.namedVariables = namedVariables + self.indexedVariables = indexedVariables + if update_ids_from_dap: + self.variablesReference = self._translate_id_from_dap(self.variablesReference) + self.kwargs = kwargs + + + @classmethod + def update_dict_ids_from_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_from_dap(dct['variablesReference']) + return dct + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + value = self.value + type = self.type # noqa (assign to builtin) + presentationHint = self.presentationHint + variablesReference = self.variablesReference + namedVariables = self.namedVariables + indexedVariables = self.indexedVariables + if update_ids_to_dap: + if variablesReference is not None: + variablesReference = self._translate_id_to_dap(variablesReference) + dct = { + 'value': value, + } + if type is not None: + dct['type'] = type + if presentationHint is not None: + dct['presentationHint'] = presentationHint.to_dict(update_ids_to_dap=update_ids_to_dap) + if variablesReference is not None: + dct['variablesReference'] = variablesReference + if namedVariables is not None: + dct['namedVariables'] = namedVariables + if indexedVariables is not None: + dct['indexedVariables'] = indexedVariables + dct.update(self.kwargs) + return dct + + @classmethod + def update_dict_ids_to_dap(cls, dct): + if 'variablesReference' in dct: + dct['variablesReference'] = cls._translate_id_to_dap(dct['variablesReference']) + return dct + + +@register +class StepInTargetsResponseBody(BaseSchema): + """ + "body" of StepInTargetsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/StepInTarget" + }, + "description": "The possible stepIn targets of the specified source location." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, targets, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array targets: The possible stepIn targets of the specified source location. + """ + self.targets = targets + if update_ids_from_dap and self.targets: + for o in self.targets: + StepInTarget.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + targets = self.targets + if targets and hasattr(targets[0], "to_dict"): + targets = [x.to_dict() for x in targets] + dct = { + 'targets': [StepInTarget.update_dict_ids_to_dap(o) for o in targets] if (update_ids_to_dap and targets) else targets, + } + dct.update(self.kwargs) + return dct + + +@register +class GotoTargetsResponseBody(BaseSchema): + """ + "body" of GotoTargetsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/GotoTarget" + }, + "description": "The possible goto targets of the specified location." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, targets, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array targets: The possible goto targets of the specified location. + """ + self.targets = targets + if update_ids_from_dap and self.targets: + for o in self.targets: + GotoTarget.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + targets = self.targets + if targets and hasattr(targets[0], "to_dict"): + targets = [x.to_dict() for x in targets] + dct = { + 'targets': [GotoTarget.update_dict_ids_to_dap(o) for o in targets] if (update_ids_to_dap and targets) else targets, + } + dct.update(self.kwargs) + return dct + + +@register +class CompletionsResponseBody(BaseSchema): + """ + "body" of CompletionsResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "targets": { + "type": "array", + "items": { + "$ref": "#/definitions/CompletionItem" + }, + "description": "The possible completions for ." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, targets, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array targets: The possible completions for . + """ + self.targets = targets + if update_ids_from_dap and self.targets: + for o in self.targets: + CompletionItem.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + targets = self.targets + if targets and hasattr(targets[0], "to_dict"): + targets = [x.to_dict() for x in targets] + dct = { + 'targets': [CompletionItem.update_dict_ids_to_dap(o) for o in targets] if (update_ids_to_dap and targets) else targets, + } + dct.update(self.kwargs) + return dct + + +@register +class ExceptionInfoResponseBody(BaseSchema): + """ + "body" of ExceptionInfoResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "exceptionId": { + "type": "string", + "description": "ID of the exception that was thrown." + }, + "description": { + "type": "string", + "description": "Descriptive text for the exception provided by the debug adapter." + }, + "breakMode": { + "description": "Mode that caused the exception notification to be raised.", + "type": "ExceptionBreakMode" + }, + "details": { + "description": "Detailed information about the exception.", + "type": "ExceptionDetails" + } + } + __refs__ = set(['breakMode', 'details']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, exceptionId, breakMode, description=None, details=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string exceptionId: ID of the exception that was thrown. + :param ExceptionBreakMode breakMode: Mode that caused the exception notification to be raised. + :param string description: Descriptive text for the exception provided by the debug adapter. + :param ExceptionDetails details: Detailed information about the exception. + """ + self.exceptionId = exceptionId + assert breakMode in ExceptionBreakMode.VALID_VALUES + self.breakMode = breakMode + self.description = description + if details is None: + self.details = ExceptionDetails() + else: + self.details = ExceptionDetails(update_ids_from_dap=update_ids_from_dap, **details) if details.__class__ != ExceptionDetails else details + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + exceptionId = self.exceptionId + breakMode = self.breakMode + description = self.description + details = self.details + dct = { + 'exceptionId': exceptionId, + 'breakMode': breakMode, + } + if description is not None: + dct['description'] = description + if details is not None: + dct['details'] = details.to_dict(update_ids_to_dap=update_ids_to_dap) + dct.update(self.kwargs) + return dct + + +@register +class ReadMemoryResponseBody(BaseSchema): + """ + "body" of ReadMemoryResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "address": { + "type": "string", + "description": "The address of the first byte of data returned. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise." + }, + "unreadableBytes": { + "type": "integer", + "description": "The number of unreadable bytes encountered after the last successfully read byte. This can be used to determine the number of bytes that must be skipped before a subsequent 'readMemory' request will succeed." + }, + "data": { + "type": "string", + "description": "The bytes read from memory, encoded using base64." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, address, unreadableBytes=None, data=None, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param string address: The address of the first byte of data returned. Treated as a hex value if prefixed with '0x', or as a decimal value otherwise. + :param integer unreadableBytes: The number of unreadable bytes encountered after the last successfully read byte. This can be used to determine the number of bytes that must be skipped before a subsequent 'readMemory' request will succeed. + :param string data: The bytes read from memory, encoded using base64. + """ + self.address = address + self.unreadableBytes = unreadableBytes + self.data = data + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + address = self.address + unreadableBytes = self.unreadableBytes + data = self.data + dct = { + 'address': address, + } + if unreadableBytes is not None: + dct['unreadableBytes'] = unreadableBytes + if data is not None: + dct['data'] = data + dct.update(self.kwargs) + return dct + + +@register +class DisassembleResponseBody(BaseSchema): + """ + "body" of DisassembleResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "instructions": { + "type": "array", + "items": { + "$ref": "#/definitions/DisassembledInstruction" + }, + "description": "The list of disassembled instructions." + } + } + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, instructions, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param array instructions: The list of disassembled instructions. + """ + self.instructions = instructions + if update_ids_from_dap and self.instructions: + for o in self.instructions: + DisassembledInstruction.update_dict_ids_from_dap(o) + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + instructions = self.instructions + if instructions and hasattr(instructions[0], "to_dict"): + instructions = [x.to_dict() for x in instructions] + dct = { + 'instructions': [DisassembledInstruction.update_dict_ids_to_dap(o) for o in instructions] if (update_ids_to_dap and instructions) else instructions, + } + dct.update(self.kwargs) + return dct + + +@register +class MessageVariables(BaseSchema): + """ + "variables" of Message + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = {} + __refs__ = set() + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + + """ + + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + dct = { + } + dct.update(self.kwargs) + return dct + + +@register +class PydevdSystemInfoResponseBody(BaseSchema): + """ + "body" of PydevdSystemInfoResponse + + Note: automatically generated code. Do not edit manually. + """ + + __props__ = { + "python": { + "description": "Information about the python version running in the current process.", + "type": "PydevdPythonInfo" + }, + "platform": { + "description": "Information about the plarforn on which the current process is running.", + "type": "PydevdPlatformInfo" + }, + "process": { + "description": "Information about the current process.", + "type": "PydevdProcessInfo" + } + } + __refs__ = set(['python', 'platform', 'process']) + + __slots__ = list(__props__.keys()) + ['kwargs'] + + def __init__(self, python, platform, process, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused) + """ + :param PydevdPythonInfo python: Information about the python version running in the current process. + :param PydevdPlatformInfo platform: Information about the plarforn on which the current process is running. + :param PydevdProcessInfo process: Information about the current process. + """ + if python is None: + self.python = PydevdPythonInfo() + else: + self.python = PydevdPythonInfo(update_ids_from_dap=update_ids_from_dap, **python) if python.__class__ != PydevdPythonInfo else python + if platform is None: + self.platform = PydevdPlatformInfo() + else: + self.platform = PydevdPlatformInfo(update_ids_from_dap=update_ids_from_dap, **platform) if platform.__class__ != PydevdPlatformInfo else platform + if process is None: + self.process = PydevdProcessInfo() + else: + self.process = PydevdProcessInfo(update_ids_from_dap=update_ids_from_dap, **process) if process.__class__ != PydevdProcessInfo else process + self.kwargs = kwargs + + + def to_dict(self, update_ids_to_dap=False): # noqa (update_ids_to_dap may be unused) + python = self.python + platform = self.platform + process = self.process + dct = { + 'python': python.to_dict(update_ids_to_dap=update_ids_to_dap), + 'platform': platform.to_dict(update_ids_to_dap=update_ids_to_dap), + 'process': process.to_dict(update_ids_to_dap=update_ids_to_dap), + } + dct.update(self.kwargs) + return dct diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema_log.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema_log.py new file mode 100644 index 0000000..8f1e886 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema_log.py @@ -0,0 +1,46 @@ +import os +import threading +import traceback + +_pid = os.getpid() +_pid_msg = '%s: ' % (_pid,) + +_debug_lock = threading.Lock() + +DEBUG = False +DEBUG_FILE = os.path.join(os.path.dirname(__file__), '__debug_output__.txt') + + +def debug(msg): + if DEBUG: + with _debug_lock: + _pid_prefix = _pid_msg + if isinstance(msg, bytes): + _pid_prefix = _pid_prefix.encode('utf-8') + + if not msg.endswith(b'\r') and not msg.endswith(b'\n'): + msg += b'\n' + mode = 'a+b' + else: + if not msg.endswith('\r') and not msg.endswith('\n'): + msg += '\n' + mode = 'a+' + with open(DEBUG_FILE, mode) as stream: + stream.write(_pid_prefix) + stream.write(msg) + + +def debug_exception(msg=None): + if DEBUG: + if msg: + debug(msg) + + with _debug_lock: + + with open(DEBUG_FILE, 'a+') as stream: + _pid_prefix = _pid_msg + if isinstance(msg, bytes): + _pid_prefix = _pid_prefix.encode('utf-8') + stream.write(_pid_prefix) + + traceback.print_exc(file=stream) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevconsole_code_for_ironpython.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevconsole_code_for_ironpython.py new file mode 100644 index 0000000..0b24780 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevconsole_code_for_ironpython.py @@ -0,0 +1,513 @@ +"""Utilities needed to emulate Python's interactive interpreter. + +""" + +# Inspired by similar code by Jeff Epler and Fredrik Lundh. + + +import sys +import traceback + + + + + + + + +#START --------------------------- from codeop import CommandCompiler, compile_command +#START --------------------------- from codeop import CommandCompiler, compile_command +#START --------------------------- from codeop import CommandCompiler, compile_command +#START --------------------------- from codeop import CommandCompiler, compile_command +#START --------------------------- from codeop import CommandCompiler, compile_command +r"""Utilities to compile possibly incomplete Python source code. + +This module provides two interfaces, broadly similar to the builtin +function compile(), which take program text, a filename and a 'mode' +and: + +- Return code object if the command is complete and valid +- Return None if the command is incomplete +- Raise SyntaxError, ValueError or OverflowError if the command is a + syntax error (OverflowError and ValueError can be produced by + malformed literals). + +Approach: + +First, check if the source consists entirely of blank lines and +comments; if so, replace it with 'pass', because the built-in +parser doesn't always do the right thing for these. + +Compile three times: as is, with \n, and with \n\n appended. If it +compiles as is, it's complete. If it compiles with one \n appended, +we expect more. If it doesn't compile either way, we compare the +error we get when compiling with \n or \n\n appended. If the errors +are the same, the code is broken. But if the errors are different, we +expect more. Not intuitive; not even guaranteed to hold in future +releases; but this matches the compiler's behavior from Python 1.4 +through 2.2, at least. + +Caveat: + +It is possible (but not likely) that the parser stops parsing with a +successful outcome before reaching the end of the source; in this +case, trailing symbols may be ignored instead of causing an error. +For example, a backslash followed by two newlines may be followed by +arbitrary garbage. This will be fixed once the API for the parser is +better. + +The two interfaces are: + +compile_command(source, filename, symbol): + + Compiles a single command in the manner described above. + +CommandCompiler(): + + Instances of this class have __call__ methods identical in + signature to compile_command; the difference is that if the + instance compiles program text containing a __future__ statement, + the instance 'remembers' and compiles all subsequent program texts + with the statement in force. + +The module also provides another class: + +Compile(): + + Instances of this class act like the built-in function compile, + but with 'memory' in the sense described above. +""" + +import __future__ + +_features = [getattr(__future__, fname) + for fname in __future__.all_feature_names] + +__all__ = ["compile_command", "Compile", "CommandCompiler"] + +PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h + +def _maybe_compile(compiler, source, filename, symbol): + # Check for source consisting of only blank lines and comments + for line in source.split("\n"): + line = line.strip() + if line and line[0] != '#': + break # Leave it alone + else: + if symbol != "eval": + source = "pass" # Replace it with a 'pass' statement + + err = err1 = err2 = None + code = code1 = code2 = None + + try: + code = compiler(source, filename, symbol) + except SyntaxError, err: + pass + + try: + code1 = compiler(source + "\n", filename, symbol) + except SyntaxError, err1: + pass + + try: + code2 = compiler(source + "\n\n", filename, symbol) + except SyntaxError, err2: + pass + + if code: + return code + if not code1 and repr(err1) == repr(err2): + raise SyntaxError, err1 + +def _compile(source, filename, symbol): + return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT) + +def compile_command(source, filename="", symbol="single"): + r"""Compile a command and determine whether it is incomplete. + + Arguments: + + source -- the source string; may contain \n characters + filename -- optional filename from which source was read; default + "" + symbol -- optional grammar start symbol; "single" (default) or "eval" + + Return value / exceptions raised: + + - Return a code object if the command is complete and valid + - Return None if the command is incomplete + - Raise SyntaxError, ValueError or OverflowError if the command is a + syntax error (OverflowError and ValueError can be produced by + malformed literals). + """ + return _maybe_compile(_compile, source, filename, symbol) + +class Compile: + """Instances of this class behave much like the built-in compile + function, but if one is used to compile text containing a future + statement, it "remembers" and compiles all subsequent program texts + with the statement in force.""" + def __init__(self): + self.flags = PyCF_DONT_IMPLY_DEDENT + + def __call__(self, source, filename, symbol): + codeob = compile(source, filename, symbol, self.flags, 1) + for feature in _features: + if codeob.co_flags & feature.compiler_flag: + self.flags |= feature.compiler_flag + return codeob + +class CommandCompiler: + """Instances of this class have __call__ methods identical in + signature to compile_command; the difference is that if the + instance compiles program text containing a __future__ statement, + the instance 'remembers' and compiles all subsequent program texts + with the statement in force.""" + + def __init__(self,): + self.compiler = Compile() + + def __call__(self, source, filename="", symbol="single"): + r"""Compile a command and determine whether it is incomplete. + + Arguments: + + source -- the source string; may contain \n characters + filename -- optional filename from which source was read; + default "" + symbol -- optional grammar start symbol; "single" (default) or + "eval" + + Return value / exceptions raised: + + - Return a code object if the command is complete and valid + - Return None if the command is incomplete + - Raise SyntaxError, ValueError or OverflowError if the command is a + syntax error (OverflowError and ValueError can be produced by + malformed literals). + """ + return _maybe_compile(self.compiler, source, filename, symbol) + +#END --------------------------- from codeop import CommandCompiler, compile_command +#END --------------------------- from codeop import CommandCompiler, compile_command +#END --------------------------- from codeop import CommandCompiler, compile_command +#END --------------------------- from codeop import CommandCompiler, compile_command +#END --------------------------- from codeop import CommandCompiler, compile_command + + + + + + + + + + + + + + + + + +__all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact", + "compile_command"] + +def softspace(file, newvalue): + oldvalue = 0 + try: + oldvalue = file.softspace + except AttributeError: + pass + try: + file.softspace = newvalue + except (AttributeError, TypeError): + # "attribute-less object" or "read-only attributes" + pass + return oldvalue + +class InteractiveInterpreter: + """Base class for InteractiveConsole. + + This class deals with parsing and interpreter state (the user's + namespace); it doesn't deal with input buffering or prompting or + input file naming (the filename is always passed in explicitly). + + """ + + def __init__(self, locals=None): + """Constructor. + + The optional 'locals' argument specifies the dictionary in + which code will be executed; it defaults to a newly created + dictionary with key "__name__" set to "__console__" and key + "__doc__" set to None. + + """ + if locals is None: + locals = {"__name__": "__console__", "__doc__": None} + self.locals = locals + self.compile = CommandCompiler() + + def runsource(self, source, filename="", symbol="single"): + """Compile and run some source in the interpreter. + + Arguments are as for compile_command(). + + One several things can happen: + + 1) The input is incorrect; compile_command() raised an + exception (SyntaxError or OverflowError). A syntax traceback + will be printed by calling the showsyntaxerror() method. + + 2) The input is incomplete, and more input is required; + compile_command() returned None. Nothing happens. + + 3) The input is complete; compile_command() returned a code + object. The code is executed by calling self.runcode() (which + also handles run-time exceptions, except for SystemExit). + + The return value is True in case 2, False in the other cases (unless + an exception is raised). The return value can be used to + decide whether to use sys.ps1 or sys.ps2 to prompt the next + line. + + """ + try: + code = self.compile(source, filename, symbol) + except (OverflowError, SyntaxError, ValueError): + # Case 1 + self.showsyntaxerror(filename) + return False + + if code is None: + # Case 2 + return True + + # Case 3 + self.runcode(code) + return False + + def runcode(self, code): + """Execute a code object. + + When an exception occurs, self.showtraceback() is called to + display a traceback. All exceptions are caught except + SystemExit, which is reraised. + + A note about KeyboardInterrupt: this exception may occur + elsewhere in this code, and may not always be caught. The + caller should be prepared to deal with it. + + """ + try: + exec code in self.locals + except SystemExit: + raise + except: + self.showtraceback() + else: + if softspace(sys.stdout, 0): + sys.stdout.write('\n') + + def showsyntaxerror(self, filename=None): + """Display the syntax error that just occurred. + + This doesn't display a stack trace because there isn't one. + + If a filename is given, it is stuffed in the exception instead + of what was there before (because Python's parser always uses + "" when reading from a string). + + The output is written by self.write(), below. + + """ + type, value, sys.last_traceback = sys.exc_info() + sys.last_type = type + sys.last_value = value + if filename and type is SyntaxError: + # Work hard to stuff the correct filename in the exception + try: + msg, (dummy_filename, lineno, offset, line) = value + except: + # Not the format we expect; leave it alone + pass + else: + # Stuff in the right filename + value = SyntaxError(msg, (filename, lineno, offset, line)) + sys.last_value = value + list = traceback.format_exception_only(type, value) + map(self.write, list) + + def showtraceback(self, *args, **kwargs): + """Display the exception that just occurred. + + We remove the first stack item because it is our own code. + + The output is written by self.write(), below. + + """ + try: + type, value, tb = sys.exc_info() + sys.last_type = type + sys.last_value = value + sys.last_traceback = tb + tblist = traceback.extract_tb(tb) + del tblist[:1] + list = traceback.format_list(tblist) + if list: + list.insert(0, "Traceback (most recent call last):\n") + list[len(list):] = traceback.format_exception_only(type, value) + finally: + tblist = tb = None + map(self.write, list) + + def write(self, data): + """Write a string. + + The base implementation writes to sys.stderr; a subclass may + replace this with a different implementation. + + """ + sys.stderr.write(data) + + +class InteractiveConsole(InteractiveInterpreter): + """Closely emulate the behavior of the interactive Python interpreter. + + This class builds on InteractiveInterpreter and adds prompting + using the familiar sys.ps1 and sys.ps2, and input buffering. + + """ + + def __init__(self, locals=None, filename=""): + """Constructor. + + The optional locals argument will be passed to the + InteractiveInterpreter base class. + + The optional filename argument should specify the (file)name + of the input stream; it will show up in tracebacks. + + """ + InteractiveInterpreter.__init__(self, locals) + self.filename = filename + self.resetbuffer() + + def resetbuffer(self): + """Reset the input buffer.""" + self.buffer = [] + + def interact(self, banner=None): + """Closely emulate the interactive Python console. + + The optional banner argument specify the banner to print + before the first interaction; by default it prints a banner + similar to the one printed by the real Python interpreter, + followed by the current class name in parentheses (so as not + to confuse this with the real interpreter -- since it's so + close!). + + """ + try: + sys.ps1 #@UndefinedVariable + except AttributeError: + sys.ps1 = ">>> " + try: + sys.ps2 #@UndefinedVariable + except AttributeError: + sys.ps2 = "... " + cprt = 'Type "help", "copyright", "credits" or "license" for more information.' + if banner is None: + self.write("Python %s on %s\n%s\n(%s)\n" % + (sys.version, sys.platform, cprt, + self.__class__.__name__)) + else: + self.write("%s\n" % str(banner)) + more = 0 + while 1: + try: + if more: + prompt = sys.ps2 #@UndefinedVariable + else: + prompt = sys.ps1 #@UndefinedVariable + try: + line = self.raw_input(prompt) + # Can be None if sys.stdin was redefined + encoding = getattr(sys.stdin, "encoding", None) + if encoding and not isinstance(line, unicode): + line = line.decode(encoding) + except EOFError: + self.write("\n") + break + else: + more = self.push(line) + except KeyboardInterrupt: + self.write("\nKeyboardInterrupt\n") + self.resetbuffer() + more = 0 + + def push(self, line): + """Push a line to the interpreter. + + The line should not have a trailing newline; it may have + internal newlines. The line is appended to a buffer and the + interpreter's runsource() method is called with the + concatenated contents of the buffer as source. If this + indicates that the command was executed or invalid, the buffer + is reset; otherwise, the command is incomplete, and the buffer + is left as it was after the line was appended. The return + value is 1 if more input is required, 0 if the line was dealt + with in some way (this is the same as runsource()). + + """ + self.buffer.append(line) + source = "\n".join(self.buffer) + more = self.runsource(source, self.filename) + if not more: + self.resetbuffer() + return more + + def raw_input(self, prompt=""): + """Write a prompt and read a line. + + The returned line does not include the trailing newline. + When the user enters the EOF key sequence, EOFError is raised. + + The base implementation uses the built-in function + raw_input(); a subclass may replace this with a different + implementation. + + """ + return raw_input(prompt) + + +def interact(banner=None, readfunc=None, local=None): + """Closely emulate the interactive Python interpreter. + + This is a backwards compatible interface to the InteractiveConsole + class. When readfunc is not specified, it attempts to import the + readline module to enable GNU readline if it is available. + + Arguments (all optional, all default to None): + + banner -- passed to InteractiveConsole.interact() + readfunc -- if not None, replaces InteractiveConsole.raw_input() + local -- passed to InteractiveInterpreter.__init__() + + """ + console = InteractiveConsole(local) + if readfunc is not None: + console.raw_input = readfunc + else: + try: + import readline + except ImportError: + pass + console.interact(banner) + + +if __name__ == '__main__': + import pdb + pdb.run("interact()\n") diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info.py new file mode 100644 index 0000000..5e0d7dd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info.py @@ -0,0 +1,23 @@ +# Defines which version of the PyDBAdditionalThreadInfo we'll use. + +import os +use_cython = os.getenv('PYDEVD_USE_CYTHON', None) + +if use_cython == 'YES': + # We must import the cython version if forcing cython + from _pydevd_bundle.pydevd_cython_wrapper import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock # @UnusedImport + +elif use_cython == 'NO': + # Use the regular version if not forcing cython + from _pydevd_bundle.pydevd_additional_thread_info_regular import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock # @UnusedImport @Reimport + +elif use_cython is None: + # Regular: use fallback if not found (message is already given elsewhere). + try: + from _pydevd_bundle.pydevd_cython_wrapper import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock + except ImportError: + from _pydevd_bundle.pydevd_additional_thread_info_regular import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock # @UnusedImport +else: + raise RuntimeError('Unexpected value for PYDEVD_USE_CYTHON: %s (accepted: YES, NO)' % (use_cython,)) + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info_regular.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info_regular.py new file mode 100644 index 0000000..8837381 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info_regular.py @@ -0,0 +1,156 @@ +import sys +from _pydevd_bundle.pydevd_constants import (STATE_RUN, PYTHON_SUSPEND, IS_JYTHON, + USE_CUSTOM_SYS_CURRENT_FRAMES, USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) +from _pydev_bundle import pydev_log +# IFDEF CYTHON +# pydev_log.debug("Using Cython speedups") +# ELSE +from _pydevd_bundle.pydevd_frame import PyDBFrame +# ENDIF + +version = 11 + +if USE_CUSTOM_SYS_CURRENT_FRAMES: + + # Some versions of Jython don't have it (but we can provide a replacement) + if IS_JYTHON: + from java.lang import NoSuchFieldException + from org.python.core import ThreadStateMapping + try: + cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + except NoSuchFieldException: + cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + cachedThreadState.accessible = True + thread_states = cachedThreadState.get(ThreadStateMapping) + + def _current_frames(): + as_array = thread_states.entrySet().toArray() + ret = {} + for thread_to_state in as_array: + thread = thread_to_state.getKey() + if thread is None: + continue + thread_state = thread_to_state.getValue() + if thread_state is None: + continue + + frame = thread_state.frame + if frame is None: + continue + + ret[thread.getId()] = frame + return ret + + elif USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + _tid_to_last_frame = {} + + # IronPython doesn't have it. Let's use our workaround... + def _current_frames(): + return _tid_to_last_frame + + else: + raise RuntimeError('Unable to proceed (sys._current_frames not available in this Python implementation).') +else: + _current_frames = sys._current_frames + + +#======================================================================================================================= +# PyDBAdditionalThreadInfo +#======================================================================================================================= +# IFDEF CYTHON +# cdef class PyDBAdditionalThreadInfo: +# ELSE +class PyDBAdditionalThreadInfo(object): +# ENDIF + + # Note: the params in cython are declared in pydevd_cython.pxd. + # IFDEF CYTHON + # ELSE + __slots__ = [ + 'pydev_state', + 'pydev_step_stop', + 'pydev_original_step_cmd', + 'pydev_step_cmd', + 'pydev_notify_kill', + 'pydev_smart_step_stop', + 'pydev_django_resolve_frame', + 'pydev_call_from_jinja2', + 'pydev_call_inside_jinja2', + 'is_tracing', + 'conditional_breakpoint_exception', + 'pydev_message', + 'suspend_type', + 'pydev_next_line', + 'pydev_func_name', + 'suspended_at_unhandled', + 'trace_suspend_type', + 'top_level_thread_tracer_no_back_frames', + 'top_level_thread_tracer_unhandled', + 'thread_tracer', + ] + # ENDIF + + def __init__(self): + self.pydev_state = STATE_RUN # STATE_RUN or STATE_SUSPEND + self.pydev_step_stop = None + + # Note: we have `pydev_original_step_cmd` and `pydev_step_cmd` because the original is to + # say the action that started it and the other is to say what's the current tracing behavior + # (because it's possible that we start with a step over but may have to switch to a + # different step strategy -- for instance, if a step over is done and we return the current + # method the strategy is changed to a step in). + + self.pydev_original_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + self.pydev_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + + self.pydev_notify_kill = False + self.pydev_smart_step_stop = None + self.pydev_django_resolve_frame = False + self.pydev_call_from_jinja2 = None + self.pydev_call_inside_jinja2 = None + self.is_tracing = False + self.conditional_breakpoint_exception = None + self.pydev_message = '' + self.suspend_type = PYTHON_SUSPEND + self.pydev_next_line = -1 + self.pydev_func_name = '.invalid.' # Must match the type in cython + self.suspended_at_unhandled = False + self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' + self.top_level_thread_tracer_no_back_frames = [] + self.top_level_thread_tracer_unhandled = None + self.thread_tracer = None + + def get_topmost_frame(self, thread): + ''' + Gets the topmost frame for the given thread. Note that it may be None + and callers should remove the reference to the frame as soon as possible + to avoid disturbing user code. + ''' + # sys._current_frames(): dictionary with thread id -> topmost frame + current_frames = _current_frames() + return current_frames.get(thread.ident) + + def __str__(self): + return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( + self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) + + +from _pydev_imps._pydev_saved_modules import threading +_set_additional_thread_info_lock = threading.Lock() + + +def set_additional_thread_info(thread): + try: + additional_info = thread.additional_info + if additional_info is None: + raise AttributeError() + except: + with _set_additional_thread_info_lock: + # If it's not there, set it within a lock to avoid any racing + # conditions. + additional_info = getattr(thread, 'additional_info', None) + if additional_info is None: + additional_info = PyDBAdditionalThreadInfo() + thread.additional_info = additional_info + + return additional_info diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py new file mode 100644 index 0000000..f51b125 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py @@ -0,0 +1,801 @@ +import sys +import bisect +import types + +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle import pydevd_utils, pydevd_source_mapping +from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info +from _pydevd_bundle.pydevd_comm import (InternalGetThreadStack, internal_get_completions, + pydevd_find_thread_by_id, InternalSetNextStatementThread, internal_reload_code, + InternalGetVariable, InternalGetArray, InternalLoadFullValue, + internal_get_description, internal_get_frame, internal_evaluate_expression, InternalConsoleExec, + internal_get_variable_json, internal_change_variable, internal_change_variable_json, + internal_evaluate_expression_json, internal_set_expression_json, internal_get_exception_details_json, + internal_step_in_thread, internal_run_thread) +from _pydevd_bundle.pydevd_comm_constants import (CMD_THREAD_SUSPEND, file_system_encoding, + CMD_STEP_INTO_MY_CODE, CMD_STOP_ON_START) +from _pydevd_bundle.pydevd_constants import (get_current_thread_id, set_protocol, get_protocol, + HTTP_JSON_PROTOCOL, JSON_PROTOCOL, IS_PY3K, DebugInfoHolder, dict_keys, dict_items) +from _pydevd_bundle.pydevd_net_command_factory_json import NetCommandFactoryJson +from _pydevd_bundle.pydevd_net_command_factory_xml import NetCommandFactory +import pydevd_file_utils +from _pydev_bundle import pydev_log +from _pydevd_bundle.pydevd_breakpoints import LineBreakpoint +from pydevd_tracing import get_exception_traceback_str + +try: + import dis +except ImportError: + + def _get_code_lines(code): + raise NotImplementedError + +else: + + def _get_code_lines(code): + if not isinstance(code, types.CodeType): + path = code + with open(path) as f: + src = f.read() + code = compile(src, path, 'exec', 0, dont_inherit=True) + return _get_code_lines(code) + + def iterate(): + # First, get all line starts for this code object. This does not include + # bodies of nested class and function definitions, as they have their + # own objects. + for _, lineno in dis.findlinestarts(code): + yield lineno + + # For nested class and function definitions, their respective code objects + # are constants referenced by this object. + for const in code.co_consts: + if isinstance(const, types.CodeType) and const.co_filename == code.co_filename: + for lineno in _get_code_lines(const): + yield lineno + + return iterate() + + +class PyDevdAPI(object): + + def run(self, py_db): + py_db.ready_to_run = True + + def notify_configuration_done(self, py_db): + py_db.on_configuration_done() + + def notify_disconnect(self, py_db): + py_db.on_disconnect() + + def set_protocol(self, py_db, seq, protocol): + set_protocol(protocol.strip()) + if get_protocol() in (HTTP_JSON_PROTOCOL, JSON_PROTOCOL): + cmd_factory_class = NetCommandFactoryJson + else: + cmd_factory_class = NetCommandFactory + + if not isinstance(py_db.cmd_factory, cmd_factory_class): + py_db.cmd_factory = cmd_factory_class() + + return py_db.cmd_factory.make_protocol_set_message(seq) + + def set_ide_os_and_breakpoints_by(self, py_db, seq, ide_os, breakpoints_by): + ''' + :param ide_os: 'WINDOWS' or 'UNIX' + :param breakpoints_by: 'ID' or 'LINE' + ''' + if breakpoints_by == 'ID': + py_db._set_breakpoints_with_id = True + else: + py_db._set_breakpoints_with_id = False + + self.set_ide_os(ide_os) + + return py_db.cmd_factory.make_version_message(seq) + + def set_ide_os(self, ide_os): + ''' + :param ide_os: 'WINDOWS' or 'UNIX' + ''' + pydevd_file_utils.set_ide_os(ide_os) + + def send_error_message(self, py_db, msg): + sys.stderr.write('pydevd: %s\n' % (msg,)) + + def set_show_return_values(self, py_db, show_return_values): + if show_return_values: + py_db.show_return_values = True + else: + if py_db.show_return_values: + # We should remove saved return values + py_db.remove_return_values_flag = True + py_db.show_return_values = False + pydev_log.debug("Show return values: %s", py_db.show_return_values) + + def list_threads(self, py_db, seq): + # Response is the command with the list of threads to be added to the writer thread. + return py_db.cmd_factory.make_list_threads_message(py_db, seq) + + def request_suspend_thread(self, py_db, thread_id='*'): + # Yes, thread suspend is done at this point, not through an internal command. + threads = [] + suspend_all = thread_id.strip() == '*' + if suspend_all: + threads = pydevd_utils.get_non_pydevd_threads() + + elif thread_id.startswith('__frame__:'): + sys.stderr.write("Can't suspend tasklet: %s\n" % (thread_id,)) + + else: + threads = [pydevd_find_thread_by_id(thread_id)] + + for t in threads: + if t is None: + continue + py_db.set_suspend( + t, + CMD_THREAD_SUSPEND, + suspend_other_threads=suspend_all, + is_pause=True, + ) + # Break here (even if it's suspend all) as py_db.set_suspend will + # take care of suspending other threads. + break + + def set_enable_thread_notifications(self, py_db, enable): + ''' + When disabled, no thread notifications (for creation/removal) will be + issued until it's re-enabled. + + Note that when it's re-enabled, a creation notification will be sent for + all existing threads even if it was previously sent (this is meant to + be used on disconnect/reconnect). + ''' + py_db.set_enable_thread_notifications(enable) + + def request_disconnect(self, py_db, resume_threads): + self.set_enable_thread_notifications(py_db, False) + self.remove_all_breakpoints(py_db, filename='*') + self.remove_all_exception_breakpoints(py_db) + self.notify_disconnect(py_db) + if resume_threads: + self.request_resume_thread(thread_id='*') + + def request_resume_thread(self, thread_id): + threads = [] + if thread_id == '*': + threads = pydevd_utils.get_non_pydevd_threads() + + elif thread_id.startswith('__frame__:'): + sys.stderr.write("Can't make tasklet run: %s\n" % (thread_id,)) + + else: + threads = [pydevd_find_thread_by_id(thread_id)] + + for t in threads: + if t is None: + continue + + internal_run_thread(t, set_additional_thread_info=set_additional_thread_info) + + def request_completions(self, py_db, seq, thread_id, frame_id, act_tok, line=-1, column=-1): + py_db.post_method_as_internal_command( + thread_id, internal_get_completions, seq, thread_id, frame_id, act_tok, line=line, column=column) + + def request_stack(self, py_db, seq, thread_id, fmt=None, timeout=.5, start_frame=0, levels=0): + # If it's already suspended, get it right away. + internal_get_thread_stack = InternalGetThreadStack( + seq, thread_id, py_db, set_additional_thread_info, fmt=fmt, timeout=timeout, start_frame=start_frame, levels=levels) + if internal_get_thread_stack.can_be_executed_by(get_current_thread_id(threading.current_thread())): + internal_get_thread_stack.do_it(py_db) + else: + py_db.post_internal_command(internal_get_thread_stack, '*') + + def request_exception_info_json(self, py_db, request, thread_id, max_frames): + py_db.post_method_as_internal_command( + thread_id, + internal_get_exception_details_json, + request, + thread_id, + max_frames, + set_additional_thread_info=set_additional_thread_info, + iter_visible_frames_info=py_db.cmd_factory._iter_visible_frames_info, + ) + + def request_step(self, py_db, thread_id, step_cmd_id): + t = pydevd_find_thread_by_id(thread_id) + if t: + py_db.post_method_as_internal_command( + thread_id, + internal_step_in_thread, + thread_id, + step_cmd_id, + set_additional_thread_info=set_additional_thread_info, + ) + elif thread_id.startswith('__frame__:'): + sys.stderr.write("Can't make tasklet step command: %s\n" % (thread_id,)) + + def request_set_next(self, py_db, seq, thread_id, set_next_cmd_id, line, func_name): + t = pydevd_find_thread_by_id(thread_id) + if t: + int_cmd = InternalSetNextStatementThread(thread_id, set_next_cmd_id, line, func_name, seq=seq) + py_db.post_internal_command(int_cmd, thread_id) + elif thread_id.startswith('__frame__:'): + sys.stderr.write("Can't set next statement in tasklet: %s\n" % (thread_id,)) + + def request_reload_code(self, py_db, seq, module_name): + thread_id = '*' # Any thread + # Note: not going for the main thread because in this case it'd only do the load + # when we stopped on a breakpoint. + py_db.post_method_as_internal_command( + thread_id, internal_reload_code, seq, module_name) + + def request_change_variable(self, py_db, seq, thread_id, frame_id, scope, attr, value): + ''' + :param scope: 'FRAME' or 'GLOBAL' + ''' + py_db.post_method_as_internal_command( + thread_id, internal_change_variable, seq, thread_id, frame_id, scope, attr, value) + + def request_get_variable(self, py_db, seq, thread_id, frame_id, scope, attrs): + ''' + :param scope: 'FRAME' or 'GLOBAL' + ''' + int_cmd = InternalGetVariable(seq, thread_id, frame_id, scope, attrs) + py_db.post_internal_command(int_cmd, thread_id) + + def request_get_array(self, py_db, seq, roffset, coffset, rows, cols, fmt, thread_id, frame_id, scope, attrs): + int_cmd = InternalGetArray(seq, roffset, coffset, rows, cols, fmt, thread_id, frame_id, scope, attrs) + py_db.post_internal_command(int_cmd, thread_id) + + def request_load_full_value(self, py_db, seq, thread_id, frame_id, vars): + int_cmd = InternalLoadFullValue(seq, thread_id, frame_id, vars) + py_db.post_internal_command(int_cmd, thread_id) + + def request_get_description(self, py_db, seq, thread_id, frame_id, expression): + py_db.post_method_as_internal_command( + thread_id, internal_get_description, seq, thread_id, frame_id, expression) + + def request_get_frame(self, py_db, seq, thread_id, frame_id): + py_db.post_method_as_internal_command( + thread_id, internal_get_frame, seq, thread_id, frame_id) + + def to_str(self, s): + ''' + In py2 converts a unicode to str (bytes) using utf-8. + -- in py3 raises an error if it's not str already. + ''' + if s.__class__ != str: + if not IS_PY3K: + s = s.encode('utf-8') + else: + raise AssertionError('Expected to have str on Python 3. Found: %s (%s)' % (s, s.__class__)) + return s + + def filename_to_str(self, filename): + ''' + In py2 converts a unicode to str (bytes) using the file system encoding. + -- in py3 raises an error if it's not str already. + ''' + if filename.__class__ != str: + if not IS_PY3K: + filename = filename.encode(file_system_encoding) + else: + raise AssertionError('Expected to have str on Python 3. Found: %s (%s)' % (filename, filename.__class__)) + return filename + + def filename_to_server(self, filename): + filename = self.filename_to_str(filename) + return pydevd_file_utils.norm_file_to_server(filename) + + class _DummyFrame(object): + ''' + Dummy frame to be used with PyDB.apply_files_filter (as we don't really have the + related frame as breakpoints are added before execution). + ''' + + class _DummyCode(object): + + def __init__(self, filename): + self.co_firstlineno = 1 + self.co_filename = filename + self.co_name = 'invalid func name ' + + def __init__(self, filename): + self.f_code = self._DummyCode(filename) + self.f_globals = {} + + ADD_BREAKPOINT_NO_ERROR = 0 + ADD_BREAKPOINT_FILE_NOT_FOUND = 1 + ADD_BREAKPOINT_FILE_EXCLUDED_BY_FILTERS = 2 + + class _AddBreakpointResult(object): + + # :see: ADD_BREAKPOINT_NO_ERROR = 0 + # :see: ADD_BREAKPOINT_FILE_NOT_FOUND = 1 + # :see: ADD_BREAKPOINT_FILE_EXCLUDED_BY_FILTERS = 2 + + __slots__ = ['error_code', 'translated_filename', 'translated_line'] + + def __init__(self, translated_filename, translated_line): + self.error_code = PyDevdAPI.ADD_BREAKPOINT_NO_ERROR + self.translated_filename = translated_filename + self.translated_line = translated_line + + def add_breakpoint( + self, py_db, filename, breakpoint_type, breakpoint_id, line, condition, func_name, + expression, suspend_policy, hit_condition, is_logpoint, adjust_line=False): + ''' + :param str filename: + Note: must be sent as it was received in the protocol. It may be translated in this + function and its final value will be available in the returned _AddBreakpointResult. + + :param str breakpoint_type: + One of: 'python-line', 'django-line', 'jinja2-line'. + + :param int breakpoint_id: + + :param int line: + Note: it's possible that a new line was actually used. If that's the case its + final value will be available in the returned _AddBreakpointResult. + + :param condition: + Either None or the condition to activate the breakpoint. + + :param str func_name: + If "None" (str), may hit in any context. + Empty string will hit only top level. + Any other value must match the scope of the method to be matched. + + :param str expression: + None or the expression to be evaluated. + + :param suspend_policy: + Either "NONE" (to suspend only the current thread when the breakpoint is hit) or + "ALL" (to suspend all threads when a breakpoint is hit). + + :param str hit_condition: + An expression where `@HIT@` will be replaced by the number of hits. + i.e.: `@HIT@ == x` or `@HIT@ >= x` + + :param bool is_logpoint: + If True and an expression is passed, pydevd will create an io message command with the + result of the evaluation. + + :return _AddBreakpointResult: + ''' + assert filename.__class__ == str, 'Expected str, found: %s' % (filename.__class__,) # i.e.: bytes on py2 and str on py3 + + original_filename = filename + pydev_log.debug('Request for breakpoint in: %s line: %s', original_filename, line) + # Parameters to reapply breakpoint. + api_add_breakpoint_params = (filename, breakpoint_type, breakpoint_id, line, condition, func_name, + expression, suspend_policy, hit_condition, is_logpoint) + + filename = self.filename_to_server(filename) # Apply user path mapping. + func_name = self.to_str(func_name) + + assert filename.__class__ == str # i.e.: bytes on py2 and str on py3 + assert func_name.__class__ == str # i.e.: bytes on py2 and str on py3 + + # Apply source mapping (i.e.: ipython). + new_filename, new_line, multi_mapping_applied = py_db.source_mapping.map_to_server(filename, line) + + py_db.api_received_breakpoints[(original_filename, breakpoint_id)] = (new_filename, api_add_breakpoint_params) + + pydev_log.debug('Breakpoint (after path/source mapping) in: %s line: %s', new_filename, new_line) + + if multi_mapping_applied: + # Note that source mapping is internal and does not change the resulting filename nor line + # (we want the outside world to see the line in the original file and not in the ipython + # cell, otherwise the editor wouldn't be correct as the returned line is the line to + # which the breakpoint will be moved in the editor). + result = self._AddBreakpointResult(filename, line) + filename = new_filename + line = new_line + + else: + if adjust_line and not filename.startswith('<'): + # Validate breakpoints and adjust their positions. + try: + lines = sorted(_get_code_lines(filename)) + except Exception: + pass + else: + if line not in lines: + # Adjust to the first preceding valid line. + idx = bisect.bisect_left(lines, line) + if idx > 0: + line = lines[idx - 1] + + result = self._AddBreakpointResult(filename, line) + + if not filename.startswith('<'): + # Note: if a mapping pointed to a file starting with '<', don't validate. + + if not pydevd_file_utils.exists(filename): + result.error_code = self.ADD_BREAKPOINT_FILE_NOT_FOUND + return result + + if ( + py_db.is_files_filter_enabled and + not py_db.get_require_module_for_filters() and + py_db.apply_files_filter(self._DummyFrame(filename), filename, False) + ): + # Note that if `get_require_module_for_filters()` returns False, we don't do this check. + # This is because we don't have the module name given a file at this point (in + # runtime it's gotten from the frame.f_globals). + # An option could be calculate it based on the filename and current sys.path, + # but on some occasions that may be wrong (for instance with `__main__` or if + # the user dynamically changes the PYTHONPATH). + + # Note: depending on the use-case, filters may be changed, so, keep on going and add the + # breakpoint even with the error code. + result.error_code = self.ADD_BREAKPOINT_FILE_EXCLUDED_BY_FILTERS + + if breakpoint_type == 'python-line': + added_breakpoint = LineBreakpoint(line, condition, func_name, expression, suspend_policy, hit_condition=hit_condition, is_logpoint=is_logpoint) + breakpoints = py_db.breakpoints + file_to_id_to_breakpoint = py_db.file_to_id_to_line_breakpoint + supported_type = True + + else: + add_plugin_breakpoint_result = None + plugin = py_db.get_plugin_lazy_init() + if plugin is not None: + add_plugin_breakpoint_result = plugin.add_breakpoint('add_line_breakpoint', py_db, breakpoint_type, filename, line, condition, expression, func_name, hit_condition=hit_condition, is_logpoint=is_logpoint) + if add_plugin_breakpoint_result is not None: + supported_type = True + added_breakpoint, breakpoints = add_plugin_breakpoint_result + file_to_id_to_breakpoint = py_db.file_to_id_to_plugin_breakpoint + else: + supported_type = False + + if not supported_type: + raise NameError(breakpoint_type) + + if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: + pydev_log.debug('Added breakpoint:%s - line:%s - func_name:%s\n', filename, line, func_name) + + if filename in file_to_id_to_breakpoint: + id_to_pybreakpoint = file_to_id_to_breakpoint[filename] + else: + id_to_pybreakpoint = file_to_id_to_breakpoint[filename] = {} + + id_to_pybreakpoint[breakpoint_id] = added_breakpoint + py_db.consolidate_breakpoints(filename, id_to_pybreakpoint, breakpoints) + if py_db.plugin is not None: + py_db.has_plugin_line_breaks = py_db.plugin.has_line_breaks() + + py_db.on_breakpoints_changed() + return result + + def reapply_breakpoints(self, py_db): + ''' + Reapplies all the received breakpoints as they were received by the API (so, new + translations are applied). + ''' + items = dict_items(py_db.api_received_breakpoints) # Create a copy with items to reapply. + self.remove_all_breakpoints(py_db, '*') + for _key, val in items: + _new_filename, api_add_breakpoint_params = val + self.add_breakpoint(py_db, *api_add_breakpoint_params) + + def remove_all_breakpoints(self, py_db, filename): + ''' + Removes all the breakpoints from a given file or from all files if filename == '*'. + + :param str filename: + Note: must be sent as it was received in the protocol. It may be translated in this + function. + ''' + assert filename.__class__ == str # i.e.: bytes on py2 and str on py3 + changed = False + lst = [ + py_db.file_to_id_to_line_breakpoint, + py_db.file_to_id_to_plugin_breakpoint, + py_db.breakpoints + ] + if hasattr(py_db, 'django_breakpoints'): + lst.append(py_db.django_breakpoints) + + if hasattr(py_db, 'jinja2_breakpoints'): + lst.append(py_db.jinja2_breakpoints) + + if filename == '*': + py_db.api_received_breakpoints.clear() + + for file_to_id_to_breakpoint in lst: + if file_to_id_to_breakpoint: + file_to_id_to_breakpoint.clear() + changed = True + + else: + items = dict_items(py_db.api_received_breakpoints) # Create a copy to remove items. + translated_filenames = [] + for key, val in items: + key_filename, _breakpoint_id = key + if key_filename == filename: + new_filename, _api_add_breakpoint_params = val + # Note: there can be actually 1:N mappings due to source mapping (i.e.: ipython). + translated_filenames.append(new_filename) + del py_db.api_received_breakpoints[key] + + for filename in translated_filenames: + for file_to_id_to_breakpoint in lst: + if filename in file_to_id_to_breakpoint: + del file_to_id_to_breakpoint[filename] + changed = True + + if changed: + py_db.on_breakpoints_changed(removed=True) + + def remove_breakpoint(self, py_db, filename, breakpoint_type, breakpoint_id): + ''' + :param str filename: + Note: must be sent as it was received in the protocol. It may be translated in this + function. + + :param str breakpoint_type: + One of: 'python-line', 'django-line', 'jinja2-line'. + + :param int breakpoint_id: + ''' + for key, val in dict_items(py_db.api_received_breakpoints): + original_filename, existing_breakpoint_id = key + _new_filename, _api_add_breakpoint_params = val + if filename == original_filename and existing_breakpoint_id == breakpoint_id: + del py_db.api_received_breakpoints[key] + break + else: + pydev_log.info( + 'Did not find breakpoint to remove: %s (breakpoint id: %s)', filename, breakpoint_id) + + file_to_id_to_breakpoint = None + filename = self.filename_to_server(filename) + + if breakpoint_type == 'python-line': + breakpoints = py_db.breakpoints + file_to_id_to_breakpoint = py_db.file_to_id_to_line_breakpoint + + elif py_db.plugin is not None: + result = py_db.plugin.get_breakpoints(py_db, breakpoint_type) + if result is not None: + file_to_id_to_breakpoint = py_db.file_to_id_to_plugin_breakpoint + breakpoints = result + + if file_to_id_to_breakpoint is None: + pydev_log.critical('Error removing breakpoint. Cannot handle breakpoint of type %s', breakpoint_type) + + else: + try: + id_to_pybreakpoint = file_to_id_to_breakpoint.get(filename, {}) + if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: + existing = id_to_pybreakpoint[breakpoint_id] + pydev_log.info('Removed breakpoint:%s - line:%s - func_name:%s (id: %s)\n' % ( + filename, existing.line, existing.func_name.encode('utf-8'), breakpoint_id)) + + del id_to_pybreakpoint[breakpoint_id] + py_db.consolidate_breakpoints(filename, id_to_pybreakpoint, breakpoints) + if py_db.plugin is not None: + py_db.has_plugin_line_breaks = py_db.plugin.has_line_breaks() + + except KeyError: + pydev_log.info("Error removing breakpoint: Breakpoint id not found: %s id: %s. Available ids: %s\n", + filename, breakpoint_id, dict_keys(id_to_pybreakpoint)) + + py_db.on_breakpoints_changed(removed=True) + + def request_exec_or_evaluate( + self, py_db, seq, thread_id, frame_id, expression, is_exec, trim_if_too_big, attr_to_set_result): + py_db.post_method_as_internal_command( + thread_id, internal_evaluate_expression, + seq, thread_id, frame_id, expression, is_exec, trim_if_too_big, attr_to_set_result) + + def request_exec_or_evaluate_json( + self, py_db, request, thread_id): + py_db.post_method_as_internal_command( + thread_id, internal_evaluate_expression_json, request, thread_id) + + def request_set_expression_json(self, py_db, request, thread_id): + py_db.post_method_as_internal_command( + thread_id, internal_set_expression_json, request, thread_id) + + def request_console_exec(self, py_db, seq, thread_id, frame_id, expression): + int_cmd = InternalConsoleExec(seq, thread_id, frame_id, expression) + py_db.post_internal_command(int_cmd, thread_id) + + def request_load_source(self, py_db, seq, filename): + ''' + :param str filename: + Note: must be sent as it was received in the protocol. It may be translated in this + function. + ''' + try: + filename = self.filename_to_server(filename) + assert filename.__class__ == str # i.e.: bytes on py2 and str on py3 + + with open(filename, 'r') as stream: + source = stream.read() + cmd = py_db.cmd_factory.make_load_source_message(seq, source) + except: + cmd = py_db.cmd_factory.make_error_message(seq, get_exception_traceback_str()) + + py_db.writer.add_command(cmd) + + def add_python_exception_breakpoint( + self, + py_db, + exception, + condition, + expression, + notify_on_handled_exceptions, + notify_on_unhandled_exceptions, + notify_on_first_raise_only, + ignore_libraries, + ): + exception_breakpoint = py_db.add_break_on_exception( + exception, + condition=condition, + expression=expression, + notify_on_handled_exceptions=notify_on_handled_exceptions, + notify_on_unhandled_exceptions=notify_on_unhandled_exceptions, + notify_on_first_raise_only=notify_on_first_raise_only, + ignore_libraries=ignore_libraries, + ) + + if exception_breakpoint is not None: + py_db.on_breakpoints_changed() + + def add_plugins_exception_breakpoint(self, py_db, breakpoint_type, exception): + supported_type = False + plugin = py_db.get_plugin_lazy_init() + if plugin is not None: + supported_type = plugin.add_breakpoint('add_exception_breakpoint', py_db, breakpoint_type, exception) + + if supported_type: + py_db.has_plugin_exception_breaks = py_db.plugin.has_exception_breaks() + py_db.on_breakpoints_changed() + else: + raise NameError(breakpoint_type) + + def remove_python_exception_breakpoint(self, py_db, exception): + try: + cp = py_db.break_on_uncaught_exceptions.copy() + cp.pop(exception, None) + py_db.break_on_uncaught_exceptions = cp + + cp = py_db.break_on_caught_exceptions.copy() + cp.pop(exception, None) + py_db.break_on_caught_exceptions = cp + except: + pydev_log.exception("Error while removing exception %s", sys.exc_info()[0]) + + py_db.on_breakpoints_changed(removed=True) + + def remove_plugins_exception_breakpoint(self, py_db, exception_type, exception): + # I.e.: no need to initialize lazy (if we didn't have it in the first place, we can't remove + # anything from it anyways). + plugin = py_db.plugin + if plugin is None: + return + + supported_type = plugin.remove_exception_breakpoint(py_db, exception_type, exception) + + if supported_type: + py_db.has_plugin_exception_breaks = py_db.plugin.has_exception_breaks() + else: + raise NameError(exception_type) + + py_db.on_breakpoints_changed(removed=True) + + def remove_all_exception_breakpoints(self, py_db): + py_db.break_on_uncaught_exceptions = {} + py_db.break_on_caught_exceptions = {} + + plugin = py_db.plugin + if plugin is not None: + plugin.remove_all_exception_breakpoints(py_db) + py_db.on_breakpoints_changed(removed=True) + + def set_project_roots(self, py_db, project_roots): + ''' + :param unicode project_roots: + ''' + py_db.set_project_roots(project_roots) + + def set_stepping_resumes_all_threads(self, py_db, stepping_resumes_all_threads): + py_db.stepping_resumes_all_threads = stepping_resumes_all_threads + + # Add it to the namespace so that it's available as PyDevdAPI.ExcludeFilter + from _pydevd_bundle.pydevd_filtering import ExcludeFilter # noqa + + def set_exclude_filters(self, py_db, exclude_filters): + ''' + :param list(PyDevdAPI.ExcludeFilter) exclude_filters: + ''' + py_db.set_exclude_filters(exclude_filters) + + def set_use_libraries_filter(self, py_db, use_libraries_filter): + py_db.set_use_libraries_filter(use_libraries_filter) + + def request_get_variable_json(self, py_db, request, thread_id): + ''' + :param VariablesRequest request: + ''' + py_db.post_method_as_internal_command( + thread_id, internal_get_variable_json, request) + + def request_change_variable_json(self, py_db, request, thread_id): + ''' + :param SetVariableRequest request: + ''' + py_db.post_method_as_internal_command( + thread_id, internal_change_variable_json, request) + + def set_dont_trace_start_end_patterns(self, py_db, start_patterns, end_patterns): + # After it's set the first time, we can still change it, but we need to reset the + # related caches. + reset_caches = False + dont_trace_start_end_patterns_previously_set = \ + py_db.dont_trace_external_files.__name__ == 'custom_dont_trace_external_files' + + if not dont_trace_start_end_patterns_previously_set and not start_patterns and not end_patterns: + # If it wasn't set previously and start and end patterns are empty we don't need to do anything. + return + + if not py_db.is_cache_file_type_empty(): + # i.e.: custom function set in set_dont_trace_start_end_patterns. + if dont_trace_start_end_patterns_previously_set: + reset_caches = py_db.dont_trace_external_files.start_patterns != start_patterns or \ + py_db.dont_trace_external_files.end_patterns != end_patterns + + else: + reset_caches = True + + def custom_dont_trace_external_files(abs_path): + return abs_path.startswith(start_patterns) or abs_path.endswith(end_patterns) + + custom_dont_trace_external_files.start_patterns = start_patterns + custom_dont_trace_external_files.end_patterns = end_patterns + py_db.dont_trace_external_files = custom_dont_trace_external_files + + if reset_caches: + py_db.clear_dont_trace_start_end_patterns_caches() + + def stop_on_entry(self): + main_thread = pydevd_utils.get_main_thread() + if main_thread is None: + pydev_log.critical('Could not find main thread while setting Stop on Entry.') + else: + info = set_additional_thread_info(main_thread) + info.pydev_original_step_cmd = CMD_STOP_ON_START + info.pydev_step_cmd = CMD_STEP_INTO_MY_CODE + + def set_ignore_system_exit_codes(self, py_db, ignore_system_exit_codes): + py_db.set_ignore_system_exit_codes(ignore_system_exit_codes) + + SourceMappingEntry = pydevd_source_mapping.SourceMappingEntry + + def set_source_mapping(self, py_db, source_filename, mapping): + ''' + :param str source_filename: + The filename for the source mapping (bytes on py2 and str on py3). + + :param list(SourceMappingEntry) mapping: + A list with the source mapping entries to be applied to the given filename. + + :return str: + An error message if it was not possible to set the mapping or an empty string if + everything is ok. + ''' + source_filename = self.filename_to_server(source_filename) + for map_entry in mapping: + map_entry.source_filename = source_filename + error_msg = py_db.source_mapping.set_source_mapping(source_filename, mapping) + if error_msg: + return error_msg + + self.reapply_breakpoints(py_db) + return '' diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_breakpoints.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_breakpoints.py new file mode 100644 index 0000000..ab7c2c5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_breakpoints.py @@ -0,0 +1,160 @@ +from _pydevd_bundle.pydevd_constants import dict_iter_values, IS_PY24 +from _pydev_bundle import pydev_log +from _pydevd_bundle import pydevd_import_class +from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame +from _pydev_imps._pydev_saved_modules import threading + + +class ExceptionBreakpoint(object): + + def __init__( + self, + qname, + condition, + expression, + notify_on_handled_exceptions, + notify_on_unhandled_exceptions, + notify_on_first_raise_only, + ignore_libraries + ): + exctype = get_exception_class(qname) + self.qname = qname + if exctype is not None: + self.name = exctype.__name__ + else: + self.name = None + + self.condition = condition + self.expression = expression + self.notify_on_unhandled_exceptions = notify_on_unhandled_exceptions + self.notify_on_handled_exceptions = notify_on_handled_exceptions + self.notify_on_first_raise_only = notify_on_first_raise_only + self.ignore_libraries = ignore_libraries + + self.type = exctype + + def __str__(self): + return self.qname + + @property + def has_condition(self): + return self.condition is not None + + def handle_hit_condition(self, frame): + return False + + +class LineBreakpoint(object): + + def __init__(self, line, condition, func_name, expression, suspend_policy="NONE", hit_condition=None, is_logpoint=False): + self.line = line + self.condition = condition + self.func_name = func_name + self.expression = expression + self.suspend_policy = suspend_policy + self.hit_condition = hit_condition + self._hit_count = 0 + self._hit_condition_lock = threading.Lock() + self.is_logpoint = is_logpoint + + @property + def has_condition(self): + return bool(self.condition) or bool(self.hit_condition) + + def handle_hit_condition(self, frame): + if not self.hit_condition: + return False + ret = False + with self._hit_condition_lock: + self._hit_count += 1 + expr = self.hit_condition.replace('@HIT@', str(self._hit_count)) + try: + ret = bool(eval(expr, frame.f_globals, frame.f_locals)) + except Exception: + ret = False + return ret + + +def get_exception_breakpoint(exctype, exceptions): + if not exctype: + exception_full_qname = None + else: + exception_full_qname = str(exctype.__module__) + '.' + exctype.__name__ + + exc = None + if exceptions is not None: + try: + return exceptions[exception_full_qname] + except KeyError: + for exception_breakpoint in dict_iter_values(exceptions): + if exception_breakpoint.type is not None and issubclass(exctype, exception_breakpoint.type): + if exc is None or issubclass(exception_breakpoint.type, exc.type): + exc = exception_breakpoint + return exc + + +def stop_on_unhandled_exception(py_db, thread, additional_info, arg): + exctype, value, tb = arg + break_on_uncaught_exceptions = py_db.break_on_uncaught_exceptions + if break_on_uncaught_exceptions: + exception_breakpoint = py_db.get_exception_breakpoint(exctype, break_on_uncaught_exceptions) + else: + exception_breakpoint = None + + if not exception_breakpoint: + return + + if tb is None: # sometimes it can be None, e.g. with GTK + return + + if exctype is KeyboardInterrupt: + return + + if exctype is SystemExit and py_db.ignore_system_exit_code(value): + return + + if py_db.exclude_exception_by_filter(exception_breakpoint, tb, True): + return + + frames = [] + user_frame = None + + while tb: + frame = tb.tb_frame + if exception_breakpoint.ignore_libraries and py_db.in_project_scope(frame): + user_frame = tb.tb_frame + frames.append(tb.tb_frame) + tb = tb.tb_next + + frames_byid = dict([(id(frame), frame) for frame in frames]) + if exception_breakpoint.ignore_libraries and user_frame is not None: + frame = user_frame + else: + frame = frames[-1] + add_exception_to_frame(frame, arg) + if exception_breakpoint.condition is not None: + eval_result = py_db.handle_breakpoint_condition(additional_info, exception_breakpoint, frame) + if not eval_result: + return + + if exception_breakpoint.expression is not None: + py_db.handle_breakpoint_expression(exception_breakpoint, additional_info, frame) + + try: + additional_info.pydev_message = exception_breakpoint.qname + except: + additional_info.pydev_message = exception_breakpoint.qname.encode('utf-8') + + pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % (exception_breakpoint.qname,)) + + py_db.do_stop_on_unhandled_exception(thread, frame, frames_byid, arg) + + +def get_exception_class(kls): + if IS_PY24 and "BaseException" == kls: + kls = "Exception" + + try: + return eval(kls) + except: + return pydevd_import_class.import_name(kls) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_collect_try_except_info.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_collect_try_except_info.py new file mode 100644 index 0000000..4d62736 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_collect_try_except_info.py @@ -0,0 +1,191 @@ +from opcode import HAVE_ARGUMENT, EXTENDED_ARG, hasconst, opname, hasname, hasjrel, haslocal, \ + hascompare, hasfree, cmp_op +import dis +import sys +from collections import namedtuple + +try: + xrange +except NameError: + xrange = range + + +class TryExceptInfo(object): + + def __init__(self, try_line, is_finally=False): + self.try_line = try_line + self.is_finally = is_finally + self.except_line = -1 + self.except_bytecode_offset = -1 + self.except_end_line = -1 + self.except_end_bytecode_offset = -1 + self.raise_lines_in_except = [] + + def is_line_in_try_block(self, line): + return self.try_line <= line <= self.except_line + + def is_line_in_except_block(self, line): + return self.except_line <= line <= self.except_end_line + + def __str__(self): + lst = [ + '{try:', + str(self.try_line), + ' except ', + str(self.except_line), + ' end block ', + str(self.except_end_line), + ] + if self.raise_lines_in_except: + lst.append(' raises: %s' % (', '.join(str(x) for x in self.raise_lines_in_except),)) + + lst.append('}') + return ''.join(lst) + + __repr__ = __str__ + + +def _get_line(op_offset_to_line, op_offset, firstlineno, search=False): + op_offset_original = op_offset + while op_offset >= 0: + ret = op_offset_to_line.get(op_offset) + if ret is not None: + return ret - firstlineno + if not search: + return ret + else: + op_offset -= 1 + raise AssertionError('Unable to find line for offset: %s.Info: %s' % ( + op_offset_original, op_offset_to_line)) + + +def debug(s): + pass + + +_Instruction = namedtuple('_Instruction', 'opname, opcode, starts_line, argval, is_jump_target, offset') + + +def _iter_as_bytecode_as_instructions_py2(co): + code = co.co_code + op_offset_to_line = dict(dis.findlinestarts(co)) + labels = set(dis.findlabels(code)) + bytecode_len = len(code) + i = 0 + extended_arg = 0 + free = None + + op_to_name = opname + + while i < bytecode_len: + c = code[i] + op = ord(c) + is_jump_target = i in labels + + curr_op_name = op_to_name[op] + initial_bytecode_offset = i + + i = i + 1 + if op < HAVE_ARGUMENT: + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), None, is_jump_target, initial_bytecode_offset) + + else: + oparg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg + + extended_arg = 0 + i = i + 2 + if op == EXTENDED_ARG: + extended_arg = oparg * 65536 + + if op in hasconst: + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), co.co_consts[oparg], is_jump_target, initial_bytecode_offset) + elif op in hasname: + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), co.co_names[oparg], is_jump_target, initial_bytecode_offset) + elif op in hasjrel: + argval = i + oparg + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), argval, is_jump_target, initial_bytecode_offset) + elif op in haslocal: + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), co.co_varnames[oparg], is_jump_target, initial_bytecode_offset) + elif op in hascompare: + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), cmp_op[oparg], is_jump_target, initial_bytecode_offset) + elif op in hasfree: + if free is None: + free = co.co_cellvars + co.co_freevars + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), free[oparg], is_jump_target, initial_bytecode_offset) + else: + yield _Instruction(curr_op_name, op, _get_line(op_offset_to_line, initial_bytecode_offset, 0), oparg, is_jump_target, initial_bytecode_offset) + + +def collect_try_except_info(co, use_func_first_line=False): + if not hasattr(co, 'co_lnotab'): + return [] + + if use_func_first_line: + firstlineno = co.co_firstlineno + else: + firstlineno = 0 + + try_except_info_lst = [] + stack_in_setup = [] + + if sys.version_info[0] < 3: + iter_in = _iter_as_bytecode_as_instructions_py2(co) + else: + iter_in = dis.Bytecode(co) + iter_in = list(iter_in) + + op_offset_to_line = dict(dis.findlinestarts(co)) + bytecode_to_instruction = {} + for instruction in iter_in: + bytecode_to_instruction[instruction.offset] = instruction + + if iter_in: + for instruction in iter_in: + curr_op_name = instruction.opname + + if curr_op_name == 'SETUP_EXCEPT': + try_except_info = TryExceptInfo( + _get_line(op_offset_to_line, instruction.offset, firstlineno, search=True)) + try_except_info.except_bytecode_offset = instruction.argval + try_except_info.except_line = _get_line( + op_offset_to_line, + try_except_info.except_bytecode_offset, + firstlineno, + ) + + stack_in_setup.append(try_except_info) + + elif curr_op_name == 'SETUP_FINALLY': + # We need to collect try..finally blocks too to make sure that + # the stack_in_setup we're using to collect info is correct. + try_except_info = TryExceptInfo( + _get_line(op_offset_to_line, instruction.offset, firstlineno, search=True), is_finally=True) + stack_in_setup.append(try_except_info) + + elif curr_op_name == 'RAISE_VARARGS': + # We want to know about reraises and returns inside of except blocks (unfortunately + # a raise appears to the debugger as a return, so, we may need to differentiate). + if instruction.argval == 0: + for info in stack_in_setup: + info.raise_lines_in_except.append( + _get_line(op_offset_to_line, instruction.offset, firstlineno, search=True)) + + elif curr_op_name == 'END_FINALLY': # The except block also ends with 'END_FINALLY'. + stack_in_setup[-1].except_end_bytecode_offset = instruction.offset + stack_in_setup[-1].except_end_line = _get_line(op_offset_to_line, instruction.offset, firstlineno, search=True) + if not stack_in_setup[-1].is_finally: + # Don't add try..finally blocks. + try_except_info_lst.append(stack_in_setup[-1]) + del stack_in_setup[-1] + + while stack_in_setup: + # On Py3 the END_FINALLY may not be there (so, the end of the function is also the end + # of the stack). + stack_in_setup[-1].except_end_bytecode_offset = instruction.offset + stack_in_setup[-1].except_end_line = _get_line(op_offset_to_line, instruction.offset, firstlineno, search=True) + if not stack_in_setup[-1].is_finally: + # Don't add try..finally blocks. + try_except_info_lst.append(stack_in_setup[-1]) + del stack_in_setup[-1] + + return try_except_info_lst diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py new file mode 100644 index 0000000..bfba443 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py @@ -0,0 +1,1527 @@ +''' pydevd - a debugging daemon +This is the daemon you launch for python remote debugging. + +Protocol: +each command has a format: + id\tsequence-num\ttext + id: protocol command number + sequence-num: each request has a sequence number. Sequence numbers + originating at the debugger are odd, sequence numbers originating + at the daemon are even. Every response uses the same sequence number + as the request. + payload: it is protocol dependent. When response is a complex structure, it + is returned as XML. Each attribute value is urlencoded, and then the whole + payload is urlencoded again to prevent stray characters corrupting protocol/xml encodings + + Commands: + + NUMBER NAME FROM* ARGUMENTS RESPONSE NOTE +100 series: program execution + 101 RUN JAVA - - + 102 LIST_THREADS JAVA RETURN with XML listing of all threads + 103 THREAD_CREATE PYDB - XML with thread information + 104 THREAD_KILL JAVA id (or * to exit) kills the thread + PYDB id nofies JAVA that thread was killed + 105 THREAD_SUSPEND JAVA XML of the stack, suspends the thread + reason for suspension + PYDB id notifies JAVA that thread was suspended + + 106 CMD_THREAD_RUN JAVA id resume the thread + PYDB id \t reason notifies JAVA that thread was resumed + + 107 STEP_INTO JAVA thread_id + 108 STEP_OVER JAVA thread_id + 109 STEP_RETURN JAVA thread_id + + 110 GET_VARIABLE JAVA thread_id \t frame_id \t GET_VARIABLE with XML of var content + FRAME|GLOBAL \t attributes* + + 111 SET_BREAK JAVA file/line of the breakpoint + 112 REMOVE_BREAK JAVA file/line of the return + 113 CMD_EVALUATE_EXPRESSION JAVA expression result of evaluating the expression + 114 CMD_GET_FRAME JAVA request for frame contents + 115 CMD_EXEC_EXPRESSION JAVA + 116 CMD_WRITE_TO_CONSOLE PYDB + 117 CMD_CHANGE_VARIABLE + 118 CMD_RUN_TO_LINE + 119 CMD_RELOAD_CODE + 120 CMD_GET_COMPLETIONS JAVA + + 200 CMD_REDIRECT_OUTPUT JAVA streams to redirect as string - + 'STDOUT' (redirect only STDOUT) + 'STDERR' (redirect only STDERR) + 'STDOUT STDERR' (redirect both streams) + +500 series diagnostics/ok + 501 VERSION either Version string (1.0) Currently just used at startup + 502 RETURN either Depends on caller - + +900 series: errors + 901 ERROR either - This is reserved for unexpected errors. + + * JAVA - remote debugger, the java end + * PYDB - pydevd, the python end +''' + +import itertools +import linecache +import os + +from _pydev_bundle.pydev_imports import _queue +from _pydev_imps._pydev_saved_modules import time +from _pydev_imps._pydev_saved_modules import thread +from _pydev_imps._pydev_saved_modules import threading +from socket import AF_INET, SOCK_STREAM, SHUT_RD, SHUT_WR, SOL_SOCKET, SO_REUSEADDR, SHUT_RDWR +from _pydevd_bundle.pydevd_constants import (DebugInfoHolder, get_thread_id, IS_JYTHON, IS_PY2, + IS_PY36_OR_GREATER, STATE_RUN, dict_keys, ASYNC_EVAL_TIMEOUT_SEC, GlobalDebuggerHolder, + get_global_debugger, GetGlobalDebugger, set_global_debugger) # Keep for backward compatibility @UnusedImport +from _pydev_bundle.pydev_override import overrides +import weakref +from _pydev_bundle._pydev_completer import extract_token_and_qualifier +from _pydevd_bundle._debug_adapter.pydevd_schema import VariablesResponseBody, \ + SetVariableResponseBody +from _pydevd_bundle._debug_adapter import pydevd_base_schema, pydevd_schema +from _pydevd_bundle.pydevd_net_command import NetCommand +from _pydevd_bundle.pydevd_xml import ExceptionOnEvaluate +try: + from urllib import quote_plus, unquote_plus +except: + from urllib.parse import quote_plus, unquote_plus # @Reimport @UnresolvedImport + +import pydevconsole +from _pydevd_bundle import pydevd_vars, pydevd_utils +import pydevd_tracing +from _pydevd_bundle import pydevd_xml +from _pydevd_bundle import pydevd_vm_type +import sys +import traceback +from _pydevd_bundle.pydevd_utils import quote_smart as quote, compare_object_attrs_key +from _pydev_bundle import pydev_log +from _pydev_bundle.pydev_log import exception as pydev_log_exception +from _pydev_bundle import _pydev_completer + +from pydevd_tracing import get_exception_traceback_str +from _pydevd_bundle import pydevd_console +from _pydev_bundle.pydev_monkey import disable_trace_thread_modules, enable_trace_thread_modules +from socket import socket +try: + import cStringIO as StringIO # may not always be available @UnusedImport +except: + try: + import StringIO # @Reimport + except: + import io as StringIO + +# CMD_XXX constants imported for backward compatibility +from _pydevd_bundle.pydevd_comm_constants import * # @UnusedWildImport + +if IS_JYTHON: + import org.python.core as JyCore # @UnresolvedImport + + +class PyDBDaemonThread(threading.Thread): + created_pydb_daemon_threads = {} + + def __init__(self, target_and_args=None): + ''' + :param target_and_args: + tuple(func, args, kwargs) if this should be a function and args to run. + -- Note: use through run_as_pydevd_daemon_thread(). + ''' + threading.Thread.__init__(self) + self.killReceived = False + mark_as_pydevd_daemon_thread(self) + self._target_and_args = target_and_args + + def run(self): + created_pydb_daemon = self.created_pydb_daemon_threads + created_pydb_daemon[self] = 1 + try: + try: + if IS_JYTHON and not isinstance(threading.currentThread(), threading._MainThread): + # we shouldn't update sys.modules for the main thread, cause it leads to the second importing 'threading' + # module, and the new instance of main thread is created + ss = JyCore.PySystemState() + # Note: Py.setSystemState() affects only the current thread. + JyCore.Py.setSystemState(ss) + + self._stop_trace() + self._on_run() + except: + if sys is not None and pydev_log_exception is not None: + pydev_log_exception() + finally: + del created_pydb_daemon[self] + + def _on_run(self): + if self._target_and_args is not None: + target, args, kwargs = self._target_and_args + target(*args, **kwargs) + else: + raise NotImplementedError('Should be reimplemented by: %s' % self.__class__) + + def do_kill_pydev_thread(self): + self.killReceived = True + + def _stop_trace(self): + if self.pydev_do_not_trace: + pydevd_tracing.SetTrace(None) # no debugging on this thread + + +def mark_as_pydevd_daemon_thread(thread): + thread.pydev_do_not_trace = True + thread.is_pydev_daemon_thread = True + thread.daemon = True + + +def run_as_pydevd_daemon_thread(func, *args, **kwargs): + ''' + Runs a function as a pydevd daemon thread (without any tracing in place). + ''' + t = PyDBDaemonThread(target_and_args=(func, args, kwargs)) + t.name = '%s (pydevd daemon thread)' % (func.__name__,) + t.start() + return t + + +class ReaderThread(PyDBDaemonThread): + ''' reader thread reads and dispatches commands in an infinite loop ''' + + def __init__(self, sock, terminate_on_socket_close=True): + assert sock is not None + from _pydevd_bundle.pydevd_process_net_command_json import process_net_command_json + from _pydevd_bundle.pydevd_process_net_command import process_net_command + PyDBDaemonThread.__init__(self) + self._terminate_on_socket_close = terminate_on_socket_close + + self.sock = sock + self._buffer = b'' + self.setName("pydevd.Reader") + self.process_net_command = process_net_command + self.process_net_command_json = process_net_command_json + self.global_debugger_holder = GlobalDebuggerHolder + + @overrides(PyDBDaemonThread.do_kill_pydev_thread) + def do_kill_pydev_thread(self): + PyDBDaemonThread.do_kill_pydev_thread(self) + # We must close the socket so that it doesn't stay halted there. + try: + self.sock.shutdown(SHUT_RD) # shutdown the socket for read + except: + pass + try: + self.sock.close() + except: + pass + + def _read(self, size): + while True: + buffer_len = len(self._buffer) + if buffer_len == size: + ret = self._buffer + self._buffer = b'' + return ret + + if buffer_len > size: + ret = self._buffer[:size] + self._buffer = self._buffer[size:] + return ret + + try: + r = self.sock.recv(max(size - buffer_len, 1024)) + except OSError: + return b'' + if not r: + return b'' + self._buffer += r + + def _read_line(self): + while True: + i = self._buffer.find(b'\n') + if i != -1: + i += 1 # Add the newline to the return + ret = self._buffer[:i] + self._buffer = self._buffer[i:] + return ret + else: + try: + r = self.sock.recv(1024) + except OSError: + return b'' + if not r: + return b'' + self._buffer += r + + @overrides(PyDBDaemonThread._on_run) + def _on_run(self): + try: + content_len = -1 + + while not self.killReceived: + try: + line = self._read_line() + + if len(line) == 0: + self.handle_except() + return # Finished communication. + + if line.startswith(b'Content-Length:'): + content_len = int(line.strip().split(b':', 1)[1]) + continue + + if content_len != -1: + # If we previously received a content length, read until a '\r\n'. + if line == b'\r\n': + json_contents = self._read(content_len) + content_len = -1 + + if len(json_contents) == 0: + self.handle_except() + return # Finished communication. + + # We just received a json message, let's process it. + self.process_net_command_json(self.global_debugger_holder.global_dbg, json_contents) + + continue + else: + # No content len, regular line-based protocol message (remove trailing new-line). + if line.endswith(b'\n\n'): + line = line[:-2] + + elif line.endswith(b'\n'): + line = line[:-1] + + elif line.endswith(b'\r'): + line = line[:-1] + except: + if not self.killReceived: + pydev_log_exception() + self.handle_except() + return # Finished communication. + + # Note: the java backend is always expected to pass utf-8 encoded strings. We now work with unicode + # internally and thus, we may need to convert to the actual encoding where needed (i.e.: filenames + # on python 2 may need to be converted to the filesystem encoding). + if hasattr(line, 'decode'): + line = line.decode('utf-8') + + if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS: + pydev_log.critical(u'debugger: received >>%s<<\n' % (line,)) + + args = line.split(u'\t', 2) + try: + cmd_id = int(args[0]) + pydev_log.debug('Received command: %s %s\n' % (ID_TO_MEANING.get(str(cmd_id), '???'), line,)) + self.process_command(cmd_id, int(args[1]), args[2]) + except: + if sys is not None and pydev_log_exception is not None: # Could happen at interpreter shutdown + pydev_log_exception("Can't process net command: %s.", line) + + except: + if not self.killReceived: + if sys is not None and pydev_log_exception is not None: # Could happen at interpreter shutdown + pydev_log_exception() + + self.handle_except() + + def handle_except(self): + if self._terminate_on_socket_close: + self.global_debugger_holder.global_dbg.finish_debugging_session() + + def process_command(self, cmd_id, seq, text): + self.process_net_command(self.global_debugger_holder.global_dbg, cmd_id, seq, text) + + +class WriterThread(PyDBDaemonThread): + ''' writer thread writes out the commands in an infinite loop ''' + + def __init__(self, sock, terminate_on_socket_close=True): + PyDBDaemonThread.__init__(self) + self.sock = sock + self._terminate_on_socket_close = terminate_on_socket_close + self.setName("pydevd.Writer") + self.cmdQueue = _queue.Queue() + if pydevd_vm_type.get_vm_type() == 'python': + self.timeout = 0 + else: + self.timeout = 0.1 + + def add_command(self, cmd): + ''' cmd is NetCommand ''' + if not self.killReceived: # we don't take new data after everybody die + self.cmdQueue.put(cmd) + + @overrides(PyDBDaemonThread._on_run) + def _on_run(self): + ''' just loop and write responses ''' + + try: + while True: + try: + try: + cmd = self.cmdQueue.get(1, 0.1) + except _queue.Empty: + if self.killReceived: + try: + self.sock.shutdown(SHUT_WR) + except: + pass + try: + self.sock.close() + except: + pass + + return # break if queue is empty and killReceived + else: + continue + except: + # pydev_log.info('Finishing debug communication...(1)') + # when liberating the thread here, we could have errors because we were shutting down + # but the thread was still not liberated + return + cmd.send(self.sock) + + if cmd.id == CMD_EXIT: + break + if time is None: + break # interpreter shutdown + time.sleep(self.timeout) + except Exception: + if self._terminate_on_socket_close: + GlobalDebuggerHolder.global_dbg.finish_debugging_session() + if DebugInfoHolder.DEBUG_TRACE_LEVEL > 0: + pydev_log_exception() + + def empty(self): + return self.cmdQueue.empty() + + @overrides(PyDBDaemonThread.do_kill_pydev_thread) + def do_kill_pydev_thread(self): + PyDBDaemonThread.do_kill_pydev_thread(self) + # We must close the socket so that it doesn't stay halted there. + try: + self.sock.shutdown(SHUT_WR) # shutdown the socket for write + except: + pass + try: + self.sock.close() + except: + pass + + +def create_server_socket(host, port): + s = socket(AF_INET, SOCK_STREAM) + s.settimeout(None) + + try: + from socket import SO_REUSEPORT + s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) + except ImportError: + s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) + + s.bind((host, port)) + pydev_log.info("Bound to port :%s", port) + return s + + +def start_server(port): + ''' binds to a port, waits for the debugger to connect ''' + s = create_server_socket(host='', port=port) + + try: + s.listen(1) + new_socket, _addr = s.accept() + pydev_log.info("Connection accepted") + # closing server socket is not necessary but we don't need it + s.shutdown(SHUT_RDWR) + s.close() + return new_socket + except: + pydev_log.exception("Could not bind to port: %s\n", port) + raise + + +def start_client(host, port): + ''' connects to a host/port ''' + pydev_log.info("Connecting to %s:%s", host, port) + + s = socket(AF_INET, SOCK_STREAM) + + # Set TCP keepalive on an open socket. + # It activates after 1 second (TCP_KEEPIDLE,) of idleness, + # then sends a keepalive ping once every 3 seconds (TCP_KEEPINTVL), + # and closes the connection after 5 failed ping (TCP_KEEPCNT), or 15 seconds + try: + from socket import IPPROTO_TCP, SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT + s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1) + s.setsockopt(IPPROTO_TCP, TCP_KEEPIDLE, 1) + s.setsockopt(IPPROTO_TCP, TCP_KEEPINTVL, 3) + s.setsockopt(IPPROTO_TCP, TCP_KEEPCNT, 5) + except ImportError: + pass # May not be available everywhere. + + try: + # 10 seconds default timeout + timeout = int(os.environ.get('PYDEVD_CONNECT_TIMEOUT', 10)) + s.settimeout(timeout) + s.connect((host, port)) + s.settimeout(None) # no timeout after connected + pydev_log.info("Connected.") + return s + except: + pydev_log.exception("Could not connect to %s: %s", host, port) + raise + + +INTERNAL_TERMINATE_THREAD = 1 +INTERNAL_SUSPEND_THREAD = 2 + + +class InternalThreadCommand(object): + ''' internal commands are generated/executed by the debugger. + + The reason for their existence is that some commands have to be executed + on specific threads. These are the InternalThreadCommands that get + get posted to PyDB.cmdQueue. + ''' + + def __init__(self, thread_id, method=None, *args, **kwargs): + self.thread_id = thread_id + self.method = method + self.args = args + self.kwargs = kwargs + + def can_be_executed_by(self, thread_id): + '''By default, it must be in the same thread to be executed + ''' + return self.thread_id == thread_id or self.thread_id.endswith('|' + thread_id) + + def do_it(self, dbg): + try: + if self.method is not None: + self.method(dbg, *self.args, **self.kwargs) + else: + raise NotImplementedError("you have to override do_it") + finally: + self.args = None + self.kwargs = None + + +class InternalThreadCommandForAnyThread(InternalThreadCommand): + + def __init__(self, thread_id, method=None, *args, **kwargs): + assert thread_id == '*' + + InternalThreadCommand.__init__(self, thread_id, method, *args, **kwargs) + + self.executed = False + self.lock = thread.allocate_lock() + + def can_be_executed_by(self, thread_id): + return True # Can be executed by any thread. + + def do_it(self, dbg): + self.lock.acquire() + try: + if self.executed: + return + self.executed = True + finally: + self.lock.release() + InternalThreadCommand.do_it(self, dbg) + + +def internal_reload_code(dbg, seq, module_name): + module_name = module_name + if module_name not in sys.modules: + if '.' in module_name: + new_module_name = module_name.split('.')[-1] + if new_module_name in sys.modules: + module_name = new_module_name + + reloaded_ok = False + + if module_name not in sys.modules: + sys.stderr.write('pydev debugger: Unable to find module to reload: "' + module_name + '".\n') + # Too much info... + # sys.stderr.write('pydev debugger: This usually means you are trying to reload the __main__ module (which cannot be reloaded).\n') + + else: + sys.stderr.write('pydev debugger: Start reloading module: "' + module_name + '" ... \n') + from _pydevd_bundle import pydevd_reload + if pydevd_reload.xreload(sys.modules[module_name]): + sys.stderr.write('pydev debugger: reload finished\n') + reloaded_ok = True + else: + sys.stderr.write('pydev debugger: reload finished without applying any change\n') + + cmd = dbg.cmd_factory.make_reloaded_code_message(seq, reloaded_ok) + dbg.writer.add_command(cmd) + + +class InternalGetThreadStack(InternalThreadCommand): + ''' + This command will either wait for a given thread to be paused to get its stack or will provide + it anyways after a timeout (in which case the stack will be gotten but local variables won't + be available and it'll not be possible to interact with the frame as it's not actually + stopped in a breakpoint). + ''' + + def __init__(self, seq, thread_id, py_db, set_additional_thread_info, fmt, timeout=.5, start_frame=0, levels=0): + InternalThreadCommand.__init__(self, thread_id) + self._py_db = weakref.ref(py_db) + self._timeout = time.time() + timeout + self.seq = seq + self._cmd = None + self._fmt = fmt + self._start_frame = start_frame + self._levels = levels + + # Note: receives set_additional_thread_info to avoid a circular import + # in this module. + self._set_additional_thread_info = set_additional_thread_info + + @overrides(InternalThreadCommand.can_be_executed_by) + def can_be_executed_by(self, _thread_id): + timed_out = time.time() >= self._timeout + + py_db = self._py_db() + t = pydevd_find_thread_by_id(self.thread_id) + frame = None + if t and not getattr(t, 'pydev_do_not_trace', None): + additional_info = self._set_additional_thread_info(t) + frame = additional_info.get_topmost_frame(t) + try: + self._cmd = py_db.cmd_factory.make_get_thread_stack_message( + py_db, self.seq, self.thread_id, frame, self._fmt, must_be_suspended=not timed_out, start_frame=self._start_frame, levels=self._levels) + finally: + frame = None + t = None + + return self._cmd is not None or timed_out + + @overrides(InternalThreadCommand.do_it) + def do_it(self, dbg): + if self._cmd is not None: + dbg.writer.add_command(self._cmd) + self._cmd = None + + +def internal_run_thread(thread, set_additional_thread_info): + info = set_additional_thread_info(thread) + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + info.pydev_step_stop = None + info.pydev_state = STATE_RUN + + +def internal_step_in_thread(py_db, thread_id, cmd_id, set_additional_thread_info): + thread_to_step = pydevd_find_thread_by_id(thread_id) + if thread_to_step: + info = set_additional_thread_info(thread_to_step) + info.pydev_original_step_cmd = cmd_id + info.pydev_step_cmd = cmd_id + info.pydev_state = STATE_RUN + + if py_db.stepping_resumes_all_threads: + threads = pydevd_utils.get_non_pydevd_threads() + for t in threads: + if t is not thread_to_step: + internal_run_thread(t, set_additional_thread_info) + + +class InternalSetNextStatementThread(InternalThreadCommand): + + def __init__(self, thread_id, cmd_id, line, func_name, seq=0): + self.thread_id = thread_id + self.cmd_id = cmd_id + self.line = line + self.seq = seq + + if IS_PY2: + if isinstance(func_name, unicode): + # On cython with python 2.X it requires an str, not unicode (but on python 3.3 it should be a str, not bytes). + func_name = func_name.encode('utf-8') + + self.func_name = func_name + + def do_it(self, dbg): + t = pydevd_find_thread_by_id(self.thread_id) + if t: + t.additional_info.pydev_original_step_cmd = self.cmd_id + t.additional_info.pydev_step_cmd = self.cmd_id + t.additional_info.pydev_next_line = int(self.line) + t.additional_info.pydev_func_name = self.func_name + t.additional_info.pydev_state = STATE_RUN + t.additional_info.pydev_message = str(self.seq) + + +def internal_get_variable_json(py_db, request): + ''' + :param VariablesRequest request: + ''' + arguments = request.arguments # : :type arguments: VariablesArguments + variables_reference = arguments.variablesReference + fmt = arguments.format + if hasattr(fmt, 'to_dict'): + fmt = fmt.to_dict() + + variables = [] + try: + variable = py_db.suspended_frames_manager.get_variable(variables_reference) + except KeyError: + pass + else: + for child_var in variable.get_children_variables(fmt=fmt): + variables.append(child_var.get_var_data(fmt=fmt)) + + body = VariablesResponseBody(variables) + variables_response = pydevd_base_schema.build_response(request, kwargs={'body':body}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + + +class InternalGetVariable(InternalThreadCommand): + ''' gets the value of a variable ''' + + def __init__(self, seq, thread_id, frame_id, scope, attrs): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.scope = scope + self.attributes = attrs + + def do_it(self, dbg): + ''' Converts request into python variable ''' + try: + xml = StringIO.StringIO() + xml.write("") + _typeName, val_dict = pydevd_vars.resolve_compound_variable_fields( + dbg, self.thread_id, self.frame_id, self.scope, self.attributes) + if val_dict is None: + val_dict = {} + + # assume properly ordered if resolver returns 'OrderedDict' + # check type as string to support OrderedDict backport for older Python + keys = dict_keys(val_dict) + if not (_typeName == "OrderedDict" or val_dict.__class__.__name__ == "OrderedDict" or IS_PY36_OR_GREATER): + keys.sort(key=compare_object_attrs_key) + + for k in keys: + val = val_dict[k] + evaluate_full_value = pydevd_xml.should_evaluate_full_value(val) + xml.write(pydevd_xml.var_to_xml(val, k, evaluate_full_value=evaluate_full_value)) + + xml.write("") + cmd = dbg.cmd_factory.make_get_variable_message(self.sequence, xml.getvalue()) + xml.close() + dbg.writer.add_command(cmd) + except Exception: + cmd = dbg.cmd_factory.make_error_message( + self.sequence, "Error resolving variables %s" % (get_exception_traceback_str(),)) + dbg.writer.add_command(cmd) + + +class InternalGetArray(InternalThreadCommand): + + def __init__(self, seq, roffset, coffset, rows, cols, format, thread_id, frame_id, scope, attrs): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.scope = scope + self.name = attrs.split("\t")[-1] + self.attrs = attrs + self.roffset = int(roffset) + self.coffset = int(coffset) + self.rows = int(rows) + self.cols = int(cols) + self.format = format + + def do_it(self, dbg): + try: + frame = dbg.find_frame(self.thread_id, self.frame_id) + var = pydevd_vars.eval_in_context(self.name, frame.f_globals, frame.f_locals) + xml = pydevd_vars.table_like_struct_to_xml(var, self.name, self.roffset, self.coffset, self.rows, self.cols, self.format) + cmd = dbg.cmd_factory.make_get_array_message(self.sequence, xml) + dbg.writer.add_command(cmd) + except: + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error resolving array: " + get_exception_traceback_str()) + dbg.writer.add_command(cmd) + + +def internal_change_variable(dbg, seq, thread_id, frame_id, scope, attr, value): + ''' Changes the value of a variable ''' + try: + frame = dbg.find_frame(thread_id, frame_id) + if frame is not None: + result = pydevd_vars.change_attr_expression(frame, attr, value, dbg) + else: + result = None + xml = "" + xml += pydevd_xml.var_to_xml(result, "") + xml += "" + cmd = dbg.cmd_factory.make_variable_changed_message(seq, xml) + dbg.writer.add_command(cmd) + except Exception: + cmd = dbg.cmd_factory.make_error_message(seq, "Error changing variable attr:%s expression:%s traceback:%s" % (attr, value, get_exception_traceback_str())) + dbg.writer.add_command(cmd) + + +def internal_change_variable_json(py_db, request): + ''' + The pydevd_vars.change_attr_expression(thread_id, frame_id, attr, value, dbg) can only + deal with changing at a frame level, so, currently changing the contents of something + in a different scope is currently not supported. + + :param SetVariableRequest request: + ''' + # : :type arguments: SetVariableArguments + arguments = request.arguments + variables_reference = arguments.variablesReference + fmt = arguments.format + if hasattr(fmt, 'to_dict'): + fmt = fmt.to_dict() + + try: + variable = py_db.suspended_frames_manager.get_variable(variables_reference) + except KeyError: + variable = None + + if variable is None: + _write_variable_response( + py_db, request, value='', success=False, message='Unable to find variable container to change: %s.' % (variables_reference,)) + return + + child_var = variable.change_variable(arguments.name, arguments.value, py_db, fmt=fmt) + + if child_var is None: + _write_variable_response( + py_db, request, value='', success=False, message='Unable to change: %s.' % (arguments.name,)) + return + + var_data = child_var.get_var_data(fmt=fmt) + body = SetVariableResponseBody( + value=var_data['value'], + type=var_data['type'], + variablesReference=var_data.get('variablesReference'), + namedVariables=var_data.get('namedVariables'), + indexedVariables=var_data.get('indexedVariables'), + ) + variables_response = pydevd_base_schema.build_response(request, kwargs={'body':body}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + + +def _write_variable_response(py_db, request, value, success, message): + body = SetVariableResponseBody('') + variables_response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body':body, + 'success': False, + 'message': message + }) + cmd = NetCommand(CMD_RETURN, 0, variables_response, is_json=True) + py_db.writer.add_command(cmd) + + +def internal_get_frame(dbg, seq, thread_id, frame_id): + ''' Converts request into python variable ''' + try: + frame = dbg.find_frame(thread_id, frame_id) + if frame is not None: + hidden_ns = pydevconsole.get_ipython_hidden_vars() + xml = "" + xml += pydevd_xml.frame_vars_to_xml(frame.f_locals, hidden_ns) + del frame + xml += "" + cmd = dbg.cmd_factory.make_get_frame_message(seq, xml) + dbg.writer.add_command(cmd) + else: + # pydevd_vars.dump_frames(thread_id) + # don't print this error: frame not found: means that the client is not synchronized (but that's ok) + cmd = dbg.cmd_factory.make_error_message(seq, "Frame not found: %s from thread: %s" % (frame_id, thread_id)) + dbg.writer.add_command(cmd) + except: + cmd = dbg.cmd_factory.make_error_message(seq, "Error resolving frame: %s from thread: %s" % (frame_id, thread_id)) + dbg.writer.add_command(cmd) + + +def internal_get_next_statement_targets(dbg, seq, thread_id, frame_id): + ''' gets the valid line numbers for use with set next statement ''' + try: + frame = dbg.find_frame(thread_id, frame_id) + if frame is not None: + code = frame.f_code + xml = "" + if hasattr(code, 'co_lnotab'): + lineno = code.co_firstlineno + lnotab = code.co_lnotab + for i in itertools.islice(lnotab, 1, len(lnotab), 2): + if isinstance(i, int): + lineno = lineno + i + else: + # in python 2 elements in co_lnotab are of type str + lineno = lineno + ord(i) + xml += "%d" % (lineno,) + else: + xml += "%d" % (frame.f_lineno,) + del frame + xml += "" + cmd = dbg.cmd_factory.make_get_next_statement_targets_message(seq, xml) + dbg.writer.add_command(cmd) + else: + cmd = dbg.cmd_factory.make_error_message(seq, "Frame not found: %s from thread: %s" % (frame_id, thread_id)) + dbg.writer.add_command(cmd) + except: + cmd = dbg.cmd_factory.make_error_message(seq, "Error resolving frame: %s from thread: %s" % (frame_id, thread_id)) + dbg.writer.add_command(cmd) + + +def _evaluate_response(py_db, request, result, error_message=''): + is_error = isinstance(result, ExceptionOnEvaluate) + if is_error: + result = result.result + if not error_message: + body = pydevd_schema.EvaluateResponseBody(result=result, variablesReference=0) + variables_response = pydevd_base_schema.build_response(request, kwargs={'body':body}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + else: + body = pydevd_schema.EvaluateResponseBody(result=result, variablesReference=0) + variables_response = pydevd_base_schema.build_response(request, kwargs={ + 'body':body, 'success':False, 'message': error_message}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + + +def internal_evaluate_expression_json(py_db, request, thread_id): + ''' + :param EvaluateRequest request: + ''' + # : :type arguments: EvaluateArguments + + arguments = request.arguments + expression = arguments.expression + frame_id = arguments.frameId + context = arguments.context + fmt = arguments.format + if hasattr(fmt, 'to_dict'): + fmt = fmt.to_dict() + + if IS_PY2 and isinstance(expression, unicode): + try: + expression = expression.encode('utf-8') + except: + _evaluate_response(py_db, request, '', error_message='Expression is not valid utf-8.') + raise + + frame = py_db.find_frame(thread_id, frame_id) + result = pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=False) + is_error = isinstance(result, ExceptionOnEvaluate) + + if is_error: + if context == 'hover': + _evaluate_response(py_db, request, result='') + return + + elif context == 'repl': + try: + pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=True) + except Exception as ex: + err = ''.join(traceback.format_exception_only(type(ex), ex)) + # Currently there is an issue in VSC where returning success=false for an + # eval request, in repl context, VSC does not show the error response in + # the debug console. So return the error message in result as well. + _evaluate_response(py_db, request, result=err, error_message=err) + return + # No result on exec. + _evaluate_response(py_db, request, result='') + return + + # Ok, we have the result (could be an error), let's put it into the saved variables. + frame_tracker = py_db.suspended_frames_manager.get_frame_tracker(thread_id) + if frame_tracker is None: + # This is not really expected. + _evaluate_response(py_db, request, result='', error_message='Thread id: %s is not current thread id.' % (thread_id,)) + return + + variable = frame_tracker.obtain_as_variable(expression, result, frame=frame) + var_data = variable.get_var_data(fmt=fmt) + + body = pydevd_schema.EvaluateResponseBody( + result=var_data['value'], + variablesReference=var_data.get('variablesReference', 0), + type=var_data.get('type'), + presentationHint=var_data.get('presentationHint'), + namedVariables=var_data.get('namedVariables'), + indexedVariables=var_data.get('indexedVariables'), + ) + variables_response = pydevd_base_schema.build_response(request, kwargs={'body':body}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + + +def internal_evaluate_expression(dbg, seq, thread_id, frame_id, expression, is_exec, trim_if_too_big, attr_to_set_result): + ''' gets the value of a variable ''' + try: + frame = dbg.find_frame(thread_id, frame_id) + if frame is not None: + result = pydevd_vars.evaluate_expression(dbg, frame, expression, is_exec) + if attr_to_set_result != "": + pydevd_vars.change_attr_expression(frame, attr_to_set_result, expression, dbg, result) + else: + result = None + + xml = "" + xml += pydevd_xml.var_to_xml(result, expression, trim_if_too_big) + xml += "" + cmd = dbg.cmd_factory.make_evaluate_expression_message(seq, xml) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + cmd = dbg.cmd_factory.make_error_message(seq, "Error evaluating expression " + exc) + dbg.writer.add_command(cmd) + + +def _set_expression_response(py_db, request, result, error_message): + body = pydevd_schema.SetExpressionResponseBody(result='', variablesReference=0) + variables_response = pydevd_base_schema.build_response(request, kwargs={ + 'body':body, 'success':False, 'message': error_message}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + + +def internal_set_expression_json(py_db, request, thread_id): + # : :type arguments: SetExpressionArguments + + arguments = request.arguments + expression = arguments.expression + frame_id = arguments.frameId + value = arguments.value + fmt = arguments.format + if hasattr(fmt, 'to_dict'): + fmt = fmt.to_dict() + + if IS_PY2 and isinstance(expression, unicode): + try: + expression = expression.encode('utf-8') + except: + _evaluate_response(py_db, request, '', error_message='Expression is not valid utf-8.') + raise + if IS_PY2 and isinstance(value, unicode): + try: + value = value.encode('utf-8') + except: + _evaluate_response(py_db, request, '', error_message='Value is not valid utf-8.') + raise + + frame = py_db.find_frame(thread_id, frame_id) + exec_code = '%s = (%s)' % (expression, value) + result = pydevd_vars.evaluate_expression(py_db, frame, exec_code, is_exec=True) + is_error = isinstance(result, ExceptionOnEvaluate) + + if is_error: + _set_expression_response(py_db, request, result, error_message='Error executing: %s' % (exec_code,)) + return + + # Ok, we have the result (could be an error), let's put it into the saved variables. + frame_tracker = py_db.suspended_frames_manager.get_frame_tracker(thread_id) + if frame_tracker is None: + # This is not really expected. + _set_expression_response(py_db, request, result, error_message='Thread id: %s is not current thread id.' % (thread_id,)) + return + + # Now that the exec is done, get the actual value changed to return. + result = pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=False) + variable = frame_tracker.obtain_as_variable(expression, result, frame=frame) + var_data = variable.get_var_data(fmt=fmt) + + body = pydevd_schema.SetExpressionResponseBody( + value=var_data['value'], + variablesReference=var_data.get('variablesReference', 0), + type=var_data.get('type'), + presentationHint=var_data.get('presentationHint'), + namedVariables=var_data.get('namedVariables'), + indexedVariables=var_data.get('indexedVariables'), + ) + variables_response = pydevd_base_schema.build_response(request, kwargs={'body':body}) + py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True)) + + +def internal_get_completions(dbg, seq, thread_id, frame_id, act_tok, line=-1, column=-1): + ''' + Note that if the column is >= 0, the act_tok is considered text and the actual + activation token/qualifier is computed in this command. + ''' + try: + remove_path = None + try: + qualifier = u'' + if column >= 0: + token_and_qualifier = extract_token_and_qualifier(act_tok, line, column) + act_tok = token_and_qualifier[0] + if act_tok: + act_tok += u'.' + qualifier = token_and_qualifier[1] + + frame = dbg.find_frame(thread_id, frame_id) + if frame is not None: + if IS_PY2: + if not isinstance(act_tok, bytes): + act_tok = act_tok.encode('utf-8') + if not isinstance(qualifier, bytes): + qualifier = qualifier.encode('utf-8') + + completions = _pydev_completer.generate_completions(frame, act_tok) + + # Note that qualifier and start are only actually valid for the + # Debug Adapter Protocol (for the line-based protocol, the IDE + # is required to filter the completions returned). + cmd = dbg.cmd_factory.make_get_completions_message( + seq, completions, qualifier, start=column - len(qualifier)) + dbg.writer.add_command(cmd) + else: + cmd = dbg.cmd_factory.make_error_message(seq, "internal_get_completions: Frame not found: %s from thread: %s" % (frame_id, thread_id)) + dbg.writer.add_command(cmd) + + finally: + if remove_path is not None: + sys.path.remove(remove_path) + + except: + exc = get_exception_traceback_str() + sys.stderr.write('%s\n' % (exc,)) + cmd = dbg.cmd_factory.make_error_message(seq, "Error evaluating expression " + exc) + dbg.writer.add_command(cmd) + + +def internal_get_description(dbg, seq, thread_id, frame_id, expression): + ''' Fetch the variable description stub from the debug console + ''' + try: + frame = dbg.find_frame(thread_id, frame_id) + description = pydevd_console.get_description(frame, thread_id, frame_id, expression) + description = pydevd_xml.make_valid_xml_value(quote(description, '/>_= \t')) + description_xml = '' % description + cmd = dbg.cmd_factory.make_get_description_message(seq, description_xml) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + cmd = dbg.cmd_factory.make_error_message(seq, "Error in fetching description" + exc) + dbg.writer.add_command(cmd) + + +def build_exception_info_response(dbg, thread_id, request_seq, set_additional_thread_info, iter_visible_frames_info, max_frames): + ''' + :return ExceptionInfoResponse + ''' + thread = pydevd_find_thread_by_id(thread_id) + additional_info = set_additional_thread_info(thread) + topmost_frame = additional_info.get_topmost_frame(thread) + + frames = [] + exc_type = None + exc_desc = None + if topmost_frame is not None: + frame_id_to_lineno = {} + try: + trace_obj = None + frame = topmost_frame + while frame is not None: + if frame.f_code.co_name == 'do_wait_suspend' and frame.f_code.co_filename.endswith('pydevd.py'): + arg = frame.f_locals.get('arg', None) + if arg is not None: + exc_type, exc_desc, trace_obj = arg + break + frame = frame.f_back + + while True: + tb_next = getattr(trace_obj, 'tb_next', None) + if tb_next is None: + break + trace_obj = tb_next + + info = dbg.suspended_frames_manager.get_topmost_frame_and_frame_id_to_line(thread_id) + if info is not None: + topmost_frame, frame_id_to_lineno = info + + if trace_obj is not None: + for frame_id, frame, method_name, original_filename, filename_in_utf8, lineno in iter_visible_frames_info( + dbg, trace_obj.tb_frame, frame_id_to_lineno): + + line_text = linecache.getline(original_filename, lineno) + + # Never filter out plugin frames! + if not getattr(frame, 'IS_PLUGIN_FRAME', False): + if dbg.is_files_filter_enabled and dbg.apply_files_filter(frame, original_filename, False): + continue + frames.append((filename_in_utf8, lineno, method_name, line_text)) + finally: + topmost_frame = None + + name = 'exception: type unknown' + if exc_type is not None: + try: + name = exc_type.__qualname__ + except: + try: + name = exc_type.__name__ + except: + try: + name = str(exc_type) + except: + pass + + description = 'exception: no description' + if exc_desc is not None: + try: + description = str(exc_desc) + except: + pass + + stack_str = ''.join(traceback.format_list(frames[-max_frames:])) + + # This is an extra bit of data used by Visual Studio + source_path = frames[0][0] if frames else '' + + if thread.stop_reason == CMD_STEP_CAUGHT_EXCEPTION: + break_mode = pydevd_schema.ExceptionBreakMode.ALWAYS + else: + break_mode = pydevd_schema.ExceptionBreakMode.UNHANDLED + + response = pydevd_schema.ExceptionInfoResponse( + request_seq=request_seq, + success=True, + command='exceptionInfo', + body=pydevd_schema.ExceptionInfoResponseBody( + exceptionId=name, + description=description, + breakMode=break_mode, + details=pydevd_schema.ExceptionDetails( + message=description, + typeName=name, + stackTrace=stack_str, + source=source_path + ) + ) + ) + return response + + +def internal_get_exception_details_json(dbg, request, thread_id, max_frames, set_additional_thread_info=None, iter_visible_frames_info=None): + ''' Fetch exception details + ''' + try: + response = build_exception_info_response(dbg, thread_id, request.seq, set_additional_thread_info, iter_visible_frames_info, max_frames) + except: + exc = get_exception_traceback_str() + response = pydevd_base_schema.build_response(request, kwargs={ + 'success': False, + 'message': exc, + 'body':{} + }) + dbg.writer.add_command(NetCommand(CMD_RETURN, 0, response, is_json=True)) + + +class InternalGetBreakpointException(InternalThreadCommand): + ''' Send details of exception raised while evaluating conditional breakpoint ''' + + def __init__(self, thread_id, exc_type, stacktrace): + self.sequence = 0 + self.thread_id = thread_id + self.stacktrace = stacktrace + self.exc_type = exc_type + + def do_it(self, dbg): + try: + callstack = "" + + makeValid = pydevd_xml.make_valid_xml_value + + for filename, line, methodname, methodobj in self.stacktrace: + if not filesystem_encoding_is_utf8 and hasattr(filename, "decode"): + # filename is a byte string encoded using the file system encoding + # convert it to utf8 + filename = filename.decode(file_system_encoding).encode("utf-8") + + callstack += '' \ + % (self.thread_id, makeValid(filename), line, makeValid(methodname), makeValid(methodobj)) + callstack += "" + + cmd = dbg.cmd_factory.make_send_breakpoint_exception_message(self.sequence, self.exc_type + "\t" + callstack) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + sys.stderr.write('%s\n' % (exc,)) + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error Sending Exception: " + exc) + dbg.writer.add_command(cmd) + + +class InternalSendCurrExceptionTrace(InternalThreadCommand): + ''' Send details of the exception that was caught and where we've broken in. + ''' + + def __init__(self, thread_id, arg, curr_frame_id): + ''' + :param arg: exception type, description, traceback object + ''' + self.sequence = 0 + self.thread_id = thread_id + self.curr_frame_id = curr_frame_id + self.arg = arg + + def do_it(self, dbg): + try: + cmd = dbg.cmd_factory.make_send_curr_exception_trace_message(dbg, self.sequence, self.thread_id, self.curr_frame_id, *self.arg) + del self.arg + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + sys.stderr.write('%s\n' % (exc,)) + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error Sending Current Exception Trace: " + exc) + dbg.writer.add_command(cmd) + + +class InternalSendCurrExceptionTraceProceeded(InternalThreadCommand): + ''' Send details of the exception that was caught and where we've broken in. + ''' + + def __init__(self, thread_id): + self.sequence = 0 + self.thread_id = thread_id + + def do_it(self, dbg): + try: + cmd = dbg.cmd_factory.make_send_curr_exception_trace_proceeded_message(self.sequence, self.thread_id) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + sys.stderr.write('%s\n' % (exc,)) + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error Sending Current Exception Trace Proceeded: " + exc) + dbg.writer.add_command(cmd) + + +class InternalEvaluateConsoleExpression(InternalThreadCommand): + ''' Execute the given command in the debug console ''' + + def __init__(self, seq, thread_id, frame_id, line, buffer_output=True): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.line = line + self.buffer_output = buffer_output + + def do_it(self, dbg): + ''' Create an XML for console output, error and more (true/false) + + + + true/false + + ''' + try: + frame = dbg.find_frame(self.thread_id, self.frame_id) + if frame is not None: + console_message = pydevd_console.execute_console_command( + frame, self.thread_id, self.frame_id, self.line, self.buffer_output) + + cmd = dbg.cmd_factory.make_send_console_message(self.sequence, console_message.to_xml()) + else: + from _pydevd_bundle.pydevd_console import ConsoleMessage + console_message = ConsoleMessage() + console_message.add_console_message( + pydevd_console.CONSOLE_ERROR, + "Select the valid frame in the debug view (thread: %s, frame: %s invalid)" % (self.thread_id, self.frame_id), + ) + cmd = dbg.cmd_factory.make_error_message(self.sequence, console_message.to_xml()) + except: + exc = get_exception_traceback_str() + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error evaluating expression " + exc) + dbg.writer.add_command(cmd) + + +class InternalRunCustomOperation(InternalThreadCommand): + ''' Run a custom command on an expression + ''' + + def __init__(self, seq, thread_id, frame_id, scope, attrs, style, encoded_code_or_file, fnname): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.scope = scope + self.attrs = attrs + self.style = style + self.code_or_file = unquote_plus(encoded_code_or_file) + self.fnname = fnname + + def do_it(self, dbg): + try: + res = pydevd_vars.custom_operation(dbg, self.thread_id, self.frame_id, self.scope, self.attrs, + self.style, self.code_or_file, self.fnname) + resEncoded = quote_plus(res) + cmd = dbg.cmd_factory.make_custom_operation_message(self.sequence, resEncoded) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error in running custom operation" + exc) + dbg.writer.add_command(cmd) + + +class InternalConsoleGetCompletions(InternalThreadCommand): + ''' Fetch the completions in the debug console + ''' + + def __init__(self, seq, thread_id, frame_id, act_tok): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.act_tok = act_tok + + def do_it(self, dbg): + ''' Get completions and write back to the client + ''' + try: + frame = dbg.find_frame(self.thread_id, self.frame_id) + completions_xml = pydevd_console.get_completions(frame, self.act_tok) + cmd = dbg.cmd_factory.make_send_console_message(self.sequence, completions_xml) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error in fetching completions" + exc) + dbg.writer.add_command(cmd) + + +class InternalConsoleExec(InternalThreadCommand): + ''' gets the value of a variable ''' + + def __init__(self, seq, thread_id, frame_id, expression): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.expression = expression + + def do_it(self, dbg): + ''' Converts request into python variable ''' + try: + try: + # don't trace new threads created by console command + disable_trace_thread_modules() + + result = pydevconsole.console_exec(self.thread_id, self.frame_id, self.expression, dbg) + xml = "" + xml += pydevd_xml.var_to_xml(result, "") + xml += "" + cmd = dbg.cmd_factory.make_evaluate_expression_message(self.sequence, xml) + dbg.writer.add_command(cmd) + except: + exc = get_exception_traceback_str() + sys.stderr.write('%s\n' % (exc,)) + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error evaluating console expression " + exc) + dbg.writer.add_command(cmd) + finally: + enable_trace_thread_modules() + + sys.stderr.flush() + sys.stdout.flush() + + +class InternalLoadFullValue(InternalThreadCommand): + ''' + Loads values asynchronously + ''' + + def __init__(self, seq, thread_id, frame_id, vars): + self.sequence = seq + self.thread_id = thread_id + self.frame_id = frame_id + self.vars = vars + + def do_it(self, dbg): + '''Starts a thread that will load values asynchronously''' + try: + var_objects = [] + for variable in self.vars: + variable = variable.strip() + if len(variable) > 0: + if '\t' in variable: # there are attributes beyond scope + scope, attrs = variable.split('\t', 1) + name = attrs[0] + else: + scope, attrs = (variable, None) + name = scope + var_obj = pydevd_vars.getVariable(dbg, self.thread_id, self.frame_id, scope, attrs) + var_objects.append((var_obj, name)) + + t = GetValueAsyncThreadDebug(dbg, self.sequence, var_objects) + t.start() + except: + exc = get_exception_traceback_str() + sys.stderr.write('%s\n' % (exc,)) + cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error evaluating variable %s " % exc) + dbg.writer.add_command(cmd) + + +class AbstractGetValueAsyncThread(PyDBDaemonThread): + ''' + Abstract class for a thread, which evaluates values for async variables + ''' + + def __init__(self, frame_accessor, seq, var_objects): + PyDBDaemonThread.__init__(self) + self.frame_accessor = frame_accessor + self.seq = seq + self.var_objs = var_objects + self.cancel_event = threading.Event() + + def send_result(self, xml): + raise NotImplementedError() + + @overrides(PyDBDaemonThread._on_run) + def _on_run(self): + start = time.time() + xml = StringIO.StringIO() + xml.write("") + for (var_obj, name) in self.var_objs: + current_time = time.time() + if current_time - start > ASYNC_EVAL_TIMEOUT_SEC or self.cancel_event.is_set(): + break + xml.write(pydevd_xml.var_to_xml(var_obj, name, evaluate_full_value=True)) + xml.write("") + self.send_result(xml) + xml.close() + + +class GetValueAsyncThreadDebug(AbstractGetValueAsyncThread): + ''' + A thread for evaluation async values, which returns result for debugger + Create message and send it via writer thread + ''' + + def send_result(self, xml): + if self.frame_accessor is not None: + cmd = self.frame_accessor.cmd_factory.make_load_full_value_message(self.seq, xml.getvalue()) + self.frame_accessor.writer.add_command(cmd) + + +class GetValueAsyncThreadConsole(AbstractGetValueAsyncThread): + ''' + A thread for evaluation async values, which returns result for Console + Send result directly to Console's server + ''' + + def send_result(self, xml): + if self.frame_accessor is not None: + self.frame_accessor.ReturnFullValue(self.seq, xml.getvalue()) + + +def pydevd_find_thread_by_id(thread_id): + try: + # there was a deadlock here when I did not remove the tracing function when thread was dead + threads = threading.enumerate() + for i in threads: + tid = get_thread_id(i) + if thread_id == tid or thread_id.endswith('|' + tid): + return i + + # This can happen when a request comes for a thread which was previously removed. + pydev_log.info("Could not find thread %s.", thread_id) + pydev_log.info("Available: %s.", ([get_thread_id(t) for t in threads],)) + except: + pydev_log.exception() + + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm_constants.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm_constants.py new file mode 100644 index 0000000..d82d4dc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm_constants.py @@ -0,0 +1,178 @@ +CMD_RUN = 101 +CMD_LIST_THREADS = 102 +CMD_THREAD_CREATE = 103 +CMD_THREAD_KILL = 104 +CMD_THREAD_SUSPEND = 105 +CMD_THREAD_RUN = 106 +CMD_STEP_INTO = 107 +CMD_STEP_OVER = 108 +CMD_STEP_RETURN = 109 +CMD_GET_VARIABLE = 110 +CMD_SET_BREAK = 111 +CMD_REMOVE_BREAK = 112 +CMD_EVALUATE_EXPRESSION = 113 +CMD_GET_FRAME = 114 +CMD_EXEC_EXPRESSION = 115 +CMD_WRITE_TO_CONSOLE = 116 +CMD_CHANGE_VARIABLE = 117 +CMD_RUN_TO_LINE = 118 +CMD_RELOAD_CODE = 119 +CMD_GET_COMPLETIONS = 120 + +# Note: renumbered (conflicted on merge) +CMD_CONSOLE_EXEC = 121 +CMD_ADD_EXCEPTION_BREAK = 122 +CMD_REMOVE_EXCEPTION_BREAK = 123 +CMD_LOAD_SOURCE = 124 +CMD_ADD_DJANGO_EXCEPTION_BREAK = 125 +CMD_REMOVE_DJANGO_EXCEPTION_BREAK = 126 +CMD_SET_NEXT_STATEMENT = 127 +CMD_SMART_STEP_INTO = 128 +CMD_EXIT = 129 +CMD_SIGNATURE_CALL_TRACE = 130 + +CMD_SET_PY_EXCEPTION = 131 +CMD_GET_FILE_CONTENTS = 132 +CMD_SET_PROPERTY_TRACE = 133 +# Pydev debug console commands +CMD_EVALUATE_CONSOLE_EXPRESSION = 134 +CMD_RUN_CUSTOM_OPERATION = 135 +CMD_GET_BREAKPOINT_EXCEPTION = 136 +CMD_STEP_CAUGHT_EXCEPTION = 137 +CMD_SEND_CURR_EXCEPTION_TRACE = 138 +CMD_SEND_CURR_EXCEPTION_TRACE_PROCEEDED = 139 +CMD_IGNORE_THROWN_EXCEPTION_AT = 140 +CMD_ENABLE_DONT_TRACE = 141 +CMD_SHOW_CONSOLE = 142 + +CMD_GET_ARRAY = 143 +CMD_STEP_INTO_MY_CODE = 144 +CMD_GET_CONCURRENCY_EVENT = 145 +CMD_SHOW_RETURN_VALUES = 146 +CMD_INPUT_REQUESTED = 147 +CMD_GET_DESCRIPTION = 148 + +CMD_PROCESS_CREATED = 149 +CMD_SHOW_CYTHON_WARNING = 150 +CMD_LOAD_FULL_VALUE = 151 + +CMD_GET_THREAD_STACK = 152 + +# This is mostly for unit-tests to diagnose errors on ci. +CMD_THREAD_DUMP_TO_STDERR = 153 + +# Sent from the client to signal that we should stop when we start executing user code. +CMD_STOP_ON_START = 154 + +# When the debugger is stopped in an exception, this command will provide the details of the current exception (in the current thread). +CMD_GET_EXCEPTION_DETAILS = 155 + +# Allows configuring pydevd settings (can be called multiple times and only keys +# available in the json will be configured -- keys not passed will not change the +# previous configuration). +CMD_PYDEVD_JSON_CONFIG = 156 + +CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION = 157 +CMD_THREAD_RESUME_SINGLE_NOTIFICATION = 158 + +CMD_STEP_OVER_MY_CODE = 159 +CMD_STEP_RETURN_MY_CODE = 160 + +CMD_REDIRECT_OUTPUT = 200 +CMD_GET_NEXT_STATEMENT_TARGETS = 201 +CMD_SET_PROJECT_ROOTS = 202 + +CMD_MODULE_EVENT = 203 +CMD_PROCESS_EVENT = 204 + +CMD_VERSION = 501 +CMD_RETURN = 502 +CMD_SET_PROTOCOL = 503 +CMD_ERROR = 901 + +# this number can be changed if there's need to do so +# if the io is too big, we'll not send all (could make the debugger too non-responsive) +MAX_IO_MSG_SIZE = 10000 + +VERSION_STRING = "@@BUILD_NUMBER@@" + +from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding +file_system_encoding = getfilesystemencoding() +filesystem_encoding_is_utf8 = file_system_encoding.lower() in ('utf-8', 'utf_8', 'utf8') + +ID_TO_MEANING = { + '101': 'CMD_RUN', + '102': 'CMD_LIST_THREADS', + '103': 'CMD_THREAD_CREATE', + '104': 'CMD_THREAD_KILL', + '105': 'CMD_THREAD_SUSPEND', + '106': 'CMD_THREAD_RUN', + '107': 'CMD_STEP_INTO', + '108': 'CMD_STEP_OVER', + '109': 'CMD_STEP_RETURN', + '110': 'CMD_GET_VARIABLE', + '111': 'CMD_SET_BREAK', + '112': 'CMD_REMOVE_BREAK', + '113': 'CMD_EVALUATE_EXPRESSION', + '114': 'CMD_GET_FRAME', + '115': 'CMD_EXEC_EXPRESSION', + '116': 'CMD_WRITE_TO_CONSOLE', + '117': 'CMD_CHANGE_VARIABLE', + '118': 'CMD_RUN_TO_LINE', + '119': 'CMD_RELOAD_CODE', + '120': 'CMD_GET_COMPLETIONS', + '121': 'CMD_CONSOLE_EXEC', + '122': 'CMD_ADD_EXCEPTION_BREAK', + '123': 'CMD_REMOVE_EXCEPTION_BREAK', + '124': 'CMD_LOAD_SOURCE', + '125': 'CMD_ADD_DJANGO_EXCEPTION_BREAK', + '126': 'CMD_REMOVE_DJANGO_EXCEPTION_BREAK', + '127': 'CMD_SET_NEXT_STATEMENT', + '128': 'CMD_SMART_STEP_INTO', + '129': 'CMD_EXIT', + '130': 'CMD_SIGNATURE_CALL_TRACE', + + '131': 'CMD_SET_PY_EXCEPTION', + '132': 'CMD_GET_FILE_CONTENTS', + '133': 'CMD_SET_PROPERTY_TRACE', + '134': 'CMD_EVALUATE_CONSOLE_EXPRESSION', + '135': 'CMD_RUN_CUSTOM_OPERATION', + '136': 'CMD_GET_BREAKPOINT_EXCEPTION', + '137': 'CMD_STEP_CAUGHT_EXCEPTION', + '138': 'CMD_SEND_CURR_EXCEPTION_TRACE', + '139': 'CMD_SEND_CURR_EXCEPTION_TRACE_PROCEEDED', + '140': 'CMD_IGNORE_THROWN_EXCEPTION_AT', + '141': 'CMD_ENABLE_DONT_TRACE', + '142': 'CMD_SHOW_CONSOLE', + '143': 'CMD_GET_ARRAY', + '144': 'CMD_STEP_INTO_MY_CODE', + '145': 'CMD_GET_CONCURRENCY_EVENT', + '146': 'CMD_SHOW_RETURN_VALUES', + '147': 'CMD_INPUT_REQUESTED', + '148': 'CMD_GET_DESCRIPTION', + + '149': 'CMD_PROCESS_CREATED', # Note: this is actually a notification of a sub-process created. + '150': 'CMD_SHOW_CYTHON_WARNING', + '151': 'CMD_LOAD_FULL_VALUE', + '152': 'CMD_GET_THREAD_STACK', + '153': 'CMD_THREAD_DUMP_TO_STDERR', + '154': 'CMD_STOP_ON_START', + '155': 'CMD_GET_EXCEPTION_DETAILS', + '156': 'CMD_PYDEVD_JSON_CONFIG', + '157': 'CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION', + '158': 'CMD_THREAD_RESUME_SINGLE_NOTIFICATION', + + '159': 'CMD_STEP_OVER_MY_CODE', + '160': 'CMD_STEP_RETURN_MY_CODE', + + '200': 'CMD_REDIRECT_OUTPUT', + '201': 'CMD_GET_NEXT_STATEMENT_TARGETS', + '202': 'CMD_SET_PROJECT_ROOTS', + '203': 'CMD_MODULE_EVENT', + '204': 'CMD_PROCESS_EVENT', # DAP process event. + + '501': 'CMD_VERSION', + '502': 'CMD_RETURN', + '503': 'CMD_SET_PROTOCOL', + '901': 'CMD_ERROR', +} diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_command_line_handling.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_command_line_handling.py new file mode 100644 index 0000000..f3f17bc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_command_line_handling.py @@ -0,0 +1,147 @@ +class ArgHandlerWithParam: + ''' + Handler for some arguments which needs a value + ''' + + def __init__(self, arg_name, convert_val=None, default_val=None): + self.arg_name = arg_name + self.arg_v_rep = '--%s' % (arg_name,) + self.convert_val = convert_val + self.default_val = default_val + + def to_argv(self, lst, setup): + v = setup.get(self.arg_name) + if v is not None and v != self.default_val: + lst.append(self.arg_v_rep) + lst.append('%s' % (v,)) + + def handle_argv(self, argv, i, setup): + assert argv[i] == self.arg_v_rep + del argv[i] + + val = argv[i] + if self.convert_val: + val = self.convert_val(val) + + setup[self.arg_name] = val + del argv[i] + +class ArgHandlerBool: + ''' + If a given flag is received, mark it as 'True' in setup. + ''' + + def __init__(self, arg_name, default_val=False): + self.arg_name = arg_name + self.arg_v_rep = '--%s' % (arg_name,) + self.default_val = default_val + + def to_argv(self, lst, setup): + v = setup.get(self.arg_name) + if v: + lst.append(self.arg_v_rep) + + def handle_argv(self, argv, i, setup): + assert argv[i] == self.arg_v_rep + del argv[i] + setup[self.arg_name] = True + + +ACCEPTED_ARG_HANDLERS = [ + ArgHandlerWithParam('port', int, 0), + ArgHandlerWithParam('vm_type'), + ArgHandlerWithParam('client'), + + ArgHandlerBool('server'), + ArgHandlerBool('DEBUG_RECORD_SOCKET_READS'), + ArgHandlerBool('multiproc'), # Used by PyCharm (reuses connection: ssh tunneling) + ArgHandlerBool('multiprocess'), # Used by PyDev (creates new connection to ide) + ArgHandlerBool('save-signatures'), + ArgHandlerBool('save-threading'), + ArgHandlerBool('save-asyncio'), + ArgHandlerBool('print-in-debugger-startup'), + ArgHandlerBool('cmd-line'), + ArgHandlerBool('module'), + ArgHandlerBool('json-dap'), # Protocol used by ptvsd to communicate with pydevd +] + +ARGV_REP_TO_HANDLER = {} +for handler in ACCEPTED_ARG_HANDLERS: + ARGV_REP_TO_HANDLER[handler.arg_v_rep] = handler + +def get_pydevd_file(): + import pydevd + f = pydevd.__file__ + if f.endswith('.pyc'): + f = f[:-1] + elif f.endswith('$py.class'): + f = f[:-len('$py.class')] + '.py' + return f + +def setup_to_argv(setup): + ''' + :param dict setup: + A dict previously gotten from process_command_line. + + :note: does not handle --file nor --DEBUG. + ''' + ret = [get_pydevd_file()] + + for handler in ACCEPTED_ARG_HANDLERS: + if handler.arg_name in setup: + handler.to_argv(ret, setup) + return ret + +def process_command_line(argv): + """ parses the arguments. + removes our arguments from the command line """ + setup = {} + for handler in ACCEPTED_ARG_HANDLERS: + setup[handler.arg_name] = handler.default_val + setup['file'] = '' + setup['qt-support'] = '' + + i = 0 + del argv[0] + while i < len(argv): + handler = ARGV_REP_TO_HANDLER.get(argv[i]) + if handler is not None: + handler.handle_argv(argv, i, setup) + + elif argv[i].startswith('--qt-support'): + # The --qt-support is special because we want to keep backward compatibility: + # Previously, just passing '--qt-support' meant that we should use the auto-discovery mode + # whereas now, if --qt-support is passed, it should be passed as --qt-support=, where + # mode can be one of 'auto', 'none', 'pyqt5', 'pyqt4', 'pyside'. + if argv[i] == '--qt-support': + setup['qt-support'] = 'auto' + + elif argv[i].startswith('--qt-support='): + qt_support = argv[i][len('--qt-support='):] + valid_modes = ('none', 'auto', 'pyqt5', 'pyqt4', 'pyside') + if qt_support not in valid_modes: + raise ValueError("qt-support mode invalid: " + qt_support) + if qt_support == 'none': + # On none, actually set an empty string to evaluate to False. + setup['qt-support'] = '' + else: + setup['qt-support'] = qt_support + else: + raise ValueError("Unexpected definition for qt-support flag: " + argv[i]) + + del argv[i] + + elif argv[i] == '--file': + # --file is special because it's the last one (so, no handler for it). + del argv[i] + setup['file'] = argv[i] + i = len(argv) # pop out, file is our last argument + + elif argv[i] == '--DEBUG': + from pydevd import set_debug + del argv[i] + set_debug(setup) + + else: + raise ValueError("Unexpected option: " + argv[i]) + return setup diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_console.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_console.py new file mode 100644 index 0000000..cf151b7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_console.py @@ -0,0 +1,248 @@ +'''An helper file for the pydev debugger (REPL) console +''' +import sys +import traceback +from code import InteractiveConsole + +from _pydev_bundle import _pydev_completer +from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface, BaseStdIn +from _pydev_bundle.pydev_imports import Exec +from _pydev_bundle.pydev_override import overrides +from _pydevd_bundle import pydevd_save_locals +from _pydevd_bundle.pydevd_io import IOBuf +from pydevd_tracing import get_exception_traceback_str +from _pydevd_bundle.pydevd_xml import make_valid_xml_value + +CONSOLE_OUTPUT = "output" +CONSOLE_ERROR = "error" + + +#======================================================================================================================= +# ConsoleMessage +#======================================================================================================================= +class ConsoleMessage: + """Console Messages + """ + + def __init__(self): + self.more = False + # List of tuple [('error', 'error_message'), ('message_list', 'output_message')] + self.console_messages = [] + + def add_console_message(self, message_type, message): + """add messages in the console_messages list + """ + for m in message.split("\n"): + if m.strip(): + self.console_messages.append((message_type, m)) + + def update_more(self, more): + """more is set to true if further input is required from the user + else more is set to false + """ + self.more = more + + def to_xml(self): + """Create an XML for console message_list, error and more (true/false) + + console message_list + console error + true/false + + """ + makeValid = make_valid_xml_value + + xml = '%s' % (self.more) + + for message_type, message in self.console_messages: + xml += '<%s message="%s">' % (message_type, makeValid(message), message_type) + + xml += '' + + return xml + + +#======================================================================================================================= +# _DebugConsoleStdIn +#======================================================================================================================= +class _DebugConsoleStdIn(BaseStdIn): + + @overrides(BaseStdIn.readline) + def readline(self, *args, **kwargs): + sys.stderr.write('Warning: Reading from stdin is still not supported in this console.\n') + return '\n' + + +#======================================================================================================================= +# DebugConsole +#======================================================================================================================= +class DebugConsole(InteractiveConsole, BaseInterpreterInterface): + """Wrapper around code.InteractiveConsole, in order to send + errors and outputs to the debug console + """ + + @overrides(BaseInterpreterInterface.create_std_in) + def create_std_in(self, *args, **kwargs): + try: + if not self.__buffer_output: + return sys.stdin + except: + pass + + return _DebugConsoleStdIn() # If buffered, raw_input is not supported in this console. + + @overrides(InteractiveConsole.push) + def push(self, line, frame, buffer_output=True): + """Change built-in stdout and stderr methods by the + new custom StdMessage. + execute the InteractiveConsole.push. + Change the stdout and stderr back be the original built-ins + + :param buffer_output: if False won't redirect the output. + + Return boolean (True if more input is required else False), + output_messages and input_messages + """ + self.__buffer_output = buffer_output + more = False + if buffer_output: + original_stdout = sys.stdout + original_stderr = sys.stderr + try: + try: + self.frame = frame + if buffer_output: + out = sys.stdout = IOBuf() + err = sys.stderr = IOBuf() + more = self.add_exec(line) + except Exception: + exc = get_exception_traceback_str() + if buffer_output: + err.buflist.append("Internal Error: %s" % (exc,)) + else: + sys.stderr.write("Internal Error: %s\n" % (exc,)) + finally: + # Remove frame references. + self.frame = None + frame = None + if buffer_output: + sys.stdout = original_stdout + sys.stderr = original_stderr + + if buffer_output: + return more, out.buflist, err.buflist + else: + return more, [], [] + + @overrides(BaseInterpreterInterface.do_add_exec) + def do_add_exec(self, line): + return InteractiveConsole.push(self, line) + + @overrides(InteractiveConsole.runcode) + def runcode(self, code): + """Execute a code object. + + When an exception occurs, self.showtraceback() is called to + display a traceback. All exceptions are caught except + SystemExit, which is reraised. + + A note about KeyboardInterrupt: this exception may occur + elsewhere in this code, and may not always be caught. The + caller should be prepared to deal with it. + + """ + try: + Exec(code, self.frame.f_globals, self.frame.f_locals) + pydevd_save_locals.save_locals(self.frame) + except SystemExit: + raise + except: + # In case sys.excepthook called, use original excepthook #PyDev-877: Debug console freezes with Python 3.5+ + # (showtraceback does it on python 3.5 onwards) + sys.excepthook = sys.__excepthook__ + try: + self.showtraceback() + finally: + sys.__excepthook__ = sys.excepthook + + def get_namespace(self): + dbg_namespace = {} + dbg_namespace.update(self.frame.f_globals) + dbg_namespace.update(self.frame.f_locals) # locals later because it has precedence over the actual globals + return dbg_namespace + + +#======================================================================================================================= +# InteractiveConsoleCache +#======================================================================================================================= +class InteractiveConsoleCache: + + thread_id = None + frame_id = None + interactive_console_instance = None + + +# Note: On Jython 2.1 we can't use classmethod or staticmethod, so, just make the functions below free-functions. +def get_interactive_console(thread_id, frame_id, frame, console_message): + """returns the global interactive console. + interactive console should have been initialized by this time + :rtype: DebugConsole + """ + if InteractiveConsoleCache.thread_id == thread_id and InteractiveConsoleCache.frame_id == frame_id: + return InteractiveConsoleCache.interactive_console_instance + + InteractiveConsoleCache.interactive_console_instance = DebugConsole() + InteractiveConsoleCache.thread_id = thread_id + InteractiveConsoleCache.frame_id = frame_id + + console_stacktrace = traceback.extract_stack(frame, limit=1) + if console_stacktrace: + current_context = console_stacktrace[0] # top entry from stacktrace + context_message = 'File "%s", line %s, in %s' % (current_context[0], current_context[1], current_context[2]) + console_message.add_console_message(CONSOLE_OUTPUT, "[Current context]: %s" % (context_message,)) + return InteractiveConsoleCache.interactive_console_instance + + +def clear_interactive_console(): + InteractiveConsoleCache.thread_id = None + InteractiveConsoleCache.frame_id = None + InteractiveConsoleCache.interactive_console_instance = None + + +def execute_console_command(frame, thread_id, frame_id, line, buffer_output=True): + """fetch an interactive console instance from the cache and + push the received command to the console. + + create and return an instance of console_message + """ + console_message = ConsoleMessage() + + interpreter = get_interactive_console(thread_id, frame_id, frame, console_message) + more, output_messages, error_messages = interpreter.push(line, frame, buffer_output) + console_message.update_more(more) + + for message in output_messages: + console_message.add_console_message(CONSOLE_OUTPUT, message) + + for message in error_messages: + console_message.add_console_message(CONSOLE_ERROR, message) + + return console_message + + +def get_description(frame, thread_id, frame_id, expression): + console_message = ConsoleMessage() + interpreter = get_interactive_console(thread_id, frame_id, frame, console_message) + try: + interpreter.frame = frame + return interpreter.getDescription(expression) + finally: + interpreter.frame = None + + +def get_completions(frame, act_tok): + """ fetch all completions, create xml for the same + return the completions xml + """ + return _pydev_completer.generate_completions_as_xml(frame, act_tok) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_constants.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_constants.py new file mode 100644 index 0000000..10298f5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_constants.py @@ -0,0 +1,564 @@ +''' +This module holds the constants used for specifying the states of the debugger. +''' +from __future__ import nested_scopes +import platform + +STATE_RUN = 1 +STATE_SUSPEND = 2 + +PYTHON_SUSPEND = 1 +DJANGO_SUSPEND = 2 +JINJA2_SUSPEND = 3 + +try: + int_types = (int, long) +except NameError: + int_types = (int,) + +import sys # Note: the sys import must be here anyways (others depend on it) + + +class DebugInfoHolder: + # we have to put it here because it can be set through the command line (so, the + # already imported references would not have it). + + # General information + DEBUG_TRACE_LEVEL = 0 # 0 = critical, 1 = info, 2 = debug, 3 = verbose + DEBUG_STREAM = sys.stderr + + # Flags to debug specific points of the code. + DEBUG_RECORD_SOCKET_READS = False + DEBUG_TRACE_BREAKPOINTS = -1 + + +IS_CPYTHON = platform.python_implementation() == 'CPython' + +# Hold a reference to the original _getframe (because psyco will change that as soon as it's imported) +IS_IRONPYTHON = sys.platform == 'cli' +try: + get_frame = sys._getframe + if IS_IRONPYTHON: + + def get_frame(): + try: + return sys._getframe() + except ValueError: + pass + +except AttributeError: + + def get_frame(): + raise AssertionError('sys._getframe not available (possible causes: enable -X:Frames on IronPython?)') + +# Used to determine the maximum size of each variable passed to eclipse -- having a big value here may make +# the communication slower -- as the variables are being gathered lazily in the latest version of eclipse, +# this value was raised from 200 to 1000. +MAXIMUM_VARIABLE_REPRESENTATION_SIZE = 1000 +# Prefix for saving functions return values in locals +RETURN_VALUES_DICT = '__pydevd_ret_val_dict' + +import os + +from _pydevd_bundle import pydevd_vm_type + +# Constant detects when running on Jython/windows properly later on. +IS_WINDOWS = sys.platform == 'win32' +IS_LINUX = sys.platform in ('linux', 'linux2') +IS_MAC = sys.platform == 'darwin' + +IS_64BIT_PROCESS = sys.maxsize > (2 ** 32) + +IS_JYTHON = pydevd_vm_type.get_vm_type() == pydevd_vm_type.PydevdVmType.JYTHON +IS_JYTH_LESS25 = False + +IS_PYPY = platform.python_implementation() == 'PyPy' + +if IS_JYTHON: + import java.lang.System # @UnresolvedImport + IS_WINDOWS = java.lang.System.getProperty("os.name").lower().startswith("windows") + if sys.version_info[0] == 2 and sys.version_info[1] < 5: + IS_JYTH_LESS25 = True + +USE_CUSTOM_SYS_CURRENT_FRAMES = not hasattr(sys, '_current_frames') or IS_PYPY +USE_CUSTOM_SYS_CURRENT_FRAMES_MAP = USE_CUSTOM_SYS_CURRENT_FRAMES and (IS_PYPY or IS_IRONPYTHON) + +IS_PYTHON_STACKLESS = "stackless" in sys.version.lower() +CYTHON_SUPPORTED = False + +try: + import platform + python_implementation = platform.python_implementation() +except: + pass +else: + if python_implementation == 'CPython' and not IS_PYTHON_STACKLESS: + # Only available for CPython! + if ( + (sys.version_info[0] == 2 and sys.version_info[1] >= 6) + or (sys.version_info[0] == 3 and sys.version_info[1] >= 3) + or (sys.version_info[0] > 3) + ): + # Supported in 2.6,2.7 or 3.3 onwards (32 or 64) + CYTHON_SUPPORTED = True + +#======================================================================================================================= +# Python 3? +#======================================================================================================================= +IS_PY3K = False +IS_PY34_OR_GREATER = False +IS_PY36_OR_GREATER = False +IS_PY37_OR_GREATER = False +IS_PY2 = True +IS_PY27 = False +IS_PY24 = False +try: + if sys.version_info[0] >= 3: + IS_PY3K = True + IS_PY2 = False + IS_PY34_OR_GREATER = sys.version_info >= (3, 4) + IS_PY36_OR_GREATER = sys.version_info >= (3, 6) + IS_PY37_OR_GREATER = sys.version_info >= (3, 7) + elif sys.version_info[0] == 2 and sys.version_info[1] == 7: + IS_PY27 = True + elif sys.version_info[0] == 2 and sys.version_info[1] == 4: + IS_PY24 = True +except AttributeError: + pass # Not all versions have sys.version_info + + +def version_str(v): + return '.'.join((str(x) for x in v[:3])) + ''.join((str(x) for x in v[3:])) + + +PY_VERSION_STR = version_str(sys.version_info) +try: + PY_IMPL_VERSION_STR = version_str(sys.implementation.version) +except AttributeError: + PY_IMPL_VERSION_STR = '' + +try: + PY_IMPL_NAME = sys.implementation.name +except AttributeError: + PY_IMPL_NAME = '' + +try: + SUPPORT_GEVENT = os.getenv('GEVENT_SUPPORT', 'False') == 'True' +except: + # Jython 2.1 doesn't accept that construct + SUPPORT_GEVENT = False + +# At the moment gevent supports Python >= 2.6 and Python >= 3.3 +USE_LIB_COPY = SUPPORT_GEVENT and \ + ((not IS_PY3K and sys.version_info[1] >= 6) or + (IS_PY3K and sys.version_info[1] >= 3)) + +INTERACTIVE_MODE_AVAILABLE = sys.platform in ('darwin', 'win32') or os.getenv('DISPLAY') is not None + +SHOW_COMPILE_CYTHON_COMMAND_LINE = os.getenv('PYDEVD_SHOW_COMPILE_CYTHON_COMMAND_LINE', 'False') == 'True' + +LOAD_VALUES_ASYNC = os.getenv('PYDEVD_LOAD_VALUES_ASYNC', 'False') == 'True' +DEFAULT_VALUE = "__pydevd_value_async" +ASYNC_EVAL_TIMEOUT_SEC = 60 +NEXT_VALUE_SEPARATOR = "__pydev_val__" +BUILTINS_MODULE_NAME = '__builtin__' if IS_PY2 else 'builtins' +SHOW_DEBUG_INFO_ENV = os.getenv('PYCHARM_DEBUG') == 'True' or os.getenv('PYDEV_DEBUG') == 'True' or os.getenv('PYDEVD_DEBUG') == 'True' +PYDEVD_DEBUG_FILE = os.getenv('PYDEVD_DEBUG_FILE') + +if SHOW_DEBUG_INFO_ENV: + # show debug info before the debugger start + DebugInfoHolder.DEBUG_RECORD_SOCKET_READS = True + DebugInfoHolder.DEBUG_TRACE_LEVEL = 3 + DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = 1 + + if PYDEVD_DEBUG_FILE: + DebugInfoHolder.DEBUG_STREAM = open(PYDEVD_DEBUG_FILE, 'w') + + +def protect_libraries_from_patching(): + """ + In this function we delete some modules from `sys.modules` dictionary and import them again inside + `_pydev_saved_modules` in order to save their original copies there. After that we can use these + saved modules within the debugger to protect them from patching by external libraries (e.g. gevent). + """ + patched = ['threading', 'thread', '_thread', 'time', 'socket', 'Queue', 'queue', 'select', + 'xmlrpclib', 'SimpleXMLRPCServer', 'BaseHTTPServer', 'SocketServer', + 'xmlrpc.client', 'xmlrpc.server', 'http.server', 'socketserver'] + + for name in patched: + try: + __import__(name) + except: + pass + + patched_modules = dict([(k, v) for k, v in sys.modules.items() + if k in patched]) + + for name in patched_modules: + del sys.modules[name] + + # import for side effects + import _pydev_imps._pydev_saved_modules + + for name in patched_modules: + sys.modules[name] = patched_modules[name] + + +if USE_LIB_COPY: + protect_libraries_from_patching() + +from _pydev_imps._pydev_saved_modules import thread +_thread_id_lock = thread.allocate_lock() +thread_get_ident = thread.get_ident + +if IS_PY3K: + + def dict_keys(d): + return list(d.keys()) + + def dict_values(d): + return list(d.values()) + + dict_iter_values = dict.values + + def dict_iter_items(d): + return d.items() + + def dict_items(d): + return list(d.items()) + +else: + dict_keys = None + try: + dict_keys = dict.keys + except: + pass + + if IS_JYTHON or not dict_keys: + + def dict_keys(d): + return d.keys() + + try: + dict_iter_values = dict.itervalues + except: + try: + dict_iter_values = dict.values # Older versions don't have the itervalues + except: + + def dict_iter_values(d): + return d.values() + + try: + dict_values = dict.values + except: + + def dict_values(d): + return d.values() + + def dict_iter_items(d): + try: + return d.iteritems() + except: + return d.items() + + def dict_items(d): + return d.items() + +try: + xrange = xrange +except: + # Python 3k does not have it + xrange = range + +try: + import itertools + izip = itertools.izip +except: + izip = zip + +try: + from StringIO import StringIO +except: + from io import StringIO + +if IS_JYTHON: + + def NO_FTRACE(frame, event, arg): + return None + +else: + _curr_trace = sys.gettrace() + + # Set a temporary trace which does nothing for us to test (otherwise setting frame.f_trace has no + # effect). + def _temp_trace(frame, event, arg): + return None + + sys.settrace(_temp_trace) + + def _check_ftrace_set_none(): + ''' + Will throw an error when executing a line event + ''' + sys._getframe().f_trace = None + _line_event = 1 + _line_event = 2 + + try: + _check_ftrace_set_none() + + def NO_FTRACE(frame, event, arg): + frame.f_trace = None + return None + + except TypeError: + + def NO_FTRACE(frame, event, arg): + # In Python <= 2.6 and <= 3.4, if we're tracing a method, frame.f_trace may not be set + # to None, it must always be set to a tracing function. + # See: tests_python.test_tracing_gotchas.test_tracing_gotchas + # + # Note: Python 2.7 sometimes works and sometimes it doesn't depending on the minor + # version because of https://bugs.python.org/issue20041 (although bug reports didn't + # include the minor version, so, mark for any Python 2.7 as I'm not completely sure + # the fix in later 2.7 versions is the same one we're dealing with). + return None + + sys.settrace(None) + + +#======================================================================================================================= +# get_pid +#======================================================================================================================= +def get_pid(): + try: + return os.getpid() + except AttributeError: + try: + # Jython does not have it! + import java.lang.management.ManagementFactory # @UnresolvedImport -- just for jython + pid = java.lang.management.ManagementFactory.getRuntimeMXBean().getName() + return pid.replace('@', '_') + except: + # ok, no pid available (will be unable to debug multiple processes) + return '000001' + + +def clear_cached_thread_id(thread): + with _thread_id_lock: + try: + if thread.__pydevd_id__ != 'console_main': + # The console_main is a special thread id used in the console and its id should never be reset + # (otherwise we may no longer be able to get its variables -- see: https://www.brainwy.com/tracker/PyDev/776). + del thread.__pydevd_id__ + except AttributeError: + pass + + +# Don't let threads be collected (so that id(thread) is guaranteed to be unique). +_thread_id_to_thread_found = {} + + +def _get_or_compute_thread_id_with_lock(thread, is_current_thread): + with _thread_id_lock: + # We do a new check with the lock in place just to be sure that nothing changed + tid = getattr(thread, '__pydevd_id__', None) + if tid is not None: + return tid + + _thread_id_to_thread_found[id(thread)] = thread + + # Note: don't use thread.ident because a new thread may have the + # same id from an old thread. + pid = get_pid() + tid = 'pid_%s_id_%s' % (pid, id(thread)) + + thread.__pydevd_id__ = tid + + return tid + + +def get_current_thread_id(thread): + ''' + Note: the difference from get_current_thread_id to get_thread_id is that + for the current thread we can get the thread id while the thread.ident + is still not set in the Thread instance. + ''' + try: + # Fast path without getting lock. + tid = thread.__pydevd_id__ + if tid is None: + # Fix for https://www.brainwy.com/tracker/PyDev/645 + # if __pydevd_id__ is None, recalculate it... also, use an heuristic + # that gives us always the same id for the thread (using thread.ident or id(thread)). + raise AttributeError() + except AttributeError: + tid = _get_or_compute_thread_id_with_lock(thread, is_current_thread=True) + + return tid + + +def get_thread_id(thread): + try: + # Fast path without getting lock. + tid = thread.__pydevd_id__ + if tid is None: + # Fix for https://www.brainwy.com/tracker/PyDev/645 + # if __pydevd_id__ is None, recalculate it... also, use an heuristic + # that gives us always the same id for the thread (using thread.ident or id(thread)). + raise AttributeError() + except AttributeError: + tid = _get_or_compute_thread_id_with_lock(thread, is_current_thread=False) + + return tid + + +def set_thread_id(thread, thread_id): + with _thread_id_lock: + thread.__pydevd_id__ = thread_id + + +#======================================================================================================================= +# Null +#======================================================================================================================= +class Null: + """ + Gotten from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68205 + """ + + def __init__(self, *args, **kwargs): + return None + + def __call__(self, *args, **kwargs): + return self + + def __enter__(self, *args, **kwargs): + return self + + def __exit__(self, *args, **kwargs): + return self + + def __getattr__(self, mname): + if len(mname) > 4 and mname[:2] == '__' and mname[-2:] == '__': + # Don't pretend to implement special method names. + raise AttributeError(mname) + return self + + def __setattr__(self, name, value): + return self + + def __delattr__(self, name): + return self + + def __repr__(self): + return "" + + def __str__(self): + return "Null" + + def __len__(self): + return 0 + + def __getitem__(self): + return self + + def __setitem__(self, *args, **kwargs): + pass + + def write(self, *args, **kwargs): + pass + + def __nonzero__(self): + return 0 + + def __iter__(self): + return iter(()) + + +# Default instance +NULL = Null() + + +def call_only_once(func): + ''' + To be used as a decorator + + @call_only_once + def func(): + print 'Calling func only this time' + + Actually, in PyDev it must be called as: + + func = call_only_once(func) to support older versions of Python. + ''' + + def new_func(*args, **kwargs): + if not new_func._called: + new_func._called = True + return func(*args, **kwargs) + + new_func._called = False + return new_func + + +# Protocol where each line is a new message (text is quoted to prevent new lines). +# payload is xml +QUOTED_LINE_PROTOCOL = 'quoted-line' + +# Uses http protocol to provide a new message. +# i.e.: Content-Length:xxx\r\n\r\npayload +# payload is xml +HTTP_PROTOCOL = 'http' + +# Message is sent without any header. +# payload is json +JSON_PROTOCOL = 'json' + +# Same header as the HTTP_PROTOCOL +# payload is json +HTTP_JSON_PROTOCOL = 'http_json' + + +class _GlobalSettings: + protocol = QUOTED_LINE_PROTOCOL + + +def set_protocol(protocol): + expected = (HTTP_PROTOCOL, QUOTED_LINE_PROTOCOL, JSON_PROTOCOL, HTTP_JSON_PROTOCOL) + assert protocol in expected, 'Protocol (%s) should be one of: %s' % ( + protocol, expected) + + _GlobalSettings.protocol = protocol + + +def get_protocol(): + return _GlobalSettings.protocol + + +def is_json_protocol(): + return _GlobalSettings.protocol in (JSON_PROTOCOL, HTTP_JSON_PROTOCOL) + + +class GlobalDebuggerHolder: + ''' + Holder for the global debugger. + ''' + global_dbg = None # Note: don't rename (the name is used in our attach to process) + + +def get_global_debugger(): + return GlobalDebuggerHolder.global_dbg + + +GetGlobalDebugger = get_global_debugger # Backward-compatibility + + +def set_global_debugger(dbg): + GlobalDebuggerHolder.global_dbg = dbg + + +if __name__ == '__main__': + if Null(): + sys.stdout.write('here\n') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_custom_frames.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_custom_frames.py new file mode 100644 index 0000000..1c929b1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_custom_frames.py @@ -0,0 +1,116 @@ +from _pydevd_bundle.pydevd_constants import get_current_thread_id, Null +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame +from _pydev_imps._pydev_saved_modules import thread, threading +import sys +from _pydev_bundle import pydev_log + +DEBUG = False + + +class CustomFramesContainer: + + # Actual Values initialized later on. + custom_frames_lock = None # : :type custom_frames_lock: threading.Lock + + custom_frames = None + + _next_frame_id = None + + _py_db_command_thread_event = None + + +def custom_frames_container_init(): # Note: no staticmethod on jython 2.1 (so, use free-function) + + CustomFramesContainer.custom_frames_lock = thread.allocate_lock() + + # custom_frames can only be accessed if properly locked with custom_frames_lock! + # Key is a string identifying the frame (as well as the thread it belongs to). + # Value is a CustomFrame. + # + CustomFramesContainer.custom_frames = {} + + # Only to be used in this module + CustomFramesContainer._next_frame_id = 0 + + # This is the event we must set to release an internal process events. It's later set by the actual debugger + # when we do create the debugger. + CustomFramesContainer._py_db_command_thread_event = Null() + + +# Initialize it the first time (it may be reinitialized later on when dealing with a fork). +custom_frames_container_init() + + +class CustomFrame: + + def __init__(self, name, frame, thread_id): + # 0 = string with the representation of that frame + self.name = name + + # 1 = the frame to show + self.frame = frame + + # 2 = an integer identifying the last time the frame was changed. + self.mod_time = 0 + + # 3 = the thread id of the given frame + self.thread_id = thread_id + + +def add_custom_frame(frame, name, thread_id): + ''' + It's possible to show paused frames by adding a custom frame through this API (it's + intended to be used for coroutines, but could potentially be used for generators too). + + :param frame: + The topmost frame to be shown paused when a thread with thread.ident == thread_id is paused. + + :param name: + The name to be shown for the custom thread in the UI. + + :param thread_id: + The thread id to which this frame is related (must match thread.ident). + + :return: str + Returns the custom thread id which will be used to show the given frame paused. + ''' + with CustomFramesContainer.custom_frames_lock: + curr_thread_id = get_current_thread_id(threading.currentThread()) + next_id = CustomFramesContainer._next_frame_id = CustomFramesContainer._next_frame_id + 1 + + # Note: the frame id kept contains an id and thread information on the thread where the frame was added + # so that later on we can check if the frame is from the current thread by doing frame_id.endswith('|'+thread_id). + frame_custom_thread_id = '__frame__:%s|%s' % (next_id, curr_thread_id) + if DEBUG: + sys.stderr.write('add_custom_frame: %s (%s) %s %s\n' % ( + frame_custom_thread_id, get_abs_path_real_path_and_base_from_frame(frame)[-1], frame.f_lineno, frame.f_code.co_name)) + + CustomFramesContainer.custom_frames[frame_custom_thread_id] = CustomFrame(name, frame, thread_id) + CustomFramesContainer._py_db_command_thread_event.set() + return frame_custom_thread_id + + +def update_custom_frame(frame_custom_thread_id, frame, thread_id, name=None): + with CustomFramesContainer.custom_frames_lock: + if DEBUG: + sys.stderr.write('update_custom_frame: %s\n' % frame_custom_thread_id) + try: + old = CustomFramesContainer.custom_frames[frame_custom_thread_id] + if name is not None: + old.name = name + old.mod_time += 1 + old.thread_id = thread_id + except: + sys.stderr.write('Unable to get frame to replace: %s\n' % (frame_custom_thread_id,)) + pydev_log.exception() + + CustomFramesContainer._py_db_command_thread_event.set() + + +def remove_custom_frame(frame_custom_thread_id): + with CustomFramesContainer.custom_frames_lock: + if DEBUG: + sys.stderr.write('remove_custom_frame: %s\n' % frame_custom_thread_id) + CustomFramesContainer.custom_frames.pop(frame_custom_thread_id, None) + CustomFramesContainer._py_db_command_thread_event.set() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.c b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.c new file mode 100644 index 0000000..74e7467 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.c @@ -0,0 +1,37383 @@ +/* Generated by Cython 0.29.8 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "depends": [], + "name": "_pydevd_bundle.pydevd_cython", + "sources": [ + "_pydevd_bundle/pydevd_cython.pyx" + ] + }, + "module_name": "_pydevd_bundle.pydevd_cython" +} +END: Cython Metadata */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.6+ or Python 3.3+. +#else +#define CYTHON_ABI "0_29_8" +#define CYTHON_HEX_VERSION 0x001D08F0 +#define CYTHON_FUTURE_DIVISION 0 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x02070000 + #define HAVE_LONG_LONG + #endif +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#ifdef PYPY_VERSION + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int32 uint32_t; + #endif + #endif +#else + #include +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) && __cplusplus >= 201103L + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #elif __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__ ) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) + #define Py_OptimizeFlag 0 +#endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#if PY_VERSION_HEX < 0x030800A4 + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif + #define __Pyx_DefaultClassType PyType_Type +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast + #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +#else +#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) +#endif +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact + #define PyObject_Unicode PyObject_Str +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) +#else + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func)) +#else + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + + +#define __PYX_ERR(f_index, lineno, Ln_error) \ +{ \ + __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ +} + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE___pydevd_bundle__pydevd_cython +#define __PYX_HAVE_API___pydevd_bundle__pydevd_cython +/* Early includes */ +#include +#include +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { + const Py_UNICODE *u_end = u; + while (*u_end++) ; + return (size_t)(u_end - u - 1); +} +#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) +#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +static PyObject *__pyx_m = NULL; +static PyObject *__pyx_d; +static PyObject *__pyx_b; +static PyObject *__pyx_cython_runtime = NULL; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "_pydevd_bundle\\pydevd_cython.pyx", + "_pydevd_bundle\\pydevd_cython.pxd", + "stringsource", + "type.pxd", +}; + +/*--- Type declarations ---*/ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo; +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame; +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper; +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions; +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame; +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer; + +/* "_pydevd_bundle/pydevd_cython.pxd":1 + * cdef class PyDBAdditionalThreadInfo: # <<<<<<<<<<<<<< + * cdef public int pydev_state; + * cdef public object pydev_step_stop; # Actually, it's a frame or None + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo { + PyObject_HEAD + int pydev_state; + PyObject *pydev_step_stop; + int pydev_original_step_cmd; + int pydev_step_cmd; + int pydev_notify_kill; + PyObject *pydev_smart_step_stop; + int pydev_django_resolve_frame; + PyObject *pydev_call_from_jinja2; + PyObject *pydev_call_inside_jinja2; + int is_tracing; + PyObject *conditional_breakpoint_exception; + PyObject *pydev_message; + int suspend_type; + int pydev_next_line; + PyObject *pydev_func_name; + int suspended_at_unhandled; + PyObject *trace_suspend_type; + PyObject *top_level_thread_tracer_no_back_frames; + PyObject *top_level_thread_tracer_unhandled; + PyObject *thread_tracer; +}; + + +/* "_pydevd_bundle/pydevd_cython.pyx":213 + * #======================================================================================================================= + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class PyDBFrame: # <<<<<<<<<<<<<< + * # ELSE + * # class PyDBFrame: + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame { + PyObject_HEAD + struct __pyx_vtabstruct_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_vtab; + PyObject *_args; + int should_skip; +}; + + +/* "_pydevd_bundle/pydevd_cython.pyx":964 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class SafeCallWrapper: # <<<<<<<<<<<<<< + * cdef method_object + * def __init__(self, method_object): + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper { + PyObject_HEAD + PyObject *method_object; +}; + + +/* "_pydevd_bundle/pydevd_cython.pyx":1117 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class TopLevelThreadTracerOnlyUnhandledExceptions: # <<<<<<<<<<<<<< + * cdef public tuple _args; + * def __init__(self, tuple args): + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions { + PyObject_HEAD + PyObject *_args; +}; + + +/* "_pydevd_bundle/pydevd_cython.pyx":1147 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class TopLevelThreadTracerNoBackFrame: # <<<<<<<<<<<<<< + * cdef public object _frame_trace_dispatch; + * cdef public tuple _args; + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame { + PyObject_HEAD + PyObject *_frame_trace_dispatch; + PyObject *_args; + PyObject *_try_except_info; + PyObject *_last_exc_arg; + PyObject *_raise_lines; + int _last_raise_line; +}; + + +/* "_pydevd_bundle/pydevd_cython.pyx":1256 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class ThreadTracer: # <<<<<<<<<<<<<< + * cdef public tuple _args; + * def __init__(self, tuple args): + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer { + PyObject_HEAD + PyObject *_args; +}; + + + +/* "_pydevd_bundle/pydevd_cython.pyx":213 + * #======================================================================================================================= + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class PyDBFrame: # <<<<<<<<<<<<<< + * # ELSE + * # class PyDBFrame: + */ + +struct __pyx_vtabstruct_14_pydevd_bundle_13pydevd_cython_PyDBFrame { + PyObject *(*trace_dispatch)(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch); +}; +static struct __pyx_vtabstruct_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_vtabptr_14_pydevd_bundle_13pydevd_cython_PyDBFrame; + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectCallNoArg.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); +#else +#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) +#endif + +/* PyCFunctionFastCall.proto */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); +#else +#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) +#endif + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); + +/* PyObjectCall2Args.proto */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* GetAttr3.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* PyObjectLookupSpecial.proto */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) { + PyObject *res; + PyTypeObject *tp = Py_TYPE(obj); +#if PY_MAJOR_VERSION < 3 + if (unlikely(PyInstance_Check(obj))) + return __Pyx_PyObject_GetAttrStr(obj, attr_name); +#endif + res = _PyType_Lookup(tp, attr_name); + if (likely(res)) { + descrgetfunc f = Py_TYPE(res)->tp_descr_get; + if (!f) { + Py_INCREF(res); + } else { + res = f(res, obj, (PyObject *)tp); + } + } else { + PyErr_SetObject(PyExc_AttributeError, attr_name); + } + return res; +} +#else +#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) +#endif + +/* PyObjectSetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); +#else +#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) +#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) +#endif + +/* None.proto */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ + const char* function_name); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + +/* RaiseTooManyValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +/* RaiseNeedMoreValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +/* IterFinish.proto */ +static CYTHON_INLINE int __Pyx_IterFinish(void); + +/* UnpackItemEndCheck.proto */ +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); + +/* ExtTypeTest.proto */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); + +/* HasAttr.proto */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); + +/* PySequenceContains.proto */ +static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { + int result = PySequence_Contains(seq, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* RaiseNoneIterError.proto */ +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_AndObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceAnd(op1, op2) : PyNumber_And(op1, op2)) +#endif + +/* dict_getitem_default.proto */ +static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); + +/* UnpackUnboundCMethod.proto */ +typedef struct { + PyObject *type; + PyObject **method_name; + PyCFunction func; + PyObject *method; + int flag; +} __Pyx_CachedCFunction; + +/* CallUnboundCMethod1.proto */ +static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); +#else +#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg) +#endif + +/* CallUnboundCMethod2.proto */ +static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1 +static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2); +#else +#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2) __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2) +#endif + +/* PyDictContains.proto */ +static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { + int result = PyDict_Contains(dict, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* DictGetItem.proto */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); +#define __Pyx_PyObject_Dict_GetItem(obj, name)\ + (likely(PyDict_CheckExact(obj)) ?\ + __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) +#else +#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) +#endif + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + +/* ListAppend.proto */ +#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod1.proto */ +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); + +/* append.proto */ +static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); + +/* SliceTupleAndList.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop); +#else +#define __Pyx_PyList_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop) +#define __Pyx_PyTuple_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop) +#endif + +/* pyfrozenset_new.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it); + +/* PySetContains.proto */ +static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); + +/* PyIntCompare.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); + +/* ObjectGetItem.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key); +#else +#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key) +#endif + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PyObject_GenericGetAttr.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr +#endif + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* SetVTable.proto */ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); + +/* TypeImport.proto */ +#ifndef __PYX_HAVE_RT_ImportType_proto +#define __PYX_HAVE_RT_ImportType_proto +enum __Pyx_ImportType_CheckSize { + __Pyx_ImportType_CheckSize_Error = 0, + __Pyx_ImportType_CheckSize_Warn = 1, + __Pyx_ImportType_CheckSize_Ignore = 2 +}; +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +#endif + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* PatchModuleWithCoroutine.proto */ +static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code); + +/* PatchInspect.proto */ +static PyObject* __Pyx_patch_inspect(PyObject* module); + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_trace_dispatch(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg, int __pyx_skip_dispatch); /* proto*/ + +/* Module declarations from 'libc.string' */ + +/* Module declarations from 'libc.stdio' */ + +/* Module declarations from '__builtin__' */ + +/* Module declarations from 'cpython.type' */ +static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; + +/* Module declarations from 'cpython' */ + +/* Module declarations from 'cpython.object' */ + +/* Module declarations from 'cpython.ref' */ + +/* Module declarations from '_pydevd_bundle.pydevd_cython' */ +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo = 0; +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame = 0; +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper = 0; +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions = 0; +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame = 0; +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer = 0; +static PyObject *__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in = 0; +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBAdditionalThreadInfo__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *, PyObject *); /*proto*/ +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBFrame__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *, PyObject *); /*proto*/ +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_SafeCallWrapper__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *, PyObject *); /*proto*/ +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *, PyObject *); /*proto*/ +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *, PyObject *); /*proto*/ +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_ThreadTracer__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *, PyObject *); /*proto*/ +#define __Pyx_MODULE_NAME "_pydevd_bundle.pydevd_cython" +extern int __pyx_module_is_main__pydevd_bundle__pydevd_cython; +int __pyx_module_is_main__pydevd_bundle__pydevd_cython = 0; + +/* Implementation of '_pydevd_bundle.pydevd_cython' */ +static PyObject *__pyx_builtin_RuntimeError; +static PyObject *__pyx_builtin_ImportError; +static PyObject *__pyx_builtin_AttributeError; +static PyObject *__pyx_builtin_SystemExit; +static PyObject *__pyx_builtin_id; +static PyObject *__pyx_builtin_StopIteration; +static PyObject *__pyx_builtin_GeneratorExit; +static PyObject *__pyx_builtin_KeyboardInterrupt; +static const char __pyx_k_[] = ""; +static const char __pyx_k_1[] = "1"; +static const char __pyx_k_i[] = "i"; +static const char __pyx_k_j[] = "j"; +static const char __pyx_k_t[] = "t"; +static const char __pyx_k__3[] = "?"; +static const char __pyx_k__4[] = "/"; +static const char __pyx_k__5[] = "\\"; +static const char __pyx_k__6[] = "."; +static const char __pyx_k_id[] = "id"; +static const char __pyx_k_os[] = "os"; +static const char __pyx_k_re[] = "re"; +static const char __pyx_k_ALL[] = "ALL"; +static const char __pyx_k_arg[] = "arg"; +static const char __pyx_k_get[] = "get"; +static const char __pyx_k_new[] = "__new__"; +static const char __pyx_k_pop[] = "pop"; +static const char __pyx_k_ret[] = "ret"; +static const char __pyx_k_run[] = "run"; +static const char __pyx_k_s_s[] = "%s.%s"; +static const char __pyx_k_sys[] = "sys"; +static const char __pyx_k_Lock[] = "Lock"; +static const char __pyx_k_None[] = "None"; +static const char __pyx_k_args[] = "args"; +static const char __pyx_k_call[] = "call"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_exec[] = "_exec"; +static const char __pyx_k_exit[] = "__exit__"; +static const char __pyx_k_line[] = "line"; +static const char __pyx_k_main[] = "main"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_path[] = "path"; +static const char __pyx_k_self[] = "self"; +static const char __pyx_k_stat[] = "stat"; +static const char __pyx_k_stop[] = "stop"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_clear[] = "clear"; +static const char __pyx_k_debug[] = "debug"; +static const char __pyx_k_enter[] = "__enter__"; +static const char __pyx_k_event[] = "event"; +static const char __pyx_k_frame[] = "frame"; +static const char __pyx_k_getId[] = "getId"; +static const char __pyx_k_ident[] = "ident"; +static const char __pyx_k_match[] = "match"; +static const char __pyx_k_py_db[] = "py_db"; +static const char __pyx_k_qname[] = "qname"; +static const char __pyx_k_rfind[] = "rfind"; +static const char __pyx_k_trace[] = "trace"; +static const char __pyx_k_utf_8[] = "utf-8"; +static const char __pyx_k_Thread[] = "Thread"; +static const char __pyx_k_append[] = "append"; +static const char __pyx_k_args_2[] = "_args"; +static const char __pyx_k_call_2[] = "__call__"; +static const char __pyx_k_encode[] = "encode"; +static const char __pyx_k_f_back[] = "f_back"; +static const char __pyx_k_f_code[] = "f_code"; +static const char __pyx_k_getKey[] = "getKey"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_kwargs[] = "kwargs"; +static const char __pyx_k_lambda[] = ""; +static const char __pyx_k_main_2[] = "__main__"; +static const char __pyx_k_module[] = ""; +static const char __pyx_k_name_2[] = "name"; +static const char __pyx_k_pickle[] = "pickle"; +static const char __pyx_k_plugin[] = "plugin"; +static const char __pyx_k_pydevd[] = "pydevd"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_return[] = "return"; +static const char __pyx_k_thread[] = "thread"; +static const char __pyx_k_update[] = "update"; +static const char __pyx_k_writer[] = "writer"; +static const char __pyx_k_IS_PY3K[] = "IS_PY3K"; +static const char __pyx_k_co_name[] = "co_name"; +static const char __pyx_k_compile[] = "compile"; +static const char __pyx_k_f_trace[] = "f_trace"; +static const char __pyx_k_getline[] = "getline"; +static const char __pyx_k_inspect[] = "inspect"; +static const char __pyx_k_invalid[] = ".invalid."; +static const char __pyx_k_linesep[] = "linesep"; +static const char __pyx_k_os_path[] = "os.path"; +static const char __pyx_k_st_size[] = "st_size"; +static const char __pyx_k_suspend[] = "suspend"; +static const char __pyx_k_tb_next[] = "tb_next"; +static const char __pyx_k_toArray[] = "toArray"; +static const char __pyx_k_version[] = "version"; +static const char __pyx_k_as_array[] = "as_array"; +static const char __pyx_k_basename[] = "basename"; +static const char __pyx_k_can_skip[] = "can_skip"; +static const char __pyx_k_co_flags[] = "co_flags"; +static const char __pyx_k_entrySet[] = "entrySet"; +static const char __pyx_k_execfile[] = "execfile"; +static const char __pyx_k_f_lineno[] = "f_lineno"; +static const char __pyx_k_f_locals[] = "f_locals"; +static const char __pyx_k_filename[] = "filename"; +static const char __pyx_k_getValue[] = "getValue"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_quitting[] = "quitting"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_st_mtime[] = "st_mtime"; +static const char __pyx_k_tb_frame[] = "tb_frame"; +static const char __pyx_k_IS_JYTHON[] = "IS_JYTHON"; +static const char __pyx_k_NO_FTRACE[] = "NO_FTRACE"; +static const char __pyx_k_PyDBFrame[] = "PyDBFrame"; +static const char __pyx_k_STATE_RUN[] = "STATE_RUN"; +static const char __pyx_k_bootstrap[] = "__bootstrap"; +static const char __pyx_k_condition[] = "condition"; +static const char __pyx_k_exception[] = "exception"; +static const char __pyx_k_f_globals[] = "f_globals"; +static const char __pyx_k_func_name[] = "func_name"; +static const char __pyx_k_java_lang[] = "java.lang"; +static const char __pyx_k_linecache[] = "linecache"; +static const char __pyx_k_log_event[] = "log_event"; +static const char __pyx_k_pydev_log[] = "pydev_log"; +static const char __pyx_k_pydevd_py[] = "pydevd.py"; +static const char __pyx_k_pyx_state[] = "__pyx_state"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_tb_lineno[] = "tb_lineno"; +static const char __pyx_k_threading[] = "threading"; +static const char __pyx_k_PYDEV_FILE[] = "PYDEV_FILE"; +static const char __pyx_k_SystemExit[] = "SystemExit"; +static const char __pyx_k_accessible[] = "accessible"; +static const char __pyx_k_checkcache[] = "checkcache"; +static const char __pyx_k_expression[] = "expression"; +static const char __pyx_k_pyx_result[] = "__pyx_result"; +static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; +static const char __pyx_k_DEBUG_START[] = "DEBUG_START"; +static const char __pyx_k_ImportError[] = "ImportError"; +static const char __pyx_k_PickleError[] = "PickleError"; +static const char __pyx_k_add_command[] = "add_command"; +static const char __pyx_k_bootstrap_2[] = "_bootstrap"; +static const char __pyx_k_breakpoints[] = "breakpoints"; +static const char __pyx_k_cmd_factory[] = "cmd_factory"; +static const char __pyx_k_co_filename[] = "co_filename"; +static const char __pyx_k_except_line[] = "except_line"; +static const char __pyx_k_f_unhandled[] = "f_unhandled"; +static const char __pyx_k_is_logpoint[] = "is_logpoint"; +static const char __pyx_k_just_raised[] = "just_raised"; +static const char __pyx_k_set_suspend[] = "set_suspend"; +static const char __pyx_k_CO_GENERATOR[] = "CO_GENERATOR"; +static const char __pyx_k_RuntimeError[] = "RuntimeError"; +static const char __pyx_k_ThreadTracer[] = "ThreadTracer"; +static const char __pyx_k_pydev_bundle[] = "_pydev_bundle"; +static const char __pyx_k_pydev_monkey[] = "pydev_monkey"; +static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; +static const char __pyx_k_stringsource[] = "stringsource"; +static const char __pyx_k_thread_state[] = "thread_state"; +static const char __pyx_k_trace_return[] = "trace_return"; +static const char __pyx_k_GeneratorExit[] = "GeneratorExit"; +static const char __pyx_k_StopIteration[] = "StopIteration"; +static const char __pyx_k_cmd_step_into[] = "cmd_step_into"; +static const char __pyx_k_cmd_step_over[] = "cmd_step_over"; +static const char __pyx_k_get_file_type[] = "get_file_type"; +static const char __pyx_k_get_func_name[] = "get_func_name"; +static const char __pyx_k_has_condition[] = "has_condition"; +static const char __pyx_k_main_debugger[] = "main_debugger"; +static const char __pyx_k_method_object[] = "method_object"; +static const char __pyx_k_original_call[] = "_original_call"; +static const char __pyx_k_pydevd_bundle[] = "_pydevd_bundle"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_thread_states[] = "thread_states"; +static const char __pyx_k_thread_tracer[] = "thread_tracer"; +static const char __pyx_k_AttributeError[] = "AttributeError"; +static const char __pyx_k_PYTHON_SUSPEND[] = "PYTHON_SUSPEND"; +static const char __pyx_k_TRACE_PROPERTY[] = "TRACE_PROPERTY"; +static const char __pyx_k_co_firstlineno[] = "co_firstlineno"; +static const char __pyx_k_current_frames[] = "_current_frames"; +static const char __pyx_k_enable_tracing[] = "enable_tracing"; +static const char __pyx_k_get_breakpoint[] = "get_breakpoint"; +static const char __pyx_k_suspend_policy[] = "suspend_policy"; +static const char __pyx_k_trace_dispatch[] = "trace_dispatch"; +static const char __pyx_k_IgnoreException[] = "[^#]*#.*@IgnoreException"; +static const char __pyx_k_SafeCallWrapper[] = "SafeCallWrapper"; +static const char __pyx_k_additional_info[] = "additional_info"; +static const char __pyx_k_bootstrap_inner[] = "__bootstrap_inner"; +static const char __pyx_k_disable_tracing[] = "disable_tracing"; +static const char __pyx_k_do_wait_suspend[] = "do_wait_suspend"; +static const char __pyx_k_exception_break[] = "exception_break"; +static const char __pyx_k_is_thread_alive[] = "is_thread_alive"; +static const char __pyx_k_make_io_message[] = "make_io_message"; +static const char __pyx_k_org_python_core[] = "org.python.core"; +static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_thread_analyser[] = "thread_analyser"; +static const char __pyx_k_thread_to_state[] = "thread_to_state"; +static const char __pyx_k_trace_exception[] = "trace_exception"; +static const char __pyx_k_DEBUG_START_PY3K[] = "DEBUG_START_PY3K"; +static const char __pyx_k_asyncio_analyser[] = "asyncio_analyser"; +static const char __pyx_k_dict_iter_values[] = "dict_iter_values"; +static const char __pyx_k_getDeclaredField[] = "getDeclaredField"; +static const char __pyx_k_handle_exception[] = "handle_exception"; +static const char __pyx_k_in_project_scope[] = "in_project_scope"; +static const char __pyx_k_threading_active[] = "threading_active"; +static const char __pyx_k_KeyboardInterrupt[] = "KeyboardInterrupt"; +static const char __pyx_k_apply_to_settrace[] = "apply_to_settrace"; +static const char __pyx_k_bootstrap_inner_2[] = "_bootstrap_inner"; +static const char __pyx_k_cachedThreadState[] = "cachedThreadState"; +static const char __pyx_k_pydev_execfile_py[] = "_pydev_execfile.py"; +static const char __pyx_k_pydevd_dont_trace[] = "pydevd_dont_trace"; +static const char __pyx_k_pydevd_file_utils[] = "pydevd_file_utils"; +static const char __pyx_k_should_trace_hook[] = "should_trace_hook"; +static const char __pyx_k_signature_factory[] = "signature_factory"; +static const char __pyx_k_thread_trace_func[] = "thread_trace_func"; +static const char __pyx_k_tid_to_last_frame[] = "_tid_to_last_frame"; +static const char __pyx_k_RETURN_VALUES_DICT[] = "RETURN_VALUES_DICT"; +static const char __pyx_k_ThreadStateMapping[] = "ThreadStateMapping"; +static const char __pyx_k_apply_files_filter[] = "apply_files_filter"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_globalThreadStates[] = "globalThreadStates"; +static const char __pyx_k_global_cache_skips[] = "global_cache_skips"; +static const char __pyx_k_pydev_do_not_trace[] = "pydev_do_not_trace"; +static const char __pyx_k_show_return_values[] = "show_return_values"; +static const char __pyx_k_pydev_log_exception[] = "pydev_log_exception"; +static const char __pyx_k_threading_get_ident[] = "threading_get_ident"; +static const char __pyx_k_IGNORE_EXCEPTION_TAG[] = "IGNORE_EXCEPTION_TAG"; +static const char __pyx_k_NoSuchFieldException[] = "NoSuchFieldException"; +static const char __pyx_k_frame_trace_dispatch[] = "frame_trace_dispatch"; +static const char __pyx_k_get_clsname_for_code[] = "get_clsname_for_code"; +static const char __pyx_k_is_line_in_try_block[] = "is_line_in_try_block"; +static const char __pyx_k_remove_return_values[] = "remove_return_values"; +static const char __pyx_k_Using_Cython_speedups[] = "Using Cython speedups"; +static const char __pyx_k_filename_to_stat_info[] = "filename_to_stat_info"; +static const char __pyx_k_get_current_thread_id[] = "get_current_thread_id"; +static const char __pyx_k_output_checker_thread[] = "output_checker_thread"; +static const char __pyx_k_raise_lines_in_except[] = "raise_lines_in_except"; +static const char __pyx_k_suspend_other_threads[] = "suspend_other_threads"; +static const char __pyx_k_termination_event_set[] = "_termination_event_set"; +static const char __pyx_k_add_exception_to_frame[] = "add_exception_to_frame"; +static const char __pyx_k_has_plugin_line_breaks[] = "has_plugin_line_breaks"; +static const char __pyx_k_ignore_exception_trace[] = "ignore_exception_trace"; +static const char __pyx_k_kill_all_pydev_threads[] = "kill_all_pydev_threads"; +static const char __pyx_k_pydev_bundle_pydev_log[] = "_pydev_bundle.pydev_log"; +static const char __pyx_k_pyx_unpickle_PyDBFrame[] = "__pyx_unpickle_PyDBFrame"; +static const char __pyx_k_suspended_at_unhandled[] = "suspended_at_unhandled"; +static const char __pyx_k_collect_try_except_info[] = "collect_try_except_info"; +static const char __pyx_k_get_trace_dispatch_func[] = "get_trace_dispatch_func"; +static const char __pyx_k_ignore_system_exit_code[] = "ignore_system_exit_code"; +static const char __pyx_k_is_files_filter_enabled[] = "is_files_filter_enabled"; +static const char __pyx_k_is_line_in_except_block[] = "is_line_in_except_block"; +static const char __pyx_k_notify_thread_not_alive[] = "notify_thread_not_alive"; +static const char __pyx_k_pydevd_traceproperty_py[] = "pydevd_traceproperty.py"; +static const char __pyx_k_top_level_thread_tracer[] = "top_level_thread_tracer"; +static const char __pyx_k_PyDBAdditionalThreadInfo[] = "PyDBAdditionalThreadInfo"; +static const char __pyx_k_finish_debugging_session[] = "_finish_debugging_session"; +static const char __pyx_k_get_exception_breakpoint[] = "get_exception_breakpoint"; +static const char __pyx_k_global_cache_frame_skips[] = "global_cache_frame_skips"; +static const char __pyx_k_should_stop_on_exception[] = "should_stop_on_exception"; +static const char __pyx_k_threading_current_thread[] = "threading_current_thread"; +static const char __pyx_k_pyx_unpickle_ThreadTracer[] = "__pyx_unpickle_ThreadTracer"; +static const char __pyx_k_remove_return_values_flag[] = "remove_return_values_flag"; +static const char __pyx_k_send_signature_call_trace[] = "send_signature_call_trace"; +static const char __pyx_k_break_on_caught_exceptions[] = "break_on_caught_exceptions"; +static const char __pyx_k_notify_on_first_raise_only[] = "notify_on_first_raise_only"; +static const char __pyx_k_pydevd_bundle_pydevd_utils[] = "_pydevd_bundle.pydevd_utils"; +static const char __pyx_k_set_additional_thread_info[] = "set_additional_thread_info"; +static const char __pyx_k_trace_unhandled_exceptions[] = "trace_unhandled_exceptions"; +static const char __pyx_k_State_s_Stop_s_Cmd_s_Kill_s[] = "State:%s Stop:%s Cmd: %s Kill:%s"; +static const char __pyx_k_exclude_exception_by_filter[] = "exclude_exception_by_filter"; +static const char __pyx_k_force_only_unhandled_tracer[] = "force_only_unhandled_tracer"; +static const char __pyx_k_handle_breakpoint_condition[] = "handle_breakpoint_condition"; +static const char __pyx_k_has_plugin_exception_breaks[] = "has_plugin_exception_breaks"; +static const char __pyx_k_pydevd_bundle_pydevd_cython[] = "_pydevd_bundle.pydevd_cython"; +static const char __pyx_k_remove_exception_from_frame[] = "remove_exception_from_frame"; +static const char __pyx_k_send_caught_exception_stack[] = "send_caught_exception_stack"; +static const char __pyx_k_send_signature_return_trace[] = "send_signature_return_trace"; +static const char __pyx_k_stop_on_unhandled_exception[] = "stop_on_unhandled_exception"; +static const char __pyx_k_handle_breakpoint_expression[] = "handle_breakpoint_expression"; +static const char __pyx_k_pyx_unpickle_SafeCallWrapper[] = "__pyx_unpickle_SafeCallWrapper"; +static const char __pyx_k_NORM_PATHS_AND_BASE_CONTAINER[] = "NORM_PATHS_AND_BASE_CONTAINER"; +static const char __pyx_k_USE_CUSTOM_SYS_CURRENT_FRAMES[] = "USE_CUSTOM_SYS_CURRENT_FRAMES"; +static const char __pyx_k_pydevd_bundle_pydevd_constants[] = "_pydevd_bundle.pydevd_constants"; +static const char __pyx_k_pydevd_bundle_pydevd_signature[] = "_pydevd_bundle.pydevd_signature"; +static const char __pyx_k_pyx_unpickle_PyDBAdditionalThr[] = "__pyx_unpickle_PyDBAdditionalThreadInfo"; +static const char __pyx_k_pyx_unpickle_TopLevelThreadTra[] = "__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions"; +static const char __pyx_k_Ignore_exception_s_in_library_s[] = "Ignore exception %s in library %s -- (%s)"; +static const char __pyx_k_TopLevelThreadTracerNoBackFrame[] = "TopLevelThreadTracerNoBackFrame"; +static const char __pyx_k_get_abs_path_real_path_and_base[] = "get_abs_path_real_path_and_base_from_frame"; +static const char __pyx_k_global_notify_skipped_step_in_l[] = "_global_notify_skipped_step_in_lock"; +static const char __pyx_k_pydev_bundle_pydev_is_thread_al[] = "_pydev_bundle.pydev_is_thread_alive"; +static const char __pyx_k_pydev_imps__pydev_saved_modules[] = "_pydev_imps._pydev_saved_modules"; +static const char __pyx_k_pydevd_bundle_pydevd_additional[] = "_pydevd_bundle.pydevd_additional_thread_info_regular"; +static const char __pyx_k_pydevd_bundle_pydevd_cython_pyx[] = "_pydevd_bundle\\pydevd_cython.pyx"; +static const char __pyx_k_pydevd_bundle_pydevd_frame_util[] = "_pydevd_bundle.pydevd_frame_utils"; +static const char __pyx_k_pydevd_bundle_pydevd_kill_all_p[] = "_pydevd_bundle.pydevd_kill_all_pydevd_threads"; +static const char __pyx_k_set_additional_thread_info_lock[] = "_set_additional_thread_info_lock"; +static const char __pyx_k_set_trace_for_frame_and_parents[] = "set_trace_for_frame_and_parents"; +static const char __pyx_k_top_level_thread_tracer_no_back[] = "top_level_thread_tracer_no_back_frames"; +static const char __pyx_k_Incompatible_checksums_s_vs_0x3d[] = "Incompatible checksums (%s vs 0x3d7902a = (_args))"; +static const char __pyx_k_Incompatible_checksums_s_vs_0x6a[] = "Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))"; +static const char __pyx_k_Incompatible_checksums_s_vs_0x77[] = "Incompatible checksums (%s vs 0x77c077b = (method_object))"; +static const char __pyx_k_Incompatible_checksums_s_vs_0xf3[] = "Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))"; +static const char __pyx_k_Incompatible_checksums_s_vs_0xfa[] = "Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))"; +static const char __pyx_k_TopLevelThreadTracerOnlyUnhandle[] = "TopLevelThreadTracerOnlyUnhandledExceptions"; +static const char __pyx_k_USE_CUSTOM_SYS_CURRENT_FRAMES_MA[] = "USE_CUSTOM_SYS_CURRENT_FRAMES_MAP"; +static const char __pyx_k_Unable_to_proceed_sys__current_f[] = "Unable to proceed (sys._current_frames not available in this Python implementation)."; +static const char __pyx_k_filename_to_lines_where_exceptio[] = "filename_to_lines_where_exceptions_are_ignored"; +static const char __pyx_k_fix_top_level_trace_and_get_trac[] = "fix_top_level_trace_and_get_trace_func"; +static const char __pyx_k_ignore_exceptions_thrown_in_line[] = "ignore_exceptions_thrown_in_lines_with_ignore_exception"; +static const char __pyx_k_notify_skipped_step_in_because_o[] = "notify_skipped_step_in_because_of_filters"; +static const char __pyx_k_pyx_unpickle_TopLevelThreadTra_2[] = "__pyx_unpickle_TopLevelThreadTracerNoBackFrame"; +static const char __pyx_k_send_caught_exception_stack_proc[] = "send_caught_exception_stack_proceeded"; +static const char __pyx_k_skip_on_exceptions_thrown_in_sam[] = "skip_on_exceptions_thrown_in_same_context"; +static const char __pyx_k_top_level_thread_tracer_unhandle[] = "top_level_thread_tracer_unhandled"; +static const char __pyx_k_trace_dispatch_and_unhandled_exc[] = "trace_dispatch_and_unhandled_exceptions"; +static const char __pyx_k_get_abs_path_real_path_and_base_2[] = "get_abs_path_real_path_and_base_from_file"; +static PyObject *__pyx_kp_s_; +static PyObject *__pyx_kp_s_1; +static PyObject *__pyx_n_s_ALL; +static PyObject *__pyx_n_s_AttributeError; +static PyObject *__pyx_n_s_CO_GENERATOR; +static PyObject *__pyx_n_s_DEBUG_START; +static PyObject *__pyx_n_s_DEBUG_START_PY3K; +static PyObject *__pyx_n_s_GeneratorExit; +static PyObject *__pyx_n_s_IGNORE_EXCEPTION_TAG; +static PyObject *__pyx_n_s_IS_JYTHON; +static PyObject *__pyx_n_s_IS_PY3K; +static PyObject *__pyx_kp_s_IgnoreException; +static PyObject *__pyx_kp_s_Ignore_exception_s_in_library_s; +static PyObject *__pyx_n_s_ImportError; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x3d; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x6a; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x77; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xf3; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xfa; +static PyObject *__pyx_n_s_KeyboardInterrupt; +static PyObject *__pyx_n_s_Lock; +static PyObject *__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER; +static PyObject *__pyx_n_s_NO_FTRACE; +static PyObject *__pyx_n_s_NoSuchFieldException; +static PyObject *__pyx_n_s_None; +static PyObject *__pyx_n_s_PYDEV_FILE; +static PyObject *__pyx_n_s_PYTHON_SUSPEND; +static PyObject *__pyx_n_s_PickleError; +static PyObject *__pyx_n_s_PyDBAdditionalThreadInfo; +static PyObject *__pyx_n_s_PyDBFrame; +static PyObject *__pyx_n_s_RETURN_VALUES_DICT; +static PyObject *__pyx_n_s_RuntimeError; +static PyObject *__pyx_n_s_STATE_RUN; +static PyObject *__pyx_n_s_SafeCallWrapper; +static PyObject *__pyx_kp_s_State_s_Stop_s_Cmd_s_Kill_s; +static PyObject *__pyx_n_s_StopIteration; +static PyObject *__pyx_n_s_SystemExit; +static PyObject *__pyx_n_s_TRACE_PROPERTY; +static PyObject *__pyx_n_s_Thread; +static PyObject *__pyx_n_s_ThreadStateMapping; +static PyObject *__pyx_n_s_ThreadTracer; +static PyObject *__pyx_n_s_TopLevelThreadTracerNoBackFrame; +static PyObject *__pyx_n_s_TopLevelThreadTracerOnlyUnhandle; +static PyObject *__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES; +static PyObject *__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA; +static PyObject *__pyx_kp_s_Unable_to_proceed_sys__current_f; +static PyObject *__pyx_kp_s_Using_Cython_speedups; +static PyObject *__pyx_kp_s__3; +static PyObject *__pyx_kp_s__4; +static PyObject *__pyx_kp_s__5; +static PyObject *__pyx_kp_s__6; +static PyObject *__pyx_n_s_accessible; +static PyObject *__pyx_n_s_add_command; +static PyObject *__pyx_n_s_add_exception_to_frame; +static PyObject *__pyx_n_s_additional_info; +static PyObject *__pyx_n_s_append; +static PyObject *__pyx_n_s_apply_files_filter; +static PyObject *__pyx_n_s_apply_to_settrace; +static PyObject *__pyx_n_s_arg; +static PyObject *__pyx_n_s_args; +static PyObject *__pyx_n_s_args_2; +static PyObject *__pyx_n_s_as_array; +static PyObject *__pyx_n_s_asyncio_analyser; +static PyObject *__pyx_n_s_basename; +static PyObject *__pyx_n_s_bootstrap; +static PyObject *__pyx_n_s_bootstrap_2; +static PyObject *__pyx_n_s_bootstrap_inner; +static PyObject *__pyx_n_s_bootstrap_inner_2; +static PyObject *__pyx_n_s_break_on_caught_exceptions; +static PyObject *__pyx_n_s_breakpoints; +static PyObject *__pyx_n_s_cachedThreadState; +static PyObject *__pyx_n_s_call; +static PyObject *__pyx_n_s_call_2; +static PyObject *__pyx_n_s_can_skip; +static PyObject *__pyx_n_s_checkcache; +static PyObject *__pyx_n_s_clear; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_cmd_factory; +static PyObject *__pyx_n_s_cmd_step_into; +static PyObject *__pyx_n_s_cmd_step_over; +static PyObject *__pyx_n_s_co_filename; +static PyObject *__pyx_n_s_co_firstlineno; +static PyObject *__pyx_n_s_co_flags; +static PyObject *__pyx_n_s_co_name; +static PyObject *__pyx_n_s_collect_try_except_info; +static PyObject *__pyx_n_s_compile; +static PyObject *__pyx_n_s_condition; +static PyObject *__pyx_n_s_current_frames; +static PyObject *__pyx_n_s_debug; +static PyObject *__pyx_n_s_dict; +static PyObject *__pyx_n_s_dict_iter_values; +static PyObject *__pyx_n_s_disable_tracing; +static PyObject *__pyx_n_s_do_wait_suspend; +static PyObject *__pyx_n_s_enable_tracing; +static PyObject *__pyx_n_s_encode; +static PyObject *__pyx_n_s_enter; +static PyObject *__pyx_n_s_entrySet; +static PyObject *__pyx_n_s_event; +static PyObject *__pyx_n_s_except_line; +static PyObject *__pyx_n_s_exception; +static PyObject *__pyx_n_s_exception_break; +static PyObject *__pyx_n_s_exclude_exception_by_filter; +static PyObject *__pyx_n_s_exec; +static PyObject *__pyx_n_s_execfile; +static PyObject *__pyx_n_s_exit; +static PyObject *__pyx_n_s_expression; +static PyObject *__pyx_n_s_f_back; +static PyObject *__pyx_n_s_f_code; +static PyObject *__pyx_n_s_f_globals; +static PyObject *__pyx_n_s_f_lineno; +static PyObject *__pyx_n_s_f_locals; +static PyObject *__pyx_n_s_f_trace; +static PyObject *__pyx_n_s_f_unhandled; +static PyObject *__pyx_n_s_filename; +static PyObject *__pyx_n_s_filename_to_lines_where_exceptio; +static PyObject *__pyx_n_s_filename_to_stat_info; +static PyObject *__pyx_n_s_finish_debugging_session; +static PyObject *__pyx_n_s_fix_top_level_trace_and_get_trac; +static PyObject *__pyx_n_s_force_only_unhandled_tracer; +static PyObject *__pyx_n_s_frame; +static PyObject *__pyx_n_s_frame_trace_dispatch; +static PyObject *__pyx_n_s_func_name; +static PyObject *__pyx_n_s_get; +static PyObject *__pyx_n_s_getDeclaredField; +static PyObject *__pyx_n_s_getId; +static PyObject *__pyx_n_s_getKey; +static PyObject *__pyx_n_s_getValue; +static PyObject *__pyx_n_s_get_abs_path_real_path_and_base; +static PyObject *__pyx_n_s_get_abs_path_real_path_and_base_2; +static PyObject *__pyx_n_s_get_breakpoint; +static PyObject *__pyx_n_s_get_clsname_for_code; +static PyObject *__pyx_n_s_get_current_thread_id; +static PyObject *__pyx_n_s_get_exception_breakpoint; +static PyObject *__pyx_n_s_get_file_type; +static PyObject *__pyx_n_s_get_func_name; +static PyObject *__pyx_n_s_get_trace_dispatch_func; +static PyObject *__pyx_n_s_getline; +static PyObject *__pyx_n_s_getstate; +static PyObject *__pyx_n_s_globalThreadStates; +static PyObject *__pyx_n_s_global_cache_frame_skips; +static PyObject *__pyx_n_s_global_cache_skips; +static PyObject *__pyx_n_s_global_notify_skipped_step_in_l; +static PyObject *__pyx_n_s_handle_breakpoint_condition; +static PyObject *__pyx_n_s_handle_breakpoint_expression; +static PyObject *__pyx_n_s_handle_exception; +static PyObject *__pyx_n_s_has_condition; +static PyObject *__pyx_n_s_has_plugin_exception_breaks; +static PyObject *__pyx_n_s_has_plugin_line_breaks; +static PyObject *__pyx_n_s_i; +static PyObject *__pyx_n_s_id; +static PyObject *__pyx_n_s_ident; +static PyObject *__pyx_n_s_ignore_exception_trace; +static PyObject *__pyx_n_s_ignore_exceptions_thrown_in_line; +static PyObject *__pyx_n_s_ignore_system_exit_code; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_in_project_scope; +static PyObject *__pyx_n_s_inspect; +static PyObject *__pyx_kp_s_invalid; +static PyObject *__pyx_n_s_is_files_filter_enabled; +static PyObject *__pyx_n_s_is_line_in_except_block; +static PyObject *__pyx_n_s_is_line_in_try_block; +static PyObject *__pyx_n_s_is_logpoint; +static PyObject *__pyx_n_s_is_thread_alive; +static PyObject *__pyx_n_s_j; +static PyObject *__pyx_n_s_java_lang; +static PyObject *__pyx_n_s_just_raised; +static PyObject *__pyx_n_s_kill_all_pydev_threads; +static PyObject *__pyx_n_s_kwargs; +static PyObject *__pyx_kp_s_lambda; +static PyObject *__pyx_n_s_line; +static PyObject *__pyx_n_s_linecache; +static PyObject *__pyx_n_s_linesep; +static PyObject *__pyx_n_s_log_event; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_main_2; +static PyObject *__pyx_n_s_main_debugger; +static PyObject *__pyx_n_s_make_io_message; +static PyObject *__pyx_n_s_match; +static PyObject *__pyx_n_s_method_object; +static PyObject *__pyx_kp_s_module; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_n_s_name_2; +static PyObject *__pyx_n_s_new; +static PyObject *__pyx_n_s_notify_on_first_raise_only; +static PyObject *__pyx_n_s_notify_skipped_step_in_because_o; +static PyObject *__pyx_n_s_notify_thread_not_alive; +static PyObject *__pyx_n_s_org_python_core; +static PyObject *__pyx_n_s_original_call; +static PyObject *__pyx_n_s_os; +static PyObject *__pyx_n_s_os_path; +static PyObject *__pyx_n_s_output_checker_thread; +static PyObject *__pyx_n_s_path; +static PyObject *__pyx_n_s_pickle; +static PyObject *__pyx_n_s_plugin; +static PyObject *__pyx_n_s_pop; +static PyObject *__pyx_n_s_py_db; +static PyObject *__pyx_n_s_pydev_bundle; +static PyObject *__pyx_n_s_pydev_bundle_pydev_is_thread_al; +static PyObject *__pyx_n_s_pydev_bundle_pydev_log; +static PyObject *__pyx_n_s_pydev_do_not_trace; +static PyObject *__pyx_kp_s_pydev_execfile_py; +static PyObject *__pyx_n_s_pydev_imps__pydev_saved_modules; +static PyObject *__pyx_n_s_pydev_log; +static PyObject *__pyx_n_s_pydev_log_exception; +static PyObject *__pyx_n_s_pydev_monkey; +static PyObject *__pyx_n_s_pydevd; +static PyObject *__pyx_n_s_pydevd_bundle; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_additional; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_constants; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_cython; +static PyObject *__pyx_kp_s_pydevd_bundle_pydevd_cython_pyx; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_frame_util; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_kill_all_p; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_signature; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_utils; +static PyObject *__pyx_n_s_pydevd_dont_trace; +static PyObject *__pyx_n_s_pydevd_file_utils; +static PyObject *__pyx_kp_s_pydevd_py; +static PyObject *__pyx_kp_s_pydevd_traceproperty_py; +static PyObject *__pyx_n_s_pyx_PickleError; +static PyObject *__pyx_n_s_pyx_checksum; +static PyObject *__pyx_n_s_pyx_result; +static PyObject *__pyx_n_s_pyx_state; +static PyObject *__pyx_n_s_pyx_type; +static PyObject *__pyx_n_s_pyx_unpickle_PyDBAdditionalThr; +static PyObject *__pyx_n_s_pyx_unpickle_PyDBFrame; +static PyObject *__pyx_n_s_pyx_unpickle_SafeCallWrapper; +static PyObject *__pyx_n_s_pyx_unpickle_ThreadTracer; +static PyObject *__pyx_n_s_pyx_unpickle_TopLevelThreadTra; +static PyObject *__pyx_n_s_pyx_unpickle_TopLevelThreadTra_2; +static PyObject *__pyx_n_s_pyx_vtable; +static PyObject *__pyx_n_s_qname; +static PyObject *__pyx_n_s_quitting; +static PyObject *__pyx_n_s_raise_lines_in_except; +static PyObject *__pyx_n_s_re; +static PyObject *__pyx_n_s_reduce; +static PyObject *__pyx_n_s_reduce_cython; +static PyObject *__pyx_n_s_reduce_ex; +static PyObject *__pyx_n_s_remove_exception_from_frame; +static PyObject *__pyx_n_s_remove_return_values; +static PyObject *__pyx_n_s_remove_return_values_flag; +static PyObject *__pyx_n_s_ret; +static PyObject *__pyx_n_s_return; +static PyObject *__pyx_n_s_rfind; +static PyObject *__pyx_n_s_run; +static PyObject *__pyx_kp_s_s_s; +static PyObject *__pyx_n_s_self; +static PyObject *__pyx_n_s_send_caught_exception_stack; +static PyObject *__pyx_n_s_send_caught_exception_stack_proc; +static PyObject *__pyx_n_s_send_signature_call_trace; +static PyObject *__pyx_n_s_send_signature_return_trace; +static PyObject *__pyx_n_s_set_additional_thread_info; +static PyObject *__pyx_n_s_set_additional_thread_info_lock; +static PyObject *__pyx_n_s_set_suspend; +static PyObject *__pyx_n_s_set_trace_for_frame_and_parents; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_should_stop_on_exception; +static PyObject *__pyx_n_s_should_trace_hook; +static PyObject *__pyx_n_s_show_return_values; +static PyObject *__pyx_n_s_signature_factory; +static PyObject *__pyx_n_s_skip_on_exceptions_thrown_in_sam; +static PyObject *__pyx_n_s_st_mtime; +static PyObject *__pyx_n_s_st_size; +static PyObject *__pyx_n_s_stat; +static PyObject *__pyx_n_s_stop; +static PyObject *__pyx_n_s_stop_on_unhandled_exception; +static PyObject *__pyx_kp_s_stringsource; +static PyObject *__pyx_n_s_suspend; +static PyObject *__pyx_n_s_suspend_other_threads; +static PyObject *__pyx_n_s_suspend_policy; +static PyObject *__pyx_n_s_suspended_at_unhandled; +static PyObject *__pyx_n_s_sys; +static PyObject *__pyx_n_s_t; +static PyObject *__pyx_n_s_tb_frame; +static PyObject *__pyx_n_s_tb_lineno; +static PyObject *__pyx_n_s_tb_next; +static PyObject *__pyx_n_s_termination_event_set; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_thread; +static PyObject *__pyx_n_s_thread_analyser; +static PyObject *__pyx_n_s_thread_state; +static PyObject *__pyx_n_s_thread_states; +static PyObject *__pyx_n_s_thread_to_state; +static PyObject *__pyx_n_s_thread_trace_func; +static PyObject *__pyx_n_s_thread_tracer; +static PyObject *__pyx_n_s_threading; +static PyObject *__pyx_n_s_threading_active; +static PyObject *__pyx_n_s_threading_current_thread; +static PyObject *__pyx_n_s_threading_get_ident; +static PyObject *__pyx_n_s_tid_to_last_frame; +static PyObject *__pyx_n_s_toArray; +static PyObject *__pyx_n_s_top_level_thread_tracer; +static PyObject *__pyx_n_s_top_level_thread_tracer_no_back; +static PyObject *__pyx_n_s_top_level_thread_tracer_unhandle; +static PyObject *__pyx_n_s_trace; +static PyObject *__pyx_n_s_trace_dispatch; +static PyObject *__pyx_n_s_trace_dispatch_and_unhandled_exc; +static PyObject *__pyx_n_s_trace_exception; +static PyObject *__pyx_n_s_trace_return; +static PyObject *__pyx_n_s_trace_unhandled_exceptions; +static PyObject *__pyx_n_s_update; +static PyObject *__pyx_kp_s_utf_8; +static PyObject *__pyx_n_s_version; +static PyObject *__pyx_n_s_writer; +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython__current_frames(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_2_current_frames(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_2get_topmost_frame(CYTHON_UNUSED struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_thread); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_4__str__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_4set_additional_thread_info(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_thread); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_6send_signature_call_trace(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_args); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_2set_suspend(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_4do_wait_suspend(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_6trace_exception(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_8trace_return(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_10should_stop_on_exception(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, CYTHON_UNUSED PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_12handle_exception(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_14get_func_name(CYTHON_UNUSED struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_16show_return_values(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_18remove_return_values(CYTHON_UNUSED struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_main_debugger, PyObject *__pyx_v_frame); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_20trace_dispatch(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_22__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_24__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_8notify_skipped_step_in_because_of_filters(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_py_db, PyObject *__pyx_v_frame); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self, PyObject *__pyx_v_method_object); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_2__call__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self, PyObject *__pyx_v_args); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_4get_method_object(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_10fix_top_level_trace_and_get_trace_func(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_py_db, PyObject *__pyx_v_frame); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12trace_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_py_db, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, PyObject *__pyx_v_args); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_2trace_unhandled_exceptions(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_4get_trace_dispatch_func(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_frame_trace_dispatch, PyObject *__pyx_v_args); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_2trace_dispatch_and_unhandled_exceptions(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_4get_trace_dispatch_func(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v_args); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_4__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_6__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_14__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_16__pyx_unpickle_PyDBAdditionalThreadInfo(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_18__pyx_unpickle_PyDBFrame(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_20__pyx_unpickle_SafeCallWrapper(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_22__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24__pyx_unpickle_TopLevelThreadTracerNoBackFrame(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_26__pyx_unpickle_ThreadTracer(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_PyDBFrame(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_ThreadTracer(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, &__pyx_n_s_get, 0, 0, 0}; +static __Pyx_CachedCFunction __pyx_umethod_PyString_Type_rfind = {0, &__pyx_n_s_rfind, 0, 0, 0}; +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; +static PyObject *__pyx_int_11; +static PyObject *__pyx_int_32; +static PyObject *__pyx_int_111; +static PyObject *__pyx_int_137; +static PyObject *__pyx_int_64458794; +static PyObject *__pyx_int_112182380; +static PyObject *__pyx_int_125568891; +static PyObject *__pyx_int_255117134; +static PyObject *__pyx_int_262582659; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__7; +static PyObject *__pyx_tuple__8; +static PyObject *__pyx_tuple__9; +static PyObject *__pyx_tuple__10; +static PyObject *__pyx_tuple__11; +static PyObject *__pyx_tuple__14; +static PyObject *__pyx_tuple__15; +static PyObject *__pyx_tuple__17; +static PyObject *__pyx_tuple__19; +static PyObject *__pyx_tuple__20; +static PyObject *__pyx_tuple__21; +static PyObject *__pyx_tuple__22; +static PyObject *__pyx_tuple__24; +static PyObject *__pyx_tuple__26; +static PyObject *__pyx_tuple__28; +static PyObject *__pyx_tuple__30; +static PyObject *__pyx_tuple__32; +static PyObject *__pyx_tuple__34; +static PyObject *__pyx_tuple__36; +static PyObject *__pyx_tuple__38; +static PyObject *__pyx_tuple__40; +static PyObject *__pyx_codeobj__12; +static PyObject *__pyx_codeobj__13; +static PyObject *__pyx_codeobj__16; +static PyObject *__pyx_codeobj__18; +static PyObject *__pyx_codeobj__23; +static PyObject *__pyx_codeobj__25; +static PyObject *__pyx_codeobj__27; +static PyObject *__pyx_codeobj__29; +static PyObject *__pyx_codeobj__31; +static PyObject *__pyx_codeobj__33; +static PyObject *__pyx_codeobj__35; +static PyObject *__pyx_codeobj__37; +static PyObject *__pyx_codeobj__39; +static PyObject *__pyx_codeobj__41; +/* Late includes */ + +/* "_pydevd_bundle/pydevd_cython.pyx":32 + * thread_states = cachedThreadState.get(ThreadStateMapping) + * + * def _current_frames(): # <<<<<<<<<<<<<< + * as_array = thread_states.entrySet().toArray() + * ret = {} + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_1_current_frames(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_1_current_frames = {"_current_frames", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_1_current_frames, METH_NOARGS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_1_current_frames(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_current_frames (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython__current_frames(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython__current_frames(CYTHON_UNUSED PyObject *__pyx_self) { + PyObject *__pyx_v_as_array = NULL; + PyObject *__pyx_v_ret = NULL; + PyObject *__pyx_v_thread_to_state = NULL; + PyObject *__pyx_v_thread = NULL; + PyObject *__pyx_v_thread_state = NULL; + PyObject *__pyx_v_frame = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + int __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("_current_frames", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":33 + * + * def _current_frames(): + * as_array = thread_states.entrySet().toArray() # <<<<<<<<<<<<<< + * ret = {} + * for thread_to_state in as_array: + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_thread_states); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_entrySet); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_toArray); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_as_array = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":34 + * def _current_frames(): + * as_array = thread_states.entrySet().toArray() + * ret = {} # <<<<<<<<<<<<<< + * for thread_to_state in as_array: + * thread = thread_to_state.getKey() + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 34, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":35 + * as_array = thread_states.entrySet().toArray() + * ret = {} + * for thread_to_state in as_array: # <<<<<<<<<<<<<< + * thread = thread_to_state.getKey() + * if thread is None: + */ + if (likely(PyList_CheckExact(__pyx_v_as_array)) || PyTuple_CheckExact(__pyx_v_as_array)) { + __pyx_t_1 = __pyx_v_as_array; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_as_array); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 35, __pyx_L1_error) + } + for (;;) { + if (likely(!__pyx_t_6)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 35, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 35, __pyx_L1_error) + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 35, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } + } else { + __pyx_t_4 = __pyx_t_6(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 35, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF_SET(__pyx_v_thread_to_state, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":36 + * ret = {} + * for thread_to_state in as_array: + * thread = thread_to_state.getKey() # <<<<<<<<<<<<<< + * if thread is None: + * continue + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_to_state, __pyx_n_s_getKey); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_thread, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":37 + * for thread_to_state in as_array: + * thread = thread_to_state.getKey() + * if thread is None: # <<<<<<<<<<<<<< + * continue + * thread_state = thread_to_state.getValue() + */ + __pyx_t_7 = (__pyx_v_thread == Py_None); + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":38 + * thread = thread_to_state.getKey() + * if thread is None: + * continue # <<<<<<<<<<<<<< + * thread_state = thread_to_state.getValue() + * if thread_state is None: + */ + goto __pyx_L3_continue; + + /* "_pydevd_bundle/pydevd_cython.pyx":37 + * for thread_to_state in as_array: + * thread = thread_to_state.getKey() + * if thread is None: # <<<<<<<<<<<<<< + * continue + * thread_state = thread_to_state.getValue() + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":39 + * if thread is None: + * continue + * thread_state = thread_to_state.getValue() # <<<<<<<<<<<<<< + * if thread_state is None: + * continue + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_to_state, __pyx_n_s_getValue); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 39, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF_SET(__pyx_v_thread_state, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":40 + * continue + * thread_state = thread_to_state.getValue() + * if thread_state is None: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_8 = (__pyx_v_thread_state == Py_None); + __pyx_t_7 = (__pyx_t_8 != 0); + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":41 + * thread_state = thread_to_state.getValue() + * if thread_state is None: + * continue # <<<<<<<<<<<<<< + * + * frame = thread_state.frame + */ + goto __pyx_L3_continue; + + /* "_pydevd_bundle/pydevd_cython.pyx":40 + * continue + * thread_state = thread_to_state.getValue() + * if thread_state is None: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":43 + * continue + * + * frame = thread_state.frame # <<<<<<<<<<<<<< + * if frame is None: + * continue + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_state, __pyx_n_s_frame); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_frame, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":44 + * + * frame = thread_state.frame + * if frame is None: # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_7 = (__pyx_v_frame == Py_None); + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":45 + * frame = thread_state.frame + * if frame is None: + * continue # <<<<<<<<<<<<<< + * + * ret[thread.getId()] = frame + */ + goto __pyx_L3_continue; + + /* "_pydevd_bundle/pydevd_cython.pyx":44 + * + * frame = thread_state.frame + * if frame is None: # <<<<<<<<<<<<<< + * continue + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":47 + * continue + * + * ret[thread.getId()] = frame # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread, __pyx_n_s_getId); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(PyDict_SetItem(__pyx_v_ret, __pyx_t_4, __pyx_v_frame) < 0)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":35 + * as_array = thread_states.entrySet().toArray() + * ret = {} + * for thread_to_state in as_array: # <<<<<<<<<<<<<< + * thread = thread_to_state.getKey() + * if thread is None: + */ + __pyx_L3_continue:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":48 + * + * ret[thread.getId()] = frame + * return ret # <<<<<<<<<<<<<< + * + * elif USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_ret); + __pyx_r = __pyx_v_ret; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":32 + * thread_states = cachedThreadState.get(ThreadStateMapping) + * + * def _current_frames(): # <<<<<<<<<<<<<< + * as_array = thread_states.entrySet().toArray() + * ret = {} + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython._current_frames", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_as_array); + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XDECREF(__pyx_v_thread_to_state); + __Pyx_XDECREF(__pyx_v_thread); + __Pyx_XDECREF(__pyx_v_thread_state); + __Pyx_XDECREF(__pyx_v_frame); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":54 + * + * # IronPython doesn't have it. Let's use our workaround... + * def _current_frames(): # <<<<<<<<<<<<<< + * return _tid_to_last_frame + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_3_current_frames(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_3_current_frames = {"_current_frames", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_3_current_frames, METH_NOARGS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_3_current_frames(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_current_frames (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_2_current_frames(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_2_current_frames(CYTHON_UNUSED PyObject *__pyx_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("_current_frames", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":55 + * # IronPython doesn't have it. Let's use our workaround... + * def _current_frames(): + * return _tid_to_last_frame # <<<<<<<<<<<<<< + * + * else: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_tid_to_last_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":54 + * + * # IronPython doesn't have it. Let's use our workaround... + * def _current_frames(): # <<<<<<<<<<<<<< + * return _tid_to_last_frame + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython._current_frames", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":99 + * # ENDIF + * + * def __init__(self): # <<<<<<<<<<<<<< + * self.pydev_state = STATE_RUN # STATE_RUN or STATE_SUSPEND + * self.pydev_step_stop = None + */ + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo___init__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":100 + * + * def __init__(self): + * self.pydev_state = STATE_RUN # STATE_RUN or STATE_SUSPEND # <<<<<<<<<<<<<< + * self.pydev_step_stop = None + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_STATE_RUN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 100, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->pydev_state = __pyx_t_2; + + /* "_pydevd_bundle/pydevd_cython.pyx":101 + * def __init__(self): + * self.pydev_state = STATE_RUN # STATE_RUN or STATE_SUSPEND + * self.pydev_step_stop = None # <<<<<<<<<<<<<< + * + * # Note: we have `pydev_original_step_cmd` and `pydev_step_cmd` because the original is to + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_step_stop); + __Pyx_DECREF(__pyx_v_self->pydev_step_stop); + __pyx_v_self->pydev_step_stop = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":109 + * # method the strategy is changed to a step in). + * + * self.pydev_original_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. # <<<<<<<<<<<<<< + * self.pydev_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + * + */ + __pyx_v_self->pydev_original_step_cmd = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":110 + * + * self.pydev_original_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + * self.pydev_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. # <<<<<<<<<<<<<< + * + * self.pydev_notify_kill = False + */ + __pyx_v_self->pydev_step_cmd = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":112 + * self.pydev_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + * + * self.pydev_notify_kill = False # <<<<<<<<<<<<<< + * self.pydev_smart_step_stop = None + * self.pydev_django_resolve_frame = False + */ + __pyx_v_self->pydev_notify_kill = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":113 + * + * self.pydev_notify_kill = False + * self.pydev_smart_step_stop = None # <<<<<<<<<<<<<< + * self.pydev_django_resolve_frame = False + * self.pydev_call_from_jinja2 = None + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_smart_step_stop); + __Pyx_DECREF(__pyx_v_self->pydev_smart_step_stop); + __pyx_v_self->pydev_smart_step_stop = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":114 + * self.pydev_notify_kill = False + * self.pydev_smart_step_stop = None + * self.pydev_django_resolve_frame = False # <<<<<<<<<<<<<< + * self.pydev_call_from_jinja2 = None + * self.pydev_call_inside_jinja2 = None + */ + __pyx_v_self->pydev_django_resolve_frame = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":115 + * self.pydev_smart_step_stop = None + * self.pydev_django_resolve_frame = False + * self.pydev_call_from_jinja2 = None # <<<<<<<<<<<<<< + * self.pydev_call_inside_jinja2 = None + * self.is_tracing = False + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_call_from_jinja2); + __Pyx_DECREF(__pyx_v_self->pydev_call_from_jinja2); + __pyx_v_self->pydev_call_from_jinja2 = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":116 + * self.pydev_django_resolve_frame = False + * self.pydev_call_from_jinja2 = None + * self.pydev_call_inside_jinja2 = None # <<<<<<<<<<<<<< + * self.is_tracing = False + * self.conditional_breakpoint_exception = None + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_call_inside_jinja2); + __Pyx_DECREF(__pyx_v_self->pydev_call_inside_jinja2); + __pyx_v_self->pydev_call_inside_jinja2 = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":117 + * self.pydev_call_from_jinja2 = None + * self.pydev_call_inside_jinja2 = None + * self.is_tracing = False # <<<<<<<<<<<<<< + * self.conditional_breakpoint_exception = None + * self.pydev_message = '' + */ + __pyx_v_self->is_tracing = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":118 + * self.pydev_call_inside_jinja2 = None + * self.is_tracing = False + * self.conditional_breakpoint_exception = None # <<<<<<<<<<<<<< + * self.pydev_message = '' + * self.suspend_type = PYTHON_SUSPEND + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->conditional_breakpoint_exception); + __Pyx_DECREF(__pyx_v_self->conditional_breakpoint_exception); + __pyx_v_self->conditional_breakpoint_exception = ((PyObject*)Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":119 + * self.is_tracing = False + * self.conditional_breakpoint_exception = None + * self.pydev_message = '' # <<<<<<<<<<<<<< + * self.suspend_type = PYTHON_SUSPEND + * self.pydev_next_line = -1 + */ + __Pyx_INCREF(__pyx_kp_s_); + __Pyx_GIVEREF(__pyx_kp_s_); + __Pyx_GOTREF(__pyx_v_self->pydev_message); + __Pyx_DECREF(__pyx_v_self->pydev_message); + __pyx_v_self->pydev_message = __pyx_kp_s_; + + /* "_pydevd_bundle/pydevd_cython.pyx":120 + * self.conditional_breakpoint_exception = None + * self.pydev_message = '' + * self.suspend_type = PYTHON_SUSPEND # <<<<<<<<<<<<<< + * self.pydev_next_line = -1 + * self.pydev_func_name = '.invalid.' # Must match the type in cython + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_PYTHON_SUSPEND); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 120, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->suspend_type = __pyx_t_2; + + /* "_pydevd_bundle/pydevd_cython.pyx":121 + * self.pydev_message = '' + * self.suspend_type = PYTHON_SUSPEND + * self.pydev_next_line = -1 # <<<<<<<<<<<<<< + * self.pydev_func_name = '.invalid.' # Must match the type in cython + * self.suspended_at_unhandled = False + */ + __pyx_v_self->pydev_next_line = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":122 + * self.suspend_type = PYTHON_SUSPEND + * self.pydev_next_line = -1 + * self.pydev_func_name = '.invalid.' # Must match the type in cython # <<<<<<<<<<<<<< + * self.suspended_at_unhandled = False + * self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' + */ + __Pyx_INCREF(__pyx_kp_s_invalid); + __Pyx_GIVEREF(__pyx_kp_s_invalid); + __Pyx_GOTREF(__pyx_v_self->pydev_func_name); + __Pyx_DECREF(__pyx_v_self->pydev_func_name); + __pyx_v_self->pydev_func_name = __pyx_kp_s_invalid; + + /* "_pydevd_bundle/pydevd_cython.pyx":123 + * self.pydev_next_line = -1 + * self.pydev_func_name = '.invalid.' # Must match the type in cython + * self.suspended_at_unhandled = False # <<<<<<<<<<<<<< + * self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' + * self.top_level_thread_tracer_no_back_frames = [] + */ + __pyx_v_self->suspended_at_unhandled = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":124 + * self.pydev_func_name = '.invalid.' # Must match the type in cython + * self.suspended_at_unhandled = False + * self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' # <<<<<<<<<<<<<< + * self.top_level_thread_tracer_no_back_frames = [] + * self.top_level_thread_tracer_unhandled = None + */ + __Pyx_INCREF(__pyx_n_s_trace); + __Pyx_GIVEREF(__pyx_n_s_trace); + __Pyx_GOTREF(__pyx_v_self->trace_suspend_type); + __Pyx_DECREF(__pyx_v_self->trace_suspend_type); + __pyx_v_self->trace_suspend_type = __pyx_n_s_trace; + + /* "_pydevd_bundle/pydevd_cython.pyx":125 + * self.suspended_at_unhandled = False + * self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' + * self.top_level_thread_tracer_no_back_frames = [] # <<<<<<<<<<<<<< + * self.top_level_thread_tracer_unhandled = None + * self.thread_tracer = None + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __Pyx_DECREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __pyx_v_self->top_level_thread_tracer_no_back_frames = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":126 + * self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' + * self.top_level_thread_tracer_no_back_frames = [] + * self.top_level_thread_tracer_unhandled = None # <<<<<<<<<<<<<< + * self.thread_tracer = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __Pyx_DECREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __pyx_v_self->top_level_thread_tracer_unhandled = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":127 + * self.top_level_thread_tracer_no_back_frames = [] + * self.top_level_thread_tracer_unhandled = None + * self.thread_tracer = None # <<<<<<<<<<<<<< + * + * def get_topmost_frame(self, thread): + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->thread_tracer); + __Pyx_DECREF(__pyx_v_self->thread_tracer); + __pyx_v_self->thread_tracer = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":99 + * # ENDIF + * + * def __init__(self): # <<<<<<<<<<<<<< + * self.pydev_state = STATE_RUN # STATE_RUN or STATE_SUSPEND + * self.pydev_step_stop = None + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":129 + * self.thread_tracer = None + * + * def get_topmost_frame(self, thread): # <<<<<<<<<<<<<< + * ''' + * Gets the topmost frame for the given thread. Note that it may be None + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_3get_topmost_frame(PyObject *__pyx_v_self, PyObject *__pyx_v_thread); /*proto*/ +static char __pyx_doc_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_2get_topmost_frame[] = "\n Gets the topmost frame for the given thread. Note that it may be None\n and callers should remove the reference to the frame as soon as possible\n to avoid disturbing user code.\n "; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_3get_topmost_frame(PyObject *__pyx_v_self, PyObject *__pyx_v_thread) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_topmost_frame (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_2get_topmost_frame(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_thread)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_2get_topmost_frame(CYTHON_UNUSED struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_thread) { + PyObject *__pyx_v_current_frames = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("get_topmost_frame", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":136 + * ''' + * # sys._current_frames(): dictionary with thread id -> topmost frame + * current_frames = _current_frames() # <<<<<<<<<<<<<< + * return current_frames.get(thread.ident) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_current_frames); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_current_frames = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":137 + * # sys._current_frames(): dictionary with thread id -> topmost frame + * current_frames = _current_frames() + * return current_frames.get(thread.ident) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_current_frames, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread, __pyx_n_s_ident); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":129 + * self.thread_tracer = None + * + * def get_topmost_frame(self, thread): # <<<<<<<<<<<<<< + * ''' + * Gets the topmost frame for the given thread. Note that it may be None + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.get_topmost_frame", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_current_frames); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":139 + * return current_frames.get(thread.ident) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( + * self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_4__str__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_4__str__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":140 + * + * def __str__(self): + * return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( # <<<<<<<<<<<<<< + * self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) + * + */ + __Pyx_XDECREF(__pyx_r); + + /* "_pydevd_bundle/pydevd_cython.pyx":141 + * def __str__(self): + * return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( + * self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_state); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_step_cmd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_self->pydev_notify_kill); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 141, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_INCREF(__pyx_v_self->pydev_step_stop); + __Pyx_GIVEREF(__pyx_v_self->pydev_step_stop); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_self->pydev_step_stop); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":140 + * + * def __str__(self): + * return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( # <<<<<<<<<<<<<< + * self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) + * + */ + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_State_s_Stop_s_Cmd_s_Kill_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":139 + * return current_frames.get(thread.ident) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( + * self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":2 + * cdef class PyDBAdditionalThreadInfo: + * cdef public int pydev_state; # <<<<<<<<<<<<<< + * cdef public object pydev_step_stop; # Actually, it's a frame or None + * cdef public int pydev_original_step_cmd; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_state); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_state.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_v_self->pydev_state = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_state.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":3 + * cdef class PyDBAdditionalThreadInfo: + * cdef public int pydev_state; + * cdef public object pydev_step_stop; # Actually, it's a frame or None # <<<<<<<<<<<<<< + * cdef public int pydev_original_step_cmd; + * cdef public int pydev_step_cmd; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->pydev_step_stop); + __pyx_r = __pyx_v_self->pydev_step_stop; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->pydev_step_stop); + __Pyx_DECREF(__pyx_v_self->pydev_step_stop); + __pyx_v_self->pydev_step_stop = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_step_stop); + __Pyx_DECREF(__pyx_v_self->pydev_step_stop); + __pyx_v_self->pydev_step_stop = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":4 + * cdef public int pydev_state; + * cdef public object pydev_step_stop; # Actually, it's a frame or None + * cdef public int pydev_original_step_cmd; # <<<<<<<<<<<<<< + * cdef public int pydev_step_cmd; + * cdef public bint pydev_notify_kill; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_original_step_cmd); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_original_step_cmd.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_v_self->pydev_original_step_cmd = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_original_step_cmd.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":5 + * cdef public object pydev_step_stop; # Actually, it's a frame or None + * cdef public int pydev_original_step_cmd; + * cdef public int pydev_step_cmd; # <<<<<<<<<<<<<< + * cdef public bint pydev_notify_kill; + * cdef public object pydev_smart_step_stop; # Actually, it's a frame or None + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_step_cmd); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_step_cmd.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 5, __pyx_L1_error) + __pyx_v_self->pydev_step_cmd = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_step_cmd.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":6 + * cdef public int pydev_original_step_cmd; + * cdef public int pydev_step_cmd; + * cdef public bint pydev_notify_kill; # <<<<<<<<<<<<<< + * cdef public object pydev_smart_step_stop; # Actually, it's a frame or None + * cdef public bint pydev_django_resolve_frame; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->pydev_notify_kill); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_notify_kill.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 6, __pyx_L1_error) + __pyx_v_self->pydev_notify_kill = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_notify_kill.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":7 + * cdef public int pydev_step_cmd; + * cdef public bint pydev_notify_kill; + * cdef public object pydev_smart_step_stop; # Actually, it's a frame or None # <<<<<<<<<<<<<< + * cdef public bint pydev_django_resolve_frame; + * cdef public object pydev_call_from_jinja2; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->pydev_smart_step_stop); + __pyx_r = __pyx_v_self->pydev_smart_step_stop; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->pydev_smart_step_stop); + __Pyx_DECREF(__pyx_v_self->pydev_smart_step_stop); + __pyx_v_self->pydev_smart_step_stop = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_smart_step_stop); + __Pyx_DECREF(__pyx_v_self->pydev_smart_step_stop); + __pyx_v_self->pydev_smart_step_stop = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":8 + * cdef public bint pydev_notify_kill; + * cdef public object pydev_smart_step_stop; # Actually, it's a frame or None + * cdef public bint pydev_django_resolve_frame; # <<<<<<<<<<<<<< + * cdef public object pydev_call_from_jinja2; + * cdef public object pydev_call_inside_jinja2; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->pydev_django_resolve_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_django_resolve_frame.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 8, __pyx_L1_error) + __pyx_v_self->pydev_django_resolve_frame = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_django_resolve_frame.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":9 + * cdef public object pydev_smart_step_stop; # Actually, it's a frame or None + * cdef public bint pydev_django_resolve_frame; + * cdef public object pydev_call_from_jinja2; # <<<<<<<<<<<<<< + * cdef public object pydev_call_inside_jinja2; + * cdef public bint is_tracing; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->pydev_call_from_jinja2); + __pyx_r = __pyx_v_self->pydev_call_from_jinja2; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->pydev_call_from_jinja2); + __Pyx_DECREF(__pyx_v_self->pydev_call_from_jinja2); + __pyx_v_self->pydev_call_from_jinja2 = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_call_from_jinja2); + __Pyx_DECREF(__pyx_v_self->pydev_call_from_jinja2); + __pyx_v_self->pydev_call_from_jinja2 = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":10 + * cdef public bint pydev_django_resolve_frame; + * cdef public object pydev_call_from_jinja2; + * cdef public object pydev_call_inside_jinja2; # <<<<<<<<<<<<<< + * cdef public bint is_tracing; + * cdef public tuple conditional_breakpoint_exception; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->pydev_call_inside_jinja2); + __pyx_r = __pyx_v_self->pydev_call_inside_jinja2; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->pydev_call_inside_jinja2); + __Pyx_DECREF(__pyx_v_self->pydev_call_inside_jinja2); + __pyx_v_self->pydev_call_inside_jinja2 = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_call_inside_jinja2); + __Pyx_DECREF(__pyx_v_self->pydev_call_inside_jinja2); + __pyx_v_self->pydev_call_inside_jinja2 = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":11 + * cdef public object pydev_call_from_jinja2; + * cdef public object pydev_call_inside_jinja2; + * cdef public bint is_tracing; # <<<<<<<<<<<<<< + * cdef public tuple conditional_breakpoint_exception; + * cdef public str pydev_message; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_tracing); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.is_tracing.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 11, __pyx_L1_error) + __pyx_v_self->is_tracing = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.is_tracing.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":12 + * cdef public object pydev_call_inside_jinja2; + * cdef public bint is_tracing; + * cdef public tuple conditional_breakpoint_exception; # <<<<<<<<<<<<<< + * cdef public str pydev_message; + * cdef public int suspend_type; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->conditional_breakpoint_exception); + __pyx_r = __pyx_v_self->conditional_breakpoint_exception; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyTuple_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(1, 12, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->conditional_breakpoint_exception); + __Pyx_DECREF(__pyx_v_self->conditional_breakpoint_exception); + __pyx_v_self->conditional_breakpoint_exception = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.conditional_breakpoint_exception.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->conditional_breakpoint_exception); + __Pyx_DECREF(__pyx_v_self->conditional_breakpoint_exception); + __pyx_v_self->conditional_breakpoint_exception = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":13 + * cdef public bint is_tracing; + * cdef public tuple conditional_breakpoint_exception; + * cdef public str pydev_message; # <<<<<<<<<<<<<< + * cdef public int suspend_type; + * cdef public int pydev_next_line; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->pydev_message); + __pyx_r = __pyx_v_self->pydev_message; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->pydev_message); + __Pyx_DECREF(__pyx_v_self->pydev_message); + __pyx_v_self->pydev_message = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_message.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_message); + __Pyx_DECREF(__pyx_v_self->pydev_message); + __pyx_v_self->pydev_message = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":14 + * cdef public tuple conditional_breakpoint_exception; + * cdef public str pydev_message; + * cdef public int suspend_type; # <<<<<<<<<<<<<< + * cdef public int pydev_next_line; + * cdef public str pydev_func_name; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->suspend_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.suspend_type.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 14, __pyx_L1_error) + __pyx_v_self->suspend_type = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.suspend_type.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":15 + * cdef public str pydev_message; + * cdef public int suspend_type; + * cdef public int pydev_next_line; # <<<<<<<<<<<<<< + * cdef public str pydev_func_name; + * cdef public bint suspended_at_unhandled; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_next_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_next_line.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 15, __pyx_L1_error) + __pyx_v_self->pydev_next_line = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_next_line.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":16 + * cdef public int suspend_type; + * cdef public int pydev_next_line; + * cdef public str pydev_func_name; # <<<<<<<<<<<<<< + * cdef public bint suspended_at_unhandled; + * cdef public str trace_suspend_type; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->pydev_func_name); + __pyx_r = __pyx_v_self->pydev_func_name; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(1, 16, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->pydev_func_name); + __Pyx_DECREF(__pyx_v_self->pydev_func_name); + __pyx_v_self->pydev_func_name = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.pydev_func_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->pydev_func_name); + __Pyx_DECREF(__pyx_v_self->pydev_func_name); + __pyx_v_self->pydev_func_name = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":17 + * cdef public int pydev_next_line; + * cdef public str pydev_func_name; + * cdef public bint suspended_at_unhandled; # <<<<<<<<<<<<<< + * cdef public str trace_suspend_type; + * cdef public object top_level_thread_tracer_no_back_frames; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->suspended_at_unhandled); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.suspended_at_unhandled.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 17, __pyx_L1_error) + __pyx_v_self->suspended_at_unhandled = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.suspended_at_unhandled.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":18 + * cdef public str pydev_func_name; + * cdef public bint suspended_at_unhandled; + * cdef public str trace_suspend_type; # <<<<<<<<<<<<<< + * cdef public object top_level_thread_tracer_no_back_frames; + * cdef public object top_level_thread_tracer_unhandled; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->trace_suspend_type); + __pyx_r = __pyx_v_self->trace_suspend_type; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(1, 18, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->trace_suspend_type); + __Pyx_DECREF(__pyx_v_self->trace_suspend_type); + __pyx_v_self->trace_suspend_type = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.trace_suspend_type.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->trace_suspend_type); + __Pyx_DECREF(__pyx_v_self->trace_suspend_type); + __pyx_v_self->trace_suspend_type = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":19 + * cdef public bint suspended_at_unhandled; + * cdef public str trace_suspend_type; + * cdef public object top_level_thread_tracer_no_back_frames; # <<<<<<<<<<<<<< + * cdef public object top_level_thread_tracer_unhandled; + * cdef public object thread_tracer; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __pyx_r = __pyx_v_self->top_level_thread_tracer_no_back_frames; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __Pyx_DECREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __pyx_v_self->top_level_thread_tracer_no_back_frames = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __Pyx_DECREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __pyx_v_self->top_level_thread_tracer_no_back_frames = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":20 + * cdef public str trace_suspend_type; + * cdef public object top_level_thread_tracer_no_back_frames; + * cdef public object top_level_thread_tracer_unhandled; # <<<<<<<<<<<<<< + * cdef public object thread_tracer; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __pyx_r = __pyx_v_self->top_level_thread_tracer_unhandled; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __Pyx_DECREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __pyx_v_self->top_level_thread_tracer_unhandled = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __Pyx_DECREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __pyx_v_self->top_level_thread_tracer_unhandled = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pxd":21 + * cdef public object top_level_thread_tracer_no_back_frames; + * cdef public object top_level_thread_tracer_unhandled; + * cdef public object thread_tracer; # <<<<<<<<<<<<<< + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->thread_tracer); + __pyx_r = __pyx_v_self->thread_tracer; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->thread_tracer); + __Pyx_DECREF(__pyx_v_self->thread_tracer); + __pyx_v_self->thread_tracer = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->thread_tracer); + __Pyx_DECREF(__pyx_v_self->thread_tracer); + __pyx_v_self->thread_tracer = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_6__reduce_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_t_12; + int __pyx_t_13; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.conditional_breakpoint_exception, self.is_tracing, self.pydev_call_from_jinja2, self.pydev_call_inside_jinja2, self.pydev_django_resolve_frame, self.pydev_func_name, self.pydev_message, self.pydev_next_line, self.pydev_notify_kill, self.pydev_original_step_cmd, self.pydev_smart_step_stop, self.pydev_state, self.pydev_step_cmd, self.pydev_step_stop, self.suspend_type, self.suspended_at_unhandled, self.thread_tracer, self.top_level_thread_tracer_no_back_frames, self.top_level_thread_tracer_unhandled, self.trace_suspend_type) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_tracing); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->pydev_django_resolve_frame); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_next_line); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_self->pydev_notify_kill); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_original_step_cmd); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_state); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->pydev_step_cmd); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_self->suspend_type); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyBool_FromLong(__pyx_v_self->suspended_at_unhandled); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(20); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_self->conditional_breakpoint_exception); + __Pyx_GIVEREF(__pyx_v_self->conditional_breakpoint_exception); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_self->conditional_breakpoint_exception); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_self->pydev_call_from_jinja2); + __Pyx_GIVEREF(__pyx_v_self->pydev_call_from_jinja2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_self->pydev_call_from_jinja2); + __Pyx_INCREF(__pyx_v_self->pydev_call_inside_jinja2); + __Pyx_GIVEREF(__pyx_v_self->pydev_call_inside_jinja2); + PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_v_self->pydev_call_inside_jinja2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_2); + __Pyx_INCREF(__pyx_v_self->pydev_func_name); + __Pyx_GIVEREF(__pyx_v_self->pydev_func_name); + PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_v_self->pydev_func_name); + __Pyx_INCREF(__pyx_v_self->pydev_message); + __Pyx_GIVEREF(__pyx_v_self->pydev_message); + PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_v_self->pydev_message); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 7, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 8, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_10, 9, __pyx_t_5); + __Pyx_INCREF(__pyx_v_self->pydev_smart_step_stop); + __Pyx_GIVEREF(__pyx_v_self->pydev_smart_step_stop); + PyTuple_SET_ITEM(__pyx_t_10, 10, __pyx_v_self->pydev_smart_step_stop); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 11, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 12, __pyx_t_7); + __Pyx_INCREF(__pyx_v_self->pydev_step_stop); + __Pyx_GIVEREF(__pyx_v_self->pydev_step_stop); + PyTuple_SET_ITEM(__pyx_t_10, 13, __pyx_v_self->pydev_step_stop); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_10, 14, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_10, 15, __pyx_t_9); + __Pyx_INCREF(__pyx_v_self->thread_tracer); + __Pyx_GIVEREF(__pyx_v_self->thread_tracer); + PyTuple_SET_ITEM(__pyx_t_10, 16, __pyx_v_self->thread_tracer); + __Pyx_INCREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + __Pyx_GIVEREF(__pyx_v_self->top_level_thread_tracer_no_back_frames); + PyTuple_SET_ITEM(__pyx_t_10, 17, __pyx_v_self->top_level_thread_tracer_no_back_frames); + __Pyx_INCREF(__pyx_v_self->top_level_thread_tracer_unhandled); + __Pyx_GIVEREF(__pyx_v_self->top_level_thread_tracer_unhandled); + PyTuple_SET_ITEM(__pyx_t_10, 18, __pyx_v_self->top_level_thread_tracer_unhandled); + __Pyx_INCREF(__pyx_v_self->trace_suspend_type); + __Pyx_GIVEREF(__pyx_v_self->trace_suspend_type); + PyTuple_SET_ITEM(__pyx_t_10, 19, __pyx_v_self->trace_suspend_type); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_9 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_10); + __pyx_t_10 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.conditional_breakpoint_exception, self.is_tracing, self.pydev_call_from_jinja2, self.pydev_call_inside_jinja2, self.pydev_django_resolve_frame, self.pydev_func_name, self.pydev_message, self.pydev_next_line, self.pydev_notify_kill, self.pydev_original_step_cmd, self.pydev_smart_step_stop, self.pydev_state, self.pydev_step_cmd, self.pydev_step_stop, self.suspend_type, self.suspended_at_unhandled, self.thread_tracer, self.top_level_thread_tracer_no_back_frames, self.top_level_thread_tracer_unhandled, self.trace_suspend_type) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_10 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_v__dict = __pyx_t_10; + __pyx_t_10 = 0; + + /* "(tree fragment)":7 + * state = (self.conditional_breakpoint_exception, self.is_tracing, self.pydev_call_from_jinja2, self.pydev_call_inside_jinja2, self.pydev_django_resolve_frame, self.pydev_func_name, self.pydev_message, self.pydev_next_line, self.pydev_notify_kill, self.pydev_original_step_cmd, self.pydev_smart_step_stop, self.pydev_state, self.pydev_step_cmd, self.pydev_step_stop, self.suspend_type, self.suspended_at_unhandled, self.thread_tracer, self.top_level_thread_tracer_no_back_frames, self.top_level_thread_tracer_unhandled, self.trace_suspend_type) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_11 = (__pyx_v__dict != Py_None); + __pyx_t_12 = (__pyx_t_11 != 0); + if (__pyx_t_12) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v__dict); + __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_9)); + __pyx_t_9 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.conditional_breakpoint_exception is not None or self.pydev_call_from_jinja2 is not None or self.pydev_call_inside_jinja2 is not None or self.pydev_func_name is not None or self.pydev_message is not None or self.pydev_smart_step_stop is not None or self.pydev_step_stop is not None or self.thread_tracer is not None or self.top_level_thread_tracer_no_back_frames is not None or self.top_level_thread_tracer_unhandled is not None or self.trace_suspend_type is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.conditional_breakpoint_exception, self.is_tracing, self.pydev_call_from_jinja2, self.pydev_call_inside_jinja2, self.pydev_django_resolve_frame, self.pydev_func_name, self.pydev_message, self.pydev_next_line, self.pydev_notify_kill, self.pydev_original_step_cmd, self.pydev_smart_step_stop, self.pydev_state, self.pydev_step_cmd, self.pydev_step_stop, self.suspend_type, self.suspended_at_unhandled, self.thread_tracer, self.top_level_thread_tracer_no_back_frames, self.top_level_thread_tracer_unhandled, self.trace_suspend_type) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.conditional_breakpoint_exception is not None or self.pydev_call_from_jinja2 is not None or self.pydev_call_inside_jinja2 is not None or self.pydev_func_name is not None or self.pydev_message is not None or self.pydev_smart_step_stop is not None or self.pydev_step_stop is not None or self.thread_tracer is not None or self.top_level_thread_tracer_no_back_frames is not None or self.top_level_thread_tracer_unhandled is not None or self.trace_suspend_type is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, None), state + */ + /*else*/ { + __pyx_t_11 = (__pyx_v_self->conditional_breakpoint_exception != ((PyObject*)Py_None)); + __pyx_t_13 = (__pyx_t_11 != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_12 = __pyx_t_13; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_13 = (__pyx_v_self->pydev_call_from_jinja2 != Py_None); + __pyx_t_11 = (__pyx_t_13 != 0); + if (!__pyx_t_11) { + } else { + __pyx_t_12 = __pyx_t_11; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_11 = (__pyx_v_self->pydev_call_inside_jinja2 != Py_None); + __pyx_t_13 = (__pyx_t_11 != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_12 = __pyx_t_13; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_13 = (__pyx_v_self->pydev_func_name != ((PyObject*)Py_None)); + __pyx_t_11 = (__pyx_t_13 != 0); + if (!__pyx_t_11) { + } else { + __pyx_t_12 = __pyx_t_11; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_11 = (__pyx_v_self->pydev_message != ((PyObject*)Py_None)); + __pyx_t_13 = (__pyx_t_11 != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_12 = __pyx_t_13; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_13 = (__pyx_v_self->pydev_smart_step_stop != Py_None); + __pyx_t_11 = (__pyx_t_13 != 0); + if (!__pyx_t_11) { + } else { + __pyx_t_12 = __pyx_t_11; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_11 = (__pyx_v_self->pydev_step_stop != Py_None); + __pyx_t_13 = (__pyx_t_11 != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_12 = __pyx_t_13; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_13 = (__pyx_v_self->thread_tracer != Py_None); + __pyx_t_11 = (__pyx_t_13 != 0); + if (!__pyx_t_11) { + } else { + __pyx_t_12 = __pyx_t_11; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_11 = (__pyx_v_self->top_level_thread_tracer_no_back_frames != Py_None); + __pyx_t_13 = (__pyx_t_11 != 0); + if (!__pyx_t_13) { + } else { + __pyx_t_12 = __pyx_t_13; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_13 = (__pyx_v_self->top_level_thread_tracer_unhandled != Py_None); + __pyx_t_11 = (__pyx_t_13 != 0); + if (!__pyx_t_11) { + } else { + __pyx_t_12 = __pyx_t_11; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_11 = (__pyx_v_self->trace_suspend_type != ((PyObject*)Py_None)); + __pyx_t_13 = (__pyx_t_11 != 0); + __pyx_t_12 = __pyx_t_13; + __pyx_L4_bool_binop_done:; + __pyx_v_use_setstate = __pyx_t_12; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.conditional_breakpoint_exception is not None or self.pydev_call_from_jinja2 is not None or self.pydev_call_inside_jinja2 is not None or self.pydev_func_name is not None or self.pydev_message is not None or self.pydev_smart_step_stop is not None or self.pydev_step_stop is not None or self.thread_tracer is not None or self.top_level_thread_tracer_no_back_frames is not None or self.top_level_thread_tracer_unhandled is not None or self.trace_suspend_type is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, None), state + * else: + */ + __pyx_t_12 = (__pyx_v_use_setstate != 0); + if (__pyx_t_12) { + + /* "(tree fragment)":13 + * use_setstate = self.conditional_breakpoint_exception is not None or self.pydev_call_from_jinja2 is not None or self.pydev_call_inside_jinja2 is not None or self.pydev_func_name is not None or self.pydev_message is not None or self.pydev_smart_step_stop is not None or self.pydev_step_stop is not None or self.thread_tracer is not None or self.top_level_thread_tracer_no_back_frames is not None or self.top_level_thread_tracer_unhandled is not None or self.trace_suspend_type is not None + * if use_setstate: + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pyx_unpickle_PyDBAdditionalThr); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_112182380); + __Pyx_GIVEREF(__pyx_int_112182380); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_112182380); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_10, 2, Py_None); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_10); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_state); + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.conditional_breakpoint_exception is not None or self.pydev_call_from_jinja2 is not None or self.pydev_call_inside_jinja2 is not None or self.pydev_func_name is not None or self.pydev_message is not None or self.pydev_smart_step_stop is not None or self.pydev_step_stop is not None or self.thread_tracer is not None or self.top_level_thread_tracer_no_back_frames is not None or self.top_level_thread_tracer_unhandled is not None or self.trace_suspend_type is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, None), state + * else: + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pyx_unpickle_PyDBAdditionalThr); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_112182380); + __Pyx_GIVEREF(__pyx_int_112182380); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_int_112182380); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_state); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10); + __pyx_t_8 = 0; + __pyx_t_10 = 0; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_8__setstate_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBAdditionalThreadInfo__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_PyDBAdditionalThreadInfo, (type(self), 0x6afc46c, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":148 + * + * + * def set_additional_thread_info(thread): # <<<<<<<<<<<<<< + * try: + * additional_info = thread.additional_info + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_5set_additional_thread_info(PyObject *__pyx_self, PyObject *__pyx_v_thread); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_5set_additional_thread_info = {"set_additional_thread_info", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_5set_additional_thread_info, METH_O, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_5set_additional_thread_info(PyObject *__pyx_self, PyObject *__pyx_v_thread) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_additional_thread_info (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_4set_additional_thread_info(__pyx_self, ((PyObject *)__pyx_v_thread)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_4set_additional_thread_info(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_thread) { + PyObject *__pyx_v_additional_info = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + __Pyx_RefNannySetupContext("set_additional_thread_info", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":149 + * + * def set_additional_thread_info(thread): + * try: # <<<<<<<<<<<<<< + * additional_info = thread.additional_info + * if additional_info is None: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":150 + * def set_additional_thread_info(thread): + * try: + * additional_info = thread.additional_info # <<<<<<<<<<<<<< + * if additional_info is None: + * raise AttributeError() + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread, __pyx_n_s_additional_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 150, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_additional_info = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":151 + * try: + * additional_info = thread.additional_info + * if additional_info is None: # <<<<<<<<<<<<<< + * raise AttributeError() + * except: + */ + __pyx_t_5 = (__pyx_v_additional_info == Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (unlikely(__pyx_t_6)) { + + /* "_pydevd_bundle/pydevd_cython.pyx":152 + * additional_info = thread.additional_info + * if additional_info is None: + * raise AttributeError() # <<<<<<<<<<<<<< + * except: + * with _set_additional_thread_info_lock: + */ + __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_builtin_AttributeError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 152, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 152, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":151 + * try: + * additional_info = thread.additional_info + * if additional_info is None: # <<<<<<<<<<<<<< + * raise AttributeError() + * except: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":149 + * + * def set_additional_thread_info(thread): + * try: # <<<<<<<<<<<<<< + * additional_info = thread.additional_info + * if additional_info is None: + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":153 + * if additional_info is None: + * raise AttributeError() + * except: # <<<<<<<<<<<<<< + * with _set_additional_thread_info_lock: + * # If it's not there, set it within a lock to avoid any racing + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.set_additional_thread_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_7, &__pyx_t_8) < 0) __PYX_ERR(0, 153, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_8); + + /* "_pydevd_bundle/pydevd_cython.pyx":154 + * raise AttributeError() + * except: + * with _set_additional_thread_info_lock: # <<<<<<<<<<<<<< + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + */ + /*with:*/ { + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_set_additional_thread_info_lock); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 154, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyObject_LookupSpecial(__pyx_t_9, __pyx_n_s_exit); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 154, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = __Pyx_PyObject_LookupSpecial(__pyx_t_9, __pyx_n_s_enter); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 154, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_11 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 154, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":157 + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + * additional_info = getattr(thread, 'additional_info', None) # <<<<<<<<<<<<<< + * if additional_info is None: + * additional_info = PyDBAdditionalThreadInfo() + */ + __pyx_t_9 = __Pyx_GetAttr3(__pyx_v_thread, __pyx_n_s_additional_info, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 157, __pyx_L18_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_XDECREF_SET(__pyx_v_additional_info, __pyx_t_9); + __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":158 + * # conditions. + * additional_info = getattr(thread, 'additional_info', None) + * if additional_info is None: # <<<<<<<<<<<<<< + * additional_info = PyDBAdditionalThreadInfo() + * thread.additional_info = additional_info + */ + __pyx_t_6 = (__pyx_v_additional_info == Py_None); + __pyx_t_5 = (__pyx_t_6 != 0); + if (__pyx_t_5) { + + /* "_pydevd_bundle/pydevd_cython.pyx":159 + * additional_info = getattr(thread, 'additional_info', None) + * if additional_info is None: + * additional_info = PyDBAdditionalThreadInfo() # <<<<<<<<<<<<<< + * thread.additional_info = additional_info + * + */ + __pyx_t_9 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 159, __pyx_L18_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF_SET(__pyx_v_additional_info, __pyx_t_9); + __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":158 + * # conditions. + * additional_info = getattr(thread, 'additional_info', None) + * if additional_info is None: # <<<<<<<<<<<<<< + * additional_info = PyDBAdditionalThreadInfo() + * thread.additional_info = additional_info + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":160 + * if additional_info is None: + * additional_info = PyDBAdditionalThreadInfo() + * thread.additional_info = additional_info # <<<<<<<<<<<<<< + * + * return additional_info + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_thread, __pyx_n_s_additional_info, __pyx_v_additional_info) < 0) __PYX_ERR(0, 160, __pyx_L18_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":154 + * raise AttributeError() + * except: + * with _set_additional_thread_info_lock: # <<<<<<<<<<<<<< + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + */ + } + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L25_try_end; + __pyx_L18_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.set_additional_thread_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_11, &__pyx_t_12) < 0) __PYX_ERR(0, 154, __pyx_L20_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_Pack(3, __pyx_t_9, __pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 154, __pyx_L20_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_13, NULL); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 154, __pyx_L20_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_17); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + if (__pyx_t_5 < 0) __PYX_ERR(0, 154, __pyx_L20_except_error) + __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ErrRestoreWithState(__pyx_t_9, __pyx_t_11, __pyx_t_12); + __pyx_t_9 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; + __PYX_ERR(0, 154, __pyx_L20_except_error) + } + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L19_exception_handled; + } + __pyx_L20_except_error:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + goto __pyx_L5_except_error; + __pyx_L19_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_L25_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_10) { + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__2, NULL); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 154, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + goto __pyx_L17; + } + __pyx_L17:; + } + goto __pyx_L30; + __pyx_L12_error:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L5_except_error; + __pyx_L30:; + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L4_exception_handled; + } + __pyx_L5_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":149 + * + * def set_additional_thread_info(thread): + * try: # <<<<<<<<<<<<<< + * additional_info = thread.additional_info + * if additional_info is None: + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":162 + * thread.additional_info = additional_info + * + * return additional_info # <<<<<<<<<<<<<< + * import linecache + * import os.path + */ + __Pyx_XDECREF(__pyx_r); + if (unlikely(!__pyx_v_additional_info)) { __Pyx_RaiseUnboundLocalError("additional_info"); __PYX_ERR(0, 162, __pyx_L1_error) } + __Pyx_INCREF(__pyx_v_additional_info); + __pyx_r = __pyx_v_additional_info; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":148 + * + * + * def set_additional_thread_info(thread): # <<<<<<<<<<<<<< + * try: + * additional_info = thread.additional_info + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.set_additional_thread_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_additional_info); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":198 + * except ImportError: + * + * def send_signature_call_trace(*args, **kwargs): # <<<<<<<<<<<<<< + * pass + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_7send_signature_call_trace(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_7send_signature_call_trace = {"send_signature_call_trace", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_7send_signature_call_trace, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_7send_signature_call_trace(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_args = 0; + CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("send_signature_call_trace (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "send_signature_call_trace", 1))) return NULL; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_6send_signature_call_trace(__pyx_self, __pyx_v_args, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_6send_signature_call_trace(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_args, CYTHON_UNUSED PyObject *__pyx_v_kwargs) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("send_signature_call_trace", 0); + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":232 + * cdef tuple _args + * cdef int should_skip + * def __init__(self, tuple args): # <<<<<<<<<<<<<< + * self._args = args # In the cython version we don't need to pass the frame + * self.should_skip = -1 # On cythonized version, put in instance. + */ + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_args,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 232, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_args = ((PyObject*)values[0]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 232, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_args), (&PyTuple_Type), 1, "args", 1))) __PYX_ERR(0, 232, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame___init__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_args); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_args) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":233 + * cdef int should_skip + * def __init__(self, tuple args): + * self._args = args # In the cython version we don't need to pass the frame # <<<<<<<<<<<<<< + * self.should_skip = -1 # On cythonized version, put in instance. + * # ELSE + */ + __Pyx_INCREF(__pyx_v_args); + __Pyx_GIVEREF(__pyx_v_args); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = __pyx_v_args; + + /* "_pydevd_bundle/pydevd_cython.pyx":234 + * def __init__(self, tuple args): + * self._args = args # In the cython version we don't need to pass the frame + * self.should_skip = -1 # On cythonized version, put in instance. # <<<<<<<<<<<<<< + * # ELSE + * # should_skip = -1 # Default value in class (put in instance on set). + */ + __pyx_v_self->should_skip = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":232 + * cdef tuple _args + * cdef int should_skip + * def __init__(self, tuple args): # <<<<<<<<<<<<<< + * self._args = args # In the cython version we don't need to pass the frame + * self.should_skip = -1 # On cythonized version, put in instance. + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":244 + * # ENDIF + * + * def set_suspend(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self._args[0].set_suspend(*args, **kwargs) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_3set_suspend(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_3set_suspend(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_suspend (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "set_suspend", 1))) return NULL; + if (unlikely(__pyx_kwds)) { + __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + } else { + __pyx_v_kwargs = NULL; + } + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_2set_suspend(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_2set_suspend(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("set_suspend", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":245 + * + * def set_suspend(self, *args, **kwargs): + * self._args[0].set_suspend(*args, **kwargs) # <<<<<<<<<<<<<< + * + * def do_wait_suspend(self, *args, **kwargs): + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 245, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_set_suspend); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":244 + * # ENDIF + * + * def set_suspend(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self._args[0].set_suspend(*args, **kwargs) + * + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.set_suspend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":247 + * self._args[0].set_suspend(*args, **kwargs) + * + * def do_wait_suspend(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self._args[0].do_wait_suspend(*args, **kwargs) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_5do_wait_suspend(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_5do_wait_suspend(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_kwargs = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("do_wait_suspend (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "do_wait_suspend", 1))) return NULL; + if (unlikely(__pyx_kwds)) { + __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + } else { + __pyx_v_kwargs = NULL; + } + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_4do_wait_suspend(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_4do_wait_suspend(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannySetupContext("do_wait_suspend", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":248 + * + * def do_wait_suspend(self, *args, **kwargs): + * self._args[0].do_wait_suspend(*args, **kwargs) # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 248, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_do_wait_suspend); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_v_args, __pyx_v_kwargs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":247 + * self._args[0].set_suspend(*args, **kwargs) + * + * def do_wait_suspend(self, *args, **kwargs): # <<<<<<<<<<<<<< + * self._args[0].do_wait_suspend(*args, **kwargs) + * + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.do_wait_suspend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":251 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * def trace_exception(self, frame, str event, arg): # <<<<<<<<<<<<<< + * cdef bint should_stop; + * # ELSE + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_7trace_exception(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_7trace_exception(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trace_exception (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_exception", 1, 3, 3, 1); __PYX_ERR(0, 251, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_exception", 1, 3, 3, 2); __PYX_ERR(0, 251, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trace_exception") < 0)) __PYX_ERR(0, 251, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = ((PyObject*)values[1]); + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("trace_exception", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 251, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_event), (&PyString_Type), 1, "event", 1))) __PYX_ERR(0, 251, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_6trace_exception(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_6trace_exception(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + int __pyx_v_should_stop; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + __Pyx_RefNannySetupContext("trace_exception", 0); + __Pyx_INCREF(__pyx_v_frame); + + /* "_pydevd_bundle/pydevd_cython.pyx":256 + * # def trace_exception(self, frame, event, arg): + * # ENDIF + * if event == 'exception': # <<<<<<<<<<<<<< + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_exception, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 256, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":257 + * # ENDIF + * if event == 'exception': + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) # <<<<<<<<<<<<<< + * + * if should_stop: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_should_stop_on_exception); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_arg); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 257, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_5); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_5), 2) < 0) __PYX_ERR(0, 257, __pyx_L1_error) + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 257, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_should_stop = __pyx_t_2; + __Pyx_DECREF_SET(__pyx_v_frame, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":259 + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * + * if should_stop: # <<<<<<<<<<<<<< + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch + */ + __pyx_t_2 = (__pyx_v_should_stop != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":260 + * + * if should_stop: + * self.handle_exception(frame, event, arg) # <<<<<<<<<<<<<< + * return self.trace_dispatch + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_handle_exception); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_5 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_6, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_6, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_6, __pyx_v_arg); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":261 + * if should_stop: + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch # <<<<<<<<<<<<<< + * + * return self.trace_exception + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 261, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":259 + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * + * if should_stop: # <<<<<<<<<<<<<< + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":256 + * # def trace_exception(self, frame, event, arg): + * # ENDIF + * if event == 'exception': # <<<<<<<<<<<<<< + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":263 + * return self.trace_dispatch + * + * return self.trace_exception # <<<<<<<<<<<<<< + * + * def trace_return(self, frame, event, arg): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_exception); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":251 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * def trace_exception(self, frame, str event, arg): # <<<<<<<<<<<<<< + * cdef bint should_stop; + * # ELSE + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_frame); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":265 + * return self.trace_exception + * + * def trace_return(self, frame, event, arg): # <<<<<<<<<<<<<< + * if event == 'return': + * main_debugger, filename = self._args[0], self._args[1] + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_9trace_return(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_9trace_return(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trace_return (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_return", 1, 3, 3, 1); __PYX_ERR(0, 265, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_return", 1, 3, 3, 2); __PYX_ERR(0, 265, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trace_return") < 0)) __PYX_ERR(0, 265, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = values[1]; + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("trace_return", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 265, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_return", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_8trace_return(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_8trace_return(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_main_debugger = NULL; + PyObject *__pyx_v_filename = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("trace_return", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":266 + * + * def trace_return(self, frame, event, arg): + * if event == 'return': # <<<<<<<<<<<<<< + * main_debugger, filename = self._args[0], self._args[1] + * send_signature_return_trace(main_debugger, frame, filename, arg) + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_return, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 266, __pyx_L1_error) + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":267 + * def trace_return(self, frame, event, arg): + * if event == 'return': + * main_debugger, filename = self._args[0], self._args[1] # <<<<<<<<<<<<<< + * send_signature_return_trace(main_debugger, frame, filename, arg) + * return self.trace_return + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 267, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 267, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 267, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_main_debugger = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_v_filename = __pyx_t_3; + __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":268 + * if event == 'return': + * main_debugger, filename = self._args[0], self._args[1] + * send_signature_return_trace(main_debugger, frame, filename, arg) # <<<<<<<<<<<<<< + * return self.trace_return + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_send_signature_return_trace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_filename, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_filename, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_6 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_filename); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_5, __pyx_v_arg); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":266 + * + * def trace_return(self, frame, event, arg): + * if event == 'return': # <<<<<<<<<<<<<< + * main_debugger, filename = self._args[0], self._args[1] + * send_signature_return_trace(main_debugger, frame, filename, arg) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":269 + * main_debugger, filename = self._args[0], self._args[1] + * send_signature_return_trace(main_debugger, frame, filename, arg) + * return self.trace_return # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_return); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":265 + * return self.trace_exception + * + * def trace_return(self, frame, event, arg): # <<<<<<<<<<<<<< + * if event == 'return': + * main_debugger, filename = self._args[0], self._args[1] + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_return", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_main_debugger); + __Pyx_XDECREF(__pyx_v_filename); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":272 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * def should_stop_on_exception(self, frame, str event, arg): # <<<<<<<<<<<<<< + * cdef PyDBAdditionalThreadInfo info; + * cdef bint flag; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_11should_stop_on_exception(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_11should_stop_on_exception(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + CYTHON_UNUSED PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("should_stop_on_exception (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("should_stop_on_exception", 1, 3, 3, 1); __PYX_ERR(0, 272, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("should_stop_on_exception", 1, 3, 3, 2); __PYX_ERR(0, 272, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "should_stop_on_exception") < 0)) __PYX_ERR(0, 272, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = ((PyObject*)values[1]); + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("should_stop_on_exception", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 272, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.should_stop_on_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_event), (&PyString_Type), 1, "event", 1))) __PYX_ERR(0, 272, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_10should_stop_on_exception(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_10should_stop_on_exception(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, CYTHON_UNUSED PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_info = 0; + PyObject *__pyx_v_main_debugger = NULL; + PyObject *__pyx_v_should_stop = NULL; + PyObject *__pyx_v_exception = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_v_trace = NULL; + PyObject *__pyx_v_exception_breakpoint = NULL; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_eval_result = NULL; + PyObject *__pyx_v_was_just_raised = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *(*__pyx_t_6)(PyObject *); + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + __Pyx_RefNannySetupContext("should_stop_on_exception", 0); + __Pyx_INCREF(__pyx_v_frame); + + /* "_pydevd_bundle/pydevd_cython.pyx":280 + * + * # main_debugger, _filename, info, _thread = self._args + * main_debugger = self._args[0] # <<<<<<<<<<<<<< + * info = self._args[2] + * should_stop = False + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 280, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_main_debugger = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":281 + * # main_debugger, _filename, info, _thread = self._args + * main_debugger = self._args[0] + * info = self._args[2] # <<<<<<<<<<<<<< + * should_stop = False + * + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 281, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo))))) __PYX_ERR(0, 281, __pyx_L1_error) + __pyx_v_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":282 + * main_debugger = self._args[0] + * info = self._args[2] + * should_stop = False # <<<<<<<<<<<<<< + * + * # 2 = 2 + */ + __Pyx_INCREF(Py_False); + __pyx_v_should_stop = Py_False; + + /* "_pydevd_bundle/pydevd_cython.pyx":285 + * + * # 2 = 2 + * if info.pydev_state != 2: # and breakpoint is not None: # <<<<<<<<<<<<<< + * exception, value, trace = arg + * + */ + __pyx_t_2 = ((__pyx_v_info->pydev_state != 2) != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":286 + * # 2 = 2 + * if info.pydev_state != 2: # and breakpoint is not None: + * exception, value, trace = arg # <<<<<<<<<<<<<< + * + * if trace is not None and hasattr(trace, 'tb_next'): + */ + if ((likely(PyTuple_CheckExact(__pyx_v_arg))) || (PyList_CheckExact(__pyx_v_arg))) { + PyObject* sequence = __pyx_v_arg; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 286, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + __pyx_t_4 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_v_arg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 286, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 2; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 3) < 0) __PYX_ERR(0, 286, __pyx_L1_error) + __pyx_t_6 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5_unpacking_done; + __pyx_L4_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 286, __pyx_L1_error) + __pyx_L5_unpacking_done:; + } + __pyx_v_exception = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_v_value = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_v_trace = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":288 + * exception, value, trace = arg + * + * if trace is not None and hasattr(trace, 'tb_next'): # <<<<<<<<<<<<<< + * # on jython trace is None on the first event and it may not have a tb_next. + * + */ + __pyx_t_7 = (__pyx_v_trace != Py_None); + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + } else { + __pyx_t_2 = __pyx_t_8; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_8 = __Pyx_HasAttr(__pyx_v_trace, __pyx_n_s_tb_next); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 288, __pyx_L1_error) + __pyx_t_7 = (__pyx_t_8 != 0); + __pyx_t_2 = __pyx_t_7; + __pyx_L7_bool_binop_done:; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":291 + * # on jython trace is None on the first event and it may not have a tb_next. + * + * should_stop = False # <<<<<<<<<<<<<< + * exception_breakpoint = None + * try: + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_should_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":292 + * + * should_stop = False + * exception_breakpoint = None # <<<<<<<<<<<<<< + * try: + * if main_debugger.plugin is not None: + */ + __Pyx_INCREF(Py_None); + __pyx_v_exception_breakpoint = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":293 + * should_stop = False + * exception_breakpoint = None + * try: # <<<<<<<<<<<<<< + * if main_debugger.plugin is not None: + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":294 + * exception_breakpoint = None + * try: + * if main_debugger.plugin is not None: # <<<<<<<<<<<<<< + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + * if result: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_plugin); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 294, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = (__pyx_t_4 != Py_None); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = (__pyx_t_2 != 0); + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":295 + * try: + * if main_debugger.plugin is not None: + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) # <<<<<<<<<<<<<< + * if result: + * should_stop, frame = result + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_plugin); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 295, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exception_break); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_12 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_12 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[6] = {__pyx_t_3, __pyx_v_main_debugger, ((PyObject *)__pyx_v_self), __pyx_v_frame, __pyx_v_self->_args, __pyx_v_arg}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_12, 5+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 295, __pyx_L9_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[6] = {__pyx_t_3, __pyx_v_main_debugger, ((PyObject *)__pyx_v_self), __pyx_v_frame, __pyx_v_self->_args, __pyx_v_arg}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_12, 5+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 295, __pyx_L9_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_5 = PyTuple_New(5+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 295, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_12, __pyx_v_main_debugger); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_12, ((PyObject *)__pyx_v_self)); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_12, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_12, __pyx_v_self->_args); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_5, 4+__pyx_t_12, __pyx_v_arg); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 295, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_result = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":296 + * if main_debugger.plugin is not None: + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + * if result: # <<<<<<<<<<<<<< + * should_stop, frame = result + * except: + */ + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 296, __pyx_L9_error) + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":297 + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + * if result: + * should_stop, frame = result # <<<<<<<<<<<<<< + * except: + * pydev_log.exception() + */ + if ((likely(PyTuple_CheckExact(__pyx_v_result))) || (PyList_CheckExact(__pyx_v_result))) { + PyObject* sequence = __pyx_v_result; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 297, __pyx_L9_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 297, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 297, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_v_result); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 297, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L17_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_1 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L17_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 297, __pyx_L9_error) + __pyx_t_6 = NULL; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L18_unpacking_done; + __pyx_L17_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 297, __pyx_L9_error) + __pyx_L18_unpacking_done:; + } + __Pyx_DECREF_SET(__pyx_v_should_stop, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_frame, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":296 + * if main_debugger.plugin is not None: + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + * if result: # <<<<<<<<<<<<<< + * should_stop, frame = result + * except: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":294 + * exception_breakpoint = None + * try: + * if main_debugger.plugin is not None: # <<<<<<<<<<<<<< + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + * if result: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":293 + * should_stop = False + * exception_breakpoint = None + * try: # <<<<<<<<<<<<<< + * if main_debugger.plugin is not None: + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + */ + } + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L14_try_end; + __pyx_L9_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":298 + * if result: + * should_stop, frame = result + * except: # <<<<<<<<<<<<<< + * pydev_log.exception() + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.should_stop_on_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 298, __pyx_L11_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); + + /* "_pydevd_bundle/pydevd_cython.pyx":299 + * should_stop, frame = result + * except: + * pydev_log.exception() # <<<<<<<<<<<<<< + * + * if not should_stop: + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 299, __pyx_L11_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_exception); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 299, __pyx_L11_except_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_3 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 299, __pyx_L11_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L10_exception_handled; + } + __pyx_L11_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":293 + * should_stop = False + * exception_breakpoint = None + * try: # <<<<<<<<<<<<<< + * if main_debugger.plugin is not None: + * result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + */ + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + goto __pyx_L1_error; + __pyx_L10_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + __pyx_L14_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":301 + * pydev_log.exception() + * + * if not should_stop: # <<<<<<<<<<<<<< + * # It was not handled by any plugin, lets check exception breakpoints. + * exception_breakpoint = main_debugger.get_exception_breakpoint( + */ + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_should_stop); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 301, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_7) != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":303 + * if not should_stop: + * # It was not handled by any plugin, lets check exception breakpoints. + * exception_breakpoint = main_debugger.get_exception_breakpoint( # <<<<<<<<<<<<<< + * exception, main_debugger.break_on_caught_exceptions) + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_get_exception_breakpoint); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "_pydevd_bundle/pydevd_cython.pyx":304 + * # It was not handled by any plugin, lets check exception breakpoints. + * exception_breakpoint = main_debugger.get_exception_breakpoint( + * exception, main_debugger.break_on_caught_exceptions) # <<<<<<<<<<<<<< + * + * if exception_breakpoint is not None: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_break_on_caught_exceptions); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = NULL; + __pyx_t_12 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_12 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_exception, __pyx_t_1}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 303, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_exception, __pyx_t_1}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 303, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_14 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_exception); + __Pyx_GIVEREF(__pyx_v_exception); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_12, __pyx_v_exception); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_12, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 303, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_exception_breakpoint, __pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":306 + * exception, main_debugger.break_on_caught_exceptions) + * + * if exception_breakpoint is not None: # <<<<<<<<<<<<<< + * if exception is SystemExit and main_debugger.ignore_system_exit_code(value): + * return False, frame + */ + __pyx_t_2 = (__pyx_v_exception_breakpoint != Py_None); + __pyx_t_7 = (__pyx_t_2 != 0); + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":307 + * + * if exception_breakpoint is not None: + * if exception is SystemExit and main_debugger.ignore_system_exit_code(value): # <<<<<<<<<<<<<< + * return False, frame + * + */ + __pyx_t_2 = (__pyx_v_exception == __pyx_builtin_SystemExit); + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { + } else { + __pyx_t_7 = __pyx_t_8; + goto __pyx_L24_bool_binop_done; + } + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_ignore_system_exit_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_5 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_14, __pyx_v_value) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_value); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 307, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_7 = __pyx_t_8; + __pyx_L24_bool_binop_done:; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":308 + * if exception_breakpoint is not None: + * if exception is SystemExit and main_debugger.ignore_system_exit_code(value): + * return False, frame # <<<<<<<<<<<<<< + * + * if exception_breakpoint.condition is not None: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 308, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":307 + * + * if exception_breakpoint is not None: + * if exception is SystemExit and main_debugger.ignore_system_exit_code(value): # <<<<<<<<<<<<<< + * return False, frame + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":310 + * return False, frame + * + * if exception_breakpoint.condition is not None: # <<<<<<<<<<<<<< + * eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + * if not eval_result: + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_exception_breakpoint, __pyx_n_s_condition); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 310, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = (__pyx_t_5 != Py_None); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":311 + * + * if exception_breakpoint.condition is not None: + * eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) # <<<<<<<<<<<<<< + * if not eval_result: + * return False, frame + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_handle_breakpoint_condition); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = NULL; + __pyx_t_12 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_12 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_14, ((PyObject *)__pyx_v_info), __pyx_v_exception_breakpoint, __pyx_v_frame}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_14, ((PyObject *)__pyx_v_info), __pyx_v_exception_breakpoint, __pyx_v_frame}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_1 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); __pyx_t_14 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_info)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_info)); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_12, ((PyObject *)__pyx_v_info)); + __Pyx_INCREF(__pyx_v_exception_breakpoint); + __Pyx_GIVEREF(__pyx_v_exception_breakpoint); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_12, __pyx_v_exception_breakpoint); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_12, __pyx_v_frame); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 311, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_eval_result = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":312 + * if exception_breakpoint.condition is not None: + * eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + * if not eval_result: # <<<<<<<<<<<<<< + * return False, frame + * + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_eval_result); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 312, __pyx_L1_error) + __pyx_t_7 = ((!__pyx_t_8) != 0); + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":313 + * eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + * if not eval_result: + * return False, frame # <<<<<<<<<<<<<< + * + * if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 313, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":312 + * if exception_breakpoint.condition is not None: + * eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + * if not eval_result: # <<<<<<<<<<<<<< + * return False, frame + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":310 + * return False, frame + * + * if exception_breakpoint.condition is not None: # <<<<<<<<<<<<<< + * eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + * if not eval_result: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":315 + * return False, frame + * + * if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): # <<<<<<<<<<<<<< + * pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) + * return False, frame + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_exclude_exception_by_filter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = NULL; + __pyx_t_12 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_12 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_exception_breakpoint, __pyx_v_trace, Py_False}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_exception_breakpoint, __pyx_v_trace, Py_False}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_14 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_exception_breakpoint); + __Pyx_GIVEREF(__pyx_v_exception_breakpoint); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_12, __pyx_v_exception_breakpoint); + __Pyx_INCREF(__pyx_v_trace); + __Pyx_GIVEREF(__pyx_v_trace); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_12, __pyx_v_trace); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_14, 2+__pyx_t_12, Py_False); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 315, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":316 + * + * if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): + * pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) # <<<<<<<<<<<<<< + * return False, frame + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_debug); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_exception); + __Pyx_GIVEREF(__pyx_v_exception); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_exception); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_Ignore_exception_s_in_library_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 316, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":317 + * if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): + * pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) + * return False, frame # <<<<<<<<<<<<<< + * + * if ignore_exception_trace(trace): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 317, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":315 + * return False, frame + * + * if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): # <<<<<<<<<<<<<< + * pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) + * return False, frame + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":319 + * return False, frame + * + * if ignore_exception_trace(trace): # <<<<<<<<<<<<<< + * return False, frame + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_ignore_exception_trace); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 319, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_3, __pyx_v_trace) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_trace); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 319, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 319, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":320 + * + * if ignore_exception_trace(trace): + * return False, frame # <<<<<<<<<<<<<< + * + * was_just_raised = just_raised(trace) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 320, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":319 + * return False, frame + * + * if ignore_exception_trace(trace): # <<<<<<<<<<<<<< + * return False, frame + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":322 + * return False, frame + * + * was_just_raised = just_raised(trace) # <<<<<<<<<<<<<< + * if was_just_raised: + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_just_raised); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_3, __pyx_v_trace) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_trace); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 322, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_v_was_just_raised = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":323 + * + * was_just_raised = just_raised(trace) + * if was_just_raised: # <<<<<<<<<<<<<< + * + * if main_debugger.skip_on_exceptions_thrown_in_same_context: + */ + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_was_just_raised); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 323, __pyx_L1_error) + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":325 + * if was_just_raised: + * + * if main_debugger.skip_on_exceptions_thrown_in_same_context: # <<<<<<<<<<<<<< + * # Option: Don't break if an exception is caught in the same function from which it is thrown + * return False, frame + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_skip_on_exceptions_thrown_in_sam); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 325, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 325, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":327 + * if main_debugger.skip_on_exceptions_thrown_in_same_context: + * # Option: Don't break if an exception is caught in the same function from which it is thrown + * return False, frame # <<<<<<<<<<<<<< + * + * if exception_breakpoint.notify_on_first_raise_only: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 327, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":325 + * if was_just_raised: + * + * if main_debugger.skip_on_exceptions_thrown_in_same_context: # <<<<<<<<<<<<<< + * # Option: Don't break if an exception is caught in the same function from which it is thrown + * return False, frame + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":323 + * + * was_just_raised = just_raised(trace) + * if was_just_raised: # <<<<<<<<<<<<<< + * + * if main_debugger.skip_on_exceptions_thrown_in_same_context: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":329 + * return False, frame + * + * if exception_breakpoint.notify_on_first_raise_only: # <<<<<<<<<<<<<< + * if main_debugger.skip_on_exceptions_thrown_in_same_context: + * # In this case we never stop if it was just raised, so, to know if it was the first we + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_exception_breakpoint, __pyx_n_s_notify_on_first_raise_only); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 329, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 329, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":330 + * + * if exception_breakpoint.notify_on_first_raise_only: + * if main_debugger.skip_on_exceptions_thrown_in_same_context: # <<<<<<<<<<<<<< + * # In this case we never stop if it was just raised, so, to know if it was the first we + * # need to check if we're in the 2nd method. + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_skip_on_exceptions_thrown_in_sam); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 330, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 330, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":333 + * # In this case we never stop if it was just raised, so, to know if it was the first we + * # need to check if we're in the 2nd method. + * if not was_just_raised and not just_raised(trace.tb_next): # <<<<<<<<<<<<<< + * return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception + * + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_was_just_raised); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 333, __pyx_L1_error) + __pyx_t_2 = ((!__pyx_t_8) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_7 = __pyx_t_2; + goto __pyx_L35_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_just_raised); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_trace, __pyx_n_s_tb_next); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 333, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = ((!__pyx_t_2) != 0); + __pyx_t_7 = __pyx_t_8; + __pyx_L35_bool_binop_done:; + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":334 + * # need to check if we're in the 2nd method. + * if not was_just_raised and not just_raised(trace.tb_next): + * return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception # <<<<<<<<<<<<<< + * + * else: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":333 + * # In this case we never stop if it was just raised, so, to know if it was the first we + * # need to check if we're in the 2nd method. + * if not was_just_raised and not just_raised(trace.tb_next): # <<<<<<<<<<<<<< + * return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":330 + * + * if exception_breakpoint.notify_on_first_raise_only: + * if main_debugger.skip_on_exceptions_thrown_in_same_context: # <<<<<<<<<<<<<< + * # In this case we never stop if it was just raised, so, to know if it was the first we + * # need to check if we're in the 2nd method. + */ + goto __pyx_L33; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":337 + * + * else: + * if not was_just_raised: # <<<<<<<<<<<<<< + * return False, frame # I.e.: we stop only when it was just raised + * + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_was_just_raised); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 337, __pyx_L1_error) + __pyx_t_8 = ((!__pyx_t_7) != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":338 + * else: + * if not was_just_raised: + * return False, frame # I.e.: we stop only when it was just raised # <<<<<<<<<<<<<< + * + * # If it got here we should stop. + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 338, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 0, Py_False); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_frame); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":337 + * + * else: + * if not was_just_raised: # <<<<<<<<<<<<<< + * return False, frame # I.e.: we stop only when it was just raised + * + */ + } + } + __pyx_L33:; + + /* "_pydevd_bundle/pydevd_cython.pyx":329 + * return False, frame + * + * if exception_breakpoint.notify_on_first_raise_only: # <<<<<<<<<<<<<< + * if main_debugger.skip_on_exceptions_thrown_in_same_context: + * # In this case we never stop if it was just raised, so, to know if it was the first we + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":341 + * + * # If it got here we should stop. + * should_stop = True # <<<<<<<<<<<<<< + * try: + * info.pydev_message = exception_breakpoint.qname + */ + __Pyx_INCREF(Py_True); + __Pyx_DECREF_SET(__pyx_v_should_stop, Py_True); + + /* "_pydevd_bundle/pydevd_cython.pyx":342 + * # If it got here we should stop. + * should_stop = True + * try: # <<<<<<<<<<<<<< + * info.pydev_message = exception_breakpoint.qname + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_9); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":343 + * should_stop = True + * try: + * info.pydev_message = exception_breakpoint.qname # <<<<<<<<<<<<<< + * except: + * info.pydev_message = exception_breakpoint.qname.encode('utf-8') + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_exception_breakpoint, __pyx_n_s_qname); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 343, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_5); + if (!(likely(PyString_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 343, __pyx_L38_error) + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_info->pydev_message); + __Pyx_DECREF(__pyx_v_info->pydev_message); + __pyx_v_info->pydev_message = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":342 + * # If it got here we should stop. + * should_stop = True + * try: # <<<<<<<<<<<<<< + * info.pydev_message = exception_breakpoint.qname + * except: + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L43_try_end; + __pyx_L38_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":344 + * try: + * info.pydev_message = exception_breakpoint.qname + * except: # <<<<<<<<<<<<<< + * info.pydev_message = exception_breakpoint.qname.encode('utf-8') + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.should_stop_on_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_14, &__pyx_t_3) < 0) __PYX_ERR(0, 344, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GOTREF(__pyx_t_3); + + /* "_pydevd_bundle/pydevd_cython.pyx":345 + * info.pydev_message = exception_breakpoint.qname + * except: + * info.pydev_message = exception_breakpoint.qname.encode('utf-8') # <<<<<<<<<<<<<< + * + * if should_stop: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_exception_breakpoint, __pyx_n_s_qname); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 345, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_encode); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 345, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_1, __pyx_kp_s_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_kp_s_utf_8); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 345, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (!(likely(PyString_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 345, __pyx_L40_except_error) + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_v_info->pydev_message); + __Pyx_DECREF(__pyx_v_info->pydev_message); + __pyx_v_info->pydev_message = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L39_exception_handled; + } + __pyx_L40_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":342 + * # If it got here we should stop. + * should_stop = True + * try: # <<<<<<<<<<<<<< + * info.pydev_message = exception_breakpoint.qname + * except: + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + goto __pyx_L1_error; + __pyx_L39_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + __pyx_L43_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":306 + * exception, main_debugger.break_on_caught_exceptions) + * + * if exception_breakpoint is not None: # <<<<<<<<<<<<<< + * if exception is SystemExit and main_debugger.ignore_system_exit_code(value): + * return False, frame + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":301 + * pydev_log.exception() + * + * if not should_stop: # <<<<<<<<<<<<<< + * # It was not handled by any plugin, lets check exception breakpoints. + * exception_breakpoint = main_debugger.get_exception_breakpoint( + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":347 + * info.pydev_message = exception_breakpoint.qname.encode('utf-8') + * + * if should_stop: # <<<<<<<<<<<<<< + * # Always add exception to frame (must remove later after we proceed). + * add_exception_to_frame(frame, (exception, value, trace)) + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_should_stop); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 347, __pyx_L1_error) + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":349 + * if should_stop: + * # Always add exception to frame (must remove later after we proceed). + * add_exception_to_frame(frame, (exception, value, trace)) # <<<<<<<<<<<<<< + * + * if exception_breakpoint is not None and exception_breakpoint.expression is not None: + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_add_exception_to_frame); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_exception); + __Pyx_GIVEREF(__pyx_v_exception); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_exception); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_value); + __Pyx_INCREF(__pyx_v_trace); + __Pyx_GIVEREF(__pyx_v_trace); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_trace); + __pyx_t_4 = NULL; + __pyx_t_12 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_12 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_frame, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_frame, __pyx_t_5}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_13 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_v_frame); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 349, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":351 + * add_exception_to_frame(frame, (exception, value, trace)) + * + * if exception_breakpoint is not None and exception_breakpoint.expression is not None: # <<<<<<<<<<<<<< + * main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) + * + */ + __pyx_t_7 = (__pyx_v_exception_breakpoint != Py_None); + __pyx_t_2 = (__pyx_t_7 != 0); + if (__pyx_t_2) { + } else { + __pyx_t_8 = __pyx_t_2; + goto __pyx_L48_bool_binop_done; + } + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_exception_breakpoint, __pyx_n_s_expression); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = (__pyx_t_3 != Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = (__pyx_t_2 != 0); + __pyx_t_8 = __pyx_t_7; + __pyx_L48_bool_binop_done:; + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":352 + * + * if exception_breakpoint is not None and exception_breakpoint.expression is not None: + * main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) # <<<<<<<<<<<<<< + * + * return should_stop, frame + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_handle_breakpoint_expression); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_13 = NULL; + __pyx_t_12 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_12 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[4] = {__pyx_t_13, __pyx_v_exception_breakpoint, ((PyObject *)__pyx_v_info), __pyx_v_frame}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[4] = {__pyx_t_13, __pyx_v_exception_breakpoint, ((PyObject *)__pyx_v_info), __pyx_v_frame}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_5 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_v_exception_breakpoint); + __Pyx_GIVEREF(__pyx_v_exception_breakpoint); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_12, __pyx_v_exception_breakpoint); + __Pyx_INCREF(((PyObject *)__pyx_v_info)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_info)); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_12, ((PyObject *)__pyx_v_info)); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_12, __pyx_v_frame); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 352, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":351 + * add_exception_to_frame(frame, (exception, value, trace)) + * + * if exception_breakpoint is not None and exception_breakpoint.expression is not None: # <<<<<<<<<<<<<< + * main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":347 + * info.pydev_message = exception_breakpoint.qname.encode('utf-8') + * + * if should_stop: # <<<<<<<<<<<<<< + * # Always add exception to frame (must remove later after we proceed). + * add_exception_to_frame(frame, (exception, value, trace)) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":288 + * exception, value, trace = arg + * + * if trace is not None and hasattr(trace, 'tb_next'): # <<<<<<<<<<<<<< + * # on jython trace is None on the first event and it may not have a tb_next. + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":285 + * + * # 2 = 2 + * if info.pydev_state != 2: # and breakpoint is not None: # <<<<<<<<<<<<<< + * exception, value, trace = arg + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":354 + * main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) + * + * return should_stop, frame # <<<<<<<<<<<<<< + * + * def handle_exception(self, frame, event, arg): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 354, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_should_stop); + __Pyx_GIVEREF(__pyx_v_should_stop); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_should_stop); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_frame); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":272 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * def should_stop_on_exception(self, frame, str event, arg): # <<<<<<<<<<<<<< + * cdef PyDBAdditionalThreadInfo info; + * cdef bint flag; + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.should_stop_on_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_info); + __Pyx_XDECREF(__pyx_v_main_debugger); + __Pyx_XDECREF(__pyx_v_should_stop); + __Pyx_XDECREF(__pyx_v_exception); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF(__pyx_v_trace); + __Pyx_XDECREF(__pyx_v_exception_breakpoint); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_eval_result); + __Pyx_XDECREF(__pyx_v_was_just_raised); + __Pyx_XDECREF(__pyx_v_frame); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":356 + * return should_stop, frame + * + * def handle_exception(self, frame, event, arg): # <<<<<<<<<<<<<< + * try: + * # print('handle_exception', frame.f_lineno, frame.f_code.co_name) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_13handle_exception(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_13handle_exception(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("handle_exception (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("handle_exception", 1, 3, 3, 1); __PYX_ERR(0, 356, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("handle_exception", 1, 3, 3, 2); __PYX_ERR(0, 356, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "handle_exception") < 0)) __PYX_ERR(0, 356, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = values[1]; + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("handle_exception", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 356, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.handle_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_12handle_exception(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_12handle_exception(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_trace_obj = NULL; + PyObject *__pyx_v_main_debugger = NULL; + PyObject *__pyx_v_initial_trace_obj = NULL; + PyObject *__pyx_v_check_trace_obj = NULL; + PyObject *__pyx_v_filename = NULL; + PyObject *__pyx_v_filename_to_lines_where_exceptions_are_ignored = NULL; + PyObject *__pyx_v_lines_ignored = NULL; + PyObject *__pyx_v_curr_stat = NULL; + PyObject *__pyx_v_last_stat = NULL; + PyObject *__pyx_v_from_user_input = NULL; + PyObject *__pyx_v_merged = NULL; + PyObject *__pyx_v_exc_lineno = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_thread = NULL; + PyObject *__pyx_v_frame_id_to_frame = NULL; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + int __pyx_t_17; + char const *__pyx_t_18; + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + PyObject *__pyx_t_21 = NULL; + __Pyx_RefNannySetupContext("handle_exception", 0); + __Pyx_INCREF(__pyx_v_frame); + + /* "_pydevd_bundle/pydevd_cython.pyx":357 + * + * def handle_exception(self, frame, event, arg): + * try: # <<<<<<<<<<<<<< + * # print('handle_exception', frame.f_lineno, frame.f_code.co_name) + * + */ + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":361 + * + * # We have 3 things in arg: exception type, description, traceback object + * trace_obj = arg[2] # <<<<<<<<<<<<<< + * main_debugger = self._args[0] + * + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_arg, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_trace_obj = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":362 + * # We have 3 things in arg: exception type, description, traceback object + * trace_obj = arg[2] + * main_debugger = self._args[0] # <<<<<<<<<<<<<< + * + * initial_trace_obj = trace_obj + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 362, __pyx_L4_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_main_debugger = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":364 + * main_debugger = self._args[0] + * + * initial_trace_obj = trace_obj # <<<<<<<<<<<<<< + * if trace_obj.tb_next is None and trace_obj.tb_frame is frame: + * # I.e.: tb_next should be only None in the context it was thrown (trace_obj.tb_frame is frame is just a double check). + */ + __Pyx_INCREF(__pyx_v_trace_obj); + __pyx_v_initial_trace_obj = __pyx_v_trace_obj; + + /* "_pydevd_bundle/pydevd_cython.pyx":365 + * + * initial_trace_obj = trace_obj + * if trace_obj.tb_next is None and trace_obj.tb_frame is frame: # <<<<<<<<<<<<<< + * # I.e.: tb_next should be only None in the context it was thrown (trace_obj.tb_frame is frame is just a double check). + * pass + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_trace_obj, __pyx_n_s_tb_next); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = (__pyx_t_1 == Py_None); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = (__pyx_t_3 != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_trace_obj, __pyx_n_s_tb_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = (__pyx_t_1 == __pyx_v_frame); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_3; + __pyx_L7_bool_binop_done:; + if (__pyx_t_2) { + goto __pyx_L6; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":370 + * else: + * # Get the trace_obj from where the exception was raised... + * while trace_obj.tb_next is not None: # <<<<<<<<<<<<<< + * trace_obj = trace_obj.tb_next + * + */ + /*else*/ { + while (1) { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_trace_obj, __pyx_n_s_tb_next); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = (__pyx_t_1 != Py_None); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) break; + + /* "_pydevd_bundle/pydevd_cython.pyx":371 + * # Get the trace_obj from where the exception was raised... + * while trace_obj.tb_next is not None: + * trace_obj = trace_obj.tb_next # <<<<<<<<<<<<<< + * + * if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_trace_obj, __pyx_n_s_tb_next); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF_SET(__pyx_v_trace_obj, __pyx_t_1); + __pyx_t_1 = 0; + } + } + __pyx_L6:; + + /* "_pydevd_bundle/pydevd_cython.pyx":373 + * trace_obj = trace_obj.tb_next + * + * if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: # <<<<<<<<<<<<<< + * for check_trace_obj in (initial_trace_obj, trace_obj): + * filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_ignore_exceptions_thrown_in_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 373, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":374 + * + * if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: + * for check_trace_obj in (initial_trace_obj, trace_obj): # <<<<<<<<<<<<<< + * filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + * + */ + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_initial_trace_obj); + __Pyx_GIVEREF(__pyx_v_initial_trace_obj); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_initial_trace_obj); + __Pyx_INCREF(__pyx_v_trace_obj); + __Pyx_GIVEREF(__pyx_v_trace_obj); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_trace_obj); + __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (__pyx_t_6 >= 2) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 374, __pyx_L4_error) + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + #endif + __Pyx_XDECREF_SET(__pyx_v_check_trace_obj, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":375 + * if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: + * for check_trace_obj in (initial_trace_obj, trace_obj): + * filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] # <<<<<<<<<<<<<< + * + * filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 375, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_check_trace_obj, __pyx_n_s_tb_frame); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 375, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 375, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_filename, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":377 + * filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + * + * filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored # <<<<<<<<<<<<<< + * + * lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_filename_to_lines_where_exceptio); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 377, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_XDECREF_SET(__pyx_v_filename_to_lines_where_exceptions_are_ignored, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":379 + * filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored + * + * lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) # <<<<<<<<<<<<<< + * if lines_ignored is None: + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename_to_lines_where_exceptions_are_ignored, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 379, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_filename); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 379, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_lines_ignored, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":380 + * + * lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) + * if lines_ignored is None: # <<<<<<<<<<<<<< + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + * + */ + __pyx_t_3 = (__pyx_v_lines_ignored == Py_None); + __pyx_t_2 = (__pyx_t_3 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":381 + * lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) + * if lines_ignored is None: + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} # <<<<<<<<<<<<<< + * + * try: + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 381, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF_SET(__pyx_v_lines_ignored, __pyx_t_7); + if (unlikely(PyObject_SetItem(__pyx_v_filename_to_lines_where_exceptions_are_ignored, __pyx_v_filename, __pyx_t_7) < 0)) __PYX_ERR(0, 381, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":380 + * + * lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) + * if lines_ignored is None: # <<<<<<<<<<<<<< + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":383 + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + * + * try: # <<<<<<<<<<<<<< + * curr_stat = os.stat(filename) + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":384 + * + * try: + * curr_stat = os.stat(filename) # <<<<<<<<<<<<<< + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + * except: + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_stat); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 384, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_v_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_filename); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 384, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_curr_stat, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":385 + * try: + * curr_stat = os.stat(filename) + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) # <<<<<<<<<<<<<< + * except: + * curr_stat = None + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_curr_stat, __pyx_n_s_st_size); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 385, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_curr_stat, __pyx_n_s_st_mtime); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 385, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_curr_stat, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":383 + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + * + * try: # <<<<<<<<<<<<<< + * curr_stat = os.stat(filename) + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L22_try_end; + __pyx_L15_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":386 + * curr_stat = os.stat(filename) + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + * except: # <<<<<<<<<<<<<< + * curr_stat = None + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.handle_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_7) < 0) __PYX_ERR(0, 386, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_7); + + /* "_pydevd_bundle/pydevd_cython.pyx":387 + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + * except: + * curr_stat = None # <<<<<<<<<<<<<< + * + * last_stat = self.filename_to_stat_info.get(filename) + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_curr_stat, Py_None); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L16_exception_handled; + } + __pyx_L17_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":383 + * lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + * + * try: # <<<<<<<<<<<<<< + * curr_stat = os.stat(filename) + * curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + */ + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L4_error; + __pyx_L16_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L22_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":389 + * curr_stat = None + * + * last_stat = self.filename_to_stat_info.get(filename) # <<<<<<<<<<<<<< + * if last_stat != curr_stat: + * self.filename_to_stat_info[filename] = curr_stat + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_filename_to_stat_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 389, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_filename); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 389, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_last_stat, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":390 + * + * last_stat = self.filename_to_stat_info.get(filename) + * if last_stat != curr_stat: # <<<<<<<<<<<<<< + * self.filename_to_stat_info[filename] = curr_stat + * lines_ignored.clear() + */ + __pyx_t_7 = PyObject_RichCompare(__pyx_v_last_stat, __pyx_v_curr_stat, Py_NE); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 390, __pyx_L4_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 390, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":391 + * last_stat = self.filename_to_stat_info.get(filename) + * if last_stat != curr_stat: + * self.filename_to_stat_info[filename] = curr_stat # <<<<<<<<<<<<<< + * lines_ignored.clear() + * try: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_filename_to_stat_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 391, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + if (unlikely(PyObject_SetItem(__pyx_t_7, __pyx_v_filename, __pyx_v_curr_stat) < 0)) __PYX_ERR(0, 391, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":392 + * if last_stat != curr_stat: + * self.filename_to_stat_info[filename] = curr_stat + * lines_ignored.clear() # <<<<<<<<<<<<<< + * try: + * linecache.checkcache(filename) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_lines_ignored, __pyx_n_s_clear); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 392, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":393 + * self.filename_to_stat_info[filename] = curr_stat + * lines_ignored.clear() + * try: # <<<<<<<<<<<<<< + * linecache.checkcache(filename) + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":394 + * lines_ignored.clear() + * try: + * linecache.checkcache(filename) # <<<<<<<<<<<<<< + * except: + * # Jython 2.1 + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_linecache); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_checkcache); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 394, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_v_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_filename); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":393 + * self.filename_to_stat_info[filename] = curr_stat + * lines_ignored.clear() + * try: # <<<<<<<<<<<<<< + * linecache.checkcache(filename) + * except: + */ + } + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L33_try_end; + __pyx_L26_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":395 + * try: + * linecache.checkcache(filename) + * except: # <<<<<<<<<<<<<< + * # Jython 2.1 + * linecache.checkcache() + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.handle_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_1) < 0) __PYX_ERR(0, 395, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_1); + + /* "_pydevd_bundle/pydevd_cython.pyx":397 + * except: + * # Jython 2.1 + * linecache.checkcache() # <<<<<<<<<<<<<< + * + * from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_linecache); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 397, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_checkcache); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 397, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_9 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 397, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L27_exception_handled; + } + __pyx_L28_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":393 + * self.filename_to_stat_info[filename] = curr_stat + * lines_ignored.clear() + * try: # <<<<<<<<<<<<<< + * linecache.checkcache(filename) + * except: + */ + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + goto __pyx_L4_error; + __pyx_L27_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + __pyx_L33_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":390 + * + * last_stat = self.filename_to_stat_info.get(filename) + * if last_stat != curr_stat: # <<<<<<<<<<<<<< + * self.filename_to_stat_info[filename] = curr_stat + * lines_ignored.clear() + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":399 + * linecache.checkcache() + * + * from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) # <<<<<<<<<<<<<< + * if from_user_input: + * merged = {} + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_filename_to_lines_where_exceptio); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 399, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_get); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 399, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_filename); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_from_user_input, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":400 + * + * from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) + * if from_user_input: # <<<<<<<<<<<<<< + * merged = {} + * merged.update(lines_ignored) + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_user_input); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 400, __pyx_L4_error) + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":401 + * from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) + * if from_user_input: + * merged = {} # <<<<<<<<<<<<<< + * merged.update(lines_ignored) + * # Override what we have with the related entries that the user entered + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 401, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_merged, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":402 + * if from_user_input: + * merged = {} + * merged.update(lines_ignored) # <<<<<<<<<<<<<< + * # Override what we have with the related entries that the user entered + * merged.update(from_user_input) + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_merged, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 402, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_lines_ignored) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_lines_ignored); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":404 + * merged.update(lines_ignored) + * # Override what we have with the related entries that the user entered + * merged.update(from_user_input) # <<<<<<<<<<<<<< + * else: + * merged = lines_ignored + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_merged, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 404, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_v_from_user_input) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_from_user_input); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":400 + * + * from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) + * if from_user_input: # <<<<<<<<<<<<<< + * merged = {} + * merged.update(lines_ignored) + */ + goto __pyx_L36; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":406 + * merged.update(from_user_input) + * else: + * merged = lines_ignored # <<<<<<<<<<<<<< + * + * exc_lineno = check_trace_obj.tb_lineno + */ + /*else*/ { + __Pyx_INCREF(__pyx_v_lines_ignored); + __Pyx_XDECREF_SET(__pyx_v_merged, __pyx_v_lines_ignored); + } + __pyx_L36:; + + /* "_pydevd_bundle/pydevd_cython.pyx":408 + * merged = lines_ignored + * + * exc_lineno = check_trace_obj.tb_lineno # <<<<<<<<<<<<<< + * + * # print ('lines ignored', lines_ignored) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_check_trace_obj, __pyx_n_s_tb_lineno); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_exc_lineno, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":414 + * # print ('merged', merged, 'curr', exc_lineno) + * + * if exc_lineno not in merged: # Note: check on merged but update lines_ignored. # <<<<<<<<<<<<<< + * try: + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + */ + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_exc_lineno, __pyx_v_merged, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 414, __pyx_L4_error) + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":415 + * + * if exc_lineno not in merged: # Note: check on merged but update lines_ignored. + * try: # <<<<<<<<<<<<<< + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":416 + * if exc_lineno not in merged: # Note: check on merged but update lines_ignored. + * try: + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) # <<<<<<<<<<<<<< + * except: + * # Jython 2.1 + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_linecache); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_getline); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_check_trace_obj, __pyx_n_s_tb_frame); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_f_globals); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_filename, __pyx_v_exc_lineno, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_filename, __pyx_v_exc_lineno, __pyx_t_9}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_14 = PyTuple_New(3+__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_14); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_15, __pyx_v_filename); + __Pyx_INCREF(__pyx_v_exc_lineno); + __Pyx_GIVEREF(__pyx_v_exc_lineno); + PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_15, __pyx_v_exc_lineno); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_14, 2+__pyx_t_15, __pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 416, __pyx_L38_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":415 + * + * if exc_lineno not in merged: # Note: check on merged but update lines_ignored. + * try: # <<<<<<<<<<<<<< + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + * except: + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L45_try_end; + __pyx_L38_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":417 + * try: + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + * except: # <<<<<<<<<<<<<< + * # Jython 2.1 + * line = linecache.getline(filename, exc_lineno) + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.handle_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_14) < 0) __PYX_ERR(0, 417, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_14); + + /* "_pydevd_bundle/pydevd_cython.pyx":419 + * except: + * # Jython 2.1 + * line = linecache.getline(filename, exc_lineno) # <<<<<<<<<<<<<< + * + * if IGNORE_EXCEPTION_TAG.match(line) is not None: + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_linecache); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 419, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_getline); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 419, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_filename, __pyx_v_exc_lineno}; + __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 419, __pyx_L40_except_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_filename, __pyx_v_exc_lineno}; + __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 419, __pyx_L40_except_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_9); + } else + #endif + { + __pyx_t_16 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 419, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_16); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_15, __pyx_v_filename); + __Pyx_INCREF(__pyx_v_exc_lineno); + __Pyx_GIVEREF(__pyx_v_exc_lineno); + PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_15, __pyx_v_exc_lineno); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_16, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 419, __pyx_L40_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_9); + __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L39_exception_handled; + } + __pyx_L40_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":415 + * + * if exc_lineno not in merged: # Note: check on merged but update lines_ignored. + * try: # <<<<<<<<<<<<<< + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + * except: + */ + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L4_error; + __pyx_L39_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L45_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":421 + * line = linecache.getline(filename, exc_lineno) + * + * if IGNORE_EXCEPTION_TAG.match(line) is not None: # <<<<<<<<<<<<<< + * lines_ignored[exc_lineno] = 1 + * return + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_IGNORE_EXCEPTION_TAG); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 421, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_match); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 421, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_14 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_v_line) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_line); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 421, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_14 != Py_None); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_2 = (__pyx_t_3 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":422 + * + * if IGNORE_EXCEPTION_TAG.match(line) is not None: + * lines_ignored[exc_lineno] = 1 # <<<<<<<<<<<<<< + * return + * else: + */ + if (unlikely(PyObject_SetItem(__pyx_v_lines_ignored, __pyx_v_exc_lineno, __pyx_int_1) < 0)) __PYX_ERR(0, 422, __pyx_L4_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":423 + * if IGNORE_EXCEPTION_TAG.match(line) is not None: + * lines_ignored[exc_lineno] = 1 + * return # <<<<<<<<<<<<<< + * else: + * # Put in the cache saying not to ignore + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":421 + * line = linecache.getline(filename, exc_lineno) + * + * if IGNORE_EXCEPTION_TAG.match(line) is not None: # <<<<<<<<<<<<<< + * lines_ignored[exc_lineno] = 1 + * return + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":426 + * else: + * # Put in the cache saying not to ignore + * lines_ignored[exc_lineno] = 0 # <<<<<<<<<<<<<< + * else: + * # Ok, dict has it already cached, so, let's check it... + */ + /*else*/ { + if (unlikely(PyObject_SetItem(__pyx_v_lines_ignored, __pyx_v_exc_lineno, __pyx_int_0) < 0)) __PYX_ERR(0, 426, __pyx_L4_error) + } + + /* "_pydevd_bundle/pydevd_cython.pyx":414 + * # print ('merged', merged, 'curr', exc_lineno) + * + * if exc_lineno not in merged: # Note: check on merged but update lines_ignored. # <<<<<<<<<<<<<< + * try: + * line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + */ + goto __pyx_L37; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":429 + * else: + * # Ok, dict has it already cached, so, let's check it... + * if merged.get(exc_lineno, 0): # <<<<<<<<<<<<<< + * return + * + */ + /*else*/ { + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_merged, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 429, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_exc_lineno, __pyx_int_0}; + __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 429, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_exc_lineno, __pyx_int_0}; + __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 429, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_14); + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 429, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_exc_lineno); + __Pyx_GIVEREF(__pyx_v_exc_lineno); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_15, __pyx_v_exc_lineno); + __Pyx_INCREF(__pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_15, __pyx_int_0); + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 429, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 429, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":430 + * # Ok, dict has it already cached, so, let's check it... + * if merged.get(exc_lineno, 0): + * return # <<<<<<<<<<<<<< + * + * thread = self._args[3] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":429 + * else: + * # Ok, dict has it already cached, so, let's check it... + * if merged.get(exc_lineno, 0): # <<<<<<<<<<<<<< + * return + * + */ + } + } + __pyx_L37:; + + /* "_pydevd_bundle/pydevd_cython.pyx":374 + * + * if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: + * for check_trace_obj in (initial_trace_obj, trace_obj): # <<<<<<<<<<<<<< + * filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + * + */ + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":373 + * trace_obj = trace_obj.tb_next + * + * if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: # <<<<<<<<<<<<<< + * for check_trace_obj in (initial_trace_obj, trace_obj): + * filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":432 + * return + * + * thread = self._args[3] # <<<<<<<<<<<<<< + * + * try: + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 432, __pyx_L4_error) + } + __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_self->_args, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 432, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_thread = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":434 + * thread = self._args[3] + * + * try: # <<<<<<<<<<<<<< + * frame_id_to_frame = {} + * frame_id_to_frame[id(frame)] = frame + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":435 + * + * try: + * frame_id_to_frame = {} # <<<<<<<<<<<<<< + * frame_id_to_frame[id(frame)] = frame + * f = trace_obj.tb_frame + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 435, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_frame_id_to_frame = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":436 + * try: + * frame_id_to_frame = {} + * frame_id_to_frame[id(frame)] = frame # <<<<<<<<<<<<<< + * f = trace_obj.tb_frame + * while f is not None: + */ + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, __pyx_v_frame); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 436, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely(PyDict_SetItem(__pyx_v_frame_id_to_frame, __pyx_t_5, __pyx_v_frame) < 0)) __PYX_ERR(0, 436, __pyx_L50_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":437 + * frame_id_to_frame = {} + * frame_id_to_frame[id(frame)] = frame + * f = trace_obj.tb_frame # <<<<<<<<<<<<<< + * while f is not None: + * frame_id_to_frame[id(f)] = f + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_trace_obj, __pyx_n_s_tb_frame); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 437, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_f = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":438 + * frame_id_to_frame[id(frame)] = frame + * f = trace_obj.tb_frame + * while f is not None: # <<<<<<<<<<<<<< + * frame_id_to_frame[id(f)] = f + * f = f.f_back + */ + while (1) { + __pyx_t_2 = (__pyx_v_f != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (!__pyx_t_3) break; + + /* "_pydevd_bundle/pydevd_cython.pyx":439 + * f = trace_obj.tb_frame + * while f is not None: + * frame_id_to_frame[id(f)] = f # <<<<<<<<<<<<<< + * f = f.f_back + * f = None + */ + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, __pyx_v_f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 439, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely(PyDict_SetItem(__pyx_v_frame_id_to_frame, __pyx_t_5, __pyx_v_f) < 0)) __PYX_ERR(0, 439, __pyx_L50_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":440 + * while f is not None: + * frame_id_to_frame[id(f)] = f + * f = f.f_back # <<<<<<<<<<<<<< + * f = None + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_f_back); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 440, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF_SET(__pyx_v_f, __pyx_t_5); + __pyx_t_5 = 0; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":441 + * frame_id_to_frame[id(f)] = f + * f = f.f_back + * f = None # <<<<<<<<<<<<<< + * + * main_debugger.send_caught_exception_stack(thread, arg, id(frame)) + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_f, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":443 + * f = None + * + * main_debugger.send_caught_exception_stack(thread, arg, id(frame)) # <<<<<<<<<<<<<< + * self.set_suspend(thread, 137) + * self.do_wait_suspend(thread, frame, event, arg) + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_send_caught_exception_stack); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 443, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, __pyx_v_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 443, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_thread, __pyx_v_arg, __pyx_t_1}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L50_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[4] = {__pyx_t_9, __pyx_v_thread, __pyx_v_arg, __pyx_t_1}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_15, 3+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L50_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(3+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 443, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_15, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_15, __pyx_v_arg); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_15, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":444 + * + * main_debugger.send_caught_exception_stack(thread, arg, id(frame)) + * self.set_suspend(thread, 137) # <<<<<<<<<<<<<< + * self.do_wait_suspend(thread, frame, event, arg) + * main_debugger.send_caught_exception_stack_proceeded(thread) + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_suspend); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 444, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_8 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_thread, __pyx_int_137}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L50_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_thread, __pyx_int_137}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L50_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 444, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_15, __pyx_v_thread); + __Pyx_INCREF(__pyx_int_137); + __Pyx_GIVEREF(__pyx_int_137); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_15, __pyx_int_137); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":445 + * main_debugger.send_caught_exception_stack(thread, arg, id(frame)) + * self.set_suspend(thread, 137) + * self.do_wait_suspend(thread, frame, event, arg) # <<<<<<<<<<<<<< + * main_debugger.send_caught_exception_stack_proceeded(thread) + * except: + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_do_wait_suspend); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 445, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = NULL; + __pyx_t_15 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + __pyx_t_15 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_v_thread, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_15, 4+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L50_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_v_thread, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_15, 4+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L50_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_5); + } else + #endif + { + __pyx_t_8 = PyTuple_New(4+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 445, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_15, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_15, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_15, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_8, 3+__pyx_t_15, __pyx_v_arg); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":446 + * self.set_suspend(thread, 137) + * self.do_wait_suspend(thread, frame, event, arg) + * main_debugger.send_caught_exception_stack_proceeded(thread) # <<<<<<<<<<<<<< + * except: + * pydev_log.exception() + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_send_caught_exception_stack_proc); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 446, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_8, __pyx_v_thread) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_thread); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 446, __pyx_L50_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":434 + * thread = self._args[3] + * + * try: # <<<<<<<<<<<<<< + * frame_id_to_frame = {} + * frame_id_to_frame[id(frame)] = frame + */ + } + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L55_try_end; + __pyx_L50_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":447 + * self.do_wait_suspend(thread, frame, event, arg) + * main_debugger.send_caught_exception_stack_proceeded(thread) + * except: # <<<<<<<<<<<<<< + * pydev_log.exception() + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.handle_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_14, &__pyx_t_8) < 0) __PYX_ERR(0, 447, __pyx_L52_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_14); + __Pyx_GOTREF(__pyx_t_8); + + /* "_pydevd_bundle/pydevd_cython.pyx":448 + * main_debugger.send_caught_exception_stack_proceeded(thread) + * except: + * pydev_log.exception() # <<<<<<<<<<<<<< + * + * main_debugger.set_trace_for_frame_and_parents(frame) + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 448, __pyx_L52_except_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_exception); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 448, __pyx_L52_except_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 448, __pyx_L52_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L51_exception_handled; + } + __pyx_L52_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":434 + * thread = self._args[3] + * + * try: # <<<<<<<<<<<<<< + * frame_id_to_frame = {} + * frame_id_to_frame[id(frame)] = frame + */ + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + goto __pyx_L4_error; + __pyx_L51_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + __pyx_L55_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":450 + * pydev_log.exception() + * + * main_debugger.set_trace_for_frame_and_parents(frame) # <<<<<<<<<<<<<< + * finally: + * # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. + */ + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_set_trace_for_frame_and_parents); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 450, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_5, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 450, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":453 + * finally: + * # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. + * remove_exception_from_frame(frame) # <<<<<<<<<<<<<< + * # Clear some local variables... + * frame = None + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_remove_exception_from_frame); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_5, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":455 + * remove_exception_from_frame(frame) + * # Clear some local variables... + * frame = None # <<<<<<<<<<<<<< + * trace_obj = None + * initial_trace_obj = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_frame, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":456 + * # Clear some local variables... + * frame = None + * trace_obj = None # <<<<<<<<<<<<<< + * initial_trace_obj = None + * check_trace_obj = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":457 + * frame = None + * trace_obj = None + * initial_trace_obj = None # <<<<<<<<<<<<<< + * check_trace_obj = None + * f = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_initial_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":458 + * trace_obj = None + * initial_trace_obj = None + * check_trace_obj = None # <<<<<<<<<<<<<< + * f = None + * frame_id_to_frame = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_check_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":459 + * initial_trace_obj = None + * check_trace_obj = None + * f = None # <<<<<<<<<<<<<< + * frame_id_to_frame = None + * main_debugger = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":460 + * check_trace_obj = None + * f = None + * frame_id_to_frame = None # <<<<<<<<<<<<<< + * main_debugger = None + * thread = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_frame_id_to_frame, ((PyObject*)Py_None)); + + /* "_pydevd_bundle/pydevd_cython.pyx":461 + * f = None + * frame_id_to_frame = None + * main_debugger = None # <<<<<<<<<<<<<< + * thread = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_main_debugger, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":462 + * frame_id_to_frame = None + * main_debugger = None + * thread = None # <<<<<<<<<<<<<< + * + * def get_func_name(self, frame): + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_thread, Py_None); + goto __pyx_L5; + } + __pyx_L4_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12) < 0)) __Pyx_ErrFetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_21); + __pyx_t_15 = __pyx_lineno; __pyx_t_17 = __pyx_clineno; __pyx_t_18 = __pyx_filename; + { + + /* "_pydevd_bundle/pydevd_cython.pyx":453 + * finally: + * # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. + * remove_exception_from_frame(frame) # <<<<<<<<<<<<<< + * # Clear some local variables... + * frame = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_remove_exception_from_frame); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 453, __pyx_L61_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_5, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 453, __pyx_L61_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":455 + * remove_exception_from_frame(frame) + * # Clear some local variables... + * frame = None # <<<<<<<<<<<<<< + * trace_obj = None + * initial_trace_obj = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_frame, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":456 + * # Clear some local variables... + * frame = None + * trace_obj = None # <<<<<<<<<<<<<< + * initial_trace_obj = None + * check_trace_obj = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":457 + * frame = None + * trace_obj = None + * initial_trace_obj = None # <<<<<<<<<<<<<< + * check_trace_obj = None + * f = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_initial_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":458 + * trace_obj = None + * initial_trace_obj = None + * check_trace_obj = None # <<<<<<<<<<<<<< + * f = None + * frame_id_to_frame = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_check_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":459 + * initial_trace_obj = None + * check_trace_obj = None + * f = None # <<<<<<<<<<<<<< + * frame_id_to_frame = None + * main_debugger = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":460 + * check_trace_obj = None + * f = None + * frame_id_to_frame = None # <<<<<<<<<<<<<< + * main_debugger = None + * thread = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_frame_id_to_frame, ((PyObject*)Py_None)); + + /* "_pydevd_bundle/pydevd_cython.pyx":461 + * f = None + * frame_id_to_frame = None + * main_debugger = None # <<<<<<<<<<<<<< + * thread = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_main_debugger, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":462 + * frame_id_to_frame = None + * main_debugger = None + * thread = None # <<<<<<<<<<<<<< + * + * def get_func_name(self, frame): + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_thread, Py_None); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21); + } + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ErrRestore(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; + __pyx_lineno = __pyx_t_15; __pyx_clineno = __pyx_t_17; __pyx_filename = __pyx_t_18; + goto __pyx_L1_error; + __pyx_L61_error:; + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21); + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; + goto __pyx_L1_error; + } + __pyx_L3_return: { + __pyx_t_21 = __pyx_r; + __pyx_r = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":453 + * finally: + * # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. + * remove_exception_from_frame(frame) # <<<<<<<<<<<<<< + * # Clear some local variables... + * frame = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_remove_exception_from_frame); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_14); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_14, function); + } + } + __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_5, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 453, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":455 + * remove_exception_from_frame(frame) + * # Clear some local variables... + * frame = None # <<<<<<<<<<<<<< + * trace_obj = None + * initial_trace_obj = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_frame, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":456 + * # Clear some local variables... + * frame = None + * trace_obj = None # <<<<<<<<<<<<<< + * initial_trace_obj = None + * check_trace_obj = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":457 + * frame = None + * trace_obj = None + * initial_trace_obj = None # <<<<<<<<<<<<<< + * check_trace_obj = None + * f = None + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_initial_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":458 + * trace_obj = None + * initial_trace_obj = None + * check_trace_obj = None # <<<<<<<<<<<<<< + * f = None + * frame_id_to_frame = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_check_trace_obj, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":459 + * initial_trace_obj = None + * check_trace_obj = None + * f = None # <<<<<<<<<<<<<< + * frame_id_to_frame = None + * main_debugger = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":460 + * check_trace_obj = None + * f = None + * frame_id_to_frame = None # <<<<<<<<<<<<<< + * main_debugger = None + * thread = None + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_frame_id_to_frame, ((PyObject*)Py_None)); + + /* "_pydevd_bundle/pydevd_cython.pyx":461 + * f = None + * frame_id_to_frame = None + * main_debugger = None # <<<<<<<<<<<<<< + * thread = None + * + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_main_debugger, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":462 + * frame_id_to_frame = None + * main_debugger = None + * thread = None # <<<<<<<<<<<<<< + * + * def get_func_name(self, frame): + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_thread, Py_None); + __pyx_r = __pyx_t_21; + __pyx_t_21 = 0; + goto __pyx_L0; + } + __pyx_L5:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":356 + * return should_stop, frame + * + * def handle_exception(self, frame, event, arg): # <<<<<<<<<<<<<< + * try: + * # print('handle_exception', frame.f_lineno, frame.f_code.co_name) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.handle_exception", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_trace_obj); + __Pyx_XDECREF(__pyx_v_main_debugger); + __Pyx_XDECREF(__pyx_v_initial_trace_obj); + __Pyx_XDECREF(__pyx_v_check_trace_obj); + __Pyx_XDECREF(__pyx_v_filename); + __Pyx_XDECREF(__pyx_v_filename_to_lines_where_exceptions_are_ignored); + __Pyx_XDECREF(__pyx_v_lines_ignored); + __Pyx_XDECREF(__pyx_v_curr_stat); + __Pyx_XDECREF(__pyx_v_last_stat); + __Pyx_XDECREF(__pyx_v_from_user_input); + __Pyx_XDECREF(__pyx_v_merged); + __Pyx_XDECREF(__pyx_v_exc_lineno); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_thread); + __Pyx_XDECREF(__pyx_v_frame_id_to_frame); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_frame); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":464 + * thread = None + * + * def get_func_name(self, frame): # <<<<<<<<<<<<<< + * code_obj = frame.f_code + * func_name = code_obj.co_name + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_15get_func_name(PyObject *__pyx_v_self, PyObject *__pyx_v_frame); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_15get_func_name(PyObject *__pyx_v_self, PyObject *__pyx_v_frame) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_func_name (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_14get_func_name(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), ((PyObject *)__pyx_v_frame)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_14get_func_name(CYTHON_UNUSED struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame) { + PyObject *__pyx_v_code_obj = NULL; + PyObject *__pyx_v_func_name = NULL; + PyObject *__pyx_v_cls_name = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + __Pyx_RefNannySetupContext("get_func_name", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":465 + * + * def get_func_name(self, frame): + * code_obj = frame.f_code # <<<<<<<<<<<<<< + * func_name = code_obj.co_name + * try: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_code_obj = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":466 + * def get_func_name(self, frame): + * code_obj = frame.f_code + * func_name = code_obj.co_name # <<<<<<<<<<<<<< + * try: + * cls_name = get_clsname_for_code(code_obj, frame) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_code_obj, __pyx_n_s_co_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 466, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_func_name = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":467 + * code_obj = frame.f_code + * func_name = code_obj.co_name + * try: # <<<<<<<<<<<<<< + * cls_name = get_clsname_for_code(code_obj, frame) + * if cls_name is not None: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":468 + * func_name = code_obj.co_name + * try: + * cls_name = get_clsname_for_code(code_obj, frame) # <<<<<<<<<<<<<< + * if cls_name is not None: + * return "%s.%s" % (cls_name, func_name) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_get_clsname_for_code); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 468, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_code_obj, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_code_obj, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 468, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_v_code_obj); + __Pyx_GIVEREF(__pyx_v_code_obj); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_code_obj); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_frame); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_cls_name = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":469 + * try: + * cls_name = get_clsname_for_code(code_obj, frame) + * if cls_name is not None: # <<<<<<<<<<<<<< + * return "%s.%s" % (cls_name, func_name) + * else: + */ + __pyx_t_9 = (__pyx_v_cls_name != Py_None); + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":470 + * cls_name = get_clsname_for_code(code_obj, frame) + * if cls_name is not None: + * return "%s.%s" % (cls_name, func_name) # <<<<<<<<<<<<<< + * else: + * return func_name + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 470, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_cls_name); + __Pyx_GIVEREF(__pyx_v_cls_name); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cls_name); + __Pyx_INCREF(__pyx_v_func_name); + __Pyx_GIVEREF(__pyx_v_func_name); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_func_name); + __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 470, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":469 + * try: + * cls_name = get_clsname_for_code(code_obj, frame) + * if cls_name is not None: # <<<<<<<<<<<<<< + * return "%s.%s" % (cls_name, func_name) + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":472 + * return "%s.%s" % (cls_name, func_name) + * else: + * return func_name # <<<<<<<<<<<<<< + * except: + * pydev_log.exception() + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_func_name); + __pyx_r = __pyx_v_func_name; + goto __pyx_L7_try_return; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":467 + * code_obj = frame.f_code + * func_name = code_obj.co_name + * try: # <<<<<<<<<<<<<< + * cls_name = get_clsname_for_code(code_obj, frame) + * if cls_name is not None: + */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":473 + * else: + * return func_name + * except: # <<<<<<<<<<<<<< + * pydev_log.exception() + * return func_name + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.get_func_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_1, &__pyx_t_8) < 0) __PYX_ERR(0, 473, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_8); + + /* "_pydevd_bundle/pydevd_cython.pyx":474 + * return func_name + * except: + * pydev_log.exception() # <<<<<<<<<<<<<< + * return func_name + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 474, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_exception); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 474, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_6 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 474, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":475 + * except: + * pydev_log.exception() + * return func_name # <<<<<<<<<<<<<< + * + * def show_return_values(self, frame, arg): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_func_name); + __pyx_r = __pyx_v_func_name; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L6_except_return; + } + __pyx_L5_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":467 + * code_obj = frame.f_code + * func_name = code_obj.co_name + * try: # <<<<<<<<<<<<<< + * cls_name = get_clsname_for_code(code_obj, frame) + * if cls_name is not None: + */ + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4); + goto __pyx_L0; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":464 + * thread = None + * + * def get_func_name(self, frame): # <<<<<<<<<<<<<< + * code_obj = frame.f_code + * func_name = code_obj.co_name + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.get_func_name", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_code_obj); + __Pyx_XDECREF(__pyx_v_func_name); + __Pyx_XDECREF(__pyx_v_cls_name); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":477 + * return func_name + * + * def show_return_values(self, frame, arg): # <<<<<<<<<<<<<< + * try: + * try: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_17show_return_values(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_17show_return_values(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("show_return_values (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_arg,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("show_return_values", 1, 2, 2, 1); __PYX_ERR(0, 477, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "show_return_values") < 0)) __PYX_ERR(0, 477, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_frame = values[0]; + __pyx_v_arg = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("show_return_values", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 477, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.show_return_values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_16show_return_values(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_16show_return_values(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_f_locals_back = NULL; + PyObject *__pyx_v_return_values_dict = NULL; + PyObject *__pyx_v_name = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + char const *__pyx_t_14; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + __Pyx_RefNannySetupContext("show_return_values", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":478 + * + * def show_return_values(self, frame, arg): + * try: # <<<<<<<<<<<<<< + * try: + * f_locals_back = getattr(frame.f_back, "f_locals", None) + */ + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":479 + * def show_return_values(self, frame, arg): + * try: + * try: # <<<<<<<<<<<<<< + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":480 + * try: + * try: + * f_locals_back = getattr(frame.f_back, "f_locals", None) # <<<<<<<<<<<<<< + * if f_locals_back is not None: + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 480, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_GetAttr3(__pyx_t_4, __pyx_n_s_f_locals, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 480, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_f_locals_back = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":481 + * try: + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: # <<<<<<<<<<<<<< + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + * if return_values_dict is None: + */ + __pyx_t_6 = (__pyx_v_f_locals_back != Py_None); + __pyx_t_7 = (__pyx_t_6 != 0); + if (__pyx_t_7) { + + /* "_pydevd_bundle/pydevd_cython.pyx":482 + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) # <<<<<<<<<<<<<< + * if return_values_dict is None: + * return_values_dict = {} + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_locals_back, __pyx_n_s_get); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 482, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_RETURN_VALUES_DICT); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 482, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = NULL; + __pyx_t_10 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_10 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_8, Py_None}; + __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 482, __pyx_L6_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_8, Py_None}; + __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 482, __pyx_L6_error) + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 482, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_11); + if (__pyx_t_9) { + __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL; + } + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_8); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, Py_None); + __pyx_t_8 = 0; + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 482, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_return_values_dict = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":483 + * if f_locals_back is not None: + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + * if return_values_dict is None: # <<<<<<<<<<<<<< + * return_values_dict = {} + * f_locals_back[RETURN_VALUES_DICT] = return_values_dict + */ + __pyx_t_7 = (__pyx_v_return_values_dict == Py_None); + __pyx_t_6 = (__pyx_t_7 != 0); + if (__pyx_t_6) { + + /* "_pydevd_bundle/pydevd_cython.pyx":484 + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + * if return_values_dict is None: + * return_values_dict = {} # <<<<<<<<<<<<<< + * f_locals_back[RETURN_VALUES_DICT] = return_values_dict + * name = self.get_func_name(frame) + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 484, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF_SET(__pyx_v_return_values_dict, __pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":485 + * if return_values_dict is None: + * return_values_dict = {} + * f_locals_back[RETURN_VALUES_DICT] = return_values_dict # <<<<<<<<<<<<<< + * name = self.get_func_name(frame) + * return_values_dict[name] = arg + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_RETURN_VALUES_DICT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 485, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely(PyObject_SetItem(__pyx_v_f_locals_back, __pyx_t_5, __pyx_v_return_values_dict) < 0)) __PYX_ERR(0, 485, __pyx_L6_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":483 + * if f_locals_back is not None: + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + * if return_values_dict is None: # <<<<<<<<<<<<<< + * return_values_dict = {} + * f_locals_back[RETURN_VALUES_DICT] = return_values_dict + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":486 + * return_values_dict = {} + * f_locals_back[RETURN_VALUES_DICT] = return_values_dict + * name = self.get_func_name(frame) # <<<<<<<<<<<<<< + * return_values_dict[name] = arg + * except: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_func_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 486, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_5 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_11, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 486, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_name = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":487 + * f_locals_back[RETURN_VALUES_DICT] = return_values_dict + * name = self.get_func_name(frame) + * return_values_dict[name] = arg # <<<<<<<<<<<<<< + * except: + * pydev_log.exception() + */ + if (unlikely(PyObject_SetItem(__pyx_v_return_values_dict, __pyx_v_name, __pyx_v_arg) < 0)) __PYX_ERR(0, 487, __pyx_L6_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":481 + * try: + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: # <<<<<<<<<<<<<< + * return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + * if return_values_dict is None: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":479 + * def show_return_values(self, frame, arg): + * try: + * try: # <<<<<<<<<<<<<< + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L11_try_end; + __pyx_L6_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":488 + * name = self.get_func_name(frame) + * return_values_dict[name] = arg + * except: # <<<<<<<<<<<<<< + * pydev_log.exception() + * finally: + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.show_return_values", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_11) < 0) __PYX_ERR(0, 488, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_11); + + /* "_pydevd_bundle/pydevd_cython.pyx":489 + * return_values_dict[name] = arg + * except: + * pydev_log.exception() # <<<<<<<<<<<<<< + * finally: + * f_locals_back = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 489, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_exception); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 489, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 489, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L7_exception_handled; + } + __pyx_L8_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":479 + * def show_return_values(self, frame, arg): + * try: + * try: # <<<<<<<<<<<<<< + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L4_error; + __pyx_L7_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L11_try_end:; + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":491 + * pydev_log.exception() + * finally: + * f_locals_back = None # <<<<<<<<<<<<<< + * + * def remove_return_values(self, main_debugger, frame): + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f_locals_back, Py_None); + goto __pyx_L5; + } + __pyx_L4_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1) < 0)) __Pyx_ErrFetch(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __pyx_t_10 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename; + { + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f_locals_back, Py_None); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17); + } + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_3, __pyx_t_2, __pyx_t_1); + __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14; + goto __pyx_L1_error; + } + __pyx_L5:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":477 + * return func_name + * + * def show_return_values(self, frame, arg): # <<<<<<<<<<<<<< + * try: + * try: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.show_return_values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f_locals_back); + __Pyx_XDECREF(__pyx_v_return_values_dict); + __Pyx_XDECREF(__pyx_v_name); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":493 + * f_locals_back = None + * + * def remove_return_values(self, main_debugger, frame): # <<<<<<<<<<<<<< + * try: + * try: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_19remove_return_values(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_19remove_return_values(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_main_debugger = 0; + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("remove_return_values (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_main_debugger,&__pyx_n_s_frame,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_main_debugger)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("remove_return_values", 1, 2, 2, 1); __PYX_ERR(0, 493, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "remove_return_values") < 0)) __PYX_ERR(0, 493, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_main_debugger = values[0]; + __pyx_v_frame = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("remove_return_values", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 493, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.remove_return_values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_18remove_return_values(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_main_debugger, __pyx_v_frame); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_18remove_return_values(CYTHON_UNUSED struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_main_debugger, PyObject *__pyx_v_frame) { + PyObject *__pyx_v_f_locals_back = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + char const *__pyx_t_14; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + __Pyx_RefNannySetupContext("remove_return_values", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":494 + * + * def remove_return_values(self, main_debugger, frame): + * try: # <<<<<<<<<<<<<< + * try: + * # Showing return values was turned off, we should remove them from locals dict. + */ + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":495 + * def remove_return_values(self, main_debugger, frame): + * try: + * try: # <<<<<<<<<<<<<< + * # Showing return values was turned off, we should remove them from locals dict. + * # The values can be in the current frame or in the back one + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":498 + * # Showing return values was turned off, we should remove them from locals dict. + * # The values can be in the current frame or in the back one + * frame.f_locals.pop(RETURN_VALUES_DICT, None) # <<<<<<<<<<<<<< + * + * f_locals_back = getattr(frame.f_back, "f_locals", None) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_locals); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_pop); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_RETURN_VALUES_DICT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, Py_None}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_5, Py_None}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_9); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_5); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, Py_None); + __pyx_t_5 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 498, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":500 + * frame.f_locals.pop(RETURN_VALUES_DICT, None) + * + * f_locals_back = getattr(frame.f_back, "f_locals", None) # <<<<<<<<<<<<<< + * if f_locals_back is not None: + * f_locals_back.pop(RETURN_VALUES_DICT, None) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 500, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_GetAttr3(__pyx_t_4, __pyx_n_s_f_locals, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 500, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_f_locals_back = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":501 + * + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: # <<<<<<<<<<<<<< + * f_locals_back.pop(RETURN_VALUES_DICT, None) + * except: + */ + __pyx_t_10 = (__pyx_v_f_locals_back != Py_None); + __pyx_t_11 = (__pyx_t_10 != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":502 + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: + * f_locals_back.pop(RETURN_VALUES_DICT, None) # <<<<<<<<<<<<<< + * except: + * pydev_log.exception() + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_locals_back, __pyx_n_s_pop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 502, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_RETURN_VALUES_DICT); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 502, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_5 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_9, Py_None}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 502, __pyx_L6_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_9, Py_None}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 502, __pyx_L6_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 502, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_8, __pyx_t_9); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_8, Py_None); + __pyx_t_9 = 0; + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 502, __pyx_L6_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":501 + * + * f_locals_back = getattr(frame.f_back, "f_locals", None) + * if f_locals_back is not None: # <<<<<<<<<<<<<< + * f_locals_back.pop(RETURN_VALUES_DICT, None) + * except: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":495 + * def remove_return_values(self, main_debugger, frame): + * try: + * try: # <<<<<<<<<<<<<< + * # Showing return values was turned off, we should remove them from locals dict. + * # The values can be in the current frame or in the back one + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L11_try_end; + __pyx_L6_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":503 + * if f_locals_back is not None: + * f_locals_back.pop(RETURN_VALUES_DICT, None) + * except: # <<<<<<<<<<<<<< + * pydev_log.exception() + * finally: + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.remove_return_values", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_4, &__pyx_t_7) < 0) __PYX_ERR(0, 503, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_7); + + /* "_pydevd_bundle/pydevd_cython.pyx":504 + * f_locals_back.pop(RETURN_VALUES_DICT, None) + * except: + * pydev_log.exception() # <<<<<<<<<<<<<< + * finally: + * f_locals_back = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 504, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_exception); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 504, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_9 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 504, __pyx_L8_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L7_exception_handled; + } + __pyx_L8_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":495 + * def remove_return_values(self, main_debugger, frame): + * try: + * try: # <<<<<<<<<<<<<< + * # Showing return values was turned off, we should remove them from locals dict. + * # The values can be in the current frame or in the back one + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L4_error; + __pyx_L7_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L11_try_end:; + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":506 + * pydev_log.exception() + * finally: + * f_locals_back = None # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f_locals_back, Py_None); + goto __pyx_L5; + } + __pyx_L4_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1) < 0)) __Pyx_ErrFetch(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __pyx_t_8 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename; + { + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_f_locals_back, Py_None); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17); + } + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_3, __pyx_t_2, __pyx_t_1); + __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __pyx_lineno = __pyx_t_8; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14; + goto __pyx_L1_error; + } + __pyx_L5:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":493 + * f_locals_back = None + * + * def remove_return_values(self, main_debugger, frame): # <<<<<<<<<<<<<< + * try: + * try: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.remove_return_values", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f_locals_back); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":509 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cpdef trace_dispatch(self, frame, str event, arg): # <<<<<<<<<<<<<< + * cdef str filename; + * cdef bint is_exception_event; + */ + +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_21trace_dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_trace_dispatch(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg, int __pyx_skip_dispatch) { + PyObject *__pyx_v_filename = 0; + int __pyx_v_is_exception_event; + int __pyx_v_has_exception_breakpoints; + int __pyx_v_can_skip; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_info = 0; + int __pyx_v_step_cmd; + int __pyx_v_line; + int __pyx_v_is_line; + int __pyx_v_is_call; + int __pyx_v_is_return; + int __pyx_v_should_stop; + PyObject *__pyx_v_breakpoints_for_file = 0; + PyObject *__pyx_v_curr_func_name = 0; + int __pyx_v_exist_result; + PyObject *__pyx_v_frame_skips_cache = 0; + PyObject *__pyx_v_frame_cache_key = 0; + PyObject *__pyx_v_line_cache_key = 0; + int __pyx_v_breakpoints_in_line_cache; + int __pyx_v_breakpoints_in_frame_cache; + int __pyx_v_has_breakpoint_in_frame; + PyObject *__pyx_v_main_debugger = NULL; + PyObject *__pyx_v_thread = NULL; + PyObject *__pyx_v_plugin_manager = NULL; + PyObject *__pyx_v_need_signature_trace_return = NULL; + PyObject *__pyx_v_stop_frame = NULL; + PyObject *__pyx_v_breakpoint = NULL; + PyObject *__pyx_v_flag = NULL; + PyObject *__pyx_v_stop_info = NULL; + PyObject *__pyx_v_stop = NULL; + PyObject *__pyx_v_bp_type = NULL; + PyObject *__pyx_v_new_frame = NULL; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_eval_result = NULL; + PyObject *__pyx_v_cmd = NULL; + long __pyx_v_should_skip; + PyObject *__pyx_v_plugin_stop = NULL; + PyObject *__pyx_v_force_check_project_scope = NULL; + PyObject *__pyx_v_f_code = NULL; + CYTHON_UNUSED PyObject *__pyx_v_stopped_on_plugin = NULL; + PyObject *__pyx_v_back = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_back_filename = NULL; + PyObject *__pyx_v_base = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + int __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + Py_ssize_t __pyx_t_14; + PyObject *(*__pyx_t_15)(PyObject *); + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + int __pyx_t_19; + char const *__pyx_t_20; + PyObject *__pyx_t_21 = NULL; + PyObject *__pyx_t_22 = NULL; + PyObject *__pyx_t_23 = NULL; + PyObject *__pyx_t_24 = NULL; + PyObject *__pyx_t_25 = NULL; + PyObject *__pyx_t_26 = NULL; + int __pyx_t_27; + PyObject *__pyx_t_28 = NULL; + char const *__pyx_t_29; + __Pyx_RefNannySetupContext("trace_dispatch", 0); + __Pyx_INCREF(__pyx_v_frame); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; + if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { + PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); + #endif + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_21trace_dispatch)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { + PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_arg); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); + __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); + if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { + __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; + } + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + } + #endif + } + + /* "_pydevd_bundle/pydevd_cython.pyx":535 + * # ENDIF + * # DEBUG = 'code_to_debug' in frame.f_code.co_filename + * main_debugger, filename, info, thread, frame_skips_cache, frame_cache_key = self._args # <<<<<<<<<<<<<< + * # if DEBUG: print('frame trace_dispatch %s %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, info.pydev_step_cmd)) + * try: + */ + __pyx_t_1 = __pyx_v_self->_args; + __Pyx_INCREF(__pyx_t_1); + if (likely(__pyx_t_1 != Py_None)) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 6)) { + if (size > 6) __Pyx_RaiseTooManyValuesError(6); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 535, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 5); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + #else + { + Py_ssize_t i; + PyObject** temps[6] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_6,&__pyx_t_4,&__pyx_t_7,&__pyx_t_8}; + for (i=0; i < 6; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 535, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 535, __pyx_L1_error) + } + if (!(likely(PyString_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 535, __pyx_L1_error) + if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo))))) __PYX_ERR(0, 535, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 535, __pyx_L1_error) + if (!(likely(PyTuple_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_8)->tp_name), 0))) __PYX_ERR(0, 535, __pyx_L1_error) + __pyx_v_main_debugger = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_v_filename = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + __pyx_v_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_6); + __pyx_t_6 = 0; + __pyx_v_thread = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_v_frame_skips_cache = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + __pyx_v_frame_cache_key = ((PyObject*)__pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":537 + * main_debugger, filename, info, thread, frame_skips_cache, frame_cache_key = self._args + * # if DEBUG: print('frame trace_dispatch %s %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, info.pydev_step_cmd)) + * try: # <<<<<<<<<<<<<< + * info.is_tracing = True + * line = frame.f_lineno + */ + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":538 + * # if DEBUG: print('frame trace_dispatch %s %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, info.pydev_step_cmd)) + * try: + * info.is_tracing = True # <<<<<<<<<<<<<< + * line = frame.f_lineno + * line_cache_key = (frame_cache_key, line) + */ + __pyx_v_info->is_tracing = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":539 + * try: + * info.is_tracing = True + * line = frame.f_lineno # <<<<<<<<<<<<<< + * line_cache_key = (frame_cache_key, line) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 539, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 539, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_line = __pyx_t_5; + + /* "_pydevd_bundle/pydevd_cython.pyx":540 + * info.is_tracing = True + * line = frame.f_lineno + * line_cache_key = (frame_cache_key, line) # <<<<<<<<<<<<<< + * + * if main_debugger._finish_debugging_session: + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 540, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 540, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_frame_cache_key); + __Pyx_GIVEREF(__pyx_v_frame_cache_key); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_frame_cache_key); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_line_cache_key = ((PyObject*)__pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":542 + * line_cache_key = (frame_cache_key, line) + * + * if main_debugger._finish_debugging_session: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_finish_debugging_session); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 542, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 542, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":543 + * + * if main_debugger._finish_debugging_session: + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * plugin_manager = main_debugger.plugin + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 543, __pyx_L4_error) + if ((__pyx_t_9 != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_8 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __pyx_t_1; + __pyx_t_1 = 0; + } + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":542 + * line_cache_key = (frame_cache_key, line) + * + * if main_debugger._finish_debugging_session: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":545 + * return None if event == 'call' else NO_FTRACE + * + * plugin_manager = main_debugger.plugin # <<<<<<<<<<<<<< + * + * is_exception_event = event == 'exception' + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_plugin); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 545, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_plugin_manager = __pyx_t_8; + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":547 + * plugin_manager = main_debugger.plugin + * + * is_exception_event = event == 'exception' # <<<<<<<<<<<<<< + * has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks + * + */ + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_exception, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 547, __pyx_L4_error) + __pyx_v_is_exception_event = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":548 + * + * is_exception_event = event == 'exception' + * has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks # <<<<<<<<<<<<<< + * + * if is_exception_event: + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_break_on_caught_exceptions); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 548, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 548, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_exception_breaks); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 548, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 548, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = __pyx_t_10; + __pyx_L7_bool_binop_done:; + __pyx_v_has_exception_breakpoints = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":550 + * has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks + * + * if is_exception_event: # <<<<<<<<<<<<<< + * if has_exception_breakpoints: + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + */ + __pyx_t_9 = (__pyx_v_is_exception_event != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":551 + * + * if is_exception_event: + * if has_exception_breakpoints: # <<<<<<<<<<<<<< + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * if should_stop: + */ + __pyx_t_9 = (__pyx_v_has_exception_breakpoints != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":552 + * if is_exception_event: + * if has_exception_breakpoints: + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) # <<<<<<<<<<<<<< + * if should_stop: + * self.handle_exception(frame, event, arg) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_should_stop_on_exception); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_4 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_5, __pyx_v_arg); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { + PyObject* sequence = __pyx_t_8; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 552, __pyx_L4_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_11 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_11(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_7), 2) < 0) __PYX_ERR(0, 552, __pyx_L4_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 552, __pyx_L4_error) + __pyx_L12_unpacking_done:; + } + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 552, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_should_stop = __pyx_t_9; + __Pyx_DECREF_SET(__pyx_v_frame, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":553 + * if has_exception_breakpoints: + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * if should_stop: # <<<<<<<<<<<<<< + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch + */ + __pyx_t_9 = (__pyx_v_should_stop != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":554 + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * if should_stop: + * self.handle_exception(frame, event, arg) # <<<<<<<<<<<<<< + * return self.trace_dispatch + * is_line = False + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_handle_exception); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 554, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 554, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 554, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 554, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_5, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_5, __pyx_v_arg); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 554, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":555 + * if should_stop: + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch # <<<<<<<<<<<<<< + * is_line = False + * is_return = False + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 555, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":553 + * if has_exception_breakpoints: + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * if should_stop: # <<<<<<<<<<<<<< + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":551 + * + * if is_exception_event: + * if has_exception_breakpoints: # <<<<<<<<<<<<<< + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + * if should_stop: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":556 + * self.handle_exception(frame, event, arg) + * return self.trace_dispatch + * is_line = False # <<<<<<<<<<<<<< + * is_return = False + * is_call = False + */ + __pyx_v_is_line = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":557 + * return self.trace_dispatch + * is_line = False + * is_return = False # <<<<<<<<<<<<<< + * is_call = False + * else: + */ + __pyx_v_is_return = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":558 + * is_line = False + * is_return = False + * is_call = False # <<<<<<<<<<<<<< + * else: + * is_line = event == 'line' + */ + __pyx_v_is_call = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":550 + * has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks + * + * if is_exception_event: # <<<<<<<<<<<<<< + * if has_exception_breakpoints: + * should_stop, frame = self.should_stop_on_exception(frame, event, arg) + */ + goto __pyx_L9; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":560 + * is_call = False + * else: + * is_line = event == 'line' # <<<<<<<<<<<<<< + * is_return = event == 'return' + * is_call = event == 'call' + */ + /*else*/ { + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_line, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 560, __pyx_L4_error) + __pyx_v_is_line = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":561 + * else: + * is_line = event == 'line' + * is_return = event == 'return' # <<<<<<<<<<<<<< + * is_call = event == 'call' + * if not is_line and not is_return and not is_call: + */ + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_return, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 561, __pyx_L4_error) + __pyx_v_is_return = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":562 + * is_line = event == 'line' + * is_return = event == 'return' + * is_call = event == 'call' # <<<<<<<<<<<<<< + * if not is_line and not is_return and not is_call: + * # Unexpected: just keep the same trace func. + */ + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 562, __pyx_L4_error) + __pyx_v_is_call = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":563 + * is_return = event == 'return' + * is_call = event == 'call' + * if not is_line and not is_return and not is_call: # <<<<<<<<<<<<<< + * # Unexpected: just keep the same trace func. + * return self.trace_dispatch + */ + __pyx_t_10 = ((!(__pyx_v_is_line != 0)) != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L15_bool_binop_done; + } + __pyx_t_10 = ((!(__pyx_v_is_return != 0)) != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L15_bool_binop_done; + } + __pyx_t_10 = ((!(__pyx_v_is_call != 0)) != 0); + __pyx_t_9 = __pyx_t_10; + __pyx_L15_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":565 + * if not is_line and not is_return and not is_call: + * # Unexpected: just keep the same trace func. + * return self.trace_dispatch # <<<<<<<<<<<<<< + * + * need_signature_trace_return = False + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 565, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":563 + * is_return = event == 'return' + * is_call = event == 'call' + * if not is_line and not is_return and not is_call: # <<<<<<<<<<<<<< + * # Unexpected: just keep the same trace func. + * return self.trace_dispatch + */ + } + } + __pyx_L9:; + + /* "_pydevd_bundle/pydevd_cython.pyx":567 + * return self.trace_dispatch + * + * need_signature_trace_return = False # <<<<<<<<<<<<<< + * if main_debugger.signature_factory is not None: + * if is_call: + */ + __Pyx_INCREF(Py_False); + __pyx_v_need_signature_trace_return = Py_False; + + /* "_pydevd_bundle/pydevd_cython.pyx":568 + * + * need_signature_trace_return = False + * if main_debugger.signature_factory is not None: # <<<<<<<<<<<<<< + * if is_call: + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_signature_factory); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 568, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = (__pyx_t_8 != Py_None); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":569 + * need_signature_trace_return = False + * if main_debugger.signature_factory is not None: + * if is_call: # <<<<<<<<<<<<<< + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + * elif is_return: + */ + __pyx_t_10 = (__pyx_v_is_call != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":570 + * if main_debugger.signature_factory is not None: + * if is_call: + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) # <<<<<<<<<<<<<< + * elif is_return: + * send_signature_return_trace(main_debugger, frame, filename, arg) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_send_signature_call_trace); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 570, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_filename}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 570, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_filename}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 570, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_1 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 570, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_5, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_5, __pyx_v_filename); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 570, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_need_signature_trace_return, __pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":569 + * need_signature_trace_return = False + * if main_debugger.signature_factory is not None: + * if is_call: # <<<<<<<<<<<<<< + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + * elif is_return: + */ + goto __pyx_L19; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":571 + * if is_call: + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + * elif is_return: # <<<<<<<<<<<<<< + * send_signature_return_trace(main_debugger, frame, filename, arg) + * + */ + __pyx_t_10 = (__pyx_v_is_return != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":572 + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + * elif is_return: + * send_signature_return_trace(main_debugger, frame, filename, arg) # <<<<<<<<<<<<<< + * + * stop_frame = info.pydev_step_stop + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_send_signature_return_trace); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 572, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_filename, __pyx_v_arg}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 572, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_filename, __pyx_v_arg}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 4+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 572, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_7 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 572, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_5, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_5, __pyx_v_filename); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_5, __pyx_v_arg); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 572, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":571 + * if is_call: + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + * elif is_return: # <<<<<<<<<<<<<< + * send_signature_return_trace(main_debugger, frame, filename, arg) + * + */ + } + __pyx_L19:; + + /* "_pydevd_bundle/pydevd_cython.pyx":568 + * + * need_signature_trace_return = False + * if main_debugger.signature_factory is not None: # <<<<<<<<<<<<<< + * if is_call: + * need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":574 + * send_signature_return_trace(main_debugger, frame, filename, arg) + * + * stop_frame = info.pydev_step_stop # <<<<<<<<<<<<<< + * step_cmd = info.pydev_step_cmd + * + */ + __pyx_t_8 = __pyx_v_info->pydev_step_stop; + __Pyx_INCREF(__pyx_t_8); + __pyx_v_stop_frame = __pyx_t_8; + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":575 + * + * stop_frame = info.pydev_step_stop + * step_cmd = info.pydev_step_cmd # <<<<<<<<<<<<<< + * + * if is_exception_event: + */ + __pyx_t_5 = __pyx_v_info->pydev_step_cmd; + __pyx_v_step_cmd = __pyx_t_5; + + /* "_pydevd_bundle/pydevd_cython.pyx":577 + * step_cmd = info.pydev_step_cmd + * + * if is_exception_event: # <<<<<<<<<<<<<< + * breakpoints_for_file = None + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + */ + __pyx_t_10 = (__pyx_v_is_exception_event != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":578 + * + * if is_exception_event: + * breakpoints_for_file = None # <<<<<<<<<<<<<< + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + */ + __Pyx_INCREF(Py_None); + __pyx_v_breakpoints_for_file = ((PyObject*)Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":579 + * if is_exception_event: + * breakpoints_for_file = None + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ # <<<<<<<<<<<<<< + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + * if step_cmd == 108: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_stop_frame); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 579, __pyx_L4_error) + if (__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L22_bool_binop_done; + } + __pyx_t_9 = (__pyx_v_stop_frame != __pyx_v_frame); + __pyx_t_12 = (__pyx_t_9 != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L22_bool_binop_done; + } + switch (__pyx_v_step_cmd) { + case 0x6C: + case 0x9F: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L22_bool_binop_done; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":580 + * breakpoints_for_file = None + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: # <<<<<<<<<<<<<< + * if step_cmd == 108: + * info.pydev_step_cmd = 107 + */ + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_arg, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 580, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_8, __pyx_builtin_StopIteration, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L4_error) + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 580, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L27_bool_binop_done; + } + __pyx_t_4 = PyObject_RichCompare(__pyx_t_8, __pyx_builtin_GeneratorExit, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L4_error) + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 580, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __pyx_t_12; + __pyx_L27_bool_binop_done:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = (__pyx_t_9 != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L22_bool_binop_done; + } + __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_arg, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 580, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_12 = (__pyx_t_8 == Py_None); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = (__pyx_t_12 != 0); + __pyx_t_10 = __pyx_t_9; + __pyx_L22_bool_binop_done:; + + /* "_pydevd_bundle/pydevd_cython.pyx":579 + * if is_exception_event: + * breakpoints_for_file = None + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ # <<<<<<<<<<<<<< + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + * if step_cmd == 108: + */ + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":581 + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + * if step_cmd == 108: # <<<<<<<<<<<<<< + * info.pydev_step_cmd = 107 + * else: + */ + __pyx_t_10 = ((__pyx_v_step_cmd == 0x6C) != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":582 + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + * if step_cmd == 108: + * info.pydev_step_cmd = 107 # <<<<<<<<<<<<<< + * else: + * info.pydev_step_cmd = 144 + */ + __pyx_v_info->pydev_step_cmd = 0x6B; + + /* "_pydevd_bundle/pydevd_cython.pyx":581 + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + * if step_cmd == 108: # <<<<<<<<<<<<<< + * info.pydev_step_cmd = 107 + * else: + */ + goto __pyx_L29; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":584 + * info.pydev_step_cmd = 107 + * else: + * info.pydev_step_cmd = 144 # <<<<<<<<<<<<<< + * info.pydev_step_stop = None + * else: + */ + /*else*/ { + __pyx_v_info->pydev_step_cmd = 0x90; + } + __pyx_L29:; + + /* "_pydevd_bundle/pydevd_cython.pyx":585 + * else: + * info.pydev_step_cmd = 144 + * info.pydev_step_stop = None # <<<<<<<<<<<<<< + * else: + * # If we are in single step mode and something causes us to exit the current frame, we need to make sure we break + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_info->pydev_step_stop); + __Pyx_DECREF(__pyx_v_info->pydev_step_stop); + __pyx_v_info->pydev_step_stop = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":579 + * if is_exception_event: + * breakpoints_for_file = None + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ # <<<<<<<<<<<<<< + * arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + * if step_cmd == 108: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":577 + * step_cmd = info.pydev_step_cmd + * + * if is_exception_event: # <<<<<<<<<<<<<< + * breakpoints_for_file = None + * if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + */ + goto __pyx_L20; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":593 + * # Note: this is especially troublesome when we're skipping code with the + * # @DontTrace comment. + * if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): # <<<<<<<<<<<<<< + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + * if step_cmd in (108, 109): + */ + /*else*/ { + __pyx_t_9 = (__pyx_v_stop_frame == __pyx_v_frame); + __pyx_t_12 = (__pyx_t_9 != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L31_bool_binop_done; + } + __pyx_t_12 = (__pyx_v_is_return != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L31_bool_binop_done; + } + switch (__pyx_v_step_cmd) { + case 0x6C: + case 0x6D: + case 0x9F: + case 0xA0: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_9 = (__pyx_t_12 != 0); + __pyx_t_10 = __pyx_t_9; + __pyx_L31_bool_binop_done:; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":594 + * # @DontTrace comment. + * if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) # <<<<<<<<<<<<<< + * if step_cmd in (108, 109): + * info.pydev_step_cmd = 107 + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 594, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_co_flags); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 594, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyInt_AndObjC(__pyx_t_4, __pyx_int_32, 0x20, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 594, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 594, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = ((!__pyx_t_10) != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":595 + * if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + * if step_cmd in (108, 109): # <<<<<<<<<<<<<< + * info.pydev_step_cmd = 107 + * else: + */ + switch (__pyx_v_step_cmd) { + case 0x6C: + case 0x6D: + + /* "_pydevd_bundle/pydevd_cython.pyx":596 + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + * if step_cmd in (108, 109): + * info.pydev_step_cmd = 107 # <<<<<<<<<<<<<< + * else: + * info.pydev_step_cmd = 144 + */ + __pyx_v_info->pydev_step_cmd = 0x6B; + + /* "_pydevd_bundle/pydevd_cython.pyx":595 + * if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + * if step_cmd in (108, 109): # <<<<<<<<<<<<<< + * info.pydev_step_cmd = 107 + * else: + */ + break; + default: + + /* "_pydevd_bundle/pydevd_cython.pyx":598 + * info.pydev_step_cmd = 107 + * else: + * info.pydev_step_cmd = 144 # <<<<<<<<<<<<<< + * info.pydev_step_stop = None + * + */ + __pyx_v_info->pydev_step_cmd = 0x90; + break; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":599 + * else: + * info.pydev_step_cmd = 144 + * info.pydev_step_stop = None # <<<<<<<<<<<<<< + * + * breakpoints_for_file = main_debugger.breakpoints.get(filename) + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_info->pydev_step_stop); + __Pyx_DECREF(__pyx_v_info->pydev_step_stop); + __pyx_v_info->pydev_step_stop = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":594 + * # @DontTrace comment. + * if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) # <<<<<<<<<<<<<< + * if step_cmd in (108, 109): + * info.pydev_step_cmd = 107 + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":593 + * # Note: this is especially troublesome when we're skipping code with the + * # @DontTrace comment. + * if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): # <<<<<<<<<<<<<< + * if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + * if step_cmd in (108, 109): + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":601 + * info.pydev_step_stop = None + * + * breakpoints_for_file = main_debugger.breakpoints.get(filename) # <<<<<<<<<<<<<< + * + * can_skip = False + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_breakpoints); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 601, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 601, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_4, __pyx_v_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_filename); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 601, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!(likely(PyDict_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_8)->tp_name), 0))) __PYX_ERR(0, 601, __pyx_L4_error) + __pyx_v_breakpoints_for_file = ((PyObject*)__pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":603 + * breakpoints_for_file = main_debugger.breakpoints.get(filename) + * + * can_skip = False # <<<<<<<<<<<<<< + * + * if info.pydev_state == 1: # 1 = 1 + */ + __pyx_v_can_skip = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":605 + * can_skip = False + * + * if info.pydev_state == 1: # 1 = 1 # <<<<<<<<<<<<<< + * # we can skip if: + * # - we have no stop marked + */ + __pyx_t_9 = ((__pyx_v_info->pydev_state == 1) != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":609 + * # - we have no stop marked + * # - we should make a step return/step over and we're not in the current frame + * can_skip = (step_cmd == -1 and stop_frame is None) \ # <<<<<<<<<<<<<< + * or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame) + * + */ + __pyx_t_10 = ((__pyx_v_step_cmd == -1L) != 0); + if (!__pyx_t_10) { + goto __pyx_L37_next_or; + } else { + } + __pyx_t_10 = (__pyx_v_stop_frame == Py_None); + __pyx_t_12 = (__pyx_t_10 != 0); + if (!__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L36_bool_binop_done; + } + __pyx_L37_next_or:; + + /* "_pydevd_bundle/pydevd_cython.pyx":610 + * # - we should make a step return/step over and we're not in the current frame + * can_skip = (step_cmd == -1 and stop_frame is None) \ + * or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame) # <<<<<<<<<<<<<< + * + * if can_skip: + */ + switch (__pyx_v_step_cmd) { + case 0x6C: + case 0x6D: + case 0x9F: + case 0xA0: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_10 = (__pyx_t_12 != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L36_bool_binop_done; + } + __pyx_t_10 = (__pyx_v_stop_frame != __pyx_v_frame); + __pyx_t_12 = (__pyx_t_10 != 0); + __pyx_t_9 = __pyx_t_12; + __pyx_L36_bool_binop_done:; + __pyx_v_can_skip = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":612 + * or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame) + * + * if can_skip: # <<<<<<<<<<<<<< + * if plugin_manager is not None and ( + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + */ + __pyx_t_9 = (__pyx_v_can_skip != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":613 + * + * if can_skip: + * if plugin_manager is not None and ( # <<<<<<<<<<<<<< + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + * can_skip = plugin_manager.can_skip(main_debugger, frame) + */ + __pyx_t_12 = (__pyx_v_plugin_manager != Py_None); + __pyx_t_10 = (__pyx_t_12 != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L42_bool_binop_done; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":614 + * if can_skip: + * if plugin_manager is not None and ( + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): # <<<<<<<<<<<<<< + * can_skip = plugin_manager.can_skip(main_debugger, frame) + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_line_breaks); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 614, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 614, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L42_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_exception_breaks); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 614, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 614, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = __pyx_t_10; + __pyx_L42_bool_binop_done:; + + /* "_pydevd_bundle/pydevd_cython.pyx":613 + * + * if can_skip: + * if plugin_manager is not None and ( # <<<<<<<<<<<<<< + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + * can_skip = plugin_manager.can_skip(main_debugger, frame) + */ + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":615 + * if plugin_manager is not None and ( + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + * can_skip = plugin_manager.can_skip(main_debugger, frame) # <<<<<<<<<<<<<< + * + * if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_plugin_manager, __pyx_n_s_can_skip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 615, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_main_debugger, __pyx_v_frame}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 615, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_main_debugger, __pyx_v_frame}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 615, __pyx_L4_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 615, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_5, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_5, __pyx_v_frame); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 615, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 615, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_can_skip = __pyx_t_9; + + /* "_pydevd_bundle/pydevd_cython.pyx":613 + * + * if can_skip: + * if plugin_manager is not None and ( # <<<<<<<<<<<<<< + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + * can_skip = plugin_manager.can_skip(main_debugger, frame) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":617 + * can_skip = plugin_manager.can_skip(main_debugger, frame) + * + * if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop: # <<<<<<<<<<<<<< + * # trace function for showing return values after step over + * can_skip = False + */ + __pyx_t_10 = (__pyx_v_can_skip != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L46_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_show_return_values); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 617, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 617, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L46_bool_binop_done; + } + switch (__pyx_v_info->pydev_step_cmd) { + case 0x6C: + case 0x9F: + __pyx_t_10 = 1; + break; + default: + __pyx_t_10 = 0; + break; + } + __pyx_t_12 = (__pyx_t_10 != 0); + if (__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L46_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 617, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_12 = (__pyx_t_8 == __pyx_v_info->pydev_step_stop); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_10 = (__pyx_t_12 != 0); + __pyx_t_9 = __pyx_t_10; + __pyx_L46_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":619 + * if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop: + * # trace function for showing return values after step over + * can_skip = False # <<<<<<<<<<<<<< + * + * # Let's check to see if we are in a function that has a breakpoint. If we don't have a breakpoint, + */ + __pyx_v_can_skip = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":617 + * can_skip = plugin_manager.can_skip(main_debugger, frame) + * + * if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop: # <<<<<<<<<<<<<< + * # trace function for showing return values after step over + * can_skip = False + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":612 + * or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame) + * + * if can_skip: # <<<<<<<<<<<<<< + * if plugin_manager is not None and ( + * main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":605 + * can_skip = False + * + * if info.pydev_state == 1: # 1 = 1 # <<<<<<<<<<<<<< + * # we can skip if: + * # - we have no stop marked + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":625 + * # also, after we hit a breakpoint and go to some other debugging state, we have to force the set trace anyway, + * # so, that's why the additional checks are there. + * if not breakpoints_for_file: # <<<<<<<<<<<<<< + * if can_skip: + * if has_exception_breakpoints: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_breakpoints_for_file); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 625, __pyx_L4_error) + __pyx_t_10 = ((!__pyx_t_9) != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":626 + * # so, that's why the additional checks are there. + * if not breakpoints_for_file: + * if can_skip: # <<<<<<<<<<<<<< + * if has_exception_breakpoints: + * return self.trace_exception + */ + __pyx_t_10 = (__pyx_v_can_skip != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":627 + * if not breakpoints_for_file: + * if can_skip: + * if has_exception_breakpoints: # <<<<<<<<<<<<<< + * return self.trace_exception + * else: + */ + __pyx_t_10 = (__pyx_v_has_exception_breakpoints != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":628 + * if can_skip: + * if has_exception_breakpoints: + * return self.trace_exception # <<<<<<<<<<<<<< + * else: + * if need_signature_trace_return: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_exception); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 628, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":627 + * if not breakpoints_for_file: + * if can_skip: + * if has_exception_breakpoints: # <<<<<<<<<<<<<< + * return self.trace_exception + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":630 + * return self.trace_exception + * else: + * if need_signature_trace_return: # <<<<<<<<<<<<<< + * return self.trace_return + * else: + */ + /*else*/ { + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_need_signature_trace_return); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 630, __pyx_L4_error) + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":631 + * else: + * if need_signature_trace_return: + * return self.trace_return # <<<<<<<<<<<<<< + * else: + * return None if is_call else NO_FTRACE + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_return); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 631, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":630 + * return self.trace_exception + * else: + * if need_signature_trace_return: # <<<<<<<<<<<<<< + * return self.trace_return + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":633 + * return self.trace_return + * else: + * return None if is_call else NO_FTRACE # <<<<<<<<<<<<<< + * + * else: + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + if ((__pyx_v_is_call != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_8 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 633, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __pyx_t_7; + __pyx_t_7 = 0; + } + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":626 + * # so, that's why the additional checks are there. + * if not breakpoints_for_file: + * if can_skip: # <<<<<<<<<<<<<< + * if has_exception_breakpoints: + * return self.trace_exception + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":625 + * # also, after we hit a breakpoint and go to some other debugging state, we have to force the set trace anyway, + * # so, that's why the additional checks are there. + * if not breakpoints_for_file: # <<<<<<<<<<<<<< + * if can_skip: + * if has_exception_breakpoints: + */ + goto __pyx_L50; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":637 + * else: + * # When cached, 0 means we don't have a breakpoint and 1 means we have. + * if can_skip: # <<<<<<<<<<<<<< + * breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + * if breakpoints_in_line_cache == 0: + */ + /*else*/ { + __pyx_t_10 = (__pyx_v_can_skip != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":638 + * # When cached, 0 means we don't have a breakpoint and 1 means we have. + * if can_skip: + * breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) # <<<<<<<<<<<<<< + * if breakpoints_in_line_cache == 0: + * return self.trace_dispatch + */ + if (unlikely(__pyx_v_frame_skips_cache == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get"); + __PYX_ERR(0, 638, __pyx_L4_error) + } + __pyx_t_8 = __Pyx_PyDict_GetItemDefault(__pyx_v_frame_skips_cache, __pyx_v_line_cache_key, __pyx_int_neg_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 638, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 638, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_breakpoints_in_line_cache = __pyx_t_5; + + /* "_pydevd_bundle/pydevd_cython.pyx":639 + * if can_skip: + * breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + * if breakpoints_in_line_cache == 0: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * + */ + __pyx_t_10 = ((__pyx_v_breakpoints_in_line_cache == 0) != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":640 + * breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + * if breakpoints_in_line_cache == 0: + * return self.trace_dispatch # <<<<<<<<<<<<<< + * + * breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 640, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":639 + * if can_skip: + * breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + * if breakpoints_in_line_cache == 0: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":637 + * else: + * # When cached, 0 means we don't have a breakpoint and 1 means we have. + * if can_skip: # <<<<<<<<<<<<<< + * breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + * if breakpoints_in_line_cache == 0: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":642 + * return self.trace_dispatch + * + * breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1) # <<<<<<<<<<<<<< + * if breakpoints_in_frame_cache != -1: + * # Gotten from cache. + */ + if (unlikely(__pyx_v_frame_skips_cache == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get"); + __PYX_ERR(0, 642, __pyx_L4_error) + } + __pyx_t_8 = __Pyx_PyDict_GetItemDefault(__pyx_v_frame_skips_cache, __pyx_v_frame_cache_key, __pyx_int_neg_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 642, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 642, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_breakpoints_in_frame_cache = __pyx_t_5; + + /* "_pydevd_bundle/pydevd_cython.pyx":643 + * + * breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1) + * if breakpoints_in_frame_cache != -1: # <<<<<<<<<<<<<< + * # Gotten from cache. + * has_breakpoint_in_frame = breakpoints_in_frame_cache == 1 + */ + __pyx_t_10 = ((__pyx_v_breakpoints_in_frame_cache != -1L) != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":645 + * if breakpoints_in_frame_cache != -1: + * # Gotten from cache. + * has_breakpoint_in_frame = breakpoints_in_frame_cache == 1 # <<<<<<<<<<<<<< + * + * else: + */ + __pyx_v_has_breakpoint_in_frame = (__pyx_v_breakpoints_in_frame_cache == 1); + + /* "_pydevd_bundle/pydevd_cython.pyx":643 + * + * breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1) + * if breakpoints_in_frame_cache != -1: # <<<<<<<<<<<<<< + * # Gotten from cache. + * has_breakpoint_in_frame = breakpoints_in_frame_cache == 1 + */ + goto __pyx_L56; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":648 + * + * else: + * has_breakpoint_in_frame = False # <<<<<<<<<<<<<< + * # Checks the breakpoint to see if there is a context match in some function + * curr_func_name = frame.f_code.co_name + */ + /*else*/ { + __pyx_v_has_breakpoint_in_frame = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":650 + * has_breakpoint_in_frame = False + * # Checks the breakpoint to see if there is a context match in some function + * curr_func_name = frame.f_code.co_name # <<<<<<<<<<<<<< + * + * # global context is set with an empty name + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 650, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_co_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 650, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!(likely(PyString_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 650, __pyx_L4_error) + __pyx_v_curr_func_name = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":653 + * + * # global context is set with an empty name + * if curr_func_name in ('?', '', ''): # <<<<<<<<<<<<<< + * curr_func_name = '' + * + */ + __Pyx_INCREF(__pyx_v_curr_func_name); + __pyx_t_13 = __pyx_v_curr_func_name; + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_t_13, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 653, __pyx_L4_error) + __pyx_t_12 = (__pyx_t_9 != 0); + if (!__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L58_bool_binop_done; + } + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_13, __pyx_kp_s_module, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 653, __pyx_L4_error) + __pyx_t_9 = (__pyx_t_12 != 0); + if (!__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L58_bool_binop_done; + } + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_t_13, __pyx_kp_s_lambda, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 653, __pyx_L4_error) + __pyx_t_12 = (__pyx_t_9 != 0); + __pyx_t_10 = __pyx_t_12; + __pyx_L58_bool_binop_done:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_12 = (__pyx_t_10 != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":654 + * # global context is set with an empty name + * if curr_func_name in ('?', '', ''): + * curr_func_name = '' # <<<<<<<<<<<<<< + * + * for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() + */ + __Pyx_INCREF(__pyx_kp_s_); + __Pyx_DECREF_SET(__pyx_v_curr_func_name, __pyx_kp_s_); + + /* "_pydevd_bundle/pydevd_cython.pyx":653 + * + * # global context is set with an empty name + * if curr_func_name in ('?', '', ''): # <<<<<<<<<<<<<< + * curr_func_name = '' + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":656 + * curr_func_name = '' + * + * for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() # <<<<<<<<<<<<<< + * # will match either global or some function + * if breakpoint.func_name in ('None', curr_func_name): + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_dict_iter_values); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 656, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_v_breakpoints_for_file) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_breakpoints_for_file); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 656, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { + __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); __pyx_t_14 = 0; + __pyx_t_15 = NULL; + } else { + __pyx_t_14 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 656, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 656, __pyx_L4_error) + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + for (;;) { + if (likely(!__pyx_t_15)) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_7); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 656, __pyx_L4_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 656, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } else { + if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_7); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 656, __pyx_L4_error) + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 656, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + } + } else { + __pyx_t_7 = __pyx_t_15(__pyx_t_8); + if (unlikely(!__pyx_t_7)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 656, __pyx_L4_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF_SET(__pyx_v_breakpoint, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":658 + * for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() + * # will match either global or some function + * if breakpoint.func_name in ('None', curr_func_name): # <<<<<<<<<<<<<< + * has_breakpoint_in_frame = True + * break + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_func_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 658, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_7, __pyx_n_s_None, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 658, __pyx_L4_error) + if (!__pyx_t_10) { + } else { + __pyx_t_12 = __pyx_t_10; + goto __pyx_L64_bool_binop_done; + } + __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_7, __pyx_v_curr_func_name, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 658, __pyx_L4_error) + __pyx_t_12 = __pyx_t_10; + __pyx_L64_bool_binop_done:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = (__pyx_t_12 != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":659 + * # will match either global or some function + * if breakpoint.func_name in ('None', curr_func_name): + * has_breakpoint_in_frame = True # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_has_breakpoint_in_frame = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":660 + * if breakpoint.func_name in ('None', curr_func_name): + * has_breakpoint_in_frame = True + * break # <<<<<<<<<<<<<< + * + * # Cache the value (1 or 0 or -1 for default because of cython). + */ + goto __pyx_L62_break; + + /* "_pydevd_bundle/pydevd_cython.pyx":658 + * for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() + * # will match either global or some function + * if breakpoint.func_name in ('None', curr_func_name): # <<<<<<<<<<<<<< + * has_breakpoint_in_frame = True + * break + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":656 + * curr_func_name = '' + * + * for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() # <<<<<<<<<<<<<< + * # will match either global or some function + * if breakpoint.func_name in ('None', curr_func_name): + */ + } + __pyx_L62_break:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":663 + * + * # Cache the value (1 or 0 or -1 for default because of cython). + * if has_breakpoint_in_frame: # <<<<<<<<<<<<<< + * frame_skips_cache[frame_cache_key] = 1 + * else: + */ + __pyx_t_10 = (__pyx_v_has_breakpoint_in_frame != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":664 + * # Cache the value (1 or 0 or -1 for default because of cython). + * if has_breakpoint_in_frame: + * frame_skips_cache[frame_cache_key] = 1 # <<<<<<<<<<<<<< + * else: + * frame_skips_cache[frame_cache_key] = 0 + */ + if (unlikely(__pyx_v_frame_skips_cache == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 664, __pyx_L4_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_frame_skips_cache, __pyx_v_frame_cache_key, __pyx_int_1) < 0)) __PYX_ERR(0, 664, __pyx_L4_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":663 + * + * # Cache the value (1 or 0 or -1 for default because of cython). + * if has_breakpoint_in_frame: # <<<<<<<<<<<<<< + * frame_skips_cache[frame_cache_key] = 1 + * else: + */ + goto __pyx_L66; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":666 + * frame_skips_cache[frame_cache_key] = 1 + * else: + * frame_skips_cache[frame_cache_key] = 0 # <<<<<<<<<<<<<< + * + * if can_skip and not has_breakpoint_in_frame: + */ + /*else*/ { + if (unlikely(__pyx_v_frame_skips_cache == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 666, __pyx_L4_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_frame_skips_cache, __pyx_v_frame_cache_key, __pyx_int_0) < 0)) __PYX_ERR(0, 666, __pyx_L4_error) + } + __pyx_L66:; + } + __pyx_L56:; + + /* "_pydevd_bundle/pydevd_cython.pyx":668 + * frame_skips_cache[frame_cache_key] = 0 + * + * if can_skip and not has_breakpoint_in_frame: # <<<<<<<<<<<<<< + * if has_exception_breakpoints: + * return self.trace_exception + */ + __pyx_t_12 = (__pyx_v_can_skip != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L68_bool_binop_done; + } + __pyx_t_12 = ((!(__pyx_v_has_breakpoint_in_frame != 0)) != 0); + __pyx_t_10 = __pyx_t_12; + __pyx_L68_bool_binop_done:; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":669 + * + * if can_skip and not has_breakpoint_in_frame: + * if has_exception_breakpoints: # <<<<<<<<<<<<<< + * return self.trace_exception + * else: + */ + __pyx_t_10 = (__pyx_v_has_exception_breakpoints != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":670 + * if can_skip and not has_breakpoint_in_frame: + * if has_exception_breakpoints: + * return self.trace_exception # <<<<<<<<<<<<<< + * else: + * if need_signature_trace_return: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_exception); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 670, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":669 + * + * if can_skip and not has_breakpoint_in_frame: + * if has_exception_breakpoints: # <<<<<<<<<<<<<< + * return self.trace_exception + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":672 + * return self.trace_exception + * else: + * if need_signature_trace_return: # <<<<<<<<<<<<<< + * return self.trace_return + * else: + */ + /*else*/ { + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_need_signature_trace_return); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 672, __pyx_L4_error) + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":673 + * else: + * if need_signature_trace_return: + * return self.trace_return # <<<<<<<<<<<<<< + * else: + * return None if is_call else NO_FTRACE + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_return); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 673, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":672 + * return self.trace_exception + * else: + * if need_signature_trace_return: # <<<<<<<<<<<<<< + * return self.trace_return + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":675 + * return self.trace_return + * else: + * return None if is_call else NO_FTRACE # <<<<<<<<<<<<<< + * + * # We may have hit a breakpoint or we are already in step mode. Either way, let's check what we should do in this frame + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + if ((__pyx_v_is_call != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_8 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 675, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __pyx_t_7; + __pyx_t_7 = 0; + } + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L3_return; + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":668 + * frame_skips_cache[frame_cache_key] = 0 + * + * if can_skip and not has_breakpoint_in_frame: # <<<<<<<<<<<<<< + * if has_exception_breakpoints: + * return self.trace_exception + */ + } + } + __pyx_L50:; + } + __pyx_L20:; + + /* "_pydevd_bundle/pydevd_cython.pyx":680 + * # if DEBUG: print('NOT skipped: %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, event, frame.__class__.__name__)) + * + * try: # <<<<<<<<<<<<<< + * flag = False + * # return is not taken into account for breakpoint hit because we'd have a double-hit in this case + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":681 + * + * try: + * flag = False # <<<<<<<<<<<<<< + * # return is not taken into account for breakpoint hit because we'd have a double-hit in this case + * # (one for the line and the other for the return). + */ + __Pyx_INCREF(Py_False); + __pyx_v_flag = Py_False; + + /* "_pydevd_bundle/pydevd_cython.pyx":685 + * # (one for the line and the other for the return). + * + * stop_info = {} # <<<<<<<<<<<<<< + * breakpoint = None + * exist_result = False + */ + __pyx_t_8 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_stop_info = ((PyObject*)__pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":686 + * + * stop_info = {} + * breakpoint = None # <<<<<<<<<<<<<< + * exist_result = False + * stop = False + */ + __Pyx_INCREF(Py_None); + __Pyx_XDECREF_SET(__pyx_v_breakpoint, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":687 + * stop_info = {} + * breakpoint = None + * exist_result = False # <<<<<<<<<<<<<< + * stop = False + * bp_type = None + */ + __pyx_v_exist_result = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":688 + * breakpoint = None + * exist_result = False + * stop = False # <<<<<<<<<<<<<< + * bp_type = None + * if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: + */ + __Pyx_INCREF(Py_False); + __pyx_v_stop = Py_False; + + /* "_pydevd_bundle/pydevd_cython.pyx":689 + * exist_result = False + * stop = False + * bp_type = None # <<<<<<<<<<<<<< + * if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: + * breakpoint = breakpoints_for_file[line] + */ + __Pyx_INCREF(Py_None); + __pyx_v_bp_type = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":690 + * stop = False + * bp_type = None + * if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: # <<<<<<<<<<<<<< + * breakpoint = breakpoints_for_file[line] + * new_frame = frame + */ + __pyx_t_12 = ((!(__pyx_v_is_return != 0)) != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L79_bool_binop_done; + } + __pyx_t_12 = ((__pyx_v_info->pydev_state != 2) != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L79_bool_binop_done; + } + __pyx_t_12 = (__pyx_v_breakpoints_for_file != ((PyObject*)Py_None)); + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L79_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_line); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 690, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + if (unlikely(__pyx_v_breakpoints_for_file == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + __PYX_ERR(0, 690, __pyx_L72_error) + } + __pyx_t_9 = (__Pyx_PyDict_ContainsTF(__pyx_t_8, __pyx_v_breakpoints_for_file, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 690, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = (__pyx_t_9 != 0); + __pyx_t_10 = __pyx_t_12; + __pyx_L79_bool_binop_done:; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":691 + * bp_type = None + * if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: + * breakpoint = breakpoints_for_file[line] # <<<<<<<<<<<<<< + * new_frame = frame + * stop = True + */ + if (unlikely(__pyx_v_breakpoints_for_file == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 691, __pyx_L72_error) + } + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_line); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 691, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_breakpoints_for_file, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF_SET(__pyx_v_breakpoint, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":692 + * if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: + * breakpoint = breakpoints_for_file[line] + * new_frame = frame # <<<<<<<<<<<<<< + * stop = True + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): + */ + __Pyx_INCREF(__pyx_v_frame); + __pyx_v_new_frame = __pyx_v_frame; + + /* "_pydevd_bundle/pydevd_cython.pyx":693 + * breakpoint = breakpoints_for_file[line] + * new_frame = frame + * stop = True # <<<<<<<<<<<<<< + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + */ + __Pyx_INCREF(Py_True); + __Pyx_DECREF_SET(__pyx_v_stop, Py_True); + + /* "_pydevd_bundle/pydevd_cython.pyx":694 + * new_frame = frame + * stop = True + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): # <<<<<<<<<<<<<< + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + */ + switch (__pyx_v_step_cmd) { + case 0x6C: + case 0x9F: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L84_bool_binop_done; + } + __pyx_t_9 = (__pyx_v_stop_frame == __pyx_v_frame); + __pyx_t_12 = (__pyx_t_9 != 0); + if (__pyx_t_12) { + } else { + __pyx_t_10 = __pyx_t_12; + goto __pyx_L84_bool_binop_done; + } + __pyx_t_12 = (__pyx_v_is_line != 0); + __pyx_t_10 = __pyx_t_12; + __pyx_L84_bool_binop_done:; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":695 + * stop = True + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) # <<<<<<<<<<<<<< + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":694 + * new_frame = frame + * stop = True + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): # <<<<<<<<<<<<<< + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":690 + * stop = False + * bp_type = None + * if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: # <<<<<<<<<<<<<< + * breakpoint = breakpoints_for_file[line] + * new_frame = frame + */ + goto __pyx_L78; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":696 + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: # <<<<<<<<<<<<<< + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + * if result: + */ + __pyx_t_12 = (__pyx_v_plugin_manager != Py_None); + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L87_bool_binop_done; + } + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_line_breaks); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 696, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 696, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_10 = __pyx_t_9; + __pyx_L87_bool_binop_done:; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":697 + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) # <<<<<<<<<<<<<< + * if result: + * exist_result = True + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_plugin_manager, __pyx_n_s_get_breakpoint); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 697, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[6] = {__pyx_t_1, __pyx_v_main_debugger, ((PyObject *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_5, 5+__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 697, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[6] = {__pyx_t_1, __pyx_v_main_debugger, ((PyObject *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_5, 5+__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 697, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_4 = PyTuple_New(5+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 697, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_main_debugger); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, ((PyObject *)__pyx_v_self)); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_5, __pyx_v_event); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_4, 4+__pyx_t_5, __pyx_v_self->_args); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 697, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_result = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":698 + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + * if result: # <<<<<<<<<<<<<< + * exist_result = True + * flag, breakpoint, new_frame, bp_type = result + */ + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 698, __pyx_L72_error) + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":699 + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + * if result: + * exist_result = True # <<<<<<<<<<<<<< + * flag, breakpoint, new_frame, bp_type = result + * + */ + __pyx_v_exist_result = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":700 + * if result: + * exist_result = True + * flag, breakpoint, new_frame, bp_type = result # <<<<<<<<<<<<<< + * + * if breakpoint: + */ + if ((likely(PyTuple_CheckExact(__pyx_v_result))) || (PyList_CheckExact(__pyx_v_result))) { + PyObject* sequence = __pyx_v_result; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 700, __pyx_L72_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + __pyx_t_4 = PyList_GET_ITEM(sequence, 2); + __pyx_t_1 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + #else + { + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_7,&__pyx_t_8,&__pyx_t_4,&__pyx_t_1}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 700, __pyx_L72_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + } else { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_7,&__pyx_t_8,&__pyx_t_4,&__pyx_t_1}; + __pyx_t_6 = PyObject_GetIter(__pyx_v_result); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 700, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 = Py_TYPE(__pyx_t_6)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_11(__pyx_t_6); if (unlikely(!item)) goto __pyx_L90_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_6), 4) < 0) __PYX_ERR(0, 700, __pyx_L72_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L91_unpacking_done; + __pyx_L90_unpacking_failed:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 700, __pyx_L72_error) + __pyx_L91_unpacking_done:; + } + __Pyx_DECREF_SET(__pyx_v_flag, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_DECREF_SET(__pyx_v_breakpoint, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_v_new_frame = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_bp_type, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":698 + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + * if result: # <<<<<<<<<<<<<< + * exist_result = True + * flag, breakpoint, new_frame, bp_type = result + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":696 + * if step_cmd in (108, 159) and (stop_frame is frame and is_line): + * stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + * elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: # <<<<<<<<<<<<<< + * result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + * if result: + */ + } + __pyx_L78:; + + /* "_pydevd_bundle/pydevd_cython.pyx":702 + * flag, breakpoint, new_frame, bp_type = result + * + * if breakpoint: # <<<<<<<<<<<<<< + * # ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint + * # lets do the conditional stuff here + */ + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_breakpoint); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 702, __pyx_L72_error) + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":705 + * # ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint + * # lets do the conditional stuff here + * if stop or exist_result: # <<<<<<<<<<<<<< + * eval_result = False + * if breakpoint.has_condition: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_stop); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 705, __pyx_L72_error) + if (!__pyx_t_9) { + } else { + __pyx_t_10 = __pyx_t_9; + goto __pyx_L94_bool_binop_done; + } + __pyx_t_9 = (__pyx_v_exist_result != 0); + __pyx_t_10 = __pyx_t_9; + __pyx_L94_bool_binop_done:; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":706 + * # lets do the conditional stuff here + * if stop or exist_result: + * eval_result = False # <<<<<<<<<<<<<< + * if breakpoint.has_condition: + * eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + */ + __Pyx_INCREF(Py_False); + __pyx_v_eval_result = Py_False; + + /* "_pydevd_bundle/pydevd_cython.pyx":707 + * if stop or exist_result: + * eval_result = False + * if breakpoint.has_condition: # <<<<<<<<<<<<<< + * eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_has_condition); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 707, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":708 + * eval_result = False + * if breakpoint.has_condition: + * eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) # <<<<<<<<<<<<<< + * + * if breakpoint.expression is not None: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_handle_breakpoint_condition); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 708, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(!__pyx_v_new_frame)) { __Pyx_RaiseUnboundLocalError("new_frame"); __PYX_ERR(0, 708, __pyx_L72_error) } + __pyx_t_8 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, ((PyObject *)__pyx_v_info), __pyx_v_breakpoint, __pyx_v_new_frame}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_8, ((PyObject *)__pyx_v_info), __pyx_v_breakpoint, __pyx_v_new_frame}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 708, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_info)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_info)); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_5, ((PyObject *)__pyx_v_info)); + __Pyx_INCREF(__pyx_v_breakpoint); + __Pyx_GIVEREF(__pyx_v_breakpoint); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_5, __pyx_v_breakpoint); + __Pyx_INCREF(__pyx_v_new_frame); + __Pyx_GIVEREF(__pyx_v_new_frame); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_5, __pyx_v_new_frame); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_eval_result, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":707 + * if stop or exist_result: + * eval_result = False + * if breakpoint.has_condition: # <<<<<<<<<<<<<< + * eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":710 + * eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + * + * if breakpoint.expression is not None: # <<<<<<<<<<<<<< + * main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_expression); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 710, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = (__pyx_t_1 != Py_None); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_9 = (__pyx_t_10 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":711 + * + * if breakpoint.expression is not None: + * main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) # <<<<<<<<<<<<<< + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + * cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_handle_breakpoint_expression); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 711, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + if (unlikely(!__pyx_v_new_frame)) { __Pyx_RaiseUnboundLocalError("new_frame"); __PYX_ERR(0, 711, __pyx_L72_error) } + __pyx_t_7 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_breakpoint, ((PyObject *)__pyx_v_info), __pyx_v_new_frame}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_breakpoint, ((PyObject *)__pyx_v_info), __pyx_v_new_frame}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_8 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_breakpoint); + __Pyx_GIVEREF(__pyx_v_breakpoint); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_5, __pyx_v_breakpoint); + __Pyx_INCREF(((PyObject *)__pyx_v_info)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_info)); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_5, ((PyObject *)__pyx_v_info)); + __Pyx_INCREF(__pyx_v_new_frame); + __Pyx_GIVEREF(__pyx_v_new_frame); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_5, __pyx_v_new_frame); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 711, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":712 + * if breakpoint.expression is not None: + * main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: # <<<<<<<<<<<<<< + * cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') + * main_debugger.writer.add_command(cmd) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_is_logpoint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 712, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 712, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L99_bool_binop_done; + } + __pyx_t_10 = (__pyx_v_info->pydev_message != ((PyObject*)Py_None)); + __pyx_t_12 = (__pyx_t_10 != 0); + if (__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L99_bool_binop_done; + } + __pyx_t_1 = __pyx_v_info->pydev_message; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_14 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 712, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = ((__pyx_t_14 > 0) != 0); + __pyx_t_9 = __pyx_t_12; + __pyx_L99_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":713 + * main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + * cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') # <<<<<<<<<<<<<< + * main_debugger.writer.add_command(cmd) + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_cmd_factory); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_make_io_message); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_linesep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_v_info->pydev_message, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_4, __pyx_kp_s_1}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_4, __pyx_kp_s_1}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_t_4); + __Pyx_INCREF(__pyx_kp_s_1); + __Pyx_GIVEREF(__pyx_kp_s_1); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_kp_s_1); + __pyx_t_4 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 713, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_cmd = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":714 + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + * cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') + * main_debugger.writer.add_command(cmd) # <<<<<<<<<<<<<< + * + * if breakpoint.has_condition: + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_writer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_add_command); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 714, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_v_cmd) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_cmd); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 714, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":712 + * if breakpoint.expression is not None: + * main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: # <<<<<<<<<<<<<< + * cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') + * main_debugger.writer.add_command(cmd) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":710 + * eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + * + * if breakpoint.expression is not None: # <<<<<<<<<<<<<< + * main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + * if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":716 + * main_debugger.writer.add_command(cmd) + * + * if breakpoint.has_condition: # <<<<<<<<<<<<<< + * if not eval_result: + * return self.trace_dispatch + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_has_condition); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 716, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 716, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":717 + * + * if breakpoint.has_condition: + * if not eval_result: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * elif breakpoint.is_logpoint: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_eval_result); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 717, __pyx_L72_error) + __pyx_t_12 = ((!__pyx_t_9) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":718 + * if breakpoint.has_condition: + * if not eval_result: + * return self.trace_dispatch # <<<<<<<<<<<<<< + * elif breakpoint.is_logpoint: + * return self.trace_dispatch + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 718, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L76_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":717 + * + * if breakpoint.has_condition: + * if not eval_result: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * elif breakpoint.is_logpoint: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":716 + * main_debugger.writer.add_command(cmd) + * + * if breakpoint.has_condition: # <<<<<<<<<<<<<< + * if not eval_result: + * return self.trace_dispatch + */ + goto __pyx_L102; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":719 + * if not eval_result: + * return self.trace_dispatch + * elif breakpoint.is_logpoint: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_is_logpoint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 719, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 719, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":720 + * return self.trace_dispatch + * elif breakpoint.is_logpoint: + * return self.trace_dispatch # <<<<<<<<<<<<<< + * + * if is_call and frame.f_code.co_name in ('', ''): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 720, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L76_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":719 + * if not eval_result: + * return self.trace_dispatch + * elif breakpoint.is_logpoint: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * + */ + } + __pyx_L102:; + + /* "_pydevd_bundle/pydevd_cython.pyx":705 + * # ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint + * # lets do the conditional stuff here + * if stop or exist_result: # <<<<<<<<<<<<<< + * eval_result = False + * if breakpoint.has_condition: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":722 + * return self.trace_dispatch + * + * if is_call and frame.f_code.co_name in ('', ''): # <<<<<<<<<<<<<< + * # If we find a call for a module, it means that the module is being imported/executed for the + * # first time. In this case we have to ignore this hit as it may later duplicated by a + */ + __pyx_t_9 = (__pyx_v_is_call != 0); + if (__pyx_t_9) { + } else { + __pyx_t_12 = __pyx_t_9; + goto __pyx_L105_bool_binop_done; + } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 722, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 722, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_kp_s_module, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 722, __pyx_L72_error) + if (!__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L107_bool_binop_done; + } + __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_kp_s_lambda, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 722, __pyx_L72_error) + __pyx_t_9 = __pyx_t_10; + __pyx_L107_bool_binop_done:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_10 = (__pyx_t_9 != 0); + __pyx_t_12 = __pyx_t_10; + __pyx_L105_bool_binop_done:; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":731 + * # its call and later its line event as they're usually in the same line. + * + * return self.trace_dispatch # <<<<<<<<<<<<<< + * + * if main_debugger.show_return_values: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 731, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L76_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":722 + * return self.trace_dispatch + * + * if is_call and frame.f_code.co_name in ('', ''): # <<<<<<<<<<<<<< + * # If we find a call for a module, it means that the module is being imported/executed for the + * # first time. In this case we have to ignore this hit as it may later duplicated by a + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":702 + * flag, breakpoint, new_frame, bp_type = result + * + * if breakpoint: # <<<<<<<<<<<<<< + * # ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint + * # lets do the conditional stuff here + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":733 + * return self.trace_dispatch + * + * if main_debugger.show_return_values: # <<<<<<<<<<<<<< + * if is_return and info.pydev_step_cmd in (108, 159) and frame.f_back == info.pydev_step_stop: + * self.show_return_values(frame, arg) + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_show_return_values); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 733, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 733, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":734 + * + * if main_debugger.show_return_values: + * if is_return and info.pydev_step_cmd in (108, 159) and frame.f_back == info.pydev_step_stop: # <<<<<<<<<<<<<< + * self.show_return_values(frame, arg) + * + */ + __pyx_t_10 = (__pyx_v_is_return != 0); + if (__pyx_t_10) { + } else { + __pyx_t_12 = __pyx_t_10; + goto __pyx_L111_bool_binop_done; + } + switch (__pyx_v_info->pydev_step_cmd) { + case 0x6C: + case 0x9F: + __pyx_t_10 = 1; + break; + default: + __pyx_t_10 = 0; + break; + } + __pyx_t_9 = (__pyx_t_10 != 0); + if (__pyx_t_9) { + } else { + __pyx_t_12 = __pyx_t_9; + goto __pyx_L111_bool_binop_done; + } + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 734, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_6, __pyx_v_info->pydev_step_stop, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 734, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = __pyx_t_9; + __pyx_L111_bool_binop_done:; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":735 + * if main_debugger.show_return_values: + * if is_return and info.pydev_step_cmd in (108, 159) and frame.f_back == info.pydev_step_stop: + * self.show_return_values(frame, arg) # <<<<<<<<<<<<<< + * + * elif main_debugger.remove_return_values_flag: + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_show_return_values); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 735, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_frame, __pyx_v_arg}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_frame, __pyx_v_arg}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 735, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_v_arg); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 735, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":734 + * + * if main_debugger.show_return_values: + * if is_return and info.pydev_step_cmd in (108, 159) and frame.f_back == info.pydev_step_stop: # <<<<<<<<<<<<<< + * self.show_return_values(frame, arg) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":733 + * return self.trace_dispatch + * + * if main_debugger.show_return_values: # <<<<<<<<<<<<<< + * if is_return and info.pydev_step_cmd in (108, 159) and frame.f_back == info.pydev_step_stop: + * self.show_return_values(frame, arg) + */ + goto __pyx_L109; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":737 + * self.show_return_values(frame, arg) + * + * elif main_debugger.remove_return_values_flag: # <<<<<<<<<<<<<< + * try: + * self.remove_return_values(main_debugger, frame) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_remove_return_values_flag); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 737, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 737, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":738 + * + * elif main_debugger.remove_return_values_flag: + * try: # <<<<<<<<<<<<<< + * self.remove_return_values(main_debugger, frame) + * finally: + */ + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":739 + * elif main_debugger.remove_return_values_flag: + * try: + * self.remove_return_values(main_debugger, frame) # <<<<<<<<<<<<<< + * finally: + * main_debugger.remove_return_values_flag = False + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_remove_return_values); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 739, __pyx_L115_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_5 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_main_debugger, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 739, __pyx_L115_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_main_debugger, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 739, __pyx_L115_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 739, __pyx_L115_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_5, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_5, __pyx_v_frame); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 739, __pyx_L115_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":741 + * self.remove_return_values(main_debugger, frame) + * finally: + * main_debugger.remove_return_values_flag = False # <<<<<<<<<<<<<< + * + * if stop: + */ + /*finally:*/ { + /*normal exit:*/{ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_main_debugger, __pyx_n_s_remove_return_values_flag, Py_False) < 0) __PYX_ERR(0, 741, __pyx_L72_error) + goto __pyx_L116; + } + __pyx_L115_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_24, &__pyx_t_25, &__pyx_t_26); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23) < 0)) __Pyx_ErrFetch(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23); + __Pyx_XGOTREF(__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_22); + __Pyx_XGOTREF(__pyx_t_23); + __Pyx_XGOTREF(__pyx_t_24); + __Pyx_XGOTREF(__pyx_t_25); + __Pyx_XGOTREF(__pyx_t_26); + __pyx_t_5 = __pyx_lineno; __pyx_t_19 = __pyx_clineno; __pyx_t_20 = __pyx_filename; + { + if (__Pyx_PyObject_SetAttrStr(__pyx_v_main_debugger, __pyx_n_s_remove_return_values_flag, Py_False) < 0) __PYX_ERR(0, 741, __pyx_L118_error) + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_XGIVEREF(__pyx_t_25); + __Pyx_XGIVEREF(__pyx_t_26); + __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_25, __pyx_t_26); + } + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_XGIVEREF(__pyx_t_23); + __Pyx_ErrRestore(__pyx_t_21, __pyx_t_22, __pyx_t_23); + __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; + __pyx_lineno = __pyx_t_5; __pyx_clineno = __pyx_t_19; __pyx_filename = __pyx_t_20; + goto __pyx_L72_error; + __pyx_L118_error:; + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_XGIVEREF(__pyx_t_25); + __Pyx_XGIVEREF(__pyx_t_26); + __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_25, __pyx_t_26); + } + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; + goto __pyx_L72_error; + } + __pyx_L116:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":737 + * self.show_return_values(frame, arg) + * + * elif main_debugger.remove_return_values_flag: # <<<<<<<<<<<<<< + * try: + * self.remove_return_values(main_debugger, frame) + */ + } + __pyx_L109:; + + /* "_pydevd_bundle/pydevd_cython.pyx":743 + * main_debugger.remove_return_values_flag = False + * + * if stop: # <<<<<<<<<<<<<< + * self.set_suspend( + * thread, + */ + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_stop); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 743, __pyx_L72_error) + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":744 + * + * if stop: + * self.set_suspend( # <<<<<<<<<<<<<< + * thread, + * 111, + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_suspend); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 744, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + + /* "_pydevd_bundle/pydevd_cython.pyx":745 + * if stop: + * self.set_suspend( + * thread, # <<<<<<<<<<<<<< + * 111, + * suspend_other_threads=breakpoint and breakpoint.suspend_policy == "ALL", + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 744, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_thread); + __Pyx_INCREF(__pyx_int_111); + __Pyx_GIVEREF(__pyx_int_111); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_111); + + /* "_pydevd_bundle/pydevd_cython.pyx":747 + * thread, + * 111, + * suspend_other_threads=breakpoint and breakpoint.suspend_policy == "ALL", # <<<<<<<<<<<<<< + * ) + * + */ + __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 747, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_breakpoint); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 747, __pyx_L72_error) + if (__pyx_t_12) { + } else { + __Pyx_INCREF(__pyx_v_breakpoint); + __pyx_t_4 = __pyx_v_breakpoint; + goto __pyx_L120_bool_binop_done; + } + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_breakpoint, __pyx_n_s_suspend_policy); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 747, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_n_s_ALL, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 747, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = __pyx_t_3; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_L120_bool_binop_done:; + if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_suspend_other_threads, __pyx_t_4) < 0) __PYX_ERR(0, 747, __pyx_L72_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":744 + * + * if stop: + * self.set_suspend( # <<<<<<<<<<<<<< + * thread, + * 111, + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 744, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":743 + * main_debugger.remove_return_values_flag = False + * + * if stop: # <<<<<<<<<<<<<< + * self.set_suspend( + * thread, + */ + goto __pyx_L119; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":750 + * ) + * + * elif flag and plugin_manager is not None: # <<<<<<<<<<<<<< + * result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + * if result: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_flag); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 750, __pyx_L72_error) + if (__pyx_t_9) { + } else { + __pyx_t_12 = __pyx_t_9; + goto __pyx_L122_bool_binop_done; + } + __pyx_t_9 = (__pyx_v_plugin_manager != Py_None); + __pyx_t_10 = (__pyx_t_9 != 0); + __pyx_t_12 = __pyx_t_10; + __pyx_L122_bool_binop_done:; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":751 + * + * elif flag and plugin_manager is not None: + * result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) # <<<<<<<<<<<<<< + * if result: + * frame = result + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_plugin_manager, __pyx_n_s_suspend); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 751, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_v_main_debugger, __pyx_v_thread, __pyx_v_frame, __pyx_v_bp_type}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_v_main_debugger, __pyx_v_thread, __pyx_v_frame, __pyx_v_bp_type}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_1 = PyTuple_New(4+__pyx_t_19); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 751, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_19, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_19, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_bp_type); + __Pyx_GIVEREF(__pyx_v_bp_type); + PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_19, __pyx_v_bp_type); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF_SET(__pyx_v_result, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":752 + * elif flag and plugin_manager is not None: + * result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + * if result: # <<<<<<<<<<<<<< + * frame = result + * + */ + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 752, __pyx_L72_error) + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":753 + * result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + * if result: + * frame = result # <<<<<<<<<<<<<< + * + * # if thread has a suspend flag, we suspend with a busy wait + */ + __Pyx_INCREF(__pyx_v_result); + __Pyx_DECREF_SET(__pyx_v_frame, __pyx_v_result); + + /* "_pydevd_bundle/pydevd_cython.pyx":752 + * elif flag and plugin_manager is not None: + * result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + * if result: # <<<<<<<<<<<<<< + * frame = result + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":750 + * ) + * + * elif flag and plugin_manager is not None: # <<<<<<<<<<<<<< + * result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + * if result: + */ + } + __pyx_L119:; + + /* "_pydevd_bundle/pydevd_cython.pyx":756 + * + * # if thread has a suspend flag, we suspend with a busy wait + * if info.pydev_state == 2: # <<<<<<<<<<<<<< + * self.do_wait_suspend(thread, frame, event, arg) + * return self.trace_dispatch + */ + __pyx_t_12 = ((__pyx_v_info->pydev_state == 2) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":757 + * # if thread has a suspend flag, we suspend with a busy wait + * if info.pydev_state == 2: + * self.do_wait_suspend(thread, frame, event, arg) # <<<<<<<<<<<<<< + * return self.trace_dispatch + * else: + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_do_wait_suspend); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 757, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_v_thread, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 757, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_v_thread, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 757, __pyx_L72_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_6 = PyTuple_New(4+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 757, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_19, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_19, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_19, __pyx_v_arg); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 757, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":758 + * if info.pydev_state == 2: + * self.do_wait_suspend(thread, frame, event, arg) + * return self.trace_dispatch # <<<<<<<<<<<<<< + * else: + * if not breakpoint and is_line: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 758, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L76_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":756 + * + * # if thread has a suspend flag, we suspend with a busy wait + * if info.pydev_state == 2: # <<<<<<<<<<<<<< + * self.do_wait_suspend(thread, frame, event, arg) + * return self.trace_dispatch + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":760 + * return self.trace_dispatch + * else: + * if not breakpoint and is_line: # <<<<<<<<<<<<<< + * # No stop from anyone and no breakpoint found in line (cache that). + * frame_skips_cache[line_cache_key] = 0 + */ + /*else*/ { + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_breakpoint); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 760, __pyx_L72_error) + __pyx_t_9 = ((!__pyx_t_10) != 0); + if (__pyx_t_9) { + } else { + __pyx_t_12 = __pyx_t_9; + goto __pyx_L127_bool_binop_done; + } + __pyx_t_9 = (__pyx_v_is_line != 0); + __pyx_t_12 = __pyx_t_9; + __pyx_L127_bool_binop_done:; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":762 + * if not breakpoint and is_line: + * # No stop from anyone and no breakpoint found in line (cache that). + * frame_skips_cache[line_cache_key] = 0 # <<<<<<<<<<<<<< + * + * except: + */ + if (unlikely(__pyx_v_frame_skips_cache == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 762, __pyx_L72_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_frame_skips_cache, __pyx_v_line_cache_key, __pyx_int_0) < 0)) __PYX_ERR(0, 762, __pyx_L72_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":760 + * return self.trace_dispatch + * else: + * if not breakpoint and is_line: # <<<<<<<<<<<<<< + * # No stop from anyone and no breakpoint found in line (cache that). + * frame_skips_cache[line_cache_key] = 0 + */ + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":680 + * # if DEBUG: print('NOT skipped: %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, event, frame.__class__.__name__)) + * + * try: # <<<<<<<<<<<<<< + * flag = False + * # return is not taken into account for breakpoint hit because we'd have a double-hit in this case + */ + } + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + goto __pyx_L77_try_end; + __pyx_L72_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":764 + * frame_skips_cache[line_cache_key] = 0 + * + * except: # <<<<<<<<<<<<<< + * pydev_log.exception() + * raise + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(0, 764, __pyx_L74_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_6); + + /* "_pydevd_bundle/pydevd_cython.pyx":765 + * + * except: + * pydev_log.exception() # <<<<<<<<<<<<<< + * raise + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L74_except_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_exception); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 765, __pyx_L74_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L74_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":766 + * except: + * pydev_log.exception() + * raise # <<<<<<<<<<<<<< + * + * # step handling. We stop when we hit the right frame + */ + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_8, __pyx_t_6); + __pyx_t_4 = 0; __pyx_t_8 = 0; __pyx_t_6 = 0; + __PYX_ERR(0, 766, __pyx_L74_except_error) + } + __pyx_L74_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":680 + * # if DEBUG: print('NOT skipped: %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, event, frame.__class__.__name__)) + * + * try: # <<<<<<<<<<<<<< + * flag = False + * # return is not taken into account for breakpoint hit because we'd have a double-hit in this case + */ + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18); + goto __pyx_L4_error; + __pyx_L76_try_return:; + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18); + goto __pyx_L3_return; + __pyx_L77_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":769 + * + * # step handling. We stop when we hit the right frame + * try: # <<<<<<<<<<<<<< + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_16); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":770 + * # step handling. We stop when we hit the right frame + * try: + * should_skip = 0 # <<<<<<<<<<<<<< + * if pydevd_dont_trace.should_trace_hook is not None: + * if self.should_skip == -1: + */ + __pyx_v_should_skip = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":771 + * try: + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: # <<<<<<<<<<<<<< + * if self.should_skip == -1: + * # I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times). + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pydevd_dont_trace); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 771, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_should_trace_hook); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 771, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = (__pyx_t_8 != Py_None); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":772 + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: + * if self.should_skip == -1: # <<<<<<<<<<<<<< + * # I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times). + * # Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code + */ + __pyx_t_9 = ((__pyx_v_self->should_skip == -1L) != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":776 + * # Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code + * # Which will be handled by this frame is read-only, so, we can cache it safely. + * if not pydevd_dont_trace.should_trace_hook(frame, filename): # <<<<<<<<<<<<<< + * # -1, 0, 1 to be Cython-friendly + * should_skip = self.should_skip = 1 + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pydevd_dont_trace); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_should_trace_hook); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_frame, __pyx_v_filename}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_frame, __pyx_v_filename}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_8); + } else + #endif + { + __pyx_t_1 = PyTuple_New(2+__pyx_t_19); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_1); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_19, __pyx_v_filename); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 776, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = ((!__pyx_t_9) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":778 + * if not pydevd_dont_trace.should_trace_hook(frame, filename): + * # -1, 0, 1 to be Cython-friendly + * should_skip = self.should_skip = 1 # <<<<<<<<<<<<<< + * else: + * should_skip = self.should_skip = 0 + */ + __pyx_v_should_skip = 1; + __pyx_v_self->should_skip = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":776 + * # Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code + * # Which will be handled by this frame is read-only, so, we can cache it safely. + * if not pydevd_dont_trace.should_trace_hook(frame, filename): # <<<<<<<<<<<<<< + * # -1, 0, 1 to be Cython-friendly + * should_skip = self.should_skip = 1 + */ + goto __pyx_L139; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":780 + * should_skip = self.should_skip = 1 + * else: + * should_skip = self.should_skip = 0 # <<<<<<<<<<<<<< + * else: + * should_skip = self.should_skip + */ + /*else*/ { + __pyx_v_should_skip = 0; + __pyx_v_self->should_skip = 0; + } + __pyx_L139:; + + /* "_pydevd_bundle/pydevd_cython.pyx":772 + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: + * if self.should_skip == -1: # <<<<<<<<<<<<<< + * # I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times). + * # Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code + */ + goto __pyx_L138; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":782 + * should_skip = self.should_skip = 0 + * else: + * should_skip = self.should_skip # <<<<<<<<<<<<<< + * + * plugin_stop = False + */ + /*else*/ { + __pyx_t_19 = __pyx_v_self->should_skip; + __pyx_v_should_skip = __pyx_t_19; + } + __pyx_L138:; + + /* "_pydevd_bundle/pydevd_cython.pyx":771 + * try: + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: # <<<<<<<<<<<<<< + * if self.should_skip == -1: + * # I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times). + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":784 + * should_skip = self.should_skip + * + * plugin_stop = False # <<<<<<<<<<<<<< + * if should_skip: + * stop = False + */ + __Pyx_INCREF(Py_False); + __pyx_v_plugin_stop = Py_False; + + /* "_pydevd_bundle/pydevd_cython.pyx":785 + * + * plugin_stop = False + * if should_skip: # <<<<<<<<<<<<<< + * stop = False + * + */ + __pyx_t_12 = (__pyx_v_should_skip != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":786 + * plugin_stop = False + * if should_skip: + * stop = False # <<<<<<<<<<<<<< + * + * elif step_cmd in (107, 144): + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":785 + * + * plugin_stop = False + * if should_skip: # <<<<<<<<<<<<<< + * stop = False + * + */ + goto __pyx_L140; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":788 + * stop = False + * + * elif step_cmd in (107, 144): # <<<<<<<<<<<<<< + * force_check_project_scope = step_cmd == 144 + * if is_line: + */ + switch (__pyx_v_step_cmd) { + case 0x6B: + case 0x90: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":789 + * + * elif step_cmd in (107, 144): + * force_check_project_scope = step_cmd == 144 # <<<<<<<<<<<<<< + * if is_line: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: + */ + __pyx_t_8 = __Pyx_PyBool_FromLong((__pyx_v_step_cmd == 0x90)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 789, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_force_check_project_scope = __pyx_t_8; + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":790 + * elif step_cmd in (107, 144): + * force_check_project_scope = step_cmd == 144 + * if is_line: # <<<<<<<<<<<<<< + * if force_check_project_scope or main_debugger.is_files_filter_enabled: + * stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + */ + __pyx_t_9 = (__pyx_v_is_line != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":791 + * force_check_project_scope = step_cmd == 144 + * if is_line: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: # <<<<<<<<<<<<<< + * stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + * else: + */ + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_force_check_project_scope); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 791, __pyx_L131_error) + if (!__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L143_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_is_files_filter_enabled); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 791, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 791, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = __pyx_t_12; + __pyx_L143_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":792 + * if is_line: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: + * stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) # <<<<<<<<<<<<<< + * else: + * stop = True + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_apply_files_filter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_frame, __pyx_t_6, __pyx_v_force_check_project_scope}; + __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_frame, __pyx_t_6, __pyx_v_force_check_project_scope}; + __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_19, __pyx_v_frame); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_19, __pyx_t_6); + __Pyx_INCREF(__pyx_v_force_check_project_scope); + __Pyx_GIVEREF(__pyx_v_force_check_project_scope); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_19, __pyx_v_force_check_project_scope); + __pyx_t_6 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyBool_FromLong((!__pyx_t_9)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 792, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":791 + * force_check_project_scope = step_cmd == 144 + * if is_line: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: # <<<<<<<<<<<<<< + * stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + * else: + */ + goto __pyx_L142; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":794 + * stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + * else: + * stop = True # <<<<<<<<<<<<<< + * + * elif is_return and frame.f_back is not None: + */ + /*else*/ { + __Pyx_INCREF(Py_True); + __Pyx_DECREF_SET(__pyx_v_stop, Py_True); + } + __pyx_L142:; + + /* "_pydevd_bundle/pydevd_cython.pyx":790 + * elif step_cmd in (107, 144): + * force_check_project_scope = step_cmd == 144 + * if is_line: # <<<<<<<<<<<<<< + * if force_check_project_scope or main_debugger.is_files_filter_enabled: + * stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + */ + goto __pyx_L141; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":796 + * stop = True + * + * elif is_return and frame.f_back is not None: # <<<<<<<<<<<<<< + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + * stop = False + */ + __pyx_t_12 = (__pyx_v_is_return != 0); + if (__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L145_bool_binop_done; + } + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 796, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_12 = (__pyx_t_8 != Py_None); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_10 = (__pyx_t_12 != 0); + __pyx_t_9 = __pyx_t_10; + __pyx_L145_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":797 + * + * elif is_return and frame.f_back is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: # <<<<<<<<<<<<<< + * stop = False + * else: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_get_file_type); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 797, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 797, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_8 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 797, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_PYDEV_FILE); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 797, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 797, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 797, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":798 + * elif is_return and frame.f_back is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + * stop = False # <<<<<<<<<<<<<< + * else: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":797 + * + * elif is_return and frame.f_back is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: # <<<<<<<<<<<<<< + * stop = False + * else: + */ + goto __pyx_L147; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":800 + * stop = False + * else: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: # <<<<<<<<<<<<<< + * stop = not main_debugger.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, force_check_project_scope) + * else: + */ + /*else*/ { + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_force_check_project_scope); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 800, __pyx_L131_error) + if (!__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L149_bool_binop_done; + } + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_is_files_filter_enabled); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 800, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 800, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __pyx_t_10; + __pyx_L149_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":801 + * else: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: + * stop = not main_debugger.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, force_check_project_scope) # <<<<<<<<<<<<<< + * else: + * stop = True + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_apply_files_filter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_t_8, __pyx_t_6, __pyx_v_force_check_project_scope}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_t_8, __pyx_t_6, __pyx_v_force_check_project_scope}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_19, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_19, __pyx_t_6); + __Pyx_INCREF(__pyx_v_force_check_project_scope); + __Pyx_GIVEREF(__pyx_v_force_check_project_scope); + PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_19, __pyx_v_force_check_project_scope); + __pyx_t_8 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyBool_FromLong((!__pyx_t_9)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 801, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":800 + * stop = False + * else: + * if force_check_project_scope or main_debugger.is_files_filter_enabled: # <<<<<<<<<<<<<< + * stop = not main_debugger.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, force_check_project_scope) + * else: + */ + goto __pyx_L148; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":803 + * stop = not main_debugger.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, force_check_project_scope) + * else: + * stop = True # <<<<<<<<<<<<<< + * + * if plugin_manager is not None: + */ + /*else*/ { + __Pyx_INCREF(Py_True); + __Pyx_DECREF_SET(__pyx_v_stop, Py_True); + } + __pyx_L148:; + } + __pyx_L147:; + + /* "_pydevd_bundle/pydevd_cython.pyx":796 + * stop = True + * + * elif is_return and frame.f_back is not None: # <<<<<<<<<<<<<< + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + * stop = False + */ + } + __pyx_L141:; + + /* "_pydevd_bundle/pydevd_cython.pyx":805 + * stop = True + * + * if plugin_manager is not None: # <<<<<<<<<<<<<< + * result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + * if result: + */ + __pyx_t_9 = (__pyx_v_plugin_manager != Py_None); + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":806 + * + * if plugin_manager is not None: + * result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) # <<<<<<<<<<<<<< + * if result: + * stop, plugin_stop = result + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_plugin_manager, __pyx_n_s_cmd_step_into); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 806, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[7] = {__pyx_t_3, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args, __pyx_v_stop_info, __pyx_v_stop}; + __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 6+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[7] = {__pyx_t_3, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args, __pyx_v_stop_info, __pyx_v_stop}; + __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 6+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_7); + } else + #endif + { + __pyx_t_6 = PyTuple_New(6+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 806, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_19, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_19, __pyx_v_event); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_19, __pyx_v_self->_args); + __Pyx_INCREF(__pyx_v_stop_info); + __Pyx_GIVEREF(__pyx_v_stop_info); + PyTuple_SET_ITEM(__pyx_t_6, 4+__pyx_t_19, __pyx_v_stop_info); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_6, 5+__pyx_t_19, __pyx_v_stop); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 806, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_result, __pyx_t_7); + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":807 + * if plugin_manager is not None: + * result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + * if result: # <<<<<<<<<<<<<< + * stop, plugin_stop = result + * + */ + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 807, __pyx_L131_error) + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":808 + * result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + * if result: + * stop, plugin_stop = result # <<<<<<<<<<<<<< + * + * elif step_cmd in (108, 159): + */ + if ((likely(PyTuple_CheckExact(__pyx_v_result))) || (PyList_CheckExact(__pyx_v_result))) { + PyObject* sequence = __pyx_v_result; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 808, __pyx_L131_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 808, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 808, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + Py_ssize_t index = -1; + __pyx_t_6 = PyObject_GetIter(__pyx_v_result); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 808, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 = Py_TYPE(__pyx_t_6)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_11(__pyx_t_6); if (unlikely(!__pyx_t_7)) goto __pyx_L153_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L153_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_6), 2) < 0) __PYX_ERR(0, 808, __pyx_L131_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L154_unpacking_done; + __pyx_L153_unpacking_failed:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 808, __pyx_L131_error) + __pyx_L154_unpacking_done:; + } + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_DECREF_SET(__pyx_v_plugin_stop, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":807 + * if plugin_manager is not None: + * result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + * if result: # <<<<<<<<<<<<<< + * stop, plugin_stop = result + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":805 + * stop = True + * + * if plugin_manager is not None: # <<<<<<<<<<<<<< + * result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + * if result: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":788 + * stop = False + * + * elif step_cmd in (107, 144): # <<<<<<<<<<<<<< + * force_check_project_scope = step_cmd == 144 + * if is_line: + */ + goto __pyx_L140; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":810 + * stop, plugin_stop = result + * + * elif step_cmd in (108, 159): # <<<<<<<<<<<<<< + * # Note: when dealing with a step over my code it's the same as a step over (the + * # difference is that when we return from a frame in one we go to regular step + */ + switch (__pyx_v_step_cmd) { + case 0x6C: + case 0x9F: + __pyx_t_10 = 1; + break; + default: + __pyx_t_10 = 0; + break; + } + __pyx_t_9 = (__pyx_t_10 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":814 + * # difference is that when we return from a frame in one we go to regular step + * # into and in the other we go to a step into my code). + * stop = stop_frame is frame and is_line # <<<<<<<<<<<<<< + * # Note: don't stop on a return for step over, only for line events + * # i.e.: don't stop in: (stop_frame is frame.f_back and is_return) as we'd stop twice in that line. + */ + __pyx_t_9 = (__pyx_v_stop_frame == __pyx_v_frame); + if (__pyx_t_9) { + } else { + __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 814, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L155_bool_binop_done; + } + __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_is_line); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 814, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_L155_bool_binop_done:; + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":818 + * # i.e.: don't stop in: (stop_frame is frame.f_back and is_return) as we'd stop twice in that line. + * + * if frame.f_code.co_flags & CO_GENERATOR: # <<<<<<<<<<<<<< + * if is_return: + * stop = False + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 818, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_flags); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 818, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_CO_GENERATOR); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 818, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyNumber_And(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 818, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 818, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":819 + * + * if frame.f_code.co_flags & CO_GENERATOR: + * if is_return: # <<<<<<<<<<<<<< + * stop = False + * + */ + __pyx_t_9 = (__pyx_v_is_return != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":820 + * if frame.f_code.co_flags & CO_GENERATOR: + * if is_return: + * stop = False # <<<<<<<<<<<<<< + * + * if plugin_manager is not None: + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":819 + * + * if frame.f_code.co_flags & CO_GENERATOR: + * if is_return: # <<<<<<<<<<<<<< + * stop = False + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":818 + * # i.e.: don't stop in: (stop_frame is frame.f_back and is_return) as we'd stop twice in that line. + * + * if frame.f_code.co_flags & CO_GENERATOR: # <<<<<<<<<<<<<< + * if is_return: + * stop = False + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":822 + * stop = False + * + * if plugin_manager is not None: # <<<<<<<<<<<<<< + * result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + * if result: + */ + __pyx_t_9 = (__pyx_v_plugin_manager != Py_None); + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":823 + * + * if plugin_manager is not None: + * result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) # <<<<<<<<<<<<<< + * if result: + * stop, plugin_stop = result + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_plugin_manager, __pyx_n_s_cmd_step_over); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 823, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[7] = {__pyx_t_7, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args, __pyx_v_stop_info, __pyx_v_stop}; + __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 6+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 823, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[7] = {__pyx_t_7, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args, __pyx_v_stop_info, __pyx_v_stop}; + __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_19, 6+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 823, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_6); + } else + #endif + { + __pyx_t_3 = PyTuple_New(6+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_19, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_19, __pyx_v_event); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_19, __pyx_v_self->_args); + __Pyx_INCREF(__pyx_v_stop_info); + __Pyx_GIVEREF(__pyx_v_stop_info); + PyTuple_SET_ITEM(__pyx_t_3, 4+__pyx_t_19, __pyx_v_stop_info); + __Pyx_INCREF(__pyx_v_stop); + __Pyx_GIVEREF(__pyx_v_stop); + PyTuple_SET_ITEM(__pyx_t_3, 5+__pyx_t_19, __pyx_v_stop); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 823, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_result, __pyx_t_6); + __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":824 + * if plugin_manager is not None: + * result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + * if result: # <<<<<<<<<<<<<< + * stop, plugin_stop = result + * + */ + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 824, __pyx_L131_error) + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":825 + * result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + * if result: + * stop, plugin_stop = result # <<<<<<<<<<<<<< + * + * elif step_cmd == 128: + */ + if ((likely(PyTuple_CheckExact(__pyx_v_result))) || (PyList_CheckExact(__pyx_v_result))) { + PyObject* sequence = __pyx_v_result; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 825, __pyx_L131_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 825, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 825, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_v_result); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 825, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_6)) goto __pyx_L161_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L161_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 825, __pyx_L131_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L162_unpacking_done; + __pyx_L161_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 825, __pyx_L131_error) + __pyx_L162_unpacking_done:; + } + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_DECREF_SET(__pyx_v_plugin_stop, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":824 + * if plugin_manager is not None: + * result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + * if result: # <<<<<<<<<<<<<< + * stop, plugin_stop = result + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":822 + * stop = False + * + * if plugin_manager is not None: # <<<<<<<<<<<<<< + * result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + * if result: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":810 + * stop, plugin_stop = result + * + * elif step_cmd in (108, 159): # <<<<<<<<<<<<<< + * # Note: when dealing with a step over my code it's the same as a step over (the + * # difference is that when we return from a frame in one we go to regular step + */ + goto __pyx_L140; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":827 + * stop, plugin_stop = result + * + * elif step_cmd == 128: # <<<<<<<<<<<<<< + * stop = False + * if info.pydev_smart_step_stop is frame: + */ + __pyx_t_10 = ((__pyx_v_step_cmd == 0x80) != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":828 + * + * elif step_cmd == 128: + * stop = False # <<<<<<<<<<<<<< + * if info.pydev_smart_step_stop is frame: + * info.pydev_func_name = '.invalid.' # Must match the type in cython + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":829 + * elif step_cmd == 128: + * stop = False + * if info.pydev_smart_step_stop is frame: # <<<<<<<<<<<<<< + * info.pydev_func_name = '.invalid.' # Must match the type in cython + * info.pydev_smart_step_stop = None + */ + __pyx_t_10 = (__pyx_v_info->pydev_smart_step_stop == __pyx_v_frame); + __pyx_t_9 = (__pyx_t_10 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":830 + * stop = False + * if info.pydev_smart_step_stop is frame: + * info.pydev_func_name = '.invalid.' # Must match the type in cython # <<<<<<<<<<<<<< + * info.pydev_smart_step_stop = None + * + */ + __Pyx_INCREF(__pyx_kp_s_invalid); + __Pyx_GIVEREF(__pyx_kp_s_invalid); + __Pyx_GOTREF(__pyx_v_info->pydev_func_name); + __Pyx_DECREF(__pyx_v_info->pydev_func_name); + __pyx_v_info->pydev_func_name = __pyx_kp_s_invalid; + + /* "_pydevd_bundle/pydevd_cython.pyx":831 + * if info.pydev_smart_step_stop is frame: + * info.pydev_func_name = '.invalid.' # Must match the type in cython + * info.pydev_smart_step_stop = None # <<<<<<<<<<<<<< + * + * if is_line or is_exception_event: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_info->pydev_smart_step_stop); + __Pyx_DECREF(__pyx_v_info->pydev_smart_step_stop); + __pyx_v_info->pydev_smart_step_stop = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":829 + * elif step_cmd == 128: + * stop = False + * if info.pydev_smart_step_stop is frame: # <<<<<<<<<<<<<< + * info.pydev_func_name = '.invalid.' # Must match the type in cython + * info.pydev_smart_step_stop = None + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":833 + * info.pydev_smart_step_stop = None + * + * if is_line or is_exception_event: # <<<<<<<<<<<<<< + * curr_func_name = frame.f_code.co_name + * + */ + __pyx_t_10 = (__pyx_v_is_line != 0); + if (!__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L165_bool_binop_done; + } + __pyx_t_10 = (__pyx_v_is_exception_event != 0); + __pyx_t_9 = __pyx_t_10; + __pyx_L165_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":834 + * + * if is_line or is_exception_event: + * curr_func_name = frame.f_code.co_name # <<<<<<<<<<<<<< + * + * # global context is set with an empty name + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 834, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 834, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(PyString_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 834, __pyx_L131_error) + __Pyx_XDECREF_SET(__pyx_v_curr_func_name, ((PyObject*)__pyx_t_6)); + __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":837 + * + * # global context is set with an empty name + * if curr_func_name in ('?', '') or curr_func_name is None: # <<<<<<<<<<<<<< + * curr_func_name = '' + * + */ + __Pyx_INCREF(__pyx_v_curr_func_name); + __pyx_t_13 = __pyx_v_curr_func_name; + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_13, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 837, __pyx_L131_error) + __pyx_t_27 = (__pyx_t_12 != 0); + if (!__pyx_t_27) { + } else { + __pyx_t_10 = __pyx_t_27; + goto __pyx_L170_bool_binop_done; + } + __pyx_t_27 = (__Pyx_PyString_Equals(__pyx_t_13, __pyx_kp_s_module, Py_EQ)); if (unlikely(__pyx_t_27 < 0)) __PYX_ERR(0, 837, __pyx_L131_error) + __pyx_t_12 = (__pyx_t_27 != 0); + __pyx_t_10 = __pyx_t_12; + __pyx_L170_bool_binop_done:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_12 = (__pyx_t_10 != 0); + if (!__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L168_bool_binop_done; + } + __pyx_t_12 = (__pyx_v_curr_func_name == ((PyObject*)Py_None)); + __pyx_t_10 = (__pyx_t_12 != 0); + __pyx_t_9 = __pyx_t_10; + __pyx_L168_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":838 + * # global context is set with an empty name + * if curr_func_name in ('?', '') or curr_func_name is None: + * curr_func_name = '' # <<<<<<<<<<<<<< + * + * if curr_func_name == info.pydev_func_name: + */ + __Pyx_INCREF(__pyx_kp_s_); + __Pyx_DECREF_SET(__pyx_v_curr_func_name, __pyx_kp_s_); + + /* "_pydevd_bundle/pydevd_cython.pyx":837 + * + * # global context is set with an empty name + * if curr_func_name in ('?', '') or curr_func_name is None: # <<<<<<<<<<<<<< + * curr_func_name = '' + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":840 + * curr_func_name = '' + * + * if curr_func_name == info.pydev_func_name: # <<<<<<<<<<<<<< + * stop = True + * + */ + __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_curr_func_name, __pyx_v_info->pydev_func_name, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 840, __pyx_L131_error) + __pyx_t_10 = (__pyx_t_9 != 0); + if (__pyx_t_10) { + + /* "_pydevd_bundle/pydevd_cython.pyx":841 + * + * if curr_func_name == info.pydev_func_name: + * stop = True # <<<<<<<<<<<<<< + * + * elif step_cmd in (109, 160): + */ + __Pyx_INCREF(Py_True); + __Pyx_DECREF_SET(__pyx_v_stop, Py_True); + + /* "_pydevd_bundle/pydevd_cython.pyx":840 + * curr_func_name = '' + * + * if curr_func_name == info.pydev_func_name: # <<<<<<<<<<<<<< + * stop = True + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":833 + * info.pydev_smart_step_stop = None + * + * if is_line or is_exception_event: # <<<<<<<<<<<<<< + * curr_func_name = frame.f_code.co_name + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":827 + * stop, plugin_stop = result + * + * elif step_cmd == 128: # <<<<<<<<<<<<<< + * stop = False + * if info.pydev_smart_step_stop is frame: + */ + goto __pyx_L140; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":843 + * stop = True + * + * elif step_cmd in (109, 160): # <<<<<<<<<<<<<< + * stop = is_return and stop_frame is frame + * + */ + switch (__pyx_v_step_cmd) { + case 0x6D: + case 0xA0: + __pyx_t_10 = 1; + break; + default: + __pyx_t_10 = 0; + break; + } + __pyx_t_9 = (__pyx_t_10 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":844 + * + * elif step_cmd in (109, 160): + * stop = is_return and stop_frame is frame # <<<<<<<<<<<<<< + * + * else: + */ + if (__pyx_v_is_return) { + } else { + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_is_return); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 844, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L173_bool_binop_done; + } + __pyx_t_9 = (__pyx_v_stop_frame == __pyx_v_frame); + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 844, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_L173_bool_binop_done:; + __Pyx_DECREF_SET(__pyx_v_stop, __pyx_t_6); + __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":843 + * stop = True + * + * elif step_cmd in (109, 160): # <<<<<<<<<<<<<< + * stop = is_return and stop_frame is frame + * + */ + goto __pyx_L140; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":847 + * + * else: + * stop = False # <<<<<<<<<<<<<< + * + * if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): + */ + /*else*/ { + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + } + __pyx_L140:; + + /* "_pydevd_bundle/pydevd_cython.pyx":849 + * stop = False + * + * if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): # <<<<<<<<<<<<<< + * f_code = getattr(frame.f_back, 'f_code', None) + * if f_code is not None: + */ + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_stop); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 849, __pyx_L131_error) + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L176_bool_binop_done; + } + __pyx_t_10 = ((__pyx_v_step_cmd != -1L) != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L176_bool_binop_done; + } + __pyx_t_10 = (__pyx_v_is_return != 0); + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L176_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_IS_PY3K); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 849, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 849, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_10) { + } else { + __pyx_t_9 = __pyx_t_10; + goto __pyx_L176_bool_binop_done; + } + __pyx_t_10 = __Pyx_HasAttr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 849, __pyx_L131_error) + __pyx_t_12 = (__pyx_t_10 != 0); + __pyx_t_9 = __pyx_t_12; + __pyx_L176_bool_binop_done:; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":850 + * + * if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): + * f_code = getattr(frame.f_back, 'f_code', None) # <<<<<<<<<<<<<< + * if f_code is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 850, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_GetAttr3(__pyx_t_6, __pyx_n_s_f_code, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 850, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_f_code = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":851 + * if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): + * f_code = getattr(frame.f_back, 'f_code', None) + * if f_code is not None: # <<<<<<<<<<<<<< + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + * stop = False + */ + __pyx_t_9 = (__pyx_v_f_code != Py_None); + __pyx_t_12 = (__pyx_t_9 != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":852 + * f_code = getattr(frame.f_back, 'f_code', None) + * if f_code is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: # <<<<<<<<<<<<<< + * stop = False + * + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_get_file_type); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 852, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 852, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 852, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_PYDEV_FILE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 852, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 852, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 852, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":853 + * if f_code is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + * stop = False # <<<<<<<<<<<<<< + * + * if plugin_stop: + */ + __Pyx_INCREF(Py_False); + __Pyx_DECREF_SET(__pyx_v_stop, Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":852 + * f_code = getattr(frame.f_back, 'f_code', None) + * if f_code is not None: + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: # <<<<<<<<<<<<<< + * stop = False + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":851 + * if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): + * f_code = getattr(frame.f_back, 'f_code', None) + * if f_code is not None: # <<<<<<<<<<<<<< + * if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + * stop = False + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":849 + * stop = False + * + * if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): # <<<<<<<<<<<<<< + * f_code = getattr(frame.f_back, 'f_code', None) + * if f_code is not None: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":855 + * stop = False + * + * if plugin_stop: # <<<<<<<<<<<<<< + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + * elif stop: + */ + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_plugin_stop); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 855, __pyx_L131_error) + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":856 + * + * if plugin_stop: + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) # <<<<<<<<<<<<<< + * elif stop: + * if is_line: + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_plugin_manager, __pyx_n_s_stop); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 856, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_step_cmd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 856, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[8] = {__pyx_t_7, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args, __pyx_v_stop_info, __pyx_v_arg, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_19, 7+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[8] = {__pyx_t_7, __pyx_v_main_debugger, __pyx_v_frame, __pyx_v_event, __pyx_v_self->_args, __pyx_v_stop_info, __pyx_v_arg, __pyx_t_4}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_19, 7+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + #endif + { + __pyx_t_8 = PyTuple_New(7+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 856, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_19, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_19, __pyx_v_event); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_8, 3+__pyx_t_19, __pyx_v_self->_args); + __Pyx_INCREF(__pyx_v_stop_info); + __Pyx_GIVEREF(__pyx_v_stop_info); + PyTuple_SET_ITEM(__pyx_t_8, 4+__pyx_t_19, __pyx_v_stop_info); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_8, 5+__pyx_t_19, __pyx_v_arg); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 6+__pyx_t_19, __pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_stopped_on_plugin = __pyx_t_3; + __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":855 + * stop = False + * + * if plugin_stop: # <<<<<<<<<<<<<< + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + * elif stop: + */ + goto __pyx_L183; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":857 + * if plugin_stop: + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + * elif stop: # <<<<<<<<<<<<<< + * if is_line: + * self.set_suspend(thread, step_cmd) + */ + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_stop); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 857, __pyx_L131_error) + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":858 + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + * elif stop: + * if is_line: # <<<<<<<<<<<<<< + * self.set_suspend(thread, step_cmd) + * self.do_wait_suspend(thread, frame, event, arg) + */ + __pyx_t_12 = (__pyx_v_is_line != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":859 + * elif stop: + * if is_line: + * self.set_suspend(thread, step_cmd) # <<<<<<<<<<<<<< + * self.do_wait_suspend(thread, frame, event, arg) + * else: # return event + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_suspend); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_step_cmd); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 859, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_thread, __pyx_t_8}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 859, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_thread, __pyx_t_8}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 859, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_19); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 859, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_19, __pyx_v_thread); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_19, __pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 859, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":860 + * if is_line: + * self.set_suspend(thread, step_cmd) + * self.do_wait_suspend(thread, frame, event, arg) # <<<<<<<<<<<<<< + * else: # return event + * back = frame.f_back + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_do_wait_suspend); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 860, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_thread, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 860, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_thread, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 860, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_8 = PyTuple_New(4+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 860, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_19, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_19, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_19, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_8, 3+__pyx_t_19, __pyx_v_arg); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 860, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":858 + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + * elif stop: + * if is_line: # <<<<<<<<<<<<<< + * self.set_suspend(thread, step_cmd) + * self.do_wait_suspend(thread, frame, event, arg) + */ + goto __pyx_L184; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":862 + * self.do_wait_suspend(thread, frame, event, arg) + * else: # return event + * back = frame.f_back # <<<<<<<<<<<<<< + * if back is not None: + * # When we get to the pydevd run function, the debugging has actually finished for the main thread + */ + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 862, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_back = __pyx_t_3; + __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":863 + * else: # return event + * back = frame.f_back + * if back is not None: # <<<<<<<<<<<<<< + * # When we get to the pydevd run function, the debugging has actually finished for the main thread + * # (note that it can still go on for other threads, but for this one, we just make it finish) + */ + __pyx_t_12 = (__pyx_v_back != Py_None); + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":867 + * # (note that it can still go on for other threads, but for this one, we just make it finish) + * # So, just setting it to None should be OK + * _, back_filename, base = get_abs_path_real_path_and_base_from_frame(back) # <<<<<<<<<<<<<< + * if (base, back.f_code.co_name) in (DEBUG_START, DEBUG_START_PY3K): + * back = None + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 867, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_v_back) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_back); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 867, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 867, __pyx_L131_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_8 = PyList_GET_ITEM(sequence, 1); + __pyx_t_7 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 867, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 867, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 867, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 867, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_11 = Py_TYPE(__pyx_t_4)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_11(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L186_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_8 = __pyx_t_11(__pyx_t_4); if (unlikely(!__pyx_t_8)) goto __pyx_L186_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 2; __pyx_t_7 = __pyx_t_11(__pyx_t_4); if (unlikely(!__pyx_t_7)) goto __pyx_L186_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_4), 3) < 0) __PYX_ERR(0, 867, __pyx_L131_error) + __pyx_t_11 = NULL; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L187_unpacking_done; + __pyx_L186_unpacking_failed:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 867, __pyx_L131_error) + __pyx_L187_unpacking_done:; + } + __pyx_v__ = __pyx_t_6; + __pyx_t_6 = 0; + __pyx_v_back_filename = __pyx_t_8; + __pyx_t_8 = 0; + __pyx_v_base = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":868 + * # So, just setting it to None should be OK + * _, back_filename, base = get_abs_path_real_path_and_base_from_frame(back) + * if (base, back.f_code.co_name) in (DEBUG_START, DEBUG_START_PY3K): # <<<<<<<<<<<<<< + * back = None + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_back, __pyx_n_s_f_code); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_co_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_base); + __Pyx_GIVEREF(__pyx_v_base); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_base); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7); + __pyx_t_7 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_DEBUG_START); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_RichCompare(__pyx_t_3, __pyx_t_7, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (!__pyx_t_12) { + } else { + __pyx_t_9 = __pyx_t_12; + goto __pyx_L189_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_DEBUG_START_PY3K); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 868, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __pyx_t_12; + __pyx_L189_bool_binop_done:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = (__pyx_t_9 != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":869 + * _, back_filename, base = get_abs_path_real_path_and_base_from_frame(back) + * if (base, back.f_code.co_name) in (DEBUG_START, DEBUG_START_PY3K): + * back = None # <<<<<<<<<<<<<< + * + * elif base == TRACE_PROPERTY: + */ + __Pyx_INCREF(Py_None); + __Pyx_DECREF_SET(__pyx_v_back, Py_None); + + /* "_pydevd_bundle/pydevd_cython.pyx":868 + * # So, just setting it to None should be OK + * _, back_filename, base = get_abs_path_real_path_and_base_from_frame(back) + * if (base, back.f_code.co_name) in (DEBUG_START, DEBUG_START_PY3K): # <<<<<<<<<<<<<< + * back = None + * + */ + goto __pyx_L188; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":871 + * back = None + * + * elif base == TRACE_PROPERTY: # <<<<<<<<<<<<<< + * # We dont want to trace the return event of pydevd_traceproperty (custom property for debugging) + * # if we're in a return, we want it to appear to the user in the previous frame! + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_TRACE_PROPERTY); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 871, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyObject_RichCompare(__pyx_v_base, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 871, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 871, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":874 + * # We dont want to trace the return event of pydevd_traceproperty (custom property for debugging) + * # if we're in a return, we want it to appear to the user in the previous frame! + * return None if is_call else NO_FTRACE # <<<<<<<<<<<<<< + * + * elif pydevd_dont_trace.should_trace_hook is not None: + */ + __Pyx_XDECREF(__pyx_r); + if ((__pyx_v_is_call != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_7 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 874, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L135_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":871 + * back = None + * + * elif base == TRACE_PROPERTY: # <<<<<<<<<<<<<< + * # We dont want to trace the return event of pydevd_traceproperty (custom property for debugging) + * # if we're in a return, we want it to appear to the user in the previous frame! + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":876 + * return None if is_call else NO_FTRACE + * + * elif pydevd_dont_trace.should_trace_hook is not None: # <<<<<<<<<<<<<< + * if not pydevd_dont_trace.should_trace_hook(back, back_filename): + * # In this case, we'll have to skip the previous one because it shouldn't be traced. + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pydevd_dont_trace); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 876, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_should_trace_hook); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 876, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_12 = (__pyx_t_3 != Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":877 + * + * elif pydevd_dont_trace.should_trace_hook is not None: + * if not pydevd_dont_trace.should_trace_hook(back, back_filename): # <<<<<<<<<<<<<< + * # In this case, we'll have to skip the previous one because it shouldn't be traced. + * # Also, we have to reset the tracing, because if the parent's parent (or some + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pydevd_dont_trace); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_should_trace_hook); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_back, __pyx_v_back_filename}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_back, __pyx_v_back_filename}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_back); + __Pyx_GIVEREF(__pyx_v_back); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_19, __pyx_v_back); + __Pyx_INCREF(__pyx_v_back_filename); + __Pyx_GIVEREF(__pyx_v_back_filename); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_19, __pyx_v_back_filename); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 877, __pyx_L131_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = ((!__pyx_t_9) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":883 + * # we should anymore (so, a step in/over/return may not stop anywhere if no parent is traced). + * # Related test: _debugger_case17a.py + * main_debugger.set_trace_for_frame_and_parents(back) # <<<<<<<<<<<<<< + * return None if is_call else NO_FTRACE + * + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_set_trace_for_frame_and_parents); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 883, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_6, __pyx_v_back) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_back); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 883, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":884 + * # Related test: _debugger_case17a.py + * main_debugger.set_trace_for_frame_and_parents(back) + * return None if is_call else NO_FTRACE # <<<<<<<<<<<<<< + * + * if back is not None: + */ + __Pyx_XDECREF(__pyx_r); + if ((__pyx_v_is_call != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_3 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 884, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L135_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":877 + * + * elif pydevd_dont_trace.should_trace_hook is not None: + * if not pydevd_dont_trace.should_trace_hook(back, back_filename): # <<<<<<<<<<<<<< + * # In this case, we'll have to skip the previous one because it shouldn't be traced. + * # Also, we have to reset the tracing, because if the parent's parent (or some + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":876 + * return None if is_call else NO_FTRACE + * + * elif pydevd_dont_trace.should_trace_hook is not None: # <<<<<<<<<<<<<< + * if not pydevd_dont_trace.should_trace_hook(back, back_filename): + * # In this case, we'll have to skip the previous one because it shouldn't be traced. + */ + } + __pyx_L188:; + + /* "_pydevd_bundle/pydevd_cython.pyx":863 + * else: # return event + * back = frame.f_back + * if back is not None: # <<<<<<<<<<<<<< + * # When we get to the pydevd run function, the debugging has actually finished for the main thread + * # (note that it can still go on for other threads, but for this one, we just make it finish) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":886 + * return None if is_call else NO_FTRACE + * + * if back is not None: # <<<<<<<<<<<<<< + * # if we're in a return, we want it to appear to the user in the previous frame! + * self.set_suspend(thread, step_cmd) + */ + __pyx_t_12 = (__pyx_v_back != Py_None); + __pyx_t_9 = (__pyx_t_12 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":888 + * if back is not None: + * # if we're in a return, we want it to appear to the user in the previous frame! + * self.set_suspend(thread, step_cmd) # <<<<<<<<<<<<<< + * self.do_wait_suspend(thread, back, event, arg) + * else: + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_suspend); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 888, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_step_cmd); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 888, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_thread, __pyx_t_6}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 888, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_thread, __pyx_t_6}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 2+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 888, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(2+__pyx_t_19); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 888, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_19, __pyx_v_thread); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_19, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 888, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":889 + * # if we're in a return, we want it to appear to the user in the previous frame! + * self.set_suspend(thread, step_cmd) + * self.do_wait_suspend(thread, back, event, arg) # <<<<<<<<<<<<<< + * else: + * # in jython we may not have a back frame + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_do_wait_suspend); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 889, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = NULL; + __pyx_t_19 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_19 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_thread, __pyx_v_back, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 889, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_thread, __pyx_v_back, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_19, 4+__pyx_t_19); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 889, __pyx_L131_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_6 = PyTuple_New(4+__pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 889, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_19, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_back); + __Pyx_GIVEREF(__pyx_v_back); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_19, __pyx_v_back); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_19, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_19, __pyx_v_arg); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 889, __pyx_L131_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":886 + * return None if is_call else NO_FTRACE + * + * if back is not None: # <<<<<<<<<<<<<< + * # if we're in a return, we want it to appear to the user in the previous frame! + * self.set_suspend(thread, step_cmd) + */ + goto __pyx_L192; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":892 + * else: + * # in jython we may not have a back frame + * info.pydev_step_stop = None # <<<<<<<<<<<<<< + * info.pydev_original_step_cmd = -1 + * info.pydev_step_cmd = -1 + */ + /*else*/ { + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_info->pydev_step_stop); + __Pyx_DECREF(__pyx_v_info->pydev_step_stop); + __pyx_v_info->pydev_step_stop = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":893 + * # in jython we may not have a back frame + * info.pydev_step_stop = None + * info.pydev_original_step_cmd = -1 # <<<<<<<<<<<<<< + * info.pydev_step_cmd = -1 + * info.pydev_state = 1 + */ + __pyx_v_info->pydev_original_step_cmd = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":894 + * info.pydev_step_stop = None + * info.pydev_original_step_cmd = -1 + * info.pydev_step_cmd = -1 # <<<<<<<<<<<<<< + * info.pydev_state = 1 + * + */ + __pyx_v_info->pydev_step_cmd = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":895 + * info.pydev_original_step_cmd = -1 + * info.pydev_step_cmd = -1 + * info.pydev_state = 1 # <<<<<<<<<<<<<< + * + * except KeyboardInterrupt: + */ + __pyx_v_info->pydev_state = 1; + } + __pyx_L192:; + } + __pyx_L184:; + + /* "_pydevd_bundle/pydevd_cython.pyx":857 + * if plugin_stop: + * stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + * elif stop: # <<<<<<<<<<<<<< + * if is_line: + * self.set_suspend(thread, step_cmd) + */ + } + __pyx_L183:; + + /* "_pydevd_bundle/pydevd_cython.pyx":769 + * + * # step handling. We stop when we hit the right frame + * try: # <<<<<<<<<<<<<< + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: + */ + } + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L136_try_end; + __pyx_L131_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":897 + * info.pydev_state = 1 + * + * except KeyboardInterrupt: # <<<<<<<<<<<<<< + * raise + * except: + */ + __pyx_t_19 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyboardInterrupt); + if (__pyx_t_19) { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(0, 897, __pyx_L133_except_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_6); + + /* "_pydevd_bundle/pydevd_cython.pyx":898 + * + * except KeyboardInterrupt: + * raise # <<<<<<<<<<<<<< + * except: + * try: + */ + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ErrRestoreWithState(__pyx_t_3, __pyx_t_8, __pyx_t_6); + __pyx_t_3 = 0; __pyx_t_8 = 0; __pyx_t_6 = 0; + __PYX_ERR(0, 898, __pyx_L133_except_error) + } + + /* "_pydevd_bundle/pydevd_cython.pyx":899 + * except KeyboardInterrupt: + * raise + * except: # <<<<<<<<<<<<<< + * try: + * pydev_log.exception() + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_8, &__pyx_t_3) < 0) __PYX_ERR(0, 899, __pyx_L133_except_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_3); + + /* "_pydevd_bundle/pydevd_cython.pyx":900 + * raise + * except: + * try: # <<<<<<<<<<<<<< + * pydev_log.exception() + * info.pydev_original_step_cmd = -1 + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_26, &__pyx_t_25, &__pyx_t_24); + __Pyx_XGOTREF(__pyx_t_26); + __Pyx_XGOTREF(__pyx_t_25); + __Pyx_XGOTREF(__pyx_t_24); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":901 + * except: + * try: + * pydev_log.exception() # <<<<<<<<<<<<<< + * info.pydev_original_step_cmd = -1 + * info.pydev_step_cmd = -1 + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 901, __pyx_L197_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_exception); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 901, __pyx_L197_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 901, __pyx_L197_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":902 + * try: + * pydev_log.exception() + * info.pydev_original_step_cmd = -1 # <<<<<<<<<<<<<< + * info.pydev_step_cmd = -1 + * except: + */ + __pyx_v_info->pydev_original_step_cmd = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":903 + * pydev_log.exception() + * info.pydev_original_step_cmd = -1 + * info.pydev_step_cmd = -1 # <<<<<<<<<<<<<< + * except: + * return None if is_call else NO_FTRACE + */ + __pyx_v_info->pydev_step_cmd = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":900 + * raise + * except: + * try: # <<<<<<<<<<<<<< + * pydev_log.exception() + * info.pydev_original_step_cmd = -1 + */ + } + __Pyx_XDECREF(__pyx_t_26); __pyx_t_26 = 0; + __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0; + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + goto __pyx_L204_try_end; + __pyx_L197_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":904 + * info.pydev_original_step_cmd = -1 + * info.pydev_step_cmd = -1 + * except: # <<<<<<<<<<<<<< + * return None if is_call else NO_FTRACE + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_7) < 0) __PYX_ERR(0, 904, __pyx_L199_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_7); + + /* "_pydevd_bundle/pydevd_cython.pyx":905 + * info.pydev_step_cmd = -1 + * except: + * return None if is_call else NO_FTRACE # <<<<<<<<<<<<<< + * + * # if we are quitting, let's stop the tracing + */ + __Pyx_XDECREF(__pyx_r); + if ((__pyx_v_is_call != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_2 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_28, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 905, __pyx_L199_except_error) + __Pyx_GOTREF(__pyx_t_28); + __pyx_t_2 = __pyx_t_28; + __pyx_t_28 = 0; + } + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L200_except_return; + } + __pyx_L199_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":900 + * raise + * except: + * try: # <<<<<<<<<<<<<< + * pydev_log.exception() + * info.pydev_original_step_cmd = -1 + */ + __Pyx_XGIVEREF(__pyx_t_26); + __Pyx_XGIVEREF(__pyx_t_25); + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_ExceptionReset(__pyx_t_26, __pyx_t_25, __pyx_t_24); + goto __pyx_L133_except_error; + __pyx_L200_except_return:; + __Pyx_XGIVEREF(__pyx_t_26); + __Pyx_XGIVEREF(__pyx_t_25); + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_ExceptionReset(__pyx_t_26, __pyx_t_25, __pyx_t_24); + goto __pyx_L134_except_return; + __pyx_L204_try_end:; + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L132_exception_handled; + } + __pyx_L133_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":769 + * + * # step handling. We stop when we hit the right frame + * try: # <<<<<<<<<<<<<< + * should_skip = 0 + * if pydevd_dont_trace.should_trace_hook is not None: + */ + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16); + goto __pyx_L4_error; + __pyx_L135_try_return:; + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16); + goto __pyx_L3_return; + __pyx_L134_except_return:; + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16); + goto __pyx_L3_return; + __pyx_L132_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16); + __pyx_L136_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":908 + * + * # if we are quitting, let's stop the tracing + * if not main_debugger.quitting: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * else: + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_quitting); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 908, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 908, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_12 = ((!__pyx_t_9) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":909 + * # if we are quitting, let's stop the tracing + * if not main_debugger.quitting: + * return self.trace_dispatch # <<<<<<<<<<<<<< + * else: + * return None if is_call else NO_FTRACE + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 909, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":908 + * + * # if we are quitting, let's stop the tracing + * if not main_debugger.quitting: # <<<<<<<<<<<<<< + * return self.trace_dispatch + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":911 + * return self.trace_dispatch + * else: + * return None if is_call else NO_FTRACE # <<<<<<<<<<<<<< + * finally: + * info.is_tracing = False + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + if ((__pyx_v_is_call != 0)) { + __Pyx_INCREF(Py_None); + __pyx_t_3 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 911, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3_return; + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":913 + * return None if is_call else NO_FTRACE + * finally: + * info.is_tracing = False # <<<<<<<<<<<<<< + * + * # end trace_dispatch + */ + /*finally:*/ { + __pyx_L4_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_28); __pyx_t_28 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_24, &__pyx_t_25, &__pyx_t_26); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18) < 0)) __Pyx_ErrFetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_24); + __Pyx_XGOTREF(__pyx_t_25); + __Pyx_XGOTREF(__pyx_t_26); + __pyx_t_19 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_29 = __pyx_filename; + { + __pyx_v_info->is_tracing = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_XGIVEREF(__pyx_t_25); + __Pyx_XGIVEREF(__pyx_t_26); + __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_25, __pyx_t_26); + } + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_ErrRestore(__pyx_t_16, __pyx_t_17, __pyx_t_18); + __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; + __pyx_lineno = __pyx_t_19; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_29; + goto __pyx_L1_error; + } + __pyx_L3_return: { + __pyx_t_26 = __pyx_r; + __pyx_r = 0; + __pyx_v_info->is_tracing = 0; + __pyx_r = __pyx_t_26; + __pyx_t_26 = 0; + goto __pyx_L0; + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":509 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cpdef trace_dispatch(self, frame, str event, arg): # <<<<<<<<<<<<<< + * cdef str filename; + * cdef bint is_exception_event; + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_28); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_filename); + __Pyx_XDECREF((PyObject *)__pyx_v_info); + __Pyx_XDECREF(__pyx_v_breakpoints_for_file); + __Pyx_XDECREF(__pyx_v_curr_func_name); + __Pyx_XDECREF(__pyx_v_frame_skips_cache); + __Pyx_XDECREF(__pyx_v_frame_cache_key); + __Pyx_XDECREF(__pyx_v_line_cache_key); + __Pyx_XDECREF(__pyx_v_main_debugger); + __Pyx_XDECREF(__pyx_v_thread); + __Pyx_XDECREF(__pyx_v_plugin_manager); + __Pyx_XDECREF(__pyx_v_need_signature_trace_return); + __Pyx_XDECREF(__pyx_v_stop_frame); + __Pyx_XDECREF(__pyx_v_breakpoint); + __Pyx_XDECREF(__pyx_v_flag); + __Pyx_XDECREF(__pyx_v_stop_info); + __Pyx_XDECREF(__pyx_v_stop); + __Pyx_XDECREF(__pyx_v_bp_type); + __Pyx_XDECREF(__pyx_v_new_frame); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_eval_result); + __Pyx_XDECREF(__pyx_v_cmd); + __Pyx_XDECREF(__pyx_v_plugin_stop); + __Pyx_XDECREF(__pyx_v_force_check_project_scope); + __Pyx_XDECREF(__pyx_v_f_code); + __Pyx_XDECREF(__pyx_v_stopped_on_plugin); + __Pyx_XDECREF(__pyx_v_back); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_back_filename); + __Pyx_XDECREF(__pyx_v_base); + __Pyx_XDECREF(__pyx_v_frame); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_21trace_dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_21trace_dispatch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trace_dispatch (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 3, 3, 1); __PYX_ERR(0, 509, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 3, 3, 2); __PYX_ERR(0, 509, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trace_dispatch") < 0)) __PYX_ERR(0, 509, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = ((PyObject*)values[1]); + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 509, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_event), (&PyString_Type), 1, "event", 1))) __PYX_ERR(0, 509, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_20trace_dispatch(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_20trace_dispatch(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("trace_dispatch", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_trace_dispatch(__pyx_v_self, __pyx_v_frame, __pyx_v_event, __pyx_v_arg, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 509, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_23__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_23__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_22__reduce_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_22__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self._args, self.should_skip) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->should_skip); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self._args, self.should_skip) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v__dict = __pyx_t_2; + __pyx_t_2 = 0; + + /* "(tree fragment)":7 + * state = (self._args, self.should_skip) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_3 = (__pyx_v__dict != Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + if (__pyx_t_4) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict); + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self._args is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self._args, self.should_skip) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self._args is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, None), state + */ + /*else*/ { + __pyx_t_4 = (__pyx_v_self->_args != ((PyObject*)Py_None)); + __pyx_v_use_setstate = __pyx_t_4; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, None), state + * else: + */ + __pyx_t_4 = (__pyx_v_use_setstate != 0); + if (__pyx_t_4) { + + /* "(tree fragment)":13 + * use_setstate = self._args is not None + * if use_setstate: + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_PyDBFrame); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_262582659); + __Pyx_GIVEREF(__pyx_int_262582659); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_262582659); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, None), state + * else: + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_PyDBFrame__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_PyDBFrame); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_262582659); + __Pyx_GIVEREF(__pyx_int_262582659); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_262582659); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBFrame__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_25__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_25__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_24__setstate_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_24__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_PyDBFrame__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBFrame__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_PyDBFrame, (type(self), 0xfa6b183, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBFrame__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.PyDBFrame.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":952 + * + * + * def notify_skipped_step_in_because_of_filters(py_db, frame): # <<<<<<<<<<<<<< + * global _global_notify_skipped_step_in + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9notify_skipped_step_in_because_of_filters(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_9notify_skipped_step_in_because_of_filters = {"notify_skipped_step_in_because_of_filters", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9notify_skipped_step_in_because_of_filters, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_9notify_skipped_step_in_because_of_filters(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_py_db = 0; + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("notify_skipped_step_in_because_of_filters (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_py_db,&__pyx_n_s_frame,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_py_db)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("notify_skipped_step_in_because_of_filters", 1, 2, 2, 1); __PYX_ERR(0, 952, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "notify_skipped_step_in_because_of_filters") < 0)) __PYX_ERR(0, 952, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_py_db = values[0]; + __pyx_v_frame = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("notify_skipped_step_in_because_of_filters", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 952, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.notify_skipped_step_in_because_of_filters", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_8notify_skipped_step_in_because_of_filters(__pyx_self, __pyx_v_py_db, __pyx_v_frame); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_8notify_skipped_step_in_because_of_filters(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_py_db, PyObject *__pyx_v_frame) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + __Pyx_RefNannySetupContext("notify_skipped_step_in_because_of_filters", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":955 + * global _global_notify_skipped_step_in + * + * with _global_notify_skipped_step_in_lock: # <<<<<<<<<<<<<< + * if _global_notify_skipped_step_in: + * # Check with lock in place (callers should actually have checked + */ + /*with:*/ { + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_global_notify_skipped_step_in_l); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 955, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_exit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 955, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_enter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 955, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 955, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":956 + * + * with _global_notify_skipped_step_in_lock: + * if _global_notify_skipped_step_in: # <<<<<<<<<<<<<< + * # Check with lock in place (callers should actually have checked + * # before without the lock in place due to performance). + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 956, __pyx_L7_error) + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":959 + * # Check with lock in place (callers should actually have checked + * # before without the lock in place due to performance). + * return # <<<<<<<<<<<<<< + * _global_notify_skipped_step_in = True + * py_db.notify_skipped_step_in_because_of_filters(frame) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L11_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":956 + * + * with _global_notify_skipped_step_in_lock: + * if _global_notify_skipped_step_in: # <<<<<<<<<<<<<< + * # Check with lock in place (callers should actually have checked + * # before without the lock in place due to performance). + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":960 + * # before without the lock in place due to performance). + * return + * _global_notify_skipped_step_in = True # <<<<<<<<<<<<<< + * py_db.notify_skipped_step_in_because_of_filters(frame) + * + */ + __Pyx_INCREF(Py_True); + __Pyx_XGOTREF(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in); + __Pyx_DECREF_SET(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in, ((PyObject*)Py_True)); + __Pyx_GIVEREF(Py_True); + + /* "_pydevd_bundle/pydevd_cython.pyx":961 + * return + * _global_notify_skipped_step_in = True + * py_db.notify_skipped_step_in_because_of_filters(frame) # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_notify_skipped_step_in_because_o); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 961, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 961, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":955 + * global _global_notify_skipped_step_in + * + * with _global_notify_skipped_step_in_lock: # <<<<<<<<<<<<<< + * if _global_notify_skipped_step_in: + * # Check with lock in place (callers should actually have checked + */ + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L12_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.notify_skipped_step_in_because_of_filters", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(0, 955, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_Pack(3, __pyx_t_1, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 955, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 955, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_9 < 0) __PYX_ERR(0, 955, __pyx_L9_except_error) + __pyx_t_11 = ((!(__pyx_t_9 != 0)) != 0); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ErrRestoreWithState(__pyx_t_1, __pyx_t_3, __pyx_t_4); + __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; + __PYX_ERR(0, 955, __pyx_L9_except_error) + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + goto __pyx_L1_error; + __pyx_L11_try_return:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + goto __pyx_L4_return; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + __pyx_L12_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_2) { + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__2, NULL); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 955, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + goto __pyx_L6; + } + __pyx_L4_return: { + __pyx_t_8 = __pyx_r; + __pyx_r = 0; + if (__pyx_t_2) { + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__2, NULL); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 955, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L0; + } + __pyx_L6:; + } + goto __pyx_L17; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L1_error; + __pyx_L17:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":952 + * + * + * def notify_skipped_step_in_because_of_filters(py_db, frame): # <<<<<<<<<<<<<< + * global _global_notify_skipped_step_in + * + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.notify_skipped_step_in_because_of_filters", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":966 + * cdef class SafeCallWrapper: + * cdef method_object + * def __init__(self, method_object): # <<<<<<<<<<<<<< + * self.method_object = method_object + * def __call__(self, *args): + */ + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_method_object = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_method_object,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_method_object)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 966, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_method_object = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 966, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.SafeCallWrapper.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper___init__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)__pyx_v_self), __pyx_v_method_object); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self, PyObject *__pyx_v_method_object) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":967 + * cdef method_object + * def __init__(self, method_object): + * self.method_object = method_object # <<<<<<<<<<<<<< + * def __call__(self, *args): + * #Cannot use 'self' once inside the delegate call since we are borrowing the self reference f_trace field + */ + __Pyx_INCREF(__pyx_v_method_object); + __Pyx_GIVEREF(__pyx_v_method_object); + __Pyx_GOTREF(__pyx_v_self->method_object); + __Pyx_DECREF(__pyx_v_self->method_object); + __pyx_v_self->method_object = __pyx_v_method_object; + + /* "_pydevd_bundle/pydevd_cython.pyx":966 + * cdef class SafeCallWrapper: + * cdef method_object + * def __init__(self, method_object): # <<<<<<<<<<<<<< + * self.method_object = method_object + * def __call__(self, *args): + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":968 + * def __init__(self, method_object): + * self.method_object = method_object + * def __call__(self, *args): # <<<<<<<<<<<<<< + * #Cannot use 'self' once inside the delegate call since we are borrowing the self reference f_trace field + * #in the frame, and that reference might get destroyed by set trace on frame and parents + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__call__", 0))) return NULL; + __Pyx_INCREF(__pyx_args); + __pyx_v_args = __pyx_args; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_2__call__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)__pyx_v_self), __pyx_v_args); + + /* function exit code */ + __Pyx_XDECREF(__pyx_v_args); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_2__call__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self, PyObject *__pyx_v_args) { + PyObject *__pyx_v_method_obj; + PyObject *__pyx_v_ret = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("__call__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":971 + * #Cannot use 'self' once inside the delegate call since we are borrowing the self reference f_trace field + * #in the frame, and that reference might get destroyed by set trace on frame and parents + * cdef PyObject* method_obj = self.method_object # <<<<<<<<<<<<<< + * Py_INCREF(method_obj) + * ret = (method_obj)(*args) + */ + __pyx_v_method_obj = ((PyObject *)__pyx_v_self->method_object); + + /* "_pydevd_bundle/pydevd_cython.pyx":972 + * #in the frame, and that reference might get destroyed by set trace on frame and parents + * cdef PyObject* method_obj = self.method_object + * Py_INCREF(method_obj) # <<<<<<<<<<<<<< + * ret = (method_obj)(*args) + * Py_XDECREF (method_obj) + */ + Py_INCREF(((PyObject *)__pyx_v_method_obj)); + + /* "_pydevd_bundle/pydevd_cython.pyx":973 + * cdef PyObject* method_obj = self.method_object + * Py_INCREF(method_obj) + * ret = (method_obj)(*args) # <<<<<<<<<<<<<< + * Py_XDECREF (method_obj) + * return SafeCallWrapper(ret) if ret is not None else None + */ + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_v_method_obj), __pyx_v_args, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 973, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":974 + * Py_INCREF(method_obj) + * ret = (method_obj)(*args) + * Py_XDECREF (method_obj) # <<<<<<<<<<<<<< + * return SafeCallWrapper(ret) if ret is not None else None + * def get_method_object(self): + */ + Py_XDECREF(__pyx_v_method_obj); + + /* "_pydevd_bundle/pydevd_cython.pyx":975 + * ret = (method_obj)(*args) + * Py_XDECREF (method_obj) + * return SafeCallWrapper(ret) if ret is not None else None # <<<<<<<<<<<<<< + * def get_method_object(self): + * return self.method_object + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = (__pyx_v_ret != Py_None); + if ((__pyx_t_2 != 0)) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), __pyx_v_ret); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 975, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + } else { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":968 + * def __init__(self, method_object): + * self.method_object = method_object + * def __call__(self, *args): # <<<<<<<<<<<<<< + * #Cannot use 'self' once inside the delegate call since we are borrowing the self reference f_trace field + * #in the frame, and that reference might get destroyed by set trace on frame and parents + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":976 + * Py_XDECREF (method_obj) + * return SafeCallWrapper(ret) if ret is not None else None + * def get_method_object(self): # <<<<<<<<<<<<<< + * return self.method_object + * # ELSE + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_5get_method_object(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_5get_method_object(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_method_object (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_4get_method_object(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_4get_method_object(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_method_object", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":977 + * return SafeCallWrapper(ret) if ret is not None else None + * def get_method_object(self): + * return self.method_object # <<<<<<<<<<<<<< + * # ELSE + * # ENDIF + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->method_object); + __pyx_r = __pyx_v_self->method_object; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":976 + * Py_XDECREF (method_obj) + * return SafeCallWrapper(ret) if ret is not None else None + * def get_method_object(self): # <<<<<<<<<<<<<< + * return self.method_object + * # ELSE + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_6__reduce_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.method_object,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->method_object); + __Pyx_GIVEREF(__pyx_v_self->method_object); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->method_object); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.method_object,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":7 + * state = (self.method_object,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.method_object is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.method_object,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.method_object is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, None), state + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->method_object != Py_None); + __pyx_v_use_setstate = __pyx_t_3; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.method_object is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, None), state + * else: + */ + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":13 + * use_setstate = self.method_object is not None + * if use_setstate: + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_SafeCallWrapper); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_125568891); + __Pyx_GIVEREF(__pyx_int_125568891); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_125568891); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.method_object is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, None), state + * else: + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_SafeCallWrapper__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_SafeCallWrapper); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_125568891); + __Pyx_GIVEREF(__pyx_int_125568891); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_125568891); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.SafeCallWrapper.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_SafeCallWrapper__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_8__setstate_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_SafeCallWrapper__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_SafeCallWrapper__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_SafeCallWrapper, (type(self), 0x77c077b, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_SafeCallWrapper__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.SafeCallWrapper.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":982 + * + * + * def fix_top_level_trace_and_get_trace_func(py_db, frame): # <<<<<<<<<<<<<< + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef str filename; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_11fix_top_level_trace_and_get_trace_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_11fix_top_level_trace_and_get_trace_func = {"fix_top_level_trace_and_get_trace_func", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_11fix_top_level_trace_and_get_trace_func, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_11fix_top_level_trace_and_get_trace_func(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_py_db = 0; + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("fix_top_level_trace_and_get_trace_func (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_py_db,&__pyx_n_s_frame,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_py_db)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("fix_top_level_trace_and_get_trace_func", 1, 2, 2, 1); __PYX_ERR(0, 982, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fix_top_level_trace_and_get_trace_func") < 0)) __PYX_ERR(0, 982, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_py_db = values[0]; + __pyx_v_frame = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("fix_top_level_trace_and_get_trace_func", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 982, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.fix_top_level_trace_and_get_trace_func", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_10fix_top_level_trace_and_get_trace_func(__pyx_self, __pyx_v_py_db, __pyx_v_frame); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_10fix_top_level_trace_and_get_trace_func(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_py_db, PyObject *__pyx_v_frame) { + PyObject *__pyx_v_name = 0; + PyObject *__pyx_v_args = 0; + PyObject *__pyx_v_thread = NULL; + PyObject *__pyx_v_f_unhandled = NULL; + int __pyx_v_force_only_unhandled_tracer; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_v_t = NULL; + PyObject *__pyx_v_additional_info = NULL; + PyObject *__pyx_v_top_level_thread_tracer = NULL; + PyObject *__pyx_v_f_trace = NULL; + PyObject *__pyx_v_thread_tracer = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + int __pyx_t_15; + __Pyx_RefNannySetupContext("fix_top_level_trace_and_get_trace_func", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":993 + * # where more information is cached (and will also setup the tracing for + * # frames where we should deal with unhandled exceptions). + * thread = None # <<<<<<<<<<<<<< + * # Cache the frame which should be traced to deal with unhandled exceptions. + * # (i.e.: thread entry-points). + */ + __Pyx_INCREF(Py_None); + __pyx_v_thread = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":997 + * # (i.e.: thread entry-points). + * + * f_unhandled = frame # <<<<<<<<<<<<<< + * # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + * force_only_unhandled_tracer = False + */ + __Pyx_INCREF(__pyx_v_frame); + __pyx_v_f_unhandled = __pyx_v_frame; + + /* "_pydevd_bundle/pydevd_cython.pyx":999 + * f_unhandled = frame + * # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + * force_only_unhandled_tracer = False # <<<<<<<<<<<<<< + * while f_unhandled is not None: + * # name = splitext(basename(f_unhandled.f_code.co_filename))[0] + */ + __pyx_v_force_only_unhandled_tracer = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1000 + * # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + * force_only_unhandled_tracer = False + * while f_unhandled is not None: # <<<<<<<<<<<<<< + * # name = splitext(basename(f_unhandled.f_code.co_filename))[0] + * + */ + while (1) { + __pyx_t_1 = (__pyx_v_f_unhandled != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (!__pyx_t_2) break; + + /* "_pydevd_bundle/pydevd_cython.pyx":1003 + * # name = splitext(basename(f_unhandled.f_code.co_filename))[0] + * + * name = f_unhandled.f_code.co_filename # <<<<<<<<<<<<<< + * # basename + * i = name.rfind('/') + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_code); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1003, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1003, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!(likely(PyString_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 1003, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1005 + * name = f_unhandled.f_code.co_filename + * # basename + * i = name.rfind('/') # <<<<<<<<<<<<<< + * j = name.rfind('\\') + * if j > i: + */ + __pyx_t_4 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_rfind, __pyx_v_name, __pyx_kp_s__4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1005, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1006 + * # basename + * i = name.rfind('/') + * j = name.rfind('\\') # <<<<<<<<<<<<<< + * if j > i: + * i = j + */ + __pyx_t_4 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_rfind, __pyx_v_name, __pyx_kp_s__5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1006, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v_j, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1007 + * i = name.rfind('/') + * j = name.rfind('\\') + * if j > i: # <<<<<<<<<<<<<< + * i = j + * if i >= 0: + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_j, __pyx_v_i, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1007, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1007, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1008 + * j = name.rfind('\\') + * if j > i: + * i = j # <<<<<<<<<<<<<< + * if i >= 0: + * name = name[i + 1:] + */ + __Pyx_INCREF(__pyx_v_j); + __Pyx_DECREF_SET(__pyx_v_i, __pyx_v_j); + + /* "_pydevd_bundle/pydevd_cython.pyx":1007 + * i = name.rfind('/') + * j = name.rfind('\\') + * if j > i: # <<<<<<<<<<<<<< + * i = j + * if i >= 0: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1009 + * if j > i: + * i = j + * if i >= 0: # <<<<<<<<<<<<<< + * name = name[i + 1:] + * # remove ext + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_i, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1009, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1009, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1010 + * i = j + * if i >= 0: + * name = name[i + 1:] # <<<<<<<<<<<<<< + * # remove ext + * i = name.rfind('.') + */ + if (unlikely(__pyx_v_name == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1010, __pyx_L1_error) + } + __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1010, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = (__pyx_t_4 == Py_None); + if (__pyx_t_2) { + __pyx_t_5 = 0; + } else { + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1010, __pyx_L1_error) + __pyx_t_5 = __pyx_t_6; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PySequence_GetSlice(__pyx_v_name, __pyx_t_5, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1010, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1009 + * if j > i: + * i = j + * if i >= 0: # <<<<<<<<<<<<<< + * name = name[i + 1:] + * # remove ext + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1012 + * name = name[i + 1:] + * # remove ext + * i = name.rfind('.') # <<<<<<<<<<<<<< + * if i >= 0: + * name = name[:i] + */ + __pyx_t_4 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyString_Type_rfind, __pyx_v_name, __pyx_kp_s__6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1012, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_i, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1013 + * # remove ext + * i = name.rfind('.') + * if i >= 0: # <<<<<<<<<<<<<< + * name = name[:i] + * + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_i, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1013, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1013, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1014 + * i = name.rfind('.') + * if i >= 0: + * name = name[:i] # <<<<<<<<<<<<<< + * + * if name == 'threading': + */ + if (unlikely(__pyx_v_name == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1014, __pyx_L1_error) + } + __Pyx_INCREF(__pyx_v_i); + __pyx_t_4 = __pyx_v_i; + __pyx_t_2 = (__pyx_t_4 == Py_None); + if (__pyx_t_2) { + __pyx_t_5 = PY_SSIZE_T_MAX; + } else { + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1014, __pyx_L1_error) + __pyx_t_5 = __pyx_t_6; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PySequence_GetSlice(__pyx_v_name, 0, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1014, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1013 + * # remove ext + * i = name.rfind('.') + * if i >= 0: # <<<<<<<<<<<<<< + * name = name[:i] + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1016 + * name = name[:i] + * + * if name == 'threading': # <<<<<<<<<<<<<< + * if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): + * # We need __bootstrap_inner, not __bootstrap. + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_name, __pyx_n_s_threading, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1016, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1017 + * + * if name == 'threading': + * if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): # <<<<<<<<<<<<<< + * # We need __bootstrap_inner, not __bootstrap. + * return None, False + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1017, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1017, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_bootstrap, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1017, __pyx_L1_error) + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L10_bool_binop_done; + } + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_bootstrap_2, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1017, __pyx_L1_error) + __pyx_t_1 = __pyx_t_2; + __pyx_L10_bool_binop_done:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1019 + * if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): + * # We need __bootstrap_inner, not __bootstrap. + * return None, False # <<<<<<<<<<<<<< + * + * elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_tuple__7); + __pyx_r = __pyx_tuple__7; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1017 + * + * if name == 'threading': + * if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): # <<<<<<<<<<<<<< + * # We need __bootstrap_inner, not __bootstrap. + * return None, False + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1021 + * return None, False + * + * elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): # <<<<<<<<<<<<<< + * # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. + * t = f_unhandled.f_locals.get('self') + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_code); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1021, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_co_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1021, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_bootstrap_inner, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1021, __pyx_L1_error) + if (!__pyx_t_1) { + } else { + __pyx_t_2 = __pyx_t_1; + goto __pyx_L12_bool_binop_done; + } + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_bootstrap_inner_2, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1021, __pyx_L1_error) + __pyx_t_2 = __pyx_t_1; + __pyx_L12_bool_binop_done:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1023 + * elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): + * # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. + * t = f_unhandled.f_locals.get('self') # <<<<<<<<<<<<<< + * force_only_unhandled_tracer = True + * if t is not None and isinstance(t, threading.Thread): + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_locals); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1023, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1023, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_3, __pyx_n_s_self) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_n_s_self); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1023, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1024 + * # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. + * t = f_unhandled.f_locals.get('self') + * force_only_unhandled_tracer = True # <<<<<<<<<<<<<< + * if t is not None and isinstance(t, threading.Thread): + * thread = t + */ + __pyx_v_force_only_unhandled_tracer = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":1025 + * t = f_unhandled.f_locals.get('self') + * force_only_unhandled_tracer = True + * if t is not None and isinstance(t, threading.Thread): # <<<<<<<<<<<<<< + * thread = t + * break + */ + __pyx_t_2 = (__pyx_v_t != Py_None); + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { + } else { + __pyx_t_1 = __pyx_t_8; + goto __pyx_L15_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_threading); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_Thread); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1025, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = PyObject_IsInstance(__pyx_v_t, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1025, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_2 = (__pyx_t_8 != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L15_bool_binop_done:; + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1026 + * force_only_unhandled_tracer = True + * if t is not None and isinstance(t, threading.Thread): + * thread = t # <<<<<<<<<<<<<< + * break + * + */ + __Pyx_INCREF(__pyx_v_t); + __Pyx_DECREF_SET(__pyx_v_thread, __pyx_v_t); + + /* "_pydevd_bundle/pydevd_cython.pyx":1027 + * if t is not None and isinstance(t, threading.Thread): + * thread = t + * break # <<<<<<<<<<<<<< + * + * elif name == 'pydev_monkey': + */ + goto __pyx_L4_break; + + /* "_pydevd_bundle/pydevd_cython.pyx":1025 + * t = f_unhandled.f_locals.get('self') + * force_only_unhandled_tracer = True + * if t is not None and isinstance(t, threading.Thread): # <<<<<<<<<<<<<< + * thread = t + * break + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1021 + * return None, False + * + * elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): # <<<<<<<<<<<<<< + * # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. + * t = f_unhandled.f_locals.get('self') + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1016 + * name = name[:i] + * + * if name == 'threading': # <<<<<<<<<<<<<< + * if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): + * # We need __bootstrap_inner, not __bootstrap. + */ + goto __pyx_L8; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1029 + * break + * + * elif name == 'pydev_monkey': # <<<<<<<<<<<<<< + * if f_unhandled.f_code.co_name == '__call__': + * force_only_unhandled_tracer = True + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_name, __pyx_n_s_pydev_monkey, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1029, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1030 + * + * elif name == 'pydev_monkey': + * if f_unhandled.f_code.co_name == '__call__': # <<<<<<<<<<<<<< + * force_only_unhandled_tracer = True + * break + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_code); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_co_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_call_2, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1030, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1031 + * elif name == 'pydev_monkey': + * if f_unhandled.f_code.co_name == '__call__': + * force_only_unhandled_tracer = True # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_force_only_unhandled_tracer = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":1032 + * if f_unhandled.f_code.co_name == '__call__': + * force_only_unhandled_tracer = True + * break # <<<<<<<<<<<<<< + * + * elif name == 'pydevd': + */ + goto __pyx_L4_break; + + /* "_pydevd_bundle/pydevd_cython.pyx":1030 + * + * elif name == 'pydev_monkey': + * if f_unhandled.f_code.co_name == '__call__': # <<<<<<<<<<<<<< + * force_only_unhandled_tracer = True + * break + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1029 + * break + * + * elif name == 'pydev_monkey': # <<<<<<<<<<<<<< + * if f_unhandled.f_code.co_name == '__call__': + * force_only_unhandled_tracer = True + */ + goto __pyx_L8; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1034 + * break + * + * elif name == 'pydevd': # <<<<<<<<<<<<<< + * if f_unhandled.f_code.co_name in ('run', 'main'): + * # We need to get to _exec + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_name, __pyx_n_s_pydevd, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1034, __pyx_L1_error) + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1035 + * + * elif name == 'pydevd': + * if f_unhandled.f_code.co_name in ('run', 'main'): # <<<<<<<<<<<<<< + * # We need to get to _exec + * return None, False + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1035, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_7, __pyx_n_s_run, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1035, __pyx_L1_error) + if (!__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L19_bool_binop_done; + } + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_7, __pyx_n_s_main, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1035, __pyx_L1_error) + __pyx_t_1 = __pyx_t_2; + __pyx_L19_bool_binop_done:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1037 + * if f_unhandled.f_code.co_name in ('run', 'main'): + * # We need to get to _exec + * return None, False # <<<<<<<<<<<<<< + * + * if f_unhandled.f_code.co_name == '_exec': + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_tuple__7); + __pyx_r = __pyx_tuple__7; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1035 + * + * elif name == 'pydevd': + * if f_unhandled.f_code.co_name in ('run', 'main'): # <<<<<<<<<<<<<< + * # We need to get to _exec + * return None, False + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1039 + * return None, False + * + * if f_unhandled.f_code.co_name == '_exec': # <<<<<<<<<<<<<< + * force_only_unhandled_tracer = True + * break + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_code); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1039, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_co_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1039, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_exec, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1039, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1040 + * + * if f_unhandled.f_code.co_name == '_exec': + * force_only_unhandled_tracer = True # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_force_only_unhandled_tracer = 1; + + /* "_pydevd_bundle/pydevd_cython.pyx":1041 + * if f_unhandled.f_code.co_name == '_exec': + * force_only_unhandled_tracer = True + * break # <<<<<<<<<<<<<< + * + * elif f_unhandled.f_back is None: + */ + goto __pyx_L4_break; + + /* "_pydevd_bundle/pydevd_cython.pyx":1039 + * return None, False + * + * if f_unhandled.f_code.co_name == '_exec': # <<<<<<<<<<<<<< + * force_only_unhandled_tracer = True + * break + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1034 + * break + * + * elif name == 'pydevd': # <<<<<<<<<<<<<< + * if f_unhandled.f_code.co_name in ('run', 'main'): + * # We need to get to _exec + */ + goto __pyx_L8; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1043 + * break + * + * elif f_unhandled.f_back is None: # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1043, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = (__pyx_t_4 == Py_None); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1044 + * + * elif f_unhandled.f_back is None: + * break # <<<<<<<<<<<<<< + * + * f_unhandled = f_unhandled.f_back + */ + goto __pyx_L4_break; + + /* "_pydevd_bundle/pydevd_cython.pyx":1043 + * break + * + * elif f_unhandled.f_back is None: # <<<<<<<<<<<<<< + * break + * + */ + } + __pyx_L8:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1046 + * break + * + * f_unhandled = f_unhandled.f_back # <<<<<<<<<<<<<< + * + * if thread is None: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1046, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_f_unhandled, __pyx_t_4); + __pyx_t_4 = 0; + } + __pyx_L4_break:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1048 + * f_unhandled = f_unhandled.f_back + * + * if thread is None: # <<<<<<<<<<<<<< + * # Important: don't call threadingCurrentThread if we're in the threading module + * # to avoid creating dummy threads. + */ + __pyx_t_1 = (__pyx_v_thread == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1051 + * # Important: don't call threadingCurrentThread if we're in the threading module + * # to avoid creating dummy threads. + * if py_db.threading_get_ident is not None: # <<<<<<<<<<<<<< + * thread = py_db.threading_active.get(py_db.threading_get_ident()) + * if thread is None: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_threading_get_ident); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1051, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = (__pyx_t_4 != Py_None); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1052 + * # to avoid creating dummy threads. + * if py_db.threading_get_ident is not None: + * thread = py_db.threading_active.get(py_db.threading_get_ident()) # <<<<<<<<<<<<<< + * if thread is None: + * return None, False + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_threading_active); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1052, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1052, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_threading_get_ident); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1052, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + __pyx_t_7 = (__pyx_t_10) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10) : __Pyx_PyObject_CallNoArg(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1052, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1052, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_thread, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1053 + * if py_db.threading_get_ident is not None: + * thread = py_db.threading_active.get(py_db.threading_get_ident()) + * if thread is None: # <<<<<<<<<<<<<< + * return None, False + * else: + */ + __pyx_t_1 = (__pyx_v_thread == Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1054 + * thread = py_db.threading_active.get(py_db.threading_get_ident()) + * if thread is None: + * return None, False # <<<<<<<<<<<<<< + * else: + * # Jython does not have threading.get_ident(). + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_tuple__7); + __pyx_r = __pyx_tuple__7; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1053 + * if py_db.threading_get_ident is not None: + * thread = py_db.threading_active.get(py_db.threading_get_ident()) + * if thread is None: # <<<<<<<<<<<<<< + * return None, False + * else: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1051 + * # Important: don't call threadingCurrentThread if we're in the threading module + * # to avoid creating dummy threads. + * if py_db.threading_get_ident is not None: # <<<<<<<<<<<<<< + * thread = py_db.threading_active.get(py_db.threading_get_ident()) + * if thread is None: + */ + goto __pyx_L23; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1057 + * else: + * # Jython does not have threading.get_ident(). + * thread = py_db.threading_current_thread() # <<<<<<<<<<<<<< + * + * if getattr(thread, 'pydev_do_not_trace', None): + */ + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_threading_current_thread); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1057, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF_SET(__pyx_v_thread, __pyx_t_4); + __pyx_t_4 = 0; + } + __pyx_L23:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1048 + * f_unhandled = f_unhandled.f_back + * + * if thread is None: # <<<<<<<<<<<<<< + * # Important: don't call threadingCurrentThread if we're in the threading module + * # to avoid creating dummy threads. + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1059 + * thread = py_db.threading_current_thread() + * + * if getattr(thread, 'pydev_do_not_trace', None): # <<<<<<<<<<<<<< + * py_db.disable_tracing() + * return None, False + */ + __pyx_t_4 = __Pyx_GetAttr3(__pyx_v_thread, __pyx_n_s_pydev_do_not_trace, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1059, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1059, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1060 + * + * if getattr(thread, 'pydev_do_not_trace', None): + * py_db.disable_tracing() # <<<<<<<<<<<<<< + * return None, False + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_disable_tracing); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1060, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1060, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1061 + * if getattr(thread, 'pydev_do_not_trace', None): + * py_db.disable_tracing() + * return None, False # <<<<<<<<<<<<<< + * + * try: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_tuple__7); + __pyx_r = __pyx_tuple__7; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1059 + * thread = py_db.threading_current_thread() + * + * if getattr(thread, 'pydev_do_not_trace', None): # <<<<<<<<<<<<<< + * py_db.disable_tracing() + * return None, False + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1063 + * return None, False + * + * try: # <<<<<<<<<<<<<< + * additional_info = thread.additional_info + * if additional_info is None: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":1064 + * + * try: + * additional_info = thread.additional_info # <<<<<<<<<<<<<< + * if additional_info is None: + * raise AttributeError() + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread, __pyx_n_s_additional_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1064, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_additional_info = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1065 + * try: + * additional_info = thread.additional_info + * if additional_info is None: # <<<<<<<<<<<<<< + * raise AttributeError() + * except: + */ + __pyx_t_2 = (__pyx_v_additional_info == Py_None); + __pyx_t_1 = (__pyx_t_2 != 0); + if (unlikely(__pyx_t_1)) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1066 + * additional_info = thread.additional_info + * if additional_info is None: + * raise AttributeError() # <<<<<<<<<<<<<< + * except: + * additional_info = py_db.set_additional_thread_info(thread) + */ + __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_builtin_AttributeError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1066, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __PYX_ERR(0, 1066, __pyx_L26_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1065 + * try: + * additional_info = thread.additional_info + * if additional_info is None: # <<<<<<<<<<<<<< + * raise AttributeError() + * except: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1063 + * return None, False + * + * try: # <<<<<<<<<<<<<< + * additional_info = thread.additional_info + * if additional_info is None: + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L31_try_end; + __pyx_L26_error:; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1067 + * if additional_info is None: + * raise AttributeError() + * except: # <<<<<<<<<<<<<< + * additional_info = py_db.set_additional_thread_info(thread) + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.fix_top_level_trace_and_get_trace_func", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_7) < 0) __PYX_ERR(0, 1067, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_7); + + /* "_pydevd_bundle/pydevd_cython.pyx":1068 + * raise AttributeError() + * except: + * additional_info = py_db.set_additional_thread_info(thread) # <<<<<<<<<<<<<< + * + * # print('enter thread tracer', thread, get_current_thread_id(thread)) + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_set_additional_thread_info); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1068, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + } + } + __pyx_t_9 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_14, __pyx_v_thread) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_thread); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1068, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF_SET(__pyx_v_additional_info, __pyx_t_9); + __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L27_exception_handled; + } + __pyx_L28_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1063 + * return None, False + * + * try: # <<<<<<<<<<<<<< + * additional_info = thread.additional_info + * if additional_info is None: + */ + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + goto __pyx_L1_error; + __pyx_L27_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13); + __pyx_L31_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1071 + * + * # print('enter thread tracer', thread, get_current_thread_id(thread)) + * args = (py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips) # <<<<<<<<<<<<<< + * + * if f_unhandled is not None: + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_global_cache_skips); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1071, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_global_cache_frame_skips); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1071, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1071, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_thread); + __Pyx_GIVEREF(__pyx_v_thread); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_thread); + __Pyx_INCREF(__pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_v_additional_info); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_t_3); + __pyx_t_7 = 0; + __pyx_t_3 = 0; + __pyx_v_args = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1073 + * args = (py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips) + * + * if f_unhandled is not None: # <<<<<<<<<<<<<< + * if f_unhandled.f_back is None and not force_only_unhandled_tracer: + * # Happens when we attach to a running program (cannot reuse instance because it's mutable). + */ + __pyx_t_1 = (__pyx_v_f_unhandled != Py_None); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1074 + * + * if f_unhandled is not None: + * if f_unhandled.f_back is None and not force_only_unhandled_tracer: # <<<<<<<<<<<<<< + * # Happens when we attach to a running program (cannot reuse instance because it's mutable). + * top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1074, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = (__pyx_t_4 == Py_None); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = (__pyx_t_1 != 0); + if (__pyx_t_8) { + } else { + __pyx_t_2 = __pyx_t_8; + goto __pyx_L37_bool_binop_done; + } + __pyx_t_8 = ((!(__pyx_v_force_only_unhandled_tracer != 0)) != 0); + __pyx_t_2 = __pyx_t_8; + __pyx_L37_bool_binop_done:; + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1076 + * if f_unhandled.f_back is None and not force_only_unhandled_tracer: + * # Happens when we attach to a running program (cannot reuse instance because it's mutable). + * top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) # <<<<<<<<<<<<<< + * additional_info.top_level_thread_tracer_no_back_frames.append(top_level_thread_tracer) # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + * else: + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer), __pyx_v_args); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1076, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1076, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_INCREF(__pyx_v_args); + __Pyx_GIVEREF(__pyx_v_args); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_args); + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame), __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1076, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_top_level_thread_tracer = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1077 + * # Happens when we attach to a running program (cannot reuse instance because it's mutable). + * top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) + * additional_info.top_level_thread_tracer_no_back_frames.append(top_level_thread_tracer) # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # <<<<<<<<<<<<<< + * else: + * top_level_thread_tracer = additional_info.top_level_thread_tracer_unhandled + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_additional_info, __pyx_n_s_top_level_thread_tracer_no_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1077, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 = __Pyx_PyObject_Append(__pyx_t_4, __pyx_v_top_level_thread_tracer); if (unlikely(__pyx_t_15 == ((int)-1))) __PYX_ERR(0, 1077, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1074 + * + * if f_unhandled is not None: + * if f_unhandled.f_back is None and not force_only_unhandled_tracer: # <<<<<<<<<<<<<< + * # Happens when we attach to a running program (cannot reuse instance because it's mutable). + * top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) + */ + goto __pyx_L36; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1079 + * additional_info.top_level_thread_tracer_no_back_frames.append(top_level_thread_tracer) # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + * else: + * top_level_thread_tracer = additional_info.top_level_thread_tracer_unhandled # <<<<<<<<<<<<<< + * if top_level_thread_tracer is None: + * # Stop in some internal place to report about unhandled exceptions + */ + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_additional_info, __pyx_n_s_top_level_thread_tracer_unhandle); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1079, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_top_level_thread_tracer = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1080 + * else: + * top_level_thread_tracer = additional_info.top_level_thread_tracer_unhandled + * if top_level_thread_tracer is None: # <<<<<<<<<<<<<< + * # Stop in some internal place to report about unhandled exceptions + * top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) + */ + __pyx_t_2 = (__pyx_v_top_level_thread_tracer == Py_None); + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1082 + * if top_level_thread_tracer is None: + * # Stop in some internal place to report about unhandled exceptions + * top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) # <<<<<<<<<<<<<< + * additional_info.top_level_thread_tracer_unhandled = top_level_thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + * + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions), __pyx_v_args); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1082, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_top_level_thread_tracer, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1083 + * # Stop in some internal place to report about unhandled exceptions + * top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) + * additional_info.top_level_thread_tracer_unhandled = top_level_thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). # <<<<<<<<<<<<<< + * + * # print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_additional_info, __pyx_n_s_top_level_thread_tracer_unhandle, __pyx_v_top_level_thread_tracer) < 0) __PYX_ERR(0, 1083, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1080 + * else: + * top_level_thread_tracer = additional_info.top_level_thread_tracer_unhandled + * if top_level_thread_tracer is None: # <<<<<<<<<<<<<< + * # Stop in some internal place to report about unhandled exceptions + * top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) + */ + } + } + __pyx_L36:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1086 + * + * # print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + * f_trace = top_level_thread_tracer.get_trace_dispatch_func() # <<<<<<<<<<<<<< + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * f_trace = SafeCallWrapper(f_trace) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_top_level_thread_tracer, __pyx_n_s_get_trace_dispatch_func); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1086, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1086, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_f_trace = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1088 + * f_trace = top_level_thread_tracer.get_trace_dispatch_func() + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * f_trace = SafeCallWrapper(f_trace) # <<<<<<<<<<<<<< + * # ENDIF + * f_unhandled.f_trace = f_trace + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), __pyx_v_f_trace); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1088, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_f_trace, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1090 + * f_trace = SafeCallWrapper(f_trace) + * # ENDIF + * f_unhandled.f_trace = f_trace # <<<<<<<<<<<<<< + * + * if frame is f_unhandled: + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_f_unhandled, __pyx_n_s_f_trace, __pyx_v_f_trace) < 0) __PYX_ERR(0, 1090, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1092 + * f_unhandled.f_trace = f_trace + * + * if frame is f_unhandled: # <<<<<<<<<<<<<< + * return f_trace, False + * + */ + __pyx_t_8 = (__pyx_v_frame == __pyx_v_f_unhandled); + __pyx_t_2 = (__pyx_t_8 != 0); + if (__pyx_t_2) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1093 + * + * if frame is f_unhandled: + * return f_trace, False # <<<<<<<<<<<<<< + * + * thread_tracer = additional_info.thread_tracer + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1093, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_f_trace); + __Pyx_GIVEREF(__pyx_v_f_trace); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_f_trace); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_4, 1, Py_False); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1092 + * f_unhandled.f_trace = f_trace + * + * if frame is f_unhandled: # <<<<<<<<<<<<<< + * return f_trace, False + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1073 + * args = (py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips) + * + * if f_unhandled is not None: # <<<<<<<<<<<<<< + * if f_unhandled.f_back is None and not force_only_unhandled_tracer: + * # Happens when we attach to a running program (cannot reuse instance because it's mutable). + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1095 + * return f_trace, False + * + * thread_tracer = additional_info.thread_tracer # <<<<<<<<<<<<<< + * if thread_tracer is None: + * thread_tracer = ThreadTracer(args) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_additional_info, __pyx_n_s_thread_tracer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1095, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_thread_tracer = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1096 + * + * thread_tracer = additional_info.thread_tracer + * if thread_tracer is None: # <<<<<<<<<<<<<< + * thread_tracer = ThreadTracer(args) + * additional_info.thread_tracer = thread_tracer + */ + __pyx_t_2 = (__pyx_v_thread_tracer == Py_None); + __pyx_t_8 = (__pyx_t_2 != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1097 + * thread_tracer = additional_info.thread_tracer + * if thread_tracer is None: + * thread_tracer = ThreadTracer(args) # <<<<<<<<<<<<<< + * additional_info.thread_tracer = thread_tracer + * + */ + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer), __pyx_v_args); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1097, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF_SET(__pyx_v_thread_tracer, __pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1098 + * if thread_tracer is None: + * thread_tracer = ThreadTracer(args) + * additional_info.thread_tracer = thread_tracer # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_additional_info, __pyx_n_s_thread_tracer, __pyx_v_thread_tracer) < 0) __PYX_ERR(0, 1098, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1096 + * + * thread_tracer = additional_info.thread_tracer + * if thread_tracer is None: # <<<<<<<<<<<<<< + * thread_tracer = ThreadTracer(args) + * additional_info.thread_tracer = thread_tracer + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1101 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * return SafeCallWrapper(thread_tracer), True # <<<<<<<<<<<<<< + * # ELSE + * # return thread_tracer, True + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), __pyx_v_thread_tracer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1101, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_INCREF(Py_True); + __Pyx_GIVEREF(Py_True); + PyTuple_SET_ITEM(__pyx_t_3, 1, Py_True); + __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":982 + * + * + * def fix_top_level_trace_and_get_trace_func(py_db, frame): # <<<<<<<<<<<<<< + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef str filename; + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.fix_top_level_trace_and_get_trace_func", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_name); + __Pyx_XDECREF(__pyx_v_args); + __Pyx_XDECREF(__pyx_v_thread); + __Pyx_XDECREF(__pyx_v_f_unhandled); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_additional_info); + __Pyx_XDECREF(__pyx_v_top_level_thread_tracer); + __Pyx_XDECREF(__pyx_v_f_trace); + __Pyx_XDECREF(__pyx_v_thread_tracer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1107 + * + * + * def trace_dispatch(py_db, frame, event, arg): # <<<<<<<<<<<<<< + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_13trace_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_13trace_dispatch = {"trace_dispatch", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_13trace_dispatch, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_13trace_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_py_db = 0; + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trace_dispatch (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_py_db,&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[4] = {0,0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_py_db)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 4, 4, 1); __PYX_ERR(0, 1107, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 4, 4, 2); __PYX_ERR(0, 1107, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 4, 4, 3); __PYX_ERR(0, 1107, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trace_dispatch") < 0)) __PYX_ERR(0, 1107, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + } + __pyx_v_py_db = values[0]; + __pyx_v_frame = values[1]; + __pyx_v_event = values[2]; + __pyx_v_arg = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("trace_dispatch", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1107, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12trace_dispatch(__pyx_self, __pyx_v_py_db, __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12trace_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_py_db, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_thread_trace_func = NULL; + PyObject *__pyx_v_apply_to_settrace = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *(*__pyx_t_6)(PyObject *); + int __pyx_t_7; + int __pyx_t_8; + __Pyx_RefNannySetupContext("trace_dispatch", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1108 + * + * def trace_dispatch(py_db, frame, event, arg): + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) # <<<<<<<<<<<<<< + * if thread_trace_func is None: + * return None if event == 'call' else NO_FTRACE + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_fix_top_level_trace_and_get_trac); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_4 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_py_db, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_py_db, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_frame); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1108, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1108, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_5 = __pyx_t_6(__pyx_t_3); if (unlikely(!__pyx_t_5)) goto __pyx_L3_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_3), 2) < 0) __PYX_ERR(0, 1108, __pyx_L1_error) + __pyx_t_6 = NULL; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4_unpacking_done; + __pyx_L3_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 1108, __pyx_L1_error) + __pyx_L4_unpacking_done:; + } + __pyx_v_thread_trace_func = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_v_apply_to_settrace = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1109 + * def trace_dispatch(py_db, frame, event, arg): + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * if apply_to_settrace: + */ + __pyx_t_7 = (__pyx_v_thread_trace_func == Py_None); + __pyx_t_8 = (__pyx_t_7 != 0); + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1110 + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * if apply_to_settrace: + * py_db.enable_tracing(thread_trace_func) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1110, __pyx_L1_error) + if (__pyx_t_8) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1110, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1109 + * def trace_dispatch(py_db, frame, event, arg): + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * if apply_to_settrace: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1111 + * if thread_trace_func is None: + * return None if event == 'call' else NO_FTRACE + * if apply_to_settrace: # <<<<<<<<<<<<<< + * py_db.enable_tracing(thread_trace_func) + * return thread_trace_func(frame, event, arg) + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_apply_to_settrace); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1111, __pyx_L1_error) + if (__pyx_t_8) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1112 + * return None if event == 'call' else NO_FTRACE + * if apply_to_settrace: + * py_db.enable_tracing(thread_trace_func) # <<<<<<<<<<<<<< + * return thread_trace_func(frame, event, arg) + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_enable_tracing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_2, __pyx_v_thread_trace_func) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_thread_trace_func); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1111 + * if thread_trace_func is None: + * return None if event == 'call' else NO_FTRACE + * if apply_to_settrace: # <<<<<<<<<<<<<< + * py_db.enable_tracing(thread_trace_func) + * return thread_trace_func(frame, event, arg) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1113 + * if apply_to_settrace: + * py_db.enable_tracing(thread_trace_func) + * return thread_trace_func(frame, event, arg) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_thread_trace_func); + __pyx_t_5 = __pyx_v_thread_trace_func; __pyx_t_2 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_4 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1113, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 3+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1113, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_3 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_4, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_4, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_4, __pyx_v_arg); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1113, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1107 + * + * + * def trace_dispatch(py_db, frame, event, arg): # <<<<<<<<<<<<<< + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_thread_trace_func); + __Pyx_XDECREF(__pyx_v_apply_to_settrace); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1119 + * cdef class TopLevelThreadTracerOnlyUnhandledExceptions: + * cdef public tuple _args; + * def __init__(self, tuple args): # <<<<<<<<<<<<<< + * self._args = args + * # ELSE + */ + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_args,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1119, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_args = ((PyObject*)values[0]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1119, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_args), (&PyTuple_Type), 1, "args", 1))) __PYX_ERR(0, 1119, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions___init__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self), __pyx_v_args); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, PyObject *__pyx_v_args) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1120 + * cdef public tuple _args; + * def __init__(self, tuple args): + * self._args = args # <<<<<<<<<<<<<< + * # ELSE + * # class TopLevelThreadTracerOnlyUnhandledExceptions(object): + */ + __Pyx_INCREF(__pyx_v_args); + __Pyx_GIVEREF(__pyx_v_args); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = __pyx_v_args; + + /* "_pydevd_bundle/pydevd_cython.pyx":1119 + * cdef class TopLevelThreadTracerOnlyUnhandledExceptions: + * cdef public tuple _args; + * def __init__(self, tuple args): # <<<<<<<<<<<<<< + * self._args = args + * # ELSE + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1128 + * # ENDIF + * + * def trace_unhandled_exceptions(self, frame, event, arg): # <<<<<<<<<<<<<< + * # Note that we ignore the frame as this tracing method should only be put in topmost frames already. + * # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_3trace_unhandled_exceptions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_3trace_unhandled_exceptions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trace_unhandled_exceptions (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_unhandled_exceptions", 1, 3, 3, 1); __PYX_ERR(0, 1128, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_unhandled_exceptions", 1, 3, 3, 2); __PYX_ERR(0, 1128, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trace_unhandled_exceptions") < 0)) __PYX_ERR(0, 1128, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = values[1]; + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("trace_unhandled_exceptions", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1128, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions.trace_unhandled_exceptions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_2trace_unhandled_exceptions(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_2trace_unhandled_exceptions(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_py_db = NULL; + PyObject *__pyx_v_t = NULL; + PyObject *__pyx_v_additional_info = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + __Pyx_RefNannySetupContext("trace_unhandled_exceptions", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1131 + * # Note that we ignore the frame as this tracing method should only be put in topmost frames already. + * # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + * if event == 'exception' and arg is not None: # <<<<<<<<<<<<<< + * py_db, t, additional_info = self._args[0:3] + * if arg is not None: + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_exception, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1131, __pyx_L1_error) + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_arg != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1132 + * # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + * if event == 'exception' and arg is not None: + * py_db, t, additional_info = self._args[0:3] # <<<<<<<<<<<<<< + * if arg is not None: + * if not additional_info.suspended_at_unhandled: + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1132, __pyx_L1_error) + } + __pyx_t_4 = __Pyx_PyTuple_GetSlice(__pyx_v_self->_args, 0, 3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (1) { + PyObject* sequence = __pyx_t_4; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1132, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1132, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_v_py_db = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_v_t = __pyx_t_6; + __pyx_t_6 = 0; + __pyx_v_additional_info = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1133 + * if event == 'exception' and arg is not None: + * py_db, t, additional_info = self._args[0:3] + * if arg is not None: # <<<<<<<<<<<<<< + * if not additional_info.suspended_at_unhandled: + * additional_info.suspended_at_unhandled = True + */ + __pyx_t_1 = (__pyx_v_arg != Py_None); + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1134 + * py_db, t, additional_info = self._args[0:3] + * if arg is not None: + * if not additional_info.suspended_at_unhandled: # <<<<<<<<<<<<<< + * additional_info.suspended_at_unhandled = True + * + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_additional_info, __pyx_n_s_suspended_at_unhandled); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1134, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1134, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = ((!__pyx_t_3) != 0); + if (__pyx_t_1) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1135 + * if arg is not None: + * if not additional_info.suspended_at_unhandled: + * additional_info.suspended_at_unhandled = True # <<<<<<<<<<<<<< + * + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, arg) + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_additional_info, __pyx_n_s_suspended_at_unhandled, Py_True) < 0) __PYX_ERR(0, 1135, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1137 + * additional_info.suspended_at_unhandled = True + * + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, arg) # <<<<<<<<<<<<<< + * + * # No need to reset frame.f_trace to keep the same trace function. + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_stop_on_unhandled_exception); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = NULL; + __pyx_t_8 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_8 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_arg}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_arg}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_5 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_t); + __Pyx_GIVEREF(__pyx_v_t); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_v_t); + __Pyx_INCREF(__pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_v_additional_info); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_8, __pyx_v_additional_info); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_8, __pyx_v_arg); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1137, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1134 + * py_db, t, additional_info = self._args[0:3] + * if arg is not None: + * if not additional_info.suspended_at_unhandled: # <<<<<<<<<<<<<< + * additional_info.suspended_at_unhandled = True + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1133 + * if event == 'exception' and arg is not None: + * py_db, t, additional_info = self._args[0:3] + * if arg is not None: # <<<<<<<<<<<<<< + * if not additional_info.suspended_at_unhandled: + * additional_info.suspended_at_unhandled = True + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1131 + * # Note that we ignore the frame as this tracing method should only be put in topmost frames already. + * # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + * if event == 'exception' and arg is not None: # <<<<<<<<<<<<<< + * py_db, t, additional_info = self._args[0:3] + * if arg is not None: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1140 + * + * # No need to reset frame.f_trace to keep the same trace function. + * return self.trace_unhandled_exceptions # <<<<<<<<<<<<<< + * + * def get_trace_dispatch_func(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_unhandled_exceptions); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1140, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1128 + * # ENDIF + * + * def trace_unhandled_exceptions(self, frame, event, arg): # <<<<<<<<<<<<<< + * # Note that we ignore the frame as this tracing method should only be put in topmost frames already. + * # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions.trace_unhandled_exceptions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_py_db); + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_additional_info); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1142 + * return self.trace_unhandled_exceptions + * + * def get_trace_dispatch_func(self): # <<<<<<<<<<<<<< + * return self.trace_unhandled_exceptions + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5get_trace_dispatch_func(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5get_trace_dispatch_func(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_trace_dispatch_func (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_4get_trace_dispatch_func(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_4get_trace_dispatch_func(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("get_trace_dispatch_func", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1143 + * + * def get_trace_dispatch_func(self): + * return self.trace_unhandled_exceptions # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_unhandled_exceptions); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1142 + * return self.trace_unhandled_exceptions + * + * def get_trace_dispatch_func(self): # <<<<<<<<<<<<<< + * return self.trace_unhandled_exceptions + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions.get_trace_dispatch_func", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1118 + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class TopLevelThreadTracerOnlyUnhandledExceptions: + * cdef public tuple _args; # <<<<<<<<<<<<<< + * def __init__(self, tuple args): + * self._args = args + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_args); + __pyx_r = __pyx_v_self->_args; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyTuple_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 1118, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions._args.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_6__reduce_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self._args,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->_args); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self._args,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":7 + * state = (self._args,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self._args is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self._args,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self._args is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, None), state + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->_args != ((PyObject*)Py_None)); + __pyx_v_use_setstate = __pyx_t_3; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, None), state + * else: + */ + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":13 + * use_setstate = self._args is not None + * if use_setstate: + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_TopLevelThreadTra); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_64458794); + __Pyx_GIVEREF(__pyx_int_64458794); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_64458794); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, None), state + * else: + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_TopLevelThreadTra); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_64458794); + __Pyx_GIVEREF(__pyx_int_64458794); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_64458794); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_8__setstate_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, (type(self), 0x3d7902a, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1154 + * cdef public set _raise_lines; + * cdef public int _last_raise_line; + * def __init__(self, frame_trace_dispatch, tuple args): # <<<<<<<<<<<<<< + * self._frame_trace_dispatch = frame_trace_dispatch + * self._args = args + */ + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame_trace_dispatch = 0; + PyObject *__pyx_v_args = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame_trace_dispatch,&__pyx_n_s_args,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame_trace_dispatch)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 1154, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1154, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_frame_trace_dispatch = values[0]; + __pyx_v_args = ((PyObject*)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1154, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_args), (&PyTuple_Type), 1, "args", 1))) __PYX_ERR(0, 1154, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame___init__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), __pyx_v_frame_trace_dispatch, __pyx_v_args); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_frame_trace_dispatch, PyObject *__pyx_v_args) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1155 + * cdef public int _last_raise_line; + * def __init__(self, frame_trace_dispatch, tuple args): + * self._frame_trace_dispatch = frame_trace_dispatch # <<<<<<<<<<<<<< + * self._args = args + * self._try_except_info = None + */ + __Pyx_INCREF(__pyx_v_frame_trace_dispatch); + __Pyx_GIVEREF(__pyx_v_frame_trace_dispatch); + __Pyx_GOTREF(__pyx_v_self->_frame_trace_dispatch); + __Pyx_DECREF(__pyx_v_self->_frame_trace_dispatch); + __pyx_v_self->_frame_trace_dispatch = __pyx_v_frame_trace_dispatch; + + /* "_pydevd_bundle/pydevd_cython.pyx":1156 + * def __init__(self, frame_trace_dispatch, tuple args): + * self._frame_trace_dispatch = frame_trace_dispatch + * self._args = args # <<<<<<<<<<<<<< + * self._try_except_info = None + * self._last_exc_arg = None + */ + __Pyx_INCREF(__pyx_v_args); + __Pyx_GIVEREF(__pyx_v_args); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = __pyx_v_args; + + /* "_pydevd_bundle/pydevd_cython.pyx":1157 + * self._frame_trace_dispatch = frame_trace_dispatch + * self._args = args + * self._try_except_info = None # <<<<<<<<<<<<<< + * self._last_exc_arg = None + * self._raise_lines = set() + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_try_except_info); + __Pyx_DECREF(__pyx_v_self->_try_except_info); + __pyx_v_self->_try_except_info = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":1158 + * self._args = args + * self._try_except_info = None + * self._last_exc_arg = None # <<<<<<<<<<<<<< + * self._raise_lines = set() + * self._last_raise_line = -1 + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_last_exc_arg); + __Pyx_DECREF(__pyx_v_self->_last_exc_arg); + __pyx_v_self->_last_exc_arg = Py_None; + + /* "_pydevd_bundle/pydevd_cython.pyx":1159 + * self._try_except_info = None + * self._last_exc_arg = None + * self._raise_lines = set() # <<<<<<<<<<<<<< + * self._last_raise_line = -1 + * # ELSE + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_raise_lines); + __Pyx_DECREF(__pyx_v_self->_raise_lines); + __pyx_v_self->_raise_lines = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1160 + * self._last_exc_arg = None + * self._raise_lines = set() + * self._last_raise_line = -1 # <<<<<<<<<<<<<< + * # ELSE + * # class TopLevelThreadTracerNoBackFrame(object): + */ + __pyx_v_self->_last_raise_line = -1; + + /* "_pydevd_bundle/pydevd_cython.pyx":1154 + * cdef public set _raise_lines; + * cdef public int _last_raise_line; + * def __init__(self, frame_trace_dispatch, tuple args): # <<<<<<<<<<<<<< + * self._frame_trace_dispatch = frame_trace_dispatch + * self._args = args + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1184 + * # ENDIF + * + * def trace_dispatch_and_unhandled_exceptions(self, frame, event, arg): # <<<<<<<<<<<<<< + * # DEBUG = 'code_to_debug' in frame.f_code.co_filename + * # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_3trace_dispatch_and_unhandled_exceptions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_3trace_dispatch_and_unhandled_exceptions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trace_dispatch_and_unhandled_exceptions (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch_and_unhandled_exceptions", 1, 3, 3, 1); __PYX_ERR(0, 1184, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("trace_dispatch_and_unhandled_exceptions", 1, 3, 3, 2); __PYX_ERR(0, 1184, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "trace_dispatch_and_unhandled_exceptions") < 0)) __PYX_ERR(0, 1184, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = values[1]; + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("trace_dispatch_and_unhandled_exceptions", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1184, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.trace_dispatch_and_unhandled_exceptions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_2trace_dispatch_and_unhandled_exceptions(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_2trace_dispatch_and_unhandled_exceptions(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_frame_trace_dispatch = NULL; + PyObject *__pyx_v_py_db = NULL; + PyObject *__pyx_v_t = NULL; + PyObject *__pyx_v_additional_info = NULL; + PyObject *__pyx_v_valid_try_except_infos = NULL; + PyObject *__pyx_v_try_except_info = NULL; + PyObject *__pyx_v_ret = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + char const *__pyx_t_14; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + __Pyx_RefNannySetupContext("trace_dispatch_and_unhandled_exceptions", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1187 + * # DEBUG = 'code_to_debug' in frame.f_code.co_filename + * # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + * frame_trace_dispatch = self._frame_trace_dispatch # <<<<<<<<<<<<<< + * if frame_trace_dispatch is not None: + * self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + */ + __pyx_t_1 = __pyx_v_self->_frame_trace_dispatch; + __Pyx_INCREF(__pyx_t_1); + __pyx_v_frame_trace_dispatch = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1188 + * # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + * frame_trace_dispatch = self._frame_trace_dispatch + * if frame_trace_dispatch is not None: # <<<<<<<<<<<<<< + * self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + * + */ + __pyx_t_2 = (__pyx_v_frame_trace_dispatch != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1189 + * frame_trace_dispatch = self._frame_trace_dispatch + * if frame_trace_dispatch is not None: + * self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) # <<<<<<<<<<<<<< + * + * if event == 'exception': + */ + __Pyx_INCREF(__pyx_v_frame_trace_dispatch); + __pyx_t_4 = __pyx_v_frame_trace_dispatch; __pyx_t_5 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_arg); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_frame_trace_dispatch); + __Pyx_DECREF(__pyx_v_self->_frame_trace_dispatch); + __pyx_v_self->_frame_trace_dispatch = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1188 + * # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + * frame_trace_dispatch = self._frame_trace_dispatch + * if frame_trace_dispatch is not None: # <<<<<<<<<<<<<< + * self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1191 + * self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + * + * if event == 'exception': # <<<<<<<<<<<<<< + * self._last_exc_arg = arg + * self._raise_lines.add(frame.f_lineno) + */ + __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_exception, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1191, __pyx_L1_error) + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1192 + * + * if event == 'exception': + * self._last_exc_arg = arg # <<<<<<<<<<<<<< + * self._raise_lines.add(frame.f_lineno) + * self._last_raise_line = frame.f_lineno + */ + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + __Pyx_GOTREF(__pyx_v_self->_last_exc_arg); + __Pyx_DECREF(__pyx_v_self->_last_exc_arg); + __pyx_v_self->_last_exc_arg = __pyx_v_arg; + + /* "_pydevd_bundle/pydevd_cython.pyx":1193 + * if event == 'exception': + * self._last_exc_arg = arg + * self._raise_lines.add(frame.f_lineno) # <<<<<<<<<<<<<< + * self._last_raise_line = frame.f_lineno + * + */ + if (unlikely(__pyx_v_self->_raise_lines == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "add"); + __PYX_ERR(0, 1193, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PySet_Add(__pyx_v_self->_raise_lines, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1193, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1194 + * self._last_exc_arg = arg + * self._raise_lines.add(frame.f_lineno) + * self._last_raise_line = frame.f_lineno # <<<<<<<<<<<<<< + * + * elif event == 'return' and self._last_exc_arg is not None: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1194, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->_last_raise_line = __pyx_t_6; + + /* "_pydevd_bundle/pydevd_cython.pyx":1191 + * self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + * + * if event == 'exception': # <<<<<<<<<<<<<< + * self._last_exc_arg = arg + * self._raise_lines.add(frame.f_lineno) + */ + goto __pyx_L4; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1196 + * self._last_raise_line = frame.f_lineno + * + * elif event == 'return' and self._last_exc_arg is not None: # <<<<<<<<<<<<<< + * # For unhandled exceptions we actually track the return when at the topmost level. + * try: + */ + __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_return, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1196, __pyx_L1_error) + if (__pyx_t_2) { + } else { + __pyx_t_3 = __pyx_t_2; + goto __pyx_L5_bool_binop_done; + } + __pyx_t_2 = (__pyx_v_self->_last_exc_arg != Py_None); + __pyx_t_9 = (__pyx_t_2 != 0); + __pyx_t_3 = __pyx_t_9; + __pyx_L5_bool_binop_done:; + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1198 + * elif event == 'return' and self._last_exc_arg is not None: + * # For unhandled exceptions we actually track the return when at the topmost level. + * try: # <<<<<<<<<<<<<< + * py_db, t, additional_info = self._args[0:3] + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + */ + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":1199 + * # For unhandled exceptions we actually track the return when at the topmost level. + * try: + * py_db, t, additional_info = self._args[0:3] # <<<<<<<<<<<<<< + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + * if frame.f_lineno in self._raise_lines: + */ + if (unlikely(__pyx_v_self->_args == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1199, __pyx_L8_error) + } + __pyx_t_1 = __Pyx_PyTuple_GetSlice(__pyx_v_self->_args, 0, 3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1199, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + if (1) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1199, __pyx_L8_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1199, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1199, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1199, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_v_py_db = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_v_t = __pyx_t_7; + __pyx_t_7 = 0; + __pyx_v_additional_info = __pyx_t_5; + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1200 + * try: + * py_db, t, additional_info = self._args[0:3] + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. # <<<<<<<<<<<<<< + * if frame.f_lineno in self._raise_lines: + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_additional_info, __pyx_n_s_suspended_at_unhandled); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1200, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1200, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_9 = ((!__pyx_t_3) != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1201 + * py_db, t, additional_info = self._args[0:3] + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + * if frame.f_lineno in self._raise_lines: # <<<<<<<<<<<<<< + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + * + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1201, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(__pyx_v_self->_raise_lines == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + __PYX_ERR(0, 1201, __pyx_L8_error) + } + __pyx_t_9 = (__Pyx_PySet_ContainsTF(__pyx_t_1, __pyx_v_self->_raise_lines, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1201, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (__pyx_t_9 != 0); + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1202 + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + * if frame.f_lineno in self._raise_lines: + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) # <<<<<<<<<<<<<< + * + * else: + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_stop_on_unhandled_exception); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1202, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1202, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1202, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1202, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_t); + __Pyx_GIVEREF(__pyx_v_t); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_v_t); + __Pyx_INCREF(__pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_v_additional_info); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_6, __pyx_v_additional_info); + __Pyx_INCREF(__pyx_v_self->_last_exc_arg); + __Pyx_GIVEREF(__pyx_v_self->_last_exc_arg); + PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_6, __pyx_v_self->_last_exc_arg); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1202, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1201 + * py_db, t, additional_info = self._args[0:3] + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + * if frame.f_lineno in self._raise_lines: # <<<<<<<<<<<<<< + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + * + */ + goto __pyx_L11; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1205 + * + * else: + * if self._try_except_info is None: # <<<<<<<<<<<<<< + * self._try_except_info = py_db.collect_try_except_info(frame.f_code) + * if not self._try_except_info: + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->_try_except_info == Py_None); + __pyx_t_9 = (__pyx_t_3 != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1206 + * else: + * if self._try_except_info is None: + * self._try_except_info = py_db.collect_try_except_info(frame.f_code) # <<<<<<<<<<<<<< + * if not self._try_except_info: + * # Consider the last exception as unhandled because there's no try..except in it. + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_collect_try_except_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1206, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1206, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1206, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_try_except_info); + __Pyx_DECREF(__pyx_v_self->_try_except_info); + __pyx_v_self->_try_except_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1205 + * + * else: + * if self._try_except_info is None: # <<<<<<<<<<<<<< + * self._try_except_info = py_db.collect_try_except_info(frame.f_code) + * if not self._try_except_info: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1207 + * if self._try_except_info is None: + * self._try_except_info = py_db.collect_try_except_info(frame.f_code) + * if not self._try_except_info: # <<<<<<<<<<<<<< + * # Consider the last exception as unhandled because there's no try..except in it. + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_self->_try_except_info); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1207, __pyx_L8_error) + __pyx_t_3 = ((!__pyx_t_9) != 0); + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1209 + * if not self._try_except_info: + * # Consider the last exception as unhandled because there's no try..except in it. + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) # <<<<<<<<<<<<<< + * else: + * # Now, consider only the try..except for the raise + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_stop_on_unhandled_exception); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1209, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1209, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[5] = {__pyx_t_4, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1209, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_7 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1209, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_t); + __Pyx_GIVEREF(__pyx_v_t); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_t); + __Pyx_INCREF(__pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_v_additional_info); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_additional_info); + __Pyx_INCREF(__pyx_v_self->_last_exc_arg); + __Pyx_GIVEREF(__pyx_v_self->_last_exc_arg); + PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_v_self->_last_exc_arg); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1209, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1207 + * if self._try_except_info is None: + * self._try_except_info = py_db.collect_try_except_info(frame.f_code) + * if not self._try_except_info: # <<<<<<<<<<<<<< + * # Consider the last exception as unhandled because there's no try..except in it. + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + */ + goto __pyx_L13; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1212 + * else: + * # Now, consider only the try..except for the raise + * valid_try_except_infos = [] # <<<<<<<<<<<<<< + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_try_block(self._last_raise_line): + */ + /*else*/ { + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1212, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_valid_try_except_infos = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1213 + * # Now, consider only the try..except for the raise + * valid_try_except_infos = [] + * for try_except_info in self._try_except_info: # <<<<<<<<<<<<<< + * if try_except_info.is_line_in_try_block(self._last_raise_line): + * valid_try_except_infos.append(try_except_info) + */ + if (likely(PyList_CheckExact(__pyx_v_self->_try_except_info)) || PyTuple_CheckExact(__pyx_v_self->_try_except_info)) { + __pyx_t_1 = __pyx_v_self->_try_except_info; __Pyx_INCREF(__pyx_t_1); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->_try_except_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1213, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1213, __pyx_L8_error) + } + for (;;) { + if (likely(!__pyx_t_11)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1213, __pyx_L8_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1213, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1213, __pyx_L8_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1213, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_11(__pyx_t_1); + if (unlikely(!__pyx_t_5)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1213, __pyx_L8_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF_SET(__pyx_v_try_except_info, __pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1214 + * valid_try_except_infos = [] + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_try_block(self._last_raise_line): # <<<<<<<<<<<<<< + * valid_try_except_infos.append(try_except_info) + * + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_try_except_info, __pyx_n_s_is_line_in_try_block); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1214, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->_last_raise_line); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1214, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_5 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_12, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1214, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1214, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1215 + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_try_block(self._last_raise_line): + * valid_try_except_infos.append(try_except_info) # <<<<<<<<<<<<<< + * + * if not valid_try_except_infos: + */ + __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_valid_try_except_infos, __pyx_v_try_except_info); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1215, __pyx_L8_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1214 + * valid_try_except_infos = [] + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_try_block(self._last_raise_line): # <<<<<<<<<<<<<< + * valid_try_except_infos.append(try_except_info) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1213 + * # Now, consider only the try..except for the raise + * valid_try_except_infos = [] + * for try_except_info in self._try_except_info: # <<<<<<<<<<<<<< + * if try_except_info.is_line_in_try_block(self._last_raise_line): + * valid_try_except_infos.append(try_except_info) + */ + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1217 + * valid_try_except_infos.append(try_except_info) + * + * if not valid_try_except_infos: # <<<<<<<<<<<<<< + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + * + */ + __pyx_t_3 = (PyList_GET_SIZE(__pyx_v_valid_try_except_infos) != 0); + __pyx_t_9 = ((!__pyx_t_3) != 0); + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1218 + * + * if not valid_try_except_infos: + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) # <<<<<<<<<<<<<< + * + * else: + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_stop_on_unhandled_exception); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1218, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[5] = {__pyx_t_7, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_4 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1218, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_7) { + __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7); __pyx_t_7 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_t); + __Pyx_GIVEREF(__pyx_v_t); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, __pyx_v_t); + __Pyx_INCREF(__pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_v_additional_info); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_6, __pyx_v_additional_info); + __Pyx_INCREF(__pyx_v_self->_last_exc_arg); + __Pyx_GIVEREF(__pyx_v_self->_last_exc_arg); + PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_6, __pyx_v_self->_last_exc_arg); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1218, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1217 + * valid_try_except_infos.append(try_except_info) + * + * if not valid_try_except_infos: # <<<<<<<<<<<<<< + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + * + */ + goto __pyx_L17; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1225 + * # where one try..except is inside the other with only a raise + * # and it's gotten in the except line. + * for try_except_info in self._try_except_info: # <<<<<<<<<<<<<< + * if try_except_info.is_line_in_except_block(frame.f_lineno): + * if ( + */ + /*else*/ { + if (likely(PyList_CheckExact(__pyx_v_self->_try_except_info)) || PyTuple_CheckExact(__pyx_v_self->_try_except_info)) { + __pyx_t_1 = __pyx_v_self->_try_except_info; __Pyx_INCREF(__pyx_t_1); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->_try_except_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1225, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1225, __pyx_L8_error) + } + for (;;) { + if (likely(!__pyx_t_11)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1225, __pyx_L8_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1225, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } else { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1225, __pyx_L8_error) + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1225, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + #endif + } + } else { + __pyx_t_5 = __pyx_t_11(__pyx_t_1); + if (unlikely(!__pyx_t_5)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 1225, __pyx_L8_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF_SET(__pyx_v_try_except_info, __pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1226 + * # and it's gotten in the except line. + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_except_block(frame.f_lineno): # <<<<<<<<<<<<<< + * if ( + * frame.f_lineno == try_except_info.except_line or + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_try_except_info, __pyx_n_s_is_line_in_except_block); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1226, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1226, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_5 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_12, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1226, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 1226, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1228 + * if try_except_info.is_line_in_except_block(frame.f_lineno): + * if ( + * frame.f_lineno == try_except_info.except_line or # <<<<<<<<<<<<<< + * frame.f_lineno in try_except_info.raise_lines_in_except + * ): + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1228, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_try_except_info, __pyx_n_s_except_line); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1228, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1228, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1228, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (!__pyx_t_3) { + } else { + __pyx_t_9 = __pyx_t_3; + goto __pyx_L22_bool_binop_done; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1229 + * if ( + * frame.f_lineno == try_except_info.except_line or + * frame.f_lineno in try_except_info.raise_lines_in_except # <<<<<<<<<<<<<< + * ): + * # In a raise inside a try..except block or some except which doesn't + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_lineno); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1229, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_try_except_info, __pyx_n_s_raise_lines_in_except); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1229, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_t_7, __pyx_t_4, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1229, __pyx_L8_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = (__pyx_t_3 != 0); + __pyx_t_9 = __pyx_t_2; + __pyx_L22_bool_binop_done:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1227 + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_except_block(frame.f_lineno): + * if ( # <<<<<<<<<<<<<< + * frame.f_lineno == try_except_info.except_line or + * frame.f_lineno in try_except_info.raise_lines_in_except + */ + if (__pyx_t_9) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1233 + * # In a raise inside a try..except block or some except which doesn't + * # match the raised exception. + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) # <<<<<<<<<<<<<< + * break + * else: + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_stop_on_unhandled_exception); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1233, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[5] = {__pyx_t_5, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1233, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) { + PyObject *__pyx_temp[5] = {__pyx_t_5, __pyx_v_py_db, __pyx_v_t, __pyx_v_additional_info, __pyx_v_self->_last_exc_arg}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1233, __pyx_L8_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_12 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1233, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_6, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_t); + __Pyx_GIVEREF(__pyx_v_t); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_6, __pyx_v_t); + __Pyx_INCREF(__pyx_v_additional_info); + __Pyx_GIVEREF(__pyx_v_additional_info); + PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_6, __pyx_v_additional_info); + __Pyx_INCREF(__pyx_v_self->_last_exc_arg); + __Pyx_GIVEREF(__pyx_v_self->_last_exc_arg); + PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_6, __pyx_v_self->_last_exc_arg); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_12, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1233, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1234 + * # match the raised exception. + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + * break # <<<<<<<<<<<<<< + * else: + * break # exited during the except block (no exception raised) + */ + goto __pyx_L19_break; + + /* "_pydevd_bundle/pydevd_cython.pyx":1227 + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_except_block(frame.f_lineno): + * if ( # <<<<<<<<<<<<<< + * frame.f_lineno == try_except_info.except_line or + * frame.f_lineno in try_except_info.raise_lines_in_except + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1236 + * break + * else: + * break # exited during the except block (no exception raised) # <<<<<<<<<<<<<< + * finally: + * # Remove reference to exception after handling it. + */ + /*else*/ { + goto __pyx_L19_break; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1226 + * # and it's gotten in the except line. + * for try_except_info in self._try_except_info: + * if try_except_info.is_line_in_except_block(frame.f_lineno): # <<<<<<<<<<<<<< + * if ( + * frame.f_lineno == try_except_info.except_line or + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1225 + * # where one try..except is inside the other with only a raise + * # and it's gotten in the except line. + * for try_except_info in self._try_except_info: # <<<<<<<<<<<<<< + * if try_except_info.is_line_in_except_block(frame.f_lineno): + * if ( + */ + } + __pyx_L19_break:; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_L17:; + } + __pyx_L13:; + } + __pyx_L11:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1200 + * try: + * py_db, t, additional_info = self._args[0:3] + * if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. # <<<<<<<<<<<<<< + * if frame.f_lineno in self._raise_lines: + * py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + */ + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1239 + * finally: + * # Remove reference to exception after handling it. + * self._last_exc_arg = None # <<<<<<<<<<<<<< + * + * ret = self.trace_dispatch_and_unhandled_exceptions + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_last_exc_arg); + __Pyx_DECREF(__pyx_v_self->_last_exc_arg); + __pyx_v_self->_last_exc_arg = Py_None; + goto __pyx_L9; + } + __pyx_L8_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_20); + __pyx_t_6 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename; + { + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_last_exc_arg); + __Pyx_DECREF(__pyx_v_self->_last_exc_arg); + __pyx_v_self->_last_exc_arg = Py_None; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20); + } + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17); + __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; + __pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14; + goto __pyx_L1_error; + } + __pyx_L9:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1196 + * self._last_raise_line = frame.f_lineno + * + * elif event == 'return' and self._last_exc_arg is not None: # <<<<<<<<<<<<<< + * # For unhandled exceptions we actually track the return when at the topmost level. + * try: + */ + } + __pyx_L4:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1241 + * self._last_exc_arg = None + * + * ret = self.trace_dispatch_and_unhandled_exceptions # <<<<<<<<<<<<<< + * + * # Need to reset (the call to _frame_trace_dispatch may have changed it). + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch_and_unhandled_exc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1241, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1245 + * # Need to reset (the call to _frame_trace_dispatch may have changed it). + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * frame.f_trace = SafeCallWrapper(ret) # <<<<<<<<<<<<<< + * # ELSE + * # frame.f_trace = ret + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), __pyx_v_ret); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1245, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_1) < 0) __PYX_ERR(0, 1245, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1249 + * # frame.f_trace = ret + * # ENDIF + * return ret # <<<<<<<<<<<<<< + * + * def get_trace_dispatch_func(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_ret); + __pyx_r = __pyx_v_ret; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1184 + * # ENDIF + * + * def trace_dispatch_and_unhandled_exceptions(self, frame, event, arg): # <<<<<<<<<<<<<< + * # DEBUG = 'code_to_debug' in frame.f_code.co_filename + * # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.trace_dispatch_and_unhandled_exceptions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_frame_trace_dispatch); + __Pyx_XDECREF(__pyx_v_py_db); + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_additional_info); + __Pyx_XDECREF(__pyx_v_valid_try_except_infos); + __Pyx_XDECREF(__pyx_v_try_except_info); + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1251 + * return ret + * + * def get_trace_dispatch_func(self): # <<<<<<<<<<<<<< + * return self.trace_dispatch_and_unhandled_exceptions + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5get_trace_dispatch_func(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5get_trace_dispatch_func(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_trace_dispatch_func (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_4get_trace_dispatch_func(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_4get_trace_dispatch_func(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("get_trace_dispatch_func", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1252 + * + * def get_trace_dispatch_func(self): + * return self.trace_dispatch_and_unhandled_exceptions # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_trace_dispatch_and_unhandled_exc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1252, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1251 + * return ret + * + * def get_trace_dispatch_func(self): # <<<<<<<<<<<<<< + * return self.trace_dispatch_and_unhandled_exceptions + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.get_trace_dispatch_func", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1148 + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class TopLevelThreadTracerNoBackFrame: + * cdef public object _frame_trace_dispatch; # <<<<<<<<<<<<<< + * cdef public tuple _args; + * cdef public object _try_except_info; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_frame_trace_dispatch); + __pyx_r = __pyx_v_self->_frame_trace_dispatch; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->_frame_trace_dispatch); + __Pyx_DECREF(__pyx_v_self->_frame_trace_dispatch); + __pyx_v_self->_frame_trace_dispatch = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_frame_trace_dispatch); + __Pyx_DECREF(__pyx_v_self->_frame_trace_dispatch); + __pyx_v_self->_frame_trace_dispatch = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1149 + * cdef class TopLevelThreadTracerNoBackFrame: + * cdef public object _frame_trace_dispatch; + * cdef public tuple _args; # <<<<<<<<<<<<<< + * cdef public object _try_except_info; + * cdef public object _last_exc_arg; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_args); + __pyx_r = __pyx_v_self->_args; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyTuple_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 1149, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame._args.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1150 + * cdef public object _frame_trace_dispatch; + * cdef public tuple _args; + * cdef public object _try_except_info; # <<<<<<<<<<<<<< + * cdef public object _last_exc_arg; + * cdef public set _raise_lines; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_try_except_info); + __pyx_r = __pyx_v_self->_try_except_info; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->_try_except_info); + __Pyx_DECREF(__pyx_v_self->_try_except_info); + __pyx_v_self->_try_except_info = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_try_except_info); + __Pyx_DECREF(__pyx_v_self->_try_except_info); + __pyx_v_self->_try_except_info = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1151 + * cdef public tuple _args; + * cdef public object _try_except_info; + * cdef public object _last_exc_arg; # <<<<<<<<<<<<<< + * cdef public set _raise_lines; + * cdef public int _last_raise_line; + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_last_exc_arg); + __pyx_r = __pyx_v_self->_last_exc_arg; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->_last_exc_arg); + __Pyx_DECREF(__pyx_v_self->_last_exc_arg); + __pyx_v_self->_last_exc_arg = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_last_exc_arg); + __Pyx_DECREF(__pyx_v_self->_last_exc_arg); + __pyx_v_self->_last_exc_arg = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1152 + * cdef public object _try_except_info; + * cdef public object _last_exc_arg; + * cdef public set _raise_lines; # <<<<<<<<<<<<<< + * cdef public int _last_raise_line; + * def __init__(self, frame_trace_dispatch, tuple args): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_raise_lines); + __pyx_r = __pyx_v_self->_raise_lines; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PySet_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "set", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 1152, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_raise_lines); + __Pyx_DECREF(__pyx_v_self->_raise_lines); + __pyx_v_self->_raise_lines = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame._raise_lines.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_raise_lines); + __Pyx_DECREF(__pyx_v_self->_raise_lines); + __pyx_v_self->_raise_lines = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1153 + * cdef public object _last_exc_arg; + * cdef public set _raise_lines; + * cdef public int _last_raise_line; # <<<<<<<<<<<<<< + * def __init__(self, frame_trace_dispatch, tuple args): + * self._frame_trace_dispatch = frame_trace_dispatch + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_last_raise_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1153, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame._last_raise_line.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1153, __pyx_L1_error) + __pyx_v_self->_last_raise_line = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame._last_raise_line.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_7__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_6__reduce_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_6__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self._args, self._frame_trace_dispatch, self._last_exc_arg, self._last_raise_line, self._raise_lines, self._try_except_info) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_last_raise_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self->_args); + __Pyx_INCREF(__pyx_v_self->_frame_trace_dispatch); + __Pyx_GIVEREF(__pyx_v_self->_frame_trace_dispatch); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->_frame_trace_dispatch); + __Pyx_INCREF(__pyx_v_self->_last_exc_arg); + __Pyx_GIVEREF(__pyx_v_self->_last_exc_arg); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_self->_last_exc_arg); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_1); + __Pyx_INCREF(__pyx_v_self->_raise_lines); + __Pyx_GIVEREF(__pyx_v_self->_raise_lines); + PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_v_self->_raise_lines); + __Pyx_INCREF(__pyx_v_self->_try_except_info); + __Pyx_GIVEREF(__pyx_v_self->_try_except_info); + PyTuple_SET_ITEM(__pyx_t_2, 5, __pyx_v_self->_try_except_info); + __pyx_t_1 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self._args, self._frame_trace_dispatch, self._last_exc_arg, self._last_raise_line, self._raise_lines, self._try_except_info) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v__dict = __pyx_t_2; + __pyx_t_2 = 0; + + /* "(tree fragment)":7 + * state = (self._args, self._frame_trace_dispatch, self._last_exc_arg, self._last_raise_line, self._raise_lines, self._try_except_info) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_3 = (__pyx_v__dict != Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + if (__pyx_t_4) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict); + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self._args is not None or self._frame_trace_dispatch is not None or self._last_exc_arg is not None or self._raise_lines is not None or self._try_except_info is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self._args, self._frame_trace_dispatch, self._last_exc_arg, self._last_raise_line, self._raise_lines, self._try_except_info) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self._args is not None or self._frame_trace_dispatch is not None or self._last_exc_arg is not None or self._raise_lines is not None or self._try_except_info is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, None), state + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->_args != ((PyObject*)Py_None)); + __pyx_t_5 = (__pyx_t_3 != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_4 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = (__pyx_v_self->_frame_trace_dispatch != Py_None); + __pyx_t_3 = (__pyx_t_5 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_4 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = (__pyx_v_self->_last_exc_arg != Py_None); + __pyx_t_5 = (__pyx_t_3 != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_4 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = (__pyx_v_self->_raise_lines != ((PyObject*)Py_None)); + __pyx_t_3 = (__pyx_t_5 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_4 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = (__pyx_v_self->_try_except_info != Py_None); + __pyx_t_5 = (__pyx_t_3 != 0); + __pyx_t_4 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + __pyx_v_use_setstate = __pyx_t_4; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None or self._frame_trace_dispatch is not None or self._last_exc_arg is not None or self._raise_lines is not None or self._try_except_info is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, None), state + * else: + */ + __pyx_t_4 = (__pyx_v_use_setstate != 0); + if (__pyx_t_4) { + + /* "(tree fragment)":13 + * use_setstate = self._args is not None or self._frame_trace_dispatch is not None or self._last_exc_arg is not None or self._raise_lines is not None or self._try_except_info is not None + * if use_setstate: + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_TopLevelThreadTra_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_255117134); + __Pyx_GIVEREF(__pyx_int_255117134); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_255117134); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None); + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_state); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None or self._frame_trace_dispatch is not None or self._last_exc_arg is not None or self._raise_lines is not None or self._try_except_info is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, None), state + * else: + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pyx_unpickle_TopLevelThreadTra_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_255117134); + __Pyx_GIVEREF(__pyx_int_255117134); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_255117134); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __pyx_t_6 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_9__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_8__setstate_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_8__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_TopLevelThreadTracerNoBackFrame, (type(self), 0xf34c74e, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1258 + * cdef class ThreadTracer: + * cdef public tuple _args; + * def __init__(self, tuple args): # <<<<<<<<<<<<<< + * self._args = args + * # ELSE + */ + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_args = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_args,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_args)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1258, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_args = ((PyObject*)values[0]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1258, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_args), (&PyTuple_Type), 1, "args", 1))) __PYX_ERR(0, 1258, __pyx_L1_error) + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer___init__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self), __pyx_v_args); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer___init__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v_args) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1259 + * cdef public tuple _args; + * def __init__(self, tuple args): + * self._args = args # <<<<<<<<<<<<<< + * # ELSE + * # class ThreadTracer(object): + */ + __Pyx_INCREF(__pyx_v_args); + __Pyx_GIVEREF(__pyx_v_args); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = __pyx_v_args; + + /* "_pydevd_bundle/pydevd_cython.pyx":1258 + * cdef class ThreadTracer: + * cdef public tuple _args; + * def __init__(self, tuple args): # <<<<<<<<<<<<<< + * self._args = args + * # ELSE + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1267 + * # ENDIF + * + * def __call__(self, frame, event, arg): # <<<<<<<<<<<<<< + * ''' This is the callback used when we enter some context in the debugger. + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__[] = " This is the callback used when we enter some context in the debugger.\n\n We also decorate the thread we are in with info about the debugging.\n The attributes added are:\n pydev_state\n pydev_step_stop\n pydev_step_cmd\n pydev_notify_kill\n\n :param PyDB py_db:\n This is the global debugger (this method should actually be added as a method to it).\n "; +#if CYTHON_COMPILING_IN_CPYTHON +struct wrapperbase __pyx_wrapperbase_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__; +#endif +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 3, 3, 1); __PYX_ERR(0, 1267, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 3, 3, 2); __PYX_ERR(0, 1267, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) __PYX_ERR(0, 1267, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = values[1]; + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1267, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self), __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_v_filename = 0; + int __pyx_v_pydev_step_cmd; + PyObject *__pyx_v_frame_cache_key = 0; + PyObject *__pyx_v_cache_skips = 0; + int __pyx_v_is_stepping; + PyObject *__pyx_v_abs_path_real_path_and_base = 0; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_additional_info = 0; + PyObject *__pyx_v_py_db = NULL; + PyObject *__pyx_v_t = NULL; + PyObject *__pyx_v_frame_skips_cache = NULL; + PyObject *__pyx_v_back_frame = NULL; + PyObject *__pyx_v_back_frame_cache_key = NULL; + PyObject *__pyx_v_file_type = NULL; + PyObject *__pyx_v_ret = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + __Pyx_RefNannySetupContext("__call__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1293 + * # DEBUG = 'code_to_debug' in frame.f_code.co_filename + * # if DEBUG: print('ENTER: trace_dispatch: %s %s %s %s' % (frame.f_code.co_filename, frame.f_lineno, event, frame.f_code.co_name)) + * py_db, t, additional_info, cache_skips, frame_skips_cache = self._args # <<<<<<<<<<<<<< + * pydev_step_cmd = additional_info.pydev_step_cmd + * is_stepping = pydev_step_cmd != -1 + */ + __pyx_t_1 = __pyx_v_self->_args; + __Pyx_INCREF(__pyx_t_1); + if (likely(__pyx_t_1 != Py_None)) { + PyObject* sequence = __pyx_t_1; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 5)) { + if (size > 5) __Pyx_RaiseTooManyValuesError(5); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 1293, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 4); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + #else + { + Py_ssize_t i; + PyObject** temps[5] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_4,&__pyx_t_5,&__pyx_t_6}; + for (i=0; i < 5; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1293, __pyx_L1_error) + __Pyx_GOTREF(item); + *(temps[i]) = item; + } + } + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 1293, __pyx_L1_error) + } + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo))))) __PYX_ERR(0, 1293, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 1293, __pyx_L1_error) + __pyx_v_py_db = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_v_t = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_v_additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_4); + __pyx_t_4 = 0; + __pyx_v_cache_skips = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + __pyx_v_frame_skips_cache = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1294 + * # if DEBUG: print('ENTER: trace_dispatch: %s %s %s %s' % (frame.f_code.co_filename, frame.f_lineno, event, frame.f_code.co_name)) + * py_db, t, additional_info, cache_skips, frame_skips_cache = self._args + * pydev_step_cmd = additional_info.pydev_step_cmd # <<<<<<<<<<<<<< + * is_stepping = pydev_step_cmd != -1 + * + */ + __pyx_t_7 = __pyx_v_additional_info->pydev_step_cmd; + __pyx_v_pydev_step_cmd = __pyx_t_7; + + /* "_pydevd_bundle/pydevd_cython.pyx":1295 + * py_db, t, additional_info, cache_skips, frame_skips_cache = self._args + * pydev_step_cmd = additional_info.pydev_step_cmd + * is_stepping = pydev_step_cmd != -1 # <<<<<<<<<<<<<< + * + * try: + */ + __pyx_v_is_stepping = (__pyx_v_pydev_step_cmd != -1L); + + /* "_pydevd_bundle/pydevd_cython.pyx":1297 + * is_stepping = pydev_step_cmd != -1 + * + * try: # <<<<<<<<<<<<<< + * if py_db._finish_debugging_session: + * if not py_db._termination_event_set: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":1298 + * + * try: + * if py_db._finish_debugging_session: # <<<<<<<<<<<<<< + * if not py_db._termination_event_set: + * # that was not working very well because jython gave some socket errors + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_finish_debugging_session); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1298, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1298, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1299 + * try: + * if py_db._finish_debugging_session: + * if not py_db._termination_event_set: # <<<<<<<<<<<<<< + * # that was not working very well because jython gave some socket errors + * try: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_termination_event_set); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1299, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1299, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = ((!__pyx_t_11) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1301 + * if not py_db._termination_event_set: + * # that was not working very well because jython gave some socket errors + * try: # <<<<<<<<<<<<<< + * if py_db.output_checker_thread is None: + * kill_all_pydev_threads() + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":1302 + * # that was not working very well because jython gave some socket errors + * try: + * if py_db.output_checker_thread is None: # <<<<<<<<<<<<<< + * kill_all_pydev_threads() + * except: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_output_checker_thread); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1302, __pyx_L11_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = (__pyx_t_1 == Py_None); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_11 = (__pyx_t_12 != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1303 + * try: + * if py_db.output_checker_thread is None: + * kill_all_pydev_threads() # <<<<<<<<<<<<<< + * except: + * pydev_log_exception() + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_kill_all_pydev_threads); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1303, __pyx_L11_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1303, __pyx_L11_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1302 + * # that was not working very well because jython gave some socket errors + * try: + * if py_db.output_checker_thread is None: # <<<<<<<<<<<<<< + * kill_all_pydev_threads() + * except: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1301 + * if not py_db._termination_event_set: + * # that was not working very well because jython gave some socket errors + * try: # <<<<<<<<<<<<<< + * if py_db.output_checker_thread is None: + * kill_all_pydev_threads() + */ + } + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L16_try_end; + __pyx_L11_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1304 + * if py_db.output_checker_thread is None: + * kill_all_pydev_threads() + * except: # <<<<<<<<<<<<<< + * pydev_log_exception() + * py_db._termination_event_set = True + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 1304, __pyx_L13_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_5); + + /* "_pydevd_bundle/pydevd_cython.pyx":1305 + * kill_all_pydev_threads() + * except: + * pydev_log_exception() # <<<<<<<<<<<<<< + * py_db._termination_event_set = True + * return None if event == 'call' else NO_FTRACE + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pydev_log_exception); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1305, __pyx_L13_except_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_4 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1305, __pyx_L13_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L12_exception_handled; + } + __pyx_L13_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1301 + * if not py_db._termination_event_set: + * # that was not working very well because jython gave some socket errors + * try: # <<<<<<<<<<<<<< + * if py_db.output_checker_thread is None: + * kill_all_pydev_threads() + */ + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); + goto __pyx_L3_error; + __pyx_L12_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); + __pyx_L16_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1306 + * except: + * pydev_log_exception() + * py_db._termination_event_set = True # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_py_db, __pyx_n_s_termination_event_set, Py_True) < 0) __PYX_ERR(0, 1306, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1299 + * try: + * if py_db._finish_debugging_session: + * if not py_db._termination_event_set: # <<<<<<<<<<<<<< + * # that was not working very well because jython gave some socket errors + * try: + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1307 + * pydev_log_exception() + * py_db._termination_event_set = True + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * # if thread is not alive, cancel trace_dispatch processing + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1307, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_5 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1307, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __pyx_t_6; + __pyx_t_6 = 0; + } + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1298 + * + * try: + * if py_db._finish_debugging_session: # <<<<<<<<<<<<<< + * if not py_db._termination_event_set: + * # that was not working very well because jython gave some socket errors + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1310 + * + * # if thread is not alive, cancel trace_dispatch processing + * if not is_thread_alive(t): # <<<<<<<<<<<<<< + * py_db.notify_thread_not_alive(get_current_thread_id(t)) + * return None if event == 'call' else NO_FTRACE + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_is_thread_alive); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1310, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, __pyx_v_t) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_t); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1310, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1310, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_12 = ((!__pyx_t_11) != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1311 + * # if thread is not alive, cancel trace_dispatch processing + * if not is_thread_alive(t): + * py_db.notify_thread_not_alive(get_current_thread_id(t)) # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_notify_thread_not_alive); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1311, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_get_current_thread_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1311, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_t) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_t); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1311, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_4, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1311, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1312 + * if not is_thread_alive(t): + * py_db.notify_thread_not_alive(get_current_thread_id(t)) + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * if py_db.thread_analyser is not None: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1312, __pyx_L3_error) + if (__pyx_t_12) { + __Pyx_INCREF(Py_None); + __pyx_t_5 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1312, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __pyx_t_6; + __pyx_t_6 = 0; + } + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1310 + * + * # if thread is not alive, cancel trace_dispatch processing + * if not is_thread_alive(t): # <<<<<<<<<<<<<< + * py_db.notify_thread_not_alive(get_current_thread_id(t)) + * return None if event == 'call' else NO_FTRACE + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1314 + * return None if event == 'call' else NO_FTRACE + * + * if py_db.thread_analyser is not None: # <<<<<<<<<<<<<< + * py_db.thread_analyser.log_event(frame) + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_thread_analyser); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1314, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_12 = (__pyx_t_5 != Py_None); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_11 = (__pyx_t_12 != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1315 + * + * if py_db.thread_analyser is not None: + * py_db.thread_analyser.log_event(frame) # <<<<<<<<<<<<<< + * + * if py_db.asyncio_analyser is not None: + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_thread_analyser); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1315, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_log_event); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1315, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1315, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1314 + * return None if event == 'call' else NO_FTRACE + * + * if py_db.thread_analyser is not None: # <<<<<<<<<<<<<< + * py_db.thread_analyser.log_event(frame) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1317 + * py_db.thread_analyser.log_event(frame) + * + * if py_db.asyncio_analyser is not None: # <<<<<<<<<<<<<< + * py_db.asyncio_analyser.log_event(frame) + * + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_asyncio_analyser); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1317, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_11 = (__pyx_t_5 != Py_None); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_12 = (__pyx_t_11 != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1318 + * + * if py_db.asyncio_analyser is not None: + * py_db.asyncio_analyser.log_event(frame) # <<<<<<<<<<<<<< + * + * # Note: it's important that the context name is also given because we may hit something once + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_asyncio_analyser); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1318, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_log_event); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1318, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + } + } + __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1318, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1317 + * py_db.thread_analyser.log_event(frame) + * + * if py_db.asyncio_analyser is not None: # <<<<<<<<<<<<<< + * py_db.asyncio_analyser.log_event(frame) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1322 + * # Note: it's important that the context name is also given because we may hit something once + * # in the global context and another in the local context. + * frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) # <<<<<<<<<<<<<< + * if frame_cache_key in cache_skips: + * if not is_stepping: + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_co_firstlineno); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_co_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1322, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4); + __pyx_t_6 = 0; + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_v_frame_cache_key = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1323 + * # in the global context and another in the local context. + * frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) + * if frame_cache_key in cache_skips: # <<<<<<<<<<<<<< + * if not is_stepping: + * # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + */ + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + __PYX_ERR(0, 1323, __pyx_L3_error) + } + __pyx_t_12 = (__Pyx_PyDict_ContainsTF(__pyx_v_frame_cache_key, __pyx_v_cache_skips, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1323, __pyx_L3_error) + __pyx_t_11 = (__pyx_t_12 != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1324 + * frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) + * if frame_cache_key in cache_skips: + * if not is_stepping: # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE + */ + __pyx_t_11 = ((!(__pyx_v_is_stepping != 0)) != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1326 + * if not is_stepping: + * # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * else: + * # When stepping we can't take into account caching based on the breakpoints (only global filtering). + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1326, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_5 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1326, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __pyx_t_4; + __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1324 + * frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) + * if frame_cache_key in cache_skips: + * if not is_stepping: # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1329 + * else: + * # When stepping we can't take into account caching based on the breakpoints (only global filtering). + * if cache_skips.get(frame_cache_key) == 1: # <<<<<<<<<<<<<< + * + * if additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + */ + /*else*/ { + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get"); + __PYX_ERR(0, 1329, __pyx_L3_error) + } + __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_cache_skips, __pyx_v_frame_cache_key, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1329, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1329, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1329, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1331 + * if cache_skips.get(frame_cache_key) == 1: + * + * if additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: # <<<<<<<<<<<<<< + * notify_skipped_step_in_because_of_filters(py_db, frame) + * + */ + switch (__pyx_v_additional_info->pydev_original_step_cmd) { + case 0x6B: + case 0x90: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_16 = (__pyx_t_12 != 0); + if (__pyx_t_16) { + } else { + __pyx_t_11 = __pyx_t_16; + goto __pyx_L27_bool_binop_done; + } + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 1331, __pyx_L3_error) + __pyx_t_12 = ((!__pyx_t_16) != 0); + __pyx_t_11 = __pyx_t_12; + __pyx_L27_bool_binop_done:; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1332 + * + * if additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + * notify_skipped_step_in_because_of_filters(py_db, frame) # <<<<<<<<<<<<<< + * + * back_frame = frame.f_back + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_notify_skipped_step_in_because_o); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1332, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_py_db, __pyx_v_frame}; + __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1332, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { + PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_py_db, __pyx_v_frame}; + __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1332, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GOTREF(__pyx_t_4); + } else + #endif + { + __pyx_t_6 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1332, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + if (__pyx_t_1) { + __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_v_frame); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1332, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1331 + * if cache_skips.get(frame_cache_key) == 1: + * + * if additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: # <<<<<<<<<<<<<< + * notify_skipped_step_in_because_of_filters(py_db, frame) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1334 + * notify_skipped_step_in_because_of_filters(py_db, frame) + * + * back_frame = frame.f_back # <<<<<<<<<<<<<< + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1334, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_back_frame = __pyx_t_4; + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1335 + * + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): # <<<<<<<<<<<<<< + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * if cache_skips.get(back_frame_cache_key) == 1: + */ + __pyx_t_12 = (__pyx_v_back_frame != Py_None); + __pyx_t_16 = (__pyx_t_12 != 0); + if (__pyx_t_16) { + } else { + __pyx_t_11 = __pyx_t_16; + goto __pyx_L30_bool_binop_done; + } + switch (__pyx_v_pydev_step_cmd) { + case 0x6B: + case 0x90: + case 0x6D: + case 0xA0: + __pyx_t_16 = 1; + break; + default: + __pyx_t_16 = 0; + break; + } + __pyx_t_12 = (__pyx_t_16 != 0); + __pyx_t_11 = __pyx_t_12; + __pyx_L30_bool_binop_done:; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1336 + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) # <<<<<<<<<<<<<< + * if cache_skips.get(back_frame_cache_key) == 1: + * # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_firstlineno); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1336, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_1 = 0; + __pyx_v_back_frame_cache_key = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1337 + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * if cache_skips.get(back_frame_cache_key) == 1: # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE + */ + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "get"); + __PYX_ERR(0, 1337, __pyx_L3_error) + } + __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_cache_skips, __pyx_v_back_frame_cache_key, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1337, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1337, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1337, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1339 + * if cache_skips.get(back_frame_cache_key) == 1: + * # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * else: + * # if DEBUG: print('skipped: trace_dispatch (cache hit: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1339, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1339, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __pyx_t_4; + __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1337 + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * if cache_skips.get(back_frame_cache_key) == 1: # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1335 + * + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): # <<<<<<<<<<<<<< + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * if cache_skips.get(back_frame_cache_key) == 1: + */ + goto __pyx_L29; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1342 + * else: + * # if DEBUG: print('skipped: trace_dispatch (cache hit: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * try: + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1342, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1342, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __pyx_t_4; + __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + } + __pyx_L29:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1329 + * else: + * # When stepping we can't take into account caching based on the breakpoints (only global filtering). + * if cache_skips.get(frame_cache_key) == 1: # <<<<<<<<<<<<<< + * + * if additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + */ + } + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1323 + * # in the global context and another in the local context. + * frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) + * if frame_cache_key in cache_skips: # <<<<<<<<<<<<<< + * if not is_stepping: + * # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1344 + * return None if event == 'call' else NO_FTRACE + * + * try: # <<<<<<<<<<<<<< + * # Make fast path faster! + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_13); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":1346 + * try: + * # Make fast path faster! + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] # <<<<<<<<<<<<<< + * except: + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1346, __pyx_L33_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1346, __pyx_L33_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1346, __pyx_L33_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1346, __pyx_L33_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!(likely(PyTuple_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 1346, __pyx_L33_error) + __pyx_v_abs_path_real_path_and_base = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1344 + * return None if event == 'call' else NO_FTRACE + * + * try: # <<<<<<<<<<<<<< + * # Make fast path faster! + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + */ + } + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L38_try_end; + __pyx_L33_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1347 + * # Make fast path faster! + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + * except: # <<<<<<<<<<<<<< + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_1) < 0) __PYX_ERR(0, 1347, __pyx_L35_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_1); + + /* "_pydevd_bundle/pydevd_cython.pyx":1348 + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + * except: + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) # <<<<<<<<<<<<<< + * + * filename = abs_path_real_path_and_base[1] + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1348, __pyx_L35_except_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_frame) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_frame); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1348, __pyx_L35_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!(likely(PyTuple_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 1348, __pyx_L35_except_error) + __Pyx_XDECREF_SET(__pyx_v_abs_path_real_path_and_base, ((PyObject*)__pyx_t_5)); + __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L34_exception_handled; + } + __pyx_L35_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1344 + * return None if event == 'call' else NO_FTRACE + * + * try: # <<<<<<<<<<<<<< + * # Make fast path faster! + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + */ + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_14, __pyx_t_13); + goto __pyx_L3_error; + __pyx_L34_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_14, __pyx_t_13); + __pyx_L38_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1350 + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + * + * filename = abs_path_real_path_and_base[1] # <<<<<<<<<<<<<< + * file_type = py_db.get_file_type(frame, abs_path_real_path_and_base) # we don't want to debug threading or anything related to pydevd + * + */ + if (unlikely(__pyx_v_abs_path_real_path_and_base == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1350, __pyx_L3_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_abs_path_real_path_and_base, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1350, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 1350, __pyx_L3_error) + __pyx_v_filename = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1351 + * + * filename = abs_path_real_path_and_base[1] + * file_type = py_db.get_file_type(frame, abs_path_real_path_and_base) # we don't want to debug threading or anything related to pydevd # <<<<<<<<<<<<<< + * + * if file_type is not None: + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_get_file_type); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1351, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_frame, __pyx_v_abs_path_real_path_and_base}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1351, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_frame, __pyx_v_abs_path_real_path_and_base}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1351, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1351, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_abs_path_real_path_and_base); + __Pyx_GIVEREF(__pyx_v_abs_path_real_path_and_base); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_v_abs_path_real_path_and_base); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1351, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_v_file_type = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1353 + * file_type = py_db.get_file_type(frame, abs_path_real_path_and_base) # we don't want to debug threading or anything related to pydevd + * + * if file_type is not None: # <<<<<<<<<<<<<< + * if file_type == 1: # inlining LIB_FILE = 1 + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + */ + __pyx_t_11 = (__pyx_v_file_type != Py_None); + __pyx_t_12 = (__pyx_t_11 != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1354 + * + * if file_type is not None: + * if file_type == 1: # inlining LIB_FILE = 1 # <<<<<<<<<<<<<< + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + * # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + */ + __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_file_type, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1354, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1354, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1355 + * if file_type is not None: + * if file_type == 1: # inlining LIB_FILE = 1 + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + * cache_skips[frame_cache_key] = 1 + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_in_project_scope); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + if (unlikely(__pyx_v_abs_path_real_path_and_base == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1355, __pyx_L3_error) + } + __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_abs_path_real_path_and_base, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_frame, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_frame, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_7, __pyx_v_frame); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_7, __pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1355, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_11 = ((!__pyx_t_12) != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1357 + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + * # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + * cache_skips[frame_cache_key] = 1 # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * else: + */ + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1357, __pyx_L3_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_cache_skips, __pyx_v_frame_cache_key, __pyx_int_1) < 0)) __PYX_ERR(0, 1357, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1358 + * # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + * cache_skips[frame_cache_key] = 1 + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * else: + * # if DEBUG: print('skipped: trace_dispatch', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1358, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1358, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __pyx_t_6; + __pyx_t_6 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1355 + * if file_type is not None: + * if file_type == 1: # inlining LIB_FILE = 1 + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + * cache_skips[frame_cache_key] = 1 + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1354 + * + * if file_type is not None: + * if file_type == 1: # inlining LIB_FILE = 1 # <<<<<<<<<<<<<< + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + * # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + */ + goto __pyx_L42; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1361 + * else: + * # if DEBUG: print('skipped: trace_dispatch', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + * cache_skips[frame_cache_key] = 1 # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + /*else*/ { + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1361, __pyx_L3_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_cache_skips, __pyx_v_frame_cache_key, __pyx_int_1) < 0)) __PYX_ERR(0, 1361, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1362 + * # if DEBUG: print('skipped: trace_dispatch', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + * cache_skips[frame_cache_key] = 1 + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * if py_db.is_files_filter_enabled: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1362, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1362, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = __pyx_t_6; + __pyx_t_6 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + } + __pyx_L42:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1353 + * file_type = py_db.get_file_type(frame, abs_path_real_path_and_base) # we don't want to debug threading or anything related to pydevd + * + * if file_type is not None: # <<<<<<<<<<<<<< + * if file_type == 1: # inlining LIB_FILE = 1 + * if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1364 + * return None if event == 'call' else NO_FTRACE + * + * if py_db.is_files_filter_enabled: # <<<<<<<<<<<<<< + * if py_db.apply_files_filter(frame, filename, False): + * cache_skips[frame_cache_key] = 1 + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_is_files_filter_enabled); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1364, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1365 + * + * if py_db.is_files_filter_enabled: + * if py_db.apply_files_filter(frame, filename, False): # <<<<<<<<<<<<<< + * cache_skips[frame_cache_key] = 1 + * + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_apply_files_filter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1365, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_frame, __pyx_v_filename, Py_False}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1365, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_frame, __pyx_v_filename, Py_False}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1365, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_5 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1365, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_v_filename); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_7, Py_False); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1365, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1365, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1366 + * if py_db.is_files_filter_enabled: + * if py_db.apply_files_filter(frame, filename, False): + * cache_skips[frame_cache_key] = 1 # <<<<<<<<<<<<<< + * + * if is_stepping and additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + */ + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1366, __pyx_L3_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_cache_skips, __pyx_v_frame_cache_key, __pyx_int_1) < 0)) __PYX_ERR(0, 1366, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1368 + * cache_skips[frame_cache_key] = 1 + * + * if is_stepping and additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: # <<<<<<<<<<<<<< + * notify_skipped_step_in_because_of_filters(py_db, frame) + * + */ + __pyx_t_12 = (__pyx_v_is_stepping != 0); + if (__pyx_t_12) { + } else { + __pyx_t_11 = __pyx_t_12; + goto __pyx_L47_bool_binop_done; + } + switch (__pyx_v_additional_info->pydev_original_step_cmd) { + case 0x6B: + case 0x90: + __pyx_t_12 = 1; + break; + default: + __pyx_t_12 = 0; + break; + } + __pyx_t_16 = (__pyx_t_12 != 0); + if (__pyx_t_16) { + } else { + __pyx_t_11 = __pyx_t_16; + goto __pyx_L47_bool_binop_done; + } + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 1368, __pyx_L3_error) + __pyx_t_12 = ((!__pyx_t_16) != 0); + __pyx_t_11 = __pyx_t_12; + __pyx_L47_bool_binop_done:; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1369 + * + * if is_stepping and additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + * notify_skipped_step_in_because_of_filters(py_db, frame) # <<<<<<<<<<<<<< + * + * # A little gotcha, sometimes when we're stepping in we have to stop in a + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_notify_skipped_step_in_because_o); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1369, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_py_db, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1369, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_py_db, __pyx_v_frame}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1369, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_1); + } else + #endif + { + __pyx_t_3 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1369, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_3); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_7, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_7, __pyx_v_frame); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1369, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1368 + * cache_skips[frame_cache_key] = 1 + * + * if is_stepping and additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: # <<<<<<<<<<<<<< + * notify_skipped_step_in_because_of_filters(py_db, frame) + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1374 + * # return event showing the back frame as the current frame, so, we need + * # to check not only the current frame but the back frame too. + * back_frame = frame.f_back # <<<<<<<<<<<<<< + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1374, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF_SET(__pyx_v_back_frame, __pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1375 + * # to check not only the current frame but the back frame too. + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): # <<<<<<<<<<<<<< + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + */ + __pyx_t_12 = (__pyx_v_back_frame != Py_None); + __pyx_t_16 = (__pyx_t_12 != 0); + if (__pyx_t_16) { + } else { + __pyx_t_11 = __pyx_t_16; + goto __pyx_L51_bool_binop_done; + } + switch (__pyx_v_pydev_step_cmd) { + case 0x6B: + case 0x90: + case 0x6D: + case 0xA0: + __pyx_t_16 = 1; + break; + default: + __pyx_t_16 = 0; + break; + } + __pyx_t_12 = (__pyx_t_16 != 0); + __pyx_t_11 = __pyx_t_12; + __pyx_L51_bool_binop_done:; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1376 + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): # <<<<<<<<<<<<<< + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * cache_skips[back_frame_cache_key] = 1 + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_apply_files_filter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_7 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_back_frame, __pyx_t_5, Py_False}; + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { + PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_v_back_frame, __pyx_t_5, Py_False}; + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + #endif + { + __pyx_t_4 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_back_frame); + __Pyx_GIVEREF(__pyx_v_back_frame); + PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_7, __pyx_v_back_frame); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_7, __pyx_t_5); + __Pyx_INCREF(Py_False); + __Pyx_GIVEREF(Py_False); + PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_7, Py_False); + __pyx_t_5 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1376, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1377 + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) # <<<<<<<<<<<<<< + * cache_skips[back_frame_cache_key] = 1 + * # if DEBUG: print('skipped: trace_dispatch (filtered out: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co_firstlineno); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_back_frame, __pyx_n_s_f_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_5); + __pyx_t_6 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __Pyx_XDECREF_SET(__pyx_v_back_frame_cache_key, ((PyObject*)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1378 + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * cache_skips[back_frame_cache_key] = 1 # <<<<<<<<<<<<<< + * # if DEBUG: print('skipped: trace_dispatch (filtered out: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE + */ + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1378, __pyx_L3_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_cache_skips, __pyx_v_back_frame_cache_key, __pyx_int_1) < 0)) __PYX_ERR(0, 1378, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1380 + * cache_skips[back_frame_cache_key] = 1 + * # if DEBUG: print('skipped: trace_dispatch (filtered out: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * else: + * # if DEBUG: print('skipped: trace_dispatch (filtered out: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1380, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1380, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1376 + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): # <<<<<<<<<<<<<< + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + * cache_skips[back_frame_cache_key] = 1 + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1375 + * # to check not only the current frame but the back frame too. + * back_frame = frame.f_back + * if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): # <<<<<<<<<<<<<< + * if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + * back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + */ + goto __pyx_L50; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1383 + * else: + * # if DEBUG: print('skipped: trace_dispatch (filtered out: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1383, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1383, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + } + __pyx_L50:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1365 + * + * if py_db.is_files_filter_enabled: + * if py_db.apply_files_filter(frame, filename, False): # <<<<<<<<<<<<<< + * cache_skips[frame_cache_key] = 1 + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1364 + * return None if event == 'call' else NO_FTRACE + * + * if py_db.is_files_filter_enabled: # <<<<<<<<<<<<<< + * if py_db.apply_files_filter(frame, filename, False): + * cache_skips[frame_cache_key] = 1 + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1386 + * + * # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) + * if additional_info.is_tracing: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE # we don't wan't to trace code invoked from pydevd_frame.trace_dispatch + * + */ + __pyx_t_11 = (__pyx_v_additional_info->is_tracing != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1387 + * # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) + * if additional_info.is_tracing: + * return None if event == 'call' else NO_FTRACE # we don't wan't to trace code invoked from pydevd_frame.trace_dispatch # <<<<<<<<<<<<<< + * + * # Just create PyDBFrame directly (removed support for Python versions < 2.5, which required keeping a weak + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1387, __pyx_L3_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1387, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1386 + * + * # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) + * if additional_info.is_tracing: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE # we don't wan't to trace code invoked from pydevd_frame.trace_dispatch + * + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1393 + * ret = PyDBFrame( + * ( + * py_db, filename, additional_info, t, frame_skips_cache, frame_cache_key, # <<<<<<<<<<<<<< + * ) + * ).trace_dispatch(frame, event, arg) + */ + __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1393, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_py_db); + __Pyx_GIVEREF(__pyx_v_py_db); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_py_db); + __Pyx_INCREF(__pyx_v_filename); + __Pyx_GIVEREF(__pyx_v_filename); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_filename); + __Pyx_INCREF(((PyObject *)__pyx_v_additional_info)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_additional_info)); + PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_additional_info)); + __Pyx_INCREF(__pyx_v_t); + __Pyx_GIVEREF(__pyx_v_t); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_t); + __Pyx_INCREF(__pyx_v_frame_skips_cache); + __Pyx_GIVEREF(__pyx_v_frame_skips_cache); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_frame_skips_cache); + __Pyx_INCREF(__pyx_v_frame_cache_key); + __Pyx_GIVEREF(__pyx_v_frame_cache_key); + PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_v_frame_cache_key); + + /* "_pydevd_bundle/pydevd_cython.pyx":1391 + * # Just create PyDBFrame directly (removed support for Python versions < 2.5, which required keeping a weak + * # reference to the frame). + * ret = PyDBFrame( # <<<<<<<<<<<<<< + * ( + * py_db, filename, additional_info, t, frame_skips_cache, frame_cache_key, + */ + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame), __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1391, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1395 + * py_db, filename, additional_info, t, frame_skips_cache, frame_cache_key, + * ) + * ).trace_dispatch(frame, event, arg) # <<<<<<<<<<<<<< + * if ret is None: + * # 1 means skipped because of filters. + */ + if (!(likely(PyString_CheckExact(__pyx_v_event))||((__pyx_v_event) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_event)->tp_name), 0))) __PYX_ERR(0, 1395, __pyx_L3_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_t_5)->__pyx_vtab)->trace_dispatch(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_t_5), __pyx_v_frame, ((PyObject*)__pyx_v_event), __pyx_v_arg, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1395, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_ret = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1396 + * ) + * ).trace_dispatch(frame, event, arg) + * if ret is None: # <<<<<<<<<<<<<< + * # 1 means skipped because of filters. + * # 2 means skipped because no breakpoints were hit. + */ + __pyx_t_11 = (__pyx_v_ret == Py_None); + __pyx_t_12 = (__pyx_t_11 != 0); + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1399 + * # 1 means skipped because of filters. + * # 2 means skipped because no breakpoints were hit. + * cache_skips[frame_cache_key] = 2 # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + if (unlikely(__pyx_v_cache_skips == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 1399, __pyx_L3_error) + } + if (unlikely(PyDict_SetItem(__pyx_v_cache_skips, __pyx_v_frame_cache_key, __pyx_int_2) < 0)) __PYX_ERR(0, 1399, __pyx_L3_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1400 + * # 2 means skipped because no breakpoints were hit. + * cache_skips[frame_cache_key] = 2 + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1400, __pyx_L3_error) + if (__pyx_t_12) { + __Pyx_INCREF(Py_None); + __pyx_t_1 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1400, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1396 + * ) + * ).trace_dispatch(frame, event, arg) + * if ret is None: # <<<<<<<<<<<<<< + * # 1 means skipped because of filters. + * # 2 means skipped because no breakpoints were hit. + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1403 + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * frame.f_trace = SafeCallWrapper(ret) # Make sure we keep the returned tracer. # <<<<<<<<<<<<<< + * # ELSE + * # frame.f_trace = ret # Make sure we keep the returned tracer. + */ + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), __pyx_v_ret); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1403, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_1) < 0) __PYX_ERR(0, 1403, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1407 + * # frame.f_trace = ret # Make sure we keep the returned tracer. + * # ENDIF + * return ret # <<<<<<<<<<<<<< + * + * except SystemExit: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_ret); + __pyx_r = __pyx_v_ret; + goto __pyx_L7_try_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1297 + * is_stepping = pydev_step_cmd != -1 + * + * try: # <<<<<<<<<<<<<< + * if py_db._finish_debugging_session: + * if not py_db._termination_event_set: + */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1409 + * return ret + * + * except SystemExit: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE + * + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_SystemExit); + if (__pyx_t_7) { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 1409, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_4); + + /* "_pydevd_bundle/pydevd_cython.pyx":1410 + * + * except SystemExit: + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * except Exception: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1410, __pyx_L5_except_error) + if (__pyx_t_12) { + __Pyx_INCREF(Py_None); + __pyx_t_6 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1410, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L6_except_return; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1412 + * return None if event == 'call' else NO_FTRACE + * + * except Exception: # <<<<<<<<<<<<<< + * if py_db._finish_debugging_session: + * return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + */ + __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_7) { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(0, 1412, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_1); + + /* "_pydevd_bundle/pydevd_cython.pyx":1413 + * + * except Exception: + * if py_db._finish_debugging_session: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + * # Log it + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_py_db, __pyx_n_s_finish_debugging_session); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1413, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1413, __pyx_L5_except_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_12) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1414 + * except Exception: + * if py_db._finish_debugging_session: + * return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. # <<<<<<<<<<<<<< + * # Log it + * try: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1414, __pyx_L5_except_error) + if (__pyx_t_12) { + __Pyx_INCREF(Py_None); + __pyx_t_6 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1414, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L6_except_return; + + /* "_pydevd_bundle/pydevd_cython.pyx":1413 + * + * except Exception: + * if py_db._finish_debugging_session: # <<<<<<<<<<<<<< + * return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + * # Log it + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1416 + * return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + * # Log it + * try: # <<<<<<<<<<<<<< + * if pydev_log_exception is not None: + * # This can actually happen during the interpreter shutdown in Python 2.7 + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":1417 + * # Log it + * try: + * if pydev_log_exception is not None: # <<<<<<<<<<<<<< + * # This can actually happen during the interpreter shutdown in Python 2.7 + * pydev_log_exception() + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pydev_log_exception); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1417, __pyx_L61_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_12 = (__pyx_t_6 != Py_None); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_11 = (__pyx_t_12 != 0); + if (__pyx_t_11) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1419 + * if pydev_log_exception is not None: + * # This can actually happen during the interpreter shutdown in Python 2.7 + * pydev_log_exception() # <<<<<<<<<<<<<< + * except: + * # Error logging? We're really in the interpreter shutdown... + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pydev_log_exception); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1419, __pyx_L61_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_6 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1419, __pyx_L61_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1417 + * # Log it + * try: + * if pydev_log_exception is not None: # <<<<<<<<<<<<<< + * # This can actually happen during the interpreter shutdown in Python 2.7 + * pydev_log_exception() + */ + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1416 + * return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + * # Log it + * try: # <<<<<<<<<<<<<< + * if pydev_log_exception is not None: + * # This can actually happen during the interpreter shutdown in Python 2.7 + */ + } + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L68_try_end; + __pyx_L61_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1420 + * # This can actually happen during the interpreter shutdown in Python 2.7 + * pydev_log_exception() + * except: # <<<<<<<<<<<<<< + * # Error logging? We're really in the interpreter shutdown... + * # (https://github.com/fabioz/PyDev.Debugger/issues/8) + */ + /*except:*/ { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L62_exception_handled; + } + __pyx_L62_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15); + __pyx_L68_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1424 + * # (https://github.com/fabioz/PyDev.Debugger/issues/8) + * pass + * return None if event == 'call' else NO_FTRACE # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_11 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1424, __pyx_L5_except_error) + if (__pyx_t_11) { + __Pyx_INCREF(Py_None); + __pyx_t_6 = Py_None; + } else { + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1424, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L6_except_return; + } + goto __pyx_L5_except_error; + __pyx_L5_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":1297 + * is_stepping = pydev_step_cmd != -1 + * + * try: # <<<<<<<<<<<<<< + * if py_db._finish_debugging_session: + * if not py_db._termination_event_set: + */ + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); + goto __pyx_L0; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":1267 + * # ENDIF + * + * def __call__(self, frame, event, arg): # <<<<<<<<<<<<<< + * ''' This is the callback used when we enter some context in the debugger. + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_filename); + __Pyx_XDECREF(__pyx_v_frame_cache_key); + __Pyx_XDECREF(__pyx_v_cache_skips); + __Pyx_XDECREF(__pyx_v_abs_path_real_path_and_base); + __Pyx_XDECREF((PyObject *)__pyx_v_additional_info); + __Pyx_XDECREF(__pyx_v_py_db); + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_frame_skips_cache); + __Pyx_XDECREF(__pyx_v_back_frame); + __Pyx_XDECREF(__pyx_v_back_frame_cache_key); + __Pyx_XDECREF(__pyx_v_file_type); + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1257 + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef class ThreadTracer: + * cdef public tuple _args; # <<<<<<<<<<<<<< + * def __init__(self, tuple args): + * self._args = args + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args___get__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args___get__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->_args); + __pyx_r = __pyx_v_self->_args; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_2__set__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_2__set__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyTuple_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 1257, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer._args.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_4__del__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_4__del__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->_args); + __Pyx_DECREF(__pyx_v_self->_args); + __pyx_v_self->_args = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_4__reduce_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_4__reduce_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self._args,) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->_args); + __Pyx_GIVEREF(__pyx_v_self->_args); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->_args); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self._args,) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":7 + * state = (self._args,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + __pyx_t_3 = (__pyx_t_2 != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self._args is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self._args,) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self._args is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, None), state + */ + /*else*/ { + __pyx_t_3 = (__pyx_v_self->_args != ((PyObject*)Py_None)); + __pyx_v_use_setstate = __pyx_t_3; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, None), state + * else: + */ + __pyx_t_3 = (__pyx_v_use_setstate != 0); + if (__pyx_t_3) { + + /* "(tree fragment)":13 + * use_setstate = self._args is not None + * if use_setstate: + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_ThreadTracer); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_64458794); + __Pyx_GIVEREF(__pyx_int_64458794); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_64458794); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self._args is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, None), state + * else: + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_ThreadTracer__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_ThreadTracer); if (unlikely(!__pyx_t_5)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_64458794); + __Pyx_GIVEREF(__pyx_int_64458794); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_64458794); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadTracer__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_6__setstate_cython__(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_6__setstate_cython__(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_ThreadTracer__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_ThreadTracer__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_ThreadTracer, (type(self), 0x3d7902a, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadTracer__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.ThreadTracer.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_bundle/pydevd_cython.pyx":1439 + * _original_call = ThreadTracer.__call__ + * + * def __call__(self, frame, event, arg): # <<<<<<<<<<<<<< + * _tid_to_last_frame[self._args[1].ident] = frame + * return _original_call(self, frame, event, arg) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15__call__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_15__call__ = {"__call__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_15__call__, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_15__call__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_self = 0; + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[4] = {0,0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, 1); __PYX_ERR(0, 1439, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, 2); __PYX_ERR(0, 1439, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, 3); __PYX_ERR(0, 1439, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) __PYX_ERR(0, 1439, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + } + __pyx_v_self = values[0]; + __pyx_v_frame = values[1]; + __pyx_v_event = values[2]; + __pyx_v_arg = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1439, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_14__call__(__pyx_self, __pyx_v_self, __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_14__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannySetupContext("__call__", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":1440 + * + * def __call__(self, frame, event, arg): + * _tid_to_last_frame[self._args[1].ident] = frame # <<<<<<<<<<<<<< + * return _original_call(self, frame, event, arg) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_tid_to_last_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_args_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_ident); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1440, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_t_2, __pyx_v_frame) < 0)) __PYX_ERR(0, 1440, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1441 + * def __call__(self, frame, event, arg): + * _tid_to_last_frame[self._args[1].ident] = frame + * return _original_call(self, frame, event, arg) # <<<<<<<<<<<<<< + * + * ThreadTracer.__call__ = __call__ + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_original_call); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1441, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_4 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[5] = {__pyx_t_3, __pyx_v_self, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1441, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { + PyObject *__pyx_temp[5] = {__pyx_t_3, __pyx_v_self, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_4, 4+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1441, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1441, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_self); + __Pyx_GIVEREF(__pyx_v_self); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_self); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, __pyx_v_arg); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1441, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1439 + * _original_call = ThreadTracer.__call__ + * + * def __call__(self, frame, event, arg): # <<<<<<<<<<<<<< + * _tid_to_last_frame[self._args[1].ident] = frame + * return _original_call(self, frame, event, arg) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_PyDBAdditionalThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_17__pyx_unpickle_PyDBAdditionalThreadInfo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_17__pyx_unpickle_PyDBAdditionalThreadInfo = {"__pyx_unpickle_PyDBAdditionalThreadInfo", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_17__pyx_unpickle_PyDBAdditionalThreadInfo, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_17__pyx_unpickle_PyDBAdditionalThreadInfo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_PyDBAdditionalThreadInfo (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PyDBAdditionalThreadInfo", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PyDBAdditionalThreadInfo", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_PyDBAdditionalThreadInfo") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PyDBAdditionalThreadInfo", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_PyDBAdditionalThreadInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_16__pyx_unpickle_PyDBAdditionalThreadInfo(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_16__pyx_unpickle_PyDBAdditionalThreadInfo(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_PyDBAdditionalThreadInfo", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x6afc46c: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x6afc46c) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0x6afc46c: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) + * __pyx_result = PyDBAdditionalThreadInfo.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0x6afc46c: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = PyDBAdditionalThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x6a, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x6afc46c: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) + * __pyx_result = PyDBAdditionalThreadInfo.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) + * __pyx_result = PyDBAdditionalThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = PyDBAdditionalThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBAdditionalThreadInfo__set_state(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x6afc46c = (conditional_breakpoint_exception, is_tracing, pydev_call_from_jinja2, pydev_call_inside_jinja2, pydev_django_resolve_frame, pydev_func_name, pydev_message, pydev_next_line, pydev_notify_kill, pydev_original_step_cmd, pydev_smart_step_stop, pydev_state, pydev_step_cmd, pydev_step_stop, suspend_type, suspended_at_unhandled, thread_tracer, top_level_thread_tracer_no_back_frames, top_level_thread_tracer_unhandled, trace_suspend_type))" % __pyx_checksum) + * __pyx_result = PyDBAdditionalThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_PyDBAdditionalThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_PyDBAdditionalThreadInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBAdditionalThreadInfo__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_PyDBAdditionalThreadInfo__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[20]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->conditional_breakpoint_exception); + __Pyx_DECREF(__pyx_v___pyx_result->conditional_breakpoint_exception); + __pyx_v___pyx_result->conditional_breakpoint_exception = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->is_tracing = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->pydev_call_from_jinja2); + __Pyx_DECREF(__pyx_v___pyx_result->pydev_call_from_jinja2); + __pyx_v___pyx_result->pydev_call_from_jinja2 = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->pydev_call_inside_jinja2); + __Pyx_DECREF(__pyx_v___pyx_result->pydev_call_inside_jinja2); + __pyx_v___pyx_result->pydev_call_inside_jinja2 = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->pydev_django_resolve_frame = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->pydev_func_name); + __Pyx_DECREF(__pyx_v___pyx_result->pydev_func_name); + __pyx_v___pyx_result->pydev_func_name = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->pydev_message); + __Pyx_DECREF(__pyx_v___pyx_result->pydev_message); + __pyx_v___pyx_result->pydev_message = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->pydev_next_line = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->pydev_notify_kill = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 9, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->pydev_original_step_cmd = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 10, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->pydev_smart_step_stop); + __Pyx_DECREF(__pyx_v___pyx_result->pydev_smart_step_stop); + __pyx_v___pyx_result->pydev_smart_step_stop = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 11, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->pydev_state = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 12, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->pydev_step_cmd = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 13, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->pydev_step_stop); + __Pyx_DECREF(__pyx_v___pyx_result->pydev_step_stop); + __pyx_v___pyx_result->pydev_step_stop = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 14, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->suspend_type = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 15, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->suspended_at_unhandled = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 16, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->thread_tracer); + __Pyx_DECREF(__pyx_v___pyx_result->thread_tracer); + __pyx_v___pyx_result->thread_tracer = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 17, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->top_level_thread_tracer_no_back_frames); + __Pyx_DECREF(__pyx_v___pyx_result->top_level_thread_tracer_no_back_frames); + __pyx_v___pyx_result->top_level_thread_tracer_no_back_frames = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 18, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->top_level_thread_tracer_unhandled); + __Pyx_DECREF(__pyx_v___pyx_result->top_level_thread_tracer_unhandled); + __pyx_v___pyx_result->top_level_thread_tracer_unhandled = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 19, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->trace_suspend_type); + __Pyx_DECREF(__pyx_v___pyx_result->trace_suspend_type); + __pyx_v___pyx_result->trace_suspend_type = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[20]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = ((__pyx_t_4 > 20) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_2 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + __pyx_t_2 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[20]) # <<<<<<<<<<<<<< + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 20, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[20]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_PyDBAdditionalThreadInfo__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_PyDBFrame(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_19__pyx_unpickle_PyDBFrame(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_19__pyx_unpickle_PyDBFrame = {"__pyx_unpickle_PyDBFrame", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_19__pyx_unpickle_PyDBFrame, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_19__pyx_unpickle_PyDBFrame(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_PyDBFrame (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PyDBFrame", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PyDBFrame", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_PyDBFrame") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_PyDBFrame", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_PyDBFrame", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_18__pyx_unpickle_PyDBFrame(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_18__pyx_unpickle_PyDBFrame(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_PyDBFrame", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xfa6b183: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xfa6b183) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0xfa6b183: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) + * __pyx_result = PyDBFrame.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0xfa6b183: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = PyDBFrame.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xfa, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xfa6b183: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) + * __pyx_result = PyDBFrame.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) + * __pyx_result = PyDBFrame.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = PyDBFrame.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBFrame__set_state(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xfa6b183 = (_args, should_skip))" % __pyx_checksum) + * __pyx_result = PyDBFrame.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_PyDBFrame(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_PyDBFrame", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] + * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_PyDBFrame__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_PyDBFrame__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[2]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_args); + __Pyx_DECREF(__pyx_v___pyx_result->_args); + __pyx_v___pyx_result->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->should_skip = __pyx_t_2; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] + * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[2]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = ((__pyx_t_4 > 2) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_3 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + __pyx_t_3 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_3) { + + /* "(tree fragment)":14 + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] + * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[2]) # <<<<<<<<<<<<<< + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] + * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[2]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_PyDBFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PyDBFrame__set_state(PyDBFrame __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0]; __pyx_result.should_skip = __pyx_state[1] + * if len(__pyx_state) > 2 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_PyDBFrame__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_SafeCallWrapper(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_21__pyx_unpickle_SafeCallWrapper(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_21__pyx_unpickle_SafeCallWrapper = {"__pyx_unpickle_SafeCallWrapper", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_21__pyx_unpickle_SafeCallWrapper, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_21__pyx_unpickle_SafeCallWrapper(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_SafeCallWrapper (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SafeCallWrapper", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SafeCallWrapper", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_SafeCallWrapper") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SafeCallWrapper", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_SafeCallWrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_20__pyx_unpickle_SafeCallWrapper(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_20__pyx_unpickle_SafeCallWrapper(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_SafeCallWrapper", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x77c077b: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x77c077b) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0x77c077b: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) + * __pyx_result = SafeCallWrapper.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0x77c077b: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = SafeCallWrapper.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x77, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x77c077b: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) + * __pyx_result = SafeCallWrapper.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) + * __pyx_result = SafeCallWrapper.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = SafeCallWrapper.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_SafeCallWrapper__set_state(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x77c077b = (method_object))" % __pyx_checksum) + * __pyx_result = SafeCallWrapper.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): + * __pyx_result.method_object = __pyx_state[0] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_SafeCallWrapper(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_SafeCallWrapper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.method_object = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_SafeCallWrapper__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_SafeCallWrapper__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): + * __pyx_result.method_object = __pyx_state[0] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->method_object); + __Pyx_DECREF(__pyx_v___pyx_result->method_object); + __pyx_v___pyx_result->method_object = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): + * __pyx_result.method_object = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_3 > 1) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.method_object = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): + * __pyx_result.method_object = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.method_object = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_SafeCallWrapper__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_23__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_23__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions = {"__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_23__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_23__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_22__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_22__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x3d7902a: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x3d7902a) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0x3d7902a: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerOnlyUnhandledExceptions.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0x3d7902a: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = TopLevelThreadTracerOnlyUnhandledExceptions.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x3d, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x3d7902a: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerOnlyUnhandledExceptions.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerOnlyUnhandledExceptions.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = TopLevelThreadTracerOnlyUnhandledExceptions.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerOnlyUnhandledExceptions.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_args); + __Pyx_DECREF(__pyx_v___pyx_result->_args); + __pyx_v___pyx_result->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_3 > 1) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state(TopLevelThreadTracerOnlyUnhandledExceptions __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_TopLevelThreadTracerNoBackFrame(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_25__pyx_unpickle_TopLevelThreadTracerNoBackFrame(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_25__pyx_unpickle_TopLevelThreadTracerNoBackFrame = {"__pyx_unpickle_TopLevelThreadTracerNoBackFrame", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_25__pyx_unpickle_TopLevelThreadTracerNoBackFrame, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_25__pyx_unpickle_TopLevelThreadTracerNoBackFrame(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_TopLevelThreadTracerNoBackFrame (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_TopLevelThreadTracerNoBackFrame", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_TopLevelThreadTracerNoBackFrame", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_TopLevelThreadTracerNoBackFrame") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_TopLevelThreadTracerNoBackFrame", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_TopLevelThreadTracerNoBackFrame", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_24__pyx_unpickle_TopLevelThreadTracerNoBackFrame(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_24__pyx_unpickle_TopLevelThreadTracerNoBackFrame(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_TopLevelThreadTracerNoBackFrame", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xf34c74e: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xf34c74e) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0xf34c74e: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerNoBackFrame.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0xf34c74e: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = TopLevelThreadTracerNoBackFrame.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xf3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xf34c74e: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerNoBackFrame.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerNoBackFrame.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = TopLevelThreadTracerNoBackFrame.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xf34c74e = (_args, _frame_trace_dispatch, _last_exc_arg, _last_raise_line, _raise_lines, _try_except_info))" % __pyx_checksum) + * __pyx_result = TopLevelThreadTracerNoBackFrame.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_TopLevelThreadTracerNoBackFrame(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_TopLevelThreadTracerNoBackFrame", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_args); + __Pyx_DECREF(__pyx_v___pyx_result->_args); + __pyx_v___pyx_result->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_frame_trace_dispatch); + __Pyx_DECREF(__pyx_v___pyx_result->_frame_trace_dispatch); + __pyx_v___pyx_result->_frame_trace_dispatch = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_last_exc_arg); + __Pyx_DECREF(__pyx_v___pyx_result->_last_exc_arg); + __pyx_v___pyx_result->_last_exc_arg = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->_last_raise_line = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PySet_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "set", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_raise_lines); + __Pyx_DECREF(__pyx_v___pyx_result->_raise_lines); + __pyx_v___pyx_result->_raise_lines = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_try_except_info); + __Pyx_DECREF(__pyx_v___pyx_result->_try_except_info); + __pyx_v___pyx_result->_try_except_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = ((__pyx_t_4 > 6) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_3 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + __pyx_t_3 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_3) { + + /* "(tree fragment)":14 + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[6]) # <<<<<<<<<<<<<< + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_ThreadTracer(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_27__pyx_unpickle_ThreadTracer(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_14_pydevd_bundle_13pydevd_cython_27__pyx_unpickle_ThreadTracer = {"__pyx_unpickle_ThreadTracer", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_27__pyx_unpickle_ThreadTracer, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_14_pydevd_bundle_13pydevd_cython_27__pyx_unpickle_ThreadTracer(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_ThreadTracer (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_ThreadTracer", 1, 3, 3, 1); __PYX_ERR(2, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_ThreadTracer", 1, 3, 3, 2); __PYX_ERR(2, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_ThreadTracer") < 0)) __PYX_ERR(2, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_ThreadTracer", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(2, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_ThreadTracer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_14_pydevd_bundle_13pydevd_cython_26__pyx_unpickle_ThreadTracer(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_14_pydevd_bundle_13pydevd_cython_26__pyx_unpickle_ThreadTracer(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_ThreadTracer", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x3d7902a: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x3d7902a) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0x3d7902a: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = ThreadTracer.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0x3d7902a: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = ThreadTracer.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x3d, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(2, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x3d7902a: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = ThreadTracer.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = ThreadTracer.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = ThreadTracer.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(2, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_ThreadTracer__set_state(((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x3d7902a = (_args))" % __pyx_checksum) + * __pyx_result = ThreadTracer.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_ThreadTracer(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_ThreadTracer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_14_pydevd_bundle_13pydevd_cython___pyx_unpickle_ThreadTracer__set_state(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_ThreadTracer__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(2, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->_args); + __Pyx_DECREF(__pyx_v___pyx_result->_args); + __pyx_v___pyx_result->_args = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(2, 13, __pyx_L1_error) + } + __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_4 = ((__pyx_t_3 > 1) != 0); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(2, 13, __pyx_L1_error) + __pyx_t_5 = (__pyx_t_4 != 0); + __pyx_t_2 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[1]) # <<<<<<<<<<<<<< + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(2, 14, __pyx_L1_error) + } + __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[1]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_ThreadTracer__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_ThreadTracer__set_state(ThreadTracer __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython.__pyx_unpickle_ThreadTracer__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)o); + p->pydev_step_stop = Py_None; Py_INCREF(Py_None); + p->pydev_smart_step_stop = Py_None; Py_INCREF(Py_None); + p->pydev_call_from_jinja2 = Py_None; Py_INCREF(Py_None); + p->pydev_call_inside_jinja2 = Py_None; Py_INCREF(Py_None); + p->conditional_breakpoint_exception = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->pydev_message = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->pydev_func_name = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->trace_suspend_type = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->top_level_thread_tracer_no_back_frames = Py_None; Py_INCREF(Py_None); + p->top_level_thread_tracer_unhandled = Py_None; Py_INCREF(Py_None); + p->thread_tracer = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo(PyObject *o) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->pydev_step_stop); + Py_CLEAR(p->pydev_smart_step_stop); + Py_CLEAR(p->pydev_call_from_jinja2); + Py_CLEAR(p->pydev_call_inside_jinja2); + Py_CLEAR(p->conditional_breakpoint_exception); + Py_CLEAR(p->pydev_message); + Py_CLEAR(p->pydev_func_name); + Py_CLEAR(p->trace_suspend_type); + Py_CLEAR(p->top_level_thread_tracer_no_back_frames); + Py_CLEAR(p->top_level_thread_tracer_unhandled); + Py_CLEAR(p->thread_tracer); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)o; + if (p->pydev_step_stop) { + e = (*v)(p->pydev_step_stop, a); if (e) return e; + } + if (p->pydev_smart_step_stop) { + e = (*v)(p->pydev_smart_step_stop, a); if (e) return e; + } + if (p->pydev_call_from_jinja2) { + e = (*v)(p->pydev_call_from_jinja2, a); if (e) return e; + } + if (p->pydev_call_inside_jinja2) { + e = (*v)(p->pydev_call_inside_jinja2, a); if (e) return e; + } + if (p->conditional_breakpoint_exception) { + e = (*v)(p->conditional_breakpoint_exception, a); if (e) return e; + } + if (p->top_level_thread_tracer_no_back_frames) { + e = (*v)(p->top_level_thread_tracer_no_back_frames, a); if (e) return e; + } + if (p->top_level_thread_tracer_unhandled) { + e = (*v)(p->top_level_thread_tracer_unhandled, a); if (e) return e; + } + if (p->thread_tracer) { + e = (*v)(p->thread_tracer, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)o; + tmp = ((PyObject*)p->pydev_step_stop); + p->pydev_step_stop = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->pydev_smart_step_stop); + p->pydev_smart_step_stop = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->pydev_call_from_jinja2); + p->pydev_call_from_jinja2 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->pydev_call_inside_jinja2); + p->pydev_call_inside_jinja2 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->conditional_breakpoint_exception); + p->conditional_breakpoint_exception = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->top_level_thread_tracer_no_back_frames); + p->top_level_thread_tracer_no_back_frames = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->top_level_thread_tracer_unhandled); + p->top_level_thread_tracer_unhandled = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->thread_tracer); + p->thread_tracer = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_state(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_state(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_11pydev_state_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_stop(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_stop(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_step_stop_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_original_step_cmd(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_original_step_cmd(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_23pydev_original_step_cmd_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_cmd(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_cmd(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_14pydev_step_cmd_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_notify_kill(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_notify_kill(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_17pydev_notify_kill_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_smart_step_stop(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_smart_step_stop(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_21pydev_smart_step_stop_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_django_resolve_frame(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_django_resolve_frame(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_26pydev_django_resolve_frame_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_from_jinja2(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_from_jinja2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22pydev_call_from_jinja2_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_inside_jinja2(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_inside_jinja2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_24pydev_call_inside_jinja2_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_is_tracing(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_is_tracing(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_10is_tracing_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_conditional_breakpoint_exception(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_conditional_breakpoint_exception(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_32conditional_breakpoint_exception_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_message(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_message(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13pydev_message_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspend_type(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspend_type(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_12suspend_type_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_next_line(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_next_line(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_next_line_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_func_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_func_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_15pydev_func_name_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspended_at_unhandled(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspended_at_unhandled(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_22suspended_at_unhandled_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_trace_suspend_type(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_trace_suspend_type(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_18trace_suspend_type_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_no_back_frames(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_no_back_frames(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_38top_level_thread_tracer_no_back_frames_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_unhandled(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_unhandled(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_33top_level_thread_tracer_unhandled_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_thread_tracer(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_thread_tracer(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_13thread_tracer_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo[] = { + {"get_topmost_frame", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_3get_topmost_frame, METH_O, __pyx_doc_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_2get_topmost_frame}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo[] = { + {(char *)"pydev_state", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_state, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_state, (char *)0, 0}, + {(char *)"pydev_step_stop", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_stop, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_stop, (char *)0, 0}, + {(char *)"pydev_original_step_cmd", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_original_step_cmd, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_original_step_cmd, (char *)0, 0}, + {(char *)"pydev_step_cmd", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_cmd, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_step_cmd, (char *)0, 0}, + {(char *)"pydev_notify_kill", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_notify_kill, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_notify_kill, (char *)0, 0}, + {(char *)"pydev_smart_step_stop", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_smart_step_stop, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_smart_step_stop, (char *)0, 0}, + {(char *)"pydev_django_resolve_frame", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_django_resolve_frame, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_django_resolve_frame, (char *)0, 0}, + {(char *)"pydev_call_from_jinja2", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_from_jinja2, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_from_jinja2, (char *)0, 0}, + {(char *)"pydev_call_inside_jinja2", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_inside_jinja2, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_call_inside_jinja2, (char *)0, 0}, + {(char *)"is_tracing", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_is_tracing, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_is_tracing, (char *)0, 0}, + {(char *)"conditional_breakpoint_exception", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_conditional_breakpoint_exception, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_conditional_breakpoint_exception, (char *)0, 0}, + {(char *)"pydev_message", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_message, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_message, (char *)0, 0}, + {(char *)"suspend_type", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspend_type, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspend_type, (char *)0, 0}, + {(char *)"pydev_next_line", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_next_line, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_next_line, (char *)0, 0}, + {(char *)"pydev_func_name", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_func_name, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_pydev_func_name, (char *)0, 0}, + {(char *)"suspended_at_unhandled", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspended_at_unhandled, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_suspended_at_unhandled, (char *)0, 0}, + {(char *)"trace_suspend_type", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_trace_suspend_type, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_trace_suspend_type, (char *)0, 0}, + {(char *)"top_level_thread_tracer_no_back_frames", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_no_back_frames, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_no_back_frames, (char *)0, 0}, + {(char *)"top_level_thread_tracer_unhandled", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_unhandled, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_top_level_thread_tracer_unhandled, (char *)0, 0}, + {(char *)"thread_tracer", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_thread_tracer, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_thread_tracer, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_bundle.pydevd_cython.PyDBAdditionalThreadInfo", /*tp_name*/ + sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_5__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo, /*tp_traverse*/ + __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_24PyDBAdditionalThreadInfo_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; +static struct __pyx_vtabstruct_14_pydevd_bundle_13pydevd_cython_PyDBFrame __pyx_vtable_14_pydevd_bundle_13pydevd_cython_PyDBFrame; + +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_PyDBFrame(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)o); + p->__pyx_vtab = __pyx_vtabptr_14_pydevd_bundle_13pydevd_cython_PyDBFrame; + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_PyDBFrame(PyObject *o) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->_args); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_PyDBFrame(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)o; + if (p->_args) { + e = (*v)(p->_args, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_PyDBFrame(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *)o; + tmp = ((PyObject*)p->_args); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_14_pydevd_bundle_13pydevd_cython_PyDBFrame[] = { + {"set_suspend", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_3set_suspend, METH_VARARGS|METH_KEYWORDS, 0}, + {"do_wait_suspend", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_5do_wait_suspend, METH_VARARGS|METH_KEYWORDS, 0}, + {"trace_exception", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_7trace_exception, METH_VARARGS|METH_KEYWORDS, 0}, + {"trace_return", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_9trace_return, METH_VARARGS|METH_KEYWORDS, 0}, + {"should_stop_on_exception", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_11should_stop_on_exception, METH_VARARGS|METH_KEYWORDS, 0}, + {"handle_exception", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_13handle_exception, METH_VARARGS|METH_KEYWORDS, 0}, + {"get_func_name", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_15get_func_name, METH_O, 0}, + {"show_return_values", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_17show_return_values, METH_VARARGS|METH_KEYWORDS, 0}, + {"remove_return_values", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_19remove_return_values, METH_VARARGS|METH_KEYWORDS, 0}, + {"trace_dispatch", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_21trace_dispatch, METH_VARARGS|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_23__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_25__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_bundle.pydevd_cython.PyDBFrame", /*tp_name*/ + sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_PyDBFrame, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_PyDBFrame, /*tp_traverse*/ + __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_PyDBFrame, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_14_pydevd_bundle_13pydevd_cython_PyDBFrame, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_14_pydevd_bundle_13pydevd_cython_PyDBFrame, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)o); + p->method_object = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper(PyObject *o) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->method_object); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)o; + if (p->method_object) { + e = (*v)(p->method_object, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper *)o; + tmp = ((PyObject*)p->method_object); + p->method_object = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper[] = { + {"get_method_object", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_5get_method_object, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_bundle.pydevd_cython.SafeCallWrapper", /*tp_name*/ + sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_3__call__, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper, /*tp_traverse*/ + __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_15SafeCallWrapper_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)o); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions(PyObject *o) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->_args); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)o; + if (p->_args) { + e = (*v)(p->_args, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions *)o; + tmp = ((PyObject*)p->_args); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions__args(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions__args(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5_args_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions[] = { + {"trace_unhandled_exceptions", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_3trace_unhandled_exceptions, METH_VARARGS|METH_KEYWORDS, 0}, + {"get_trace_dispatch_func", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_5get_trace_dispatch_func, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions[] = { + {(char *)"_args", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions__args, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions__args, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_bundle.pydevd_cython.TopLevelThreadTracerOnlyUnhandledExceptions", /*tp_name*/ + sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions, /*tp_traverse*/ + __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_43TopLevelThreadTracerOnlyUnhandledExceptions_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)o); + p->_frame_trace_dispatch = Py_None; Py_INCREF(Py_None); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->_try_except_info = Py_None; Py_INCREF(Py_None); + p->_last_exc_arg = Py_None; Py_INCREF(Py_None); + p->_raise_lines = ((PyObject*)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame(PyObject *o) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->_frame_trace_dispatch); + Py_CLEAR(p->_args); + Py_CLEAR(p->_try_except_info); + Py_CLEAR(p->_last_exc_arg); + Py_CLEAR(p->_raise_lines); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)o; + if (p->_frame_trace_dispatch) { + e = (*v)(p->_frame_trace_dispatch, a); if (e) return e; + } + if (p->_args) { + e = (*v)(p->_args, a); if (e) return e; + } + if (p->_try_except_info) { + e = (*v)(p->_try_except_info, a); if (e) return e; + } + if (p->_last_exc_arg) { + e = (*v)(p->_last_exc_arg, a); if (e) return e; + } + if (p->_raise_lines) { + e = (*v)(p->_raise_lines, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame *)o; + tmp = ((PyObject*)p->_frame_trace_dispatch); + p->_frame_trace_dispatch = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_args); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_try_except_info); + p->_try_except_info = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_last_exc_arg); + p->_last_exc_arg = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_raise_lines); + p->_raise_lines = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__frame_trace_dispatch(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__frame_trace_dispatch(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_21_frame_trace_dispatch_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__args(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__args(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5_args_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__try_except_info(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__try_except_info(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_try_except_info_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_exc_arg(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_exc_arg(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_13_last_exc_arg_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__raise_lines(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__raise_lines(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_12_raise_lines_5__del__(o); + } +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_raise_line(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_raise_line(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_16_last_raise_line_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame[] = { + {"trace_dispatch_and_unhandled_exceptions", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_3trace_dispatch_and_unhandled_exceptions, METH_VARARGS|METH_KEYWORDS, 0}, + {"get_trace_dispatch_func", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_5get_trace_dispatch_func, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_7__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_9__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame[] = { + {(char *)"_frame_trace_dispatch", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__frame_trace_dispatch, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__frame_trace_dispatch, (char *)0, 0}, + {(char *)"_args", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__args, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__args, (char *)0, 0}, + {(char *)"_try_except_info", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__try_except_info, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__try_except_info, (char *)0, 0}, + {(char *)"_last_exc_arg", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_exc_arg, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_exc_arg, (char *)0, 0}, + {(char *)"_raise_lines", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__raise_lines, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__raise_lines, (char *)0, 0}, + {(char *)"_last_raise_line", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_raise_line, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame__last_raise_line, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_bundle.pydevd_cython.TopLevelThreadTracerNoBackFrame", /*tp_name*/ + sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame, /*tp_traverse*/ + __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_31TopLevelThreadTracerNoBackFrame_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_14_pydevd_bundle_13pydevd_cython_ThreadTracer(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)o); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_ThreadTracer(PyObject *o) { + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->_args); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_ThreadTracer(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)o; + if (p->_args) { + e = (*v)(p->_args, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_ThreadTracer(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *p = (struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer *)o; + tmp = ((PyObject*)p->_args); + p->_args = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_14_pydevd_bundle_13pydevd_cython_12ThreadTracer__args(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_1__get__(o); +} + +static int __pyx_setprop_14_pydevd_bundle_13pydevd_cython_12ThreadTracer__args(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_3__set__(o, v); + } + else { + return __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5_args_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_14_pydevd_bundle_13pydevd_cython_ThreadTracer[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_5__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_7__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_14_pydevd_bundle_13pydevd_cython_ThreadTracer[] = { + {(char *)"_args", __pyx_getprop_14_pydevd_bundle_13pydevd_cython_12ThreadTracer__args, __pyx_setprop_14_pydevd_bundle_13pydevd_cython_12ThreadTracer__args, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_bundle.pydevd_cython.ThreadTracer", /*tp_name*/ + sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_ThreadTracer), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_14_pydevd_bundle_13pydevd_cython_ThreadTracer, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_3__call__, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_14_pydevd_bundle_13pydevd_cython_ThreadTracer, /*tp_traverse*/ + __pyx_tp_clear_14_pydevd_bundle_13pydevd_cython_ThreadTracer, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_14_pydevd_bundle_13pydevd_cython_ThreadTracer, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_14_pydevd_bundle_13pydevd_cython_ThreadTracer, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_14_pydevd_bundle_13pydevd_cython_ThreadTracer, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_pydevd_cython(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_pydevd_cython}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "pydevd_cython", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 1, 0}, + {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, + {&__pyx_n_s_ALL, __pyx_k_ALL, sizeof(__pyx_k_ALL), 0, 0, 1, 1}, + {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1}, + {&__pyx_n_s_CO_GENERATOR, __pyx_k_CO_GENERATOR, sizeof(__pyx_k_CO_GENERATOR), 0, 0, 1, 1}, + {&__pyx_n_s_DEBUG_START, __pyx_k_DEBUG_START, sizeof(__pyx_k_DEBUG_START), 0, 0, 1, 1}, + {&__pyx_n_s_DEBUG_START_PY3K, __pyx_k_DEBUG_START_PY3K, sizeof(__pyx_k_DEBUG_START_PY3K), 0, 0, 1, 1}, + {&__pyx_n_s_GeneratorExit, __pyx_k_GeneratorExit, sizeof(__pyx_k_GeneratorExit), 0, 0, 1, 1}, + {&__pyx_n_s_IGNORE_EXCEPTION_TAG, __pyx_k_IGNORE_EXCEPTION_TAG, sizeof(__pyx_k_IGNORE_EXCEPTION_TAG), 0, 0, 1, 1}, + {&__pyx_n_s_IS_JYTHON, __pyx_k_IS_JYTHON, sizeof(__pyx_k_IS_JYTHON), 0, 0, 1, 1}, + {&__pyx_n_s_IS_PY3K, __pyx_k_IS_PY3K, sizeof(__pyx_k_IS_PY3K), 0, 0, 1, 1}, + {&__pyx_kp_s_IgnoreException, __pyx_k_IgnoreException, sizeof(__pyx_k_IgnoreException), 0, 0, 1, 0}, + {&__pyx_kp_s_Ignore_exception_s_in_library_s, __pyx_k_Ignore_exception_s_in_library_s, sizeof(__pyx_k_Ignore_exception_s_in_library_s), 0, 0, 1, 0}, + {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0x3d, __pyx_k_Incompatible_checksums_s_vs_0x3d, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x3d), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0x6a, __pyx_k_Incompatible_checksums_s_vs_0x6a, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x6a), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0x77, __pyx_k_Incompatible_checksums_s_vs_0x77, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x77), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0xf3, __pyx_k_Incompatible_checksums_s_vs_0xf3, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xf3), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0xfa, __pyx_k_Incompatible_checksums_s_vs_0xfa, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xfa), 0, 0, 1, 0}, + {&__pyx_n_s_KeyboardInterrupt, __pyx_k_KeyboardInterrupt, sizeof(__pyx_k_KeyboardInterrupt), 0, 0, 1, 1}, + {&__pyx_n_s_Lock, __pyx_k_Lock, sizeof(__pyx_k_Lock), 0, 0, 1, 1}, + {&__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER, __pyx_k_NORM_PATHS_AND_BASE_CONTAINER, sizeof(__pyx_k_NORM_PATHS_AND_BASE_CONTAINER), 0, 0, 1, 1}, + {&__pyx_n_s_NO_FTRACE, __pyx_k_NO_FTRACE, sizeof(__pyx_k_NO_FTRACE), 0, 0, 1, 1}, + {&__pyx_n_s_NoSuchFieldException, __pyx_k_NoSuchFieldException, sizeof(__pyx_k_NoSuchFieldException), 0, 0, 1, 1}, + {&__pyx_n_s_None, __pyx_k_None, sizeof(__pyx_k_None), 0, 0, 1, 1}, + {&__pyx_n_s_PYDEV_FILE, __pyx_k_PYDEV_FILE, sizeof(__pyx_k_PYDEV_FILE), 0, 0, 1, 1}, + {&__pyx_n_s_PYTHON_SUSPEND, __pyx_k_PYTHON_SUSPEND, sizeof(__pyx_k_PYTHON_SUSPEND), 0, 0, 1, 1}, + {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_PyDBAdditionalThreadInfo, __pyx_k_PyDBAdditionalThreadInfo, sizeof(__pyx_k_PyDBAdditionalThreadInfo), 0, 0, 1, 1}, + {&__pyx_n_s_PyDBFrame, __pyx_k_PyDBFrame, sizeof(__pyx_k_PyDBFrame), 0, 0, 1, 1}, + {&__pyx_n_s_RETURN_VALUES_DICT, __pyx_k_RETURN_VALUES_DICT, sizeof(__pyx_k_RETURN_VALUES_DICT), 0, 0, 1, 1}, + {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, + {&__pyx_n_s_STATE_RUN, __pyx_k_STATE_RUN, sizeof(__pyx_k_STATE_RUN), 0, 0, 1, 1}, + {&__pyx_n_s_SafeCallWrapper, __pyx_k_SafeCallWrapper, sizeof(__pyx_k_SafeCallWrapper), 0, 0, 1, 1}, + {&__pyx_kp_s_State_s_Stop_s_Cmd_s_Kill_s, __pyx_k_State_s_Stop_s_Cmd_s_Kill_s, sizeof(__pyx_k_State_s_Stop_s_Cmd_s_Kill_s), 0, 0, 1, 0}, + {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1}, + {&__pyx_n_s_SystemExit, __pyx_k_SystemExit, sizeof(__pyx_k_SystemExit), 0, 0, 1, 1}, + {&__pyx_n_s_TRACE_PROPERTY, __pyx_k_TRACE_PROPERTY, sizeof(__pyx_k_TRACE_PROPERTY), 0, 0, 1, 1}, + {&__pyx_n_s_Thread, __pyx_k_Thread, sizeof(__pyx_k_Thread), 0, 0, 1, 1}, + {&__pyx_n_s_ThreadStateMapping, __pyx_k_ThreadStateMapping, sizeof(__pyx_k_ThreadStateMapping), 0, 0, 1, 1}, + {&__pyx_n_s_ThreadTracer, __pyx_k_ThreadTracer, sizeof(__pyx_k_ThreadTracer), 0, 0, 1, 1}, + {&__pyx_n_s_TopLevelThreadTracerNoBackFrame, __pyx_k_TopLevelThreadTracerNoBackFrame, sizeof(__pyx_k_TopLevelThreadTracerNoBackFrame), 0, 0, 1, 1}, + {&__pyx_n_s_TopLevelThreadTracerOnlyUnhandle, __pyx_k_TopLevelThreadTracerOnlyUnhandle, sizeof(__pyx_k_TopLevelThreadTracerOnlyUnhandle), 0, 0, 1, 1}, + {&__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES, __pyx_k_USE_CUSTOM_SYS_CURRENT_FRAMES, sizeof(__pyx_k_USE_CUSTOM_SYS_CURRENT_FRAMES), 0, 0, 1, 1}, + {&__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA, __pyx_k_USE_CUSTOM_SYS_CURRENT_FRAMES_MA, sizeof(__pyx_k_USE_CUSTOM_SYS_CURRENT_FRAMES_MA), 0, 0, 1, 1}, + {&__pyx_kp_s_Unable_to_proceed_sys__current_f, __pyx_k_Unable_to_proceed_sys__current_f, sizeof(__pyx_k_Unable_to_proceed_sys__current_f), 0, 0, 1, 0}, + {&__pyx_kp_s_Using_Cython_speedups, __pyx_k_Using_Cython_speedups, sizeof(__pyx_k_Using_Cython_speedups), 0, 0, 1, 0}, + {&__pyx_kp_s__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 1, 0}, + {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0}, + {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0}, + {&__pyx_kp_s__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 1, 0}, + {&__pyx_n_s_accessible, __pyx_k_accessible, sizeof(__pyx_k_accessible), 0, 0, 1, 1}, + {&__pyx_n_s_add_command, __pyx_k_add_command, sizeof(__pyx_k_add_command), 0, 0, 1, 1}, + {&__pyx_n_s_add_exception_to_frame, __pyx_k_add_exception_to_frame, sizeof(__pyx_k_add_exception_to_frame), 0, 0, 1, 1}, + {&__pyx_n_s_additional_info, __pyx_k_additional_info, sizeof(__pyx_k_additional_info), 0, 0, 1, 1}, + {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, + {&__pyx_n_s_apply_files_filter, __pyx_k_apply_files_filter, sizeof(__pyx_k_apply_files_filter), 0, 0, 1, 1}, + {&__pyx_n_s_apply_to_settrace, __pyx_k_apply_to_settrace, sizeof(__pyx_k_apply_to_settrace), 0, 0, 1, 1}, + {&__pyx_n_s_arg, __pyx_k_arg, sizeof(__pyx_k_arg), 0, 0, 1, 1}, + {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, + {&__pyx_n_s_args_2, __pyx_k_args_2, sizeof(__pyx_k_args_2), 0, 0, 1, 1}, + {&__pyx_n_s_as_array, __pyx_k_as_array, sizeof(__pyx_k_as_array), 0, 0, 1, 1}, + {&__pyx_n_s_asyncio_analyser, __pyx_k_asyncio_analyser, sizeof(__pyx_k_asyncio_analyser), 0, 0, 1, 1}, + {&__pyx_n_s_basename, __pyx_k_basename, sizeof(__pyx_k_basename), 0, 0, 1, 1}, + {&__pyx_n_s_bootstrap, __pyx_k_bootstrap, sizeof(__pyx_k_bootstrap), 0, 0, 1, 1}, + {&__pyx_n_s_bootstrap_2, __pyx_k_bootstrap_2, sizeof(__pyx_k_bootstrap_2), 0, 0, 1, 1}, + {&__pyx_n_s_bootstrap_inner, __pyx_k_bootstrap_inner, sizeof(__pyx_k_bootstrap_inner), 0, 0, 1, 1}, + {&__pyx_n_s_bootstrap_inner_2, __pyx_k_bootstrap_inner_2, sizeof(__pyx_k_bootstrap_inner_2), 0, 0, 1, 1}, + {&__pyx_n_s_break_on_caught_exceptions, __pyx_k_break_on_caught_exceptions, sizeof(__pyx_k_break_on_caught_exceptions), 0, 0, 1, 1}, + {&__pyx_n_s_breakpoints, __pyx_k_breakpoints, sizeof(__pyx_k_breakpoints), 0, 0, 1, 1}, + {&__pyx_n_s_cachedThreadState, __pyx_k_cachedThreadState, sizeof(__pyx_k_cachedThreadState), 0, 0, 1, 1}, + {&__pyx_n_s_call, __pyx_k_call, sizeof(__pyx_k_call), 0, 0, 1, 1}, + {&__pyx_n_s_call_2, __pyx_k_call_2, sizeof(__pyx_k_call_2), 0, 0, 1, 1}, + {&__pyx_n_s_can_skip, __pyx_k_can_skip, sizeof(__pyx_k_can_skip), 0, 0, 1, 1}, + {&__pyx_n_s_checkcache, __pyx_k_checkcache, sizeof(__pyx_k_checkcache), 0, 0, 1, 1}, + {&__pyx_n_s_clear, __pyx_k_clear, sizeof(__pyx_k_clear), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_cmd_factory, __pyx_k_cmd_factory, sizeof(__pyx_k_cmd_factory), 0, 0, 1, 1}, + {&__pyx_n_s_cmd_step_into, __pyx_k_cmd_step_into, sizeof(__pyx_k_cmd_step_into), 0, 0, 1, 1}, + {&__pyx_n_s_cmd_step_over, __pyx_k_cmd_step_over, sizeof(__pyx_k_cmd_step_over), 0, 0, 1, 1}, + {&__pyx_n_s_co_filename, __pyx_k_co_filename, sizeof(__pyx_k_co_filename), 0, 0, 1, 1}, + {&__pyx_n_s_co_firstlineno, __pyx_k_co_firstlineno, sizeof(__pyx_k_co_firstlineno), 0, 0, 1, 1}, + {&__pyx_n_s_co_flags, __pyx_k_co_flags, sizeof(__pyx_k_co_flags), 0, 0, 1, 1}, + {&__pyx_n_s_co_name, __pyx_k_co_name, sizeof(__pyx_k_co_name), 0, 0, 1, 1}, + {&__pyx_n_s_collect_try_except_info, __pyx_k_collect_try_except_info, sizeof(__pyx_k_collect_try_except_info), 0, 0, 1, 1}, + {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1}, + {&__pyx_n_s_condition, __pyx_k_condition, sizeof(__pyx_k_condition), 0, 0, 1, 1}, + {&__pyx_n_s_current_frames, __pyx_k_current_frames, sizeof(__pyx_k_current_frames), 0, 0, 1, 1}, + {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_n_s_dict_iter_values, __pyx_k_dict_iter_values, sizeof(__pyx_k_dict_iter_values), 0, 0, 1, 1}, + {&__pyx_n_s_disable_tracing, __pyx_k_disable_tracing, sizeof(__pyx_k_disable_tracing), 0, 0, 1, 1}, + {&__pyx_n_s_do_wait_suspend, __pyx_k_do_wait_suspend, sizeof(__pyx_k_do_wait_suspend), 0, 0, 1, 1}, + {&__pyx_n_s_enable_tracing, __pyx_k_enable_tracing, sizeof(__pyx_k_enable_tracing), 0, 0, 1, 1}, + {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, + {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1}, + {&__pyx_n_s_entrySet, __pyx_k_entrySet, sizeof(__pyx_k_entrySet), 0, 0, 1, 1}, + {&__pyx_n_s_event, __pyx_k_event, sizeof(__pyx_k_event), 0, 0, 1, 1}, + {&__pyx_n_s_except_line, __pyx_k_except_line, sizeof(__pyx_k_except_line), 0, 0, 1, 1}, + {&__pyx_n_s_exception, __pyx_k_exception, sizeof(__pyx_k_exception), 0, 0, 1, 1}, + {&__pyx_n_s_exception_break, __pyx_k_exception_break, sizeof(__pyx_k_exception_break), 0, 0, 1, 1}, + {&__pyx_n_s_exclude_exception_by_filter, __pyx_k_exclude_exception_by_filter, sizeof(__pyx_k_exclude_exception_by_filter), 0, 0, 1, 1}, + {&__pyx_n_s_exec, __pyx_k_exec, sizeof(__pyx_k_exec), 0, 0, 1, 1}, + {&__pyx_n_s_execfile, __pyx_k_execfile, sizeof(__pyx_k_execfile), 0, 0, 1, 1}, + {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1}, + {&__pyx_n_s_expression, __pyx_k_expression, sizeof(__pyx_k_expression), 0, 0, 1, 1}, + {&__pyx_n_s_f_back, __pyx_k_f_back, sizeof(__pyx_k_f_back), 0, 0, 1, 1}, + {&__pyx_n_s_f_code, __pyx_k_f_code, sizeof(__pyx_k_f_code), 0, 0, 1, 1}, + {&__pyx_n_s_f_globals, __pyx_k_f_globals, sizeof(__pyx_k_f_globals), 0, 0, 1, 1}, + {&__pyx_n_s_f_lineno, __pyx_k_f_lineno, sizeof(__pyx_k_f_lineno), 0, 0, 1, 1}, + {&__pyx_n_s_f_locals, __pyx_k_f_locals, sizeof(__pyx_k_f_locals), 0, 0, 1, 1}, + {&__pyx_n_s_f_trace, __pyx_k_f_trace, sizeof(__pyx_k_f_trace), 0, 0, 1, 1}, + {&__pyx_n_s_f_unhandled, __pyx_k_f_unhandled, sizeof(__pyx_k_f_unhandled), 0, 0, 1, 1}, + {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1}, + {&__pyx_n_s_filename_to_lines_where_exceptio, __pyx_k_filename_to_lines_where_exceptio, sizeof(__pyx_k_filename_to_lines_where_exceptio), 0, 0, 1, 1}, + {&__pyx_n_s_filename_to_stat_info, __pyx_k_filename_to_stat_info, sizeof(__pyx_k_filename_to_stat_info), 0, 0, 1, 1}, + {&__pyx_n_s_finish_debugging_session, __pyx_k_finish_debugging_session, sizeof(__pyx_k_finish_debugging_session), 0, 0, 1, 1}, + {&__pyx_n_s_fix_top_level_trace_and_get_trac, __pyx_k_fix_top_level_trace_and_get_trac, sizeof(__pyx_k_fix_top_level_trace_and_get_trac), 0, 0, 1, 1}, + {&__pyx_n_s_force_only_unhandled_tracer, __pyx_k_force_only_unhandled_tracer, sizeof(__pyx_k_force_only_unhandled_tracer), 0, 0, 1, 1}, + {&__pyx_n_s_frame, __pyx_k_frame, sizeof(__pyx_k_frame), 0, 0, 1, 1}, + {&__pyx_n_s_frame_trace_dispatch, __pyx_k_frame_trace_dispatch, sizeof(__pyx_k_frame_trace_dispatch), 0, 0, 1, 1}, + {&__pyx_n_s_func_name, __pyx_k_func_name, sizeof(__pyx_k_func_name), 0, 0, 1, 1}, + {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, + {&__pyx_n_s_getDeclaredField, __pyx_k_getDeclaredField, sizeof(__pyx_k_getDeclaredField), 0, 0, 1, 1}, + {&__pyx_n_s_getId, __pyx_k_getId, sizeof(__pyx_k_getId), 0, 0, 1, 1}, + {&__pyx_n_s_getKey, __pyx_k_getKey, sizeof(__pyx_k_getKey), 0, 0, 1, 1}, + {&__pyx_n_s_getValue, __pyx_k_getValue, sizeof(__pyx_k_getValue), 0, 0, 1, 1}, + {&__pyx_n_s_get_abs_path_real_path_and_base, __pyx_k_get_abs_path_real_path_and_base, sizeof(__pyx_k_get_abs_path_real_path_and_base), 0, 0, 1, 1}, + {&__pyx_n_s_get_abs_path_real_path_and_base_2, __pyx_k_get_abs_path_real_path_and_base_2, sizeof(__pyx_k_get_abs_path_real_path_and_base_2), 0, 0, 1, 1}, + {&__pyx_n_s_get_breakpoint, __pyx_k_get_breakpoint, sizeof(__pyx_k_get_breakpoint), 0, 0, 1, 1}, + {&__pyx_n_s_get_clsname_for_code, __pyx_k_get_clsname_for_code, sizeof(__pyx_k_get_clsname_for_code), 0, 0, 1, 1}, + {&__pyx_n_s_get_current_thread_id, __pyx_k_get_current_thread_id, sizeof(__pyx_k_get_current_thread_id), 0, 0, 1, 1}, + {&__pyx_n_s_get_exception_breakpoint, __pyx_k_get_exception_breakpoint, sizeof(__pyx_k_get_exception_breakpoint), 0, 0, 1, 1}, + {&__pyx_n_s_get_file_type, __pyx_k_get_file_type, sizeof(__pyx_k_get_file_type), 0, 0, 1, 1}, + {&__pyx_n_s_get_func_name, __pyx_k_get_func_name, sizeof(__pyx_k_get_func_name), 0, 0, 1, 1}, + {&__pyx_n_s_get_trace_dispatch_func, __pyx_k_get_trace_dispatch_func, sizeof(__pyx_k_get_trace_dispatch_func), 0, 0, 1, 1}, + {&__pyx_n_s_getline, __pyx_k_getline, sizeof(__pyx_k_getline), 0, 0, 1, 1}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_globalThreadStates, __pyx_k_globalThreadStates, sizeof(__pyx_k_globalThreadStates), 0, 0, 1, 1}, + {&__pyx_n_s_global_cache_frame_skips, __pyx_k_global_cache_frame_skips, sizeof(__pyx_k_global_cache_frame_skips), 0, 0, 1, 1}, + {&__pyx_n_s_global_cache_skips, __pyx_k_global_cache_skips, sizeof(__pyx_k_global_cache_skips), 0, 0, 1, 1}, + {&__pyx_n_s_global_notify_skipped_step_in_l, __pyx_k_global_notify_skipped_step_in_l, sizeof(__pyx_k_global_notify_skipped_step_in_l), 0, 0, 1, 1}, + {&__pyx_n_s_handle_breakpoint_condition, __pyx_k_handle_breakpoint_condition, sizeof(__pyx_k_handle_breakpoint_condition), 0, 0, 1, 1}, + {&__pyx_n_s_handle_breakpoint_expression, __pyx_k_handle_breakpoint_expression, sizeof(__pyx_k_handle_breakpoint_expression), 0, 0, 1, 1}, + {&__pyx_n_s_handle_exception, __pyx_k_handle_exception, sizeof(__pyx_k_handle_exception), 0, 0, 1, 1}, + {&__pyx_n_s_has_condition, __pyx_k_has_condition, sizeof(__pyx_k_has_condition), 0, 0, 1, 1}, + {&__pyx_n_s_has_plugin_exception_breaks, __pyx_k_has_plugin_exception_breaks, sizeof(__pyx_k_has_plugin_exception_breaks), 0, 0, 1, 1}, + {&__pyx_n_s_has_plugin_line_breaks, __pyx_k_has_plugin_line_breaks, sizeof(__pyx_k_has_plugin_line_breaks), 0, 0, 1, 1}, + {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1}, + {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, + {&__pyx_n_s_ident, __pyx_k_ident, sizeof(__pyx_k_ident), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_exception_trace, __pyx_k_ignore_exception_trace, sizeof(__pyx_k_ignore_exception_trace), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_exceptions_thrown_in_line, __pyx_k_ignore_exceptions_thrown_in_line, sizeof(__pyx_k_ignore_exceptions_thrown_in_line), 0, 0, 1, 1}, + {&__pyx_n_s_ignore_system_exit_code, __pyx_k_ignore_system_exit_code, sizeof(__pyx_k_ignore_system_exit_code), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_in_project_scope, __pyx_k_in_project_scope, sizeof(__pyx_k_in_project_scope), 0, 0, 1, 1}, + {&__pyx_n_s_inspect, __pyx_k_inspect, sizeof(__pyx_k_inspect), 0, 0, 1, 1}, + {&__pyx_kp_s_invalid, __pyx_k_invalid, sizeof(__pyx_k_invalid), 0, 0, 1, 0}, + {&__pyx_n_s_is_files_filter_enabled, __pyx_k_is_files_filter_enabled, sizeof(__pyx_k_is_files_filter_enabled), 0, 0, 1, 1}, + {&__pyx_n_s_is_line_in_except_block, __pyx_k_is_line_in_except_block, sizeof(__pyx_k_is_line_in_except_block), 0, 0, 1, 1}, + {&__pyx_n_s_is_line_in_try_block, __pyx_k_is_line_in_try_block, sizeof(__pyx_k_is_line_in_try_block), 0, 0, 1, 1}, + {&__pyx_n_s_is_logpoint, __pyx_k_is_logpoint, sizeof(__pyx_k_is_logpoint), 0, 0, 1, 1}, + {&__pyx_n_s_is_thread_alive, __pyx_k_is_thread_alive, sizeof(__pyx_k_is_thread_alive), 0, 0, 1, 1}, + {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1}, + {&__pyx_n_s_java_lang, __pyx_k_java_lang, sizeof(__pyx_k_java_lang), 0, 0, 1, 1}, + {&__pyx_n_s_just_raised, __pyx_k_just_raised, sizeof(__pyx_k_just_raised), 0, 0, 1, 1}, + {&__pyx_n_s_kill_all_pydev_threads, __pyx_k_kill_all_pydev_threads, sizeof(__pyx_k_kill_all_pydev_threads), 0, 0, 1, 1}, + {&__pyx_n_s_kwargs, __pyx_k_kwargs, sizeof(__pyx_k_kwargs), 0, 0, 1, 1}, + {&__pyx_kp_s_lambda, __pyx_k_lambda, sizeof(__pyx_k_lambda), 0, 0, 1, 0}, + {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1}, + {&__pyx_n_s_linecache, __pyx_k_linecache, sizeof(__pyx_k_linecache), 0, 0, 1, 1}, + {&__pyx_n_s_linesep, __pyx_k_linesep, sizeof(__pyx_k_linesep), 0, 0, 1, 1}, + {&__pyx_n_s_log_event, __pyx_k_log_event, sizeof(__pyx_k_log_event), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_main_2, __pyx_k_main_2, sizeof(__pyx_k_main_2), 0, 0, 1, 1}, + {&__pyx_n_s_main_debugger, __pyx_k_main_debugger, sizeof(__pyx_k_main_debugger), 0, 0, 1, 1}, + {&__pyx_n_s_make_io_message, __pyx_k_make_io_message, sizeof(__pyx_k_make_io_message), 0, 0, 1, 1}, + {&__pyx_n_s_match, __pyx_k_match, sizeof(__pyx_k_match), 0, 0, 1, 1}, + {&__pyx_n_s_method_object, __pyx_k_method_object, sizeof(__pyx_k_method_object), 0, 0, 1, 1}, + {&__pyx_kp_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 0}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1}, + {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, + {&__pyx_n_s_notify_on_first_raise_only, __pyx_k_notify_on_first_raise_only, sizeof(__pyx_k_notify_on_first_raise_only), 0, 0, 1, 1}, + {&__pyx_n_s_notify_skipped_step_in_because_o, __pyx_k_notify_skipped_step_in_because_o, sizeof(__pyx_k_notify_skipped_step_in_because_o), 0, 0, 1, 1}, + {&__pyx_n_s_notify_thread_not_alive, __pyx_k_notify_thread_not_alive, sizeof(__pyx_k_notify_thread_not_alive), 0, 0, 1, 1}, + {&__pyx_n_s_org_python_core, __pyx_k_org_python_core, sizeof(__pyx_k_org_python_core), 0, 0, 1, 1}, + {&__pyx_n_s_original_call, __pyx_k_original_call, sizeof(__pyx_k_original_call), 0, 0, 1, 1}, + {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, + {&__pyx_n_s_os_path, __pyx_k_os_path, sizeof(__pyx_k_os_path), 0, 0, 1, 1}, + {&__pyx_n_s_output_checker_thread, __pyx_k_output_checker_thread, sizeof(__pyx_k_output_checker_thread), 0, 0, 1, 1}, + {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1}, + {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_s_plugin, __pyx_k_plugin, sizeof(__pyx_k_plugin), 0, 0, 1, 1}, + {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1}, + {&__pyx_n_s_py_db, __pyx_k_py_db, sizeof(__pyx_k_py_db), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_bundle, __pyx_k_pydev_bundle, sizeof(__pyx_k_pydev_bundle), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_bundle_pydev_is_thread_al, __pyx_k_pydev_bundle_pydev_is_thread_al, sizeof(__pyx_k_pydev_bundle_pydev_is_thread_al), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_bundle_pydev_log, __pyx_k_pydev_bundle_pydev_log, sizeof(__pyx_k_pydev_bundle_pydev_log), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_do_not_trace, __pyx_k_pydev_do_not_trace, sizeof(__pyx_k_pydev_do_not_trace), 0, 0, 1, 1}, + {&__pyx_kp_s_pydev_execfile_py, __pyx_k_pydev_execfile_py, sizeof(__pyx_k_pydev_execfile_py), 0, 0, 1, 0}, + {&__pyx_n_s_pydev_imps__pydev_saved_modules, __pyx_k_pydev_imps__pydev_saved_modules, sizeof(__pyx_k_pydev_imps__pydev_saved_modules), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_log, __pyx_k_pydev_log, sizeof(__pyx_k_pydev_log), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_log_exception, __pyx_k_pydev_log_exception, sizeof(__pyx_k_pydev_log_exception), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_monkey, __pyx_k_pydev_monkey, sizeof(__pyx_k_pydev_monkey), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd, __pyx_k_pydevd, sizeof(__pyx_k_pydevd), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle, __pyx_k_pydevd_bundle, sizeof(__pyx_k_pydevd_bundle), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_additional, __pyx_k_pydevd_bundle_pydevd_additional, sizeof(__pyx_k_pydevd_bundle_pydevd_additional), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_constants, __pyx_k_pydevd_bundle_pydevd_constants, sizeof(__pyx_k_pydevd_bundle_pydevd_constants), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_cython, __pyx_k_pydevd_bundle_pydevd_cython, sizeof(__pyx_k_pydevd_bundle_pydevd_cython), 0, 0, 1, 1}, + {&__pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_k_pydevd_bundle_pydevd_cython_pyx, sizeof(__pyx_k_pydevd_bundle_pydevd_cython_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_pydevd_bundle_pydevd_frame_util, __pyx_k_pydevd_bundle_pydevd_frame_util, sizeof(__pyx_k_pydevd_bundle_pydevd_frame_util), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_kill_all_p, __pyx_k_pydevd_bundle_pydevd_kill_all_p, sizeof(__pyx_k_pydevd_bundle_pydevd_kill_all_p), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_signature, __pyx_k_pydevd_bundle_pydevd_signature, sizeof(__pyx_k_pydevd_bundle_pydevd_signature), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_utils, __pyx_k_pydevd_bundle_pydevd_utils, sizeof(__pyx_k_pydevd_bundle_pydevd_utils), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_dont_trace, __pyx_k_pydevd_dont_trace, sizeof(__pyx_k_pydevd_dont_trace), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_file_utils, __pyx_k_pydevd_file_utils, sizeof(__pyx_k_pydevd_file_utils), 0, 0, 1, 1}, + {&__pyx_kp_s_pydevd_py, __pyx_k_pydevd_py, sizeof(__pyx_k_pydevd_py), 0, 0, 1, 0}, + {&__pyx_kp_s_pydevd_traceproperty_py, __pyx_k_pydevd_traceproperty_py, sizeof(__pyx_k_pydevd_traceproperty_py), 0, 0, 1, 0}, + {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_PyDBAdditionalThr, __pyx_k_pyx_unpickle_PyDBAdditionalThr, sizeof(__pyx_k_pyx_unpickle_PyDBAdditionalThr), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_PyDBFrame, __pyx_k_pyx_unpickle_PyDBFrame, sizeof(__pyx_k_pyx_unpickle_PyDBFrame), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_SafeCallWrapper, __pyx_k_pyx_unpickle_SafeCallWrapper, sizeof(__pyx_k_pyx_unpickle_SafeCallWrapper), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_ThreadTracer, __pyx_k_pyx_unpickle_ThreadTracer, sizeof(__pyx_k_pyx_unpickle_ThreadTracer), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_TopLevelThreadTra, __pyx_k_pyx_unpickle_TopLevelThreadTra, sizeof(__pyx_k_pyx_unpickle_TopLevelThreadTra), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_TopLevelThreadTra_2, __pyx_k_pyx_unpickle_TopLevelThreadTra_2, sizeof(__pyx_k_pyx_unpickle_TopLevelThreadTra_2), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, + {&__pyx_n_s_qname, __pyx_k_qname, sizeof(__pyx_k_qname), 0, 0, 1, 1}, + {&__pyx_n_s_quitting, __pyx_k_quitting, sizeof(__pyx_k_quitting), 0, 0, 1, 1}, + {&__pyx_n_s_raise_lines_in_except, __pyx_k_raise_lines_in_except, sizeof(__pyx_k_raise_lines_in_except), 0, 0, 1, 1}, + {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_remove_exception_from_frame, __pyx_k_remove_exception_from_frame, sizeof(__pyx_k_remove_exception_from_frame), 0, 0, 1, 1}, + {&__pyx_n_s_remove_return_values, __pyx_k_remove_return_values, sizeof(__pyx_k_remove_return_values), 0, 0, 1, 1}, + {&__pyx_n_s_remove_return_values_flag, __pyx_k_remove_return_values_flag, sizeof(__pyx_k_remove_return_values_flag), 0, 0, 1, 1}, + {&__pyx_n_s_ret, __pyx_k_ret, sizeof(__pyx_k_ret), 0, 0, 1, 1}, + {&__pyx_n_s_return, __pyx_k_return, sizeof(__pyx_k_return), 0, 0, 1, 1}, + {&__pyx_n_s_rfind, __pyx_k_rfind, sizeof(__pyx_k_rfind), 0, 0, 1, 1}, + {&__pyx_n_s_run, __pyx_k_run, sizeof(__pyx_k_run), 0, 0, 1, 1}, + {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_n_s_send_caught_exception_stack, __pyx_k_send_caught_exception_stack, sizeof(__pyx_k_send_caught_exception_stack), 0, 0, 1, 1}, + {&__pyx_n_s_send_caught_exception_stack_proc, __pyx_k_send_caught_exception_stack_proc, sizeof(__pyx_k_send_caught_exception_stack_proc), 0, 0, 1, 1}, + {&__pyx_n_s_send_signature_call_trace, __pyx_k_send_signature_call_trace, sizeof(__pyx_k_send_signature_call_trace), 0, 0, 1, 1}, + {&__pyx_n_s_send_signature_return_trace, __pyx_k_send_signature_return_trace, sizeof(__pyx_k_send_signature_return_trace), 0, 0, 1, 1}, + {&__pyx_n_s_set_additional_thread_info, __pyx_k_set_additional_thread_info, sizeof(__pyx_k_set_additional_thread_info), 0, 0, 1, 1}, + {&__pyx_n_s_set_additional_thread_info_lock, __pyx_k_set_additional_thread_info_lock, sizeof(__pyx_k_set_additional_thread_info_lock), 0, 0, 1, 1}, + {&__pyx_n_s_set_suspend, __pyx_k_set_suspend, sizeof(__pyx_k_set_suspend), 0, 0, 1, 1}, + {&__pyx_n_s_set_trace_for_frame_and_parents, __pyx_k_set_trace_for_frame_and_parents, sizeof(__pyx_k_set_trace_for_frame_and_parents), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_should_stop_on_exception, __pyx_k_should_stop_on_exception, sizeof(__pyx_k_should_stop_on_exception), 0, 0, 1, 1}, + {&__pyx_n_s_should_trace_hook, __pyx_k_should_trace_hook, sizeof(__pyx_k_should_trace_hook), 0, 0, 1, 1}, + {&__pyx_n_s_show_return_values, __pyx_k_show_return_values, sizeof(__pyx_k_show_return_values), 0, 0, 1, 1}, + {&__pyx_n_s_signature_factory, __pyx_k_signature_factory, sizeof(__pyx_k_signature_factory), 0, 0, 1, 1}, + {&__pyx_n_s_skip_on_exceptions_thrown_in_sam, __pyx_k_skip_on_exceptions_thrown_in_sam, sizeof(__pyx_k_skip_on_exceptions_thrown_in_sam), 0, 0, 1, 1}, + {&__pyx_n_s_st_mtime, __pyx_k_st_mtime, sizeof(__pyx_k_st_mtime), 0, 0, 1, 1}, + {&__pyx_n_s_st_size, __pyx_k_st_size, sizeof(__pyx_k_st_size), 0, 0, 1, 1}, + {&__pyx_n_s_stat, __pyx_k_stat, sizeof(__pyx_k_stat), 0, 0, 1, 1}, + {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1}, + {&__pyx_n_s_stop_on_unhandled_exception, __pyx_k_stop_on_unhandled_exception, sizeof(__pyx_k_stop_on_unhandled_exception), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_suspend, __pyx_k_suspend, sizeof(__pyx_k_suspend), 0, 0, 1, 1}, + {&__pyx_n_s_suspend_other_threads, __pyx_k_suspend_other_threads, sizeof(__pyx_k_suspend_other_threads), 0, 0, 1, 1}, + {&__pyx_n_s_suspend_policy, __pyx_k_suspend_policy, sizeof(__pyx_k_suspend_policy), 0, 0, 1, 1}, + {&__pyx_n_s_suspended_at_unhandled, __pyx_k_suspended_at_unhandled, sizeof(__pyx_k_suspended_at_unhandled), 0, 0, 1, 1}, + {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, + {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1}, + {&__pyx_n_s_tb_frame, __pyx_k_tb_frame, sizeof(__pyx_k_tb_frame), 0, 0, 1, 1}, + {&__pyx_n_s_tb_lineno, __pyx_k_tb_lineno, sizeof(__pyx_k_tb_lineno), 0, 0, 1, 1}, + {&__pyx_n_s_tb_next, __pyx_k_tb_next, sizeof(__pyx_k_tb_next), 0, 0, 1, 1}, + {&__pyx_n_s_termination_event_set, __pyx_k_termination_event_set, sizeof(__pyx_k_termination_event_set), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_thread, __pyx_k_thread, sizeof(__pyx_k_thread), 0, 0, 1, 1}, + {&__pyx_n_s_thread_analyser, __pyx_k_thread_analyser, sizeof(__pyx_k_thread_analyser), 0, 0, 1, 1}, + {&__pyx_n_s_thread_state, __pyx_k_thread_state, sizeof(__pyx_k_thread_state), 0, 0, 1, 1}, + {&__pyx_n_s_thread_states, __pyx_k_thread_states, sizeof(__pyx_k_thread_states), 0, 0, 1, 1}, + {&__pyx_n_s_thread_to_state, __pyx_k_thread_to_state, sizeof(__pyx_k_thread_to_state), 0, 0, 1, 1}, + {&__pyx_n_s_thread_trace_func, __pyx_k_thread_trace_func, sizeof(__pyx_k_thread_trace_func), 0, 0, 1, 1}, + {&__pyx_n_s_thread_tracer, __pyx_k_thread_tracer, sizeof(__pyx_k_thread_tracer), 0, 0, 1, 1}, + {&__pyx_n_s_threading, __pyx_k_threading, sizeof(__pyx_k_threading), 0, 0, 1, 1}, + {&__pyx_n_s_threading_active, __pyx_k_threading_active, sizeof(__pyx_k_threading_active), 0, 0, 1, 1}, + {&__pyx_n_s_threading_current_thread, __pyx_k_threading_current_thread, sizeof(__pyx_k_threading_current_thread), 0, 0, 1, 1}, + {&__pyx_n_s_threading_get_ident, __pyx_k_threading_get_ident, sizeof(__pyx_k_threading_get_ident), 0, 0, 1, 1}, + {&__pyx_n_s_tid_to_last_frame, __pyx_k_tid_to_last_frame, sizeof(__pyx_k_tid_to_last_frame), 0, 0, 1, 1}, + {&__pyx_n_s_toArray, __pyx_k_toArray, sizeof(__pyx_k_toArray), 0, 0, 1, 1}, + {&__pyx_n_s_top_level_thread_tracer, __pyx_k_top_level_thread_tracer, sizeof(__pyx_k_top_level_thread_tracer), 0, 0, 1, 1}, + {&__pyx_n_s_top_level_thread_tracer_no_back, __pyx_k_top_level_thread_tracer_no_back, sizeof(__pyx_k_top_level_thread_tracer_no_back), 0, 0, 1, 1}, + {&__pyx_n_s_top_level_thread_tracer_unhandle, __pyx_k_top_level_thread_tracer_unhandle, sizeof(__pyx_k_top_level_thread_tracer_unhandle), 0, 0, 1, 1}, + {&__pyx_n_s_trace, __pyx_k_trace, sizeof(__pyx_k_trace), 0, 0, 1, 1}, + {&__pyx_n_s_trace_dispatch, __pyx_k_trace_dispatch, sizeof(__pyx_k_trace_dispatch), 0, 0, 1, 1}, + {&__pyx_n_s_trace_dispatch_and_unhandled_exc, __pyx_k_trace_dispatch_and_unhandled_exc, sizeof(__pyx_k_trace_dispatch_and_unhandled_exc), 0, 0, 1, 1}, + {&__pyx_n_s_trace_exception, __pyx_k_trace_exception, sizeof(__pyx_k_trace_exception), 0, 0, 1, 1}, + {&__pyx_n_s_trace_return, __pyx_k_trace_return, sizeof(__pyx_k_trace_return), 0, 0, 1, 1}, + {&__pyx_n_s_trace_unhandled_exceptions, __pyx_k_trace_unhandled_exceptions, sizeof(__pyx_k_trace_unhandled_exceptions), 0, 0, 1, 1}, + {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_kp_s_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 0, 1, 0}, + {&__pyx_n_s_version, __pyx_k_version, sizeof(__pyx_k_version), 0, 0, 1, 1}, + {&__pyx_n_s_writer, __pyx_k_writer, sizeof(__pyx_k_writer), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 58, __pyx_L1_error) + __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(0, 196, __pyx_L1_error) + __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 152, __pyx_L1_error) + __pyx_builtin_SystemExit = __Pyx_GetBuiltinName(__pyx_n_s_SystemExit); if (!__pyx_builtin_SystemExit) __PYX_ERR(0, 307, __pyx_L1_error) + __pyx_builtin_id = __Pyx_GetBuiltinName(__pyx_n_s_id); if (!__pyx_builtin_id) __PYX_ERR(0, 436, __pyx_L1_error) + __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 580, __pyx_L1_error) + __pyx_builtin_GeneratorExit = __Pyx_GetBuiltinName(__pyx_n_s_GeneratorExit); if (!__pyx_builtin_GeneratorExit) __PYX_ERR(0, 580, __pyx_L1_error) + __pyx_builtin_KeyboardInterrupt = __Pyx_GetBuiltinName(__pyx_n_s_KeyboardInterrupt); if (!__pyx_builtin_KeyboardInterrupt) __PYX_ERR(0, 897, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "_pydevd_bundle/pydevd_cython.pyx":154 + * raise AttributeError() + * except: + * with _set_additional_thread_info_lock: # <<<<<<<<<<<<<< + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + */ + __pyx_tuple__2 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "_pydevd_bundle/pydevd_cython.pyx":1019 + * if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): + * # We need __bootstrap_inner, not __bootstrap. + * return None, False # <<<<<<<<<<<<<< + * + * elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): + */ + __pyx_tuple__7 = PyTuple_Pack(2, Py_None, Py_False); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 1019, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + + /* "_pydevd_bundle/pydevd_cython.pyx":12 + * from _pydev_bundle import pydev_log + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * pydev_log.debug("Using Cython speedups") # <<<<<<<<<<<<<< + * # ELSE + * # from _pydevd_bundle.pydevd_frame import PyDBFrame + */ + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_Using_Cython_speedups); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + + /* "_pydevd_bundle/pydevd_cython.pyx":26 + * from org.python.core import ThreadStateMapping + * try: + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version # <<<<<<<<<<<<<< + * except NoSuchFieldException: + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + */ + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_n_s_globalThreadStates); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + + /* "_pydevd_bundle/pydevd_cython.pyx":28 + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + * except NoSuchFieldException: + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 # <<<<<<<<<<<<<< + * cachedThreadState.accessible = True + * thread_states = cachedThreadState.get(ThreadStateMapping) + */ + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_n_s_cachedThreadState); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + + /* "_pydevd_bundle/pydevd_cython.pyx":32 + * thread_states = cachedThreadState.get(ThreadStateMapping) + * + * def _current_frames(): # <<<<<<<<<<<<<< + * as_array = thread_states.entrySet().toArray() + * ret = {} + */ + __pyx_tuple__11 = PyTuple_Pack(6, __pyx_n_s_as_array, __pyx_n_s_ret, __pyx_n_s_thread_to_state, __pyx_n_s_thread, __pyx_n_s_thread_state, __pyx_n_s_frame); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 32, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(0, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_current_frames, 32, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 32, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":54 + * + * # IronPython doesn't have it. Let's use our workaround... + * def _current_frames(): # <<<<<<<<<<<<<< + * return _tid_to_last_frame + * + */ + __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_current_frames, 54, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 54, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":58 + * + * else: + * raise RuntimeError('Unable to proceed (sys._current_frames not available in this Python implementation).') # <<<<<<<<<<<<<< + * else: + * _current_frames = sys._current_frames + */ + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_s_Unable_to_proceed_sys__current_f); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); + + /* "_pydevd_bundle/pydevd_cython.pyx":148 + * + * + * def set_additional_thread_info(thread): # <<<<<<<<<<<<<< + * try: + * additional_info = thread.additional_info + */ + __pyx_tuple__15 = PyTuple_Pack(2, __pyx_n_s_thread, __pyx_n_s_additional_info); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_set_additional_thread_info, 148, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 148, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":198 + * except ImportError: + * + * def send_signature_call_trace(*args, **kwargs): # <<<<<<<<<<<<<< + * pass + * + */ + __pyx_tuple__17 = PyTuple_Pack(2, __pyx_n_s_args, __pyx_n_s_kwargs); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 198, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARARGS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_send_signature_call_trace, 198, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 198, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":203 + * basename = os.path.basename + * + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') # <<<<<<<<<<<<<< + * DEBUG_START = ('pydevd.py', 'run') + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') + */ + __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_IgnoreException); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__19); + __Pyx_GIVEREF(__pyx_tuple__19); + + /* "_pydevd_bundle/pydevd_cython.pyx":204 + * + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') + * DEBUG_START = ('pydevd.py', 'run') # <<<<<<<<<<<<<< + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') + * TRACE_PROPERTY = 'pydevd_traceproperty.py' + */ + __pyx_tuple__20 = PyTuple_Pack(2, __pyx_kp_s_pydevd_py, __pyx_n_s_run); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 204, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); + + /* "_pydevd_bundle/pydevd_cython.pyx":205 + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') + * DEBUG_START = ('pydevd.py', 'run') + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') # <<<<<<<<<<<<<< + * TRACE_PROPERTY = 'pydevd_traceproperty.py' + * + */ + __pyx_tuple__21 = PyTuple_Pack(2, __pyx_kp_s_pydev_execfile_py, __pyx_n_s_execfile); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 205, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__21); + __Pyx_GIVEREF(__pyx_tuple__21); + + /* "_pydevd_bundle/pydevd_cython.pyx":952 + * + * + * def notify_skipped_step_in_because_of_filters(py_db, frame): # <<<<<<<<<<<<<< + * global _global_notify_skipped_step_in + * + */ + __pyx_tuple__22 = PyTuple_Pack(2, __pyx_n_s_py_db, __pyx_n_s_frame); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 952, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_notify_skipped_step_in_because_o, 952, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 952, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":982 + * + * + * def fix_top_level_trace_and_get_trace_func(py_db, frame): # <<<<<<<<<<<<<< + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef str filename; + */ + __pyx_tuple__24 = PyTuple_Pack(15, __pyx_n_s_py_db, __pyx_n_s_frame, __pyx_n_s_filename, __pyx_n_s_name_2, __pyx_n_s_args, __pyx_n_s_thread, __pyx_n_s_f_unhandled, __pyx_n_s_force_only_unhandled_tracer, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_t, __pyx_n_s_additional_info, __pyx_n_s_top_level_thread_tracer, __pyx_n_s_f_trace, __pyx_n_s_thread_tracer); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__24); + __Pyx_GIVEREF(__pyx_tuple__24); + __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(2, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_fix_top_level_trace_and_get_trac, 982, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 982, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1107 + * + * + * def trace_dispatch(py_db, frame, event, arg): # <<<<<<<<<<<<<< + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: + */ + __pyx_tuple__26 = PyTuple_Pack(6, __pyx_n_s_py_db, __pyx_n_s_frame, __pyx_n_s_event, __pyx_n_s_arg, __pyx_n_s_thread_trace_func, __pyx_n_s_apply_to_settrace); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 1107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__26); + __Pyx_GIVEREF(__pyx_tuple__26); + __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(4, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_trace_dispatch, 1107, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 1107, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":1439 + * _original_call = ThreadTracer.__call__ + * + * def __call__(self, frame, event, arg): # <<<<<<<<<<<<<< + * _tid_to_last_frame[self._args[1].ident] = frame + * return _original_call(self, frame, event, arg) + */ + __pyx_tuple__28 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_frame, __pyx_n_s_event, __pyx_n_s_arg); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 1439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__28); + __Pyx_GIVEREF(__pyx_tuple__28); + __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_bundle_pydevd_cython_pyx, __pyx_n_s_call_2, 1439, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 1439, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __pyx_unpickle_PyDBAdditionalThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_tuple__30 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__30); + __Pyx_GIVEREF(__pyx_tuple__30); + __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_PyDBAdditionalThr, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__32 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__32); + __Pyx_GIVEREF(__pyx_tuple__32); + __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_PyDBFrame, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__34 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__34); + __Pyx_GIVEREF(__pyx_tuple__34); + __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_SafeCallWrapper, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__36 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__36); + __Pyx_GIVEREF(__pyx_tuple__36); + __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_TopLevelThreadTra, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__38 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__38); + __Pyx_GIVEREF(__pyx_tuple__38); + __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__38, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_TopLevelThreadTra_2, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(2, 1, __pyx_L1_error) + __pyx_tuple__40 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__40); + __Pyx_GIVEREF(__pyx_tuple__40); + __pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__40, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_ThreadTracer, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type; + __pyx_umethod_PyString_Type_rfind.type = (PyObject*)&PyString_Type; + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_11 = PyInt_FromLong(11); if (unlikely(!__pyx_int_11)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_32 = PyInt_FromLong(32); if (unlikely(!__pyx_int_32)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_111 = PyInt_FromLong(111); if (unlikely(!__pyx_int_111)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_137 = PyInt_FromLong(137); if (unlikely(!__pyx_int_137)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_64458794 = PyInt_FromLong(64458794L); if (unlikely(!__pyx_int_64458794)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_112182380 = PyInt_FromLong(112182380L); if (unlikely(!__pyx_int_112182380)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_125568891 = PyInt_FromLong(125568891L); if (unlikely(!__pyx_int_125568891)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_255117134 = PyInt_FromLong(255117134L); if (unlikely(!__pyx_int_255117134)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_262582659 = PyInt_FromLong(262582659L); if (unlikely(!__pyx_int_262582659)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in = ((PyObject*)Py_None); Py_INCREF(Py_None); + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo) < 0) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo.tp_dictoffset && __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_PyDBAdditionalThreadInfo, (PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo) < 0) __PYX_ERR(0, 67, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo) < 0) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo = &__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo; + __pyx_vtabptr_14_pydevd_bundle_13pydevd_cython_PyDBFrame = &__pyx_vtable_14_pydevd_bundle_13pydevd_cython_PyDBFrame; + __pyx_vtable_14_pydevd_bundle_13pydevd_cython_PyDBFrame.trace_dispatch = (PyObject *(*)(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBFrame *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch))__pyx_f_14_pydevd_bundle_13pydevd_cython_9PyDBFrame_trace_dispatch; + if (PyType_Ready(&__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame) < 0) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame.tp_dictoffset && __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (__Pyx_SetVtable(__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame.tp_dict, __pyx_vtabptr_14_pydevd_bundle_13pydevd_cython_PyDBFrame) < 0) __PYX_ERR(0, 213, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_PyDBFrame, (PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame) < 0) __PYX_ERR(0, 213, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame) < 0) __PYX_ERR(0, 213, __pyx_L1_error) + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame = &__pyx_type_14_pydevd_bundle_13pydevd_cython_PyDBFrame; + if (PyType_Ready(&__pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper) < 0) __PYX_ERR(0, 964, __pyx_L1_error) + __pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper.tp_dictoffset && __pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_SafeCallWrapper, (PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper) < 0) __PYX_ERR(0, 964, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper) < 0) __PYX_ERR(0, 964, __pyx_L1_error) + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper = &__pyx_type_14_pydevd_bundle_13pydevd_cython_SafeCallWrapper; + if (PyType_Ready(&__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions.tp_dictoffset && __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_TopLevelThreadTracerOnlyUnhandle, (PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions) < 0) __PYX_ERR(0, 1117, __pyx_L1_error) + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions = &__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerOnlyUnhandledExceptions; + if (PyType_Ready(&__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame) < 0) __PYX_ERR(0, 1147, __pyx_L1_error) + __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame.tp_dictoffset && __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_TopLevelThreadTracerNoBackFrame, (PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame) < 0) __PYX_ERR(0, 1147, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame) < 0) __PYX_ERR(0, 1147, __pyx_L1_error) + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame = &__pyx_type_14_pydevd_bundle_13pydevd_cython_TopLevelThreadTracerNoBackFrame; + if (PyType_Ready(&__pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer) < 0) __PYX_ERR(0, 1256, __pyx_L1_error) + __pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer.tp_dictoffset && __pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #if CYTHON_COMPILING_IN_CPYTHON + { + PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer, "__call__"); if (unlikely(!wrapper)) __PYX_ERR(0, 1256, __pyx_L1_error) + if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { + __pyx_wrapperbase_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__ = *((PyWrapperDescrObject *)wrapper)->d_base; + __pyx_wrapperbase_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__.doc = __pyx_doc_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__; + ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_14_pydevd_bundle_13pydevd_cython_12ThreadTracer_2__call__; + } + } + #endif + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ThreadTracer, (PyObject *)&__pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer) < 0) __PYX_ERR(0, 1256, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer) < 0) __PYX_ERR(0, 1256, __pyx_L1_error) + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer = &__pyx_type_14_pydevd_bundle_13pydevd_cython_ThreadTracer; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), + #else + sizeof(PyHeapTypeObject), + #endif + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION < 3 +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC void +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#else +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initpydevd_cython(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initpydevd_cython(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_pydevd_cython(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_pydevd_cython(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_pydevd_cython(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'pydevd_cython' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_pydevd_cython(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("pydevd_cython", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_b); + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main__pydevd_bundle__pydevd_cython) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "_pydevd_bundle.pydevd_cython")) { + if (unlikely(PyDict_SetItemString(modules, "_pydevd_bundle.pydevd_cython", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error; + if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error; + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "_pydevd_bundle/pydevd_cython.pyx":7 + * # DO NOT edit manually! + * # DO NOT edit manually! + * import sys # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_constants import (STATE_RUN, PYTHON_SUSPEND, IS_JYTHON, + * USE_CUSTOM_SYS_CURRENT_FRAMES, USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":8 + * # DO NOT edit manually! + * import sys + * from _pydevd_bundle.pydevd_constants import (STATE_RUN, PYTHON_SUSPEND, IS_JYTHON, # <<<<<<<<<<<<<< + * USE_CUSTOM_SYS_CURRENT_FRAMES, USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + * from _pydev_bundle import pydev_log + */ + __pyx_t_1 = PyList_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_STATE_RUN); + __Pyx_GIVEREF(__pyx_n_s_STATE_RUN); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_STATE_RUN); + __Pyx_INCREF(__pyx_n_s_PYTHON_SUSPEND); + __Pyx_GIVEREF(__pyx_n_s_PYTHON_SUSPEND); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_PYTHON_SUSPEND); + __Pyx_INCREF(__pyx_n_s_IS_JYTHON); + __Pyx_GIVEREF(__pyx_n_s_IS_JYTHON); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_IS_JYTHON); + __Pyx_INCREF(__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES); + __Pyx_GIVEREF(__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES); + PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES); + __Pyx_INCREF(__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); + __Pyx_GIVEREF(__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); + PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_constants, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_STATE_RUN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_STATE_RUN, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_PYTHON_SUSPEND); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_PYTHON_SUSPEND, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_IS_JYTHON); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_IS_JYTHON, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":10 + * from _pydevd_bundle.pydevd_constants import (STATE_RUN, PYTHON_SUSPEND, IS_JYTHON, + * USE_CUSTOM_SYS_CURRENT_FRAMES, USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + * from _pydev_bundle import pydev_log # <<<<<<<<<<<<<< + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * pydev_log.debug("Using Cython speedups") + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_pydev_log); + __Pyx_GIVEREF(__pyx_n_s_pydev_log); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_pydev_log); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydev_bundle, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pydev_log, __pyx_t_2) < 0) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":12 + * from _pydev_bundle import pydev_log + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * pydev_log.debug("Using Cython speedups") # <<<<<<<<<<<<<< + * # ELSE + * # from _pydevd_bundle.pydevd_frame import PyDBFrame + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":17 + * # ENDIF + * + * version = 11 # <<<<<<<<<<<<<< + * + * if USE_CUSTOM_SYS_CURRENT_FRAMES: + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_int_11) < 0) __PYX_ERR(0, 17, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":19 + * version = 11 + * + * if USE_CUSTOM_SYS_CURRENT_FRAMES: # <<<<<<<<<<<<<< + * + * # Some versions of Jython don't have it (but we can provide a replacement) + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":22 + * + * # Some versions of Jython don't have it (but we can provide a replacement) + * if IS_JYTHON: # <<<<<<<<<<<<<< + * from java.lang import NoSuchFieldException + * from org.python.core import ThreadStateMapping + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_IS_JYTHON); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 22, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":23 + * # Some versions of Jython don't have it (but we can provide a replacement) + * if IS_JYTHON: + * from java.lang import NoSuchFieldException # <<<<<<<<<<<<<< + * from org.python.core import ThreadStateMapping + * try: + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_NoSuchFieldException); + __Pyx_GIVEREF(__pyx_n_s_NoSuchFieldException); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_NoSuchFieldException); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_java_lang, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_NoSuchFieldException); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_NoSuchFieldException, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":24 + * if IS_JYTHON: + * from java.lang import NoSuchFieldException + * from org.python.core import ThreadStateMapping # <<<<<<<<<<<<<< + * try: + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_ThreadStateMapping); + __Pyx_GIVEREF(__pyx_n_s_ThreadStateMapping); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ThreadStateMapping); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_org_python_core, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_ThreadStateMapping); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ThreadStateMapping, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":25 + * from java.lang import NoSuchFieldException + * from org.python.core import ThreadStateMapping + * try: # <<<<<<<<<<<<<< + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + * except NoSuchFieldException: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":26 + * from org.python.core import ThreadStateMapping + * try: + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version # <<<<<<<<<<<<<< + * except NoSuchFieldException: + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ThreadStateMapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_getDeclaredField); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_cachedThreadState, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":25 + * from java.lang import NoSuchFieldException + * from org.python.core import ThreadStateMapping + * try: # <<<<<<<<<<<<<< + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + * except NoSuchFieldException: + */ + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L9_try_end; + __pyx_L4_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":27 + * try: + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + * except NoSuchFieldException: # <<<<<<<<<<<<<< + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + * cachedThreadState.accessible = True + */ + __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_2, &__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_NoSuchFieldException); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 27, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_8); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_7); + __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_7 = 0; + if (__pyx_t_9) { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_2, &__pyx_t_1) < 0) __PYX_ERR(0, 27, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + + /* "_pydevd_bundle/pydevd_cython.pyx":28 + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + * except NoSuchFieldException: + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 # <<<<<<<<<<<<<< + * cachedThreadState.accessible = True + * thread_states = cachedThreadState.get(ThreadStateMapping) + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_ThreadStateMapping); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 28, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_getDeclaredField); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 28, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 28, __pyx_L6_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_cachedThreadState, __pyx_t_8) < 0) __PYX_ERR(0, 28, __pyx_L6_except_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L5_exception_handled; + } + goto __pyx_L6_except_error; + __pyx_L6_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":25 + * from java.lang import NoSuchFieldException + * from org.python.core import ThreadStateMapping + * try: # <<<<<<<<<<<<<< + * cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + * except NoSuchFieldException: + */ + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + goto __pyx_L1_error; + __pyx_L5_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + __pyx_L9_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":29 + * except NoSuchFieldException: + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + * cachedThreadState.accessible = True # <<<<<<<<<<<<<< + * thread_states = cachedThreadState.get(ThreadStateMapping) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_cachedThreadState); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(__pyx_t_1, __pyx_n_s_accessible, Py_True) < 0) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":30 + * cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + * cachedThreadState.accessible = True + * thread_states = cachedThreadState.get(ThreadStateMapping) # <<<<<<<<<<<<<< + * + * def _current_frames(): + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_cachedThreadState); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ThreadStateMapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_thread_states, __pyx_t_7) < 0) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":32 + * thread_states = cachedThreadState.get(ThreadStateMapping) + * + * def _current_frames(): # <<<<<<<<<<<<<< + * as_array = thread_states.entrySet().toArray() + * ret = {} + */ + __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_1_current_frames, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 32, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_current_frames, __pyx_t_7) < 0) __PYX_ERR(0, 32, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":22 + * + * # Some versions of Jython don't have it (but we can provide a replacement) + * if IS_JYTHON: # <<<<<<<<<<<<<< + * from java.lang import NoSuchFieldException + * from org.python.core import ThreadStateMapping + */ + goto __pyx_L3; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":50 + * return ret + * + * elif USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: # <<<<<<<<<<<<<< + * _tid_to_last_frame = {} + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (likely(__pyx_t_3)) { + + /* "_pydevd_bundle/pydevd_cython.pyx":51 + * + * elif USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + * _tid_to_last_frame = {} # <<<<<<<<<<<<<< + * + * # IronPython doesn't have it. Let's use our workaround... + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tid_to_last_frame, __pyx_t_7) < 0) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":54 + * + * # IronPython doesn't have it. Let's use our workaround... + * def _current_frames(): # <<<<<<<<<<<<<< + * return _tid_to_last_frame + * + */ + __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_3_current_frames, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_current_frames, __pyx_t_7) < 0) __PYX_ERR(0, 54, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":50 + * return ret + * + * elif USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: # <<<<<<<<<<<<<< + * _tid_to_last_frame = {} + * + */ + goto __pyx_L3; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":58 + * + * else: + * raise RuntimeError('Unable to proceed (sys._current_frames not available in this Python implementation).') # <<<<<<<<<<<<<< + * else: + * _current_frames = sys._current_frames + */ + /*else*/ { + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 58, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_Raise(__pyx_t_7, 0, 0, 0); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __PYX_ERR(0, 58, __pyx_L1_error) + } + __pyx_L3:; + + /* "_pydevd_bundle/pydevd_cython.pyx":19 + * version = 11 + * + * if USE_CUSTOM_SYS_CURRENT_FRAMES: # <<<<<<<<<<<<<< + * + * # Some versions of Jython don't have it (but we can provide a replacement) + */ + goto __pyx_L2; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":60 + * raise RuntimeError('Unable to proceed (sys._current_frames not available in this Python implementation).') + * else: + * _current_frames = sys._current_frames # <<<<<<<<<<<<<< + * + * + */ + /*else*/ { + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sys); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_current_frames); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_current_frames, __pyx_t_1) < 0) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_L2:; + + /* "_pydevd_bundle/pydevd_cython.pyx":144 + * + * + * from _pydev_imps._pydev_saved_modules import threading # <<<<<<<<<<<<<< + * _set_additional_thread_info_lock = threading.Lock() + * + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_threading); + __Pyx_GIVEREF(__pyx_n_s_threading); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_threading); + __pyx_t_7 = __Pyx_Import(__pyx_n_s_pydev_imps__pydev_saved_modules, __pyx_t_1, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_threading); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_threading, __pyx_t_1) < 0) __PYX_ERR(0, 144, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":145 + * + * from _pydev_imps._pydev_saved_modules import threading + * _set_additional_thread_info_lock = threading.Lock() # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_threading); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_Lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 145, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_additional_thread_info_lock, __pyx_t_7) < 0) __PYX_ERR(0, 145, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":148 + * + * + * def set_additional_thread_info(thread): # <<<<<<<<<<<<<< + * try: + * additional_info = thread.additional_info + */ + __pyx_t_7 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_5set_additional_thread_info, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_additional_thread_info, __pyx_t_7) < 0) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":163 + * + * return additional_info + * import linecache # <<<<<<<<<<<<<< + * import os.path + * import re + */ + __pyx_t_7 = __Pyx_Import(__pyx_n_s_linecache, 0, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_linecache, __pyx_t_7) < 0) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":164 + * return additional_info + * import linecache + * import os.path # <<<<<<<<<<<<<< + * import re + * + */ + __pyx_t_7 = __Pyx_Import(__pyx_n_s_os_path, 0, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 164, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_7) < 0) __PYX_ERR(0, 164, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":165 + * import linecache + * import os.path + * import re # <<<<<<<<<<<<<< + * + * from _pydev_bundle import pydev_log + */ + __pyx_t_7 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_7) < 0) __PYX_ERR(0, 165, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":167 + * import re + * + * from _pydev_bundle import pydev_log # <<<<<<<<<<<<<< + * from _pydevd_bundle import pydevd_dont_trace + * from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) + */ + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_n_s_pydev_log); + __Pyx_GIVEREF(__pyx_n_s_pydev_log); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_pydev_log); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydev_bundle, __pyx_t_7, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_pydev_log); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pydev_log, __pyx_t_7) < 0) __PYX_ERR(0, 167, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":168 + * + * from _pydev_bundle import pydev_log + * from _pydevd_bundle import pydevd_dont_trace # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) + * from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 168, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_pydevd_dont_trace); + __Pyx_GIVEREF(__pyx_n_s_pydevd_dont_trace); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_pydevd_dont_trace); + __pyx_t_7 = __Pyx_Import(__pyx_n_s_pydevd_bundle, __pyx_t_1, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 168, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_pydevd_dont_trace); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 168, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pydevd_dont_trace, __pyx_t_1) < 0) __PYX_ERR(0, 168, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":169 + * from _pydev_bundle import pydev_log + * from _pydevd_bundle import pydevd_dont_trace + * from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code + */ + __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_n_s_dict_iter_values); + __Pyx_GIVEREF(__pyx_n_s_dict_iter_values); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_dict_iter_values); + __Pyx_INCREF(__pyx_n_s_IS_PY3K); + __Pyx_GIVEREF(__pyx_n_s_IS_PY3K); + PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_IS_PY3K); + __Pyx_INCREF(__pyx_n_s_RETURN_VALUES_DICT); + __Pyx_GIVEREF(__pyx_n_s_RETURN_VALUES_DICT); + PyList_SET_ITEM(__pyx_t_7, 2, __pyx_n_s_RETURN_VALUES_DICT); + __Pyx_INCREF(__pyx_n_s_NO_FTRACE); + __Pyx_GIVEREF(__pyx_n_s_NO_FTRACE); + PyList_SET_ITEM(__pyx_t_7, 3, __pyx_n_s_NO_FTRACE); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_constants, __pyx_t_7, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_dict_iter_values); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_dict_iter_values, __pyx_t_7) < 0) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_IS_PY3K); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_IS_PY3K, __pyx_t_7) < 0) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_RETURN_VALUES_DICT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_RETURN_VALUES_DICT, __pyx_t_7) < 0) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_NO_FTRACE, __pyx_t_7) < 0) __PYX_ERR(0, 169, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":170 + * from _pydevd_bundle import pydevd_dont_trace + * from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) + * from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file + */ + __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_add_exception_to_frame); + __Pyx_GIVEREF(__pyx_n_s_add_exception_to_frame); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_add_exception_to_frame); + __Pyx_INCREF(__pyx_n_s_just_raised); + __Pyx_GIVEREF(__pyx_n_s_just_raised); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_just_raised); + __Pyx_INCREF(__pyx_n_s_remove_exception_from_frame); + __Pyx_GIVEREF(__pyx_n_s_remove_exception_from_frame); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_remove_exception_from_frame); + __Pyx_INCREF(__pyx_n_s_ignore_exception_trace); + __Pyx_GIVEREF(__pyx_n_s_ignore_exception_trace); + PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_ignore_exception_trace); + __pyx_t_7 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_frame_util, __pyx_t_1, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_add_exception_to_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_add_exception_to_frame, __pyx_t_1) < 0) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_just_raised); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_just_raised, __pyx_t_1) < 0) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_remove_exception_from_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_remove_exception_from_frame, __pyx_t_1) < 0) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_ignore_exception_trace); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ignore_exception_trace, __pyx_t_1) < 0) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":171 + * from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) + * from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code # <<<<<<<<<<<<<< + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file + * try: + */ + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_n_s_get_clsname_for_code); + __Pyx_GIVEREF(__pyx_n_s_get_clsname_for_code); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_get_clsname_for_code); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_utils, __pyx_t_7, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_get_clsname_for_code); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_clsname_for_code, __pyx_t_7) < 0) __PYX_ERR(0, 171, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":172 + * from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file # <<<<<<<<<<<<<< + * try: + * from inspect import CO_GENERATOR + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_get_abs_path_real_path_and_base); + __Pyx_GIVEREF(__pyx_n_s_get_abs_path_real_path_and_base); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_get_abs_path_real_path_and_base); + __Pyx_INCREF(__pyx_n_s_get_abs_path_real_path_and_base_2); + __Pyx_GIVEREF(__pyx_n_s_get_abs_path_real_path_and_base_2); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_get_abs_path_real_path_and_base_2); + __pyx_t_7 = __Pyx_Import(__pyx_n_s_pydevd_file_utils, __pyx_t_1, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_abs_path_real_path_and_base, __pyx_t_1) < 0) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_get_abs_path_real_path_and_base_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_abs_path_real_path_and_base_2, __pyx_t_1) < 0) __PYX_ERR(0, 172, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":173 + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file + * try: # <<<<<<<<<<<<<< + * from inspect import CO_GENERATOR + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_4); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":174 + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file + * try: + * from inspect import CO_GENERATOR # <<<<<<<<<<<<<< + * except: + * CO_GENERATOR = 0 + */ + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 174, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_n_s_CO_GENERATOR); + __Pyx_GIVEREF(__pyx_n_s_CO_GENERATOR); + PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_CO_GENERATOR); + __pyx_t_1 = __Pyx_patch_inspect(__Pyx_Import(__pyx_n_s_inspect, __pyx_t_7, -1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_CO_GENERATOR); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 174, __pyx_L12_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CO_GENERATOR, __pyx_t_7) < 0) __PYX_ERR(0, 174, __pyx_L12_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":173 + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file + * try: # <<<<<<<<<<<<<< + * from inspect import CO_GENERATOR + * except: + */ + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L17_try_end; + __pyx_L12_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":175 + * try: + * from inspect import CO_GENERATOR + * except: # <<<<<<<<<<<<<< + * CO_GENERATOR = 0 + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_7, &__pyx_t_2) < 0) __PYX_ERR(0, 175, __pyx_L14_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_2); + + /* "_pydevd_bundle/pydevd_cython.pyx":176 + * from inspect import CO_GENERATOR + * except: + * CO_GENERATOR = 0 # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CO_GENERATOR, __pyx_int_0) < 0) __PYX_ERR(0, 176, __pyx_L14_except_error) + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L13_exception_handled; + } + __pyx_L14_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":173 + * from _pydevd_bundle.pydevd_utils import get_clsname_for_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file + * try: # <<<<<<<<<<<<<< + * from inspect import CO_GENERATOR + * except: + */ + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_5, __pyx_t_4); + goto __pyx_L1_error; + __pyx_L13_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_5, __pyx_t_4); + __pyx_L17_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":194 + * # ENDIF + * + * try: # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace + * except ImportError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + /*try:*/ { + + /* "_pydevd_bundle/pydevd_cython.pyx":195 + * + * try: + * from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace # <<<<<<<<<<<<<< + * except ImportError: + * + */ + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L20_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_send_signature_call_trace); + __Pyx_GIVEREF(__pyx_n_s_send_signature_call_trace); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_send_signature_call_trace); + __Pyx_INCREF(__pyx_n_s_send_signature_return_trace); + __Pyx_GIVEREF(__pyx_n_s_send_signature_return_trace); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_send_signature_return_trace); + __pyx_t_7 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_signature, __pyx_t_2, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 195, __pyx_L20_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_send_signature_call_trace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L20_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_send_signature_call_trace, __pyx_t_2) < 0) __PYX_ERR(0, 195, __pyx_L20_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_send_signature_return_trace); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 195, __pyx_L20_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_send_signature_return_trace, __pyx_t_2) < 0) __PYX_ERR(0, 195, __pyx_L20_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":194 + * # ENDIF + * + * try: # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace + * except ImportError: + */ + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L25_try_end; + __pyx_L20_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":196 + * try: + * from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace + * except ImportError: # <<<<<<<<<<<<<< + * + * def send_signature_call_trace(*args, **kwargs): + */ + __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ImportError); + if (__pyx_t_9) { + __Pyx_AddTraceback("_pydevd_bundle.pydevd_cython", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_2, &__pyx_t_1) < 0) __PYX_ERR(0, 196, __pyx_L22_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + + /* "_pydevd_bundle/pydevd_cython.pyx":198 + * except ImportError: + * + * def send_signature_call_trace(*args, **kwargs): # <<<<<<<<<<<<<< + * pass + * + */ + __pyx_t_8 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_7send_signature_call_trace, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 198, __pyx_L22_except_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_send_signature_call_trace, __pyx_t_8) < 0) __PYX_ERR(0, 198, __pyx_L22_except_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L21_exception_handled; + } + goto __pyx_L22_except_error; + __pyx_L22_except_error:; + + /* "_pydevd_bundle/pydevd_cython.pyx":194 + * # ENDIF + * + * try: # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace + * except ImportError: + */ + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + goto __pyx_L1_error; + __pyx_L21_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); + __pyx_L25_try_end:; + } + + /* "_pydevd_bundle/pydevd_cython.pyx":201 + * pass + * + * basename = os.path.basename # <<<<<<<<<<<<<< + * + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_os); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_basename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_basename, __pyx_t_1) < 0) __PYX_ERR(0, 201, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":203 + * basename = os.path.basename + * + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') # <<<<<<<<<<<<<< + * DEBUG_START = ('pydevd.py', 'run') + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_IGNORE_EXCEPTION_TAG, __pyx_t_1) < 0) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":204 + * + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') + * DEBUG_START = ('pydevd.py', 'run') # <<<<<<<<<<<<<< + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') + * TRACE_PROPERTY = 'pydevd_traceproperty.py' + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEBUG_START, __pyx_tuple__20) < 0) __PYX_ERR(0, 204, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":205 + * IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') + * DEBUG_START = ('pydevd.py', 'run') + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') # <<<<<<<<<<<<<< + * TRACE_PROPERTY = 'pydevd_traceproperty.py' + * + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DEBUG_START_PY3K, __pyx_tuple__21) < 0) __PYX_ERR(0, 205, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":206 + * DEBUG_START = ('pydevd.py', 'run') + * DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') + * TRACE_PROPERTY = 'pydevd_traceproperty.py' # <<<<<<<<<<<<<< + * + * + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_TRACE_PROPERTY, __pyx_kp_s_pydevd_traceproperty_py) < 0) __PYX_ERR(0, 206, __pyx_L1_error) + + /* "_pydevd_bundle/pydevd_cython.pyx":226 + * # Same thing in the main debugger but only considering the file contents, while the one in the main debugger + * # considers the user input (so, the actual result must be a join of both). + * filename_to_lines_where_exceptions_are_ignored = {} # <<<<<<<<<<<<<< + * filename_to_stat_info = {} + * + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame->tp_dict, __pyx_n_s_filename_to_lines_where_exceptio, __pyx_t_1) < 0) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyType_Modified(__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame); + + /* "_pydevd_bundle/pydevd_cython.pyx":227 + * # considers the user input (so, the actual result must be a join of both). + * filename_to_lines_where_exceptions_are_ignored = {} + * filename_to_stat_info = {} # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame->tp_dict, __pyx_n_s_filename_to_stat_info, __pyx_t_1) < 0) __PYX_ERR(0, 227, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyType_Modified(__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBFrame); + + /* "_pydevd_bundle/pydevd_cython.pyx":916 + * + * # end trace_dispatch + * from _pydev_bundle.pydev_is_thread_alive import is_thread_alive # <<<<<<<<<<<<<< + * from _pydev_bundle.pydev_log import exception as pydev_log_exception + * from _pydev_imps._pydev_saved_modules import threading + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_is_thread_alive); + __Pyx_GIVEREF(__pyx_n_s_is_thread_alive); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_is_thread_alive); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydev_bundle_pydev_is_thread_al, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_is_thread_alive); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_is_thread_alive, __pyx_t_1) < 0) __PYX_ERR(0, 916, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":917 + * # end trace_dispatch + * from _pydev_bundle.pydev_is_thread_alive import is_thread_alive + * from _pydev_bundle.pydev_log import exception as pydev_log_exception # <<<<<<<<<<<<<< + * from _pydev_imps._pydev_saved_modules import threading + * from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE, + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_exception); + __Pyx_GIVEREF(__pyx_n_s_exception); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_exception); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydev_bundle_pydev_log, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_exception); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pydev_log_exception, __pyx_t_2) < 0) __PYX_ERR(0, 917, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":918 + * from _pydev_bundle.pydev_is_thread_alive import is_thread_alive + * from _pydev_bundle.pydev_log import exception as pydev_log_exception + * from _pydev_imps._pydev_saved_modules import threading # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE, + * USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_threading); + __Pyx_GIVEREF(__pyx_n_s_threading); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_threading); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydev_imps__pydev_saved_modules, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_threading); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_threading, __pyx_t_1) < 0) __PYX_ERR(0, 918, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":919 + * from _pydev_bundle.pydev_log import exception as pydev_log_exception + * from _pydev_imps._pydev_saved_modules import threading + * from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE, # <<<<<<<<<<<<<< + * USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + * from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads + */ + __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_get_current_thread_id); + __Pyx_GIVEREF(__pyx_n_s_get_current_thread_id); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_get_current_thread_id); + __Pyx_INCREF(__pyx_n_s_NO_FTRACE); + __Pyx_GIVEREF(__pyx_n_s_NO_FTRACE); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_NO_FTRACE); + __Pyx_INCREF(__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); + __Pyx_GIVEREF(__pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); + PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_constants, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_get_current_thread_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_current_thread_id, __pyx_t_2) < 0) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_NO_FTRACE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_NO_FTRACE, __pyx_t_2) < 0) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 919, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA, __pyx_t_2) < 0) __PYX_ERR(0, 920, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":921 + * from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE, + * USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + * from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads # <<<<<<<<<<<<<< + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER + * + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_kill_all_pydev_threads); + __Pyx_GIVEREF(__pyx_n_s_kill_all_pydev_threads); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_kill_all_pydev_threads); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_kill_all_p, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_kill_all_pydev_threads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_kill_all_pydev_threads, __pyx_t_1) < 0) __PYX_ERR(0, 921, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":922 + * USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) + * from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER # <<<<<<<<<<<<<< + * + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + */ + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 922, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_get_abs_path_real_path_and_base); + __Pyx_GIVEREF(__pyx_n_s_get_abs_path_real_path_and_base); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_get_abs_path_real_path_and_base); + __Pyx_INCREF(__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); + __Pyx_GIVEREF(__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_file_utils, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 922, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 922, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_abs_path_real_path_and_base, __pyx_t_2) < 0) __PYX_ERR(0, 922, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 922, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER, __pyx_t_2) < 0) __PYX_ERR(0, 922, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":945 + * # - Breakpoints are changed + * # It can be used when running regularly (without step over/step in/step return) + * global_cache_skips = {} # <<<<<<<<<<<<<< + * global_cache_frame_skips = {} + * + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 945, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_global_cache_skips, __pyx_t_1) < 0) __PYX_ERR(0, 945, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":946 + * # It can be used when running regularly (without step over/step in/step return) + * global_cache_skips = {} + * global_cache_frame_skips = {} # <<<<<<<<<<<<<< + * + * _global_notify_skipped_step_in = False + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 946, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_global_cache_frame_skips, __pyx_t_1) < 0) __PYX_ERR(0, 946, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":948 + * global_cache_frame_skips = {} + * + * _global_notify_skipped_step_in = False # <<<<<<<<<<<<<< + * _global_notify_skipped_step_in_lock = threading.Lock() + * + */ + __Pyx_INCREF(Py_False); + __Pyx_XGOTREF(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in); + __Pyx_DECREF_SET(__pyx_v_14_pydevd_bundle_13pydevd_cython__global_notify_skipped_step_in, ((PyObject*)Py_False)); + __Pyx_GIVEREF(Py_False); + + /* "_pydevd_bundle/pydevd_cython.pyx":949 + * + * _global_notify_skipped_step_in = False + * _global_notify_skipped_step_in_lock = threading.Lock() # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_threading); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Lock); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 949, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_global_notify_skipped_step_in_l, __pyx_t_1) < 0) __PYX_ERR(0, 949, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":952 + * + * + * def notify_skipped_step_in_because_of_filters(py_db, frame): # <<<<<<<<<<<<<< + * global _global_notify_skipped_step_in + * + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_9notify_skipped_step_in_because_of_filters, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 952, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_notify_skipped_step_in_because_o, __pyx_t_1) < 0) __PYX_ERR(0, 952, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":982 + * + * + * def fix_top_level_trace_and_get_trace_func(py_db, frame): # <<<<<<<<<<<<<< + * # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + * cdef str filename; + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_11fix_top_level_trace_and_get_trace_func, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_fix_top_level_trace_and_get_trac, __pyx_t_1) < 0) __PYX_ERR(0, 982, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1107 + * + * + * def trace_dispatch(py_db, frame, event, arg): # <<<<<<<<<<<<<< + * thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + * if thread_trace_func is None: + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_13trace_dispatch, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1107, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_trace_dispatch, __pyx_t_1) < 0) __PYX_ERR(0, 1107, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1427 + * + * + * if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: # <<<<<<<<<<<<<< + * # This is far from ideal, as we'll leak frames (we'll always have the last created frame, not really + * # the last topmost frame saved -- this should be Ok for our usage, but it may leak frames and things + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_USE_CUSTOM_SYS_CURRENT_FRAMES_MA); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1427, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1427, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "_pydevd_bundle/pydevd_cython.pyx":1435 + * # + * # See: https://github.com/IronLanguages/main/issues/1630 + * from _pydevd_bundle.pydevd_additional_thread_info_regular import _tid_to_last_frame # <<<<<<<<<<<<<< + * + * _original_call = ThreadTracer.__call__ + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_tid_to_last_frame); + __Pyx_GIVEREF(__pyx_n_s_tid_to_last_frame); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_tid_to_last_frame); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_additional, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_tid_to_last_frame); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1435, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_tid_to_last_frame, __pyx_t_1) < 0) __PYX_ERR(0, 1435, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1437 + * from _pydevd_bundle.pydevd_additional_thread_info_regular import _tid_to_last_frame + * + * _original_call = ThreadTracer.__call__ # <<<<<<<<<<<<<< + * + * def __call__(self, frame, event, arg): + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer), __pyx_n_s_call_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1437, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_original_call, __pyx_t_2) < 0) __PYX_ERR(0, 1437, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1439 + * _original_call = ThreadTracer.__call__ + * + * def __call__(self, frame, event, arg): # <<<<<<<<<<<<<< + * _tid_to_last_frame[self._args[1].ident] = frame + * return _original_call(self, frame, event, arg) + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_15__call__, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1439, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_call_2, __pyx_t_2) < 0) __PYX_ERR(0, 1439, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1443 + * return _original_call(self, frame, event, arg) + * + * ThreadTracer.__call__ = __call__ # <<<<<<<<<<<<<< + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_call_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1443, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_ThreadTracer), __pyx_n_s_call_2, __pyx_t_2) < 0) __PYX_ERR(0, 1443, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1427 + * + * + * if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: # <<<<<<<<<<<<<< + * # This is far from ideal, as we'll leak frames (we'll always have the last created frame, not really + * # the last topmost frame saved -- this should be Ok for our usage, but it may leak frames and things + */ + } + + /* "(tree fragment)":1 + * def __pyx_unpickle_PyDBAdditionalThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_17__pyx_unpickle_PyDBAdditionalThreadInfo, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_PyDBAdditionalThr, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":11 + * __pyx_unpickle_PyDBAdditionalThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_PyDBAdditionalThreadInfo__set_state(PyDBAdditionalThreadInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.conditional_breakpoint_exception = __pyx_state[0]; __pyx_result.is_tracing = __pyx_state[1]; __pyx_result.pydev_call_from_jinja2 = __pyx_state[2]; __pyx_result.pydev_call_inside_jinja2 = __pyx_state[3]; __pyx_result.pydev_django_resolve_frame = __pyx_state[4]; __pyx_result.pydev_func_name = __pyx_state[5]; __pyx_result.pydev_message = __pyx_state[6]; __pyx_result.pydev_next_line = __pyx_state[7]; __pyx_result.pydev_notify_kill = __pyx_state[8]; __pyx_result.pydev_original_step_cmd = __pyx_state[9]; __pyx_result.pydev_smart_step_stop = __pyx_state[10]; __pyx_result.pydev_state = __pyx_state[11]; __pyx_result.pydev_step_cmd = __pyx_state[12]; __pyx_result.pydev_step_stop = __pyx_state[13]; __pyx_result.suspend_type = __pyx_state[14]; __pyx_result.suspended_at_unhandled = __pyx_state[15]; __pyx_result.thread_tracer = __pyx_state[16]; __pyx_result.top_level_thread_tracer_no_back_frames = __pyx_state[17]; __pyx_result.top_level_thread_tracer_unhandled = __pyx_state[18]; __pyx_result.trace_suspend_type = __pyx_state[19] + * if len(__pyx_state) > 20 and hasattr(__pyx_result, '__dict__'): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_19__pyx_unpickle_PyDBFrame, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_PyDBFrame, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_SafeCallWrapper(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_21__pyx_unpickle_SafeCallWrapper, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_SafeCallWrapper, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":11 + * __pyx_unpickle_SafeCallWrapper__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_SafeCallWrapper__set_state(SafeCallWrapper __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.method_object = __pyx_state[0] + * if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_23__pyx_unpickle_TopLevelThreadTracerOnlyUnhandledExceptions, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_TopLevelThreadTra, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_TopLevelThreadTracerNoBackFrame(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_25__pyx_unpickle_TopLevelThreadTracerNoBackFrame, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_TopLevelThreadTra_2, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":11 + * __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_TopLevelThreadTracerNoBackFrame__set_state(TopLevelThreadTracerNoBackFrame __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result._args = __pyx_state[0]; __pyx_result._frame_trace_dispatch = __pyx_state[1]; __pyx_result._last_exc_arg = __pyx_state[2]; __pyx_result._last_raise_line = __pyx_state[3]; __pyx_result._raise_lines = __pyx_state[4]; __pyx_result._try_except_info = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_14_pydevd_bundle_13pydevd_cython_27__pyx_unpickle_ThreadTracer, NULL, __pyx_n_s_pydevd_bundle_pydevd_cython); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_ThreadTracer, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_bundle/pydevd_cython.pyx":1 + * from __future__ import print_function # <<<<<<<<<<<<<< + * + * # Important: Autogenerated file. + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init _pydevd_bundle.pydevd_cython", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + Py_CLEAR(__pyx_m); + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init _pydevd_bundle.pydevd_cython"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); + if (unlikely(!result)) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { + return NULL; + } + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif +#endif + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = PyCFunction_GET_FUNCTION(func); + self = PyCFunction_GET_SELF(func); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallNoArg */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, NULL, 0); + } +#endif +#ifdef __Pyx_CyFunction_USED + if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) +#else + if (likely(PyCFunction_Check(func))) +#endif + { + if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { + return __Pyx_PyObject_CallMethO(func, NULL); + } + } + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); +} +#endif + +/* PyCFunctionFastCall */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { + PyCFunctionObject *func = (PyCFunctionObject*)func_obj; + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + int flags = PyCFunction_GET_FLAGS(func); + assert(PyCFunction_Check(func)); + assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); + assert(nargs >= 0); + assert(nargs == 0 || args != NULL); + /* _PyCFunction_FastCallDict() must not be called with an exception set, + because it may clear it (directly or indirectly) and so the + caller loses its exception */ + assert(!PyErr_Occurred()); + if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { + return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); + } +} +#endif + +/* PyObjectCallOneArg */ +#if CYTHON_COMPILING_IN_CPYTHON +static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_New(1); + if (unlikely(!args)) return NULL; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, &arg, 1); + } +#endif + if (likely(PyCFunction_Check(func))) { + if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { + return __Pyx_PyObject_CallMethO(func, arg); +#if CYTHON_FAST_PYCCALL + } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) { + return __Pyx_PyCFunction_FastCall(func, &arg, 1); +#endif + } + } + return __Pyx__PyObject_CallOneArg(func, arg); +} +#else +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_Pack(1, arg); + if (unlikely(!args)) return NULL; + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +#endif + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* KeywordStringCheck */ +static int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + +/* PyObjectCall2Args */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args, *result = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyFunction_FastCall(function, args, 2); + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyCFunction_FastCall(function, args, 2); + } + #endif + args = PyTuple_New(2); + if (unlikely(!args)) goto done; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); +done: + return result; +} + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; icurexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; + if (unlikely(PyTuple_Check(err))) + return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} +#endif + +/* GetAttr */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_USE_TYPE_SLOTS +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* GetAttr3 */ +static PyObject *__Pyx_GetAttr3Default(PyObject *d) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + Py_INCREF(d); + return d; +} +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { + PyObject *r = __Pyx_GetAttr(o, n); + return (likely(r)) ? r : __Pyx_GetAttr3Default(d); +} + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + __Pyx_PyThreadState_declare + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + #endif + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +#endif + +/* GetException */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) +#endif +{ + PyObject *local_type, *local_value, *local_tb; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* PyObjectSetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +#endif + return PyObject_SetAttr(obj, attr_name, value); +} +#endif + +/* None */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +/* RaiseDoubleKeywords */ +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + continue; + } + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = (**name == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +/* ArgTypeTest */ +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +/* GetItemInt */ +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* RaiseTooManyValuesToUnpack */ +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); +} + +/* RaiseNeedMoreValuesToUnpack */ +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", + index, (index == 1) ? "" : "s"); +} + +/* IterFinish */ +static CYTHON_INLINE int __Pyx_IterFinish(void) { +#if CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* exc_type = tstate->curexc_type; + if (unlikely(exc_type)) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { + PyObject *exc_value, *exc_tb; + exc_value = tstate->curexc_value; + exc_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + Py_DECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_tb); + return 0; + } else { + return -1; + } + } + return 0; +#else + if (unlikely(PyErr_Occurred())) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +#endif +} + +/* UnpackItemEndCheck */ +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else { + return __Pyx_IterFinish(); + } + return 0; +} + +/* ExtTypeTest */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(__Pyx_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + +/* HasAttr */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { + PyObject *r; + if (unlikely(!__Pyx_PyBaseString_Check(n))) { + PyErr_SetString(PyExc_TypeError, + "hasattr(): attribute name must be string"); + return -1; + } + r = __Pyx_GetAttr(o, n); + if (unlikely(!r)) { + PyErr_Clear(); + return 0; + } else { + Py_DECREF(r); + return 1; + } +} + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* RaiseNoneIterError */ +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + +/* PyIntBinop */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long a = PyInt_AS_LONG(op1); + return PyInt_FromLong(a & b); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; +#endif + const digit* digits = ((PyLongObject*)op1)->ob_digit; + const Py_ssize_t size = Py_SIZE(op1); + if (likely(__Pyx_sst_abs(size) <= 1)) { + a = likely(size) ? digits[0] : 0; + if (size == -1) a = -a; + } else { + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_and(op1, op2); + } + } + x = a & b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla & llb; + return PyLong_FromLongLong(llx); +#endif + + + } + #endif + return (inplace ? PyNumber_InPlaceAnd : PyNumber_And)(op1, op2); +} +#endif + +/* UnpackUnboundCMethod */ +static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { + PyObject *method; + method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); + if (unlikely(!method)) + return -1; + target->method = method; +#if CYTHON_COMPILING_IN_CPYTHON + #if PY_MAJOR_VERSION >= 3 + if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type))) + #endif + { + PyMethodDescrObject *descr = (PyMethodDescrObject*) method; + target->func = descr->d_method->ml_meth; + target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS); + } +#endif + return 0; +} + +/* CallUnboundCMethod1 */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) { + if (likely(cfunc->func)) { + int flag = cfunc->flag; + if (flag == METH_O) { + return (*(cfunc->func))(self, arg); + } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) { + if (PY_VERSION_HEX >= 0x030700A0) { + return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1); + } else { + return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); + } + } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) { + return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); + } + } + return __Pyx__CallUnboundCMethod1(cfunc, self, arg); +} +#endif +static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){ + PyObject *args, *result = NULL; + if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_COMPILING_IN_CPYTHON + if (cfunc->func && (cfunc->flag & METH_VARARGS)) { + args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + if (cfunc->flag & METH_KEYWORDS) + result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL); + else + result = (*cfunc->func)(self, args); + } else { + args = PyTuple_New(2); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 1, arg); + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); + } +#else + args = PyTuple_Pack(2, self, arg); + if (unlikely(!args)) goto bad; + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); +#endif +bad: + Py_XDECREF(args); + return result; +} + +/* CallUnboundCMethod2 */ +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1 +static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) { + if (likely(cfunc->func)) { + PyObject *args[2] = {arg1, arg2}; + if (cfunc->flag == METH_FASTCALL) { + #if PY_VERSION_HEX >= 0x030700A0 + return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2); + #else + return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL); + #endif + } + #if PY_VERSION_HEX >= 0x030700A0 + if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS)) + return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL); + #endif + } + return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2); +} +#endif +static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){ + PyObject *args, *result = NULL; + if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_COMPILING_IN_CPYTHON + if (cfunc->func && (cfunc->flag & METH_VARARGS)) { + args = PyTuple_New(2); + if (unlikely(!args)) goto bad; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + if (cfunc->flag & METH_KEYWORDS) + result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL); + else + result = (*cfunc->func)(self, args); + } else { + args = PyTuple_New(3); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 1, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 2, arg2); + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); + } +#else + args = PyTuple_Pack(3, self, arg1, arg2); + if (unlikely(!args)) goto bad; + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); +#endif +bad: + Py_XDECREF(args); + return result; +} + +/* dict_getitem_default */ +static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) { + PyObject* value; +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (unlikely(PyErr_Occurred())) + return NULL; + value = default_value; + } + Py_INCREF(value); + if ((1)); +#else + if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) { + value = PyDict_GetItem(d, key); + if (unlikely(!value)) { + value = default_value; + } + Py_INCREF(value); + } +#endif + else { + if (default_value == Py_None) + value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key); + else + value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value); + } + return value; +} + +/* DictGetItem */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* PyIntBinop */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) { + (void)inplace; + (void)zerodivision_check; + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long x; + long a = PyInt_AS_LONG(op1); + x = (long)((unsigned long)a + b); + if (likely((x^a) >= 0 || (x^b) >= 0)) + return PyInt_FromLong(x); + return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; +#endif + const digit* digits = ((PyLongObject*)op1)->ob_digit; + const Py_ssize_t size = Py_SIZE(op1); + if (likely(__Pyx_sst_abs(size) <= 1)) { + a = likely(size) ? digits[0] : 0; + if (size == -1) a = -a; + } else { + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; +#ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; +#endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + } + x = a + b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla + llb; + return PyLong_FromLongLong(llx); +#endif + + + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + double result; + PyFPE_START_PROTECT("add", return NULL) + result = ((double)a) + (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); + } + return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); +} +#endif + +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (descr != NULL) { + *method = descr; + return 0; + } + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(name)); +#endif + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod1 */ +static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); + Py_DECREF(method); + return result; +} +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { + PyObject *method = NULL, *result; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_Call2Args(method, obj, arg); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) return NULL; + return __Pyx__PyObject_CallMethod1(method, arg); +} + +/* append */ +static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1; + } else { + PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x); + if (unlikely(!retval)) + return -1; + Py_DECREF(retval); + } + return 0; +} + +/* SliceTupleAndList */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) { + Py_ssize_t start = *_start, stop = *_stop, length = *_length; + if (start < 0) { + start += length; + if (start < 0) + start = 0; + } + if (stop < 0) + stop += length; + else if (stop > length) + stop = length; + *_length = stop - start; + *_start = start; + *_stop = stop; +} +static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { + PyObject *v; + Py_ssize_t i; + for (i = 0; i < length; i++) { + v = dest[i] = src[i]; + Py_INCREF(v); + } +} +static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice( + PyObject* src, Py_ssize_t start, Py_ssize_t stop) { + PyObject* dest; + Py_ssize_t length = PyList_GET_SIZE(src); + __Pyx_crop_slice(&start, &stop, &length); + if (unlikely(length <= 0)) + return PyList_New(0); + dest = PyList_New(length); + if (unlikely(!dest)) + return NULL; + __Pyx_copy_object_array( + ((PyListObject*)src)->ob_item + start, + ((PyListObject*)dest)->ob_item, + length); + return dest; +} +static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice( + PyObject* src, Py_ssize_t start, Py_ssize_t stop) { + PyObject* dest; + Py_ssize_t length = PyTuple_GET_SIZE(src); + __Pyx_crop_slice(&start, &stop, &length); + if (unlikely(length <= 0)) + return PyTuple_New(0); + dest = PyTuple_New(length); + if (unlikely(!dest)) + return NULL; + __Pyx_copy_object_array( + ((PyTupleObject*)src)->ob_item + start, + ((PyTupleObject*)dest)->ob_item, + length); + return dest; +} +#endif + +/* pyfrozenset_new */ +static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) { + if (it) { + PyObject* result; +#if CYTHON_COMPILING_IN_PYPY + PyObject* args; + args = PyTuple_Pack(1, it); + if (unlikely(!args)) + return NULL; + result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL); + Py_DECREF(args); + return result; +#else + if (PyFrozenSet_CheckExact(it)) { + Py_INCREF(it); + return it; + } + result = PyFrozenSet_New(it); + if (unlikely(!result)) + return NULL; + if (likely(PySet_GET_SIZE(result))) + return result; + Py_DECREF(result); +#endif + } +#if CYTHON_USE_TYPE_SLOTS + return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL); +#else + return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL); +#endif +} + +/* PySetContains */ +static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) { + int result = -1; + if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) { + PyObject *tmpkey; + PyErr_Clear(); + tmpkey = __Pyx_PyFrozenSet_New(key); + if (tmpkey != NULL) { + result = PySet_Contains(set, tmpkey); + Py_DECREF(tmpkey); + } + } + return result; +} +static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) { + int result = PySet_Contains(set, key); + if (unlikely(result < 0)) { + result = __Pyx_PySet_ContainsUnhashable(set, key); + } + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* PyIntCompare */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) { + if (op1 == op2) { + Py_RETURN_TRUE; + } + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long a = PyInt_AS_LONG(op1); + if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = Py_SIZE(op1); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + if (intval == 0) { + if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } else if (intval < 0) { + if (size >= 0) + Py_RETURN_FALSE; + intval = -intval; + size = -size; + } else { + if (size <= 0) + Py_RETURN_FALSE; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } + return ( + PyObject_RichCompare(op1, op2, Py_EQ)); +} + +/* ObjectGetItem */ +#if CYTHON_USE_TYPE_SLOTS +static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { + PyObject *runerr; + Py_ssize_t key_value; + PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; + if (unlikely(!(m && m->sq_item))) { + PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name); + return NULL; + } + key_value = __Pyx_PyIndex_AsSsize_t(index); + if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) { + return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1); + } + if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) { + PyErr_Clear(); + PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name); + } + return NULL; +} +static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { + PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping; + if (likely(m && m->mp_subscript)) { + return m->mp_subscript(obj, key); + } + return __Pyx_PyObject_GetIndex(obj, key); +} +#endif + +/* Import */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (!py_import) + goto bad; + #endif + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, 1); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif + } + } +bad: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +/* ImportFrom */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, attr_name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(attr_name)); +#endif + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* SetupReduce */ +static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD; + setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD; + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto GOOD; +BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} + +/* SetVTable */ +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +/* TypeImport */ +#ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, + size_t size, enum __Pyx_ImportType_CheckSize check_size) +{ + PyObject *result = 0; + char warning[200]; + Py_ssize_t basicsize; +#ifdef Py_LIMITED_API + PyObject *py_basicsize; +#endif + result = PyObject_GetAttrString(module, class_name); + if (!result) + goto bad; + if (!PyType_Check(result)) { + PyErr_Format(PyExc_TypeError, + "%.200s.%.200s is not a type object", + module_name, class_name); + goto bad; + } +#ifndef Py_LIMITED_API + basicsize = ((PyTypeObject *)result)->tp_basicsize; +#else + py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); + if (!py_basicsize) + goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) + goto bad; +#endif + if ((size_t)basicsize < size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(result); + return NULL; +} +#endif + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = a->tp_base; + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); + } +} + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } +#endif + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (long) -1; + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CheckBinaryVersion */ +static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + return PyErr_WarnEx(NULL, message, 1); + } + return 0; +} + +/* InitStrings */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + ++t; + } + return 0; +} + +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type %.200s). " + "The ability to return an instance of a strict subclass of int " + "is deprecated, and may be removed in a future version of Python.", + Py_TYPE(result)->tp_name)) { + Py_DECREF(result); + return NULL; + } + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + type_name, type_name, Py_TYPE(result)->tp_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +#endif /* Py_PYTHON_H */ diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pxd b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pxd new file mode 100644 index 0000000..303ea79 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pxd @@ -0,0 +1,21 @@ +cdef class PyDBAdditionalThreadInfo: + cdef public int pydev_state; + cdef public object pydev_step_stop; # Actually, it's a frame or None + cdef public int pydev_original_step_cmd; + cdef public int pydev_step_cmd; + cdef public bint pydev_notify_kill; + cdef public object pydev_smart_step_stop; # Actually, it's a frame or None + cdef public bint pydev_django_resolve_frame; + cdef public object pydev_call_from_jinja2; + cdef public object pydev_call_inside_jinja2; + cdef public bint is_tracing; + cdef public tuple conditional_breakpoint_exception; + cdef public str pydev_message; + cdef public int suspend_type; + cdef public int pydev_next_line; + cdef public str pydev_func_name; + cdef public bint suspended_at_unhandled; + cdef public str trace_suspend_type; + cdef public object top_level_thread_tracer_no_back_frames; + cdef public object top_level_thread_tracer_unhandled; + cdef public object thread_tracer; diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pyx b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pyx new file mode 100644 index 0000000..d8d8090 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython.pyx @@ -0,0 +1,1443 @@ +from __future__ import print_function + +# Important: Autogenerated file. + +# DO NOT edit manually! +# DO NOT edit manually! +import sys +from _pydevd_bundle.pydevd_constants import (STATE_RUN, PYTHON_SUSPEND, IS_JYTHON, + USE_CUSTOM_SYS_CURRENT_FRAMES, USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) +from _pydev_bundle import pydev_log +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +pydev_log.debug("Using Cython speedups") +# ELSE +# from _pydevd_bundle.pydevd_frame import PyDBFrame +# ENDIF + +version = 11 + +if USE_CUSTOM_SYS_CURRENT_FRAMES: + + # Some versions of Jython don't have it (but we can provide a replacement) + if IS_JYTHON: + from java.lang import NoSuchFieldException + from org.python.core import ThreadStateMapping + try: + cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version + except NoSuchFieldException: + cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 + cachedThreadState.accessible = True + thread_states = cachedThreadState.get(ThreadStateMapping) + + def _current_frames(): + as_array = thread_states.entrySet().toArray() + ret = {} + for thread_to_state in as_array: + thread = thread_to_state.getKey() + if thread is None: + continue + thread_state = thread_to_state.getValue() + if thread_state is None: + continue + + frame = thread_state.frame + if frame is None: + continue + + ret[thread.getId()] = frame + return ret + + elif USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + _tid_to_last_frame = {} + + # IronPython doesn't have it. Let's use our workaround... + def _current_frames(): + return _tid_to_last_frame + + else: + raise RuntimeError('Unable to proceed (sys._current_frames not available in this Python implementation).') +else: + _current_frames = sys._current_frames + + +#======================================================================================================================= +# PyDBAdditionalThreadInfo +#======================================================================================================================= +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef class PyDBAdditionalThreadInfo: +# ELSE +# class PyDBAdditionalThreadInfo(object): +# ENDIF + + # Note: the params in cython are declared in pydevd_cython.pxd. + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + # ELSE +# __slots__ = [ +# 'pydev_state', +# 'pydev_step_stop', +# 'pydev_original_step_cmd', +# 'pydev_step_cmd', +# 'pydev_notify_kill', +# 'pydev_smart_step_stop', +# 'pydev_django_resolve_frame', +# 'pydev_call_from_jinja2', +# 'pydev_call_inside_jinja2', +# 'is_tracing', +# 'conditional_breakpoint_exception', +# 'pydev_message', +# 'suspend_type', +# 'pydev_next_line', +# 'pydev_func_name', +# 'suspended_at_unhandled', +# 'trace_suspend_type', +# 'top_level_thread_tracer_no_back_frames', +# 'top_level_thread_tracer_unhandled', +# 'thread_tracer', +# ] + # ENDIF + + def __init__(self): + self.pydev_state = STATE_RUN # STATE_RUN or STATE_SUSPEND + self.pydev_step_stop = None + + # Note: we have `pydev_original_step_cmd` and `pydev_step_cmd` because the original is to + # say the action that started it and the other is to say what's the current tracing behavior + # (because it's possible that we start with a step over but may have to switch to a + # different step strategy -- for instance, if a step over is done and we return the current + # method the strategy is changed to a step in). + + self.pydev_original_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + self.pydev_step_cmd = -1 # Something as CMD_STEP_INTO, CMD_STEP_OVER, etc. + + self.pydev_notify_kill = False + self.pydev_smart_step_stop = None + self.pydev_django_resolve_frame = False + self.pydev_call_from_jinja2 = None + self.pydev_call_inside_jinja2 = None + self.is_tracing = False + self.conditional_breakpoint_exception = None + self.pydev_message = '' + self.suspend_type = PYTHON_SUSPEND + self.pydev_next_line = -1 + self.pydev_func_name = '.invalid.' # Must match the type in cython + self.suspended_at_unhandled = False + self.trace_suspend_type = 'trace' # 'trace' or 'frame_eval' + self.top_level_thread_tracer_no_back_frames = [] + self.top_level_thread_tracer_unhandled = None + self.thread_tracer = None + + def get_topmost_frame(self, thread): + ''' + Gets the topmost frame for the given thread. Note that it may be None + and callers should remove the reference to the frame as soon as possible + to avoid disturbing user code. + ''' + # sys._current_frames(): dictionary with thread id -> topmost frame + current_frames = _current_frames() + return current_frames.get(thread.ident) + + def __str__(self): + return 'State:%s Stop:%s Cmd: %s Kill:%s' % ( + self.pydev_state, self.pydev_step_stop, self.pydev_step_cmd, self.pydev_notify_kill) + + +from _pydev_imps._pydev_saved_modules import threading +_set_additional_thread_info_lock = threading.Lock() + + +def set_additional_thread_info(thread): + try: + additional_info = thread.additional_info + if additional_info is None: + raise AttributeError() + except: + with _set_additional_thread_info_lock: + # If it's not there, set it within a lock to avoid any racing + # conditions. + additional_info = getattr(thread, 'additional_info', None) + if additional_info is None: + additional_info = PyDBAdditionalThreadInfo() + thread.additional_info = additional_info + + return additional_info +import linecache +import os.path +import re + +from _pydev_bundle import pydev_log +from _pydevd_bundle import pydevd_dont_trace +from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) +from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace +from _pydevd_bundle.pydevd_utils import get_clsname_for_code +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file +try: + from inspect import CO_GENERATOR +except: + CO_GENERATOR = 0 + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +# ELSE +# # Note: those are now inlined on cython. +# 107 = 107 +# 144 = 144 +# 109 = 109 +# 160 = 160 +# 108 = 108 +# 159 = 159 +# 137 = 137 +# 111 = 111 +# 128 = 128 +# 1 = 1 +# 2 = 2 +# ENDIF + +try: + from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace +except ImportError: + + def send_signature_call_trace(*args, **kwargs): + pass + +basename = os.path.basename + +IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') +DEBUG_START = ('pydevd.py', 'run') +DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') +TRACE_PROPERTY = 'pydevd_traceproperty.py' + + +#======================================================================================================================= +# PyDBFrame +#======================================================================================================================= +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef class PyDBFrame: +# ELSE +# class PyDBFrame: +# '''This makes the tracing for a given frame, so, the trace_dispatch +# is used initially when we enter into a new context ('call') and then +# is reused for the entire context. +# ''' +# ENDIF + + # Note: class (and not instance) attributes. + + # Same thing in the main debugger but only considering the file contents, while the one in the main debugger + # considers the user input (so, the actual result must be a join of both). + filename_to_lines_where_exceptions_are_ignored = {} + filename_to_stat_info = {} + + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + cdef tuple _args + cdef int should_skip + def __init__(self, tuple args): + self._args = args # In the cython version we don't need to pass the frame + self.should_skip = -1 # On cythonized version, put in instance. + # ELSE +# should_skip = -1 # Default value in class (put in instance on set). +# +# def __init__(self, args): +# # args = main_debugger, filename, base, info, t, frame +# # yeap, much faster than putting in self and then getting it from self later on +# self._args = args + # ENDIF + + def set_suspend(self, *args, **kwargs): + self._args[0].set_suspend(*args, **kwargs) + + def do_wait_suspend(self, *args, **kwargs): + self._args[0].do_wait_suspend(*args, **kwargs) + + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + def trace_exception(self, frame, str event, arg): + cdef bint should_stop; + # ELSE +# def trace_exception(self, frame, event, arg): + # ENDIF + if event == 'exception': + should_stop, frame = self.should_stop_on_exception(frame, event, arg) + + if should_stop: + self.handle_exception(frame, event, arg) + return self.trace_dispatch + + return self.trace_exception + + def trace_return(self, frame, event, arg): + if event == 'return': + main_debugger, filename = self._args[0], self._args[1] + send_signature_return_trace(main_debugger, frame, filename, arg) + return self.trace_return + + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + def should_stop_on_exception(self, frame, str event, arg): + cdef PyDBAdditionalThreadInfo info; + cdef bint flag; + # ELSE +# def should_stop_on_exception(self, frame, event, arg): + # ENDIF + + # main_debugger, _filename, info, _thread = self._args + main_debugger = self._args[0] + info = self._args[2] + should_stop = False + + # 2 = 2 + if info.pydev_state != 2: # and breakpoint is not None: + exception, value, trace = arg + + if trace is not None and hasattr(trace, 'tb_next'): + # on jython trace is None on the first event and it may not have a tb_next. + + should_stop = False + exception_breakpoint = None + try: + if main_debugger.plugin is not None: + result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + if result: + should_stop, frame = result + except: + pydev_log.exception() + + if not should_stop: + # It was not handled by any plugin, lets check exception breakpoints. + exception_breakpoint = main_debugger.get_exception_breakpoint( + exception, main_debugger.break_on_caught_exceptions) + + if exception_breakpoint is not None: + if exception is SystemExit and main_debugger.ignore_system_exit_code(value): + return False, frame + + if exception_breakpoint.condition is not None: + eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + if not eval_result: + return False, frame + + if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): + pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) + return False, frame + + if ignore_exception_trace(trace): + return False, frame + + was_just_raised = just_raised(trace) + if was_just_raised: + + if main_debugger.skip_on_exceptions_thrown_in_same_context: + # Option: Don't break if an exception is caught in the same function from which it is thrown + return False, frame + + if exception_breakpoint.notify_on_first_raise_only: + if main_debugger.skip_on_exceptions_thrown_in_same_context: + # In this case we never stop if it was just raised, so, to know if it was the first we + # need to check if we're in the 2nd method. + if not was_just_raised and not just_raised(trace.tb_next): + return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception + + else: + if not was_just_raised: + return False, frame # I.e.: we stop only when it was just raised + + # If it got here we should stop. + should_stop = True + try: + info.pydev_message = exception_breakpoint.qname + except: + info.pydev_message = exception_breakpoint.qname.encode('utf-8') + + if should_stop: + # Always add exception to frame (must remove later after we proceed). + add_exception_to_frame(frame, (exception, value, trace)) + + if exception_breakpoint is not None and exception_breakpoint.expression is not None: + main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) + + return should_stop, frame + + def handle_exception(self, frame, event, arg): + try: + # print('handle_exception', frame.f_lineno, frame.f_code.co_name) + + # We have 3 things in arg: exception type, description, traceback object + trace_obj = arg[2] + main_debugger = self._args[0] + + initial_trace_obj = trace_obj + if trace_obj.tb_next is None and trace_obj.tb_frame is frame: + # I.e.: tb_next should be only None in the context it was thrown (trace_obj.tb_frame is frame is just a double check). + pass + else: + # Get the trace_obj from where the exception was raised... + while trace_obj.tb_next is not None: + trace_obj = trace_obj.tb_next + + if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: + for check_trace_obj in (initial_trace_obj, trace_obj): + filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + + filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored + + lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) + if lines_ignored is None: + lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + + try: + curr_stat = os.stat(filename) + curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + except: + curr_stat = None + + last_stat = self.filename_to_stat_info.get(filename) + if last_stat != curr_stat: + self.filename_to_stat_info[filename] = curr_stat + lines_ignored.clear() + try: + linecache.checkcache(filename) + except: + # Jython 2.1 + linecache.checkcache() + + from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) + if from_user_input: + merged = {} + merged.update(lines_ignored) + # Override what we have with the related entries that the user entered + merged.update(from_user_input) + else: + merged = lines_ignored + + exc_lineno = check_trace_obj.tb_lineno + + # print ('lines ignored', lines_ignored) + # print ('user input', from_user_input) + # print ('merged', merged, 'curr', exc_lineno) + + if exc_lineno not in merged: # Note: check on merged but update lines_ignored. + try: + line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + except: + # Jython 2.1 + line = linecache.getline(filename, exc_lineno) + + if IGNORE_EXCEPTION_TAG.match(line) is not None: + lines_ignored[exc_lineno] = 1 + return + else: + # Put in the cache saying not to ignore + lines_ignored[exc_lineno] = 0 + else: + # Ok, dict has it already cached, so, let's check it... + if merged.get(exc_lineno, 0): + return + + thread = self._args[3] + + try: + frame_id_to_frame = {} + frame_id_to_frame[id(frame)] = frame + f = trace_obj.tb_frame + while f is not None: + frame_id_to_frame[id(f)] = f + f = f.f_back + f = None + + main_debugger.send_caught_exception_stack(thread, arg, id(frame)) + self.set_suspend(thread, 137) + self.do_wait_suspend(thread, frame, event, arg) + main_debugger.send_caught_exception_stack_proceeded(thread) + except: + pydev_log.exception() + + main_debugger.set_trace_for_frame_and_parents(frame) + finally: + # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. + remove_exception_from_frame(frame) + # Clear some local variables... + frame = None + trace_obj = None + initial_trace_obj = None + check_trace_obj = None + f = None + frame_id_to_frame = None + main_debugger = None + thread = None + + def get_func_name(self, frame): + code_obj = frame.f_code + func_name = code_obj.co_name + try: + cls_name = get_clsname_for_code(code_obj, frame) + if cls_name is not None: + return "%s.%s" % (cls_name, func_name) + else: + return func_name + except: + pydev_log.exception() + return func_name + + def show_return_values(self, frame, arg): + try: + try: + f_locals_back = getattr(frame.f_back, "f_locals", None) + if f_locals_back is not None: + return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + if return_values_dict is None: + return_values_dict = {} + f_locals_back[RETURN_VALUES_DICT] = return_values_dict + name = self.get_func_name(frame) + return_values_dict[name] = arg + except: + pydev_log.exception() + finally: + f_locals_back = None + + def remove_return_values(self, main_debugger, frame): + try: + try: + # Showing return values was turned off, we should remove them from locals dict. + # The values can be in the current frame or in the back one + frame.f_locals.pop(RETURN_VALUES_DICT, None) + + f_locals_back = getattr(frame.f_back, "f_locals", None) + if f_locals_back is not None: + f_locals_back.pop(RETURN_VALUES_DICT, None) + except: + pydev_log.exception() + finally: + f_locals_back = None + + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + cpdef trace_dispatch(self, frame, str event, arg): + cdef str filename; + cdef bint is_exception_event; + cdef bint has_exception_breakpoints; + cdef bint can_skip; + cdef PyDBAdditionalThreadInfo info; + cdef int step_cmd; + cdef int line; + cdef bint is_line; + cdef bint is_call; + cdef bint is_return; + cdef bint should_stop; + cdef dict breakpoints_for_file; + cdef str curr_func_name; + cdef bint exist_result; + cdef dict frame_skips_cache; + cdef tuple frame_cache_key; + cdef tuple line_cache_key; + cdef int breakpoints_in_line_cache; + cdef int breakpoints_in_frame_cache; + cdef bint has_breakpoint_in_frame; + cdef bint need_trace_return; + # ELSE +# def trace_dispatch(self, frame, event, arg): + # ENDIF + # DEBUG = 'code_to_debug' in frame.f_code.co_filename + main_debugger, filename, info, thread, frame_skips_cache, frame_cache_key = self._args + # if DEBUG: print('frame trace_dispatch %s %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, info.pydev_step_cmd)) + try: + info.is_tracing = True + line = frame.f_lineno + line_cache_key = (frame_cache_key, line) + + if main_debugger._finish_debugging_session: + return None if event == 'call' else NO_FTRACE + + plugin_manager = main_debugger.plugin + + is_exception_event = event == 'exception' + has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks + + if is_exception_event: + if has_exception_breakpoints: + should_stop, frame = self.should_stop_on_exception(frame, event, arg) + if should_stop: + self.handle_exception(frame, event, arg) + return self.trace_dispatch + is_line = False + is_return = False + is_call = False + else: + is_line = event == 'line' + is_return = event == 'return' + is_call = event == 'call' + if not is_line and not is_return and not is_call: + # Unexpected: just keep the same trace func. + return self.trace_dispatch + + need_signature_trace_return = False + if main_debugger.signature_factory is not None: + if is_call: + need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + elif is_return: + send_signature_return_trace(main_debugger, frame, filename, arg) + + stop_frame = info.pydev_step_stop + step_cmd = info.pydev_step_cmd + + if is_exception_event: + breakpoints_for_file = None + if stop_frame and stop_frame is not frame and step_cmd in (108, 159) and \ + arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + if step_cmd == 108: + info.pydev_step_cmd = 107 + else: + info.pydev_step_cmd = 144 + info.pydev_step_stop = None + else: + # If we are in single step mode and something causes us to exit the current frame, we need to make sure we break + # eventually. Force the step mode to step into and the step stop frame to None. + # I.e.: F6 in the end of a function should stop in the next possible position (instead of forcing the user + # to make a step in or step over at that location). + # Note: this is especially troublesome when we're skipping code with the + # @DontTrace comment. + if stop_frame is frame and is_return and step_cmd in (108, 109, 159, 160): + if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + if step_cmd in (108, 109): + info.pydev_step_cmd = 107 + else: + info.pydev_step_cmd = 144 + info.pydev_step_stop = None + + breakpoints_for_file = main_debugger.breakpoints.get(filename) + + can_skip = False + + if info.pydev_state == 1: # 1 = 1 + # we can skip if: + # - we have no stop marked + # - we should make a step return/step over and we're not in the current frame + can_skip = (step_cmd == -1 and stop_frame is None) \ + or (step_cmd in (108, 109, 159, 160) and stop_frame is not frame) + + if can_skip: + if plugin_manager is not None and ( + main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + can_skip = plugin_manager.can_skip(main_debugger, frame) + + if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (108, 159) and frame.f_back is info.pydev_step_stop: + # trace function for showing return values after step over + can_skip = False + + # Let's check to see if we are in a function that has a breakpoint. If we don't have a breakpoint, + # we will return nothing for the next trace + # also, after we hit a breakpoint and go to some other debugging state, we have to force the set trace anyway, + # so, that's why the additional checks are there. + if not breakpoints_for_file: + if can_skip: + if has_exception_breakpoints: + return self.trace_exception + else: + if need_signature_trace_return: + return self.trace_return + else: + return None if is_call else NO_FTRACE + + else: + # When cached, 0 means we don't have a breakpoint and 1 means we have. + if can_skip: + breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + if breakpoints_in_line_cache == 0: + return self.trace_dispatch + + breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1) + if breakpoints_in_frame_cache != -1: + # Gotten from cache. + has_breakpoint_in_frame = breakpoints_in_frame_cache == 1 + + else: + has_breakpoint_in_frame = False + # Checks the breakpoint to see if there is a context match in some function + curr_func_name = frame.f_code.co_name + + # global context is set with an empty name + if curr_func_name in ('?', '', ''): + curr_func_name = '' + + for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() + # will match either global or some function + if breakpoint.func_name in ('None', curr_func_name): + has_breakpoint_in_frame = True + break + + # Cache the value (1 or 0 or -1 for default because of cython). + if has_breakpoint_in_frame: + frame_skips_cache[frame_cache_key] = 1 + else: + frame_skips_cache[frame_cache_key] = 0 + + if can_skip and not has_breakpoint_in_frame: + if has_exception_breakpoints: + return self.trace_exception + else: + if need_signature_trace_return: + return self.trace_return + else: + return None if is_call else NO_FTRACE + + # We may have hit a breakpoint or we are already in step mode. Either way, let's check what we should do in this frame + # if DEBUG: print('NOT skipped: %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, event, frame.__class__.__name__)) + + try: + flag = False + # return is not taken into account for breakpoint hit because we'd have a double-hit in this case + # (one for the line and the other for the return). + + stop_info = {} + breakpoint = None + exist_result = False + stop = False + bp_type = None + if not is_return and info.pydev_state != 2 and breakpoints_for_file is not None and line in breakpoints_for_file: + breakpoint = breakpoints_for_file[line] + new_frame = frame + stop = True + if step_cmd in (108, 159) and (stop_frame is frame and is_line): + stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + if result: + exist_result = True + flag, breakpoint, new_frame, bp_type = result + + if breakpoint: + # ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint + # lets do the conditional stuff here + if stop or exist_result: + eval_result = False + if breakpoint.has_condition: + eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + + if breakpoint.expression is not None: + main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') + main_debugger.writer.add_command(cmd) + + if breakpoint.has_condition: + if not eval_result: + return self.trace_dispatch + elif breakpoint.is_logpoint: + return self.trace_dispatch + + if is_call and frame.f_code.co_name in ('', ''): + # If we find a call for a module, it means that the module is being imported/executed for the + # first time. In this case we have to ignore this hit as it may later duplicated by a + # line event at the same place (so, if there's a module with a print() in the first line + # the user will hit that line twice, which is not what we want). + # + # As for lambda, as it only has a single statement, it's not interesting to trace + # its call and later its line event as they're usually in the same line. + + return self.trace_dispatch + + if main_debugger.show_return_values: + if is_return and info.pydev_step_cmd in (108, 159) and frame.f_back == info.pydev_step_stop: + self.show_return_values(frame, arg) + + elif main_debugger.remove_return_values_flag: + try: + self.remove_return_values(main_debugger, frame) + finally: + main_debugger.remove_return_values_flag = False + + if stop: + self.set_suspend( + thread, + 111, + suspend_other_threads=breakpoint and breakpoint.suspend_policy == "ALL", + ) + + elif flag and plugin_manager is not None: + result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + if result: + frame = result + + # if thread has a suspend flag, we suspend with a busy wait + if info.pydev_state == 2: + self.do_wait_suspend(thread, frame, event, arg) + return self.trace_dispatch + else: + if not breakpoint and is_line: + # No stop from anyone and no breakpoint found in line (cache that). + frame_skips_cache[line_cache_key] = 0 + + except: + pydev_log.exception() + raise + + # step handling. We stop when we hit the right frame + try: + should_skip = 0 + if pydevd_dont_trace.should_trace_hook is not None: + if self.should_skip == -1: + # I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times). + # Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code + # Which will be handled by this frame is read-only, so, we can cache it safely. + if not pydevd_dont_trace.should_trace_hook(frame, filename): + # -1, 0, 1 to be Cython-friendly + should_skip = self.should_skip = 1 + else: + should_skip = self.should_skip = 0 + else: + should_skip = self.should_skip + + plugin_stop = False + if should_skip: + stop = False + + elif step_cmd in (107, 144): + force_check_project_scope = step_cmd == 144 + if is_line: + if force_check_project_scope or main_debugger.is_files_filter_enabled: + stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + else: + stop = True + + elif is_return and frame.f_back is not None: + if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + stop = False + else: + if force_check_project_scope or main_debugger.is_files_filter_enabled: + stop = not main_debugger.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, force_check_project_scope) + else: + stop = True + + if plugin_manager is not None: + result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + if result: + stop, plugin_stop = result + + elif step_cmd in (108, 159): + # Note: when dealing with a step over my code it's the same as a step over (the + # difference is that when we return from a frame in one we go to regular step + # into and in the other we go to a step into my code). + stop = stop_frame is frame and is_line + # Note: don't stop on a return for step over, only for line events + # i.e.: don't stop in: (stop_frame is frame.f_back and is_return) as we'd stop twice in that line. + + if frame.f_code.co_flags & CO_GENERATOR: + if is_return: + stop = False + + if plugin_manager is not None: + result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + if result: + stop, plugin_stop = result + + elif step_cmd == 128: + stop = False + if info.pydev_smart_step_stop is frame: + info.pydev_func_name = '.invalid.' # Must match the type in cython + info.pydev_smart_step_stop = None + + if is_line or is_exception_event: + curr_func_name = frame.f_code.co_name + + # global context is set with an empty name + if curr_func_name in ('?', '') or curr_func_name is None: + curr_func_name = '' + + if curr_func_name == info.pydev_func_name: + stop = True + + elif step_cmd in (109, 160): + stop = is_return and stop_frame is frame + + else: + stop = False + + if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): + f_code = getattr(frame.f_back, 'f_code', None) + if f_code is not None: + if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + stop = False + + if plugin_stop: + stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + elif stop: + if is_line: + self.set_suspend(thread, step_cmd) + self.do_wait_suspend(thread, frame, event, arg) + else: # return event + back = frame.f_back + if back is not None: + # When we get to the pydevd run function, the debugging has actually finished for the main thread + # (note that it can still go on for other threads, but for this one, we just make it finish) + # So, just setting it to None should be OK + _, back_filename, base = get_abs_path_real_path_and_base_from_frame(back) + if (base, back.f_code.co_name) in (DEBUG_START, DEBUG_START_PY3K): + back = None + + elif base == TRACE_PROPERTY: + # We dont want to trace the return event of pydevd_traceproperty (custom property for debugging) + # if we're in a return, we want it to appear to the user in the previous frame! + return None if is_call else NO_FTRACE + + elif pydevd_dont_trace.should_trace_hook is not None: + if not pydevd_dont_trace.should_trace_hook(back, back_filename): + # In this case, we'll have to skip the previous one because it shouldn't be traced. + # Also, we have to reset the tracing, because if the parent's parent (or some + # other parent) has to be traced and it's not currently, we wouldn't stop where + # we should anymore (so, a step in/over/return may not stop anywhere if no parent is traced). + # Related test: _debugger_case17a.py + main_debugger.set_trace_for_frame_and_parents(back) + return None if is_call else NO_FTRACE + + if back is not None: + # if we're in a return, we want it to appear to the user in the previous frame! + self.set_suspend(thread, step_cmd) + self.do_wait_suspend(thread, back, event, arg) + else: + # in jython we may not have a back frame + info.pydev_step_stop = None + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + info.pydev_state = 1 + + except KeyboardInterrupt: + raise + except: + try: + pydev_log.exception() + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + except: + return None if is_call else NO_FTRACE + + # if we are quitting, let's stop the tracing + if not main_debugger.quitting: + return self.trace_dispatch + else: + return None if is_call else NO_FTRACE + finally: + info.is_tracing = False + + # end trace_dispatch +from _pydev_bundle.pydev_is_thread_alive import is_thread_alive +from _pydev_bundle.pydev_log import exception as pydev_log_exception +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE, + USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) +from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +from cpython.object cimport PyObject +from cpython.ref cimport Py_INCREF, Py_XDECREF +# ELSE +# from _pydevd_bundle.pydevd_frame import PyDBFrame +# ENDIF + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef dict _global_notify_skipped_step_in +# ELSE +# # Note: those are now inlined on cython. +# 107 = 107 +# 144 = 144 +# 109 = 109 +# 160 = 160 +# ENDIF + +# Cache where we should keep that we completely skipped entering some context. +# It needs to be invalidated when: +# - Breakpoints are changed +# It can be used when running regularly (without step over/step in/step return) +global_cache_skips = {} +global_cache_frame_skips = {} + +_global_notify_skipped_step_in = False +_global_notify_skipped_step_in_lock = threading.Lock() + + +def notify_skipped_step_in_because_of_filters(py_db, frame): + global _global_notify_skipped_step_in + + with _global_notify_skipped_step_in_lock: + if _global_notify_skipped_step_in: + # Check with lock in place (callers should actually have checked + # before without the lock in place due to performance). + return + _global_notify_skipped_step_in = True + py_db.notify_skipped_step_in_because_of_filters(frame) + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef class SafeCallWrapper: + cdef method_object + def __init__(self, method_object): + self.method_object = method_object + def __call__(self, *args): + #Cannot use 'self' once inside the delegate call since we are borrowing the self reference f_trace field + #in the frame, and that reference might get destroyed by set trace on frame and parents + cdef PyObject* method_obj = self.method_object + Py_INCREF(method_obj) + ret = (method_obj)(*args) + Py_XDECREF (method_obj) + return SafeCallWrapper(ret) if ret is not None else None + def get_method_object(self): + return self.method_object +# ELSE +# ENDIF + + +def fix_top_level_trace_and_get_trace_func(py_db, frame): + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + cdef str filename; + cdef str name; + cdef tuple args; + # ENDIF + + # Note: this is always the first entry-point in the tracing for any thread. + # After entering here we'll set a new tracing function for this thread + # where more information is cached (and will also setup the tracing for + # frames where we should deal with unhandled exceptions). + thread = None + # Cache the frame which should be traced to deal with unhandled exceptions. + # (i.e.: thread entry-points). + + f_unhandled = frame + # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + force_only_unhandled_tracer = False + while f_unhandled is not None: + # name = splitext(basename(f_unhandled.f_code.co_filename))[0] + + name = f_unhandled.f_code.co_filename + # basename + i = name.rfind('/') + j = name.rfind('\\') + if j > i: + i = j + if i >= 0: + name = name[i + 1:] + # remove ext + i = name.rfind('.') + if i >= 0: + name = name[:i] + + if name == 'threading': + if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): + # We need __bootstrap_inner, not __bootstrap. + return None, False + + elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): + # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. + t = f_unhandled.f_locals.get('self') + force_only_unhandled_tracer = True + if t is not None and isinstance(t, threading.Thread): + thread = t + break + + elif name == 'pydev_monkey': + if f_unhandled.f_code.co_name == '__call__': + force_only_unhandled_tracer = True + break + + elif name == 'pydevd': + if f_unhandled.f_code.co_name in ('run', 'main'): + # We need to get to _exec + return None, False + + if f_unhandled.f_code.co_name == '_exec': + force_only_unhandled_tracer = True + break + + elif f_unhandled.f_back is None: + break + + f_unhandled = f_unhandled.f_back + + if thread is None: + # Important: don't call threadingCurrentThread if we're in the threading module + # to avoid creating dummy threads. + if py_db.threading_get_ident is not None: + thread = py_db.threading_active.get(py_db.threading_get_ident()) + if thread is None: + return None, False + else: + # Jython does not have threading.get_ident(). + thread = py_db.threading_current_thread() + + if getattr(thread, 'pydev_do_not_trace', None): + py_db.disable_tracing() + return None, False + + try: + additional_info = thread.additional_info + if additional_info is None: + raise AttributeError() + except: + additional_info = py_db.set_additional_thread_info(thread) + + # print('enter thread tracer', thread, get_current_thread_id(thread)) + args = (py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips) + + if f_unhandled is not None: + if f_unhandled.f_back is None and not force_only_unhandled_tracer: + # Happens when we attach to a running program (cannot reuse instance because it's mutable). + top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) + additional_info.top_level_thread_tracer_no_back_frames.append(top_level_thread_tracer) # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + else: + top_level_thread_tracer = additional_info.top_level_thread_tracer_unhandled + if top_level_thread_tracer is None: + # Stop in some internal place to report about unhandled exceptions + top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) + additional_info.top_level_thread_tracer_unhandled = top_level_thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + + # print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + f_trace = top_level_thread_tracer.get_trace_dispatch_func() + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + f_trace = SafeCallWrapper(f_trace) + # ENDIF + f_unhandled.f_trace = f_trace + + if frame is f_unhandled: + return f_trace, False + + thread_tracer = additional_info.thread_tracer + if thread_tracer is None: + thread_tracer = ThreadTracer(args) + additional_info.thread_tracer = thread_tracer + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + return SafeCallWrapper(thread_tracer), True +# ELSE +# return thread_tracer, True +# ENDIF + + +def trace_dispatch(py_db, frame, event, arg): + thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + if thread_trace_func is None: + return None if event == 'call' else NO_FTRACE + if apply_to_settrace: + py_db.enable_tracing(thread_trace_func) + return thread_trace_func(frame, event, arg) + + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef class TopLevelThreadTracerOnlyUnhandledExceptions: + cdef public tuple _args; + def __init__(self, tuple args): + self._args = args +# ELSE +# class TopLevelThreadTracerOnlyUnhandledExceptions(object): +# +# def __init__(self, args): +# self._args = args +# ENDIF + + def trace_unhandled_exceptions(self, frame, event, arg): + # Note that we ignore the frame as this tracing method should only be put in topmost frames already. + # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + if event == 'exception' and arg is not None: + py_db, t, additional_info = self._args[0:3] + if arg is not None: + if not additional_info.suspended_at_unhandled: + additional_info.suspended_at_unhandled = True + + py_db.stop_on_unhandled_exception(py_db, t, additional_info, arg) + + # No need to reset frame.f_trace to keep the same trace function. + return self.trace_unhandled_exceptions + + def get_trace_dispatch_func(self): + return self.trace_unhandled_exceptions + + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef class TopLevelThreadTracerNoBackFrame: + cdef public object _frame_trace_dispatch; + cdef public tuple _args; + cdef public object _try_except_info; + cdef public object _last_exc_arg; + cdef public set _raise_lines; + cdef public int _last_raise_line; + def __init__(self, frame_trace_dispatch, tuple args): + self._frame_trace_dispatch = frame_trace_dispatch + self._args = args + self._try_except_info = None + self._last_exc_arg = None + self._raise_lines = set() + self._last_raise_line = -1 +# ELSE +# class TopLevelThreadTracerNoBackFrame(object): +# ''' +# This tracer is pretty special in that it's dealing with a frame without f_back (i.e.: top frame +# on remote attach or QThread). +# +# This means that we have to carefully inspect exceptions to discover whether the exception will +# be unhandled or not (if we're dealing with an unhandled exception we need to stop as unhandled, +# otherwise we need to use the regular tracer -- unfortunately the debugger has little info to +# work with in the tracing -- see: https://bugs.python.org/issue34099, so, we inspect bytecode to +# determine if some exception will be traced or not... note that if this is not available -- such +# as on Jython -- we consider any top-level exception to be unnhandled). +# ''' +# +# def __init__(self, frame_trace_dispatch, args): +# self._frame_trace_dispatch = frame_trace_dispatch +# self._args = args +# self._try_except_info = None +# self._last_exc_arg = None +# self._raise_lines = set() +# self._last_raise_line = -1 +# ENDIF + + def trace_dispatch_and_unhandled_exceptions(self, frame, event, arg): + # DEBUG = 'code_to_debug' in frame.f_code.co_filename + # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + frame_trace_dispatch = self._frame_trace_dispatch + if frame_trace_dispatch is not None: + self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + + if event == 'exception': + self._last_exc_arg = arg + self._raise_lines.add(frame.f_lineno) + self._last_raise_line = frame.f_lineno + + elif event == 'return' and self._last_exc_arg is not None: + # For unhandled exceptions we actually track the return when at the topmost level. + try: + py_db, t, additional_info = self._args[0:3] + if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + if frame.f_lineno in self._raise_lines: + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + + else: + if self._try_except_info is None: + self._try_except_info = py_db.collect_try_except_info(frame.f_code) + if not self._try_except_info: + # Consider the last exception as unhandled because there's no try..except in it. + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + else: + # Now, consider only the try..except for the raise + valid_try_except_infos = [] + for try_except_info in self._try_except_info: + if try_except_info.is_line_in_try_block(self._last_raise_line): + valid_try_except_infos.append(try_except_info) + + if not valid_try_except_infos: + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + + else: + # Note: check all, not only the "valid" ones to cover the case + # in "tests_python.test_tracing_on_top_level.raise_unhandled10" + # where one try..except is inside the other with only a raise + # and it's gotten in the except line. + for try_except_info in self._try_except_info: + if try_except_info.is_line_in_except_block(frame.f_lineno): + if ( + frame.f_lineno == try_except_info.except_line or + frame.f_lineno in try_except_info.raise_lines_in_except + ): + # In a raise inside a try..except block or some except which doesn't + # match the raised exception. + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + break + else: + break # exited during the except block (no exception raised) + finally: + # Remove reference to exception after handling it. + self._last_exc_arg = None + + ret = self.trace_dispatch_and_unhandled_exceptions + + # Need to reset (the call to _frame_trace_dispatch may have changed it). + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + frame.f_trace = SafeCallWrapper(ret) + # ELSE +# frame.f_trace = ret + # ENDIF + return ret + + def get_trace_dispatch_func(self): + return self.trace_dispatch_and_unhandled_exceptions + + +# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) +cdef class ThreadTracer: + cdef public tuple _args; + def __init__(self, tuple args): + self._args = args +# ELSE +# class ThreadTracer(object): +# +# def __init__(self, args): +# self._args = args +# ENDIF + + def __call__(self, frame, event, arg): + ''' This is the callback used when we enter some context in the debugger. + + We also decorate the thread we are in with info about the debugging. + The attributes added are: + pydev_state + pydev_step_stop + pydev_step_cmd + pydev_notify_kill + + :param PyDB py_db: + This is the global debugger (this method should actually be added as a method to it). + ''' + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + cdef str filename; + cdef str base; + cdef int pydev_step_cmd; + cdef tuple frame_cache_key; + cdef dict cache_skips; + cdef bint is_stepping; + cdef tuple abs_path_real_path_and_base; + cdef PyDBAdditionalThreadInfo additional_info; + # ENDIF + + # DEBUG = 'code_to_debug' in frame.f_code.co_filename + # if DEBUG: print('ENTER: trace_dispatch: %s %s %s %s' % (frame.f_code.co_filename, frame.f_lineno, event, frame.f_code.co_name)) + py_db, t, additional_info, cache_skips, frame_skips_cache = self._args + pydev_step_cmd = additional_info.pydev_step_cmd + is_stepping = pydev_step_cmd != -1 + + try: + if py_db._finish_debugging_session: + if not py_db._termination_event_set: + # that was not working very well because jython gave some socket errors + try: + if py_db.output_checker_thread is None: + kill_all_pydev_threads() + except: + pydev_log_exception() + py_db._termination_event_set = True + return None if event == 'call' else NO_FTRACE + + # if thread is not alive, cancel trace_dispatch processing + if not is_thread_alive(t): + py_db.notify_thread_not_alive(get_current_thread_id(t)) + return None if event == 'call' else NO_FTRACE + + if py_db.thread_analyser is not None: + py_db.thread_analyser.log_event(frame) + + if py_db.asyncio_analyser is not None: + py_db.asyncio_analyser.log_event(frame) + + # Note: it's important that the context name is also given because we may hit something once + # in the global context and another in the local context. + frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) + if frame_cache_key in cache_skips: + if not is_stepping: + # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + else: + # When stepping we can't take into account caching based on the breakpoints (only global filtering). + if cache_skips.get(frame_cache_key) == 1: + + if additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + notify_skipped_step_in_because_of_filters(py_db, frame) + + back_frame = frame.f_back + if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + if cache_skips.get(back_frame_cache_key) == 1: + # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + else: + # if DEBUG: print('skipped: trace_dispatch (cache hit: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + + try: + # Make fast path faster! + abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + except: + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + + filename = abs_path_real_path_and_base[1] + file_type = py_db.get_file_type(frame, abs_path_real_path_and_base) # we don't want to debug threading or anything related to pydevd + + if file_type is not None: + if file_type == 1: # inlining LIB_FILE = 1 + if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + cache_skips[frame_cache_key] = 1 + return None if event == 'call' else NO_FTRACE + else: + # if DEBUG: print('skipped: trace_dispatch', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + cache_skips[frame_cache_key] = 1 + return None if event == 'call' else NO_FTRACE + + if py_db.is_files_filter_enabled: + if py_db.apply_files_filter(frame, filename, False): + cache_skips[frame_cache_key] = 1 + + if is_stepping and additional_info.pydev_original_step_cmd in (107, 144) and not _global_notify_skipped_step_in: + notify_skipped_step_in_because_of_filters(py_db, frame) + + # A little gotcha, sometimes when we're stepping in we have to stop in a + # return event showing the back frame as the current frame, so, we need + # to check not only the current frame but the back frame too. + back_frame = frame.f_back + if back_frame is not None and pydev_step_cmd in (107, 144, 109, 160): + if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + cache_skips[back_frame_cache_key] = 1 + # if DEBUG: print('skipped: trace_dispatch (filtered out: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + else: + # if DEBUG: print('skipped: trace_dispatch (filtered out: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + + # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) + if additional_info.is_tracing: + return None if event == 'call' else NO_FTRACE # we don't wan't to trace code invoked from pydevd_frame.trace_dispatch + + # Just create PyDBFrame directly (removed support for Python versions < 2.5, which required keeping a weak + # reference to the frame). + ret = PyDBFrame( + ( + py_db, filename, additional_info, t, frame_skips_cache, frame_cache_key, + ) + ).trace_dispatch(frame, event, arg) + if ret is None: + # 1 means skipped because of filters. + # 2 means skipped because no breakpoints were hit. + cache_skips[frame_cache_key] = 2 + return None if event == 'call' else NO_FTRACE + + # IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated) + frame.f_trace = SafeCallWrapper(ret) # Make sure we keep the returned tracer. + # ELSE +# frame.f_trace = ret # Make sure we keep the returned tracer. + # ENDIF + return ret + + except SystemExit: + return None if event == 'call' else NO_FTRACE + + except Exception: + if py_db._finish_debugging_session: + return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + # Log it + try: + if pydev_log_exception is not None: + # This can actually happen during the interpreter shutdown in Python 2.7 + pydev_log_exception() + except: + # Error logging? We're really in the interpreter shutdown... + # (https://github.com/fabioz/PyDev.Debugger/issues/8) + pass + return None if event == 'call' else NO_FTRACE + + +if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + # This is far from ideal, as we'll leak frames (we'll always have the last created frame, not really + # the last topmost frame saved -- this should be Ok for our usage, but it may leak frames and things + # may live longer... as IronPython is garbage-collected, things should live longer anyways, so, it + # shouldn't be an issue as big as it's in CPython -- it may still be annoying, but this should + # be a reasonable workaround until IronPython itself is able to provide that functionality). + # + # See: https://github.com/IronLanguages/main/issues/1630 + from _pydevd_bundle.pydevd_additional_thread_info_regular import _tid_to_last_frame + + _original_call = ThreadTracer.__call__ + + def __call__(self, frame, event, arg): + _tid_to_last_frame[self._args[1].ident] = frame + return _original_call(self, frame, event, arg) + + ThreadTracer.__call__ = __call__ diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython_wrapper.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython_wrapper.py new file mode 100644 index 0000000..1058519 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_cython_wrapper.py @@ -0,0 +1,52 @@ +import sys +try: + try: + from _pydevd_bundle_ext import pydevd_cython as mod + + except ImportError: + from _pydevd_bundle import pydevd_cython as mod + +except ImportError: + import struct + + try: + is_python_64bit = (struct.calcsize('P') == 8) + except: + # In Jython this call fails, but this is Ok, we don't support Jython for speedups anyways. + raise ImportError + plat = '32' + if is_python_64bit: + plat = '64' + + # We also accept things as: + # + # _pydevd_bundle.pydevd_cython_win32_27_32 + # _pydevd_bundle.pydevd_cython_win32_34_64 + # + # to have multiple pre-compiled pyds distributed along the IDE + # (generated by build_tools/build_binaries_windows.py). + + mod_name = 'pydevd_cython_%s_%s%s_%s' % (sys.platform, sys.version_info[0], sys.version_info[1], plat) + check_name = '_pydevd_bundle.%s' % (mod_name,) + mod = getattr(__import__(check_name), mod_name) + +# Regardless of how it was found, make sure it's later available as the +# initial name so that the expected types from cython in frame eval +# are valid. +sys.modules['_pydevd_bundle.pydevd_cython'] = mod + +trace_dispatch = mod.trace_dispatch + +PyDBAdditionalThreadInfo = mod.PyDBAdditionalThreadInfo + +set_additional_thread_info = mod.set_additional_thread_info + +global_cache_skips = mod.global_cache_skips + +global_cache_frame_skips = mod.global_cache_frame_skips + +_set_additional_thread_info_lock = mod._set_additional_thread_info_lock + +fix_top_level_trace_and_get_trace_func = mod.fix_top_level_trace_and_get_trace_func + +version = getattr(mod, 'version', 0) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_defaults.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_defaults.py new file mode 100644 index 0000000..ec2393b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_defaults.py @@ -0,0 +1,8 @@ +''' +This module holds the customization settings for the debugger. +''' +from _pydevd_bundle.pydevd_constants import QUOTED_LINE_PROTOCOL + + +class PydevdCustomization(object): + DEFAULT_PROTOCOL = QUOTED_LINE_PROTOCOL diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace.py new file mode 100644 index 0000000..be73810 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace.py @@ -0,0 +1,123 @@ +''' +Support for a tag that allows skipping over functions while debugging. +''' +import linecache +import re + +# To suppress tracing a method, add the tag @DontTrace +# to a comment either preceding or on the same line as +# the method definition +# +# E.g.: +# #@DontTrace +# def test1(): +# pass +# +# ... or ... +# +# def test2(): #@DontTrace +# pass +DONT_TRACE_TAG = '@DontTrace' + +# Regular expression to match a decorator (at the beginning +# of a line). +RE_DECORATOR = re.compile(r'^\s*@') + +# Mapping from code object to bool. +# If the key exists, the value is the cached result of should_trace_hook +_filename_to_ignored_lines = {} + +def default_should_trace_hook(frame, filename): + ''' + Return True if this frame should be traced, False if tracing should be blocked. + ''' + # First, check whether this code object has a cached value + ignored_lines = _filename_to_ignored_lines.get(filename) + if ignored_lines is None: + # Now, look up that line of code and check for a @DontTrace + # preceding or on the same line as the method. + # E.g.: + # #@DontTrace + # def test(): + # pass + # ... or ... + # def test(): #@DontTrace + # pass + ignored_lines = {} + lines = linecache.getlines(filename) + for i_line, line in enumerate(lines): + j = line.find('#') + if j >= 0: + comment = line[j:] + if DONT_TRACE_TAG in comment: + ignored_lines[i_line] = 1 + + #Note: when it's found in the comment, mark it up and down for the decorator lines found. + k = i_line - 1 + while k >= 0: + if RE_DECORATOR.match(lines[k]): + ignored_lines[k] = 1 + k -= 1 + else: + break + + k = i_line + 1 + while k <= len(lines): + if RE_DECORATOR.match(lines[k]): + ignored_lines[k] = 1 + k += 1 + else: + break + + + _filename_to_ignored_lines[filename] = ignored_lines + + func_line = frame.f_code.co_firstlineno - 1 # co_firstlineno is 1-based, so -1 is needed + return not ( + func_line - 1 in ignored_lines or #-1 to get line before method + func_line in ignored_lines) #method line + + +should_trace_hook = None + + +def clear_trace_filter_cache(): + ''' + Clear the trace filter cache. + Call this after reloading. + ''' + global should_trace_hook + try: + # Need to temporarily disable a hook because otherwise + # _filename_to_ignored_lines.clear() will never complete. + old_hook = should_trace_hook + should_trace_hook = None + + # Clear the linecache + linecache.clearcache() + _filename_to_ignored_lines.clear() + + finally: + should_trace_hook = old_hook + + +def trace_filter(mode): + ''' + Set the trace filter mode. + + mode: Whether to enable the trace hook. + True: Trace filtering on (skipping methods tagged @DontTrace) + False: Trace filtering off (trace methods tagged @DontTrace) + None/default: Toggle trace filtering. + ''' + global should_trace_hook + if mode is None: + mode = should_trace_hook is None + + if mode: + should_trace_hook = default_should_trace_hook + else: + should_trace_hook = None + + return mode + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace_files.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace_files.py new file mode 100644 index 0000000..4a8f600 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_dont_trace_files.py @@ -0,0 +1,136 @@ +# Important: Autogenerated file. + +# DO NOT edit manually! +# DO NOT edit manually! + +from _pydevd_bundle.pydevd_constants import IS_PY3K + +LIB_FILE = 1 +PYDEV_FILE = 2 + +DONT_TRACE = { + # commonly used things from the stdlib that we don't want to trace + 'Queue.py':LIB_FILE, + 'queue.py':LIB_FILE, + 'socket.py':LIB_FILE, + 'weakref.py':LIB_FILE, + '_weakrefset.py':LIB_FILE, + 'linecache.py':LIB_FILE, + 'threading.py':LIB_FILE, + 'dis.py':LIB_FILE, + + # things from pydev that we don't want to trace + '_pydev_execfile.py':PYDEV_FILE, + '__main__pydevd_gen_debug_adapter_protocol.py': PYDEV_FILE, + '_pydev_BaseHTTPServer.py': PYDEV_FILE, + '_pydev_SimpleXMLRPCServer.py': PYDEV_FILE, + '_pydev_SocketServer.py': PYDEV_FILE, + '_pydev_calltip_util.py': PYDEV_FILE, + '_pydev_completer.py': PYDEV_FILE, + '_pydev_execfile.py': PYDEV_FILE, + '_pydev_filesystem_encoding.py': PYDEV_FILE, + '_pydev_getopt.py': PYDEV_FILE, + '_pydev_imports_tipper.py': PYDEV_FILE, + '_pydev_inspect.py': PYDEV_FILE, + '_pydev_jy_imports_tipper.py': PYDEV_FILE, + '_pydev_log.py': PYDEV_FILE, + '_pydev_pkgutil_old.py': PYDEV_FILE, + '_pydev_saved_modules.py': PYDEV_FILE, + '_pydev_sys_patch.py': PYDEV_FILE, + '_pydev_tipper_common.py': PYDEV_FILE, + '_pydev_uuid_old.py': PYDEV_FILE, + '_pydev_xmlrpclib.py': PYDEV_FILE, + 'django_debug.py': PYDEV_FILE, + 'jinja2_debug.py': PYDEV_FILE, + 'pycompletionserver.py': PYDEV_FILE, + 'pydev_app_engine_debug_startup.py': PYDEV_FILE, + 'pydev_console_utils.py': PYDEV_FILE, + 'pydev_import_hook.py': PYDEV_FILE, + 'pydev_imports.py': PYDEV_FILE, + 'pydev_ipython_console.py': PYDEV_FILE, + 'pydev_ipython_console_011.py': PYDEV_FILE, + 'pydev_is_thread_alive.py': PYDEV_FILE, + 'pydev_localhost.py': PYDEV_FILE, + 'pydev_log.py': PYDEV_FILE, + 'pydev_monkey.py': PYDEV_FILE, + 'pydev_monkey_qt.py': PYDEV_FILE, + 'pydev_override.py': PYDEV_FILE, + 'pydev_run_in_console.py': PYDEV_FILE, + 'pydev_umd.py': PYDEV_FILE, + 'pydev_versioncheck.py': PYDEV_FILE, + 'pydevconsole.py': PYDEV_FILE, + 'pydevconsole_code_for_ironpython.py': PYDEV_FILE, + 'pydevd.py': PYDEV_FILE, + 'pydevd_additional_thread_info.py': PYDEV_FILE, + 'pydevd_additional_thread_info_regular.py': PYDEV_FILE, + 'pydevd_api.py': PYDEV_FILE, + 'pydevd_base_schema.py': PYDEV_FILE, + 'pydevd_breakpoints.py': PYDEV_FILE, + 'pydevd_collect_try_except_info.py': PYDEV_FILE, + 'pydevd_comm.py': PYDEV_FILE, + 'pydevd_comm_constants.py': PYDEV_FILE, + 'pydevd_command_line_handling.py': PYDEV_FILE, + 'pydevd_concurrency_logger.py': PYDEV_FILE, + 'pydevd_console.py': PYDEV_FILE, + 'pydevd_constants.py': PYDEV_FILE, + 'pydevd_custom_frames.py': PYDEV_FILE, + 'pydevd_cython_wrapper.py': PYDEV_FILE, + 'pydevd_defaults.py': PYDEV_FILE, + 'pydevd_dont_trace.py': PYDEV_FILE, + 'pydevd_dont_trace_files.py': PYDEV_FILE, + 'pydevd_exec.py': PYDEV_FILE, + 'pydevd_exec2.py': PYDEV_FILE, + 'pydevd_extension_api.py': PYDEV_FILE, + 'pydevd_extension_utils.py': PYDEV_FILE, + 'pydevd_file_utils.py': PYDEV_FILE, + 'pydevd_filtering.py': PYDEV_FILE, + 'pydevd_frame.py': PYDEV_FILE, + 'pydevd_frame_eval_cython_wrapper.py': PYDEV_FILE, + 'pydevd_frame_eval_main.py': PYDEV_FILE, + 'pydevd_frame_tracing.py': PYDEV_FILE, + 'pydevd_frame_utils.py': PYDEV_FILE, + 'pydevd_helpers.py': PYDEV_FILE, + 'pydevd_import_class.py': PYDEV_FILE, + 'pydevd_io.py': PYDEV_FILE, + 'pydevd_json_debug_options.py': PYDEV_FILE, + 'pydevd_kill_all_pydevd_threads.py': PYDEV_FILE, + 'pydevd_modify_bytecode.py': PYDEV_FILE, + 'pydevd_net_command.py': PYDEV_FILE, + 'pydevd_net_command_factory_json.py': PYDEV_FILE, + 'pydevd_net_command_factory_xml.py': PYDEV_FILE, + 'pydevd_plugin_numpy_types.py': PYDEV_FILE, + 'pydevd_plugin_utils.py': PYDEV_FILE, + 'pydevd_plugins_django_form_str.py': PYDEV_FILE, + 'pydevd_process_net_command.py': PYDEV_FILE, + 'pydevd_process_net_command_json.py': PYDEV_FILE, + 'pydevd_referrers.py': PYDEV_FILE, + 'pydevd_reload.py': PYDEV_FILE, + 'pydevd_resolver.py': PYDEV_FILE, + 'pydevd_safe_repr.py': PYDEV_FILE, + 'pydevd_save_locals.py': PYDEV_FILE, + 'pydevd_schema.py': PYDEV_FILE, + 'pydevd_schema_log.py': PYDEV_FILE, + 'pydevd_signature.py': PYDEV_FILE, + 'pydevd_source_mapping.py': PYDEV_FILE, + 'pydevd_stackless.py': PYDEV_FILE, + 'pydevd_suspended_frames.py': PYDEV_FILE, + 'pydevd_thread_wrappers.py': PYDEV_FILE, + 'pydevd_trace_api.py': PYDEV_FILE, + 'pydevd_trace_dispatch.py': PYDEV_FILE, + 'pydevd_trace_dispatch_regular.py': PYDEV_FILE, + 'pydevd_traceproperty.py': PYDEV_FILE, + 'pydevd_tracing.py': PYDEV_FILE, + 'pydevd_utils.py': PYDEV_FILE, + 'pydevd_vars.py': PYDEV_FILE, + 'pydevd_vm_type.py': PYDEV_FILE, + 'pydevd_xml.py': PYDEV_FILE, +} + +if IS_PY3K: + # if we try to trace io.py it seems it can get halted (see http://bugs.python.org/issue4716) + DONT_TRACE['io.py'] = LIB_FILE + + # Don't trace common encodings too + DONT_TRACE['cp1252.py'] = LIB_FILE + DONT_TRACE['utf_8.py'] = LIB_FILE + DONT_TRACE['codecs.py'] = LIB_FILE diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_exec.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_exec.py new file mode 100644 index 0000000..9a342ee --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_exec.py @@ -0,0 +1,5 @@ +def Exec(exp, global_vars, local_vars=None): + if local_vars is not None: + exec exp in global_vars, local_vars + else: + exec exp in global_vars \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_exec2.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_exec2.py new file mode 100644 index 0000000..ee4f37a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_exec2.py @@ -0,0 +1,5 @@ +def Exec(exp, global_vars, local_vars=None): + if local_vars is not None: + exec(exp, global_vars, local_vars) + else: + exec(exp, global_vars) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_extension_api.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_extension_api.py new file mode 100644 index 0000000..aac7c79 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_extension_api.py @@ -0,0 +1,87 @@ +import abc + + +# borrowed from from six +def _with_metaclass(meta, *bases): + """Create a base class with a metaclass.""" + + class metaclass(meta): + def __new__(cls, name, this_bases, d): + return meta(name, bases, d) + + return type.__new__(metaclass, 'temporary_class', (), {}) + + +# ======================================================================================================================= +# AbstractResolver +# ======================================================================================================================= +class _AbstractResolver(_with_metaclass(abc.ABCMeta)): + """ + This class exists only for documentation purposes to explain how to create a resolver. + + Some examples on how to resolve things: + - list: get_dictionary could return a dict with index->item and use the index to resolve it later + - set: get_dictionary could return a dict with id(object)->object and reiterate in that array to resolve it later + - arbitrary instance: get_dictionary could return dict with attr_name->attr and use getattr to resolve it later + """ + + @abc.abstractmethod + def resolve(self, var, attribute): + """ + In this method, we'll resolve some child item given the string representation of the item in the key + representing the previously asked dictionary. + + @param var: this is the actual variable to be resolved. + @param attribute: this is the string representation of a key previously returned in get_dictionary. + """ + raise NotImplementedError + + @abc.abstractmethod + def get_dictionary(self, var): + """ + @param var: this is the variable that should have its children gotten. + + @return: a dictionary where each pair key, value should be shown to the user as children items + in the variables view for the given var. + """ + raise NotImplementedError + + +class _AbstractProvider(_with_metaclass(abc.ABCMeta)): + @abc.abstractmethod + def can_provide(self, type_object, type_name): + raise NotImplementedError + + +# ======================================================================================================================= +# API CLASSES: +# ======================================================================================================================= + +class TypeResolveProvider(_AbstractResolver, _AbstractProvider): + """ + Implement this in an extension to provide a custom resolver, see _AbstractResolver + """ + + +class StrPresentationProvider(_AbstractProvider): + """ + Implement this in an extension to provide a str presentation for a type + """ + + @abc.abstractmethod + def get_str(self, val): + raise NotImplementedError + + +class DebuggerEventHandler(_with_metaclass(abc.ABCMeta)): + """ + Implement this to receive lifecycle events from the debugger + """ + + def on_debugger_modules_loaded(self, **kwargs): + """ + This method invoked after all debugger modules are loaded. Useful for importing and/or patching debugger + modules at a safe time + :param kwargs: This is intended to be flexible dict passed from the debugger. + Currently passes the debugger version + """ diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_extension_utils.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_extension_utils.py new file mode 100644 index 0000000..1386cc7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_extension_utils.py @@ -0,0 +1,67 @@ +import pkgutil +import sys +from _pydev_bundle import pydev_log +try: + import pydevd_plugins.extensions as extensions +except: + pydev_log.exception() + extensions = None + + +class ExtensionManager(object): + + def __init__(self): + self.loaded_extensions = None + self.type_to_instance = {} + + def _load_modules(self): + self.loaded_extensions = [] + if extensions: + for module_loader, name, ispkg in pkgutil.walk_packages(extensions.__path__, + extensions.__name__ + '.'): + mod_name = name.split('.')[-1] + if not ispkg and mod_name.startswith('pydevd_plugin'): + try: + __import__(name) + module = sys.modules[name] + self.loaded_extensions.append(module) + except ImportError: + pydev_log.critical('Unable to load extension: %s', name) + + def _ensure_loaded(self): + if self.loaded_extensions is None: + self._load_modules() + + def _iter_attr(self): + for extension in self.loaded_extensions: + dunder_all = getattr(extension, '__all__', None) + for attr_name in dir(extension): + if not attr_name.startswith('_'): + if dunder_all is None or attr_name in dunder_all: + yield attr_name, getattr(extension, attr_name) + + def get_extension_classes(self, extension_type): + self._ensure_loaded() + if extension_type in self.type_to_instance: + return self.type_to_instance[extension_type] + handlers = self.type_to_instance.setdefault(extension_type, []) + for attr_name, attr in self._iter_attr(): + if isinstance(attr, type) and issubclass(attr, extension_type) and attr is not extension_type: + try: + handlers.append(attr()) + except: + pydev_log.exception('Unable to load extension class: %s', attr_name) + return handlers + + +EXTENSION_MANAGER_INSTANCE = ExtensionManager() + + +def extensions_of_type(extension_type): + """ + + :param T extension_type: The type of the extension hook + :rtype: list[T] + """ + return EXTENSION_MANAGER_INSTANCE.get_extension_classes(extension_type) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py new file mode 100644 index 0000000..f763d5e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py @@ -0,0 +1,297 @@ +import fnmatch +import glob +import os.path +import sys + +from _pydev_bundle import pydev_log +import pydevd_file_utils +import json +from collections import namedtuple +from _pydev_imps._pydev_saved_modules import threading + +try: + xrange # noqa +except NameError: + xrange = range # noqa + +ExcludeFilter = namedtuple('ExcludeFilter', 'name, exclude, is_path') + + +def _convert_to_str_and_clear_empty(roots): + if sys.version_info[0] <= 2: + # In py2 we need bytes for the files. + roots = [ + root if not isinstance(root, unicode) else root.encode(sys.getfilesystemencoding()) + for root in roots + ] + + new_roots = [] + for root in roots: + assert isinstance(root, str), '%s not str (found: %s)' % (root, type(root)) + if root: + new_roots.append(root) + return new_roots + + +def _check_matches(patterns, paths): + if not patterns and not paths: + # Matched to the end. + return True + + if (not patterns and paths) or (patterns and not paths): + return False + + pattern = patterns[0] + path = paths[0] + + if not glob.has_magic(pattern): + + if pattern != path: + return False + + elif pattern == '**': + if len(patterns) == 1: + return True # if ** is the last one it matches anything to the right. + + for i in xrange(len(paths)): + # Recursively check the remaining patterns as the + # current pattern could match any number of paths. + if _check_matches(patterns[1:], paths[i:]): + return True + + elif not fnmatch.fnmatch(path, pattern): + # Current part doesn't match. + return False + + return _check_matches(patterns[1:], paths[1:]) + + +def glob_matches_path(path, pattern, sep=os.sep, altsep=os.altsep): + if altsep: + pattern = pattern.replace(altsep, sep) + path = path.replace(altsep, sep) + + drive = '' + if len(path) > 1 and path[1] == ':': + drive, path = path[0], path[2:] + + if drive and len(pattern) > 1: + if pattern[1] == ':': + if drive.lower() != pattern[0].lower(): + return False + pattern = pattern[2:] + + patterns = pattern.split(sep) + paths = path.split(sep) + if paths: + if paths[0] == '': + paths = paths[1:] + if patterns: + if patterns[0] == '': + patterns = patterns[1:] + + return _check_matches(patterns, paths) + + +class FilesFiltering(object): + ''' + Note: calls at FilesFiltering are uncached. + + The actual API used should be through PyDB. + ''' + + def __init__(self): + self._exclude_filters = [] + self._project_roots = [] + self._library_roots = [] + + # Filter out libraries? + self._use_libraries_filter = False + self.require_module = False # True if some exclude filter filters by the module. + + self.set_use_libraries_filter(os.getenv('PYDEVD_FILTER_LIBRARIES') is not None) + + project_roots = os.getenv('IDE_PROJECT_ROOTS', None) + if project_roots is not None: + project_roots = project_roots.split(os.pathsep) + else: + project_roots = [] + self.set_project_roots(project_roots) + + library_roots = os.getenv('LIBRARY_ROOTS', None) + if library_roots is not None: + library_roots = library_roots.split(os.pathsep) + else: + library_roots = self._get_default_library_roots() + self.set_library_roots(library_roots) + + # Stepping filters. + pydevd_filters = os.getenv('PYDEVD_FILTERS', '') + if pydevd_filters: + pydev_log.debug("PYDEVD_FILTERS %s", (pydevd_filters,)) + if pydevd_filters.startswith('{'): + # dict(glob_pattern (str) -> exclude(True or False)) + exclude_filters = [] + for key, val in json.loads(pydevd_filters).items(): + exclude_filters.append(ExcludeFilter(key, val, True)) + self._exclude_filters = exclude_filters + else: + # A ';' separated list of strings with globs for the + # list of excludes. + filters = pydevd_filters.split(';') + new_filters = [] + for new_filter in filters: + if new_filter.strip(): + new_filters.append(ExcludeFilter(new_filter.strip(), True, True)) + self._exclude_filters = new_filters + + @classmethod + def _get_default_library_roots(cls): + # Provide sensible defaults if not in env vars. + import site + + roots = [] + + try: + import sysconfig # Python 2.7 onwards only. + except ImportError: + pass + else: + for path_name in set(('stdlib', 'platstdlib', 'purelib', 'platlib')) & set(sysconfig.get_path_names()): + roots.append(sysconfig.get_path(path_name)) + + # Make sure we always get at least the standard library location (based on the `os` and + # `threading` modules -- it's a bit weird that it may be different on the ci, but it happens). + roots.append(os.path.dirname(os.__file__)) + roots.append(os.path.dirname(threading.__file__)) + + if hasattr(site, 'getusersitepackages'): + site_paths = site.getusersitepackages() + if isinstance(site_paths, (list, tuple)): + for site_path in site_paths: + roots.append(site_path) + else: + roots.append(site_paths) + + if hasattr(site, 'getsitepackages'): + site_paths = site.getsitepackages() + if isinstance(site_paths, (list, tuple)): + for site_path in site_paths: + roots.append(site_path) + else: + roots.append(site_paths) + + for path in sys.path: + if os.path.exists(path) and os.path.basename(path) == 'site-packages': + roots.append(path) + + roots.extend([os.path.realpath(path) for path in roots]) + + return sorted(set(roots)) + + def _normpath(self, filename): + return pydevd_file_utils.get_abs_path_real_path_and_base_from_file(filename)[0] + + def _fix_roots(self, roots): + roots = _convert_to_str_and_clear_empty(roots) + new_roots = [] + for root in roots: + new_roots.append(self._normpath(root)) + return new_roots + + def set_project_roots(self, project_roots): + self._project_roots = self._fix_roots(project_roots) + pydev_log.debug("IDE_PROJECT_ROOTS %s\n" % project_roots) + + def _get_project_roots(self): + return self._project_roots + + def set_library_roots(self, roots): + self._library_roots = self._fix_roots(roots) + pydev_log.debug("LIBRARY_ROOTS %s\n" % roots) + + def _get_library_roots(self): + return self._library_roots + + def in_project_roots(self, filename): + ''' + Note: don't call directly. Use PyDb.in_project_scope (no caching here). + ''' + if filename.startswith('<'): # Note: always use only startswith (pypy can have: "some other name"). + # This is a dummy filename that is usually used for eval or exec. Assume + # that it is user code, with one exception: is used in the + # standard library. + in_project = not filename.startswith(' max(len(x) for x in found_in_library): + in_project = True + + return in_project + + def use_libraries_filter(self): + ''' + Should we debug only what's inside project folders? + ''' + return self._use_libraries_filter + + def set_use_libraries_filter(self, use): + pydev_log.debug("pydevd: Use libraries filter: %s\n" % use) + self._use_libraries_filter = use + + def use_exclude_filters(self): + # Enabled if we have any filters registered. + return len(self._exclude_filters) > 0 + + def exclude_by_filter(self, filename, module_name): + ''' + :return: True if it should be excluded, False if it should be included and None + if no rule matched the given file. + ''' + for exclude_filter in self._exclude_filters: # : :type exclude_filter: ExcludeFilter + if exclude_filter.is_path: + if glob_matches_path(filename, exclude_filter.name): + return exclude_filter.exclude + else: + # Module filter. + if exclude_filter.name == module_name or module_name.startswith(exclude_filter.name + '.'): + return exclude_filter.exclude + return None + + def set_exclude_filters(self, exclude_filters): + ''' + :param list(ExcludeFilter) exclude_filters: + ''' + self._exclude_filters = exclude_filters + self.require_module = False + for exclude_filter in exclude_filters: + if not exclude_filter.is_path: + self.require_module = True + break diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py new file mode 100644 index 0000000..54359b6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py @@ -0,0 +1,764 @@ +import linecache +import os.path +import re + +from _pydev_bundle import pydev_log +from _pydevd_bundle import pydevd_dont_trace +from _pydevd_bundle.pydevd_constants import (dict_iter_values, IS_PY3K, RETURN_VALUES_DICT, NO_FTRACE) +from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised, remove_exception_from_frame, ignore_exception_trace +from _pydevd_bundle.pydevd_utils import get_clsname_for_code +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, get_abs_path_real_path_and_base_from_file +try: + from inspect import CO_GENERATOR +except: + CO_GENERATOR = 0 + +# IFDEF CYTHON +# cython_inline_constant: CMD_STEP_INTO = 107 +# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144 +# cython_inline_constant: CMD_STEP_RETURN = 109 +# cython_inline_constant: CMD_STEP_RETURN_MY_CODE = 160 +# cython_inline_constant: CMD_STEP_OVER = 108 +# cython_inline_constant: CMD_STEP_OVER_MY_CODE = 159 +# cython_inline_constant: CMD_STEP_CAUGHT_EXCEPTION = 137 +# cython_inline_constant: CMD_SET_BREAK = 111 +# cython_inline_constant: CMD_SMART_STEP_INTO = 128 +# cython_inline_constant: STATE_RUN = 1 +# cython_inline_constant: STATE_SUSPEND = 2 +# ELSE +# Note: those are now inlined on cython. +CMD_STEP_INTO = 107 +CMD_STEP_INTO_MY_CODE = 144 +CMD_STEP_RETURN = 109 +CMD_STEP_RETURN_MY_CODE = 160 +CMD_STEP_OVER = 108 +CMD_STEP_OVER_MY_CODE = 159 +CMD_STEP_CAUGHT_EXCEPTION = 137 +CMD_SET_BREAK = 111 +CMD_SMART_STEP_INTO = 128 +STATE_RUN = 1 +STATE_SUSPEND = 2 +# ENDIF + +try: + from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace +except ImportError: + + def send_signature_call_trace(*args, **kwargs): + pass + +basename = os.path.basename + +IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException') +DEBUG_START = ('pydevd.py', 'run') +DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile') +TRACE_PROPERTY = 'pydevd_traceproperty.py' + + +#======================================================================================================================= +# PyDBFrame +#======================================================================================================================= +# IFDEF CYTHON +# cdef class PyDBFrame: +# ELSE +class PyDBFrame: + '''This makes the tracing for a given frame, so, the trace_dispatch + is used initially when we enter into a new context ('call') and then + is reused for the entire context. + ''' +# ENDIF + + # Note: class (and not instance) attributes. + + # Same thing in the main debugger but only considering the file contents, while the one in the main debugger + # considers the user input (so, the actual result must be a join of both). + filename_to_lines_where_exceptions_are_ignored = {} + filename_to_stat_info = {} + + # IFDEF CYTHON + # cdef tuple _args + # cdef int should_skip + # def __init__(self, tuple args): + # self._args = args # In the cython version we don't need to pass the frame + # self.should_skip = -1 # On cythonized version, put in instance. + # ELSE + should_skip = -1 # Default value in class (put in instance on set). + + def __init__(self, args): + # args = main_debugger, filename, base, info, t, frame + # yeap, much faster than putting in self and then getting it from self later on + self._args = args + # ENDIF + + def set_suspend(self, *args, **kwargs): + self._args[0].set_suspend(*args, **kwargs) + + def do_wait_suspend(self, *args, **kwargs): + self._args[0].do_wait_suspend(*args, **kwargs) + + # IFDEF CYTHON + # def trace_exception(self, frame, str event, arg): + # cdef bint should_stop; + # ELSE + def trace_exception(self, frame, event, arg): + # ENDIF + if event == 'exception': + should_stop, frame = self.should_stop_on_exception(frame, event, arg) + + if should_stop: + self.handle_exception(frame, event, arg) + return self.trace_dispatch + + return self.trace_exception + + def trace_return(self, frame, event, arg): + if event == 'return': + main_debugger, filename = self._args[0], self._args[1] + send_signature_return_trace(main_debugger, frame, filename, arg) + return self.trace_return + + # IFDEF CYTHON + # def should_stop_on_exception(self, frame, str event, arg): + # cdef PyDBAdditionalThreadInfo info; + # cdef bint flag; + # ELSE + def should_stop_on_exception(self, frame, event, arg): + # ENDIF + + # main_debugger, _filename, info, _thread = self._args + main_debugger = self._args[0] + info = self._args[2] + should_stop = False + + # STATE_SUSPEND = 2 + if info.pydev_state != 2: # and breakpoint is not None: + exception, value, trace = arg + + if trace is not None and hasattr(trace, 'tb_next'): + # on jython trace is None on the first event and it may not have a tb_next. + + should_stop = False + exception_breakpoint = None + try: + if main_debugger.plugin is not None: + result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg) + if result: + should_stop, frame = result + except: + pydev_log.exception() + + if not should_stop: + # It was not handled by any plugin, lets check exception breakpoints. + exception_breakpoint = main_debugger.get_exception_breakpoint( + exception, main_debugger.break_on_caught_exceptions) + + if exception_breakpoint is not None: + if exception is SystemExit and main_debugger.ignore_system_exit_code(value): + return False, frame + + if exception_breakpoint.condition is not None: + eval_result = main_debugger.handle_breakpoint_condition(info, exception_breakpoint, frame) + if not eval_result: + return False, frame + + if main_debugger.exclude_exception_by_filter(exception_breakpoint, trace, False): + pydev_log.debug("Ignore exception %s in library %s -- (%s)" % (exception, frame.f_code.co_filename, frame.f_code.co_name)) + return False, frame + + if ignore_exception_trace(trace): + return False, frame + + was_just_raised = just_raised(trace) + if was_just_raised: + + if main_debugger.skip_on_exceptions_thrown_in_same_context: + # Option: Don't break if an exception is caught in the same function from which it is thrown + return False, frame + + if exception_breakpoint.notify_on_first_raise_only: + if main_debugger.skip_on_exceptions_thrown_in_same_context: + # In this case we never stop if it was just raised, so, to know if it was the first we + # need to check if we're in the 2nd method. + if not was_just_raised and not just_raised(trace.tb_next): + return False, frame # I.e.: we stop only when we're at the caller of a method that throws an exception + + else: + if not was_just_raised: + return False, frame # I.e.: we stop only when it was just raised + + # If it got here we should stop. + should_stop = True + try: + info.pydev_message = exception_breakpoint.qname + except: + info.pydev_message = exception_breakpoint.qname.encode('utf-8') + + if should_stop: + # Always add exception to frame (must remove later after we proceed). + add_exception_to_frame(frame, (exception, value, trace)) + + if exception_breakpoint is not None and exception_breakpoint.expression is not None: + main_debugger.handle_breakpoint_expression(exception_breakpoint, info, frame) + + return should_stop, frame + + def handle_exception(self, frame, event, arg): + try: + # print('handle_exception', frame.f_lineno, frame.f_code.co_name) + + # We have 3 things in arg: exception type, description, traceback object + trace_obj = arg[2] + main_debugger = self._args[0] + + initial_trace_obj = trace_obj + if trace_obj.tb_next is None and trace_obj.tb_frame is frame: + # I.e.: tb_next should be only None in the context it was thrown (trace_obj.tb_frame is frame is just a double check). + pass + else: + # Get the trace_obj from where the exception was raised... + while trace_obj.tb_next is not None: + trace_obj = trace_obj.tb_next + + if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception: + for check_trace_obj in (initial_trace_obj, trace_obj): + filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1] + + filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored + + lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename) + if lines_ignored is None: + lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {} + + try: + curr_stat = os.stat(filename) + curr_stat = (curr_stat.st_size, curr_stat.st_mtime) + except: + curr_stat = None + + last_stat = self.filename_to_stat_info.get(filename) + if last_stat != curr_stat: + self.filename_to_stat_info[filename] = curr_stat + lines_ignored.clear() + try: + linecache.checkcache(filename) + except: + # Jython 2.1 + linecache.checkcache() + + from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename) + if from_user_input: + merged = {} + merged.update(lines_ignored) + # Override what we have with the related entries that the user entered + merged.update(from_user_input) + else: + merged = lines_ignored + + exc_lineno = check_trace_obj.tb_lineno + + # print ('lines ignored', lines_ignored) + # print ('user input', from_user_input) + # print ('merged', merged, 'curr', exc_lineno) + + if exc_lineno not in merged: # Note: check on merged but update lines_ignored. + try: + line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals) + except: + # Jython 2.1 + line = linecache.getline(filename, exc_lineno) + + if IGNORE_EXCEPTION_TAG.match(line) is not None: + lines_ignored[exc_lineno] = 1 + return + else: + # Put in the cache saying not to ignore + lines_ignored[exc_lineno] = 0 + else: + # Ok, dict has it already cached, so, let's check it... + if merged.get(exc_lineno, 0): + return + + thread = self._args[3] + + try: + frame_id_to_frame = {} + frame_id_to_frame[id(frame)] = frame + f = trace_obj.tb_frame + while f is not None: + frame_id_to_frame[id(f)] = f + f = f.f_back + f = None + + main_debugger.send_caught_exception_stack(thread, arg, id(frame)) + self.set_suspend(thread, CMD_STEP_CAUGHT_EXCEPTION) + self.do_wait_suspend(thread, frame, event, arg) + main_debugger.send_caught_exception_stack_proceeded(thread) + except: + pydev_log.exception() + + main_debugger.set_trace_for_frame_and_parents(frame) + finally: + # Make sure the user cannot see the '__exception__' we added after we leave the suspend state. + remove_exception_from_frame(frame) + # Clear some local variables... + frame = None + trace_obj = None + initial_trace_obj = None + check_trace_obj = None + f = None + frame_id_to_frame = None + main_debugger = None + thread = None + + def get_func_name(self, frame): + code_obj = frame.f_code + func_name = code_obj.co_name + try: + cls_name = get_clsname_for_code(code_obj, frame) + if cls_name is not None: + return "%s.%s" % (cls_name, func_name) + else: + return func_name + except: + pydev_log.exception() + return func_name + + def show_return_values(self, frame, arg): + try: + try: + f_locals_back = getattr(frame.f_back, "f_locals", None) + if f_locals_back is not None: + return_values_dict = f_locals_back.get(RETURN_VALUES_DICT, None) + if return_values_dict is None: + return_values_dict = {} + f_locals_back[RETURN_VALUES_DICT] = return_values_dict + name = self.get_func_name(frame) + return_values_dict[name] = arg + except: + pydev_log.exception() + finally: + f_locals_back = None + + def remove_return_values(self, main_debugger, frame): + try: + try: + # Showing return values was turned off, we should remove them from locals dict. + # The values can be in the current frame or in the back one + frame.f_locals.pop(RETURN_VALUES_DICT, None) + + f_locals_back = getattr(frame.f_back, "f_locals", None) + if f_locals_back is not None: + f_locals_back.pop(RETURN_VALUES_DICT, None) + except: + pydev_log.exception() + finally: + f_locals_back = None + + # IFDEF CYTHON + # cpdef trace_dispatch(self, frame, str event, arg): + # cdef str filename; + # cdef bint is_exception_event; + # cdef bint has_exception_breakpoints; + # cdef bint can_skip; + # cdef PyDBAdditionalThreadInfo info; + # cdef int step_cmd; + # cdef int line; + # cdef bint is_line; + # cdef bint is_call; + # cdef bint is_return; + # cdef bint should_stop; + # cdef dict breakpoints_for_file; + # cdef str curr_func_name; + # cdef bint exist_result; + # cdef dict frame_skips_cache; + # cdef tuple frame_cache_key; + # cdef tuple line_cache_key; + # cdef int breakpoints_in_line_cache; + # cdef int breakpoints_in_frame_cache; + # cdef bint has_breakpoint_in_frame; + # cdef bint need_trace_return; + # ELSE + def trace_dispatch(self, frame, event, arg): + # ENDIF + # DEBUG = 'code_to_debug' in frame.f_code.co_filename + main_debugger, filename, info, thread, frame_skips_cache, frame_cache_key = self._args + # if DEBUG: print('frame trace_dispatch %s %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event, info.pydev_step_cmd)) + try: + info.is_tracing = True + line = frame.f_lineno + line_cache_key = (frame_cache_key, line) + + if main_debugger._finish_debugging_session: + return None if event == 'call' else NO_FTRACE + + plugin_manager = main_debugger.plugin + + is_exception_event = event == 'exception' + has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks + + if is_exception_event: + if has_exception_breakpoints: + should_stop, frame = self.should_stop_on_exception(frame, event, arg) + if should_stop: + self.handle_exception(frame, event, arg) + return self.trace_dispatch + is_line = False + is_return = False + is_call = False + else: + is_line = event == 'line' + is_return = event == 'return' + is_call = event == 'call' + if not is_line and not is_return and not is_call: + # Unexpected: just keep the same trace func. + return self.trace_dispatch + + need_signature_trace_return = False + if main_debugger.signature_factory is not None: + if is_call: + need_signature_trace_return = send_signature_call_trace(main_debugger, frame, filename) + elif is_return: + send_signature_return_trace(main_debugger, frame, filename, arg) + + stop_frame = info.pydev_step_stop + step_cmd = info.pydev_step_cmd + + if is_exception_event: + breakpoints_for_file = None + if stop_frame and stop_frame is not frame and step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and \ + arg[0] in (StopIteration, GeneratorExit) and arg[2] is None: + if step_cmd == CMD_STEP_OVER: + info.pydev_step_cmd = CMD_STEP_INTO + else: + info.pydev_step_cmd = CMD_STEP_INTO_MY_CODE + info.pydev_step_stop = None + else: + # If we are in single step mode and something causes us to exit the current frame, we need to make sure we break + # eventually. Force the step mode to step into and the step stop frame to None. + # I.e.: F6 in the end of a function should stop in the next possible position (instead of forcing the user + # to make a step in or step over at that location). + # Note: this is especially troublesome when we're skipping code with the + # @DontTrace comment. + if stop_frame is frame and is_return and step_cmd in (CMD_STEP_OVER, CMD_STEP_RETURN, CMD_STEP_OVER_MY_CODE, CMD_STEP_RETURN_MY_CODE): + if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR) + if step_cmd in (CMD_STEP_OVER, CMD_STEP_RETURN): + info.pydev_step_cmd = CMD_STEP_INTO + else: + info.pydev_step_cmd = CMD_STEP_INTO_MY_CODE + info.pydev_step_stop = None + + breakpoints_for_file = main_debugger.breakpoints.get(filename) + + can_skip = False + + if info.pydev_state == 1: # STATE_RUN = 1 + # we can skip if: + # - we have no stop marked + # - we should make a step return/step over and we're not in the current frame + can_skip = (step_cmd == -1 and stop_frame is None) \ + or (step_cmd in (CMD_STEP_OVER, CMD_STEP_RETURN, CMD_STEP_OVER_MY_CODE, CMD_STEP_RETURN_MY_CODE) and stop_frame is not frame) + + if can_skip: + if plugin_manager is not None and ( + main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks): + can_skip = plugin_manager.can_skip(main_debugger, frame) + + if can_skip and main_debugger.show_return_values and info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and frame.f_back is info.pydev_step_stop: + # trace function for showing return values after step over + can_skip = False + + # Let's check to see if we are in a function that has a breakpoint. If we don't have a breakpoint, + # we will return nothing for the next trace + # also, after we hit a breakpoint and go to some other debugging state, we have to force the set trace anyway, + # so, that's why the additional checks are there. + if not breakpoints_for_file: + if can_skip: + if has_exception_breakpoints: + return self.trace_exception + else: + if need_signature_trace_return: + return self.trace_return + else: + return None if is_call else NO_FTRACE + + else: + # When cached, 0 means we don't have a breakpoint and 1 means we have. + if can_skip: + breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1) + if breakpoints_in_line_cache == 0: + return self.trace_dispatch + + breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1) + if breakpoints_in_frame_cache != -1: + # Gotten from cache. + has_breakpoint_in_frame = breakpoints_in_frame_cache == 1 + + else: + has_breakpoint_in_frame = False + # Checks the breakpoint to see if there is a context match in some function + curr_func_name = frame.f_code.co_name + + # global context is set with an empty name + if curr_func_name in ('?', '', ''): + curr_func_name = '' + + for breakpoint in dict_iter_values(breakpoints_for_file): # jython does not support itervalues() + # will match either global or some function + if breakpoint.func_name in ('None', curr_func_name): + has_breakpoint_in_frame = True + break + + # Cache the value (1 or 0 or -1 for default because of cython). + if has_breakpoint_in_frame: + frame_skips_cache[frame_cache_key] = 1 + else: + frame_skips_cache[frame_cache_key] = 0 + + if can_skip and not has_breakpoint_in_frame: + if has_exception_breakpoints: + return self.trace_exception + else: + if need_signature_trace_return: + return self.trace_return + else: + return None if is_call else NO_FTRACE + + # We may have hit a breakpoint or we are already in step mode. Either way, let's check what we should do in this frame + # if DEBUG: print('NOT skipped: %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, event, frame.__class__.__name__)) + + try: + flag = False + # return is not taken into account for breakpoint hit because we'd have a double-hit in this case + # (one for the line and the other for the return). + + stop_info = {} + breakpoint = None + exist_result = False + stop = False + bp_type = None + if not is_return and info.pydev_state != STATE_SUSPEND and breakpoints_for_file is not None and line in breakpoints_for_file: + breakpoint = breakpoints_for_file[line] + new_frame = frame + stop = True + if step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and (stop_frame is frame and is_line): + stop = False # we don't stop on breakpoint if we have to stop by step-over (it will be processed later) + elif plugin_manager is not None and main_debugger.has_plugin_line_breaks: + result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args) + if result: + exist_result = True + flag, breakpoint, new_frame, bp_type = result + + if breakpoint: + # ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint + # lets do the conditional stuff here + if stop or exist_result: + eval_result = False + if breakpoint.has_condition: + eval_result = main_debugger.handle_breakpoint_condition(info, breakpoint, new_frame) + + if breakpoint.expression is not None: + main_debugger.handle_breakpoint_expression(breakpoint, info, new_frame) + if breakpoint.is_logpoint and info.pydev_message is not None and len(info.pydev_message) > 0: + cmd = main_debugger.cmd_factory.make_io_message(info.pydev_message + os.linesep, '1') + main_debugger.writer.add_command(cmd) + + if breakpoint.has_condition: + if not eval_result: + return self.trace_dispatch + elif breakpoint.is_logpoint: + return self.trace_dispatch + + if is_call and frame.f_code.co_name in ('', ''): + # If we find a call for a module, it means that the module is being imported/executed for the + # first time. In this case we have to ignore this hit as it may later duplicated by a + # line event at the same place (so, if there's a module with a print() in the first line + # the user will hit that line twice, which is not what we want). + # + # As for lambda, as it only has a single statement, it's not interesting to trace + # its call and later its line event as they're usually in the same line. + + return self.trace_dispatch + + if main_debugger.show_return_values: + if is_return and info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and frame.f_back == info.pydev_step_stop: + self.show_return_values(frame, arg) + + elif main_debugger.remove_return_values_flag: + try: + self.remove_return_values(main_debugger, frame) + finally: + main_debugger.remove_return_values_flag = False + + if stop: + self.set_suspend( + thread, + CMD_SET_BREAK, + suspend_other_threads=breakpoint and breakpoint.suspend_policy == "ALL", + ) + + elif flag and plugin_manager is not None: + result = plugin_manager.suspend(main_debugger, thread, frame, bp_type) + if result: + frame = result + + # if thread has a suspend flag, we suspend with a busy wait + if info.pydev_state == STATE_SUSPEND: + self.do_wait_suspend(thread, frame, event, arg) + return self.trace_dispatch + else: + if not breakpoint and is_line: + # No stop from anyone and no breakpoint found in line (cache that). + frame_skips_cache[line_cache_key] = 0 + + except: + pydev_log.exception() + raise + + # step handling. We stop when we hit the right frame + try: + should_skip = 0 + if pydevd_dont_trace.should_trace_hook is not None: + if self.should_skip == -1: + # I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times). + # Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code + # Which will be handled by this frame is read-only, so, we can cache it safely. + if not pydevd_dont_trace.should_trace_hook(frame, filename): + # -1, 0, 1 to be Cython-friendly + should_skip = self.should_skip = 1 + else: + should_skip = self.should_skip = 0 + else: + should_skip = self.should_skip + + plugin_stop = False + if should_skip: + stop = False + + elif step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE): + force_check_project_scope = step_cmd == CMD_STEP_INTO_MY_CODE + if is_line: + if force_check_project_scope or main_debugger.is_files_filter_enabled: + stop = not main_debugger.apply_files_filter(frame, frame.f_code.co_filename, force_check_project_scope) + else: + stop = True + + elif is_return and frame.f_back is not None: + if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + stop = False + else: + if force_check_project_scope or main_debugger.is_files_filter_enabled: + stop = not main_debugger.apply_files_filter(frame.f_back, frame.f_back.f_code.co_filename, force_check_project_scope) + else: + stop = True + + if plugin_manager is not None: + result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop) + if result: + stop, plugin_stop = result + + elif step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE): + # Note: when dealing with a step over my code it's the same as a step over (the + # difference is that when we return from a frame in one we go to regular step + # into and in the other we go to a step into my code). + stop = stop_frame is frame and is_line + # Note: don't stop on a return for step over, only for line events + # i.e.: don't stop in: (stop_frame is frame.f_back and is_return) as we'd stop twice in that line. + + if frame.f_code.co_flags & CO_GENERATOR: + if is_return: + stop = False + + if plugin_manager is not None: + result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop) + if result: + stop, plugin_stop = result + + elif step_cmd == CMD_SMART_STEP_INTO: + stop = False + if info.pydev_smart_step_stop is frame: + info.pydev_func_name = '.invalid.' # Must match the type in cython + info.pydev_smart_step_stop = None + + if is_line or is_exception_event: + curr_func_name = frame.f_code.co_name + + # global context is set with an empty name + if curr_func_name in ('?', '') or curr_func_name is None: + curr_func_name = '' + + if curr_func_name == info.pydev_func_name: + stop = True + + elif step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE): + stop = is_return and stop_frame is frame + + else: + stop = False + + if stop and step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"): + f_code = getattr(frame.f_back, 'f_code', None) + if f_code is not None: + if main_debugger.get_file_type(frame.f_back) == main_debugger.PYDEV_FILE: + stop = False + + if plugin_stop: + stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd) + elif stop: + if is_line: + self.set_suspend(thread, step_cmd) + self.do_wait_suspend(thread, frame, event, arg) + else: # return event + back = frame.f_back + if back is not None: + # When we get to the pydevd run function, the debugging has actually finished for the main thread + # (note that it can still go on for other threads, but for this one, we just make it finish) + # So, just setting it to None should be OK + _, back_filename, base = get_abs_path_real_path_and_base_from_frame(back) + if (base, back.f_code.co_name) in (DEBUG_START, DEBUG_START_PY3K): + back = None + + elif base == TRACE_PROPERTY: + # We dont want to trace the return event of pydevd_traceproperty (custom property for debugging) + # if we're in a return, we want it to appear to the user in the previous frame! + return None if is_call else NO_FTRACE + + elif pydevd_dont_trace.should_trace_hook is not None: + if not pydevd_dont_trace.should_trace_hook(back, back_filename): + # In this case, we'll have to skip the previous one because it shouldn't be traced. + # Also, we have to reset the tracing, because if the parent's parent (or some + # other parent) has to be traced and it's not currently, we wouldn't stop where + # we should anymore (so, a step in/over/return may not stop anywhere if no parent is traced). + # Related test: _debugger_case17a.py + main_debugger.set_trace_for_frame_and_parents(back) + return None if is_call else NO_FTRACE + + if back is not None: + # if we're in a return, we want it to appear to the user in the previous frame! + self.set_suspend(thread, step_cmd) + self.do_wait_suspend(thread, back, event, arg) + else: + # in jython we may not have a back frame + info.pydev_step_stop = None + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + info.pydev_state = STATE_RUN + + except KeyboardInterrupt: + raise + except: + try: + pydev_log.exception() + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + except: + return None if is_call else NO_FTRACE + + # if we are quitting, let's stop the tracing + if not main_debugger.quitting: + return self.trace_dispatch + else: + return None if is_call else NO_FTRACE + finally: + info.is_tracing = False + + # end trace_dispatch diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame_utils.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame_utils.py new file mode 100644 index 0000000..d7ad3e2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_frame_utils.py @@ -0,0 +1,74 @@ +from _pydevd_bundle.pydevd_constants import IS_PY3K + + +class Frame(object): + + def __init__( + self, + f_back, + f_fileno, + f_code, + f_locals, + f_globals=None, + f_trace=None): + self.f_back = f_back + self.f_lineno = f_fileno + self.f_code = f_code + self.f_locals = f_locals + self.f_globals = f_globals + self.f_trace = f_trace + + if self.f_globals is None: + self.f_globals = {} + + +class FCode(object): + + def __init__(self, name, filename): + self.co_name = name + self.co_filename = filename + self.co_firstlineno = 1 + + +def add_exception_to_frame(frame, exception_info): + frame.f_locals['__exception__'] = exception_info + + +def remove_exception_from_frame(frame): + frame.f_locals.pop('__exception__', None) + + +FILES_WITH_IMPORT_HOOKS = ['pydev_monkey_qt.py', 'pydev_import_hook.py'] + + +def just_raised(trace): + if trace is None: + return False + return trace.tb_next is None + + +def ignore_exception_trace(trace): + while trace is not None: + filename = trace.tb_frame.f_code.co_filename + if filename in ( + '', ''): + # Do not stop on inner exceptions in py3 while importing + return True + + # ImportError should appear in a user's code, not inside debugger + for file in FILES_WITH_IMPORT_HOOKS: + if filename.endswith(file): + return True + + trace = trace.tb_next + + return False + + +def cached_call(obj, func, *args): + cached_name = '_cached_' + func.__name__ + if not hasattr(obj, cached_name): + setattr(obj, cached_name, func(*args)) + + return getattr(obj, cached_name) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_import_class.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_import_class.py new file mode 100644 index 0000000..ee3527c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_import_class.py @@ -0,0 +1,68 @@ +#Note: code gotten from _pydev_imports_tipper. + +import sys + +def _imp(name, log=None): + try: + return __import__(name) + except: + if '.' in name: + sub = name[0:name.rfind('.')] + + if log is not None: + log.add_content('Unable to import', name, 'trying with', sub) + log.add_exception() + + return _imp(sub, log) + else: + s = 'Unable to import module: %s - sys.path: %s' % (str(name), sys.path) + if log is not None: + log.add_content(s) + log.add_exception() + + raise ImportError(s) + + +IS_IPY = False +if sys.platform == 'cli': + IS_IPY = True + _old_imp = _imp + def _imp(name, log=None): + #We must add a reference in clr for .Net + import clr #@UnresolvedImport + initial_name = name + while '.' in name: + try: + clr.AddReference(name) + break #If it worked, that's OK. + except: + name = name[0:name.rfind('.')] + else: + try: + clr.AddReference(name) + except: + pass #That's OK (not dot net module). + + return _old_imp(initial_name, log) + + +def import_name(name, log=None): + mod = _imp(name, log) + + components = name.split('.') + + old_comp = None + for comp in components[1:]: + try: + #this happens in the following case: + #we have mx.DateTime.mxDateTime.mxDateTime.pyd + #but after importing it, mx.DateTime.mxDateTime shadows access to mxDateTime.pyd + mod = getattr(mod, comp) + except AttributeError: + if old_comp != comp: + raise + + old_comp = comp + + return mod + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py new file mode 100644 index 0000000..aaa64c2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py @@ -0,0 +1,136 @@ +from _pydevd_bundle import pydevd_constants +from _pydev_imps._pydev_saved_modules import threading + +IS_PY3K = pydevd_constants.IS_PY3K + + +class IORedirector: + ''' + This class works to wrap a stream (stdout/stderr) with an additional redirect. + ''' + + def __init__(self, original, new_redirect, wrap_buffer=False): + ''' + :param stream original: + The stream to be wrapped (usually stdout/stderr, but could be None). + + :param stream new_redirect: + Usually IOBuf (below). + + :param bool wrap_buffer: + Whether to create a buffer attribute (needed to mimick python 3 s + tdout/stderr which has a buffer to write binary data). + ''' + self._lock = threading.RLock() + self._writing = False + self._redirect_to = (original, new_redirect) + if wrap_buffer and hasattr(original, 'buffer'): + self.buffer = IORedirector(original.buffer, new_redirect.buffer, False) + + def write(self, s): + # Note that writing to the original stream may fail for some reasons + # (such as trying to write something that's not a string or having it closed). + with self._lock: + if self._writing: + return + self._writing = True + try: + for r in self._redirect_to: + if hasattr(r, 'write'): + r.write(s) + finally: + self._writing = False + + def isatty(self): + for r in self._redirect_to: + if hasattr(r, 'isatty'): + return r.isatty() + return False + + def flush(self): + for r in self._redirect_to: + if hasattr(r, 'flush'): + r.flush() + + def __getattr__(self, name): + for r in self._redirect_to: + if hasattr(r, name): + return getattr(r, name) + raise AttributeError(name) + + +class IOBuf: + '''This class works as a replacement for stdio and stderr. + It is a buffer and when its contents are requested, it will erase what + it has so far so that the next return will not return the same contents again. + ''' + + def __init__(self): + self.buflist = [] + import os + self.encoding = os.environ.get('PYTHONIOENCODING', 'utf-8') + + def getvalue(self): + b = self.buflist + self.buflist = [] # clear it + return ''.join(b) # bytes on py2, str on py3. + + def write(self, s): + if not IS_PY3K: + if isinstance(s, unicode): + # can't use 'errors' as kwargs in py 2.6 + s = s.encode(self.encoding, 'replace') + else: + if isinstance(s, bytes): + s = s.decode(self.encoding, errors='replace') + self.buflist.append(s) + + def isatty(self): + return False + + def flush(self): + pass + + def empty(self): + return len(self.buflist) == 0 + + +class _RedirectionsHolder: + _stack_stdout = [] + _stack_stderr = [] + + +def start_redirect(keep_original_redirection=False, std='stdout'): + ''' + @param std: 'stdout', 'stderr', or 'both' + ''' + import sys + buf = IOBuf() + + if std == 'both': + config_stds = ['stdout', 'stderr'] + else: + config_stds = [std] + + for std in config_stds: + original = getattr(sys, std) + stack = getattr(_RedirectionsHolder, '_stack_%s' % std) + stack.append(original) + + if keep_original_redirection: + setattr(sys, std, IORedirector(getattr(sys, std), buf)) + else: + setattr(sys, std, buf) + return buf + + +def end_redirect(std='stdout'): + import sys + if std == 'both': + config_stds = ['stdout', 'stderr'] + else: + config_stds = [std] + for std in config_stds: + stack = getattr(_RedirectionsHolder, '_stack_%s' % std) + setattr(sys, std, stack.pop()) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_json_debug_options.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_json_debug_options.py new file mode 100644 index 0000000..308ee12 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_json_debug_options.py @@ -0,0 +1,122 @@ +import sys +import platform +try: + import urllib + urllib.unquote # noqa +except Exception: + import urllib.parse as urllib + + +def bool_parser(s): + return s in ("True", "true", "1") + + +if sys.version_info >= (3,): + + def unquote(s): + return None if s is None else urllib.unquote(s) + +else: + + # In Python 2, urllib.unquote doesn't handle Unicode strings correctly, + # so we need to convert to ASCII first, unquote, and then decode. + def unquote(s): + if s is None: + return None + if not isinstance(s, bytes): + s = bytes(s) + s = urllib.unquote(s) + if isinstance(s, bytes): + s = s.decode('utf-8') + return s + +DEBUG_OPTIONS_PARSER = { + 'WAIT_ON_ABNORMAL_EXIT': bool_parser, + 'WAIT_ON_NORMAL_EXIT': bool_parser, + 'BREAK_SYSTEMEXIT_ZERO': bool_parser, + 'REDIRECT_OUTPUT': bool_parser, + 'VERSION': unquote, + 'INTERPRETER_OPTIONS': unquote, + 'WEB_BROWSER_URL': unquote, + 'DJANGO_DEBUG': bool_parser, + 'FLASK_DEBUG': bool_parser, + 'FIX_FILE_PATH_CASE': bool_parser, + 'CLIENT_OS_TYPE': unquote, + 'DEBUG_STDLIB': bool_parser, + 'STOP_ON_ENTRY': bool_parser, + 'SHOW_RETURN_VALUE': bool_parser, + 'MULTIPROCESS': bool_parser, +} + +DEBUG_OPTIONS_BY_FLAG = { + 'RedirectOutput': 'REDIRECT_OUTPUT=True', + 'WaitOnNormalExit': 'WAIT_ON_NORMAL_EXIT=True', + 'WaitOnAbnormalExit': 'WAIT_ON_ABNORMAL_EXIT=True', + 'BreakOnSystemExitZero': 'BREAK_SYSTEMEXIT_ZERO=True', + 'Django': 'DJANGO_DEBUG=True', + 'Flask': 'FLASK_DEBUG=True', + 'Jinja': 'FLASK_DEBUG=True', + 'FixFilePathCase': 'FIX_FILE_PATH_CASE=True', + 'DebugStdLib': 'DEBUG_STDLIB=True', + 'WindowsClient': 'CLIENT_OS_TYPE=WINDOWS', + 'UnixClient': 'CLIENT_OS_TYPE=UNIX', + 'StopOnEntry': 'STOP_ON_ENTRY=True', + 'ShowReturnValue': 'SHOW_RETURN_VALUE=True', + 'Multiprocess': 'MULTIPROCESS=True', +} + + +def _build_debug_options(flags): + """Build string representation of debug options from the launch config.""" + return ';'.join(DEBUG_OPTIONS_BY_FLAG[flag] + for flag in flags or [] + if flag in DEBUG_OPTIONS_BY_FLAG) + + +def _parse_debug_options(opts): + """Debug options are semicolon separated key=value pairs + """ + options = {} + if not opts: + return options + + for opt in opts.split(';'): + try: + key, value = opt.split('=') + except ValueError: + continue + try: + options[key] = DEBUG_OPTIONS_PARSER[key](value) + except KeyError: + continue + + return options + + +def _extract_debug_options(opts, flags=None): + """Return the debug options encoded in the given value. + + "opts" is a semicolon-separated string of "key=value" pairs. + "flags" is a list of strings. + + If flags is provided then it is used as a fallback. + + The values come from the launch config: + + { + type:'python', + request:'launch'|'attach', + name:'friendly name for debug config', + debugOptions:[ + 'RedirectOutput', 'Django' + ], + options:'REDIRECT_OUTPUT=True;DJANGO_DEBUG=True' + } + + Further information can be found here: + + https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes + """ + if not opts: + opts = _build_debug_options(flags) + return _parse_debug_options(opts) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_kill_all_pydevd_threads.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_kill_all_pydevd_threads.py new file mode 100644 index 0000000..d9bb5e1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_kill_all_pydevd_threads.py @@ -0,0 +1,8 @@ +from _pydevd_bundle.pydevd_comm import PyDBDaemonThread +from _pydevd_bundle.pydevd_constants import dict_keys + +def kill_all_pydev_threads(): + threads = dict_keys(PyDBDaemonThread.created_pydb_daemon_threads) + for t in threads: + if hasattr(t, 'do_kill_pydev_thread'): + t.do_kill_pydev_thread() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py new file mode 100644 index 0000000..5f94726 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command.py @@ -0,0 +1,134 @@ +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import DebugInfoHolder, IS_PY2, \ + get_global_debugger, GetGlobalDebugger, set_global_debugger # Keep for backward compatibility @UnusedImport +from _pydevd_bundle.pydevd_utils import quote_smart as quote, to_string +from _pydevd_bundle.pydevd_comm_constants import ID_TO_MEANING, CMD_EXIT +from _pydevd_bundle.pydevd_constants import HTTP_PROTOCOL, HTTP_JSON_PROTOCOL, \ + get_protocol, IS_JYTHON +import json +from _pydev_bundle import pydev_log + + +class _NullNetCommand(object): + + id = -1 + + def send(self, *args, **kwargs): + pass + + +class _NullExitCommand(_NullNetCommand): + + id = CMD_EXIT + + +# Constant meant to be passed to the writer when the command is meant to be ignored. +NULL_NET_COMMAND = _NullNetCommand() + +# Exit command -- only internal (we don't want/need to send this to the IDE). +NULL_EXIT_COMMAND = _NullExitCommand() + + +class NetCommand: + """ + Commands received/sent over the network. + + Command can represent command received from the debugger, + or one to be sent by daemon. + """ + next_seq = 0 # sequence numbers + + _showing_debug_info = 0 + _show_debug_info_lock = threading.RLock() + + def __init__(self, cmd_id, seq, text, is_json=False): + """ + If sequence is 0, new sequence will be generated (otherwise, this was the response + to a command from the client). + """ + protocol = get_protocol() + self.id = cmd_id + if seq == 0: + NetCommand.next_seq += 2 + seq = NetCommand.next_seq + + self.seq = seq + + if is_json: + if hasattr(text, 'to_dict'): + as_dict = text.to_dict(update_ids_to_dap=True) + else: + assert isinstance(text, dict) + as_dict = text + as_dict['pydevd_cmd_id'] = cmd_id + as_dict['seq'] = seq + text = json.dumps(as_dict) + + if IS_PY2: + if isinstance(text, unicode): + text = text.encode('utf-8') + else: + assert isinstance(text, str) + else: + assert isinstance(text, str) + + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: + self._show_debug_info(cmd_id, seq, text) + + if is_json: + msg = text + else: + if protocol not in (HTTP_PROTOCOL, HTTP_JSON_PROTOCOL): + encoded = quote(to_string(text), '/<>_=" \t') + msg = '%s\t%s\t%s\n' % (cmd_id, seq, encoded) + + else: + msg = '%s\t%s\t%s' % (cmd_id, seq, text) + + if IS_PY2: + assert isinstance(msg, str) # i.e.: bytes + as_bytes = msg + else: + if isinstance(msg, str): + msg = msg.encode('utf-8') + + assert isinstance(msg, bytes) + as_bytes = msg + self._as_bytes = as_bytes + + def send(self, sock): + as_bytes = self._as_bytes + try: + if get_protocol() in (HTTP_PROTOCOL, HTTP_JSON_PROTOCOL): + sock.sendall(('Content-Length: %s\r\n\r\n' % len(as_bytes)).encode('ascii')) + sock.sendall(as_bytes) + except: + if IS_JYTHON: + # Ignore errors in sock.sendall in Jython (seems to be common for Jython to + # give spurious exceptions at interpreter shutdown here). + pass + else: + raise + + @classmethod + def _show_debug_info(cls, cmd_id, seq, text): + with cls._show_debug_info_lock: + # Only one thread each time (rlock). + if cls._showing_debug_info: + # avoid recursing in the same thread (just printing could create + # a new command when redirecting output). + return + + cls._showing_debug_info += 1 + try: + out_message = 'sending cmd --> ' + out_message += "%20s" % ID_TO_MEANING.get(str(cmd_id), 'UNKNOWN') + out_message += ' ' + out_message += text.replace('\n', ' ') + try: + pydev_log.critical('%s\n', out_message) + except: + pass + finally: + cls._showing_debug_info -= 1 + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py new file mode 100644 index 0000000..581a6f7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py @@ -0,0 +1,360 @@ +from functools import partial +import itertools +import os + +from _pydev_bundle._pydev_imports_tipper import TYPE_IMPORT, TYPE_CLASS, TYPE_FUNCTION, TYPE_ATTR, \ + TYPE_BUILTIN, TYPE_PARAM +from _pydev_bundle.pydev_is_thread_alive import is_thread_alive +from _pydev_bundle.pydev_override import overrides +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle._debug_adapter import pydevd_schema +from _pydevd_bundle._debug_adapter.pydevd_schema import ModuleEvent, ModuleEventBody, Module, \ + OutputEventBody, OutputEvent, ContinuedEventBody +from _pydevd_bundle.pydevd_comm_constants import CMD_THREAD_CREATE, CMD_RETURN, CMD_MODULE_EVENT, \ + CMD_WRITE_TO_CONSOLE, CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE, \ + CMD_STEP_RETURN, CMD_STEP_CAUGHT_EXCEPTION, CMD_ADD_EXCEPTION_BREAK, CMD_SET_BREAK, \ + CMD_SET_NEXT_STATEMENT, CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION, \ + CMD_THREAD_RESUME_SINGLE_NOTIFICATION, CMD_THREAD_KILL, CMD_STOP_ON_START +from _pydevd_bundle.pydevd_constants import get_thread_id, dict_values +from _pydevd_bundle.pydevd_net_command import NetCommand, NULL_NET_COMMAND +from _pydevd_bundle.pydevd_net_command_factory_xml import NetCommandFactory +from _pydevd_bundle.pydevd_utils import get_non_pydevd_threads +import pydevd_file_utils +from _pydevd_bundle.pydevd_comm import build_exception_info_response, pydevd_find_thread_by_id +from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info + + +class ModulesManager(object): + + def __init__(self): + self._lock = threading.Lock() + self._modules = {} + self._next_id = partial(next, itertools.count(0)) + + def track_module(self, filename_in_utf8, module_name, frame): + ''' + :return list(NetCommand): + Returns a list with the module events to be sent. + ''' + if filename_in_utf8 in self._modules: + return [] + + module_events = [] + with self._lock: + # Must check again after getting the lock. + if filename_in_utf8 in self._modules: + return + + version = frame.f_globals.get('__version__', '') + package_name = frame.f_globals.get('__package__', '') + module_id = self._next_id() + + module = Module(module_id, module_name, filename_in_utf8) + if version: + module.version = version + + if package_name: + # Note: package doesn't appear in the docs but seems to be expected? + module.kwargs['package'] = package_name + + module_event = ModuleEvent(ModuleEventBody('new', module)) + + module_events.append(NetCommand(CMD_MODULE_EVENT, 0, module_event, is_json=True)) + + self._modules[filename_in_utf8] = module.to_dict() + return module_events + + def get_modules_info(self): + ''' + :return list(Module) + ''' + with self._lock: + return dict_values(self._modules) + + +class NetCommandFactoryJson(NetCommandFactory): + ''' + Factory for commands which will provide messages as json (they should be + similar to the debug adapter where possible, although some differences + are currently Ok). + + Note that it currently overrides the xml version so that messages + can be done one at a time (any message not overridden will currently + use the xml version) -- after having all messages handled, it should + no longer use NetCommandFactory as the base class. + ''' + + def __init__(self): + NetCommandFactory.__init__(self) + self.modules_manager = ModulesManager() + + @overrides(NetCommandFactory.make_version_message) + def make_version_message(self, seq): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_protocol_set_message) + def make_protocol_set_message(self, seq): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_thread_created_message) + def make_thread_created_message(self, thread): + + # Note: the thread id for the debug adapter must be an int + # (make the actual id from get_thread_id respect that later on). + msg = pydevd_schema.ThreadEvent( + pydevd_schema.ThreadEventBody('started', get_thread_id(thread)), + ) + + return NetCommand(CMD_THREAD_CREATE, 0, msg, is_json=True) + + @overrides(NetCommandFactory.make_thread_killed_message) + def make_thread_killed_message(self, tid): + msg = pydevd_schema.ThreadEvent( + pydevd_schema.ThreadEventBody('exited', tid), + ) + + return NetCommand(CMD_THREAD_KILL, 0, msg, is_json=True) + + @overrides(NetCommandFactory.make_list_threads_message) + def make_list_threads_message(self, py_db, seq): + threads = [] + for thread in get_non_pydevd_threads(): + if is_thread_alive(thread): + thread_id = get_thread_id(thread) + + # Notify that it's created (no-op if we already notified before). + py_db.notify_thread_created(thread_id, thread) + + thread_schema = pydevd_schema.Thread(id=thread_id, name=thread.getName()) + threads.append(thread_schema.to_dict()) + + body = pydevd_schema.ThreadsResponseBody(threads) + response = pydevd_schema.ThreadsResponse( + request_seq=seq, success=True, command='threads', body=body) + + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + @overrides(NetCommandFactory.make_get_completions_message) + def make_get_completions_message(self, seq, completions, qualifier, start): + COMPLETION_TYPE_LOOK_UP = { + TYPE_IMPORT: pydevd_schema.CompletionItemType.MODULE, + TYPE_CLASS: pydevd_schema.CompletionItemType.CLASS, + TYPE_FUNCTION: pydevd_schema.CompletionItemType.FUNCTION, + TYPE_ATTR: pydevd_schema.CompletionItemType.FIELD, + TYPE_BUILTIN: pydevd_schema.CompletionItemType.KEYWORD, + TYPE_PARAM: pydevd_schema.CompletionItemType.VARIABLE, + } + + qualifier = qualifier.lower() + qualifier_len = len(qualifier) + targets = [] + for completion in completions: + label = completion[0] + if label.lower().startswith(qualifier): + completion = pydevd_schema.CompletionItem( + label=label, type=COMPLETION_TYPE_LOOK_UP[completion[3]], start=start, length=qualifier_len) + targets.append(completion.to_dict()) + + body = pydevd_schema.CompletionsResponseBody(targets) + response = pydevd_schema.CompletionsResponse( + request_seq=seq, success=True, command='completions', body=body) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def _format_frame_name(self, fmt, initial_name, module_name, line, path): + if fmt is None: + return initial_name + frame_name = initial_name + if fmt.get('module', False): + if module_name: + if initial_name == '': + frame_name = module_name + else: + frame_name = '%s.%s' % (module_name, initial_name) + else: + basename = os.path.basename(path) + basename = basename[0:-3] if basename.lower().endswith('.py') else basename + if initial_name == '': + frame_name = '%s in %s' % (initial_name, basename) + else: + frame_name = '%s.%s' % (basename, initial_name) + + if fmt.get('line', False): + frame_name = '%s : %d' % (frame_name, line) + + return frame_name + + @overrides(NetCommandFactory.make_get_thread_stack_message) + def make_get_thread_stack_message(self, py_db, seq, thread_id, topmost_frame, fmt, must_be_suspended=False, start_frame=0, levels=0): + frames = [] + module_events = [] + if topmost_frame is not None: + frame_id_to_lineno = {} + try: + # : :type suspended_frames_manager: SuspendedFramesManager + suspended_frames_manager = py_db.suspended_frames_manager + info = suspended_frames_manager.get_topmost_frame_and_frame_id_to_line(thread_id) + if info is None: + # Could not find stack of suspended frame... + if must_be_suspended: + return None + else: + # Note: we have to use the topmost frame where it was suspended (it may + # be different if it was an exception). + topmost_frame, frame_id_to_lineno = info + + for frame_id, frame, method_name, original_filename, filename_in_utf8, lineno in self._iter_visible_frames_info( + py_db, topmost_frame, frame_id_to_lineno + ): + + module_name = frame.f_globals.get('__name__', '') + + module_events.extend(self.modules_manager.track_module(filename_in_utf8, module_name, frame)) + + presentation_hint = None + if not getattr(frame, 'IS_PLUGIN_FRAME', False): # Never filter out plugin frames! + if py_db.is_files_filter_enabled and py_db.apply_files_filter(frame, original_filename, False): + continue + + if not py_db.in_project_scope(frame): + presentation_hint = 'subtle' + + formatted_name = self._format_frame_name(fmt, method_name, module_name, lineno, filename_in_utf8) + frames.append(pydevd_schema.StackFrame( + frame_id, formatted_name, lineno, column=1, source={ + 'path': filename_in_utf8, + 'sourceReference': pydevd_file_utils.get_client_filename_source_reference(filename_in_utf8), + }, + presentationHint=presentation_hint).to_dict()) + finally: + topmost_frame = None + + for module_event in module_events: + py_db.writer.add_command(module_event) + + total_frames = len(frames) + stack_frames = frames + if bool(levels): + start = start_frame + end = min(start + levels, total_frames) + stack_frames = frames[start:end] + + response = pydevd_schema.StackTraceResponse( + request_seq=seq, + success=True, + command='stackTrace', + body=pydevd_schema.StackTraceResponseBody(stackFrames=stack_frames, totalFrames=total_frames)) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + @overrides(NetCommandFactory.make_io_message) + def make_io_message(self, v, ctx): + category = 'stdout' if int(ctx) == 1 else 'stderr' + body = OutputEventBody(v, category) + event = OutputEvent(body) + return NetCommand(CMD_WRITE_TO_CONSOLE, 0, event, is_json=True) + + _STEP_REASONS = set([ + CMD_STEP_INTO, + CMD_STEP_INTO_MY_CODE, + CMD_STEP_OVER, + CMD_STEP_OVER_MY_CODE, + CMD_STEP_RETURN, + CMD_STEP_INTO_MY_CODE, + ]) + _EXCEPTION_REASONS = set([ + CMD_STEP_CAUGHT_EXCEPTION, + CMD_ADD_EXCEPTION_BREAK, + ]) + + @overrides(NetCommandFactory.make_thread_suspend_single_notification) + def make_thread_suspend_single_notification(self, py_db, thread_id, stop_reason): + exc_desc = None + exc_name = None + thread = pydevd_find_thread_by_id(thread_id) + info = set_additional_thread_info(thread) + + if stop_reason in self._STEP_REASONS: + if info.pydev_original_step_cmd == CMD_STOP_ON_START: + + # Just to make sure that's not set as the original reason anymore. + info.pydev_original_step_cmd = -1 + stop_reason = 'entry' + else: + stop_reason = 'step' + elif stop_reason in self._EXCEPTION_REASONS: + stop_reason = 'exception' + elif stop_reason == CMD_SET_BREAK: + stop_reason = 'breakpoint' + elif stop_reason == CMD_SET_NEXT_STATEMENT: + stop_reason = 'goto' + else: + stop_reason = 'pause' + + if stop_reason == 'exception': + exception_info_response = build_exception_info_response( + py_db, thread_id, -1, set_additional_thread_info, self._iter_visible_frames_info, max_frames=-1) + exception_info_response + + exc_name = exception_info_response.body.exceptionId + exc_desc = exception_info_response.body.description + + body = pydevd_schema.StoppedEventBody( + reason=stop_reason, + description=exc_desc, + threadId=thread_id, + text=exc_name, + allThreadsStopped=True, + preserveFocusHint=stop_reason not in ['step', 'exception', 'breakpoint', 'entry', 'goto'], + ) + event = pydevd_schema.StoppedEvent(body) + return NetCommand(CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION, 0, event, is_json=True) + + @overrides(NetCommandFactory.make_thread_resume_single_notification) + def make_thread_resume_single_notification(self, thread_id): + body = ContinuedEventBody(threadId=thread_id, allThreadsContinued=True) + event = pydevd_schema.ContinuedEvent(body) + return NetCommand(CMD_THREAD_RESUME_SINGLE_NOTIFICATION, 0, event, is_json=True) + + @overrides(NetCommandFactory.make_set_next_stmnt_status_message) + def make_set_next_stmnt_status_message(self, seq, is_success, exception_msg): + response = pydevd_schema.GotoResponse( + request_seq=int(seq), + success=is_success, + command='goto', + body={}, + message=(None if is_success else exception_msg)) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + @overrides(NetCommandFactory.make_send_curr_exception_trace_message) + def make_send_curr_exception_trace_message(self, *args, **kwargs): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_send_curr_exception_trace_proceeded_message) + def make_send_curr_exception_trace_proceeded_message(self, *args, **kwargs): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_send_breakpoint_exception_message) + def make_send_breakpoint_exception_message(self, *args, **kwargs): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_process_created_message) + def make_process_created_message(self, *args, **kwargs): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_thread_suspend_message) + def make_thread_suspend_message(self, *args, **kwargs): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_thread_run_message) + def make_thread_run_message(self, *args, **kwargs): + return NULL_NET_COMMAND # Not a part of the debug adapter protocol + + @overrides(NetCommandFactory.make_skipped_step_in_because_of_filters) + def make_skipped_step_in_because_of_filters(self, py_db, frame): + msg = 'Frame skipped from debugging during step-in.' + if py_db.get_use_libraries_filter(): + msg += '\nNote: may have been skipped because of "justMyCode" option (default == true).' + + body = OutputEventBody(msg, category='console') + event = OutputEvent(body) + return NetCommand(CMD_WRITE_TO_CONSOLE, 0, event, is_json=True) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_xml.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_xml.py new file mode 100644 index 0000000..e66eb8a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_xml.py @@ -0,0 +1,461 @@ +import json +import sys + +from _pydev_bundle.pydev_is_thread_alive import is_thread_alive +from _pydev_imps._pydev_saved_modules import thread +from _pydevd_bundle import pydevd_xml +from _pydevd_bundle.pydevd_comm_constants import ( + CMD_THREAD_CREATE, CMD_THREAD_KILL, CMD_THREAD_SUSPEND, CMD_THREAD_RUN, CMD_GET_VARIABLE, + CMD_EVALUATE_EXPRESSION, CMD_GET_FRAME, CMD_WRITE_TO_CONSOLE, CMD_GET_COMPLETIONS, + CMD_LOAD_SOURCE, CMD_SET_NEXT_STATEMENT, CMD_EXIT, CMD_GET_FILE_CONTENTS, + CMD_EVALUATE_CONSOLE_EXPRESSION, CMD_RUN_CUSTOM_OPERATION, + CMD_GET_BREAKPOINT_EXCEPTION, CMD_SEND_CURR_EXCEPTION_TRACE, + CMD_SEND_CURR_EXCEPTION_TRACE_PROCEEDED, CMD_SHOW_CONSOLE, CMD_GET_ARRAY, + CMD_INPUT_REQUESTED, CMD_GET_DESCRIPTION, CMD_PROCESS_CREATED, + CMD_SHOW_CYTHON_WARNING, CMD_LOAD_FULL_VALUE, CMD_GET_THREAD_STACK, + CMD_GET_EXCEPTION_DETAILS, CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION, + CMD_THREAD_RESUME_SINGLE_NOTIFICATION, + CMD_GET_NEXT_STATEMENT_TARGETS, CMD_VERSION, + CMD_RETURN, CMD_SET_PROTOCOL, CMD_ERROR, MAX_IO_MSG_SIZE, VERSION_STRING, + CMD_RELOAD_CODE) +from _pydevd_bundle.pydevd_constants import (DebugInfoHolder, get_thread_id, IS_IRONPYTHON, + get_global_debugger, GetGlobalDebugger, set_global_debugger) # Keep for backward compatibility @UnusedImport +from _pydevd_bundle.pydevd_net_command import NetCommand, NULL_NET_COMMAND, NULL_EXIT_COMMAND +from _pydevd_bundle.pydevd_utils import quote_smart as quote, get_non_pydevd_threads +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame +import pydevd_file_utils +from pydevd_tracing import get_exception_traceback_str +from _pydev_bundle._pydev_completer import completions_to_xml +from _pydev_bundle import pydev_log + +if IS_IRONPYTHON: + + # redefine `unquote` for IronPython, since we use it only for logging messages, but it leads to SOF with IronPython + def unquote(s): + return s + + +#======================================================================================================================= +# NetCommandFactory +#======================================================================================================================= +class NetCommandFactory(object): + + def _thread_to_xml(self, thread): + """ thread information as XML """ + name = pydevd_xml.make_valid_xml_value(thread.getName()) + cmdText = '' % (quote(name), get_thread_id(thread)) + return cmdText + + def make_error_message(self, seq, text): + cmd = NetCommand(CMD_ERROR, seq, text) + if DebugInfoHolder.DEBUG_TRACE_LEVEL > 2: + sys.stderr.write("Error: %s" % (text,)) + return cmd + + def make_protocol_set_message(self, seq): + return NetCommand(CMD_SET_PROTOCOL, seq, '') + + def make_thread_created_message(self, thread): + cmdText = "" + self._thread_to_xml(thread) + "" + return NetCommand(CMD_THREAD_CREATE, 0, cmdText) + + def make_process_created_message(self): + cmdText = '' + return NetCommand(CMD_PROCESS_CREATED, 0, cmdText) + + def make_show_cython_warning_message(self): + try: + return NetCommand(CMD_SHOW_CYTHON_WARNING, 0, '') + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_custom_frame_created_message(self, frame_id, frame_description): + frame_description = pydevd_xml.make_valid_xml_value(frame_description) + return NetCommand(CMD_THREAD_CREATE, 0, '' % (frame_description, frame_id)) + + def make_list_threads_message(self, py_db, seq): + """ returns thread listing as XML """ + try: + threads = get_non_pydevd_threads() + cmd_text = [""] + append = cmd_text.append + for thread in threads: + if is_thread_alive(thread): + append(self._thread_to_xml(thread)) + append("") + return NetCommand(CMD_RETURN, seq, ''.join(cmd_text)) + except: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_thread_stack_message(self, py_db, seq, thread_id, topmost_frame, fmt, must_be_suspended=False, start_frame=0, levels=0): + """ + Returns thread stack as XML. + + :param must_be_suspended: If True and the thread is not suspended, returns None. + """ + try: + # If frame is None, the return is an empty frame list. + cmd_text = ['' % (thread_id,)] + + if topmost_frame is not None: + frame_id_to_lineno = {} + try: + # : :type suspended_frames_manager: SuspendedFramesManager + suspended_frames_manager = py_db.suspended_frames_manager + info = suspended_frames_manager.get_topmost_frame_and_frame_id_to_line(thread_id) + if info is None: + # Could not find stack of suspended frame... + if must_be_suspended: + return None + else: + # Note: we have to use the topmost frame where it was suspended (it may + # be different if it was an exception). + topmost_frame, frame_id_to_lineno = info + + cmd_text.append(self.make_thread_stack_str(py_db, topmost_frame, frame_id_to_lineno)) + finally: + topmost_frame = None + cmd_text.append('') + return NetCommand(CMD_GET_THREAD_STACK, seq, ''.join(cmd_text)) + except: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_variable_changed_message(self, seq, payload): + # notify debugger that value was changed successfully + return NetCommand(CMD_RETURN, seq, payload) + + def make_io_message(self, v, ctx): + ''' + @param v: the message to pass to the debug server + @param ctx: 1 for stdio 2 for stderr + ''' + + try: + if len(v) > MAX_IO_MSG_SIZE: + v = v[0:MAX_IO_MSG_SIZE] + v += '...' + + v = pydevd_xml.make_valid_xml_value(quote(v, '/>_= ')) + return NetCommand(str(CMD_WRITE_TO_CONSOLE), 0, '' % (v, ctx)) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_version_message(self, seq): + try: + return NetCommand(CMD_VERSION, seq, VERSION_STRING) + except: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_thread_killed_message(self, tid): + try: + return NetCommand(CMD_THREAD_KILL, 0, str(tid)) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def _iter_visible_frames_info(self, py_db, frame, frame_id_to_lineno): + while frame is not None: + if frame.f_code is None: + continue # IronPython sometimes does not have it! + + method_name = frame.f_code.co_name # method name (if in method) or ? if global + if method_name is None: + continue # IronPython sometimes does not have it! + + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + if py_db.get_file_type(frame, abs_path_real_path_and_base) == py_db.PYDEV_FILE: + # Skip pydevd files. + frame = frame.f_back + continue + + frame_id = id(frame) + lineno = frame_id_to_lineno.get(frame_id, frame.f_lineno) + + filename_in_utf8, lineno, changed = py_db.source_mapping.map_to_client(abs_path_real_path_and_base[0], lineno) + filename_in_utf8 = pydevd_file_utils.norm_file_to_client(filename_in_utf8) + + yield frame_id, frame, method_name, abs_path_real_path_and_base[0], filename_in_utf8, lineno + + frame = frame.f_back + + def make_thread_stack_str(self, py_db, frame, frame_id_to_lineno=None): + ''' + :param frame_id_to_lineno: + If available, the line number for the frame will be gotten from this dict, + otherwise frame.f_lineno will be used (needed for unhandled exceptions as + the place where we report may be different from the place where it's raised). + ''' + if frame_id_to_lineno is None: + frame_id_to_lineno = {} + make_valid_xml_value = pydevd_xml.make_valid_xml_value + cmd_text_list = [] + append = cmd_text_list.append + + curr_frame = frame + frame = None # Clear frame reference + try: + for frame_id, frame, method_name, _original_filename, filename_in_utf8, lineno in self._iter_visible_frames_info( + py_db, curr_frame, frame_id_to_lineno + ): + + # print("file is ", filename_in_utf8) + # print("line is ", lineno) + + # Note: variables are all gotten 'on-demand'. + append('' % (quote(make_valid_xml_value(filename_in_utf8), '/>_= \t'), lineno)) + append("") + except: + pydev_log.exception() + + curr_frame = None # Clear frame reference + return ''.join(cmd_text_list) + + def make_thread_suspend_str( + self, + py_db, + thread_id, + frame, + stop_reason=None, + message=None, + suspend_type="trace", + frame_id_to_lineno=None + ): + """ + :return tuple(str,str): + Returns tuple(thread_suspended_str, thread_stack_str). + + i.e.: + ( + ''' + + + + + + + ''' + , + ''' + + + ''' + ) + """ + make_valid_xml_value = pydevd_xml.make_valid_xml_value + cmd_text_list = [] + append = cmd_text_list.append + + cmd_text_list.append('') + if message: + message = make_valid_xml_value(message) + + append('') + thread_stack_str = self.make_thread_stack_str(py_db, frame, frame_id_to_lineno) + append(thread_stack_str) + append("") + + return ''.join(cmd_text_list), thread_stack_str + + def make_thread_suspend_message(self, py_db, thread_id, frame, stop_reason, message, suspend_type, frame_id_to_lineno=None): + try: + thread_suspend_str, thread_stack_str = self.make_thread_suspend_str( + py_db, thread_id, frame, stop_reason, message, suspend_type, frame_id_to_lineno=frame_id_to_lineno) + cmd = NetCommand(CMD_THREAD_SUSPEND, 0, thread_suspend_str) + cmd.thread_stack_str = thread_stack_str + cmd.thread_suspend_str = thread_suspend_str + return cmd + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_thread_suspend_single_notification(self, py_db, thread_id, stop_reason): + try: + return NetCommand(CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION, 0, json.dumps( + {'thread_id': thread_id, 'stop_reason':stop_reason})) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_thread_resume_single_notification(self, thread_id): + try: + return NetCommand(CMD_THREAD_RESUME_SINGLE_NOTIFICATION, 0, json.dumps( + {'thread_id': thread_id})) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_thread_run_message(self, thread_id, reason): + try: + return NetCommand(CMD_THREAD_RUN, 0, "%s\t%s" % (thread_id, reason)) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_get_variable_message(self, seq, payload): + try: + return NetCommand(CMD_GET_VARIABLE, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_array_message(self, seq, payload): + try: + return NetCommand(CMD_GET_ARRAY, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_description_message(self, seq, payload): + try: + return NetCommand(CMD_GET_DESCRIPTION, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_frame_message(self, seq, payload): + try: + return NetCommand(CMD_GET_FRAME, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_evaluate_expression_message(self, seq, payload): + try: + return NetCommand(CMD_EVALUATE_EXPRESSION, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_completions_message(self, seq, completions, qualifier, start): + try: + payload = completions_to_xml(completions) + return NetCommand(CMD_GET_COMPLETIONS, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_file_contents(self, seq, payload): + try: + return NetCommand(CMD_GET_FILE_CONTENTS, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_reloaded_code_message(self, seq, reloaded_ok): + try: + return NetCommand(CMD_RELOAD_CODE, seq, '' % reloaded_ok) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_send_breakpoint_exception_message(self, seq, payload): + try: + return NetCommand(CMD_GET_BREAKPOINT_EXCEPTION, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def _make_send_curr_exception_trace_str(self, py_db, thread_id, exc_type, exc_desc, trace_obj): + while trace_obj.tb_next is not None: + trace_obj = trace_obj.tb_next + + exc_type = pydevd_xml.make_valid_xml_value(str(exc_type)).replace('\t', ' ') or 'exception: type unknown' + exc_desc = pydevd_xml.make_valid_xml_value(str(exc_desc)).replace('\t', ' ') or 'exception: no description' + + thread_suspend_str, thread_stack_str = self.make_thread_suspend_str( + py_db, thread_id, trace_obj.tb_frame, CMD_SEND_CURR_EXCEPTION_TRACE, '') + return exc_type, exc_desc, thread_suspend_str, thread_stack_str + + def make_send_curr_exception_trace_message(self, py_db, seq, thread_id, curr_frame_id, exc_type, exc_desc, trace_obj): + try: + exc_type, exc_desc, thread_suspend_str, _thread_stack_str = self._make_send_curr_exception_trace_str( + py_db, thread_id, exc_type, exc_desc, trace_obj) + payload = str(curr_frame_id) + '\t' + exc_type + "\t" + exc_desc + "\t" + thread_suspend_str + return NetCommand(CMD_SEND_CURR_EXCEPTION_TRACE, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_get_exception_details_message(self, py_db, seq, thread_id, topmost_frame): + """Returns exception details as XML """ + try: + # If the debugger is not suspended, just return the thread and its id. + cmd_text = ['') + cmd_text.append(thread_stack_str) + break + frame = frame.f_back + else: + cmd_text.append('>') + finally: + frame = None + cmd_text.append('') + return NetCommand(CMD_GET_EXCEPTION_DETAILS, seq, ''.join(cmd_text)) + except: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_send_curr_exception_trace_proceeded_message(self, seq, thread_id): + try: + return NetCommand(CMD_SEND_CURR_EXCEPTION_TRACE_PROCEEDED, 0, str(thread_id)) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_send_console_message(self, seq, payload): + try: + return NetCommand(CMD_EVALUATE_CONSOLE_EXPRESSION, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_custom_operation_message(self, seq, payload): + try: + return NetCommand(CMD_RUN_CUSTOM_OPERATION, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_load_source_message(self, seq, source): + return NetCommand(CMD_LOAD_SOURCE, seq, '%s' % source) + + def make_show_console_message(self, py_db, thread_id, frame): + try: + thread_suspended_str, _thread_stack_str = self.make_thread_suspend_str( + py_db, thread_id, frame, CMD_SHOW_CONSOLE, '') + return NetCommand(CMD_SHOW_CONSOLE, 0, thread_suspended_str) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_input_requested_message(self, started): + try: + return NetCommand(CMD_INPUT_REQUESTED, 0, str(started)) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_set_next_stmnt_status_message(self, seq, is_success, exception_msg): + try: + message = str(is_success) + '\t' + exception_msg + return NetCommand(CMD_SET_NEXT_STATEMENT, int(seq), message) + except: + return self.make_error_message(0, get_exception_traceback_str()) + + def make_load_full_value_message(self, seq, payload): + try: + return NetCommand(CMD_LOAD_FULL_VALUE, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_exit_message(self): + return NULL_EXIT_COMMAND + + def make_get_next_statement_targets_message(self, seq, payload): + try: + return NetCommand(CMD_GET_NEXT_STATEMENT_TARGETS, seq, payload) + except Exception: + return self.make_error_message(seq, get_exception_traceback_str()) + + def make_skipped_step_in_because_of_filters(self, py_db, frame): + return NULL_NET_COMMAND # Not a part of the xml protocol diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_plugin_utils.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_plugin_utils.py new file mode 100644 index 0000000..0cd0d76 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_plugin_utils.py @@ -0,0 +1,91 @@ +import types + +from _pydev_bundle import pydev_log +from _pydevd_bundle import pydevd_trace_api + +try: + from pydevd_plugins import django_debug +except: + django_debug = None + pydev_log.debug('Unable to load django_debug plugin') + +try: + from pydevd_plugins import jinja2_debug +except: + jinja2_debug = None + pydev_log.debug('Unable to load jinja2_debug plugin') + +def load_plugins(): + plugins = [] + if django_debug is not None: + plugins.append(django_debug) + + if jinja2_debug is not None: + plugins.append(jinja2_debug) + return plugins + + +def bind_func_to_method(func, obj, method_name): + bound_method = types.MethodType(func, obj) + + setattr(obj, method_name, bound_method) + return bound_method + + +class PluginManager(object): + + def __init__(self, main_debugger): + self.plugins = load_plugins() + self.active_plugins = [] + self.main_debugger = main_debugger + self.rebind_methods() + + def add_breakpoint(self, func_name, *args, **kwargs): + # add breakpoint for plugin and remember which plugin to use in tracing + for plugin in self.plugins: + if hasattr(plugin, func_name): + func = getattr(plugin, func_name) + result = func(self, *args, **kwargs) + if result: + self.activate(plugin) + + return result + return None + + def activate(self, plugin): + if plugin not in self.active_plugins: + self.active_plugins.append(plugin) + self.rebind_methods() + + def rebind_methods(self): + if len(self.active_plugins) == 0: + self.bind_functions(pydevd_trace_api, getattr, pydevd_trace_api) + elif len(self.active_plugins) == 1: + self.bind_functions(pydevd_trace_api, getattr, self.active_plugins[0]) + else: + self.bind_functions(pydevd_trace_api, create_dispatch, self.active_plugins) + + def bind_functions(self, interface, function_factory, arg): + for name in dir(interface): + func = function_factory(arg, name) + if type(func) == types.FunctionType: + bind_func_to_method(func, self, name) + + +def create_dispatch(obj, name): + def dispatch(self, *args, **kwargs): + result = None + for p in self.active_plugins: + r = getattr(p, name)(self, *args, **kwargs) + if not result: + result = r + return result + return dispatch + + + + + + + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command.py new file mode 100644 index 0000000..a34907c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command.py @@ -0,0 +1,619 @@ +import json +import os +import sys +import traceback + +from _pydev_bundle import pydev_log +from _pydev_bundle.pydev_log import exception as pydev_log_exception +from _pydevd_bundle import pydevd_traceproperty, pydevd_dont_trace, pydevd_utils +from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info +from _pydevd_bundle.pydevd_breakpoints import get_exception_class +from _pydevd_bundle.pydevd_comm import (pydevd_find_thread_by_id, + InternalEvaluateConsoleExpression, InternalConsoleGetCompletions, InternalRunCustomOperation, + internal_get_next_statement_targets) +from _pydevd_bundle.pydevd_constants import IS_PY3K, NEXT_VALUE_SEPARATOR, IS_WINDOWS +from _pydevd_bundle.pydevd_comm_constants import ID_TO_MEANING, CMD_EXEC_EXPRESSION +from _pydevd_bundle.pydevd_api import PyDevdAPI +from _pydev_bundle.pydev_imports import StringIO + + +class _PyDevCommandProcessor(object): + + def __init__(self): + self.api = PyDevdAPI() + + def process_net_command(self, py_db, cmd_id, seq, text): + '''Processes a command received from the Java side + + @param cmd_id: the id of the command + @param seq: the sequence of the command + @param text: the text received in the command + ''' + meaning = ID_TO_MEANING[str(cmd_id)] + + # print('Handling %s (%s)' % (meaning, text)) + + method_name = meaning.lower() + + on_command = getattr(self, method_name.lower(), None) + if on_command is None: + # I have no idea what this is all about + cmd = py_db.cmd_factory.make_error_message(seq, "unexpected command " + str(cmd_id)) + py_db.writer.add_command(cmd) + return + + py_db._main_lock.acquire() + try: + cmd = on_command(py_db, cmd_id, seq, text) + if cmd is not None: + py_db.writer.add_command(cmd) + except: + if traceback is not None and sys is not None and pydev_log_exception is not None: + pydev_log_exception() + + stream = StringIO() + traceback.print_exc(file=stream) + cmd = py_db.cmd_factory.make_error_message( + seq, + "Unexpected exception in process_net_command.\nInitial params: %s. Exception: %s" % ( + ((cmd_id, seq, text), stream.getvalue()) + ) + ) + if cmd is not None: + py_db.writer.add_command(cmd) + + finally: + py_db._main_lock.release() + + def cmd_run(self, py_db, cmd_id, seq, text): + return self.api.run(py_db) + + def cmd_list_threads(self, py_db, cmd_id, seq, text): + return self.api.list_threads(py_db, seq) + + def cmd_get_completions(self, py_db, cmd_id, seq, text): + # we received some command to get a variable + # the text is: thread_id\tframe_id\tactivation token + thread_id, frame_id, _scope, act_tok = text.split('\t', 3) + + return self.api.request_completions(py_db, seq, thread_id, frame_id, act_tok) + + def cmd_get_thread_stack(self, py_db, cmd_id, seq, text): + # Receives a thread_id and a given timeout, which is the time we should + # wait to the provide the stack if a given thread is still not suspended. + if '\t' in text: + thread_id, timeout = text.split('\t') + timeout = float(timeout) + else: + thread_id = text + timeout = .5 # Default timeout is .5 seconds + + return self.api.request_stack(py_db, seq, thread_id, fmt={}, timeout=timeout) + + def cmd_set_protocol(self, py_db, cmd_id, seq, text): + return self.api.set_protocol(py_db, seq, text.strip()) + + def cmd_thread_suspend(self, py_db, cmd_id, seq, text): + return self.api.request_suspend_thread(py_db, text.strip()) + + def cmd_version(self, py_db, cmd_id, seq, text): + # Default based on server process (although ideally the IDE should + # provide it). + if IS_WINDOWS: + ide_os = 'WINDOWS' + else: + ide_os = 'UNIX' + + # Breakpoints can be grouped by 'LINE' or by 'ID'. + breakpoints_by = 'LINE' + + splitted = text.split('\t') + if len(splitted) == 1: + _local_version = splitted + + elif len(splitted) == 2: + _local_version, ide_os = splitted + + elif len(splitted) == 3: + _local_version, ide_os, breakpoints_by = splitted + + version_msg = self.api.set_ide_os_and_breakpoints_by(py_db, seq, ide_os, breakpoints_by) + + # Enable thread notifications after the version command is completed. + self.api.set_enable_thread_notifications(py_db, True) + + return version_msg + + def cmd_thread_run(self, py_db, cmd_id, seq, text): + return self.api.request_resume_thread(text.strip()) + + def _cmd_step(self, py_db, cmd_id, seq, text): + return self.api.request_step(py_db, text.strip(), cmd_id) + + cmd_step_into = _cmd_step + cmd_step_into_my_code = _cmd_step + cmd_step_over = _cmd_step + cmd_step_over_my_code = _cmd_step + cmd_step_return = _cmd_step + cmd_step_return_my_code = _cmd_step + + def _cmd_set_next(self, py_db, cmd_id, seq, text): + thread_id, line, func_name = text.split('\t', 2) + return self.api.request_set_next(py_db, seq, thread_id, cmd_id, line, func_name) + + cmd_run_to_line = _cmd_set_next + cmd_set_next_statement = _cmd_set_next + cmd_smart_step_into = _cmd_set_next + + def cmd_reload_code(self, py_db, cmd_id, seq, text): + module_name = text.strip() + self.api.request_reload_code(py_db, seq, module_name) + + def cmd_change_variable(self, py_db, cmd_id, seq, text): + # the text is: thread\tstackframe\tFRAME|GLOBAL\tattribute_to_change\tvalue_to_change + thread_id, frame_id, scope, attr_and_value = text.split('\t', 3) + + tab_index = attr_and_value.rindex('\t') + attr = attr_and_value[0:tab_index].replace('\t', '.') + value = attr_and_value[tab_index + 1:] + self.api.request_change_variable(py_db, seq, thread_id, frame_id, scope, attr, value) + + def cmd_get_variable(self, py_db, cmd_id, seq, text): + # we received some command to get a variable + # the text is: thread_id\tframe_id\tFRAME|GLOBAL\tattributes* + thread_id, frame_id, scopeattrs = text.split('\t', 2) + + if scopeattrs.find('\t') != -1: # there are attributes beyond scope + scope, attrs = scopeattrs.split('\t', 1) + else: + scope, attrs = (scopeattrs, None) + + self.api.request_get_variable(py_db, seq, thread_id, frame_id, scope, attrs) + + def cmd_get_array(self, py_db, cmd_id, seq, text): + # Note: untested and unused in pydev + # we received some command to get an array variable + # the text is: thread_id\tframe_id\tFRAME|GLOBAL\tname\ttemp\troffs\tcoffs\trows\tcols\tformat + roffset, coffset, rows, cols, format, thread_id, frame_id, scopeattrs = text.split('\t', 7) + + if scopeattrs.find('\t') != -1: # there are attributes beyond scope + scope, attrs = scopeattrs.split('\t', 1) + else: + scope, attrs = (scopeattrs, None) + + self.api.request_get_array(py_db, seq, roffset, coffset, rows, cols, format, thread_id, frame_id, scope, attrs) + + def cmd_show_return_values(self, py_db, cmd_id, seq, text): + show_return_values = text.split('\t')[1] + self.api.set_show_return_values(py_db, int(show_return_values) == 1) + + def cmd_load_full_value(self, py_db, cmd_id, seq, text): + # Note: untested and unused in pydev + thread_id, frame_id, scopeattrs = text.split('\t', 2) + vars = scopeattrs.split(NEXT_VALUE_SEPARATOR) + + self.api.request_load_full_value(py_db, seq, thread_id, frame_id, vars) + + def cmd_get_description(self, py_db, cmd_id, seq, text): + # Note: untested and unused in pydev + thread_id, frame_id, expression = text.split('\t', 2) + self.api.request_get_description(py_db, seq, thread_id, frame_id, expression) + + def cmd_get_frame(self, py_db, cmd_id, seq, text): + thread_id, frame_id, scope = text.split('\t', 2) + self.api.request_get_frame(py_db, seq, thread_id, frame_id) + + def cmd_set_break(self, py_db, cmd_id, seq, text): + # func name: 'None': match anything. Empty: match global, specified: only method context. + # command to add some breakpoint. + # text is filename\tline. Add to breakpoints dictionary + suspend_policy = u"NONE" # Can be 'NONE' or 'ALL' + is_logpoint = False + hit_condition = None + if py_db._set_breakpoints_with_id: + try: + try: + breakpoint_id, btype, filename, line, func_name, condition, expression, hit_condition, is_logpoint, suspend_policy = text.split(u'\t', 9) + except ValueError: # not enough values to unpack + # No suspend_policy passed (use default). + breakpoint_id, btype, filename, line, func_name, condition, expression, hit_condition, is_logpoint = text.split(u'\t', 8) + is_logpoint = is_logpoint == u'True' + except ValueError: # not enough values to unpack + breakpoint_id, btype, filename, line, func_name, condition, expression = text.split(u'\t', 6) + + breakpoint_id = int(breakpoint_id) + line = int(line) + + # We must restore new lines and tabs as done in + # AbstractDebugTarget.breakpointAdded + condition = condition.replace(u"@_@NEW_LINE_CHAR@_@", u'\n').\ + replace(u"@_@TAB_CHAR@_@", u'\t').strip() + + expression = expression.replace(u"@_@NEW_LINE_CHAR@_@", u'\n').\ + replace(u"@_@TAB_CHAR@_@", u'\t').strip() + else: + # Note: this else should be removed after PyCharm migrates to setting + # breakpoints by id (and ideally also provides func_name). + btype, filename, line, func_name, suspend_policy, condition, expression = text.split(u'\t', 6) + # If we don't have an id given for each breakpoint, consider + # the id to be the line. + breakpoint_id = line = int(line) + + condition = condition.replace(u"@_@NEW_LINE_CHAR@_@", u'\n'). \ + replace(u"@_@TAB_CHAR@_@", u'\t').strip() + + expression = expression.replace(u"@_@NEW_LINE_CHAR@_@", u'\n'). \ + replace(u"@_@TAB_CHAR@_@", u'\t').strip() + + if condition is not None and (len(condition) <= 0 or condition == u"None"): + condition = None + + if expression is not None and (len(expression) <= 0 or expression == u"None"): + expression = None + + if hit_condition is not None and (len(hit_condition) <= 0 or hit_condition == u"None"): + hit_condition = None + + result = self.api.add_breakpoint( + py_db, self.api.filename_to_str(filename), btype, breakpoint_id, line, condition, func_name, expression, suspend_policy, hit_condition, is_logpoint) + error_code = result.error_code + + if error_code: + translated_filename = result.translated_filename + if error_code == self.api.ADD_BREAKPOINT_FILE_NOT_FOUND: + pydev_log.critical('pydev debugger: warning: Trying to add breakpoint to file that does not exist: %s (will have no effect).' % (translated_filename,)) + + elif error_code == self.api.ADD_BREAKPOINT_FILE_EXCLUDED_BY_FILTERS: + pydev_log.critical('pydev debugger: warning: Trying to add breakpoint to file that is excluded by filters: %s (will have no effect).' % (translated_filename,)) + + else: + # Shouldn't get here. + pydev_log.critical('pydev debugger: warning: Breakpoint not validated (reason unknown -- please report as error): %s.' % (translated_filename,)) + + def cmd_remove_break(self, py_db, cmd_id, seq, text): + # command to remove some breakpoint + # text is type\file\tid. Remove from breakpoints dictionary + breakpoint_type, filename, breakpoint_id = text.split('\t', 2) + + filename = self.api.filename_to_str(filename) + + try: + breakpoint_id = int(breakpoint_id) + except ValueError: + pydev_log.critical('Error removing breakpoint. Expected breakpoint_id to be an int. Found: %s', breakpoint_id) + + else: + self.api.remove_breakpoint(py_db, filename, breakpoint_type, breakpoint_id) + + def _cmd_exec_or_evaluate_expression(self, py_db, cmd_id, seq, text): + # command to evaluate the given expression + # text is: thread\tstackframe\tLOCAL\texpression + attr_to_set_result = "" + try: + thread_id, frame_id, scope, expression, trim, attr_to_set_result = text.split('\t', 5) + except ValueError: + thread_id, frame_id, scope, expression, trim = text.split('\t', 4) + is_exec = cmd_id == CMD_EXEC_EXPRESSION + trim_if_too_big = int(trim) == 1 + + self.api.request_exec_or_evaluate( + py_db, seq, thread_id, frame_id, expression, is_exec, trim_if_too_big, attr_to_set_result) + + cmd_evaluate_expression = _cmd_exec_or_evaluate_expression + cmd_exec_expression = _cmd_exec_or_evaluate_expression + + def cmd_console_exec(self, py_db, cmd_id, seq, text): + # command to exec expression in console, in case expression is only partially valid 'False' is returned + # text is: thread\tstackframe\tLOCAL\texpression + + thread_id, frame_id, scope, expression = text.split('\t', 3) + self.api.request_console_exec(py_db, seq, thread_id, frame_id, expression) + + def cmd_set_py_exception(self, py_db, cmd_id, seq, text): + # Command which receives set of exceptions on which user wants to break the debugger + # text is: + # + # break_on_uncaught; + # break_on_caught; + # skip_on_exceptions_thrown_in_same_context; + # ignore_exceptions_thrown_in_lines_with_ignore_exception; + # ignore_libraries; + # TypeError;ImportError;zipimport.ZipImportError; + # + # i.e.: true;true;true;true;true;TypeError;ImportError;zipimport.ZipImportError; + # + # This API is optional and works 'in bulk' -- it's possible + # to get finer-grained control with CMD_ADD_EXCEPTION_BREAK/CMD_REMOVE_EXCEPTION_BREAK + # which allows setting caught/uncaught per exception. + splitted = text.split(';') + py_db.break_on_uncaught_exceptions = {} + py_db.break_on_caught_exceptions = {} + if len(splitted) >= 5: + if splitted[0] == 'true': + break_on_uncaught = True + else: + break_on_uncaught = False + + if splitted[1] == 'true': + break_on_caught = True + else: + break_on_caught = False + + if splitted[2] == 'true': + py_db.skip_on_exceptions_thrown_in_same_context = True + else: + py_db.skip_on_exceptions_thrown_in_same_context = False + + if splitted[3] == 'true': + py_db.ignore_exceptions_thrown_in_lines_with_ignore_exception = True + else: + py_db.ignore_exceptions_thrown_in_lines_with_ignore_exception = False + + if splitted[4] == 'true': + ignore_libraries = True + else: + ignore_libraries = False + + for exception_type in splitted[5:]: + exception_type = exception_type.strip() + if not exception_type: + continue + + exception_breakpoint = py_db.add_break_on_exception( + exception_type, + condition=None, + expression=None, + notify_on_handled_exceptions=break_on_caught, + notify_on_unhandled_exceptions=break_on_uncaught, + notify_on_first_raise_only=True, + ignore_libraries=ignore_libraries, + ) + + py_db.on_breakpoints_changed() + + else: + sys.stderr.write("Error when setting exception list. Received: %s\n" % (text,)) + + def _load_source(self, py_db, cmd_id, seq, text): + filename = text + filename = self.api.filename_to_str(filename) + self.api.request_load_source(py_db, seq, filename) + + cmd_load_source = _load_source + cmd_get_file_contents = _load_source + + def cmd_set_property_trace(self, py_db, cmd_id, seq, text): + # Command which receives whether to trace property getter/setter/deleter + # text is feature_state(true/false);disable_getter/disable_setter/disable_deleter + if text: + splitted = text.split(';') + if len(splitted) >= 3: + if py_db.disable_property_trace is False and splitted[0] == 'true': + # Replacing property by custom property only when the debugger starts + pydevd_traceproperty.replace_builtin_property() + py_db.disable_property_trace = True + # Enable/Disable tracing of the property getter + if splitted[1] == 'true': + py_db.disable_property_getter_trace = True + else: + py_db.disable_property_getter_trace = False + # Enable/Disable tracing of the property setter + if splitted[2] == 'true': + py_db.disable_property_setter_trace = True + else: + py_db.disable_property_setter_trace = False + # Enable/Disable tracing of the property deleter + if splitted[3] == 'true': + py_db.disable_property_deleter_trace = True + else: + py_db.disable_property_deleter_trace = False + + def cmd_add_exception_break(self, py_db, cmd_id, seq, text): + # Note that this message has some idiosyncrasies... + # + # notify_on_handled_exceptions can be 0, 1 or 2 + # 0 means we should not stop on handled exceptions. + # 1 means we should stop on handled exceptions showing it on all frames where the exception passes. + # 2 means we should stop on handled exceptions but we should only notify about it once. + # + # To ignore_libraries properly, besides setting ignore_libraries to 1, the IDE_PROJECT_ROOTS environment + # variable must be set (so, we'll ignore anything not below IDE_PROJECT_ROOTS) -- this is not ideal as + # the environment variable may not be properly set if it didn't start from the debugger (we should + # create a custom message for that). + # + # There are 2 global settings which can only be set in CMD_SET_PY_EXCEPTION. Namely: + # + # py_db.skip_on_exceptions_thrown_in_same_context + # - If True, we should only show the exception in a caller, not where it was first raised. + # + # py_db.ignore_exceptions_thrown_in_lines_with_ignore_exception + # - If True exceptions thrown in lines with '@IgnoreException' will not be shown. + + condition = "" + expression = "" + if text.find('\t') != -1: + try: + exception, condition, expression, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries = text.split('\t', 5) + except: + exception, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries = text.split('\t', 3) + else: + exception, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries = text, 0, 0, 0 + + condition = condition.replace("@_@NEW_LINE_CHAR@_@", '\n').replace("@_@TAB_CHAR@_@", '\t').strip() + + if condition is not None and (len(condition) == 0 or condition == "None"): + condition = None + + expression = expression.replace("@_@NEW_LINE_CHAR@_@", '\n').replace("@_@TAB_CHAR@_@", '\t').strip() + + if expression is not None and (len(expression) == 0 or expression == "None"): + expression = None + + if exception.find('-') != -1: + breakpoint_type, exception = exception.split('-') + else: + breakpoint_type = 'python' + + if breakpoint_type == 'python': + self.api.add_python_exception_breakpoint( + py_db, exception, condition, expression, + notify_on_handled_exceptions=int(notify_on_handled_exceptions) > 0, + notify_on_unhandled_exceptions=int(notify_on_unhandled_exceptions) == 1, + notify_on_first_raise_only=int(notify_on_handled_exceptions) == 2, + ignore_libraries=int(ignore_libraries) > 0, + ) + else: + self.api.add_plugins_exception_breakpoint(py_db, breakpoint_type, exception) + + def cmd_remove_exception_break(self, py_db, cmd_id, seq, text): + exception = text + if exception.find('-') != -1: + exception_type, exception = exception.split('-') + else: + exception_type = 'python' + + if exception_type == 'python': + self.api.remove_python_exception_breakpoint(py_db, exception) + else: + self.api.remove_plugins_exception_breakpoint(py_db, exception_type, exception) + + def cmd_add_django_exception_break(self, py_db, cmd_id, seq, text): + self.api.add_plugins_exception_breakpoint(py_db, breakpoint_type='django', exception=text) + + def cmd_remove_django_exception_break(self, py_db, cmd_id, seq, text): + self.api.remove_plugins_exception_breakpoint(py_db, exception_type='django', exception=text) + + def cmd_evaluate_console_expression(self, py_db, cmd_id, seq, text): + # Command which takes care for the debug console communication + if text != "": + thread_id, frame_id, console_command = text.split('\t', 2) + console_command, line = console_command.split('\t') + + if console_command == 'EVALUATE': + int_cmd = InternalEvaluateConsoleExpression( + seq, thread_id, frame_id, line, buffer_output=True) + + elif console_command == 'EVALUATE_UNBUFFERED': + int_cmd = InternalEvaluateConsoleExpression( + seq, thread_id, frame_id, line, buffer_output=False) + + elif console_command == 'GET_COMPLETIONS': + int_cmd = InternalConsoleGetCompletions(seq, thread_id, frame_id, line) + + else: + raise ValueError('Unrecognized command: %s' % (console_command,)) + + py_db.post_internal_command(int_cmd, thread_id) + + def cmd_run_custom_operation(self, py_db, cmd_id, seq, text): + # Command which runs a custom operation + if text != "": + try: + location, custom = text.split('||', 1) + except: + sys.stderr.write('Custom operation now needs a || separator. Found: %s\n' % (text,)) + raise + + thread_id, frame_id, scopeattrs = location.split('\t', 2) + + if scopeattrs.find('\t') != -1: # there are attributes beyond scope + scope, attrs = scopeattrs.split('\t', 1) + else: + scope, attrs = (scopeattrs, None) + + # : style: EXECFILE or EXEC + # : encoded_code_or_file: file to execute or code + # : fname: name of function to be executed in the resulting namespace + style, encoded_code_or_file, fnname = custom.split('\t', 3) + int_cmd = InternalRunCustomOperation(seq, thread_id, frame_id, scope, attrs, + style, encoded_code_or_file, fnname) + py_db.post_internal_command(int_cmd, thread_id) + + def cmd_ignore_thrown_exception_at(self, py_db, cmd_id, seq, text): + if text: + replace = 'REPLACE:' # Not all 3.x versions support u'REPLACE:', so, doing workaround. + if not IS_PY3K: + replace = unicode(replace) # noqa + + if text.startswith(replace): + text = text[8:] + py_db.filename_to_lines_where_exceptions_are_ignored.clear() + + if text: + for line in text.split('||'): # Can be bulk-created (one in each line) + filename, line_number = line.split('|') + filename = self.api.filename_to_server(filename) + + if os.path.exists(filename): + lines_ignored = py_db.filename_to_lines_where_exceptions_are_ignored.get(filename) + if lines_ignored is None: + lines_ignored = py_db.filename_to_lines_where_exceptions_are_ignored[filename] = {} + lines_ignored[int(line_number)] = 1 + else: + sys.stderr.write('pydev debugger: warning: trying to ignore exception thrown'\ + ' on file that does not exist: %s (will have no effect)\n' % (filename,)) + + def cmd_enable_dont_trace(self, py_db, cmd_id, seq, text): + if text: + true_str = 'true' # Not all 3.x versions support u'str', so, doing workaround. + if not IS_PY3K: + true_str = unicode(true_str) # noqa + + mode = text.strip() == true_str + pydevd_dont_trace.trace_filter(mode) + + def cmd_redirect_output(self, py_db, cmd_id, seq, text): + if text: + py_db.enable_output_redirection('STDOUT' in text, 'STDERR' in text) + + def cmd_get_next_statement_targets(self, py_db, cmd_id, seq, text): + thread_id, frame_id = text.split('\t', 1) + + py_db.post_method_as_internal_command( + thread_id, internal_get_next_statement_targets, seq, thread_id, frame_id) + + def cmd_set_project_roots(self, py_db, cmd_id, seq, text): + self.api.set_project_roots(py_db, text.split(u'\t')) + + def cmd_thread_dump_to_stderr(self, py_db, cmd_id, seq, text): + pydevd_utils.dump_threads() + + def cmd_stop_on_start(self, py_db, cmd_id, seq, text): + if text.strip() in ('True', 'true', '1'): + self.api.stop_on_entry() + + def cmd_pydevd_json_config(self, py_db, cmd_id, seq, text): + # Expected to receive a json string as: + # { + # 'skip_suspend_on_breakpoint_exception': [], + # 'skip_print_breakpoint_exception': [], + # 'multi_threads_single_notification': bool, + # } + msg = json.loads(text.strip()) + if 'skip_suspend_on_breakpoint_exception' in msg: + py_db.skip_suspend_on_breakpoint_exception = tuple( + get_exception_class(x) for x in msg['skip_suspend_on_breakpoint_exception']) + + if 'skip_print_breakpoint_exception' in msg: + py_db.skip_print_breakpoint_exception = tuple( + get_exception_class(x) for x in msg['skip_print_breakpoint_exception']) + + if 'multi_threads_single_notification' in msg: + py_db.multi_threads_single_notification = msg['multi_threads_single_notification'] + + def cmd_get_exception_details(self, py_db, cmd_id, seq, text): + thread_id = text + t = pydevd_find_thread_by_id(thread_id) + frame = None + if t and not getattr(t, 'pydev_do_not_trace', None): + additional_info = set_additional_thread_info(t) + frame = additional_info.get_topmost_frame(t) + try: + return py_db.cmd_factory.make_get_exception_details_message(py_db, seq, thread_id, frame) + finally: + frame = None + t = None + + +process_net_command = _PyDevCommandProcessor().process_net_command + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py new file mode 100644 index 0000000..8888193 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py @@ -0,0 +1,935 @@ +import itertools +import json +import linecache +import os +import platform +import sys +from functools import partial + +import pydevd_file_utils +from _pydev_bundle import pydev_log +from _pydevd_bundle._debug_adapter import pydevd_base_schema, pydevd_schema +from _pydevd_bundle._debug_adapter.pydevd_schema import ( + CompletionsResponseBody, EvaluateResponseBody, ExceptionOptions, + GotoTargetsResponseBody, ModulesResponseBody, ProcessEventBody, + ProcessEvent, Scope, ScopesResponseBody, SetExpressionResponseBody, + SetVariableResponseBody, SourceBreakpoint, SourceResponseBody, + VariablesResponseBody, SetBreakpointsResponseBody) +from _pydevd_bundle.pydevd_api import PyDevdAPI +from _pydevd_bundle.pydevd_breakpoints import get_exception_class +from _pydevd_bundle.pydevd_comm_constants import ( + CMD_PROCESS_EVENT, CMD_RETURN, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO, + CMD_STEP_INTO_MY_CODE, CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE, file_system_encoding, + CMD_STEP_RETURN_MY_CODE, CMD_STEP_RETURN) +from _pydevd_bundle.pydevd_filtering import ExcludeFilter +from _pydevd_bundle.pydevd_json_debug_options import _extract_debug_options +from _pydevd_bundle.pydevd_net_command import NetCommand +from _pydevd_bundle.pydevd_utils import convert_dap_log_message_to_expression +from _pydevd_bundle.pydevd_constants import (PY_IMPL_NAME, DebugInfoHolder, PY_VERSION_STR, + PY_IMPL_VERSION_STR, IS_64BIT_PROCESS) + + +def _convert_rules_to_exclude_filters(rules, filename_to_server, on_error): + exclude_filters = [] + if not isinstance(rules, list): + on_error('Invalid "rules" (expected list of dicts). Found: %s' % (rules,)) + + else: + directory_exclude_filters = [] + module_exclude_filters = [] + glob_exclude_filters = [] + + for rule in rules: + if not isinstance(rule, dict): + on_error('Invalid "rules" (expected list of dicts). Found: %s' % (rules,)) + continue + + include = rule.get('include') + if include is None: + on_error('Invalid "rule" (expected dict with "include"). Found: %s' % (rule,)) + continue + + path = rule.get('path') + module = rule.get('module') + if path is None and module is None: + on_error('Invalid "rule" (expected dict with "path" or "module"). Found: %s' % (rule,)) + continue + + if path is not None: + glob_pattern = path + if '*' not in path and '?' not in path: + path = filename_to_server(path) + + if os.path.isdir(glob_pattern): + # If a directory was specified, add a '/**' + # to be consistent with the glob pattern required + # by pydevd. + if not glob_pattern.endswith('/') and not glob_pattern.endswith('\\'): + glob_pattern += '/' + glob_pattern += '**' + directory_exclude_filters.append(ExcludeFilter(glob_pattern, not include, True)) + else: + glob_exclude_filters.append(ExcludeFilter(glob_pattern, not include, True)) + + elif module is not None: + module_exclude_filters.append(ExcludeFilter(module, not include, False)) + + else: + on_error('Internal error: expected path or module to be specified.') + + # Note that we have to sort the directory/module exclude filters so that the biggest + # paths match first. + # i.e.: if we have: + # /sub1/sub2/sub3 + # a rule with /sub1/sub2 would match before a rule only with /sub1. + directory_exclude_filters = sorted(directory_exclude_filters, key=lambda exclude_filter:-len(exclude_filter.name)) + module_exclude_filters = sorted(module_exclude_filters, key=lambda exclude_filter:-len(exclude_filter.name)) + exclude_filters = directory_exclude_filters + glob_exclude_filters + module_exclude_filters + + return exclude_filters + + +class IDMap(object): + + def __init__(self): + self._value_to_key = {} + self._key_to_value = {} + self._next_id = partial(next, itertools.count(0)) + + def obtain_value(self, key): + return self._key_to_value[key] + + def obtain_key(self, value): + try: + key = self._value_to_key[value] + except KeyError: + key = self._next_id() + self._key_to_value[key] = value + self._value_to_key[value] = key + return key + + +class _PyDevJsonCommandProcessor(object): + + def __init__(self, from_json): + self.from_json = from_json + self.api = PyDevdAPI() + self._debug_options = {} + self._next_breakpoint_id = partial(next, itertools.count(0)) + self._goto_targets_map = IDMap() + self._launch_or_attach_request_done = False + + def process_net_command_json(self, py_db, json_contents, send_response=True): + ''' + Processes a debug adapter protocol json command. + ''' + + DEBUG = False + + try: + request = self.from_json(json_contents, update_ids_from_dap=True) + except KeyError as e: + request = self.from_json(json_contents, update_ids_from_dap=False) + error_msg = str(e) + if error_msg.startswith("'") and error_msg.endswith("'"): + error_msg = error_msg[1:-1] + + # This means a failure updating ids from the DAP (the client sent a key we didn't send). + def on_request(py_db, request): + error_response = { + 'type': 'response', + 'request_seq': request.seq, + 'success': False, + 'command': request.command, + 'message': error_msg, + } + return NetCommand(CMD_RETURN, 0, error_response, is_json=True) + + else: + if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS and DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: + pydev_log.info('Process %s: %s\n' % ( + request.__class__.__name__, json.dumps(request.to_dict(), indent=4, sort_keys=True),)) + + assert request.type == 'request' + method_name = 'on_%s_request' % (request.command.lower(),) + on_request = getattr(self, method_name, None) + if on_request is None: + print('Unhandled: %s not available in _PyDevJsonCommandProcessor.\n' % (method_name,)) + return + + if DEBUG: + print('Handled in pydevd: %s (in _PyDevJsonCommandProcessor).\n' % (method_name,)) + + with py_db._main_lock: + cmd = on_request(py_db, request) + if cmd is not None and send_response: + py_db.writer.add_command(cmd) + + def on_configurationdone_request(self, py_db, request): + ''' + :param ConfigurationDoneRequest request: + ''' + if not self._launch_or_attach_request_done: + pydev_log.critical('Missing launch request or attach request before configuration done request.') + + self.api.run(py_db) + self.api.notify_configuration_done(py_db) + + configuration_done_response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, configuration_done_response, is_json=True) + + def on_threads_request(self, py_db, request): + ''' + :param ThreadsRequest request: + ''' + return self.api.list_threads(py_db, request.seq) + + def on_completions_request(self, py_db, request): + ''' + :param CompletionsRequest request: + ''' + arguments = request.arguments # : :type arguments: CompletionsArguments + seq = request.seq + text = arguments.text + frame_id = arguments.frameId + thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference( + frame_id) + + if thread_id is None: + body = CompletionsResponseBody([]) + variables_response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': body, + 'success': False, + 'message': 'Thread to get completions seems to have resumed already.' + }) + return NetCommand(CMD_RETURN, 0, variables_response, is_json=True) + + # Note: line and column are 1-based (convert to 0-based for pydevd). + column = arguments.column - 1 + + if arguments.line is None: + # line is optional + line = -1 + else: + line = arguments.line - 1 + + self.api.request_completions(py_db, seq, thread_id, frame_id, text, line=line, column=column) + + def _resolve_remote_root(self, local_root, remote_root): + if remote_root == '.': + cwd = os.getcwd() + append_pathsep = local_root.endswith('\\') or local_root.endswith('/') + return cwd + (os.path.sep if append_pathsep else '') + return remote_root + + def _set_debug_options(self, py_db, args, start_reason): + rules = args.get('rules') + stepping_resumes_all_threads = args.get('steppingResumesAllThreads', True) + self.api.set_stepping_resumes_all_threads(py_db, stepping_resumes_all_threads) + + exclude_filters = [] + + if rules is not None: + exclude_filters = _convert_rules_to_exclude_filters( + rules, self.api.filename_to_server, lambda msg: self.api.send_error_message(py_db, msg)) + + self.api.set_exclude_filters(py_db, exclude_filters) + + self._debug_options = _extract_debug_options( + args.get('options'), + args.get('debugOptions'), + ) + self._debug_options['args'] = args + + debug_stdlib = self._debug_options.get('DEBUG_STDLIB', False) + self.api.set_use_libraries_filter(py_db, not debug_stdlib) + + path_mappings = [] + for pathMapping in args.get('pathMappings', []): + localRoot = pathMapping.get('localRoot', '') + remoteRoot = pathMapping.get('remoteRoot', '') + remoteRoot = self._resolve_remote_root(localRoot, remoteRoot) + if (localRoot != '') and (remoteRoot != ''): + path_mappings.append((localRoot, remoteRoot)) + + if bool(path_mappings): + pydevd_file_utils.setup_client_server_paths(path_mappings) + + if self._debug_options.get('REDIRECT_OUTPUT', False): + py_db.enable_output_redirection(True, True) + else: + py_db.enable_output_redirection(False, False) + + self.api.set_show_return_values(py_db, self._debug_options.get('SHOW_RETURN_VALUE', False)) + + if not self._debug_options.get('BREAK_SYSTEMEXIT_ZERO', False): + ignore_system_exit_codes = [0] + if self._debug_options.get('DJANGO_DEBUG', False): + ignore_system_exit_codes += [3] + + self.api.set_ignore_system_exit_codes(py_db, ignore_system_exit_codes) + + if self._debug_options.get('STOP_ON_ENTRY', False) and start_reason == 'launch': + self.api.stop_on_entry() + + def _send_process_event(self, py_db, start_method): + if len(sys.argv) > 0: + name = sys.argv[0] + else: + name = '' + + if isinstance(name, bytes): + name = name.decode(file_system_encoding, 'replace') + name = name.encode('utf-8') + + body = ProcessEventBody( + name=name, + systemProcessId=os.getpid(), + isLocalProcess=True, + startMethod=start_method, + ) + event = ProcessEvent(body) + py_db.writer.add_command(NetCommand(CMD_PROCESS_EVENT, 0, event, is_json=True)) + + def _handle_launch_or_attach_request(self, py_db, request, start_reason): + self._send_process_event(py_db, start_reason) + self._launch_or_attach_request_done = True + self.api.set_enable_thread_notifications(py_db, True) + self._set_debug_options(py_db, request.arguments.kwargs, start_reason=start_reason) + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_launch_request(self, py_db, request): + ''' + :param LaunchRequest request: + ''' + return self._handle_launch_or_attach_request(py_db, request, start_reason='launch') + + def on_attach_request(self, py_db, request): + ''' + :param AttachRequest request: + ''' + return self._handle_launch_or_attach_request(py_db, request, start_reason='attach') + + def on_pause_request(self, py_db, request): + ''' + :param PauseRequest request: + ''' + arguments = request.arguments # : :type arguments: PauseArguments + thread_id = arguments.threadId + + self.api.request_suspend_thread(py_db, thread_id=thread_id) + + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_continue_request(self, py_db, request): + ''' + :param ContinueRequest request: + ''' + arguments = request.arguments # : :type arguments: ContinueArguments + thread_id = arguments.threadId + + def on_resumed(): + body = {'allThreadsContinued': thread_id == '*'} + response = pydevd_base_schema.build_response(request, kwargs={'body': body}) + cmd = NetCommand(CMD_RETURN, 0, response, is_json=True) + py_db.writer.add_command(cmd) + + # Only send resumed notification when it has actually resumed! + # (otherwise the user could send a continue, receive the notification and then + # request a new pause which would be paused without sending any notification as + # it didn't really run in the first place). + py_db.threads_suspended_single_notification.add_on_resumed_callback(on_resumed) + self.api.request_resume_thread(thread_id) + + def on_next_request(self, py_db, request): + ''' + :param NextRequest request: + ''' + arguments = request.arguments # : :type arguments: NextArguments + thread_id = arguments.threadId + + if py_db.get_use_libraries_filter(): + step_cmd_id = CMD_STEP_OVER_MY_CODE + else: + step_cmd_id = CMD_STEP_OVER + + self.api.request_step(py_db, thread_id, step_cmd_id) + + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_stepin_request(self, py_db, request): + ''' + :param StepInRequest request: + ''' + arguments = request.arguments # : :type arguments: StepInArguments + thread_id = arguments.threadId + + if py_db.get_use_libraries_filter(): + step_cmd_id = CMD_STEP_INTO_MY_CODE + else: + step_cmd_id = CMD_STEP_INTO + + self.api.request_step(py_db, thread_id, step_cmd_id) + + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_stepout_request(self, py_db, request): + ''' + :param StepOutRequest request: + ''' + arguments = request.arguments # : :type arguments: StepOutArguments + thread_id = arguments.threadId + + if py_db.get_use_libraries_filter(): + step_cmd_id = CMD_STEP_RETURN_MY_CODE + else: + step_cmd_id = CMD_STEP_RETURN + + self.api.request_step(py_db, thread_id, step_cmd_id) + + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def _get_hit_condition_expression(self, hit_condition): + '''Following hit condition values are supported + + * x or == x when breakpoint is hit x times + * >= x when breakpoint is hit more than or equal to x times + * % x when breakpoint is hit multiple of x times + + Returns '@HIT@ == x' where @HIT@ will be replaced by number of hits + ''' + if not hit_condition: + return None + + expr = hit_condition.strip() + try: + int(expr) + return '@HIT@ == {}'.format(expr) + except ValueError: + pass + + if expr.startswith('%'): + return '@HIT@ {} == 0'.format(expr) + + if expr.startswith('==') or \ + expr.startswith('>') or \ + expr.startswith('<'): + return '@HIT@ {}'.format(expr) + + return hit_condition + + def on_disconnect_request(self, py_db, request): + ''' + :param DisconnectRequest request: + ''' + self._launch_or_attach_request_done = False + py_db.enable_output_redirection(False, False) + self.api.request_disconnect(py_db, resume_threads=True) + + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_setbreakpoints_request(self, py_db, request): + ''' + :param SetBreakpointsRequest request: + ''' + if not self._launch_or_attach_request_done: + # Note that to validate the breakpoints we need the launch request to be done already + # (otherwise the filters wouldn't be set for the breakpoint validation). + body = SetBreakpointsResponseBody([]) + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': body, + 'success': False, + 'message': 'Breakpoints may only be set after the launch request is received.' + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + arguments = request.arguments # : :type arguments: SetBreakpointsArguments + # TODO: Path is optional here it could be source reference. + filename = self.api.filename_to_str(arguments.source.path) + func_name = 'None' + + self.api.remove_all_breakpoints(py_db, filename) + + btype = 'python-line' + suspend_policy = 'ALL' + + if not filename.lower().endswith('.py'): # Note: check based on original file, not mapping. + if self._debug_options.get('DJANGO_DEBUG', False): + btype = 'django-line' + elif self._debug_options.get('FLASK_DEBUG', False): + btype = 'jinja2-line' + + breakpoints_set = [] + + for source_breakpoint in arguments.breakpoints: + source_breakpoint = SourceBreakpoint(**source_breakpoint) + line = source_breakpoint.line + condition = source_breakpoint.condition + breakpoint_id = line + + hit_condition = self._get_hit_condition_expression(source_breakpoint.hitCondition) + log_message = source_breakpoint.logMessage + if not log_message: + is_logpoint = None + expression = None + else: + is_logpoint = True + expression = convert_dap_log_message_to_expression(log_message) + + result = self.api.add_breakpoint( + py_db, filename, btype, breakpoint_id, line, condition, func_name, expression, suspend_policy, hit_condition, is_logpoint, adjust_line=True) + error_code = result.error_code + + if error_code: + if error_code == self.api.ADD_BREAKPOINT_FILE_NOT_FOUND: + error_msg = 'Breakpoint in file that does not exist.' + + elif error_code == self.api.ADD_BREAKPOINT_FILE_EXCLUDED_BY_FILTERS: + error_msg = 'Breakpoint in file excluded by filters.' + if py_db.get_use_libraries_filter(): + error_msg += '\nNote: may be excluded because of "justMyCode" option (default == true).' + + else: + # Shouldn't get here. + error_msg = 'Breakpoint not validated (reason unknown -- please report as bug).' + + breakpoints_set.append(pydevd_schema.Breakpoint( + verified=False, line=result.translated_line, message=error_msg, source=arguments.source).to_dict()) + else: + # Note that the id is made up (the id for pydevd is unique only within a file, so, the + # line is used for it). + # Also, the id is currently not used afterwards, so, we don't even keep a mapping. + breakpoints_set.append(pydevd_schema.Breakpoint( + verified=True, id=self._next_breakpoint_id(), line=result.translated_line, source=arguments.source).to_dict()) + + body = {'breakpoints': breakpoints_set} + set_breakpoints_response = pydevd_base_schema.build_response(request, kwargs={'body': body}) + return NetCommand(CMD_RETURN, 0, set_breakpoints_response, is_json=True) + + def on_setexceptionbreakpoints_request(self, py_db, request): + ''' + :param SetExceptionBreakpointsRequest request: + ''' + # : :type arguments: SetExceptionBreakpointsArguments + arguments = request.arguments + filters = arguments.filters + exception_options = arguments.exceptionOptions + self.api.remove_all_exception_breakpoints(py_db) + + # Can't set these in the DAP. + condition = None + expression = None + notify_on_first_raise_only = False + + ignore_libraries = 1 if py_db.get_use_libraries_filter() else 0 + + if exception_options: + break_raised = True + break_uncaught = True + + for option in exception_options: + option = ExceptionOptions(**option) + if not option.path: + continue + + notify_on_handled_exceptions = 1 if option.breakMode == 'always' else 0 + notify_on_unhandled_exceptions = 1 if option.breakMode in ('unhandled', 'userUnhandled') else 0 + exception_paths = option.path + + exception_names = [] + if len(exception_paths) == 0: + continue + + elif len(exception_paths) == 1: + if 'Python Exceptions' in exception_paths[0]['names']: + exception_names = ['BaseException'] + + else: + path_iterator = iter(exception_paths) + if 'Python Exceptions' in next(path_iterator)['names']: + for path in path_iterator: + for ex_name in path['names']: + exception_names.append(ex_name) + + for exception_name in exception_names: + self.api.add_python_exception_breakpoint( + py_db, + exception_name, + condition, + expression, + notify_on_handled_exceptions, + notify_on_unhandled_exceptions, + notify_on_first_raise_only, + ignore_libraries + ) + + else: + break_raised = 'raised' in filters + break_uncaught = 'uncaught' in filters + if break_raised or break_uncaught: + notify_on_handled_exceptions = 1 if break_raised else 0 + notify_on_unhandled_exceptions = 1 if break_uncaught else 0 + exception = 'BaseException' + + self.api.add_python_exception_breakpoint( + py_db, + exception, + condition, + expression, + notify_on_handled_exceptions, + notify_on_unhandled_exceptions, + notify_on_first_raise_only, + ignore_libraries + ) + + if break_raised or break_uncaught: + btype = None + if self._debug_options.get('DJANGO_DEBUG', False): + btype = 'django' + elif self._debug_options.get('FLASK_DEBUG', False): + btype = 'jinja2' + + if btype: + self.api.add_plugins_exception_breakpoint( + py_db, btype, 'BaseException') # Note: Exception name could be anything here. + + # Note: no body required on success. + set_breakpoints_response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, set_breakpoints_response, is_json=True) + + def on_stacktrace_request(self, py_db, request): + ''' + :param StackTraceRequest request: + ''' + # : :type stack_trace_arguments: StackTraceArguments + stack_trace_arguments = request.arguments + thread_id = stack_trace_arguments.threadId + start_frame = stack_trace_arguments.startFrame + levels = stack_trace_arguments.levels + + fmt = stack_trace_arguments.format + if hasattr(fmt, 'to_dict'): + fmt = fmt.to_dict() + self.api.request_stack(py_db, request.seq, thread_id, fmt=fmt, start_frame=start_frame, levels=levels) + + def on_exceptioninfo_request(self, py_db, request): + ''' + :param ExceptionInfoRequest request: + ''' + # : :type exception_into_arguments: ExceptionInfoArguments + exception_into_arguments = request.arguments + thread_id = exception_into_arguments.threadId + max_frames = int(self._debug_options['args'].get('maxExceptionStackFrames', 0)) + self.api.request_exception_info_json(py_db, request, thread_id, max_frames) + + def on_scopes_request(self, py_db, request): + ''' + Scopes are the top-level items which appear for a frame (so, we receive the frame id + and provide the scopes it has). + + :param ScopesRequest request: + ''' + frame_id = request.arguments.frameId + + variables_reference = frame_id + scopes = [Scope('Locals', int(variables_reference), False).to_dict()] + body = ScopesResponseBody(scopes) + scopes_response = pydevd_base_schema.build_response(request, kwargs={'body': body}) + return NetCommand(CMD_RETURN, 0, scopes_response, is_json=True) + + def on_evaluate_request(self, py_db, request): + ''' + :param EvaluateRequest request: + ''' + # : :type arguments: EvaluateArguments + arguments = request.arguments + + thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference( + arguments.frameId) + + if thread_id is not None: + self.api.request_exec_or_evaluate_json( + py_db, request, thread_id) + else: + body = EvaluateResponseBody('', 0) + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': body, + 'success': False, + 'message': 'Unable to find thread for evaluation.' + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_setexpression_request(self, py_db, request): + # : :type arguments: SetExpressionArguments + arguments = request.arguments + + thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference( + arguments.frameId) + + if thread_id is not None: + self.api.request_set_expression_json(py_db, request, thread_id) + else: + body = SetExpressionResponseBody('') + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': body, + 'success': False, + 'message': 'Unable to find thread to set expression.' + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_variables_request(self, py_db, request): + ''' + Variables can be asked whenever some place returned a variables reference (so, it + can be a scope gotten from on_scopes_request, the result of some evaluation, etc.). + + Note that in the DAP the variables reference requires a unique int... the way this works for + pydevd is that an instance is generated for that specific variable reference and we use its + id(instance) to identify it to make sure all items are unique (and the actual {id->instance} + is added to a dict which is only valid while the thread is suspended and later cleared when + the related thread resumes execution). + + see: SuspendedFramesManager + + :param VariablesRequest request: + ''' + arguments = request.arguments # : :type arguments: VariablesArguments + variables_reference = arguments.variablesReference + + thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference( + variables_reference) + if thread_id is not None: + self.api.request_get_variable_json(py_db, request, thread_id) + else: + variables = [] + body = VariablesResponseBody(variables) + variables_response = pydevd_base_schema.build_response(request, kwargs={ + 'body': body, + 'success': False, + 'message': 'Unable to find thread to evaluate variable reference.' + }) + return NetCommand(CMD_RETURN, 0, variables_response, is_json=True) + + def on_setvariable_request(self, py_db, request): + arguments = request.arguments # : :type arguments: SetVariableArguments + variables_reference = arguments.variablesReference + + if arguments.name.startswith('(return) '): + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': SetVariableResponseBody(''), + 'success': False, + 'message': 'Cannot change return value' + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_reference( + variables_reference) + if thread_id is not None: + self.api.request_change_variable_json(py_db, request, thread_id) + else: + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': SetVariableResponseBody(''), + 'success': False, + 'message': 'Unable to find thread to evaluate variable reference.' + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_modules_request(self, py_db, request): + modules_manager = py_db.cmd_factory.modules_manager # : :type modules_manager: ModulesManager + modules_info = modules_manager.get_modules_info() + body = ModulesResponseBody(modules_info) + variables_response = pydevd_base_schema.build_response(request, kwargs={'body': body}) + return NetCommand(CMD_RETURN, 0, variables_response, is_json=True) + + def on_source_request(self, py_db, request): + ''' + :param SourceRequest request: + ''' + source_reference = request.arguments.sourceReference + server_filename = None + content = None + + if source_reference != 0: + server_filename = pydevd_file_utils.get_server_filename_from_source_reference(source_reference) + if server_filename: + # Try direct file access first - it's much faster when available. + try: + with open(server_filename, 'r') as stream: + content = stream.read() + except: + pass + + if content is None: + # File might not exist at all, or we might not have a permission to read it, + # but it might also be inside a zipfile, or an IPython cell. In this case, + # linecache might still be able to retrieve the source. + lines = (linecache.getline(server_filename, i) for i in itertools.count(1)) + lines = itertools.takewhile(bool, lines) # empty lines are '\n', EOF is '' + + # If we didn't get at least one line back, reset it to None so that it's + # reported as error below, and not as an empty file. + content = ''.join(lines) or None + + body = SourceResponseBody(content or '') + response_args = {'body': body} + + if content is None: + if source_reference == 0: + message = 'Source unavailable' + elif server_filename: + message = 'Unable to retrieve source for %s' % (server_filename,) + else: + message = 'Invalid sourceReference %d' % (source_reference,) + response_args.update({'success': False, 'message': message}) + + response = pydevd_base_schema.build_response(request, kwargs=response_args) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_gototargets_request(self, py_db, request): + path = request.arguments.source.path + line = request.arguments.line + target_id = self._goto_targets_map.obtain_key((path, line)) + target = { + 'id': target_id, + 'label': '%s:%s' % (path, line), + 'line': line + } + body = GotoTargetsResponseBody(targets=[target]) + response_args = {'body': body} + response = pydevd_base_schema.build_response(request, kwargs=response_args) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_goto_request(self, py_db, request): + target_id = int(request.arguments.targetId) + thread_id = request.arguments.threadId + try: + _, line = self._goto_targets_map.obtain_value(target_id) + except KeyError: + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': {}, + 'success': False, + 'message': 'Unknown goto target id: %d' % (target_id,), + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + self.api.request_set_next(py_db, request.seq, thread_id, CMD_SET_NEXT_STATEMENT, line, '*') + # See 'NetCommandFactoryJson.make_set_next_stmnt_status_message' for response + return None + + def on_setdebuggerproperty_request(self, py_db, request): + args = request.arguments # : :type args: SetDebuggerPropertyArguments + if args.ideOS is not None: + self.api.set_ide_os(args.ideOS) + + if args.dontTraceStartPatterns is not None and args.dontTraceEndPatterns is not None: + start_patterns = tuple(args.dontTraceStartPatterns) + end_patterns = tuple(args.dontTraceEndPatterns) + self.api.set_dont_trace_start_end_patterns(py_db, start_patterns, end_patterns) + + if args.skipSuspendOnBreakpointException is not None: + py_db.skip_suspend_on_breakpoint_exception = tuple( + get_exception_class(x) for x in args.skipSuspendOnBreakpointException) + + if args.skipPrintBreakpointException is not None: + py_db.skip_print_breakpoint_exception = tuple( + get_exception_class(x) for x in args.skipPrintBreakpointException) + + if args.multiThreadsSingleNotification is not None: + py_db.multi_threads_single_notification = args.multiThreadsSingleNotification + + # TODO: Support other common settings. Note that not all of these might be relevant to python. + # JustMyCodeStepping: 0 or 1 + # AllowOutOfProcessSymbols: 0 or 1 + # DisableJITOptimization: 0 or 1 + # InterpreterOptions: 0 or 1 + # StopOnExceptionCrossingManagedBoundary: 0 or 1 + # WarnIfNoUserCodeOnLaunch: 0 or 1 + # EnableStepFiltering: true of false + + response = pydevd_base_schema.build_response(request, kwargs={'body': {}}) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_pydevdsysteminfo_request(self, py_db, request): + try: + pid = os.getpid() + except AttributeError: + pid = None + + try: + impl_desc = platform.python_implementation() + except AttributeError: + impl_desc = PY_IMPL_NAME + + py_info = pydevd_schema.PydevdPythonInfo( + version=PY_VERSION_STR, + implementation=pydevd_schema.PydevdPythonImplementationInfo( + name=PY_IMPL_NAME, + version=PY_IMPL_VERSION_STR, + description=impl_desc, + ) + ) + platform_info = pydevd_schema.PydevdPlatformInfo(name=sys.platform) + process_info = pydevd_schema.PydevdProcessInfo( + pid=pid, + executable=sys.executable, + bitness=64 if IS_64BIT_PROCESS else 32, + ) + body = { + 'python': py_info, + 'platform': platform_info, + 'process': process_info, + } + response = pydevd_base_schema.build_response(request, kwargs={'body': body}) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + def on_setpydevdsourcemap_request(self, py_db, request): + args = request.arguments # : :type args: SetPydevdSourceMapArguments + SourceMappingEntry = self.api.SourceMappingEntry + + path = args.source.path + source_maps = args.pydevdSourceMaps + # : :type source_map: PydevdSourceMap + new_mappings = [ + SourceMappingEntry( + source_map['line'], + source_map['endLine'], + source_map['runtimeLine'], + self.api.filename_to_str(source_map['runtimeSource']['path']) + ) for source_map in source_maps + ] + + error_msg = self.api.set_source_mapping(py_db, path, new_mappings) + if error_msg: + response = pydevd_base_schema.build_response( + request, + kwargs={ + 'body': {}, + 'success': False, + 'message': error_msg, + }) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + response = pydevd_base_schema.build_response(request) + return NetCommand(CMD_RETURN, 0, response, is_json=True) + + +process_net_command_json = _PyDevJsonCommandProcessor(pydevd_base_schema.from_json).process_net_command_json diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_referrers.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_referrers.py new file mode 100644 index 0000000..d8dd6bd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_referrers.py @@ -0,0 +1,242 @@ +import sys +from _pydevd_bundle import pydevd_xml +from os.path import basename +import traceback +from _pydev_bundle import pydev_log +try: + from urllib import quote, quote_plus, unquote, unquote_plus +except: + from urllib.parse import quote, quote_plus, unquote, unquote_plus # @Reimport @UnresolvedImport + + +#=================================================================================================== +# print_var_node +#=================================================================================================== +def print_var_node(xml_node, stream): + name = xml_node.getAttribute('name') + value = xml_node.getAttribute('value') + val_type = xml_node.getAttribute('type') + + found_as = xml_node.getAttribute('found_as') + stream.write('Name: ') + stream.write(unquote_plus(name)) + stream.write(', Value: ') + stream.write(unquote_plus(value)) + stream.write(', Type: ') + stream.write(unquote_plus(val_type)) + if found_as: + stream.write(', Found as: %s' % (unquote_plus(found_as),)) + stream.write('\n') + + +#=================================================================================================== +# print_referrers +#=================================================================================================== +def print_referrers(obj, stream=None): + if stream is None: + stream = sys.stdout + result = get_referrer_info(obj) + from xml.dom.minidom import parseString + dom = parseString(result) + + xml = dom.getElementsByTagName('xml')[0] + for node in xml.childNodes: + if node.nodeType == node.TEXT_NODE: + continue + + if node.localName == 'for': + stream.write('Searching references for: ') + for child in node.childNodes: + if child.nodeType == node.TEXT_NODE: + continue + print_var_node(child, stream) + + elif node.localName == 'var': + stream.write('Referrer found: ') + print_var_node(node, stream) + + else: + sys.stderr.write('Unhandled node: %s\n' % (node,)) + + return result + + +#=================================================================================================== +# get_referrer_info +#=================================================================================================== +def get_referrer_info(searched_obj): + DEBUG = 0 + if DEBUG: + sys.stderr.write('Getting referrers info.\n') + try: + try: + if searched_obj is None: + ret = ['\n'] + + ret.append('\n') + ret.append(pydevd_xml.var_to_xml( + searched_obj, + 'Skipping getting referrers for None', + additional_in_xml=' id="%s"' % (id(searched_obj),))) + ret.append('\n') + ret.append('') + ret = ''.join(ret) + return ret + + obj_id = id(searched_obj) + + try: + if DEBUG: + sys.stderr.write('Getting referrers...\n') + import gc + referrers = gc.get_referrers(searched_obj) + except: + pydev_log.exception() + ret = ['\n'] + + ret.append('\n') + ret.append(pydevd_xml.var_to_xml( + searched_obj, + 'Exception raised while trying to get_referrers.', + additional_in_xml=' id="%s"' % (id(searched_obj),))) + ret.append('\n') + ret.append('') + ret = ''.join(ret) + return ret + + if DEBUG: + sys.stderr.write('Found %s referrers.\n' % (len(referrers),)) + + curr_frame = sys._getframe() + frame_type = type(curr_frame) + + # Ignore this frame and any caller frame of this frame + + ignore_frames = {} # Should be a set, but it's not available on all python versions. + while curr_frame is not None: + if basename(curr_frame.f_code.co_filename).startswith('pydev'): + ignore_frames[curr_frame] = 1 + curr_frame = curr_frame.f_back + + ret = ['\n'] + + ret.append('\n') + if DEBUG: + sys.stderr.write('Searching Referrers of obj with id="%s"\n' % (obj_id,)) + + ret.append(pydevd_xml.var_to_xml( + searched_obj, + 'Referrers of obj with id="%s"' % (obj_id,))) + ret.append('\n') + + curr_frame = sys._getframe() + all_objects = None + + for r in referrers: + try: + if r in ignore_frames: + continue # Skip the references we may add ourselves + except: + pass # Ok: unhashable type checked... + + if r is referrers: + continue + + if r is curr_frame.f_locals: + continue + + r_type = type(r) + r_id = str(id(r)) + + representation = str(r_type) + + found_as = '' + if r_type == frame_type: + if DEBUG: + sys.stderr.write('Found frame referrer: %r\n' % (r,)) + for key, val in r.f_locals.items(): + if val is searched_obj: + found_as = key + break + + elif r_type == dict: + if DEBUG: + sys.stderr.write('Found dict referrer: %r\n' % (r,)) + + # Try to check if it's a value in the dict (and under which key it was found) + for key, val in r.items(): + if val is searched_obj: + found_as = key + if DEBUG: + sys.stderr.write(' Found as %r in dict\n' % (found_as,)) + break + + # Ok, there's one annoying thing: many times we find it in a dict from an instance, + # but with this we don't directly have the class, only the dict, so, to workaround that + # we iterate over all reachable objects ad check if one of those has the given dict. + if all_objects is None: + all_objects = gc.get_objects() + + for x in all_objects: + try: + if getattr(x, '__dict__', None) is r: + r = x + r_type = type(x) + r_id = str(id(r)) + representation = str(r_type) + break + except: + pass # Just ignore any error here (i.e.: ReferenceError, etc.) + + elif r_type in (tuple, list): + if DEBUG: + sys.stderr.write('Found tuple referrer: %r\n' % (r,)) + + for i, x in enumerate(r): + if x is searched_obj: + found_as = '%s[%s]' % (r_type.__name__, i) + if DEBUG: + sys.stderr.write(' Found as %s in tuple: \n' % (found_as,)) + break + + if found_as: + if not isinstance(found_as, str): + found_as = str(found_as) + found_as = ' found_as="%s"' % (pydevd_xml.make_valid_xml_value(found_as),) + + ret.append(pydevd_xml.var_to_xml( + r, + representation, + additional_in_xml=' id="%s"%s' % (r_id, found_as))) + finally: + if DEBUG: + sys.stderr.write('Done searching for references.\n') + + # If we have any exceptions, don't keep dangling references from this frame to any of our objects. + all_objects = None + referrers = None + searched_obj = None + r = None + x = None + key = None + val = None + curr_frame = None + ignore_frames = None + except: + pydev_log.exception() + ret = ['\n'] + + ret.append('\n') + ret.append(pydevd_xml.var_to_xml( + searched_obj, + 'Error getting referrers for:', + additional_in_xml=' id="%s"' % (id(searched_obj),))) + ret.append('\n') + ret.append('') + ret = ''.join(ret) + return ret + + ret.append('') + ret = ''.join(ret) + return ret + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_reload.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_reload.py new file mode 100644 index 0000000..5b77452 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_reload.py @@ -0,0 +1,448 @@ +""" +Based on the python xreload. + +Changes +====================== + +1. we don't recreate the old namespace from new classes. Rather, we keep the existing namespace, +load a new version of it and update only some of the things we can inplace. That way, we don't break +things such as singletons or end up with a second representation of the same class in memory. + +2. If we find it to be a __metaclass__, we try to update it as a regular class. + +3. We don't remove old attributes (and leave them lying around even if they're no longer used). + +4. Reload hooks were changed + +These changes make it more stable, especially in the common case (where in a debug session only the +contents of a function are changed), besides providing flexibility for users that want to extend +on it. + + + +Hooks +====================== + +Classes/modules can be specially crafted to work with the reload (so that it can, for instance, +update some constant which was changed). + +1. To participate in the change of some attribute: + + In a module: + + __xreload_old_new__(namespace, name, old, new) + + in a class: + + @classmethod + __xreload_old_new__(cls, name, old, new) + + A class or module may include a method called '__xreload_old_new__' which is called when we're + unable to reload a given attribute. + + + +2. To do something after the whole reload is finished: + + In a module: + + __xreload_after_reload_update__(namespace): + + In a class: + + @classmethod + __xreload_after_reload_update__(cls): + + + A class or module may include a method called '__xreload_after_reload_update__' which is called + after the reload finishes. + + +Important: when providing a hook, always use the namespace or cls provided and not anything in the global +namespace, as the global namespace are only temporarily created during the reload and may not reflect the +actual application state (while the cls and namespace passed are). + + +Current limitations +====================== + + +- Attributes/constants are added, but not changed (so singletons and the application state is not + broken -- use provided hooks to workaround it). + +- Code using metaclasses may not always work. + +- Functions and methods using decorators (other than classmethod and staticmethod) are not handled + correctly. + +- Renamings are not handled correctly. + +- Dependent modules are not reloaded. + +- New __slots__ can't be added to existing classes. + + +Info +====================== + +Original: http://svn.python.org/projects/sandbox/trunk/xreload/xreload.py +Note: it seems https://github.com/plone/plone.reload/blob/master/plone/reload/xreload.py enhances it (to check later) + +Interesting alternative: https://code.google.com/p/reimport/ + +Alternative to reload(). + +This works by executing the module in a scratch namespace, and then patching classes, methods and +functions in place. This avoids the need to patch instances. New objects are copied into the +target namespace. + +""" + +import imp +from _pydev_bundle.pydev_imports import Exec +from _pydevd_bundle import pydevd_dont_trace +import sys +import traceback +import types +from _pydev_bundle import pydev_log + +NO_DEBUG = 0 +LEVEL1 = 1 +LEVEL2 = 2 + +DEBUG = NO_DEBUG + + +def write(*args): + new_lst = [] + for a in args: + new_lst.append(str(a)) + + msg = ' '.join(new_lst) + sys.stdout.write('%s\n' % (msg,)) + + +def write_err(*args): + new_lst = [] + for a in args: + new_lst.append(str(a)) + + msg = ' '.join(new_lst) + sys.stderr.write('pydev debugger: %s\n' % (msg,)) + + +def notify_info0(*args): + write_err(*args) + + +def notify_info(*args): + if DEBUG >= LEVEL1: + write(*args) + + +def notify_info2(*args): + if DEBUG >= LEVEL2: + write(*args) + + +def notify_error(*args): + write_err(*args) + + +#======================================================================================================================= +# code_objects_equal +#======================================================================================================================= +def code_objects_equal(code0, code1): + for d in dir(code0): + if d.startswith('_') or 'lineno' in d: + continue + if getattr(code0, d) != getattr(code1, d): + return False + return True + + +#======================================================================================================================= +# xreload +#======================================================================================================================= +def xreload(mod): + """Reload a module in place, updating classes, methods and functions. + + mod: a module object + + Returns a boolean indicating whether a change was done. + """ + r = Reload(mod) + r.apply() + found_change = r.found_change + r = None + pydevd_dont_trace.clear_trace_filter_cache() + return found_change + +# This isn't actually used... Initially I planned to reload variables which are immutable on the +# namespace, but this can destroy places where we're saving state, which may not be what we want, +# so, we're being conservative and giving the user hooks if he wants to do a reload. +# +# immutable_types = [int, str, float, tuple] #That should be common to all Python versions +# +# for name in 'long basestr unicode frozenset'.split(): +# try: +# immutable_types.append(__builtins__[name]) +# except: +# pass #Just ignore: not all python versions are created equal. +# immutable_types = tuple(immutable_types) + + +#======================================================================================================================= +# Reload +#======================================================================================================================= +class Reload: + + def __init__(self, mod): + self.mod = mod + self.found_change = False + + def apply(self): + mod = self.mod + self._on_finish_callbacks = [] + try: + # Get the module name, e.g. 'foo.bar.whatever' + modname = mod.__name__ + # Get the module namespace (dict) early; this is part of the type check + modns = mod.__dict__ + # Parse it into package name and module name, e.g. 'foo.bar' and 'whatever' + i = modname.rfind(".") + if i >= 0: + pkgname, modname = modname[:i], modname[i + 1:] + else: + pkgname = None + # Compute the search path + if pkgname: + # We're not reloading the package, only the module in it + pkg = sys.modules[pkgname] + path = pkg.__path__ # Search inside the package + else: + # Search the top-level module path + pkg = None + path = None # Make find_module() uses the default search path + # Find the module; may raise ImportError + (stream, filename, (suffix, mode, kind)) = imp.find_module(modname, path) + # Turn it into a code object + try: + # Is it Python source code or byte code read from a file? + if kind not in (imp.PY_COMPILED, imp.PY_SOURCE): + # Fall back to built-in reload() + notify_error('Could not find source to reload (mod: %s)' % (modname,)) + return + if kind == imp.PY_SOURCE: + source = stream.read() + code = compile(source, filename, "exec") + else: + import marshal + code = marshal.load(stream) + finally: + if stream: + stream.close() + # Execute the code. We copy the module dict to a temporary; then + # clear the module dict; then execute the new code in the module + # dict; then swap things back and around. This trick (due to + # Glyph Lefkowitz) ensures that the (readonly) __globals__ + # attribute of methods and functions is set to the correct dict + # object. + new_namespace = modns.copy() + new_namespace.clear() + new_namespace["__name__"] = modns["__name__"] + Exec(code, new_namespace) + # Now we get to the hard part + oldnames = set(modns) + newnames = set(new_namespace) + + # Create new tokens (note: not deleting existing) + for name in newnames - oldnames: + notify_info0('Added:', name, 'to namespace') + self.found_change = True + modns[name] = new_namespace[name] + + # Update in-place what we can + for name in oldnames & newnames: + self._update(modns, name, modns[name], new_namespace[name]) + + self._handle_namespace(modns) + + for c in self._on_finish_callbacks: + c() + del self._on_finish_callbacks[:] + except: + pydev_log.exception() + + def _handle_namespace(self, namespace, is_class_namespace=False): + on_finish = None + if is_class_namespace: + xreload_after_update = getattr(namespace, '__xreload_after_reload_update__', None) + if xreload_after_update is not None: + self.found_change = True + on_finish = lambda: xreload_after_update() + + elif '__xreload_after_reload_update__' in namespace: + xreload_after_update = namespace['__xreload_after_reload_update__'] + self.found_change = True + on_finish = lambda: xreload_after_update(namespace) + + if on_finish is not None: + # If a client wants to know about it, give him a chance. + self._on_finish_callbacks.append(on_finish) + + def _update(self, namespace, name, oldobj, newobj, is_class_namespace=False): + """Update oldobj, if possible in place, with newobj. + + If oldobj is immutable, this simply returns newobj. + + Args: + oldobj: the object to be updated + newobj: the object used as the source for the update + """ + try: + notify_info2('Updating: ', oldobj) + if oldobj is newobj: + # Probably something imported + return + + if type(oldobj) is not type(newobj): + # Cop-out: if the type changed, give up + notify_error('Type of: %s changed... Skipping.' % (oldobj,)) + return + + if isinstance(newobj, types.FunctionType): + self._update_function(oldobj, newobj) + return + + if isinstance(newobj, types.MethodType): + self._update_method(oldobj, newobj) + return + + if isinstance(newobj, classmethod): + self._update_classmethod(oldobj, newobj) + return + + if isinstance(newobj, staticmethod): + self._update_staticmethod(oldobj, newobj) + return + + if hasattr(types, 'ClassType'): + classtype = (types.ClassType, type) # object is not instance of types.ClassType. + else: + classtype = type + + if isinstance(newobj, classtype): + self._update_class(oldobj, newobj) + return + + # New: dealing with metaclasses. + if hasattr(newobj, '__metaclass__') and hasattr(newobj, '__class__') and newobj.__metaclass__ == newobj.__class__: + self._update_class(oldobj, newobj) + return + + if namespace is not None: + + if oldobj != newobj and str(oldobj) != str(newobj) and repr(oldobj) != repr(newobj): + xreload_old_new = None + if is_class_namespace: + xreload_old_new = getattr(namespace, '__xreload_old_new__', None) + if xreload_old_new is not None: + self.found_change = True + xreload_old_new(name, oldobj, newobj) + + elif '__xreload_old_new__' in namespace: + xreload_old_new = namespace['__xreload_old_new__'] + xreload_old_new(namespace, name, oldobj, newobj) + self.found_change = True + + # Too much information to the user... + # else: + # notify_info0('%s NOT updated. Create __xreload_old_new__(name, old, new) for custom reload' % (name,)) + + except: + notify_error('Exception found when updating %s. Proceeding for other items.' % (name,)) + pydev_log.exception() + + # All of the following functions have the same signature as _update() + + def _update_function(self, oldfunc, newfunc): + """Update a function object.""" + oldfunc.__doc__ = newfunc.__doc__ + oldfunc.__dict__.update(newfunc.__dict__) + + try: + newfunc.__code__ + attr_name = '__code__' + except AttributeError: + newfunc.func_code + attr_name = 'func_code' + + old_code = getattr(oldfunc, attr_name) + new_code = getattr(newfunc, attr_name) + if not code_objects_equal(old_code, new_code): + notify_info0('Updated function code:', oldfunc) + setattr(oldfunc, attr_name, new_code) + self.found_change = True + + try: + oldfunc.__defaults__ = newfunc.__defaults__ + except AttributeError: + oldfunc.func_defaults = newfunc.func_defaults + + return oldfunc + + def _update_method(self, oldmeth, newmeth): + """Update a method object.""" + # XXX What if im_func is not a function? + if hasattr(oldmeth, 'im_func') and hasattr(newmeth, 'im_func'): + self._update(None, None, oldmeth.im_func, newmeth.im_func) + elif hasattr(oldmeth, '__func__') and hasattr(newmeth, '__func__'): + self._update(None, None, oldmeth.__func__, newmeth.__func__) + return oldmeth + + def _update_class(self, oldclass, newclass): + """Update a class object.""" + olddict = oldclass.__dict__ + newdict = newclass.__dict__ + + oldnames = set(olddict) + newnames = set(newdict) + + for name in newnames - oldnames: + setattr(oldclass, name, newdict[name]) + notify_info0('Added:', name, 'to', oldclass) + self.found_change = True + + # Note: not removing old things... + # for name in oldnames - newnames: + # notify_info('Removed:', name, 'from', oldclass) + # delattr(oldclass, name) + + for name in (oldnames & newnames) - set(['__dict__', '__doc__']): + self._update(oldclass, name, olddict[name], newdict[name], is_class_namespace=True) + + old_bases = getattr(oldclass, '__bases__', None) + new_bases = getattr(newclass, '__bases__', None) + if str(old_bases) != str(new_bases): + notify_error('Changing the hierarchy of a class is not supported. %s may be inconsistent.' % (oldclass,)) + + self._handle_namespace(oldclass, is_class_namespace=True) + + def _update_classmethod(self, oldcm, newcm): + """Update a classmethod update.""" + # While we can't modify the classmethod object itself (it has no + # mutable attributes), we *can* extract the underlying function + # (by calling __get__(), which returns a method object) and update + # it in-place. We don't have the class available to pass to + # __get__() but any object except None will do. + self._update(None, None, oldcm.__get__(0), newcm.__get__(0)) + + def _update_staticmethod(self, oldsm, newsm): + """Update a staticmethod update.""" + # While we can't modify the staticmethod object itself (it has no + # mutable attributes), we *can* extract the underlying function + # (by calling __get__(), which returns it) and update it in-place. + # We don't have the class available to pass to __get__() but any + # object except None will do. + self._update(None, None, oldsm.__get__(0), newsm.__get__(0)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_resolver.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_resolver.py new file mode 100644 index 0000000..cd4cb83 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_resolver.py @@ -0,0 +1,644 @@ +from _pydev_bundle import pydev_log +try: + import StringIO +except: + import io as StringIO +import traceback +from os.path import basename + +from functools import partial +from _pydevd_bundle.pydevd_constants import dict_iter_items, dict_keys, xrange +from _pydevd_bundle.pydevd_safe_repr import SafeRepr + +# Note: 300 is already a lot to see in the outline (after that the user should really use the shell to get things) +# and this also means we'll pass less information to the client side (which makes debugging faster). +MAX_ITEMS_TO_HANDLE = 300 + +TOO_LARGE_MSG = 'Too large to show contents. Max items to show: ' + str(MAX_ITEMS_TO_HANDLE) +TOO_LARGE_ATTR = 'Unable to handle:' + + +#======================================================================================================================= +# UnableToResolveVariableException +#======================================================================================================================= +class UnableToResolveVariableException(Exception): + pass + + +#======================================================================================================================= +# InspectStub +#======================================================================================================================= +class InspectStub: + + def isbuiltin(self, _args): + return False + + def isroutine(self, object): + return False + + +try: + import inspect +except: + inspect = InspectStub() + +try: + from collections import OrderedDict +except: + OrderedDict = dict + +try: + import java.lang # @UnresolvedImport +except: + pass + +# types does not include a MethodWrapperType +try: + MethodWrapperType = type([].__str__) +except: + MethodWrapperType = None + +#======================================================================================================================= +# See: pydevd_extension_api module for resolver interface +#======================================================================================================================= + + +def sorted_attributes_key(attr_name): + if attr_name.startswith('__'): + if attr_name.endswith('__'): + # __ double under before and after __ + return (3, attr_name) + else: + # __ double under before + return (2, attr_name) + elif attr_name.startswith('_'): + # _ single under + return (1, attr_name) + else: + # Regular (Before anything) + return (0, attr_name) + + +#======================================================================================================================= +# DefaultResolver +#======================================================================================================================= +class DefaultResolver: + ''' + DefaultResolver is the class that'll actually resolve how to show some variable. + ''' + + def resolve(self, var, attribute): + return getattr(var, attribute) + + def get_contents_debug_adapter_protocol(self, obj, fmt=None): + if MethodWrapperType: + dct, used___dict__ = self._get_py_dictionary(obj) + else: + dct = self._get_jy_dictionary(obj)[0] + + lst = sorted(dict_iter_items(dct), key=lambda tup: sorted_attributes_key(tup[0])) + if used___dict__: + return [(attr_name, attr_value, '.__dict__[%s]' % attr_name) for (attr_name, attr_value) in lst] + else: + return [(attr_name, attr_value, '.%s' % attr_name) for (attr_name, attr_value) in lst] + + def get_dictionary(self, var, names=None, used___dict__=False): + if MethodWrapperType: + return self._get_py_dictionary(var, names, used___dict__=used___dict__)[0] + else: + return self._get_jy_dictionary(var)[0] + + def _get_jy_dictionary(self, obj): + ret = {} + found = java.util.HashMap() + + original = obj + if hasattr(obj, '__class__') and obj.__class__ == java.lang.Class: + + # get info about superclasses + classes = [] + classes.append(obj) + c = obj.getSuperclass() + while c != None: + classes.append(c) + c = c.getSuperclass() + + # get info about interfaces + interfs = [] + for obj in classes: + interfs.extend(obj.getInterfaces()) + classes.extend(interfs) + + # now is the time when we actually get info on the declared methods and fields + for obj in classes: + + declaredMethods = obj.getDeclaredMethods() + declaredFields = obj.getDeclaredFields() + for i in xrange(len(declaredMethods)): + name = declaredMethods[i].getName() + ret[name] = declaredMethods[i].toString() + found.put(name, 1) + + for i in xrange(len(declaredFields)): + name = declaredFields[i].getName() + found.put(name, 1) + # if declaredFields[i].isAccessible(): + declaredFields[i].setAccessible(True) + # ret[name] = declaredFields[i].get( declaredFields[i] ) + try: + ret[name] = declaredFields[i].get(original) + except: + ret[name] = declaredFields[i].toString() + + # this simple dir does not always get all the info, that's why we have the part before + # (e.g.: if we do a dir on String, some methods that are from other interfaces such as + # charAt don't appear) + try: + d = dir(original) + for name in d: + if found.get(name) != 1: + ret[name] = getattr(original, name) + except: + # sometimes we're unable to do a dir + pass + + return ret + + def get_names(self, var): + used___dict__ = False + try: + names = dir(var) + except TypeError: + names = [] + if not names: + if hasattr(var, '__dict__'): + names = dict_keys(var.__dict__) + used___dict__ = True + return names, used___dict__ + + def _get_py_dictionary(self, var, names=None, used___dict__=False): + ''' + :return tuple(names, used___dict__), where used___dict__ means we have to access + using obj.__dict__[name] instead of getattr(obj, name) + ''' + + # TODO: Those should be options (would fix https://github.com/Microsoft/ptvsd/issues/66). + filter_private = False + filter_special = True + filter_function = True + filter_builtin = True + + if not names: + names, used___dict__ = self.get_names(var) + d = {} + + # Be aware that the order in which the filters are applied attempts to + # optimize the operation by removing as many items as possible in the + # first filters, leaving fewer items for later filters + + if filter_builtin or filter_function: + for name in names: + try: + name_as_str = name + if name_as_str.__class__ != str: + name_as_str = '%r' % (name_as_str,) + + if filter_special: + if name_as_str.startswith('__') and name_as_str.endswith('__'): + continue + + if filter_private: + if name_as_str.startswith('_') or name_as_str.endswith('__'): + continue + if not used___dict__: + attr = getattr(var, name) + else: + attr = var.__dict__[name] + + # filter builtins? + if filter_builtin: + if inspect.isbuiltin(attr): + continue + + # filter functions? + if filter_function: + if inspect.isroutine(attr) or isinstance(attr, MethodWrapperType): + continue + except: + # if some error occurs getting it, let's put it to the user. + strIO = StringIO.StringIO() + traceback.print_exc(file=strIO) + attr = strIO.getvalue() + + d[name_as_str] = attr + + return d, used___dict__ + + +#======================================================================================================================= +# DictResolver +#======================================================================================================================= +class DictResolver: + + def resolve(self, dict, key): + if key in ('__len__', TOO_LARGE_ATTR): + return None + + if '(' not in key: + # we have to treat that because the dict resolver is also used to directly resolve the global and local + # scopes (which already have the items directly) + try: + return dict[key] + except: + return getattr(dict, key) + + # ok, we have to iterate over the items to find the one that matches the id, because that's the only way + # to actually find the reference from the string we have before. + expected_id = int(key.split('(')[-1][:-1]) + for key, val in dict_iter_items(dict): + if id(key) == expected_id: + return val + + raise UnableToResolveVariableException() + + def key_to_str(self, key, fmt=None): + if fmt is not None: + if fmt.get('hex', False): + safe_repr = SafeRepr() + safe_repr.convert_to_hex = True + return safe_repr(key) + return '%r' % (key,) + + def init_dict(self): + return {} + + def get_contents_debug_adapter_protocol(self, dct, fmt=None): + ''' + This method is to be used in the case where the variables are all saved by its id (and as + such don't need to have the `resolve` method called later on, so, keys don't need to + embed the reference in the key). + + Note that the return should be ordered. + + :return list(tuple(name:str, value:object, evaluateName:str)) + ''' + ret = [] + + i = 0 + for key, val in dict_iter_items(dct): + i += 1 + key_as_str = self.key_to_str(key, fmt) + eval_key_str = self.key_to_str(key) # do not format the key + ret.append((key_as_str, val, '[%s]' % (eval_key_str,))) + if i > MAX_ITEMS_TO_HANDLE: + ret.append((TOO_LARGE_ATTR, TOO_LARGE_MSG, None)) + break + + ret.append(('__len__', len(dct), partial(_apply_evaluate_name, evaluate_name='len(%s)'))) + # in case the class extends built-in type and has some additional fields + from_default_resolver = defaultResolver.get_contents_debug_adapter_protocol(dct, fmt) + + if from_default_resolver: + ret = from_default_resolver + ret + + return sorted(ret, key=lambda tup: sorted_attributes_key(tup[0])) + + def get_dictionary(self, dict): + ret = self.init_dict() + + i = 0 + for key, val in dict_iter_items(dict): + i += 1 + # we need to add the id because otherwise we cannot find the real object to get its contents later on. + key = '%s (%s)' % (self.key_to_str(key), id(key)) + ret[key] = val + if i > MAX_ITEMS_TO_HANDLE: + ret[TOO_LARGE_ATTR] = TOO_LARGE_MSG + break + + ret['__len__'] = len(dict) + # in case if the class extends built-in type and has some additional fields + additional_fields = defaultResolver.get_dictionary(dict) + ret.update(additional_fields) + return ret + + +def _apply_evaluate_name(parent_name, evaluate_name): + return evaluate_name % (parent_name,) + + +#======================================================================================================================= +# TupleResolver +#======================================================================================================================= +class TupleResolver: # to enumerate tuples and lists + + def resolve(self, var, attribute): + ''' + @param var: that's the original attribute + @param attribute: that's the key passed in the dict (as a string) + ''' + if attribute in ('__len__', TOO_LARGE_ATTR): + return None + try: + return var[int(attribute)] + except: + return getattr(var, attribute) + + def get_contents_debug_adapter_protocol(self, lst, fmt=None): + ''' + This method is to be used in the case where the variables are all saved by its id (and as + such don't need to have the `resolve` method called later on, so, keys don't need to + embed the reference in the key). + + Note that the return should be ordered. + + :return list(tuple(name:str, value:object, evaluateName:str)) + ''' + l = len(lst) + ret = [] + + format_str = '%0' + str(int(len(str(l - 1)))) + 'd' + if fmt is not None and fmt.get('hex', False): + format_str = '0x%0' + str(int(len(hex(l).lstrip('0x')))) + 'x' + + for i, item in enumerate(lst): + ret.append((format_str % i, item, '[%s]' % i)) + + if i > MAX_ITEMS_TO_HANDLE: + ret.append((TOO_LARGE_ATTR, TOO_LARGE_MSG, None)) + break + + ret.append(('__len__', len(lst), partial(_apply_evaluate_name, evaluate_name='len(%s)'))) + # Needed in case the class extends the built-in type and has some additional fields. + from_default_resolver = defaultResolver.get_contents_debug_adapter_protocol(lst, fmt=fmt) + if from_default_resolver: + ret = from_default_resolver + ret + return ret + + def get_dictionary(self, var, fmt={}): + l = len(var) + d = {} + + format_str = '%0' + str(int(len(str(l - 1)))) + 'd' + if fmt is not None and fmt.get('hex', False): + format_str = '0x%0' + str(int(len(hex(l).lstrip('0x')))) + 'x' + + for i, item in enumerate(var): + d[format_str % i] = item + + if i > MAX_ITEMS_TO_HANDLE: + d[TOO_LARGE_ATTR] = TOO_LARGE_MSG + break + + d['__len__'] = len(var) + # in case if the class extends built-in type and has some additional fields + additional_fields = defaultResolver.get_dictionary(var) + d.update(additional_fields) + return d + + +#======================================================================================================================= +# SetResolver +#======================================================================================================================= +class SetResolver: + ''' + Resolves a set as dict id(object)->object + ''' + + def get_contents_debug_adapter_protocol(self, obj, fmt=None): + ret = [] + + for i, item in enumerate(obj): + ret.append((str(id(item)), item, None)) + + if i > MAX_ITEMS_TO_HANDLE: + ret.append((TOO_LARGE_ATTR, TOO_LARGE_MSG, None)) + break + + ret.append(('__len__', len(obj), partial(_apply_evaluate_name, evaluate_name='len(%s)'))) + # Needed in case the class extends the built-in type and has some additional fields. + from_default_resolver = defaultResolver.get_contents_debug_adapter_protocol(obj, fmt=fmt) + if from_default_resolver: + ret = from_default_resolver + ret + return ret + + def resolve(self, var, attribute): + if attribute in ('__len__', TOO_LARGE_ATTR): + return None + + try: + attribute = int(attribute) + except: + return getattr(var, attribute) + + for v in var: + if id(v) == attribute: + return v + + raise UnableToResolveVariableException('Unable to resolve %s in %s' % (attribute, var)) + + def get_dictionary(self, var): + d = {} + for i, item in enumerate(var): + d[str(id(item))] = item + + if i > MAX_ITEMS_TO_HANDLE: + d[TOO_LARGE_ATTR] = TOO_LARGE_MSG + break + + d['__len__'] = len(var) + # in case if the class extends built-in type and has some additional fields + additional_fields = defaultResolver.get_dictionary(var) + d.update(additional_fields) + return d + + def change_var_from_name(self, container, name, new_value): + # The name given in this case must be the id(item), so, we can actually + # iterate in the set and see which item matches the given id. + + try: + # Check that the new value can actually be added to a set (i.e.: it's hashable/comparable). + set().add(new_value) + except: + return None + + for item in container: + if str(id(item)) == name: + container.remove(item) + container.add(new_value) + return str(id(new_value)) + + return None + + +#======================================================================================================================= +# InstanceResolver +#======================================================================================================================= +class InstanceResolver: + + def resolve(self, var, attribute): + field = var.__class__.getDeclaredField(attribute) + field.setAccessible(True) + return field.get(var) + + def get_dictionary(self, obj): + ret = {} + + declaredFields = obj.__class__.getDeclaredFields() + for i in xrange(len(declaredFields)): + name = declaredFields[i].getName() + try: + declaredFields[i].setAccessible(True) + ret[name] = declaredFields[i].get(obj) + except: + pydev_log.exception() + + return ret + + +#======================================================================================================================= +# JyArrayResolver +#======================================================================================================================= +class JyArrayResolver: + ''' + This resolves a regular Object[] array from java + ''' + + def resolve(self, var, attribute): + if attribute == '__len__': + return None + return var[int(attribute)] + + def get_dictionary(self, obj): + ret = {} + + for i in xrange(len(obj)): + ret[ i ] = obj[i] + + ret['__len__'] = len(obj) + return ret + + +#======================================================================================================================= +# MultiValueDictResolver +#======================================================================================================================= +class MultiValueDictResolver(DictResolver): + + def resolve(self, dict, key): + if key in ('__len__', TOO_LARGE_ATTR): + return None + + # ok, we have to iterate over the items to find the one that matches the id, because that's the only way + # to actually find the reference from the string we have before. + expected_id = int(key.split('(')[-1][:-1]) + for key in dict_keys(dict): + val = dict.getlist(key) + if id(key) == expected_id: + return val + + raise UnableToResolveVariableException() + + +#======================================================================================================================= +# DjangoFormResolver +#======================================================================================================================= +class DjangoFormResolver(DefaultResolver): + + def get_dictionary(self, var, names=None): + # Do not call self.errors because it is a property and has side effects. + names, used___dict__ = self.get_names(var) + + has_errors_attr = False + if "errors" in names: + has_errors_attr = True + names.remove("errors") + + d = defaultResolver.get_dictionary(var, names=names, used___dict__=used___dict__) + if has_errors_attr: + try: + errors_attr = getattr(var, "_errors") + except: + errors_attr = None + d["errors"] = errors_attr + return d + + +#======================================================================================================================= +# DequeResolver +#======================================================================================================================= +class DequeResolver(TupleResolver): + + def get_dictionary(self, var): + d = TupleResolver.get_dictionary(self, var) + d['maxlen'] = getattr(var, 'maxlen', None) + return d + + +#======================================================================================================================= +# OrderedDictResolver +#======================================================================================================================= +class OrderedDictResolver(DictResolver): + + def init_dict(self): + return OrderedDict() + + +#======================================================================================================================= +# FrameResolver +#======================================================================================================================= +class FrameResolver: + ''' + This resolves a frame. + ''' + + def resolve(self, obj, attribute): + if attribute == '__internals__': + return defaultResolver.get_dictionary(obj) + + if attribute == 'stack': + return self.get_frame_stack(obj) + + if attribute == 'f_locals': + return obj.f_locals + + return None + + def get_dictionary(self, obj): + ret = {} + ret['__internals__'] = defaultResolver.get_dictionary(obj) + ret['stack'] = self.get_frame_stack(obj) + ret['f_locals'] = obj.f_locals + return ret + + def get_frame_stack(self, frame): + ret = [] + if frame is not None: + ret.append(self.get_frame_name(frame)) + + while frame.f_back: + frame = frame.f_back + ret.append(self.get_frame_name(frame)) + + return ret + + def get_frame_name(self, frame): + if frame is None: + return 'None' + try: + name = basename(frame.f_code.co_filename) + return 'frame: %s [%s:%s] id:%s' % (frame.f_code.co_name, name, frame.f_lineno, id(frame)) + except: + return 'frame object' + + +defaultResolver = DefaultResolver() +dictResolver = DictResolver() +tupleResolver = TupleResolver() +instanceResolver = InstanceResolver() +jyArrayResolver = JyArrayResolver() +setResolver = SetResolver() +multiValueDictResolver = MultiValueDictResolver() +djangoFormResolver = DjangoFormResolver() +dequeResolver = DequeResolver() +orderedDictResolver = OrderedDictResolver() +frameResolver = FrameResolver() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_safe_repr.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_safe_repr.py new file mode 100644 index 0000000..512be7f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_safe_repr.py @@ -0,0 +1,406 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +# Gotten from ptvsd for supporting the format expected there. +import sys +from _pydevd_bundle.pydevd_constants import IS_PY2 +import locale +import json + +# Py3 compat - alias unicode to str, and xrange to range +try: + unicode # noqa +except NameError: + unicode = str +try: + xrange # noqa +except NameError: + xrange = range + + +class SafeRepr(object): + # Can be used to override the encoding from locale.getpreferredencoding() + locale_preferred_encoding = None + + # Can be used to override the encoding used for sys.stdout.encoding + sys_stdout_encoding = None + + # String types are truncated to maxstring_outer when at the outer- + # most level, and truncated to maxstring_inner characters inside + # collections. + maxstring_outer = 2 ** 16 + maxstring_inner = 30 + if sys.version_info >= (3, 0): + string_types = (str, bytes) + set_info = (set, '{', '}', False) + frozenset_info = (frozenset, 'frozenset({', '})', False) + int_types = (int,) + long_iter_types = (list, tuple, bytearray, range, + dict, set, frozenset) + else: + string_types = (str, unicode) + set_info = (set, 'set([', '])', False) + frozenset_info = (frozenset, 'frozenset([', '])', False) + int_types = (int, long) # noqa + long_iter_types = (list, tuple, bytearray, xrange, + dict, set, frozenset, buffer) # noqa + + # Collection types are recursively iterated for each limit in + # maxcollection. + maxcollection = (15, 10) + + # Specifies type, prefix string, suffix string, and whether to include a + # comma if there is only one element. (Using a sequence rather than a + # mapping because we use isinstance() to determine the matching type.) + collection_types = [ + (tuple, '(', ')', True), + (list, '[', ']', False), + frozenset_info, + set_info, + ] + try: + from collections import deque + collection_types.append((deque, 'deque([', '])', False)) + except Exception: + pass + + # type, prefix string, suffix string, item prefix string, + # item key/value separator, item suffix string + dict_types = [(dict, '{', '}', '', ': ', '')] + try: + from collections import OrderedDict + dict_types.append((OrderedDict, 'OrderedDict([', '])', '(', ', ', ')')) + except Exception: + pass + + # All other types are treated identically to strings, but using + # different limits. + maxother_outer = 2 ** 16 + maxother_inner = 30 + + convert_to_hex = False + raw_value = False + + def __call__(self, obj): + ''' + :param object obj: + The object for which we want a representation. + + :return str: + Returns bytes encoded as utf-8 on py2 and str on py3. + ''' + try: + if IS_PY2: + return ''.join((x.encode('utf-8') if isinstance(x, unicode) else x) for x in self._repr(obj, 0)) + else: + return ''.join(self._repr(obj, 0)) + except Exception: + try: + return 'An exception was raised: %r' % sys.exc_info()[1] + except Exception: + return 'An exception was raised' + + def _repr(self, obj, level): + '''Returns an iterable of the parts in the final repr string.''' + + try: + obj_repr = type(obj).__repr__ + except Exception: + obj_repr = None + + def has_obj_repr(t): + r = t.__repr__ + try: + return obj_repr == r + except Exception: + return obj_repr is r + + for t, prefix, suffix, comma in self.collection_types: + if isinstance(obj, t) and has_obj_repr(t): + return self._repr_iter(obj, level, prefix, suffix, comma) + + for t, prefix, suffix, item_prefix, item_sep, item_suffix in self.dict_types: # noqa + if isinstance(obj, t) and has_obj_repr(t): + return self._repr_dict(obj, level, prefix, suffix, + item_prefix, item_sep, item_suffix) + + for t in self.string_types: + if isinstance(obj, t) and has_obj_repr(t): + return self._repr_str(obj, level) + + if self._is_long_iter(obj): + return self._repr_long_iter(obj) + + return self._repr_other(obj, level) + + # Determines whether an iterable exceeds the limits set in + # maxlimits, and is therefore unsafe to repr(). + def _is_long_iter(self, obj, level=0): + try: + # Strings have their own limits (and do not nest). Because + # they don't have __iter__ in 2.x, this check goes before + # the next one. + if isinstance(obj, self.string_types): + return len(obj) > self.maxstring_inner + + # If it's not an iterable (and not a string), it's fine. + if not hasattr(obj, '__iter__'): + return False + + # If it's not an instance of these collection types then it + # is fine. Note: this is a fix for + # https://github.com/Microsoft/ptvsd/issues/406 + if not isinstance(obj, self.long_iter_types): + return False + + # Iterable is its own iterator - this is a one-off iterable + # like generator or enumerate(). We can't really count that, + # but repr() for these should not include any elements anyway, + # so we can treat it the same as non-iterables. + if obj is iter(obj): + return False + + # xrange reprs fine regardless of length. + if isinstance(obj, xrange): + return False + + # numpy and scipy collections (ndarray etc) have + # self-truncating repr, so they're always safe. + try: + module = type(obj).__module__.partition('.')[0] + if module in ('numpy', 'scipy'): + return False + except Exception: + pass + + # Iterables that nest too deep are considered long. + if level >= len(self.maxcollection): + return True + + # It is too long if the length exceeds the limit, or any + # of its elements are long iterables. + if hasattr(obj, '__len__'): + try: + size = len(obj) + except Exception: + size = None + if size is not None and size > self.maxcollection[level]: + return True + return any((self._is_long_iter(item, level + 1) for item in obj)) # noqa + return any(i > self.maxcollection[level] or self._is_long_iter(item, level + 1) for i, item in enumerate(obj)) # noqa + + except Exception: + # If anything breaks, assume the worst case. + return True + + def _repr_iter(self, obj, level, prefix, suffix, + comma_after_single_element=False): + yield prefix + + if level >= len(self.maxcollection): + yield '...' + else: + count = self.maxcollection[level] + yield_comma = False + for item in obj: + if yield_comma: + yield ', ' + yield_comma = True + + count -= 1 + if count <= 0: + yield '...' + break + + for p in self._repr(item, 100 if item is obj else level + 1): + yield p + else: + if comma_after_single_element: + if count == self.maxcollection[level] - 1: + yield ',' + yield suffix + + def _repr_long_iter(self, obj): + try: + length = hex(len(obj)) if self.convert_to_hex else len(obj) + obj_repr = '<%s, len() = %s>' % (type(obj).__name__, length) + except Exception: + try: + obj_repr = '<' + type(obj).__name__ + '>' + except Exception: + obj_repr = '' + yield obj_repr + + def _repr_dict(self, obj, level, prefix, suffix, + item_prefix, item_sep, item_suffix): + if not obj: + yield prefix + suffix + return + if level >= len(self.maxcollection): + yield prefix + '...' + suffix + return + + yield prefix + + count = self.maxcollection[level] + yield_comma = False + + try: + sorted_keys = sorted(obj) + except Exception: + sorted_keys = list(obj) + + for key in sorted_keys: + if yield_comma: + yield ', ' + yield_comma = True + + count -= 1 + if count <= 0: + yield '...' + break + + yield item_prefix + for p in self._repr(key, level + 1): + yield p + + yield item_sep + + try: + item = obj[key] + except Exception: + yield '' + else: + for p in self._repr(item, 100 if item is obj else level + 1): + yield p + yield item_suffix + + yield suffix + + def _repr_str(self, obj, level): + return self._repr_obj(obj, level, + self.maxstring_inner, self.maxstring_outer) + + def _repr_other(self, obj, level): + return self._repr_obj(obj, level, + self.maxother_inner, self.maxother_outer) + + def _repr_obj(self, obj, level, limit_inner, limit_outer): + try: + if self.raw_value: + # For raw value retrieval, ignore all limits. + if isinstance(obj, bytes): + yield obj.decode('latin-1') + return + + try: + mv = memoryview(obj) + except Exception: + yield self._convert_to_unicode_or_bytes_repr(repr(obj)) + return + else: + # Map bytes to Unicode codepoints with same values. + yield mv.tobytes().decode('latin-1') + return + elif self.convert_to_hex and isinstance(obj, self.int_types): + obj_repr = hex(obj) + else: + obj_repr = repr(obj) + except Exception: + try: + obj_repr = object.__repr__(obj) + except Exception: + try: + obj_repr = '' # noqa + except Exception: + obj_repr = '' + + limit = limit_inner if level > 0 else limit_outer + + if limit >= len(obj_repr): + yield self._convert_to_unicode_or_bytes_repr(obj_repr) + return + + # Slightly imprecise calculations - we may end up with a string that is + # up to 3 characters longer than limit. If you need precise formatting, + # you are using the wrong class. + left_count, right_count = max(1, int(2 * limit / 3)), max(1, int(limit / 3)) # noqa + + if IS_PY2 and isinstance(obj_repr, bytes): + # If we can convert to unicode before slicing, that's better (but don't do + # it if it's not possible as we may be dealing with actual binary data). + + obj_repr = self._bytes_as_unicode_if_possible(obj_repr) + if isinstance(obj_repr, unicode): + # Deal with high-surrogate leftovers on Python 2. + try: + if left_count > 0 and unichr(0xD800) <= obj_repr[left_count - 1] <= unichr(0xDBFF): + left_count -= 1 + except ValueError: + # On Jython unichr(0xD800) will throw an error: + # ValueError: unichr() arg is a lone surrogate in range (0xD800, 0xDFFF) (Jython UTF-16 encoding) + # Just ignore it in this case. + pass + + start = obj_repr[:left_count] + + # Note: yielding unicode is fine (it'll be properly converted to utf-8 if needed). + yield start + yield '...' + + # Deal with high-surrogate leftovers on Python 2. + try: + if right_count > 0 and unichr(0xD800) <= obj_repr[-right_count - 1] <= unichr(0xDBFF): + right_count -= 1 + except ValueError: + # On Jython unichr(0xD800) will throw an error: + # ValueError: unichr() arg is a lone surrogate in range (0xD800, 0xDFFF) (Jython UTF-16 encoding) + # Just ignore it in this case. + pass + + yield obj_repr[-right_count:] + return + else: + # We can't decode it (binary string). Use repr() of bytes. + obj_repr = repr(obj_repr) + + yield obj_repr[:left_count] + yield '...' + yield obj_repr[-right_count:] + + def _convert_to_unicode_or_bytes_repr(self, obj_repr): + if IS_PY2 and isinstance(obj_repr, bytes): + obj_repr = self._bytes_as_unicode_if_possible(obj_repr) + if isinstance(obj_repr, bytes): + # If we haven't been able to decode it this means it's some binary data + # we can't make sense of, so, we need its repr() -- otherwise json + # encoding may break later on. + obj_repr = repr(obj_repr) + return obj_repr + + def _bytes_as_unicode_if_possible(self, obj_repr): + # We try to decode with 3 possible encoding (sys.stdout.encoding, + # locale.getpreferredencoding() and 'utf-8). If no encoding can decode + # the input, we return the original bytes. + try_encodings = [] + encoding = self.sys_stdout_encoding or getattr(sys.stdout, 'encoding', '') + if encoding: + try_encodings.append(encoding.lower()) + + preferred_encoding = self.locale_preferred_encoding or locale.getpreferredencoding() + if preferred_encoding: + preferred_encoding = preferred_encoding.lower() + if preferred_encoding not in try_encodings: + try_encodings.append(preferred_encoding) + + if 'utf-8' not in try_encodings: + try_encodings.append('utf-8') + + for encoding in try_encodings: + try: + return obj_repr.decode(encoding) + except UnicodeDecodeError: + pass + + return obj_repr # Return the original version (in bytes) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_save_locals.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_save_locals.py new file mode 100644 index 0000000..3c6b0d6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_save_locals.py @@ -0,0 +1,69 @@ +""" +Utility for saving locals. +""" +import sys + +try: + import types + + frame_type = types.FrameType +except: + frame_type = type(sys._getframe()) + + +def is_save_locals_available(): + return save_locals_impl is not None + + +def save_locals(frame): + """ + Copy values from locals_dict into the fast stack slots in the given frame. + + Note: the 'save_locals' branch had a different approach wrapping the frame (much more code, but it gives ideas + on how to save things partially, not the 'whole' locals). + """ + if not isinstance(frame, frame_type): + # Fix exception when changing Django variable (receiving DjangoTemplateFrame) + return + + if save_locals_impl is not None: + try: + save_locals_impl(frame) + except: + pass + + +def make_save_locals_impl(): + """ + Factory for the 'save_locals_impl' method. This may seem like a complicated pattern but it is essential that the method is created at + module load time. Inner imports after module load time would cause an occasional debugger deadlock due to the importer lock and debugger + lock being taken in different order in different threads. + """ + try: + if '__pypy__' in sys.builtin_module_names: + import __pypy__ # @UnresolvedImport + save_locals = __pypy__.locals_to_fast + except: + pass + else: + if '__pypy__' in sys.builtin_module_names: + def save_locals_pypy_impl(frame): + save_locals(frame) + + return save_locals_pypy_impl + + try: + import ctypes + locals_to_fast = ctypes.pythonapi.PyFrame_LocalsToFast + except: + pass + else: + def save_locals_ctypes_impl(frame): + locals_to_fast(ctypes.py_object(frame), ctypes.c_int(0)) + + return save_locals_ctypes_impl + + return None + + +save_locals_impl = make_save_locals_impl() diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_signature.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_signature.py new file mode 100644 index 0000000..dc1c984 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_signature.py @@ -0,0 +1,202 @@ +from _pydev_bundle import pydev_log + +try: + import trace +except ImportError: + pass +else: + trace._warn = lambda *args: None # workaround for http://bugs.python.org/issue17143 (PY-8706) + +import os +from _pydevd_bundle.pydevd_comm import CMD_SIGNATURE_CALL_TRACE, NetCommand +from _pydevd_bundle import pydevd_xml +from _pydevd_bundle.pydevd_constants import xrange, dict_iter_items +from _pydevd_bundle.pydevd_utils import get_clsname_for_code + + +class Signature(object): + + def __init__(self, file, name): + self.file = file + self.name = name + self.args = [] + self.args_str = [] + self.return_type = None + + def add_arg(self, name, type): + self.args.append((name, type)) + self.args_str.append("%s:%s" % (name, type)) + + def set_args(self, frame, recursive=False): + self.args = [] + + code = frame.f_code + locals = frame.f_locals + + for i in xrange(0, code.co_argcount): + name = code.co_varnames[i] + class_name = get_type_of_value(locals[name], recursive=recursive) + + self.add_arg(name, class_name) + + def __str__(self): + return "%s %s(%s)" % (self.file, self.name, ", ".join(self.args_str)) + + +def get_type_of_value(value, ignore_module_name=('__main__', '__builtin__', 'builtins'), recursive=False): + tp = type(value) + class_name = tp.__name__ + if class_name == 'instance': # old-style classes + tp = value.__class__ + class_name = tp.__name__ + + if hasattr(tp, '__module__') and tp.__module__ and tp.__module__ not in ignore_module_name: + class_name = "%s.%s" % (tp.__module__, class_name) + + if class_name == 'list': + class_name = 'List' + if len(value) > 0 and recursive: + class_name += '[%s]' % get_type_of_value(value[0], recursive=recursive) + return class_name + + if class_name == 'dict': + class_name = 'Dict' + if len(value) > 0 and recursive: + for (k, v) in dict_iter_items(value): + class_name += '[%s, %s]' % (get_type_of_value(k, recursive=recursive), + get_type_of_value(v, recursive=recursive)) + break + return class_name + + if class_name == 'tuple': + class_name = 'Tuple' + if len(value) > 0 and recursive: + class_name += '[' + class_name += ', '.join(get_type_of_value(v, recursive=recursive) for v in value) + class_name += ']' + + return class_name + + +def _modname(path): + """Return a plausible module name for the path""" + base = os.path.basename(path) + filename, ext = os.path.splitext(base) + return filename + + +class SignatureFactory(object): + + def __init__(self): + self._caller_cache = {} + self.cache = CallSignatureCache() + + def create_signature(self, frame, filename, with_args=True): + try: + _, modulename, funcname = self.file_module_function_of(frame) + signature = Signature(filename, funcname) + if with_args: + signature.set_args(frame, recursive=True) + return signature + except: + pydev_log.exception() + + def file_module_function_of(self, frame): # this code is take from trace module and fixed to work with new-style classes + code = frame.f_code + filename = code.co_filename + if filename: + modulename = _modname(filename) + else: + modulename = None + + funcname = code.co_name + clsname = None + if code in self._caller_cache: + if self._caller_cache[code] is not None: + clsname = self._caller_cache[code] + else: + self._caller_cache[code] = None + clsname = get_clsname_for_code(code, frame) + if clsname is not None: + # cache the result - assumption is that new.* is + # not called later to disturb this relationship + # _caller_cache could be flushed if functions in + # the new module get called. + self._caller_cache[code] = clsname + + if clsname is not None: + funcname = "%s.%s" % (clsname, funcname) + + return filename, modulename, funcname + + +def get_signature_info(signature): + return signature.file, signature.name, ' '.join([arg[1] for arg in signature.args]) + + +def get_frame_info(frame): + co = frame.f_code + return co.co_name, frame.f_lineno, co.co_filename + + +class CallSignatureCache(object): + + def __init__(self): + self.cache = {} + + def add(self, signature): + filename, name, args_type = get_signature_info(signature) + calls_from_file = self.cache.setdefault(filename, {}) + name_calls = calls_from_file.setdefault(name, {}) + name_calls[args_type] = None + + def is_in_cache(self, signature): + filename, name, args_type = get_signature_info(signature) + if args_type in self.cache.get(filename, {}).get(name, {}): + return True + return False + + +def create_signature_message(signature): + cmdTextList = [""] + + cmdTextList.append('' % (pydevd_xml.make_valid_xml_value(signature.file), pydevd_xml.make_valid_xml_value(signature.name))) + + for arg in signature.args: + cmdTextList.append('' % (pydevd_xml.make_valid_xml_value(arg[0]), pydevd_xml.make_valid_xml_value(arg[1]))) + + if signature.return_type is not None: + cmdTextList.append('' % (pydevd_xml.make_valid_xml_value(signature.return_type))) + + cmdTextList.append("") + cmdText = ''.join(cmdTextList) + return NetCommand(CMD_SIGNATURE_CALL_TRACE, 0, cmdText) + + +def send_signature_call_trace(dbg, frame, filename): + if dbg.signature_factory and dbg.in_project_scope(frame): + signature = dbg.signature_factory.create_signature(frame, filename) + if signature is not None: + if dbg.signature_factory.cache is not None: + if not dbg.signature_factory.cache.is_in_cache(signature): + dbg.signature_factory.cache.add(signature) + dbg.writer.add_command(create_signature_message(signature)) + return True + else: + # we don't send signature if it is cached + return False + else: + dbg.writer.add_command(create_signature_message(signature)) + return True + return False + + +def send_signature_return_trace(dbg, frame, filename, return_value): + if dbg.signature_factory and dbg.in_project_scope(frame): + signature = dbg.signature_factory.create_signature(frame, filename, with_args=False) + signature.return_type = get_type_of_value(return_value, recursive=True) + dbg.writer.add_command(create_signature_message(signature)) + return True + + return False + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_source_mapping.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_source_mapping.py new file mode 100644 index 0000000..f0b634b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_source_mapping.py @@ -0,0 +1,130 @@ +import bisect +from _pydevd_bundle.pydevd_constants import dict_items + + +class SourceMappingEntry(object): + + __slots__ = ['source_filename', 'line', 'end_line', 'runtime_line', 'runtime_source'] + + def __init__(self, line, end_line, runtime_line, runtime_source): + assert isinstance(runtime_source, str) + + self.line = int(line) + self.end_line = int(end_line) + self.runtime_line = int(runtime_line) + self.runtime_source = runtime_source + self.source_filename = None # Should be set after translated to server. + + def contains_line(self, i): + return self.line <= i <= self.end_line + + def contains_runtime_line(self, i): + line_count = self.end_line + self.line + runtime_end_line = self.runtime_line + line_count + return self.runtime_line <= i <= runtime_end_line + + def __str__(self): + return 'SourceMappingEntry(%s)' % ( + ', '.join('%s=%r' % (attr, getattr(self, attr)) for attr in self.__slots__)) + + __repr__ = __str__ + + +class _KeyifyList(object): + + def __init__(self, inner, key): + self.inner = inner + self.key = key + + def __len__(self): + return len(self.inner) + + def __getitem__(self, k): + return self.key(self.inner[k]) + + +class SourceMapping(object): + + def __init__(self): + self._mappings_to_server = {} + self._mappings_to_client = {} + self._cache = {} + + def set_source_mapping(self, source_filename, mapping): + ''' + :param str source_filename: + The filename for the source mapping (bytes on py2 and str on py3). + Note: the source_filename must be already normalized to the server. + + :param list(SourceMappingEntry) mapping: + A list with the source mapping entries to be applied to the given filename. + + :return str: + An error message if it was not possible to set the mapping or an empty string if + everything is ok. + ''' + # Let's first validate if it's ok to apply that mapping. + # File mappings must be 1:N, not M:N (i.e.: if there's a mapping from file1.py to , + # there can be no other mapping from any other file to ). + # This is a limitation to make it easier to remove existing breakpoints when new breakpoints are + # set to a file (so, any file matching that breakpoint can be removed instead of needing to check + # which lines are corresponding to that file). + for map_entry in mapping: + existing_source_filename = self._mappings_to_client.get(map_entry.runtime_source) + if existing_source_filename and existing_source_filename != source_filename: + return 'Cannot apply mapping from %s to %s (it conflicts with mapping: %s to %s)' % ( + source_filename, map_entry.runtime_source, existing_source_filename, map_entry.runtime_source) + + current_mapping = self._mappings_to_server.get(source_filename, []) + for map_entry in current_mapping: + del self._mappings_to_client[map_entry.runtime_source] + + self._mappings_to_server[source_filename] = sorted(mapping, key=lambda entry:entry.line) + + for map_entry in mapping: + self._mappings_to_client[map_entry.runtime_source] = source_filename + + return '' + + def map_to_client(self, filename, lineno): + # Note: the filename must be normalized to the client after this point. + key = (filename, lineno, 'client') + try: + return self._cache[key] + except KeyError: + for source_filename, mapping in dict_items(self._mappings_to_server): + for map_entry in mapping: + if map_entry.runtime_source == filename: + if map_entry.contains_runtime_line(lineno): + return source_filename, map_entry.line + (lineno - map_entry.runtime_line), True + + return filename, lineno, False + + def map_to_server(self, filename, lineno): + # Note: the filename must be already normalized to the server at this point. + changed = False + mappings = self._mappings_to_server.get(filename) + if mappings: + + i = bisect.bisect(_KeyifyList(mappings, lambda entry:entry.line), lineno) + if i >= len(mappings): + i -= 1 + + if i == 0: + entry = mappings[i] + + elif i > 0: + entry = mappings[i - 1] + + if not entry.contains_line(lineno): + entry = mappings[i] + if not entry.contains_line(lineno): + entry = None + + if entry is not None: + lineno = entry.runtime_line + (lineno - entry.line) + + filename = entry.runtime_source + changed = True + + return filename, lineno, changed diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_stackless.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_stackless.py new file mode 100644 index 0000000..66e49bf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_stackless.py @@ -0,0 +1,414 @@ +from __future__ import nested_scopes + +import weakref +import sys + +from _pydevd_bundle.pydevd_comm import get_global_debugger +from _pydevd_bundle.pydevd_constants import call_only_once +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import dict_items +from _pydevd_bundle.pydevd_custom_frames import update_custom_frame, remove_custom_frame, add_custom_frame +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame +import stackless # @UnresolvedImport +from _pydev_bundle import pydev_log + + +# Used so that we don't loose the id (because we'll remove when it's not alive and would generate a new id for the +# same tasklet). +class TaskletToLastId: + ''' + So, why not a WeakKeyDictionary? + The problem is that removals from the WeakKeyDictionary will create a new tasklet (as it adds a callback to + remove the key when it's garbage-collected), so, we can get into a recursion. + ''' + + def __init__(self): + self.tasklet_ref_to_last_id = {} + self._i = 0 + + def get(self, tasklet): + return self.tasklet_ref_to_last_id.get(weakref.ref(tasklet)) + + def __setitem__(self, tasklet, last_id): + self.tasklet_ref_to_last_id[weakref.ref(tasklet)] = last_id + self._i += 1 + if self._i % 100 == 0: # Collect at each 100 additions to the dict (no need to rush). + for tasklet_ref in list(self.tasklet_ref_to_last_id.keys()): + if tasklet_ref() is None: + del self.tasklet_ref_to_last_id[tasklet_ref] + + +_tasklet_to_last_id = TaskletToLastId() + + +#======================================================================================================================= +# _TaskletInfo +#======================================================================================================================= +class _TaskletInfo: + + _last_id = 0 + + def __init__(self, tasklet_weakref, tasklet): + self.frame_id = None + self.tasklet_weakref = tasklet_weakref + + last_id = _tasklet_to_last_id.get(tasklet) + if last_id is None: + _TaskletInfo._last_id += 1 + last_id = _TaskletInfo._last_id + _tasklet_to_last_id[tasklet] = last_id + + self._tasklet_id = last_id + + self.update_name() + + def update_name(self): + tasklet = self.tasklet_weakref() + if tasklet: + if tasklet.blocked: + state = 'blocked' + elif tasklet.paused: + state = 'paused' + elif tasklet.scheduled: + state = 'scheduled' + else: + state = '' + + try: + name = tasklet.name + except AttributeError: + if tasklet.is_main: + name = 'MainTasklet' + else: + name = 'Tasklet-%s' % (self._tasklet_id,) + + thread_id = tasklet.thread_id + if thread_id != -1: + for thread in threading.enumerate(): + if thread.ident == thread_id: + if thread.name: + thread_name = "of %s" % (thread.name,) + else: + thread_name = "of Thread-%s" % (thread.name or str(thread_id),) + break + else: + # should not happen. + thread_name = "of Thread-%s" % (str(thread_id),) + thread = None + else: + # tasklet is no longer bound to a thread, because its thread ended + thread_name = "without thread" + + tid = id(tasklet) + tasklet = None + else: + state = 'dead' + name = 'Tasklet-%s' % (self._tasklet_id,) + thread_name = "" + tid = '-' + self.tasklet_name = '%s %s %s (%s)' % (state, name, thread_name, tid) + + if not hasattr(stackless.tasklet, "trace_function"): + + # bug https://bitbucket.org/stackless-dev/stackless/issue/42 + # is not fixed. Stackless releases before 2014 + def update_name(self): + tasklet = self.tasklet_weakref() + if tasklet: + try: + name = tasklet.name + except AttributeError: + if tasklet.is_main: + name = 'MainTasklet' + else: + name = 'Tasklet-%s' % (self._tasklet_id,) + + thread_id = tasklet.thread_id + for thread in threading.enumerate(): + if thread.ident == thread_id: + if thread.name: + thread_name = "of %s" % (thread.name,) + else: + thread_name = "of Thread-%s" % (thread.name or str(thread_id),) + break + else: + # should not happen. + thread_name = "of Thread-%s" % (str(thread_id),) + thread = None + + tid = id(tasklet) + tasklet = None + else: + name = 'Tasklet-%s' % (self._tasklet_id,) + thread_name = "" + tid = '-' + self.tasklet_name = '%s %s (%s)' % (name, thread_name, tid) + + +_weak_tasklet_registered_to_info = {} + + +#======================================================================================================================= +# get_tasklet_info +#======================================================================================================================= +def get_tasklet_info(tasklet): + return register_tasklet_info(tasklet) + + +#======================================================================================================================= +# register_tasklet_info +#======================================================================================================================= +def register_tasklet_info(tasklet): + r = weakref.ref(tasklet) + info = _weak_tasklet_registered_to_info.get(r) + if info is None: + info = _weak_tasklet_registered_to_info[r] = _TaskletInfo(r, tasklet) + + return info + + +_application_set_schedule_callback = None + + +#======================================================================================================================= +# _schedule_callback +#======================================================================================================================= +def _schedule_callback(prev, next): + ''' + Called when a context is stopped or a new context is made runnable. + ''' + try: + if not prev and not next: + return + + current_frame = sys._getframe() + + if next: + register_tasklet_info(next) + + # Ok, making next runnable: set the tracing facility in it. + debugger = get_global_debugger() + if debugger is not None: + next.trace_function = debugger.get_thread_local_trace_func() + frame = next.frame + if frame is current_frame: + frame = frame.f_back + if hasattr(frame, 'f_trace'): # Note: can be None (but hasattr should cover for that too). + frame.f_trace = debugger.get_thread_local_trace_func() + + debugger = None + + if prev: + register_tasklet_info(prev) + + try: + for tasklet_ref, tasklet_info in dict_items(_weak_tasklet_registered_to_info): # Make sure it's a copy! + tasklet = tasklet_ref() + if tasklet is None or not tasklet.alive: + # Garbage-collected already! + try: + del _weak_tasklet_registered_to_info[tasklet_ref] + except KeyError: + pass + if tasklet_info.frame_id is not None: + remove_custom_frame(tasklet_info.frame_id) + else: + is_running = stackless.get_thread_info(tasklet.thread_id)[1] is tasklet + if tasklet is prev or (tasklet is not next and not is_running): + # the tasklet won't run after this scheduler action: + # - the tasklet is the previous tasklet + # - it is not the next tasklet and it is not an already running tasklet + frame = tasklet.frame + if frame is current_frame: + frame = frame.f_back + if frame is not None: + # print >>sys.stderr, "SchedCB: %r, %d, '%s', '%s'" % (tasklet, frame.f_lineno, _filename, base) + if debugger.get_file_type(frame) is None: + tasklet_info.update_name() + if tasklet_info.frame_id is None: + tasklet_info.frame_id = add_custom_frame(frame, tasklet_info.tasklet_name, tasklet.thread_id) + else: + update_custom_frame(tasklet_info.frame_id, frame, tasklet.thread_id, name=tasklet_info.tasklet_name) + + elif tasklet is next or is_running: + if tasklet_info.frame_id is not None: + # Remove info about stackless suspended when it starts to run. + remove_custom_frame(tasklet_info.frame_id) + tasklet_info.frame_id = None + + finally: + tasklet = None + tasklet_info = None + frame = None + + except: + pydev_log.exception() + + if _application_set_schedule_callback is not None: + return _application_set_schedule_callback(prev, next) + + +if not hasattr(stackless.tasklet, "trace_function"): + + # Older versions of Stackless, released before 2014 + # This code does not work reliable! It is affected by several + # stackless bugs: Stackless issues #44, #42, #40 + def _schedule_callback(prev, next): + ''' + Called when a context is stopped or a new context is made runnable. + ''' + try: + if not prev and not next: + return + + if next: + register_tasklet_info(next) + + # Ok, making next runnable: set the tracing facility in it. + debugger = get_global_debugger() + if debugger is not None and next.frame: + if hasattr(next.frame, 'f_trace'): + next.frame.f_trace = debugger.get_thread_local_trace_func() + debugger = None + + if prev: + register_tasklet_info(prev) + + try: + for tasklet_ref, tasklet_info in dict_items(_weak_tasklet_registered_to_info): # Make sure it's a copy! + tasklet = tasklet_ref() + if tasklet is None or not tasklet.alive: + # Garbage-collected already! + try: + del _weak_tasklet_registered_to_info[tasklet_ref] + except KeyError: + pass + if tasklet_info.frame_id is not None: + remove_custom_frame(tasklet_info.frame_id) + else: + if tasklet.paused or tasklet.blocked or tasklet.scheduled: + if tasklet.frame and tasklet.frame.f_back: + f_back = tasklet.frame.f_back + if debugger.get_file_type(f_back) is None: + if tasklet_info.frame_id is None: + tasklet_info.frame_id = add_custom_frame(f_back, tasklet_info.tasklet_name, tasklet.thread_id) + else: + update_custom_frame(tasklet_info.frame_id, f_back, tasklet.thread_id) + + elif tasklet.is_current: + if tasklet_info.frame_id is not None: + # Remove info about stackless suspended when it starts to run. + remove_custom_frame(tasklet_info.frame_id) + tasklet_info.frame_id = None + + finally: + tasklet = None + tasklet_info = None + f_back = None + + except: + pydev_log.exception() + + if _application_set_schedule_callback is not None: + return _application_set_schedule_callback(prev, next) + + _original_setup = stackless.tasklet.setup + + #======================================================================================================================= + # setup + #======================================================================================================================= + def setup(self, *args, **kwargs): + ''' + Called to run a new tasklet: rebind the creation so that we can trace it. + ''' + + f = self.tempval + + def new_f(old_f, args, kwargs): + + debugger = get_global_debugger() + if debugger is not None: + debugger.enable_tracing() + + debugger = None + + # Remove our own traces :) + self.tempval = old_f + register_tasklet_info(self) + + # Hover old_f to see the stackless being created and *args and **kwargs to see its parameters. + return old_f(*args, **kwargs) + + # This is the way to tell stackless that the function it should execute is our function, not the original one. Note: + # setting tempval is the same as calling bind(new_f), but it seems that there's no other way to get the currently + # bound function, so, keeping on using tempval instead of calling bind (which is actually the same thing in a better + # API). + + self.tempval = new_f + + return _original_setup(self, f, args, kwargs) + + #======================================================================================================================= + # __call__ + #======================================================================================================================= + def __call__(self, *args, **kwargs): + ''' + Called to run a new tasklet: rebind the creation so that we can trace it. + ''' + + return setup(self, *args, **kwargs) + + _original_run = stackless.run + + #======================================================================================================================= + # run + #======================================================================================================================= + def run(*args, **kwargs): + debugger = get_global_debugger() + if debugger is not None: + debugger.enable_tracing() + debugger = None + + return _original_run(*args, **kwargs) + + +#======================================================================================================================= +# patch_stackless +#======================================================================================================================= +def patch_stackless(): + ''' + This function should be called to patch the stackless module so that new tasklets are properly tracked in the + debugger. + ''' + global _application_set_schedule_callback + _application_set_schedule_callback = stackless.set_schedule_callback(_schedule_callback) + + def set_schedule_callback(callable): + global _application_set_schedule_callback + old = _application_set_schedule_callback + _application_set_schedule_callback = callable + return old + + def get_schedule_callback(): + global _application_set_schedule_callback + return _application_set_schedule_callback + + set_schedule_callback.__doc__ = stackless.set_schedule_callback.__doc__ + if hasattr(stackless, "get_schedule_callback"): + get_schedule_callback.__doc__ = stackless.get_schedule_callback.__doc__ + stackless.set_schedule_callback = set_schedule_callback + stackless.get_schedule_callback = get_schedule_callback + + if not hasattr(stackless.tasklet, "trace_function"): + # Older versions of Stackless, released before 2014 + __call__.__doc__ = stackless.tasklet.__call__.__doc__ + stackless.tasklet.__call__ = __call__ + + setup.__doc__ = stackless.tasklet.setup.__doc__ + stackless.tasklet.setup = setup + + run.__doc__ = stackless.run.__doc__ + stackless.run = run + + +patch_stackless = call_only_once(patch_stackless) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_suspended_frames.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_suspended_frames.py new file mode 100644 index 0000000..dd73d41 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_suspended_frames.py @@ -0,0 +1,461 @@ +from contextlib import contextmanager +import sys + +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import get_frame, dict_items, RETURN_VALUES_DICT, \ + dict_iter_items +from _pydevd_bundle.pydevd_xml import get_variable_details, get_type +from _pydev_bundle.pydev_override import overrides +from _pydevd_bundle.pydevd_resolver import sorted_attributes_key, TOO_LARGE_ATTR +from _pydevd_bundle.pydevd_safe_repr import SafeRepr +from _pydev_bundle import pydev_log +from _pydevd_bundle import pydevd_vars +from _pydev_bundle.pydev_imports import Exec + + +class _AbstractVariable(object): + + # Default attributes in class, set in instance. + + name = None + value = None + evaluate_name = None + + def get_name(self): + return self.name + + def get_value(self): + return self.value + + def get_variable_reference(self): + return id(self.value) + + def get_var_data(self, fmt=None): + ''' + :param dict fmt: + Format expected by the DAP (keys: 'hex': bool, 'rawString': bool) + ''' + safe_repr = SafeRepr() + if fmt is not None: + safe_repr.convert_to_hex = fmt.get('hex', False) + safe_repr.raw_value = fmt.get('rawString', False) + + type_name, _type_qualifier, _is_exception_on_eval, resolver, value = get_variable_details( + self.value, to_string=safe_repr) + + is_raw_string = type_name in ('str', 'unicode', 'bytes', 'bytearray') + + attributes = [] + + if is_raw_string: + attributes.append('rawString') + + name = self.name + + if self._is_return_value: + attributes.append('readOnly') + name = '(return) %s' % (name,) + + elif name in (TOO_LARGE_ATTR, '__len__'): + attributes.append('readOnly') + + var_data = { + 'name': name, + 'value': value, + 'type': type_name, + } + + if self.evaluate_name is not None: + var_data['evaluateName'] = self.evaluate_name + + if resolver is not None: # I.e.: it's a container + var_data['variablesReference'] = self.get_variable_reference() + else: + var_data['variablesReference'] = 0 # It's mandatory (although if == 0 it doesn't have children). + + if len(attributes) > 0: + var_data['presentationHint'] = {'attributes': attributes} + + return var_data + + def get_children_variables(self, fmt=None): + raise NotImplementedError() + + def get_child_variable_named(self, name, fmt=None): + for child_var in self.get_children_variables(fmt=fmt): + if child_var.get_name() == name: + return child_var + return None + + +class _ObjectVariable(_AbstractVariable): + + def __init__(self, name, value, register_variable, is_return_value=False, evaluate_name=None, frame=None): + _AbstractVariable.__init__(self) + self.frame = frame + self.name = name + self.value = value + self._register_variable = register_variable + self._register_variable(self) + self._is_return_value = is_return_value + self.evaluate_name = evaluate_name + + @overrides(_AbstractVariable.get_children_variables) + def get_children_variables(self, fmt=None): + _type, _type_name, resolver = get_type(self.value) + + children_variables = [] + if resolver is not None: # i.e.: it's a container. + if hasattr(resolver, 'get_contents_debug_adapter_protocol'): + # The get_contents_debug_adapter_protocol needs to return sorted. + lst = resolver.get_contents_debug_adapter_protocol(self.value, fmt=fmt) + else: + # If there's no special implementation, the default is sorting the keys. + dct = resolver.get_dictionary(self.value) + lst = dict_items(dct) + lst.sort(key=lambda tup: sorted_attributes_key(tup[0])) + # No evaluate name in this case. + lst = [(key, value, None) for (key, value) in lst] + + parent_evaluate_name = self.evaluate_name + if parent_evaluate_name: + for key, val, evaluate_name in lst: + if evaluate_name is not None: + if callable(evaluate_name): + evaluate_name = evaluate_name(parent_evaluate_name) + else: + evaluate_name = parent_evaluate_name + evaluate_name + variable = _ObjectVariable( + key, val, self._register_variable, evaluate_name=evaluate_name, frame=self.frame) + children_variables.append(variable) + else: + for key, val, evaluate_name in lst: + # No evaluate name + variable = _ObjectVariable(key, val, self._register_variable, frame=self.frame) + children_variables.append(variable) + + return children_variables + + def change_variable(self, name, value, py_db, fmt=None): + + children_variable = self.get_child_variable_named(name) + if children_variable is None: + return None + + var_data = children_variable.get_var_data() + evaluate_name = var_data.get('evaluateName') + + if not evaluate_name: + # Note: right now we only pass control to the resolver in the cases where + # there's no evaluate name (the idea being that if we can evaluate it, + # we can use that evaluation to set the value too -- if in the future + # a case where this isn't true is found this logic may need to be changed). + _type, _type_name, container_resolver = get_type(self.value) + if hasattr(container_resolver, 'change_var_from_name'): + try: + new_value = eval(value) + except: + return None + new_key = container_resolver.change_var_from_name(self.value, name, new_value) + if new_key is not None: + return _ObjectVariable( + new_key, new_value, self._register_variable, evaluate_name=None, frame=self.frame) + + return None + else: + return None + + frame = self.frame + if frame is None: + return None + + try: + # This handles the simple cases (such as dict, list, object) + Exec('%s=%s' % (evaluate_name, value), frame.f_globals, frame.f_locals) + except: + return None + + return self.get_child_variable_named(name, fmt=fmt) + + +def sorted_variables_key(obj): + return sorted_attributes_key(obj.name) + + +class _FrameVariable(_AbstractVariable): + + def __init__(self, frame, register_variable): + _AbstractVariable.__init__(self) + self.frame = frame + + self.name = self.frame.f_code.co_name + self.value = frame + + self._register_variable = register_variable + self._register_variable(self) + + def change_variable(self, name, value, py_db, fmt=None): + frame = self.frame + + pydevd_vars.change_attr_expression(frame, name, value, py_db) + + return self.get_child_variable_named(name, fmt=fmt) + + @overrides(_AbstractVariable.get_children_variables) + def get_children_variables(self, fmt=None): + children_variables = [] + for key, val in dict_items(self.frame.f_locals): + is_return_value = key == RETURN_VALUES_DICT + if is_return_value: + for return_key, return_value in dict_iter_items(val): + variable = _ObjectVariable( + return_key, return_value, self._register_variable, is_return_value, '%s[%r]' % (key, return_key), frame=self.frame) + children_variables.append(variable) + else: + variable = _ObjectVariable(key, val, self._register_variable, is_return_value, key, frame=self.frame) + children_variables.append(variable) + + # Frame variables always sorted. + children_variables.sort(key=sorted_variables_key) + + return children_variables + + +class _FramesTracker(object): + ''' + This is a helper class to be used to track frames when a thread becomes suspended. + ''' + + def __init__(self, suspended_frames_manager, py_db): + self._suspended_frames_manager = suspended_frames_manager + self.py_db = py_db + self._frame_id_to_frame = {} + + # Note that a given frame may appear in multiple threads when we have custom + # frames added, but as those are coroutines, this map will point to the actual + # main thread (which is the one that needs to be suspended for us to get the + # variables). + self._frame_id_to_main_thread_id = {} + + # A map of the suspended thread id -> list(frames ids) -- note that + # frame ids are kept in order (the first one is the suspended frame). + self._thread_id_to_frame_ids = {} + + # A map of the lines where it's suspended (needed for exceptions where the frame + # lineno is not correct). + self._frame_id_to_lineno = {} + + # The main suspended thread (if this is a coroutine this isn't the id of the + # coroutine thread, it's the id of the actual suspended thread). + self._main_thread_id = None + + # Helper to know if it was already untracked. + self._untracked = False + + # We need to be thread-safe! + self._lock = threading.Lock() + + self._variable_reference_to_variable = {} + + def _register_variable(self, variable): + variable_reference = variable.get_variable_reference() + self._variable_reference_to_variable[variable_reference] = variable + + def obtain_as_variable(self, name, value, evaluate_name=None, frame=None): + if evaluate_name is None: + evaluate_name = name + + variable_reference = id(value) + variable = self._variable_reference_to_variable.get(variable_reference) + if variable is not None: + return variable + + # Still not created, let's do it now. + return _ObjectVariable( + name, value, self._register_variable, is_return_value=False, evaluate_name=evaluate_name, frame=frame) + + def get_main_thread_id(self): + return self._main_thread_id + + def get_variable(self, variable_reference): + return self._variable_reference_to_variable[variable_reference] + + def track(self, thread_id, frame, frame_id_to_lineno, frame_custom_thread_id=None): + ''' + :param thread_id: + The thread id to be used for this frame. + + :param frame: + The topmost frame which is suspended at the given thread. + + :param frame_id_to_lineno: + If available, the line number for the frame will be gotten from this dict, + otherwise frame.f_lineno will be used (needed for unhandled exceptions as + the place where we report may be different from the place where it's raised). + + :param frame_custom_thread_id: + If None this this is the id of the thread id for the custom frame (i.e.: coroutine). + ''' + with self._lock: + coroutine_or_main_thread_id = frame_custom_thread_id or thread_id + + if coroutine_or_main_thread_id in self._suspended_frames_manager._thread_id_to_tracker: + sys.stderr.write('pydevd: Something is wrong. Tracker being added twice to the same thread id.\n') + + self._suspended_frames_manager._thread_id_to_tracker[coroutine_or_main_thread_id] = self + self._main_thread_id = thread_id + self._frame_id_to_lineno = frame_id_to_lineno + + frame_ids_from_thread = self._thread_id_to_frame_ids.setdefault( + coroutine_or_main_thread_id, []) + + while frame is not None: + frame_id = id(frame) + self._frame_id_to_frame[frame_id] = frame + _FrameVariable(frame, self._register_variable) # Instancing is enough to register. + self._suspended_frames_manager._variable_reference_to_frames_tracker[frame_id] = self + frame_ids_from_thread.append(frame_id) + + self._frame_id_to_main_thread_id[frame_id] = thread_id + + frame = frame.f_back + + def untrack_all(self): + with self._lock: + if self._untracked: + # Calling multiple times is expected for the set next statement. + return + self._untracked = True + for thread_id in self._thread_id_to_frame_ids: + self._suspended_frames_manager._thread_id_to_tracker.pop(thread_id, None) + + for frame_id in self._frame_id_to_frame: + del self._suspended_frames_manager._variable_reference_to_frames_tracker[frame_id] + + self._frame_id_to_frame.clear() + self._frame_id_to_main_thread_id.clear() + self._thread_id_to_frame_ids.clear() + self._frame_id_to_lineno.clear() + self._main_thread_id = None + self._suspended_frames_manager = None + self._variable_reference_to_variable.clear() + + def get_topmost_frame_and_frame_id_to_line(self, thread_id): + with self._lock: + frame_ids = self._thread_id_to_frame_ids.get(thread_id) + if frame_ids is not None: + frame_id = frame_ids[0] + return self._frame_id_to_frame[frame_id], self._frame_id_to_lineno + + def find_frame(self, thread_id, frame_id): + with self._lock: + return self._frame_id_to_frame.get(frame_id) + + def create_thread_suspend_command(self, thread_id, stop_reason, message, suspend_type): + with self._lock: + frame_ids = self._thread_id_to_frame_ids[thread_id] + + # First one is topmost frame suspended. + frame = self._frame_id_to_frame[frame_ids[0]] + + cmd = self.py_db.cmd_factory.make_thread_suspend_message( + self.py_db, thread_id, frame, stop_reason, message, suspend_type, frame_id_to_lineno=self._frame_id_to_lineno) + + frame = None + return cmd + + +class SuspendedFramesManager(object): + + def __init__(self): + self._thread_id_to_fake_frames = {} + self._thread_id_to_tracker = {} + + # Mappings + self._variable_reference_to_frames_tracker = {} + + def _get_tracker_for_variable_reference(self, variable_reference): + tracker = self._variable_reference_to_frames_tracker.get(variable_reference) + if tracker is not None: + return tracker + + for _thread_id, tracker in dict_iter_items(self._thread_id_to_tracker): + try: + tracker.get_variable(variable_reference) + except KeyError: + pass + else: + return tracker + + return None + + def get_thread_id_for_variable_reference(self, variable_reference): + ''' + We can't evaluate variable references values on any thread, only in the suspended + thread (the main reason for this is that in UI frameworks inspecting a UI object + from a different thread can potentially crash the application). + + :param int variable_reference: + The variable reference (can be either a frame id or a reference to a previously + gotten variable). + + :return str: + The thread id for the thread to be used to inspect the given variable reference or + None if the thread was already resumed. + ''' + frames_tracker = self._get_tracker_for_variable_reference(variable_reference) + if frames_tracker is not None: + return frames_tracker.get_main_thread_id() + return None + + def get_frame_tracker(self, thread_id): + return self._thread_id_to_tracker.get(thread_id) + + def get_variable(self, variable_reference): + ''' + :raises KeyError + ''' + frames_tracker = self._get_tracker_for_variable_reference(variable_reference) + if frames_tracker is None: + raise KeyError() + return frames_tracker.get_variable(variable_reference) + + def get_topmost_frame_and_frame_id_to_line(self, thread_id): + tracker = self._thread_id_to_tracker.get(thread_id) + if tracker is None: + return None + return tracker.get_topmost_frame_and_frame_id_to_line(thread_id) + + @contextmanager + def track_frames(self, py_db): + tracker = _FramesTracker(self, py_db) + try: + yield tracker + finally: + tracker.untrack_all() + + def add_fake_frame(self, thread_id, frame_id, frame): + self._thread_id_to_fake_frames.setdefault(thread_id, {})[int(frame_id)] = frame + + def find_frame(self, thread_id, frame_id): + try: + if frame_id == "*": + return get_frame() # any frame is specified with "*" + frame_id = int(frame_id) + + fake_frames = self._thread_id_to_fake_frames.get(thread_id) + if fake_frames is not None: + frame = fake_frames.get(frame_id) + if frame is not None: + return frame + + frames_tracker = self._thread_id_to_tracker.get(thread_id) + if frames_tracker is not None: + frame = frames_tracker.find_frame(thread_id, frame_id) + if frame is not None: + return frame + + return None + except: + pydev_log.exception() + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_api.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_api.py new file mode 100644 index 0000000..999bc1c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_api.py @@ -0,0 +1,58 @@ +def add_line_breakpoint(plugin, pydb, type, file, line, condition, expression, func_name): + return None + + +def add_exception_breakpoint(plugin, pydb, type, exception): + return False + + +def remove_exception_breakpoint(plugin, pydb, type, exception): + return False + + +def remove_all_exception_breakpoints(plugin, pydb): + return False + + +def get_breakpoints(plugin, pydb): + return None + + +def can_skip(plugin, pydb, frame): + return True + + +def has_exception_breaks(plugin): + return False + + +def has_line_breaks(plugin): + return False + + +def cmd_step_into(plugin, pydb, frame, event, args, stop_info, stop): + return False + + +def cmd_step_over(plugin, pydb, frame, event, args, stop_info, stop): + return False + + +def stop(plugin, pydb, frame, event, args, stop_info, arg, step_cmd): + return False + + +def get_breakpoint(plugin, pydb, pydb_frame, frame, event, args): + return None + + +def suspend(plugin, pydb, thread, frame): + return None + + +def exception_break(plugin, pydb, pydb_frame, frame, args, arg): + return None + + +def change_variable(plugin, frame, attr, expression): + return False diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch.py new file mode 100644 index 0000000..dc38315 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch.py @@ -0,0 +1,64 @@ +# Defines which version of the trace_dispatch we'll use. +# Should give warning only here if cython is not available but supported. + +import os +from _pydevd_bundle.pydevd_constants import CYTHON_SUPPORTED +from _pydev_bundle import pydev_log + +use_cython = os.getenv('PYDEVD_USE_CYTHON', None) +dirname = os.path.dirname(os.path.dirname(__file__)) +# Do not show incorrect warning for .egg files for Remote debugger +if not CYTHON_SUPPORTED or dirname.endswith('.egg'): + # Do not try to import cython extensions if cython isn't supported + use_cython = 'NO' + + +def delete_old_compiled_extensions(): + import _pydevd_bundle + cython_extensions_dir = os.path.dirname(os.path.dirname(_pydevd_bundle.__file__)) + _pydevd_bundle_ext_dir = os.path.dirname(_pydevd_bundle.__file__) + _pydevd_frame_eval_ext_dir = os.path.join(cython_extensions_dir, '_pydevd_frame_eval_ext') + try: + import shutil + for file in os.listdir(_pydevd_bundle_ext_dir): + if file.startswith("pydevd") and file.endswith(".so"): + os.remove(os.path.join(_pydevd_bundle_ext_dir, file)) + for file in os.listdir(_pydevd_frame_eval_ext_dir): + if file.startswith("pydevd") and file.endswith(".so"): + os.remove(os.path.join(_pydevd_frame_eval_ext_dir, file)) + build_dir = os.path.join(cython_extensions_dir, "build") + if os.path.exists(build_dir): + shutil.rmtree(os.path.join(cython_extensions_dir, "build")) + except OSError: + pydev_log.error_once("warning: failed to delete old cython speedups. Please delete all *.so files from the directories " + "\"%s\" and \"%s\"" % (_pydevd_bundle_ext_dir, _pydevd_frame_eval_ext_dir)) + + +if use_cython == 'YES': + # We must import the cython version if forcing cython + from _pydevd_bundle.pydevd_cython_wrapper import trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func + +elif use_cython == 'NO': + # Use the regular version if not forcing cython + from _pydevd_bundle.pydevd_trace_dispatch_regular import trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func # @UnusedImport + +elif use_cython is None: + # Regular: use fallback if not found and give message to user + try: + from _pydevd_bundle.pydevd_cython_wrapper import trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func + + # This version number is always available + from _pydevd_bundle.pydevd_additional_thread_info_regular import version as regular_version + # This version number from the already compiled cython extension + from _pydevd_bundle.pydevd_cython_wrapper import version as cython_version + if cython_version != regular_version: + # delete_old_compiled_extensions() -- would be ok in dev mode but we don't want to erase + # files from other python versions on release, so, just raise import error here. + raise ImportError('Cython version of speedups does not match.') + + except ImportError: + from _pydevd_bundle.pydevd_trace_dispatch_regular import trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func # @UnusedImport + pydev_log.show_compile_cython_command_line() +else: + raise RuntimeError('Unexpected value for PYDEVD_USE_CYTHON: %s (accepted: YES, NO)' % (use_cython,)) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch_regular.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch_regular.py new file mode 100644 index 0000000..bc07e76 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch_regular.py @@ -0,0 +1,534 @@ +from _pydev_bundle.pydev_is_thread_alive import is_thread_alive +from _pydev_bundle.pydev_log import exception as pydev_log_exception +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import (get_current_thread_id, NO_FTRACE, + USE_CUSTOM_SYS_CURRENT_FRAMES_MAP) +from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER + +# IFDEF CYTHON +# from cpython.object cimport PyObject +# from cpython.ref cimport Py_INCREF, Py_XDECREF +# ELSE +from _pydevd_bundle.pydevd_frame import PyDBFrame +# ENDIF + +# IFDEF CYTHON +# cdef dict _global_notify_skipped_step_in +# cython_inline_constant: CMD_STEP_INTO = 107 +# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144 +# cython_inline_constant: CMD_STEP_RETURN = 109 +# cython_inline_constant: CMD_STEP_RETURN_MY_CODE = 160 +# ELSE +# Note: those are now inlined on cython. +CMD_STEP_INTO = 107 +CMD_STEP_INTO_MY_CODE = 144 +CMD_STEP_RETURN = 109 +CMD_STEP_RETURN_MY_CODE = 160 +# ENDIF + +# Cache where we should keep that we completely skipped entering some context. +# It needs to be invalidated when: +# - Breakpoints are changed +# It can be used when running regularly (without step over/step in/step return) +global_cache_skips = {} +global_cache_frame_skips = {} + +_global_notify_skipped_step_in = False +_global_notify_skipped_step_in_lock = threading.Lock() + + +def notify_skipped_step_in_because_of_filters(py_db, frame): + global _global_notify_skipped_step_in + + with _global_notify_skipped_step_in_lock: + if _global_notify_skipped_step_in: + # Check with lock in place (callers should actually have checked + # before without the lock in place due to performance). + return + _global_notify_skipped_step_in = True + py_db.notify_skipped_step_in_because_of_filters(frame) + +# IFDEF CYTHON +# cdef class SafeCallWrapper: +# cdef method_object +# def __init__(self, method_object): +# self.method_object = method_object +# def __call__(self, *args): +# #Cannot use 'self' once inside the delegate call since we are borrowing the self reference f_trace field +# #in the frame, and that reference might get destroyed by set trace on frame and parents +# cdef PyObject* method_obj = self.method_object +# Py_INCREF(method_obj) +# ret = (method_obj)(*args) +# Py_XDECREF (method_obj) +# return SafeCallWrapper(ret) if ret is not None else None +# def get_method_object(self): +# return self.method_object +# ELSE +# ENDIF + + +def fix_top_level_trace_and_get_trace_func(py_db, frame): + # IFDEF CYTHON + # cdef str filename; + # cdef str name; + # cdef tuple args; + # ENDIF + + # Note: this is always the first entry-point in the tracing for any thread. + # After entering here we'll set a new tracing function for this thread + # where more information is cached (and will also setup the tracing for + # frames where we should deal with unhandled exceptions). + thread = None + # Cache the frame which should be traced to deal with unhandled exceptions. + # (i.e.: thread entry-points). + + f_unhandled = frame + # print('called at', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + force_only_unhandled_tracer = False + while f_unhandled is not None: + # name = splitext(basename(f_unhandled.f_code.co_filename))[0] + + name = f_unhandled.f_code.co_filename + # basename + i = name.rfind('/') + j = name.rfind('\\') + if j > i: + i = j + if i >= 0: + name = name[i + 1:] + # remove ext + i = name.rfind('.') + if i >= 0: + name = name[:i] + + if name == 'threading': + if f_unhandled.f_code.co_name in ('__bootstrap', '_bootstrap'): + # We need __bootstrap_inner, not __bootstrap. + return None, False + + elif f_unhandled.f_code.co_name in ('__bootstrap_inner', '_bootstrap_inner'): + # Note: be careful not to use threading.currentThread to avoid creating a dummy thread. + t = f_unhandled.f_locals.get('self') + force_only_unhandled_tracer = True + if t is not None and isinstance(t, threading.Thread): + thread = t + break + + elif name == 'pydev_monkey': + if f_unhandled.f_code.co_name == '__call__': + force_only_unhandled_tracer = True + break + + elif name == 'pydevd': + if f_unhandled.f_code.co_name in ('run', 'main'): + # We need to get to _exec + return None, False + + if f_unhandled.f_code.co_name == '_exec': + force_only_unhandled_tracer = True + break + + elif f_unhandled.f_back is None: + break + + f_unhandled = f_unhandled.f_back + + if thread is None: + # Important: don't call threadingCurrentThread if we're in the threading module + # to avoid creating dummy threads. + if py_db.threading_get_ident is not None: + thread = py_db.threading_active.get(py_db.threading_get_ident()) + if thread is None: + return None, False + else: + # Jython does not have threading.get_ident(). + thread = py_db.threading_current_thread() + + if getattr(thread, 'pydev_do_not_trace', None): + py_db.disable_tracing() + return None, False + + try: + additional_info = thread.additional_info + if additional_info is None: + raise AttributeError() + except: + additional_info = py_db.set_additional_thread_info(thread) + + # print('enter thread tracer', thread, get_current_thread_id(thread)) + args = (py_db, thread, additional_info, global_cache_skips, global_cache_frame_skips) + + if f_unhandled is not None: + if f_unhandled.f_back is None and not force_only_unhandled_tracer: + # Happens when we attach to a running program (cannot reuse instance because it's mutable). + top_level_thread_tracer = TopLevelThreadTracerNoBackFrame(ThreadTracer(args), args) + additional_info.top_level_thread_tracer_no_back_frames.append(top_level_thread_tracer) # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + else: + top_level_thread_tracer = additional_info.top_level_thread_tracer_unhandled + if top_level_thread_tracer is None: + # Stop in some internal place to report about unhandled exceptions + top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args) + additional_info.top_level_thread_tracer_unhandled = top_level_thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough). + + # print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno) + f_trace = top_level_thread_tracer.get_trace_dispatch_func() + # IFDEF CYTHON + # f_trace = SafeCallWrapper(f_trace) + # ENDIF + f_unhandled.f_trace = f_trace + + if frame is f_unhandled: + return f_trace, False + + thread_tracer = additional_info.thread_tracer + if thread_tracer is None: + thread_tracer = ThreadTracer(args) + additional_info.thread_tracer = thread_tracer + +# IFDEF CYTHON +# return SafeCallWrapper(thread_tracer), True +# ELSE + return thread_tracer, True +# ENDIF + + +def trace_dispatch(py_db, frame, event, arg): + thread_trace_func, apply_to_settrace = py_db.fix_top_level_trace_and_get_trace_func(py_db, frame) + if thread_trace_func is None: + return None if event == 'call' else NO_FTRACE + if apply_to_settrace: + py_db.enable_tracing(thread_trace_func) + return thread_trace_func(frame, event, arg) + + +# IFDEF CYTHON +# cdef class TopLevelThreadTracerOnlyUnhandledExceptions: +# cdef public tuple _args; +# def __init__(self, tuple args): +# self._args = args +# ELSE +class TopLevelThreadTracerOnlyUnhandledExceptions(object): + + def __init__(self, args): + self._args = args +# ENDIF + + def trace_unhandled_exceptions(self, frame, event, arg): + # Note that we ignore the frame as this tracing method should only be put in topmost frames already. + # print('trace_unhandled_exceptions', event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno) + if event == 'exception' and arg is not None: + py_db, t, additional_info = self._args[0:3] + if arg is not None: + if not additional_info.suspended_at_unhandled: + additional_info.suspended_at_unhandled = True + + py_db.stop_on_unhandled_exception(py_db, t, additional_info, arg) + + # No need to reset frame.f_trace to keep the same trace function. + return self.trace_unhandled_exceptions + + def get_trace_dispatch_func(self): + return self.trace_unhandled_exceptions + + +# IFDEF CYTHON +# cdef class TopLevelThreadTracerNoBackFrame: +# +# cdef public object _frame_trace_dispatch; +# cdef public tuple _args; +# cdef public object _try_except_info; +# cdef public object _last_exc_arg; +# cdef public set _raise_lines; +# cdef public int _last_raise_line; +# +# def __init__(self, frame_trace_dispatch, tuple args): +# self._frame_trace_dispatch = frame_trace_dispatch +# self._args = args +# self._try_except_info = None +# self._last_exc_arg = None +# self._raise_lines = set() +# self._last_raise_line = -1 +# ELSE +class TopLevelThreadTracerNoBackFrame(object): + ''' + This tracer is pretty special in that it's dealing with a frame without f_back (i.e.: top frame + on remote attach or QThread). + + This means that we have to carefully inspect exceptions to discover whether the exception will + be unhandled or not (if we're dealing with an unhandled exception we need to stop as unhandled, + otherwise we need to use the regular tracer -- unfortunately the debugger has little info to + work with in the tracing -- see: https://bugs.python.org/issue34099, so, we inspect bytecode to + determine if some exception will be traced or not... note that if this is not available -- such + as on Jython -- we consider any top-level exception to be unnhandled). + ''' + + def __init__(self, frame_trace_dispatch, args): + self._frame_trace_dispatch = frame_trace_dispatch + self._args = args + self._try_except_info = None + self._last_exc_arg = None + self._raise_lines = set() + self._last_raise_line = -1 +# ENDIF + + def trace_dispatch_and_unhandled_exceptions(self, frame, event, arg): + # DEBUG = 'code_to_debug' in frame.f_code.co_filename + # if DEBUG: print('trace_dispatch_and_unhandled_exceptions: %s %s %s %s %s %s' % (event, frame.f_code.co_name, frame.f_code.co_filename, frame.f_code.co_firstlineno, self._frame_trace_dispatch, frame.f_lineno)) + frame_trace_dispatch = self._frame_trace_dispatch + if frame_trace_dispatch is not None: + self._frame_trace_dispatch = frame_trace_dispatch(frame, event, arg) + + if event == 'exception': + self._last_exc_arg = arg + self._raise_lines.add(frame.f_lineno) + self._last_raise_line = frame.f_lineno + + elif event == 'return' and self._last_exc_arg is not None: + # For unhandled exceptions we actually track the return when at the topmost level. + try: + py_db, t, additional_info = self._args[0:3] + if not additional_info.suspended_at_unhandled: # Note: only check it here, don't set. + if frame.f_lineno in self._raise_lines: + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + + else: + if self._try_except_info is None: + self._try_except_info = py_db.collect_try_except_info(frame.f_code) + if not self._try_except_info: + # Consider the last exception as unhandled because there's no try..except in it. + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + else: + # Now, consider only the try..except for the raise + valid_try_except_infos = [] + for try_except_info in self._try_except_info: + if try_except_info.is_line_in_try_block(self._last_raise_line): + valid_try_except_infos.append(try_except_info) + + if not valid_try_except_infos: + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + + else: + # Note: check all, not only the "valid" ones to cover the case + # in "tests_python.test_tracing_on_top_level.raise_unhandled10" + # where one try..except is inside the other with only a raise + # and it's gotten in the except line. + for try_except_info in self._try_except_info: + if try_except_info.is_line_in_except_block(frame.f_lineno): + if ( + frame.f_lineno == try_except_info.except_line or + frame.f_lineno in try_except_info.raise_lines_in_except + ): + # In a raise inside a try..except block or some except which doesn't + # match the raised exception. + py_db.stop_on_unhandled_exception(py_db, t, additional_info, self._last_exc_arg) + break + else: + break # exited during the except block (no exception raised) + finally: + # Remove reference to exception after handling it. + self._last_exc_arg = None + + ret = self.trace_dispatch_and_unhandled_exceptions + + # Need to reset (the call to _frame_trace_dispatch may have changed it). + # IFDEF CYTHON + # frame.f_trace = SafeCallWrapper(ret) + # ELSE + frame.f_trace = ret + # ENDIF + return ret + + def get_trace_dispatch_func(self): + return self.trace_dispatch_and_unhandled_exceptions + + +# IFDEF CYTHON +# cdef class ThreadTracer: +# cdef public tuple _args; +# def __init__(self, tuple args): +# self._args = args +# ELSE +class ThreadTracer(object): + + def __init__(self, args): + self._args = args +# ENDIF + + def __call__(self, frame, event, arg): + ''' This is the callback used when we enter some context in the debugger. + + We also decorate the thread we are in with info about the debugging. + The attributes added are: + pydev_state + pydev_step_stop + pydev_step_cmd + pydev_notify_kill + + :param PyDB py_db: + This is the global debugger (this method should actually be added as a method to it). + ''' + # IFDEF CYTHON + # cdef str filename; + # cdef str base; + # cdef int pydev_step_cmd; + # cdef tuple frame_cache_key; + # cdef dict cache_skips; + # cdef bint is_stepping; + # cdef tuple abs_path_real_path_and_base; + # cdef PyDBAdditionalThreadInfo additional_info; + # ENDIF + + # DEBUG = 'code_to_debug' in frame.f_code.co_filename + # if DEBUG: print('ENTER: trace_dispatch: %s %s %s %s' % (frame.f_code.co_filename, frame.f_lineno, event, frame.f_code.co_name)) + py_db, t, additional_info, cache_skips, frame_skips_cache = self._args + pydev_step_cmd = additional_info.pydev_step_cmd + is_stepping = pydev_step_cmd != -1 + + try: + if py_db._finish_debugging_session: + if not py_db._termination_event_set: + # that was not working very well because jython gave some socket errors + try: + if py_db.output_checker_thread is None: + kill_all_pydev_threads() + except: + pydev_log_exception() + py_db._termination_event_set = True + return None if event == 'call' else NO_FTRACE + + # if thread is not alive, cancel trace_dispatch processing + if not is_thread_alive(t): + py_db.notify_thread_not_alive(get_current_thread_id(t)) + return None if event == 'call' else NO_FTRACE + + if py_db.thread_analyser is not None: + py_db.thread_analyser.log_event(frame) + + if py_db.asyncio_analyser is not None: + py_db.asyncio_analyser.log_event(frame) + + # Note: it's important that the context name is also given because we may hit something once + # in the global context and another in the local context. + frame_cache_key = (frame.f_code.co_firstlineno, frame.f_code.co_name, frame.f_code.co_filename) + if frame_cache_key in cache_skips: + if not is_stepping: + # if DEBUG: print('skipped: trace_dispatch (cache hit)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + else: + # When stepping we can't take into account caching based on the breakpoints (only global filtering). + if cache_skips.get(frame_cache_key) == 1: + + if additional_info.pydev_original_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) and not _global_notify_skipped_step_in: + notify_skipped_step_in_because_of_filters(py_db, frame) + + back_frame = frame.f_back + if back_frame is not None and pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE): + back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + if cache_skips.get(back_frame_cache_key) == 1: + # if DEBUG: print('skipped: trace_dispatch (cache hit: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + else: + # if DEBUG: print('skipped: trace_dispatch (cache hit: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + + try: + # Make fast path faster! + abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + except: + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + + filename = abs_path_real_path_and_base[1] + file_type = py_db.get_file_type(frame, abs_path_real_path_and_base) # we don't want to debug threading or anything related to pydevd + + if file_type is not None: + if file_type == 1: # inlining LIB_FILE = 1 + if not py_db.in_project_scope(frame, abs_path_real_path_and_base[0]): + # if DEBUG: print('skipped: trace_dispatch (not in scope)', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + cache_skips[frame_cache_key] = 1 + return None if event == 'call' else NO_FTRACE + else: + # if DEBUG: print('skipped: trace_dispatch', abs_path_real_path_and_base[-1], frame.f_lineno, event, frame.f_code.co_name, file_type) + cache_skips[frame_cache_key] = 1 + return None if event == 'call' else NO_FTRACE + + if py_db.is_files_filter_enabled: + if py_db.apply_files_filter(frame, filename, False): + cache_skips[frame_cache_key] = 1 + + if is_stepping and additional_info.pydev_original_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) and not _global_notify_skipped_step_in: + notify_skipped_step_in_because_of_filters(py_db, frame) + + # A little gotcha, sometimes when we're stepping in we have to stop in a + # return event showing the back frame as the current frame, so, we need + # to check not only the current frame but the back frame too. + back_frame = frame.f_back + if back_frame is not None and pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE, CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE): + if py_db.apply_files_filter(back_frame, back_frame.f_code.co_filename, False): + back_frame_cache_key = (back_frame.f_code.co_firstlineno, back_frame.f_code.co_name, back_frame.f_code.co_filename) + cache_skips[back_frame_cache_key] = 1 + # if DEBUG: print('skipped: trace_dispatch (filtered out: 1)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + else: + # if DEBUG: print('skipped: trace_dispatch (filtered out: 2)', frame_cache_key, frame.f_lineno, event, frame.f_code.co_name) + return None if event == 'call' else NO_FTRACE + + # if DEBUG: print('trace_dispatch', filename, frame.f_lineno, event, frame.f_code.co_name, file_type) + if additional_info.is_tracing: + return None if event == 'call' else NO_FTRACE # we don't wan't to trace code invoked from pydevd_frame.trace_dispatch + + # Just create PyDBFrame directly (removed support for Python versions < 2.5, which required keeping a weak + # reference to the frame). + ret = PyDBFrame( + ( + py_db, filename, additional_info, t, frame_skips_cache, frame_cache_key, + ) + ).trace_dispatch(frame, event, arg) + if ret is None: + # 1 means skipped because of filters. + # 2 means skipped because no breakpoints were hit. + cache_skips[frame_cache_key] = 2 + return None if event == 'call' else NO_FTRACE + + # IFDEF CYTHON + # frame.f_trace = SafeCallWrapper(ret) # Make sure we keep the returned tracer. + # ELSE + frame.f_trace = ret # Make sure we keep the returned tracer. + # ENDIF + return ret + + except SystemExit: + return None if event == 'call' else NO_FTRACE + + except Exception: + if py_db._finish_debugging_session: + return None if event == 'call' else NO_FTRACE # Don't log errors when we're shutting down. + # Log it + try: + if pydev_log_exception is not None: + # This can actually happen during the interpreter shutdown in Python 2.7 + pydev_log_exception() + except: + # Error logging? We're really in the interpreter shutdown... + # (https://github.com/fabioz/PyDev.Debugger/issues/8) + pass + return None if event == 'call' else NO_FTRACE + + +if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + # This is far from ideal, as we'll leak frames (we'll always have the last created frame, not really + # the last topmost frame saved -- this should be Ok for our usage, but it may leak frames and things + # may live longer... as IronPython is garbage-collected, things should live longer anyways, so, it + # shouldn't be an issue as big as it's in CPython -- it may still be annoying, but this should + # be a reasonable workaround until IronPython itself is able to provide that functionality). + # + # See: https://github.com/IronLanguages/main/issues/1630 + from _pydevd_bundle.pydevd_additional_thread_info_regular import _tid_to_last_frame + + _original_call = ThreadTracer.__call__ + + def __call__(self, frame, event, arg): + _tid_to_last_frame[self._args[1].ident] = frame + return _original_call(self, frame, event, arg) + + ThreadTracer.__call__ = __call__ diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_traceproperty.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_traceproperty.py new file mode 100644 index 0000000..2bfebc4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_traceproperty.py @@ -0,0 +1,100 @@ +'''For debug purpose we are replacing actual builtin property by the debug property +''' +from _pydevd_bundle.pydevd_comm import get_global_debugger +from _pydevd_bundle.pydevd_constants import DebugInfoHolder, IS_PY2 +from _pydev_bundle import pydev_log + + +#======================================================================================================================= +# replace_builtin_property +#======================================================================================================================= +def replace_builtin_property(new_property=None): + if new_property is None: + new_property = DebugProperty + original = property + if IS_PY2: + try: + import __builtin__ + __builtin__.__dict__['property'] = new_property + except: + pydev_log.exception() # @Reimport + else: + try: + import builtins # Python 3.0 does not have the __builtin__ module @UnresolvedImport + builtins.__dict__['property'] = new_property + except: + pydev_log.exception() # @Reimport + return original + + +#======================================================================================================================= +# DebugProperty +#======================================================================================================================= +class DebugProperty(object): + """A custom property which allows python property to get + controlled by the debugger and selectively disable/re-enable + the tracing. + """ + + def __init__(self, fget=None, fset=None, fdel=None, doc=None): + self.fget = fget + self.fset = fset + self.fdel = fdel + self.__doc__ = doc + + def __get__(self, obj, objtype=None): + if obj is None: + return self + global_debugger = get_global_debugger() + try: + if global_debugger is not None and global_debugger.disable_property_getter_trace: + global_debugger.disable_tracing() + if self.fget is None: + raise AttributeError("unreadable attribute") + return self.fget(obj) + finally: + if global_debugger is not None: + global_debugger.enable_tracing() + + def __set__(self, obj, value): + global_debugger = get_global_debugger() + try: + if global_debugger is not None and global_debugger.disable_property_setter_trace: + global_debugger.disable_tracing() + if self.fset is None: + raise AttributeError("can't set attribute") + self.fset(obj, value) + finally: + if global_debugger is not None: + global_debugger.enable_tracing() + + def __delete__(self, obj): + global_debugger = get_global_debugger() + try: + if global_debugger is not None and global_debugger.disable_property_deleter_trace: + global_debugger.disable_tracing() + if self.fdel is None: + raise AttributeError("can't delete attribute") + self.fdel(obj) + finally: + if global_debugger is not None: + global_debugger.enable_tracing() + + def getter(self, fget): + """Overriding getter decorator for the property + """ + self.fget = fget + return self + + def setter(self, fset): + """Overriding setter decorator for the property + """ + self.fset = fset + return self + + def deleter(self, fdel): + """Overriding deleter decorator for the property + """ + self.fdel = fdel + return self + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py new file mode 100644 index 0000000..85e0013 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py @@ -0,0 +1,245 @@ +from __future__ import nested_scopes +import traceback +import warnings + +try: + from urllib import quote +except: + from urllib.parse import quote # @UnresolvedImport + +import inspect +import sys +from _pydevd_bundle.pydevd_constants import IS_PY3K, USE_CUSTOM_SYS_CURRENT_FRAMES, IS_PYPY +from _pydev_imps._pydev_saved_modules import threading + + +def save_main_module(file, module_name): + # patch provided by: Scott Schlesier - when script is run, it does not + # use globals from pydevd: + # This will prevent the pydevd script from contaminating the namespace for the script to be debugged + # pretend pydevd is not the main module, and + # convince the file to be debugged that it was loaded as main + sys.modules[module_name] = sys.modules['__main__'] + sys.modules[module_name].__name__ = module_name + + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + warnings.simplefilter("ignore", category=PendingDeprecationWarning) + from imp import new_module + + m = new_module('__main__') + sys.modules['__main__'] = m + if hasattr(sys.modules[module_name], '__loader__'): + m.__loader__ = getattr(sys.modules[module_name], '__loader__') + m.__file__ = file + + return m + + +def is_current_thread_main_thread(): + if hasattr(threading, 'main_thread'): + return threading.current_thread() is threading.main_thread() + else: + return isinstance(threading.current_thread(), threading._MainThread) + + +def get_main_thread(): + if hasattr(threading, 'main_thread'): + return threading.main_thread() + else: + for t in threading.enumerate(): + if isinstance(t, threading._MainThread): + return t + return None + + +def to_number(x): + if is_string(x): + try: + n = float(x) + return n + except ValueError: + pass + + l = x.find('(') + if l != -1: + y = x[0:l - 1] + # print y + try: + n = float(y) + return n + except ValueError: + pass + return None + + +def compare_object_attrs_key(x): + if '__len__' == x: + as_number = to_number(x) + if as_number is None: + as_number = 99999999 + # __len__ should appear after other attributes in a list. + return (1, as_number) + else: + return (-1, to_string(x)) + + +if IS_PY3K: + + def is_string(x): + return isinstance(x, str) + +else: + + def is_string(x): + return isinstance(x, basestring) + + +def to_string(x): + if is_string(x): + return x + else: + return str(x) + + +def print_exc(): + if traceback: + traceback.print_exc() + + +if IS_PY3K: + + def quote_smart(s, safe='/'): + return quote(s, safe) + +else: + + def quote_smart(s, safe='/'): + if isinstance(s, unicode): + s = s.encode('utf-8') + + return quote(s, safe) + + +def get_clsname_for_code(code, frame): + clsname = None + if len(code.co_varnames) > 0: + # We are checking the first argument of the function + # (`self` or `cls` for methods). + first_arg_name = code.co_varnames[0] + if first_arg_name in frame.f_locals: + first_arg_obj = frame.f_locals[first_arg_name] + if inspect.isclass(first_arg_obj): # class method + first_arg_class = first_arg_obj + else: # instance method + first_arg_class = first_arg_obj.__class__ + func_name = code.co_name + if hasattr(first_arg_class, func_name): + method = getattr(first_arg_class, func_name) + func_code = None + if hasattr(method, 'func_code'): # Python2 + func_code = method.func_code + elif hasattr(method, '__code__'): # Python3 + func_code = method.__code__ + if func_code and func_code == code: + clsname = first_arg_class.__name__ + + return clsname + + +def get_non_pydevd_threads(): + threads = threading.enumerate() + return [t for t in threads if t and not getattr(t, 'is_pydev_daemon_thread', False)] + + +def dump_threads(stream=None): + ''' + Helper to dump thread info. + ''' + if stream is None: + stream = sys.stderr + thread_id_to_name = {} + try: + for t in threading.enumerate(): + thread_id_to_name[t.ident] = '%s (daemon: %s, pydevd thread: %s)' % ( + t.name, t.daemon, getattr(t, 'is_pydev_daemon_thread', False)) + except: + pass + + if USE_CUSTOM_SYS_CURRENT_FRAMES and IS_PYPY: + # On PyPy we can use its fake_frames to get the traceback + # (instead of the actual real frames that need the tracing to be correct). + _current_frames = sys._current_frames + else: + from _pydevd_bundle.pydevd_additional_thread_info_regular import _current_frames + + stream.write('===============================================================================\n') + stream.write('Threads running\n') + stream.write('================================= Thread Dump =================================\n') + stream.flush() + + for thread_id, stack in _current_frames().items(): + stream.write('\n-------------------------------------------------------------------------------\n') + stream.write(" Thread %s" % thread_id_to_name.get(thread_id, thread_id)) + stream.write('\n\n') + + for i, (filename, lineno, name, line) in enumerate(traceback.extract_stack(stack)): + + stream.write(' File "%s", line %d, in %s\n' % (filename, lineno, name)) + if line: + stream.write(" %s\n" % (line.strip())) + + if i == 0 and 'self' in stack.f_locals: + stream.write(' self: ') + try: + stream.write(str(stack.f_locals['self'])) + except: + stream.write('Unable to get str of: %s' % (type(stack.f_locals['self']),)) + stream.write('\n') + stream.flush() + + stream.write('\n=============================== END Thread Dump ===============================') + stream.flush() + + +def _extract_variable_nested_braces(char_iter): + expression = [] + level = 0 + for c in char_iter: + if c == '{': + level += 1 + if c == '}': + level -= 1 + if level == -1: + return ''.join(expression).strip() + expression.append(c) + raise SyntaxError('Unbalanced braces in expression.') + + +def _extract_expression_list(log_message): + # Note: not using re because of nested braces. + expression = [] + expression_vars = [] + char_iter = iter(log_message) + for c in char_iter: + if c == '{': + expression_var = _extract_variable_nested_braces(char_iter) + if expression_var: + expression.append('%s') + expression_vars.append(expression_var) + else: + expression.append(c) + + expression = ''.join(expression) + return expression, expression_vars + + +def convert_dap_log_message_to_expression(log_message): + try: + expression, expression_vars = _extract_expression_list(log_message) + except SyntaxError: + return repr('Unbalanced braces in: %s' % (log_message)) + if not expression_vars: + return repr(expression) + # Note: use '%' to be compatible with Python 2.6. + return repr(expression) + ' % (' + ', '.join(str(x) for x in expression_vars) + ',)' diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py new file mode 100644 index 0000000..6cd2f8d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_vars.py @@ -0,0 +1,526 @@ +""" pydevd_vars deals with variables: + resolution/conversion to XML. +""" +import pickle +from _pydevd_bundle.pydevd_constants import get_frame, get_current_thread_id, xrange + +from _pydevd_bundle.pydevd_xml import ExceptionOnEvaluate, get_type, var_to_xml +from _pydev_bundle import pydev_log + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO +import sys # @Reimport + +from _pydev_imps._pydev_saved_modules import threading +import traceback +from _pydevd_bundle import pydevd_save_locals +from _pydev_bundle.pydev_imports import Exec, execfile +from _pydevd_bundle.pydevd_utils import to_string + +SENTINEL_VALUE = [] + + +class VariableError(RuntimeError): + pass + + +def iter_frames(frame): + while frame is not None: + yield frame + frame = frame.f_back + frame = None + + +def dump_frames(thread_id): + sys.stdout.write('dumping frames\n') + if thread_id != get_current_thread_id(threading.currentThread()): + raise VariableError("find_frame: must execute on same thread") + + frame = get_frame() + for frame in iter_frames(frame): + sys.stdout.write('%s\n' % pickle.dumps(frame)) + + +def getVariable(dbg, thread_id, frame_id, scope, attrs): + """ + returns the value of a variable + + :scope: can be BY_ID, EXPRESSION, GLOBAL, LOCAL, FRAME + + BY_ID means we'll traverse the list of all objects alive to get the object. + + :attrs: after reaching the proper scope, we have to get the attributes until we find + the proper location (i.e.: obj\tattr1\tattr2) + + :note: when BY_ID is used, the frame_id is considered the id of the object to find and + not the frame (as we don't care about the frame in this case). + """ + if scope == 'BY_ID': + if thread_id != get_current_thread_id(threading.currentThread()): + raise VariableError("getVariable: must execute on same thread") + + try: + import gc + objects = gc.get_objects() + except: + pass # Not all python variants have it. + else: + frame_id = int(frame_id) + for var in objects: + if id(var) == frame_id: + if attrs is not None: + attrList = attrs.split('\t') + for k in attrList: + _type, _typeName, resolver = get_type(var) + var = resolver.resolve(var, k) + + return var + + # If it didn't return previously, we coudn't find it by id (i.e.: alrceady garbage collected). + sys.stderr.write('Unable to find object with id: %s\n' % (frame_id,)) + return None + + frame = dbg.find_frame(thread_id, frame_id) + if frame is None: + return {} + + if attrs is not None: + attrList = attrs.split('\t') + else: + attrList = [] + + for attr in attrList: + attr.replace("@_@TAB_CHAR@_@", '\t') + + if scope == 'EXPRESSION': + for count in xrange(len(attrList)): + if count == 0: + # An Expression can be in any scope (globals/locals), therefore it needs to evaluated as an expression + var = evaluate_expression(dbg, frame, attrList[count], False) + else: + _type, _typeName, resolver = get_type(var) + var = resolver.resolve(var, attrList[count]) + else: + if scope == "GLOBAL": + var = frame.f_globals + del attrList[0] # globals are special, and they get a single dummy unused attribute + else: + # in a frame access both locals and globals as Python does + var = {} + var.update(frame.f_globals) + var.update(frame.f_locals) + + for k in attrList: + _type, _typeName, resolver = get_type(var) + var = resolver.resolve(var, k) + + return var + + +def resolve_compound_variable_fields(dbg, thread_id, frame_id, scope, attrs): + """ + Resolve compound variable in debugger scopes by its name and attributes + + :param thread_id: id of the variable's thread + :param frame_id: id of the variable's frame + :param scope: can be BY_ID, EXPRESSION, GLOBAL, LOCAL, FRAME + :param attrs: after reaching the proper scope, we have to get the attributes until we find + the proper location (i.e.: obj\tattr1\tattr2) + :return: a dictionary of variables's fields + """ + + var = getVariable(dbg, thread_id, frame_id, scope, attrs) + + try: + _type, _typeName, resolver = get_type(var) + return _typeName, resolver.get_dictionary(var) + except: + pydev_log.exception('Error evaluating: thread_id: %s\nframe_id: %s\nscope: %s\nattrs: %s.', + thread_id, frame_id, scope, attrs) + + +def resolve_var_object(var, attrs): + """ + Resolve variable's attribute + + :param var: an object of variable + :param attrs: a sequence of variable's attributes separated by \t (i.e.: obj\tattr1\tattr2) + :return: a value of resolved variable's attribute + """ + if attrs is not None: + attr_list = attrs.split('\t') + else: + attr_list = [] + for k in attr_list: + type, _typeName, resolver = get_type(var) + var = resolver.resolve(var, k) + return var + + +def resolve_compound_var_object_fields(var, attrs): + """ + Resolve compound variable by its object and attributes + + :param var: an object of variable + :param attrs: a sequence of variable's attributes separated by \t (i.e.: obj\tattr1\tattr2) + :return: a dictionary of variables's fields + """ + attr_list = attrs.split('\t') + + for k in attr_list: + type, _typeName, resolver = get_type(var) + var = resolver.resolve(var, k) + + try: + type, _typeName, resolver = get_type(var) + return resolver.get_dictionary(var) + except: + pydev_log.exception() + + +def custom_operation(dbg, thread_id, frame_id, scope, attrs, style, code_or_file, operation_fn_name): + """ + We'll execute the code_or_file and then search in the namespace the operation_fn_name to execute with the given var. + + code_or_file: either some code (i.e.: from pprint import pprint) or a file to be executed. + operation_fn_name: the name of the operation to execute after the exec (i.e.: pprint) + """ + expressionValue = getVariable(dbg, thread_id, frame_id, scope, attrs) + + try: + namespace = {'__name__': ''} + if style == "EXECFILE": + namespace['__file__'] = code_or_file + execfile(code_or_file, namespace, namespace) + else: # style == EXEC + namespace['__file__'] = '' + Exec(code_or_file, namespace, namespace) + + return str(namespace[operation_fn_name](expressionValue)) + except: + pydev_log.exception() + + +def eval_in_context(expression, globals, locals): + result = None + try: + result = eval(expression, globals, locals) + except Exception: + s = StringIO() + traceback.print_exc(file=s) + result = s.getvalue() + + try: + try: + etype, value, tb = sys.exc_info() + result = value + finally: + etype = value = tb = None + except: + pass + + result = ExceptionOnEvaluate(result) + + # Ok, we have the initial error message, but let's see if we're dealing with a name mangling error... + try: + if '__' in expression: + # Try to handle '__' name mangling... + split = expression.split('.') + curr = locals.get(split[0]) + for entry in split[1:]: + if entry.startswith('__') and not hasattr(curr, entry): + entry = '_%s%s' % (curr.__class__.__name__, entry) + curr = getattr(curr, entry) + + result = curr + except: + pass + return result + + +def evaluate_expression(dbg, frame, expression, is_exec): + '''returns the result of the evaluated expression + @param is_exec: determines if we should do an exec or an eval + ''' + if frame is None: + return + + # Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 + # (Names not resolved in generator expression in method) + # See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html + updated_globals = {} + updated_globals.update(frame.f_globals) + updated_globals.update(frame.f_locals) # locals later because it has precedence over the actual globals + + try: + expression = str(expression.replace('@LINE@', '\n')) + + if is_exec: + try: + # try to make it an eval (if it is an eval we can print it, otherwise we'll exec it and + # it will have whatever the user actually did) + compiled = compile(expression, '', 'eval') + except: + Exec(expression, updated_globals, frame.f_locals) + pydevd_save_locals.save_locals(frame) + else: + result = eval(compiled, updated_globals, frame.f_locals) + if result is not None: # Only print if it's not None (as python does) + sys.stdout.write('%s\n' % (result,)) + return + + else: + return eval_in_context(expression, updated_globals, frame.f_locals) + finally: + # Should not be kept alive if an exception happens and this frame is kept in the stack. + del updated_globals + del frame + + +def change_attr_expression(frame, attr, expression, dbg, value=SENTINEL_VALUE): + '''Changes some attribute in a given frame. + ''' + if frame is None: + return + + try: + expression = expression.replace('@LINE@', '\n') + + if dbg.plugin and value is SENTINEL_VALUE: + result = dbg.plugin.change_variable(frame, attr, expression) + if result: + return result + + if attr[:7] == "Globals": + attr = attr[8:] + if attr in frame.f_globals: + if value is SENTINEL_VALUE: + value = eval(expression, frame.f_globals, frame.f_locals) + frame.f_globals[attr] = value + return frame.f_globals[attr] + else: + if '.' not in attr: # i.e.: if we have a '.', we're changing some attribute of a local var. + if pydevd_save_locals.is_save_locals_available(): + if value is SENTINEL_VALUE: + value = eval(expression, frame.f_globals, frame.f_locals) + frame.f_locals[attr] = value + pydevd_save_locals.save_locals(frame) + return frame.f_locals[attr] + + # default way (only works for changing it in the topmost frame) + if value is SENTINEL_VALUE: + value = eval(expression, frame.f_globals, frame.f_locals) + result = value + Exec('%s=%s' % (attr, expression), frame.f_globals, frame.f_locals) + return result + + except Exception: + pydev_log.exception() + + +MAXIMUM_ARRAY_SIZE = 100 +MAX_SLICE_SIZE = 1000 + + +def table_like_struct_to_xml(array, name, roffset, coffset, rows, cols, format): + _, type_name, _ = get_type(array) + if type_name == 'ndarray': + array, metaxml, r, c, f = array_to_meta_xml(array, name, format) + xml = metaxml + format = '%' + f + if rows == -1 and cols == -1: + rows = r + cols = c + xml += array_to_xml(array, roffset, coffset, rows, cols, format) + elif type_name == 'DataFrame': + xml = dataframe_to_xml(array, name, roffset, coffset, rows, cols, format) + else: + raise VariableError("Do not know how to convert type %s to table" % (type_name)) + + return "%s" % xml + + +def array_to_xml(array, roffset, coffset, rows, cols, format): + xml = "" + rows = min(rows, MAXIMUM_ARRAY_SIZE) + cols = min(cols, MAXIMUM_ARRAY_SIZE) + + # there is no obvious rule for slicing (at least 5 choices) + if len(array) == 1 and (rows > 1 or cols > 1): + array = array[0] + if array.size > len(array): + array = array[roffset:, coffset:] + rows = min(rows, len(array)) + cols = min(cols, len(array[0])) + if len(array) == 1: + array = array[0] + elif array.size == len(array): + if roffset == 0 and rows == 1: + array = array[coffset:] + cols = min(cols, len(array)) + elif coffset == 0 and cols == 1: + array = array[roffset:] + rows = min(rows, len(array)) + + xml += "" % (rows, cols) + for row in xrange(rows): + xml += "" % to_string(row) + for col in xrange(cols): + value = array + if rows == 1 or cols == 1: + if rows == 1 and cols == 1: + value = array[0] + else: + if rows == 1: + dim = col + else: + dim = row + value = array[dim] + if "ndarray" in str(type(value)): + value = value[0] + else: + value = array[row][col] + value = format % value + xml += var_to_xml(value, '') + return xml + + +def array_to_meta_xml(array, name, format): + type = array.dtype.kind + slice = name + l = len(array.shape) + + # initial load, compute slice + if format == '%': + if l > 2: + slice += '[0]' * (l - 2) + for r in xrange(l - 2): + array = array[0] + if type == 'f': + format = '.5f' + elif type == 'i' or type == 'u': + format = 'd' + else: + format = 's' + else: + format = format.replace('%', '') + + l = len(array.shape) + reslice = "" + if l > 2: + raise Exception("%s has more than 2 dimensions." % slice) + elif l == 1: + # special case with 1D arrays arr[i, :] - row, but arr[:, i] - column with equal shape and ndim + # http://stackoverflow.com/questions/16837946/numpy-a-2-rows-1-column-file-loadtxt-returns-1row-2-columns + # explanation: http://stackoverflow.com/questions/15165170/how-do-i-maintain-row-column-orientation-of-vectors-in-numpy?rq=1 + # we use kind of a hack - get information about memory from C_CONTIGUOUS + is_row = array.flags['C_CONTIGUOUS'] + + if is_row: + rows = 1 + cols = min(len(array), MAX_SLICE_SIZE) + if cols < len(array): + reslice = '[0:%s]' % (cols) + array = array[0:cols] + else: + cols = 1 + rows = min(len(array), MAX_SLICE_SIZE) + if rows < len(array): + reslice = '[0:%s]' % (rows) + array = array[0:rows] + elif l == 2: + rows = min(array.shape[-2], MAX_SLICE_SIZE) + cols = min(array.shape[-1], MAX_SLICE_SIZE) + if cols < array.shape[-1] or rows < array.shape[-2]: + reslice = '[0:%s, 0:%s]' % (rows, cols) + array = array[0:rows, 0:cols] + + # avoid slice duplication + if not slice.endswith(reslice): + slice += reslice + + bounds = (0, 0) + if type in "biufc": + bounds = (array.min(), array.max()) + xml = '' % \ + (slice, rows, cols, format, type, bounds[1], bounds[0]) + return array, xml, rows, cols, format + + +def dataframe_to_xml(df, name, roffset, coffset, rows, cols, format): + """ + :type df: pandas.core.frame.DataFrame + :type name: str + :type coffset: int + :type roffset: int + :type rows: int + :type cols: int + :type format: str + + + """ + num_rows = min(df.shape[0], MAX_SLICE_SIZE) + num_cols = min(df.shape[1], MAX_SLICE_SIZE) + if (num_rows, num_cols) != df.shape: + df = df.iloc[0:num_rows, 0: num_cols] + slice = '.iloc[0:%s, 0:%s]' % (num_rows, num_cols) + else: + slice = '' + slice = name + slice + xml = '\n' % \ + (slice, num_rows, num_cols) + + if (rows, cols) == (-1, -1): + rows, cols = num_rows, num_cols + + rows = min(rows, MAXIMUM_ARRAY_SIZE) + cols = min(min(cols, MAXIMUM_ARRAY_SIZE), num_cols) + # need to precompute column bounds here before slicing! + col_bounds = [None] * cols + for col in xrange(cols): + dtype = df.dtypes.iloc[coffset + col].kind + if dtype in "biufc": + cvalues = df.iloc[:, coffset + col] + bounds = (cvalues.min(), cvalues.max()) + else: + bounds = (0, 0) + col_bounds[col] = bounds + + df = df.iloc[roffset: roffset + rows, coffset: coffset + cols] + rows, cols = df.shape + + xml += "\n" % (rows, cols) + format = format.replace('%', '') + col_formats = [] + + get_label = lambda label: str(label) if not isinstance(label, tuple) else '/'.join(map(str, label)) + + for col in xrange(cols): + dtype = df.dtypes.iloc[col].kind + if dtype == 'f' and format: + fmt = format + elif dtype == 'f': + fmt = '.5f' + elif dtype == 'i' or dtype == 'u': + fmt = 'd' + else: + fmt = 's' + col_formats.append('%' + fmt) + bounds = col_bounds[col] + + xml += '\n' % \ + (str(col), get_label(df.axes[1].values[col]), dtype, fmt, bounds[1], bounds[0]) + for row, label in enumerate(iter(df.axes[0])): + xml += "\n" % \ + (str(row), get_label(label)) + xml += "\n" + xml += "\n" % (rows, cols) + for row in xrange(rows): + xml += "\n" % str(row) + for col in xrange(cols): + value = df.iat[row, col] + value = col_formats[col] % value + xml += var_to_xml(value, '') + return xml diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_vm_type.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_vm_type.py new file mode 100644 index 0000000..d2cf5b6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_vm_type.py @@ -0,0 +1,41 @@ +import sys + +#======================================================================================================================= +# PydevdVmType +#======================================================================================================================= +class PydevdVmType: + + PYTHON = 'python' + JYTHON = 'jython' + vm_type = None + + +#======================================================================================================================= +# set_vm_type +#======================================================================================================================= +def set_vm_type(vm_type): + PydevdVmType.vm_type = vm_type + + +#======================================================================================================================= +# get_vm_type +#======================================================================================================================= +def get_vm_type(): + if PydevdVmType.vm_type is None: + setup_type() + return PydevdVmType.vm_type + + +#======================================================================================================================= +# setup_type +#======================================================================================================================= +def setup_type(str=None): + if str is not None: + PydevdVmType.vm_type = str + return + + if sys.platform.startswith("java"): + PydevdVmType.vm_type = PydevdVmType.JYTHON + else: + PydevdVmType.vm_type = PydevdVmType.PYTHON + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_xml.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_xml.py new file mode 100644 index 0000000..ee1dd6f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_xml.py @@ -0,0 +1,379 @@ +from _pydev_bundle import pydev_log +from _pydevd_bundle import pydevd_extension_utils +from _pydevd_bundle import pydevd_resolver +import sys +from _pydevd_bundle.pydevd_constants import dict_iter_items, dict_keys, IS_PY3K, \ + BUILTINS_MODULE_NAME, MAXIMUM_VARIABLE_REPRESENTATION_SIZE, RETURN_VALUES_DICT, LOAD_VALUES_ASYNC, \ + DEFAULT_VALUE +from _pydev_bundle.pydev_imports import quote +from _pydevd_bundle.pydevd_extension_api import TypeResolveProvider, StrPresentationProvider + +try: + import types + + frame_type = types.FrameType +except: + frame_type = None + + +def make_valid_xml_value(s): + # Same thing as xml.sax.saxutils.escape but also escaping double quotes. + return s.replace("&", "&").replace('<', '<').replace('>', '>').replace('"', '"') + + +class ExceptionOnEvaluate: + + def __init__(self, result): + self.result = result + + +_IS_JYTHON = sys.platform.startswith("java") + + +def _create_default_type_map(): + default_type_map = [ + # None means that it should not be treated as a compound variable + + # isintance does not accept a tuple on some versions of python, so, we must declare it expanded + (type(None), None,), + (int, None), + (float, None), + (complex, None), + (str, None), + (tuple, pydevd_resolver.tupleResolver), + (list, pydevd_resolver.tupleResolver), + (dict, pydevd_resolver.dictResolver), + ] + try: + default_type_map.append((long, None)) # @UndefinedVariable + except: + pass # not available on all python versions + + try: + default_type_map.append((unicode, None)) # @UndefinedVariable + except: + pass # not available on all python versions + + try: + default_type_map.append((set, pydevd_resolver.setResolver)) + except: + pass # not available on all python versions + + try: + default_type_map.append((frozenset, pydevd_resolver.setResolver)) + except: + pass # not available on all python versions + + try: + from django.utils.datastructures import MultiValueDict + default_type_map.insert(0, (MultiValueDict, pydevd_resolver.multiValueDictResolver)) + # we should put it before dict + except: + pass # django may not be installed + + try: + from django.forms import BaseForm + default_type_map.insert(0, (BaseForm, pydevd_resolver.djangoFormResolver)) + # we should put it before instance resolver + except: + pass # django may not be installed + + try: + from collections import deque + default_type_map.append((deque, pydevd_resolver.dequeResolver)) + except: + pass + + if frame_type is not None: + default_type_map.append((frame_type, pydevd_resolver.frameResolver)) + + if _IS_JYTHON: + from org.python import core # @UnresolvedImport + default_type_map.append((core.PyNone, None)) + default_type_map.append((core.PyInteger, None)) + default_type_map.append((core.PyLong, None)) + default_type_map.append((core.PyFloat, None)) + default_type_map.append((core.PyComplex, None)) + default_type_map.append((core.PyString, None)) + default_type_map.append((core.PyTuple, pydevd_resolver.tupleResolver)) + default_type_map.append((core.PyList, pydevd_resolver.tupleResolver)) + default_type_map.append((core.PyDictionary, pydevd_resolver.dictResolver)) + default_type_map.append((core.PyStringMap, pydevd_resolver.dictResolver)) + + if hasattr(core, 'PyJavaInstance'): + # Jython 2.5b3 removed it. + default_type_map.append((core.PyJavaInstance, pydevd_resolver.instanceResolver)) + + return default_type_map + + +class TypeResolveHandler(object): + NO_PROVIDER = [] # Sentinel value (any mutable object to be used as a constant would be valid). + + def __init__(self): + # Note: don't initialize with the types we already know about so that the extensions can override + # the default resolvers that are already available if they want. + self._type_to_resolver_cache = {} + self._type_to_str_provider_cache = {} + self._initialized = False + + def _initialize(self): + self._default_type_map = _create_default_type_map() + self._resolve_providers = pydevd_extension_utils.extensions_of_type(TypeResolveProvider) + self._str_providers = pydevd_extension_utils.extensions_of_type(StrPresentationProvider) + self._initialized = True + + def get_type(self, o): + try: + try: + # Faster than type(o) as we don't need the function call. + type_object = o.__class__ + except: + # Not all objects have __class__ (i.e.: there are bad bindings around). + type_object = type(o) + + type_name = type_object.__name__ + except: + # This happens for org.python.core.InitModule + return 'Unable to get Type', 'Unable to get Type', None + + return self._get_type(o, type_object, type_name) + + def _get_type(self, o, type_object, type_name): + resolver = self._type_to_resolver_cache.get(type_object) + if resolver is not None: + return type_object, type_name, resolver + + if not self._initialized: + self._initialize() + + try: + for resolver in self._resolve_providers: + if resolver.can_provide(type_object, type_name): + # Cache it + self._type_to_resolver_cache[type_object] = resolver + return type_object, type_name, resolver + + for t in self._default_type_map: + if isinstance(o, t[0]): + # Cache it + resolver = t[1] + self._type_to_resolver_cache[type_object] = resolver + return (type_object, type_name, resolver) + except: + pydev_log.exception() + + # No match return default (and cache it). + resolver = pydevd_resolver.defaultResolver + self._type_to_resolver_cache[type_object] = resolver + return type_object, type_name, resolver + + if _IS_JYTHON: + _base_get_type = _get_type + + def _get_type(self, o, type_object, type_name): + if type_name == 'org.python.core.PyJavaInstance': + return type_object, type_name, pydevd_resolver.instanceResolver + + if type_name == 'org.python.core.PyArray': + return type_object, type_name, pydevd_resolver.jyArrayResolver + + return self._base_get_type(o, type_object, type_name) + + def str_from_providers(self, o, type_object, type_name): + provider = self._type_to_str_provider_cache.get(type_object) + + if provider is self.NO_PROVIDER: + return None + + if provider is not None: + return provider.get_str(o) + + if not self._initialized: + self._initialize() + + for provider in self._str_providers: + if provider.can_provide(type_object, type_name): + self._type_to_str_provider_cache[type_object] = provider + return provider.get_str(o) + + self._type_to_str_provider_cache[type_object] = self.NO_PROVIDER + return None + + +_TYPE_RESOLVE_HANDLER = TypeResolveHandler() + +""" +def get_type(o): + Receives object and returns a triple (typeObject, typeString, resolver). + + resolver != None means that variable is a container, and should be displayed as a hierarchy. + + Use the resolver to get its attributes. + + All container objects should have a resolver. +""" +get_type = _TYPE_RESOLVE_HANDLER.get_type + +_str_from_providers = _TYPE_RESOLVE_HANDLER.str_from_providers + + +def is_builtin(x): + return getattr(x, '__module__', None) == BUILTINS_MODULE_NAME + + +def should_evaluate_full_value(val): + return not LOAD_VALUES_ASYNC or (is_builtin(type(val)) and not isinstance(val, (list, tuple, dict))) + + +def return_values_from_dict_to_xml(return_dict): + res = "" + for name, val in dict_iter_items(return_dict): + res += var_to_xml(val, name, additional_in_xml=' isRetVal="True"') + return res + + +def frame_vars_to_xml(frame_f_locals, hidden_ns=None): + """ dumps frame variables to XML + + """ + xml = "" + + keys = dict_keys(frame_f_locals) + if hasattr(keys, 'sort'): + keys.sort() # Python 3.0 does not have it + else: + keys = sorted(keys) # Jython 2.1 does not have it + + return_values_xml = '' + + for k in keys: + try: + v = frame_f_locals[k] + eval_full_val = should_evaluate_full_value(v) + + if k == RETURN_VALUES_DICT: + for name, val in dict_iter_items(v): + return_values_xml += var_to_xml(val, name, additional_in_xml=' isRetVal="True"') + + else: + if hidden_ns is not None and k in hidden_ns: + xml += var_to_xml(v, str(k), additional_in_xml=' isIPythonHidden="True"', + evaluate_full_value=eval_full_val) + else: + xml += var_to_xml(v, str(k), evaluate_full_value=eval_full_val) + except Exception: + pydev_log.exception("Unexpected error, recovered safely.") + + # Show return values as the first entry. + return return_values_xml + xml + + +def get_variable_details(val, evaluate_full_value=True, to_string=None): + try: + # This should be faster than isinstance (but we have to protect against not having a '__class__' attribute). + is_exception_on_eval = val.__class__ == ExceptionOnEvaluate + except: + is_exception_on_eval = False + + if is_exception_on_eval: + v = val.result + else: + v = val + + _type, type_name, resolver = get_type(v) + type_qualifier = getattr(_type, "__module__", "") + if not evaluate_full_value: + value = DEFAULT_VALUE + else: + try: + str_from_provider = _str_from_providers(v, _type, type_name) + if str_from_provider is not None: + value = str_from_provider + + elif to_string is not None: + value = to_string(v) + + elif hasattr(v, '__class__'): + if v.__class__ == frame_type: + value = pydevd_resolver.frameResolver.get_frame_name(v) + + elif v.__class__ in (list, tuple): + if len(v) > 300: + value = '%s: %s' % (str(v.__class__), '' % (len(v),)) + else: + value = '%s: %s' % (str(v.__class__), v) + else: + try: + cName = str(v.__class__) + if cName.find('.') != -1: + cName = cName.split('.')[-1] + + elif cName.find("'") != -1: # does not have '.' (could be something like ) + cName = cName[cName.index("'") + 1:] + + if cName.endswith("'>"): + cName = cName[:-2] + except: + cName = str(v.__class__) + + value = '%s: %s' % (cName, v) + else: + value = str(v) + except: + try: + value = repr(v) + except: + value = 'Unable to get repr for %s' % v.__class__ + + # fix to work with unicode values + try: + if not IS_PY3K: + if value.__class__ == unicode: # @UndefinedVariable + value = value.encode('utf-8', 'replace') + else: + if value.__class__ == bytes: + value = value.decode('utf-8', 'replace') + except TypeError: + pass + + return type_name, type_qualifier, is_exception_on_eval, resolver, value + + +def var_to_xml(val, name, trim_if_too_big=True, additional_in_xml='', evaluate_full_value=True): + """ single variable or dictionary to xml representation """ + + type_name, type_qualifier, is_exception_on_eval, resolver, value = get_variable_details( + val, evaluate_full_value) + + try: + name = quote(name, '/>_= ') # TODO: Fix PY-5834 without using quote + except: + pass + + xml = ' MAXIMUM_VARIABLE_REPRESENTATION_SIZE and trim_if_too_big: + value = value[0:MAXIMUM_VARIABLE_REPRESENTATION_SIZE] + value += '...' + + xml_value = ' value="%s"' % (make_valid_xml_value(quote(value, '/>_= '))) + else: + xml_value = '' + + if is_exception_on_eval: + xml_container = ' isErrorOnEval="True"' + else: + if resolver is not None: + xml_container = ' isContainer="True"' + else: + xml_container = '' + + return ''.join((xml, xml_qualifier, xml_value, xml_container, additional_in_xml, ' />\n')) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/.gitignore b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/.gitignore new file mode 100644 index 0000000..fdd8a24 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/.gitignore @@ -0,0 +1,2 @@ +/pydevd_frame_evaluator.*.so +/pydevd_frame_evaluator.*.pyd diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_cython_wrapper.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_cython_wrapper.py new file mode 100644 index 0000000..0864a4e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_cython_wrapper.py @@ -0,0 +1,43 @@ +try: + try: + from _pydevd_frame_eval_ext import pydevd_frame_evaluator as mod + except ImportError: + from _pydevd_frame_eval import pydevd_frame_evaluator as mod + +except ImportError: + try: + import sys + + try: + is_64bits = sys.maxsize > 2 ** 32 + except: + # In Jython this call fails, but this is Ok, we don't support Jython for speedups anyways. + raise ImportError + plat = '32' + if is_64bits: + plat = '64' + + # We also accept things as: + # + # _pydevd_frame_eval.pydevd_frame_evaluator_win32_27_32 + # _pydevd_frame_eval.pydevd_frame_evaluator_win32_34_64 + # + # to have multiple pre-compiled pyds distributed along the IDE + # (generated by build_tools/build_binaries_windows.py). + + mod_name = 'pydevd_frame_evaluator_%s_%s%s_%s' % (sys.platform, sys.version_info[0], sys.version_info[1], plat) + check_name = '_pydevd_frame_eval.%s' % (mod_name,) + mod = __import__(check_name) + mod = getattr(mod, mod_name) + except ImportError: + raise + +frame_eval_func = mod.frame_eval_func + +stop_frame_eval = mod.stop_frame_eval + +dummy_trace_dispatch = mod.dummy_trace_dispatch + +get_thread_info_py = mod.get_thread_info_py + +clear_thread_local_info = mod.clear_thread_local_info diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_main.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_main.py new file mode 100644 index 0000000..c9fa1c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_main.py @@ -0,0 +1,34 @@ +import os +import sys + +from _pydev_bundle import pydev_log + +IS_PY36_OR_GREATER = sys.version_info >= (3, 6) + +frame_eval_func = None +stop_frame_eval = None +dummy_trace_dispatch = None +clear_thread_local_info = None + +use_cython = os.getenv('PYDEVD_USE_CYTHON', None) + +# "NO" means we should not use frame evaluation, 'YES' we should use it (and fail if not there) and unspecified uses if possible. +use_frame_eval = os.environ.get('PYDEVD_USE_FRAME_EVAL', None) + +if use_frame_eval == 'NO' or use_cython == 'NO': + pass + +elif use_frame_eval == 'YES': + # Fail if unable to use + from _pydevd_frame_eval.pydevd_frame_eval_cython_wrapper import frame_eval_func, stop_frame_eval, dummy_trace_dispatch, clear_thread_local_info + +elif use_frame_eval is None: + # Try to use if possible + if IS_PY36_OR_GREATER: + try: + from _pydevd_frame_eval.pydevd_frame_eval_cython_wrapper import frame_eval_func, stop_frame_eval, dummy_trace_dispatch, clear_thread_local_info + except ImportError: + pydev_log.show_compile_cython_command_line() + +else: + raise RuntimeError('Unexpected value for PYDEVD_USE_FRAME_EVAL: %s (accepted: YES, NO)' % (use_frame_eval,)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.c b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.c new file mode 100644 index 0000000..9f70de6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.c @@ -0,0 +1,12573 @@ +/* Generated by Cython 0.29.8 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "depends": [ + "_pydevd_frame_eval\\release_mem.h" + ], + "include_dirs": [ + "_pydevd_frame_eval" + ], + "name": "_pydevd_frame_eval.pydevd_frame_evaluator", + "sources": [ + "_pydevd_frame_eval/pydevd_frame_evaluator.pyx" + ] + }, + "module_name": "_pydevd_frame_eval.pydevd_frame_evaluator" +} +END: Cython Metadata */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.6+ or Python 3.3+. +#else +#define CYTHON_ABI "0_29_8" +#define CYTHON_HEX_VERSION 0x001D08F0 +#define CYTHON_FUTURE_DIVISION 0 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x02070000 + #define HAVE_LONG_LONG + #endif +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#ifdef PYPY_VERSION + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int32 uint32_t; + #endif + #endif +#else + #include +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) && __cplusplus >= 201103L + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #elif __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__ ) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) + #define Py_OptimizeFlag 0 +#endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_DefaultClassType PyClass_Type +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#if PY_VERSION_HEX < 0x030800A4 + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif + #define __Pyx_DefaultClassType PyType_Type +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast + #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +#else +#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) +#endif +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) + #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact + #define PyObject_Unicode PyObject_Str +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) +#else + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func)) +#else + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + + +#define __PYX_ERR(f_index, lineno, Ln_error) \ +{ \ + __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ +} + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE___pydevd_frame_eval__pydevd_frame_evaluator +#define __PYX_HAVE_API___pydevd_frame_eval__pydevd_frame_evaluator +/* Early includes */ +#include "frameobject.h" +#include "release_mem.h" +#include "code.h" +#include "pystate.h" +#include "ceval.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { + const Py_UNICODE *u_end = u; + while (*u_end++) ; + return (size_t)(u_end - u - 1); +} +#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) +#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +static PyObject *__pyx_m = NULL; +static PyObject *__pyx_d; +static PyObject *__pyx_b; +static PyObject *__pyx_cython_runtime = NULL; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "_pydevd_frame_eval\\pydevd_frame_evaluator.pyx", + "stringsource", + "_pydevd_bundle\\pydevd_cython.pxd", +}; + +/*--- Type declarations ---*/ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo; +struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo; +struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo; + +/* "_pydevd_bundle/pydevd_cython.pxd":1 + * cdef class PyDBAdditionalThreadInfo: # <<<<<<<<<<<<<< + * cdef public int pydev_state; + * cdef public object pydev_step_stop; # Actually, it's a frame or None + */ +struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo { + PyObject_HEAD + int pydev_state; + PyObject *pydev_step_stop; + int pydev_original_step_cmd; + int pydev_step_cmd; + int pydev_notify_kill; + PyObject *pydev_smart_step_stop; + int pydev_django_resolve_frame; + PyObject *pydev_call_from_jinja2; + PyObject *pydev_call_inside_jinja2; + int is_tracing; + PyObject *conditional_breakpoint_exception; + PyObject *pydev_message; + int suspend_type; + int pydev_next_line; + PyObject *pydev_func_name; + int suspended_at_unhandled; + PyObject *trace_suspend_type; + PyObject *top_level_thread_tracer_no_back_frames; + PyObject *top_level_thread_tracer_unhandled; + PyObject *thread_tracer; +}; + + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":21 + * + * + * cdef class ThreadInfo: # <<<<<<<<<<<<<< + * + * cdef public PyDBAdditionalThreadInfo additional_info + */ +struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo { + PyObject_HEAD + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *additional_info; + int is_pydevd_thread; + int inside_frame_eval; + int fully_initialized; + PyObject *thread_trace_func; +}; + + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":69 + * + * + * cdef class FuncCodeInfo: # <<<<<<<<<<<<<< + * + * cdef public str co_filename + */ +struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo { + PyObject_HEAD + PyObject *co_filename; + PyObject *real_path; + int always_skip_code; + int breakpoint_found; + PyObject *new_code; + int breakpoints_mtime; +}; + + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectCallNoArg.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); +#else +#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) +#endif + +/* PyCFunctionFastCall.proto */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); +#else +#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) +#endif + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); + +/* PyObjectCall2Args.proto */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* GetAttr3.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* PyObjectLookupSpecial.proto */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) { + PyObject *res; + PyTypeObject *tp = Py_TYPE(obj); +#if PY_MAJOR_VERSION < 3 + if (unlikely(PyInstance_Check(obj))) + return __Pyx_PyObject_GetAttrStr(obj, attr_name); +#endif + res = _PyType_Lookup(tp, attr_name); + if (likely(res)) { + descrgetfunc f = Py_TYPE(res)->tp_descr_get; + if (!f) { + Py_INCREF(res); + } else { + res = f(res, obj, (PyObject *)tp); + } + } else { + PyErr_SetObject(PyExc_AttributeError, attr_name); + } + return res; +} +#else +#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) +#endif + +/* PyObjectSetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); +#else +#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) +#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) +#endif + +/* None.proto */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +/* ExtTypeTest.proto */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ + const char* function_name); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* StrEquals.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + +/* PyIntCompare.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace); + +/* DictGetItem.proto */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); +#define __Pyx_PyObject_Dict_GetItem(obj, name)\ + (likely(PyDict_CheckExact(obj)) ?\ + __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) +#else +#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) +#endif + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + +/* RaiseTooManyValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +/* RaiseNeedMoreValuesToUnpack.proto */ +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +/* IterFinish.proto */ +static CYTHON_INLINE int __Pyx_IterFinish(void); + +/* UnpackItemEndCheck.proto */ +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); + +/* PyDictContains.proto */ +static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) { + int result = PyDict_Contains(dict, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* WriteUnraisableException.proto */ +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename, + int full_traceback, int nogil); + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* HasAttr.proto */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PyObject_GenericGetAttr.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr +#endif + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* TypeImport.proto */ +#ifndef __PYX_HAVE_RT_ImportType_proto +#define __PYX_HAVE_RT_ImportType_proto +enum __Pyx_ImportType_CheckSize { + __Pyx_ImportType_CheckSize_Error = 0, + __Pyx_ImportType_CheckSize_Warn = 1, + __Pyx_ImportType_CheckSize_Ignore = 2 +}; +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +#endif + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + + +/* Module declarations from 'cpython.mem' */ + +/* Module declarations from '_pydevd_bundle.pydevd_cython' */ +static PyTypeObject *__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo = 0; + +/* Module declarations from '_pydevd_frame_eval.pydevd_frame_evaluator' */ +static PyTypeObject *__pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo = 0; +static PyTypeObject *__pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo = 0; +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_thread_info(void); /*proto*/ +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_func_code_info(PyFrameObject *, PyCodeObject *); /*proto*/ +static PyObject *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval(PyFrameObject *, int); /*proto*/ +static PyObject *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_ThreadInfo__set_state(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *, PyObject *); /*proto*/ +static PyObject *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_FuncCodeInfo__set_state(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *, PyObject *); /*proto*/ +#define __Pyx_MODULE_NAME "_pydevd_frame_eval.pydevd_frame_evaluator" +extern int __pyx_module_is_main__pydevd_frame_eval__pydevd_frame_evaluator; +int __pyx_module_is_main__pydevd_frame_eval__pydevd_frame_evaluator = 0; + +/* Implementation of '_pydevd_frame_eval.pydevd_frame_evaluator' */ +static PyObject *__pyx_builtin_AttributeError; +static const char __pyx_k__2[] = ""; +static const char __pyx_k_arg[] = "arg"; +static const char __pyx_k_dis[] = "dis"; +static const char __pyx_k_get[] = "get"; +static const char __pyx_k_new[] = "__new__"; +static const char __pyx_k_obj[] = "obj"; +static const char __pyx_k_call[] = "call"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_exit[] = "__exit__"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_enter[] = "__enter__"; +static const char __pyx_k_event[] = "event"; +static const char __pyx_k_frame[] = "frame"; +static const char __pyx_k_local[] = "local"; +static const char __pyx_k_mtime[] = "mtime"; +static const char __pyx_k_state[] = "state"; +static const char __pyx_k_active[] = "_active"; +static const char __pyx_k_f_back[] = "f_back"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_pickle[] = "pickle"; +static const char __pyx_k_plugin[] = "plugin"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_thread[] = "thread"; +static const char __pyx_k_update[] = "update"; +static const char __pyx_k_f_trace[] = "f_trace"; +static const char __pyx_k_can_skip[] = "can_skip"; +static const char __pyx_k_code_obj[] = "code_obj"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_decref_py[] = "decref_py"; +static const char __pyx_k_get_ident[] = "get_ident"; +static const char __pyx_k_pyx_state[] = "__pyx_state"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_threading[] = "threading"; +static const char __pyx_k_ThreadInfo[] = "ThreadInfo"; +static const char __pyx_k_global_dbg[] = "global_dbg"; +static const char __pyx_k_pyx_result[] = "__pyx_result"; +static const char __pyx_k_PickleError[] = "PickleError"; +static const char __pyx_k_breakpoints[] = "breakpoints"; +static const char __pyx_k_insert_code[] = "insert_code"; +static const char __pyx_k_thread_info[] = "thread_info"; +static const char __pyx_k_FuncCodeInfo[] = "FuncCodeInfo"; +static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; +static const char __pyx_k_stringsource[] = "stringsource"; +static const char __pyx_k_get_file_type[] = "get_file_type"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_AttributeError[] = "AttributeError"; +static const char __pyx_k_findlinestarts[] = "findlinestarts"; +static const char __pyx_k_set_trace_func[] = "set_trace_func"; +static const char __pyx_k_trace_dispatch[] = "trace_dispatch"; +static const char __pyx_k_additional_info[] = "additional_info"; +static const char __pyx_k_frame_eval_func[] = "frame_eval_func"; +static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_stop_frame_eval[] = "stop_frame_eval"; +static const char __pyx_k_code_extra_index[] = "_code_extra_index"; +static const char __pyx_k_pydevd_file_utils[] = "pydevd_file_utils"; +static const char __pyx_k_signature_factory[] = "signature_factory"; +static const char __pyx_k_thread_local_info[] = "_thread_local_info"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_get_thread_info_py[] = "get_thread_info_py"; +static const char __pyx_k_show_return_values[] = "show_return_values"; +static const char __pyx_k_get_cache_file_type[] = "get_cache_file_type"; +static const char __pyx_k_update_globals_dict[] = "update_globals_dict"; +static const char __pyx_k_GlobalDebuggerHolder[] = "GlobalDebuggerHolder"; +static const char __pyx_k_dummy_trace_dispatch[] = "dummy_trace_dispatch"; +static const char __pyx_k_dummy_tracing_holder[] = "dummy_tracing_holder"; +static const char __pyx_k_get_func_code_info_py[] = "get_func_code_info_py"; +static const char __pyx_k_has_plugin_line_breaks[] = "has_plugin_line_breaks"; +static const char __pyx_k_initialize_if_possible[] = "initialize_if_possible"; +static const char __pyx_k_is_pydev_daemon_thread[] = "is_pydev_daemon_thread"; +static const char __pyx_k_clear_thread_local_info[] = "clear_thread_local_info"; +static const char __pyx_k_pyx_unpickle_ThreadInfo[] = "__pyx_unpickle_ThreadInfo"; +static const char __pyx_k_pydevd_bundle_pydevd_comm[] = "_pydevd_bundle.pydevd_comm"; +static const char __pyx_k_pyx_unpickle_FuncCodeInfo[] = "__pyx_unpickle_FuncCodeInfo"; +static const char __pyx_k_break_on_caught_exceptions[] = "break_on_caught_exceptions"; +static const char __pyx_k_has_plugin_exception_breaks[] = "has_plugin_exception_breaks"; +static const char __pyx_k_NORM_PATHS_AND_BASE_CONTAINER[] = "NORM_PATHS_AND_BASE_CONTAINER"; +static const char __pyx_k_pydevd_frame_eval_pydevd_frame[] = "_pydevd_frame_eval.pydevd_frame_tracing"; +static const char __pyx_k_create_pydev_trace_code_wrapper[] = "create_pydev_trace_code_wrapper"; +static const char __pyx_k_get_abs_path_real_path_and_base[] = "get_abs_path_real_path_and_base_from_file"; +static const char __pyx_k_pydev_imps__pydev_saved_modules[] = "_pydev_imps._pydev_saved_modules"; +static const char __pyx_k_pydevd_bundle_pydevd_additional[] = "_pydevd_bundle.pydevd_additional_thread_info"; +static const char __pyx_k_pydevd_bundle_pydevd_trace_disp[] = "_pydevd_bundle.pydevd_trace_dispatch"; +static const char __pyx_k_pydevd_frame_eval_pydevd_modify[] = "_pydevd_frame_eval.pydevd_modify_bytecode"; +static const char __pyx_k_set_additional_thread_info_lock[] = "_set_additional_thread_info_lock"; +static const char __pyx_k_Incompatible_checksums_s_vs_0x2c[] = "Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))"; +static const char __pyx_k_Incompatible_checksums_s_vs_0xe2[] = "Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))"; +static const char __pyx_k_fix_top_level_trace_and_get_trac[] = "fix_top_level_trace_and_get_trace_func"; +static const char __pyx_k_pydevd_frame_eval_pydevd_frame_2[] = "_pydevd_frame_eval\\pydevd_frame_evaluator.pyx"; +static const char __pyx_k_pydevd_frame_eval_pydevd_frame_3[] = "_pydevd_frame_eval.pydevd_frame_evaluator"; +static PyObject *__pyx_n_s_AttributeError; +static PyObject *__pyx_n_s_FuncCodeInfo; +static PyObject *__pyx_n_s_GlobalDebuggerHolder; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0x2c; +static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xe2; +static PyObject *__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER; +static PyObject *__pyx_n_s_PickleError; +static PyObject *__pyx_n_s_ThreadInfo; +static PyObject *__pyx_kp_s__2; +static PyObject *__pyx_n_s_active; +static PyObject *__pyx_n_s_additional_info; +static PyObject *__pyx_n_s_arg; +static PyObject *__pyx_n_s_break_on_caught_exceptions; +static PyObject *__pyx_n_s_breakpoints; +static PyObject *__pyx_n_s_call; +static PyObject *__pyx_n_s_can_skip; +static PyObject *__pyx_n_s_clear_thread_local_info; +static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_code_extra_index; +static PyObject *__pyx_n_s_code_obj; +static PyObject *__pyx_n_s_create_pydev_trace_code_wrapper; +static PyObject *__pyx_n_s_decref_py; +static PyObject *__pyx_n_s_dict; +static PyObject *__pyx_n_s_dis; +static PyObject *__pyx_n_s_dummy_trace_dispatch; +static PyObject *__pyx_n_s_dummy_tracing_holder; +static PyObject *__pyx_n_s_enter; +static PyObject *__pyx_n_s_event; +static PyObject *__pyx_n_s_exit; +static PyObject *__pyx_n_s_f_back; +static PyObject *__pyx_n_s_f_trace; +static PyObject *__pyx_n_s_findlinestarts; +static PyObject *__pyx_n_s_fix_top_level_trace_and_get_trac; +static PyObject *__pyx_n_s_frame; +static PyObject *__pyx_n_s_frame_eval_func; +static PyObject *__pyx_n_s_get; +static PyObject *__pyx_n_s_get_abs_path_real_path_and_base; +static PyObject *__pyx_n_s_get_cache_file_type; +static PyObject *__pyx_n_s_get_file_type; +static PyObject *__pyx_n_s_get_func_code_info_py; +static PyObject *__pyx_n_s_get_ident; +static PyObject *__pyx_n_s_get_thread_info_py; +static PyObject *__pyx_n_s_getstate; +static PyObject *__pyx_n_s_global_dbg; +static PyObject *__pyx_n_s_has_plugin_exception_breaks; +static PyObject *__pyx_n_s_has_plugin_line_breaks; +static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_initialize_if_possible; +static PyObject *__pyx_n_s_insert_code; +static PyObject *__pyx_n_s_is_pydev_daemon_thread; +static PyObject *__pyx_n_s_local; +static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_mtime; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_n_s_new; +static PyObject *__pyx_n_s_obj; +static PyObject *__pyx_n_s_pickle; +static PyObject *__pyx_n_s_plugin; +static PyObject *__pyx_n_s_pydev_imps__pydev_saved_modules; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_additional; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_comm; +static PyObject *__pyx_n_s_pydevd_bundle_pydevd_trace_disp; +static PyObject *__pyx_n_s_pydevd_file_utils; +static PyObject *__pyx_n_s_pydevd_frame_eval_pydevd_frame; +static PyObject *__pyx_kp_s_pydevd_frame_eval_pydevd_frame_2; +static PyObject *__pyx_n_s_pydevd_frame_eval_pydevd_frame_3; +static PyObject *__pyx_n_s_pydevd_frame_eval_pydevd_modify; +static PyObject *__pyx_n_s_pyx_PickleError; +static PyObject *__pyx_n_s_pyx_checksum; +static PyObject *__pyx_n_s_pyx_result; +static PyObject *__pyx_n_s_pyx_state; +static PyObject *__pyx_n_s_pyx_type; +static PyObject *__pyx_n_s_pyx_unpickle_FuncCodeInfo; +static PyObject *__pyx_n_s_pyx_unpickle_ThreadInfo; +static PyObject *__pyx_n_s_reduce; +static PyObject *__pyx_n_s_reduce_cython; +static PyObject *__pyx_n_s_reduce_ex; +static PyObject *__pyx_n_s_set_additional_thread_info_lock; +static PyObject *__pyx_n_s_set_trace_func; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; +static PyObject *__pyx_n_s_show_return_values; +static PyObject *__pyx_n_s_signature_factory; +static PyObject *__pyx_n_s_state; +static PyObject *__pyx_n_s_stop_frame_eval; +static PyObject *__pyx_kp_s_stringsource; +static PyObject *__pyx_n_s_test; +static PyObject *__pyx_n_s_thread; +static PyObject *__pyx_n_s_thread_info; +static PyObject *__pyx_n_s_thread_local_info; +static PyObject *__pyx_n_s_threading; +static PyObject *__pyx_n_s_trace_dispatch; +static PyObject *__pyx_n_s_update; +static PyObject *__pyx_n_s_update_globals_dict; +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_clear_thread_local_info(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo___init__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_2initialize_if_possible(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_4__reduce_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_6__setstate_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo___init__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_2__reduce_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_4__setstate_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_2dummy_trace_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg); /* proto */ +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_4get_thread_info_py(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_6decref_py(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_obj); /* proto */ +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_8get_func_code_info_py(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_code_obj); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10frame_eval_func(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12stop_frame_eval(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_14__pyx_unpickle_ThreadInfo(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_16__pyx_unpickle_FuncCodeInfo(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_int_46987879; +static PyObject *__pyx_int_237773445; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_tuple_; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__7; +static PyObject *__pyx_tuple__9; +static PyObject *__pyx_tuple__11; +static PyObject *__pyx_tuple__13; +static PyObject *__pyx_tuple__15; +static PyObject *__pyx_tuple__17; +static PyObject *__pyx_codeobj__3; +static PyObject *__pyx_codeobj__5; +static PyObject *__pyx_codeobj__6; +static PyObject *__pyx_codeobj__8; +static PyObject *__pyx_codeobj__10; +static PyObject *__pyx_codeobj__12; +static PyObject *__pyx_codeobj__14; +static PyObject *__pyx_codeobj__16; +static PyObject *__pyx_codeobj__18; +/* Late includes */ + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":16 + * _thread_local_info = threading.local() + * + * def clear_thread_local_info(): # <<<<<<<<<<<<<< + * global _thread_local_info + * _thread_local_info = threading.local() + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_1clear_thread_local_info(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_1clear_thread_local_info = {"clear_thread_local_info", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_1clear_thread_local_info, METH_NOARGS, 0}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_1clear_thread_local_info(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("clear_thread_local_info (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_clear_thread_local_info(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_clear_thread_local_info(CYTHON_UNUSED PyObject *__pyx_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannySetupContext("clear_thread_local_info", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":18 + * def clear_thread_local_info(): + * global _thread_local_info + * _thread_local_info = threading.local() # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_threading); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_local); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 18, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_thread_local_info, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":16 + * _thread_local_info = threading.local() + * + * def clear_thread_local_info(): # <<<<<<<<<<<<<< + * global _thread_local_info + * _thread_local_info = threading.local() + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.clear_thread_local_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":29 + * cdef public object thread_trace_func + * + * def __init__(self): # <<<<<<<<<<<<<< + * self.additional_info = None + * self.is_pydevd_thread = False + */ + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo___init__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo___init__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":30 + * + * def __init__(self): + * self.additional_info = None # <<<<<<<<<<<<<< + * self.is_pydevd_thread = False + * self.inside_frame_eval = 0 + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->additional_info); + __Pyx_DECREF(((PyObject *)__pyx_v_self->additional_info)); + __pyx_v_self->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)Py_None); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":31 + * def __init__(self): + * self.additional_info = None + * self.is_pydevd_thread = False # <<<<<<<<<<<<<< + * self.inside_frame_eval = 0 + * self.fully_initialized = False + */ + __pyx_v_self->is_pydevd_thread = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":32 + * self.additional_info = None + * self.is_pydevd_thread = False + * self.inside_frame_eval = 0 # <<<<<<<<<<<<<< + * self.fully_initialized = False + * self.thread_trace_func = None + */ + __pyx_v_self->inside_frame_eval = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":33 + * self.is_pydevd_thread = False + * self.inside_frame_eval = 0 + * self.fully_initialized = False # <<<<<<<<<<<<<< + * self.thread_trace_func = None + * + */ + __pyx_v_self->fully_initialized = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":34 + * self.inside_frame_eval = 0 + * self.fully_initialized = False + * self.thread_trace_func = None # <<<<<<<<<<<<<< + * + * def initialize_if_possible(self): + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->thread_trace_func); + __Pyx_DECREF(__pyx_v_self->thread_trace_func); + __pyx_v_self->thread_trace_func = Py_None; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":29 + * cdef public object thread_trace_func + * + * def __init__(self): # <<<<<<<<<<<<<< + * self.additional_info = None + * self.is_pydevd_thread = False + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":36 + * self.thread_trace_func = None + * + * def initialize_if_possible(self): # <<<<<<<<<<<<<< + * # Don't call threading.currentThread because if we're too early in the process + * # we may create a dummy thread. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_3initialize_if_possible(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_3initialize_if_possible(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("initialize_if_possible (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_2initialize_if_possible(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_2initialize_if_possible(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_v_thread_ident = NULL; + PyObject *__pyx_v_t = NULL; + PyObject *__pyx_v_additional_info = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + int __pyx_t_18; + int __pyx_t_19; + char const *__pyx_t_20; + __Pyx_RefNannySetupContext("initialize_if_possible", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":39 + * # Don't call threading.currentThread because if we're too early in the process + * # we may create a dummy thread. + * self.inside_frame_eval += 1 # <<<<<<<<<<<<<< + * + * try: + */ + __pyx_v_self->inside_frame_eval = (__pyx_v_self->inside_frame_eval + 1); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":41 + * self.inside_frame_eval += 1 + * + * try: # <<<<<<<<<<<<<< + * thread_ident = threading.get_ident() # Note this is py3 only, if py2 needed to be supported, _get_ident would be needed. + * t = threading._active.get(thread_ident) + */ + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":42 + * + * try: + * thread_ident = threading.get_ident() # Note this is py3 only, if py2 needed to be supported, _get_ident would be needed. # <<<<<<<<<<<<<< + * t = threading._active.get(thread_ident) + * if t is None: + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_threading); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_ident); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 42, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_thread_ident = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":43 + * try: + * thread_ident = threading.get_ident() # Note this is py3 only, if py2 needed to be supported, _get_ident would be needed. + * t = threading._active.get(thread_ident) # <<<<<<<<<<<<<< + * if t is None: + * return # Cannot initialize until thread becomes active. + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_threading); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_active); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_thread_ident) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_thread_ident); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_t = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":44 + * thread_ident = threading.get_ident() # Note this is py3 only, if py2 needed to be supported, _get_ident would be needed. + * t = threading._active.get(thread_ident) + * if t is None: # <<<<<<<<<<<<<< + * return # Cannot initialize until thread becomes active. + * + */ + __pyx_t_4 = (__pyx_v_t == Py_None); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":45 + * t = threading._active.get(thread_ident) + * if t is None: + * return # Cannot initialize until thread becomes active. # <<<<<<<<<<<<<< + * + * if getattr(t, 'is_pydev_daemon_thread', False): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L3_return; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":44 + * thread_ident = threading.get_ident() # Note this is py3 only, if py2 needed to be supported, _get_ident would be needed. + * t = threading._active.get(thread_ident) + * if t is None: # <<<<<<<<<<<<<< + * return # Cannot initialize until thread becomes active. + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":47 + * return # Cannot initialize until thread becomes active. + * + * if getattr(t, 'is_pydev_daemon_thread', False): # <<<<<<<<<<<<<< + * self.is_pydevd_thread = True + * self.fully_initialized = True + */ + __pyx_t_1 = __Pyx_GetAttr3(__pyx_v_t, __pyx_n_s_is_pydev_daemon_thread, Py_False); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 47, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_5) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":48 + * + * if getattr(t, 'is_pydev_daemon_thread', False): + * self.is_pydevd_thread = True # <<<<<<<<<<<<<< + * self.fully_initialized = True + * else: + */ + __pyx_v_self->is_pydevd_thread = 1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":49 + * if getattr(t, 'is_pydev_daemon_thread', False): + * self.is_pydevd_thread = True + * self.fully_initialized = True # <<<<<<<<<<<<<< + * else: + * try: + */ + __pyx_v_self->fully_initialized = 1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":47 + * return # Cannot initialize until thread becomes active. + * + * if getattr(t, 'is_pydev_daemon_thread', False): # <<<<<<<<<<<<<< + * self.is_pydevd_thread = True + * self.fully_initialized = True + */ + goto __pyx_L7; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":51 + * self.fully_initialized = True + * else: + * try: # <<<<<<<<<<<<<< + * additional_info = t.additional_info + * if additional_info is None: + */ + /*else*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":52 + * else: + * try: + * additional_info = t.additional_info # <<<<<<<<<<<<<< + * if additional_info is None: + * raise AttributeError() + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_additional_info); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_additional_info = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":53 + * try: + * additional_info = t.additional_info + * if additional_info is None: # <<<<<<<<<<<<<< + * raise AttributeError() + * except: + */ + __pyx_t_5 = (__pyx_v_additional_info == Py_None); + __pyx_t_4 = (__pyx_t_5 != 0); + if (unlikely(__pyx_t_4)) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":54 + * additional_info = t.additional_info + * if additional_info is None: + * raise AttributeError() # <<<<<<<<<<<<<< + * except: + * with _set_additional_thread_info_lock: + */ + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_AttributeError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L8_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(0, 54, __pyx_L8_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":53 + * try: + * additional_info = t.additional_info + * if additional_info is None: # <<<<<<<<<<<<<< + * raise AttributeError() + * except: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":51 + * self.fully_initialized = True + * else: + * try: # <<<<<<<<<<<<<< + * additional_info = t.additional_info + * if additional_info is None: + */ + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L13_try_end; + __pyx_L8_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":55 + * if additional_info is None: + * raise AttributeError() + * except: # <<<<<<<<<<<<<< + * with _set_additional_thread_info_lock: + * # If it's not there, set it within a lock to avoid any racing + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.initialize_if_possible", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_2) < 0) __PYX_ERR(0, 55, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_2); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":56 + * raise AttributeError() + * except: + * with _set_additional_thread_info_lock: # <<<<<<<<<<<<<< + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + */ + /*with:*/ { + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_set_additional_thread_info_lock); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 56, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_PyObject_LookupSpecial(__pyx_t_9, __pyx_n_s_exit); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 56, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = __Pyx_PyObject_LookupSpecial(__pyx_t_9, __pyx_n_s_enter); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 56, __pyx_L17_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_12, function); + } + } + __pyx_t_11 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 56, __pyx_L17_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":59 + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + * additional_info = getattr(thread, 'additional_info', None) # <<<<<<<<<<<<<< + * if additional_info is None: + * additional_info = PyDBAdditionalThreadInfo() + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_thread); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 59, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_GetAttr3(__pyx_t_9, __pyx_n_s_additional_info, Py_None); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 59, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF_SET(__pyx_v_additional_info, __pyx_t_11); + __pyx_t_11 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":60 + * # conditions. + * additional_info = getattr(thread, 'additional_info', None) + * if additional_info is None: # <<<<<<<<<<<<<< + * additional_info = PyDBAdditionalThreadInfo() + * t.additional_info = additional_info + */ + __pyx_t_4 = (__pyx_v_additional_info == Py_None); + __pyx_t_5 = (__pyx_t_4 != 0); + if (__pyx_t_5) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":61 + * additional_info = getattr(thread, 'additional_info', None) + * if additional_info is None: + * additional_info = PyDBAdditionalThreadInfo() # <<<<<<<<<<<<<< + * t.additional_info = additional_info + * self.additional_info = additional_info + */ + __pyx_t_11 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 61, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF_SET(__pyx_v_additional_info, __pyx_t_11); + __pyx_t_11 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":60 + * # conditions. + * additional_info = getattr(thread, 'additional_info', None) + * if additional_info is None: # <<<<<<<<<<<<<< + * additional_info = PyDBAdditionalThreadInfo() + * t.additional_info = additional_info + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":62 + * if additional_info is None: + * additional_info = PyDBAdditionalThreadInfo() + * t.additional_info = additional_info # <<<<<<<<<<<<<< + * self.additional_info = additional_info + * self.fully_initialized = True + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_t, __pyx_n_s_additional_info, __pyx_v_additional_info) < 0) __PYX_ERR(0, 62, __pyx_L23_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":56 + * raise AttributeError() + * except: + * with _set_additional_thread_info_lock: # <<<<<<<<<<<<<< + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + */ + } + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L30_try_end; + __pyx_L23_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + /*except:*/ { + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.initialize_if_possible", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_9, &__pyx_t_12) < 0) __PYX_ERR(0, 56, __pyx_L25_except_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_Pack(3, __pyx_t_11, __pyx_t_9, __pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 56, __pyx_L25_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_13, NULL); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 56, __pyx_L25_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_17); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + if (__pyx_t_5 < 0) __PYX_ERR(0, 56, __pyx_L25_except_error) + __pyx_t_4 = ((!(__pyx_t_5 != 0)) != 0); + if (__pyx_t_4) { + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_GIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ErrRestoreWithState(__pyx_t_11, __pyx_t_9, __pyx_t_12); + __pyx_t_11 = 0; __pyx_t_9 = 0; __pyx_t_12 = 0; + __PYX_ERR(0, 56, __pyx_L25_except_error) + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L24_exception_handled; + } + __pyx_L25_except_error:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + goto __pyx_L10_except_error; + __pyx_L24_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_L30_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_10) { + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 56, __pyx_L10_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + goto __pyx_L22; + } + __pyx_L22:; + } + goto __pyx_L35; + __pyx_L17_error:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L10_except_error; + __pyx_L35:; + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L9_exception_handled; + } + __pyx_L10_except_error:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":51 + * self.fully_initialized = True + * else: + * try: # <<<<<<<<<<<<<< + * additional_info = t.additional_info + * if additional_info is None: + */ + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + goto __pyx_L4_error; + __pyx_L9_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + __pyx_L13_try_end:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":63 + * additional_info = PyDBAdditionalThreadInfo() + * t.additional_info = additional_info + * self.additional_info = additional_info # <<<<<<<<<<<<<< + * self.fully_initialized = True + * finally: + */ + if (unlikely(!__pyx_v_additional_info)) { __Pyx_RaiseUnboundLocalError("additional_info"); __PYX_ERR(0, 63, __pyx_L4_error) } + if (!(likely(((__pyx_v_additional_info) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_additional_info, __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo))))) __PYX_ERR(0, 63, __pyx_L4_error) + __pyx_t_2 = __pyx_v_additional_info; + __Pyx_INCREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->additional_info); + __Pyx_DECREF(((PyObject *)__pyx_v_self->additional_info)); + __pyx_v_self->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":64 + * t.additional_info = additional_info + * self.additional_info = additional_info + * self.fully_initialized = True # <<<<<<<<<<<<<< + * finally: + * self.inside_frame_eval -= 1 + */ + __pyx_v_self->fully_initialized = 1; + } + __pyx_L7:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":66 + * self.fully_initialized = True + * finally: + * self.inside_frame_eval -= 1 # <<<<<<<<<<<<<< + * + * + */ + /*finally:*/ { + /*normal exit:*/{ + __pyx_v_self->inside_frame_eval = (__pyx_v_self->inside_frame_eval - 1); + goto __pyx_L5; + } + __pyx_L4_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_10 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_16, &__pyx_t_15); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6) < 0)) __Pyx_ErrFetch(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_15); + __pyx_t_18 = __pyx_lineno; __pyx_t_19 = __pyx_clineno; __pyx_t_20 = __pyx_filename; + { + __pyx_v_self->inside_frame_eval = (__pyx_v_self->inside_frame_eval - 1); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_16, __pyx_t_15); + } + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_ErrRestore(__pyx_t_8, __pyx_t_7, __pyx_t_6); + __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_10 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; + __pyx_lineno = __pyx_t_18; __pyx_clineno = __pyx_t_19; __pyx_filename = __pyx_t_20; + goto __pyx_L1_error; + } + __pyx_L3_return: { + __pyx_t_15 = __pyx_r; + __pyx_r = 0; + __pyx_v_self->inside_frame_eval = (__pyx_v_self->inside_frame_eval - 1); + __pyx_r = __pyx_t_15; + __pyx_t_15 = 0; + goto __pyx_L0; + } + __pyx_L5:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":36 + * self.thread_trace_func = None + * + * def initialize_if_possible(self): # <<<<<<<<<<<<<< + * # Don't call threading.currentThread because if we're too early in the process + * # we may create a dummy thread. + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.initialize_if_possible", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_thread_ident); + __Pyx_XDECREF(__pyx_v_t); + __Pyx_XDECREF(__pyx_v_additional_info); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":23 + * cdef class ThreadInfo: + * + * cdef public PyDBAdditionalThreadInfo additional_info # <<<<<<<<<<<<<< + * cdef public bint is_pydevd_thread + * cdef public int inside_frame_eval + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->additional_info)); + __pyx_r = ((PyObject *)__pyx_v_self->additional_info); + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo))))) __PYX_ERR(0, 23, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->additional_info); + __Pyx_DECREF(((PyObject *)__pyx_v_self->additional_info)); + __pyx_v_self->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.additional_info.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_4__del__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->additional_info); + __Pyx_DECREF(((PyObject *)__pyx_v_self->additional_info)); + __pyx_v_self->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":24 + * + * cdef public PyDBAdditionalThreadInfo additional_info + * cdef public bint is_pydevd_thread # <<<<<<<<<<<<<< + * cdef public int inside_frame_eval + * cdef public bint fully_initialized + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_pydevd_thread); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.is_pydevd_thread.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 24, __pyx_L1_error) + __pyx_v_self->is_pydevd_thread = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.is_pydevd_thread.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":25 + * cdef public PyDBAdditionalThreadInfo additional_info + * cdef public bint is_pydevd_thread + * cdef public int inside_frame_eval # <<<<<<<<<<<<<< + * cdef public bint fully_initialized + * cdef public object thread_trace_func + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->inside_frame_eval); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.inside_frame_eval.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L1_error) + __pyx_v_self->inside_frame_eval = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.inside_frame_eval.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":26 + * cdef public bint is_pydevd_thread + * cdef public int inside_frame_eval + * cdef public bint fully_initialized # <<<<<<<<<<<<<< + * cdef public object thread_trace_func + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->fully_initialized); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.fully_initialized.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 26, __pyx_L1_error) + __pyx_v_self->fully_initialized = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.fully_initialized.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":27 + * cdef public int inside_frame_eval + * cdef public bint fully_initialized + * cdef public object thread_trace_func # <<<<<<<<<<<<<< + * + * def __init__(self): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->thread_trace_func); + __pyx_r = __pyx_v_self->thread_trace_func; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->thread_trace_func); + __Pyx_DECREF(__pyx_v_self->thread_trace_func); + __pyx_v_self->thread_trace_func = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_4__del__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->thread_trace_func); + __Pyx_DECREF(__pyx_v_self->thread_trace_func); + __pyx_v_self->thread_trace_func = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_5__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_4__reduce_cython__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_4__reduce_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.additional_info, self.fully_initialized, self.inside_frame_eval, self.is_pydevd_thread, self.thread_trace_func) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->fully_initialized); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->inside_frame_eval); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_self->is_pydevd_thread); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_self->additional_info)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->additional_info)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self->additional_info)); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_3); + __Pyx_INCREF(__pyx_v_self->thread_trace_func); + __Pyx_GIVEREF(__pyx_v_self->thread_trace_func); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_self->thread_trace_func); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.additional_info, self.fully_initialized, self.inside_frame_eval, self.is_pydevd_thread, self.thread_trace_func) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_4 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v__dict = __pyx_t_4; + __pyx_t_4 = 0; + + /* "(tree fragment)":7 + * state = (self.additional_info, self.fully_initialized, self.inside_frame_eval, self.is_pydevd_thread, self.thread_trace_func) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_5 = (__pyx_v__dict != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v__dict); + __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.additional_info is not None or self.thread_trace_func is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.additional_info, self.fully_initialized, self.inside_frame_eval, self.is_pydevd_thread, self.thread_trace_func) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.additional_info is not None or self.thread_trace_func is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, None), state + */ + /*else*/ { + __pyx_t_5 = (((PyObject *)__pyx_v_self->additional_info) != Py_None); + __pyx_t_7 = (__pyx_t_5 != 0); + if (!__pyx_t_7) { + } else { + __pyx_t_6 = __pyx_t_7; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_7 = (__pyx_v_self->thread_trace_func != Py_None); + __pyx_t_5 = (__pyx_t_7 != 0); + __pyx_t_6 = __pyx_t_5; + __pyx_L4_bool_binop_done:; + __pyx_v_use_setstate = __pyx_t_6; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.additional_info is not None or self.thread_trace_func is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, None), state + * else: + */ + __pyx_t_6 = (__pyx_v_use_setstate != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":13 + * use_setstate = self.additional_info is not None or self.thread_trace_func is not None + * if use_setstate: + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pyx_unpickle_ThreadInfo); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_46987879); + __Pyx_GIVEREF(__pyx_int_46987879); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_46987879); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_4, 2, Py_None); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.additional_info is not None or self.thread_trace_func is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, None), state + * else: + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_ThreadInfo__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_ThreadInfo); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_46987879); + __Pyx_GIVEREF(__pyx_int_46987879); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_46987879); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_state); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); + __pyx_t_2 = 0; + __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadInfo__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_7__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_6__setstate_cython__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_6__setstate_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_ThreadInfo__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_ThreadInfo__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_ThreadInfo, (type(self), 0x2ccfa67, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadInfo__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":82 + * cdef public int breakpoints_mtime + * + * def __init__(self): # <<<<<<<<<<<<<< + * self.co_filename = '' + * self.real_path = '' + */ + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo___init__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo___init__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":83 + * + * def __init__(self): + * self.co_filename = '' # <<<<<<<<<<<<<< + * self.real_path = '' + * self.always_skip_code = False + */ + __Pyx_INCREF(__pyx_kp_s__2); + __Pyx_GIVEREF(__pyx_kp_s__2); + __Pyx_GOTREF(__pyx_v_self->co_filename); + __Pyx_DECREF(__pyx_v_self->co_filename); + __pyx_v_self->co_filename = __pyx_kp_s__2; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":84 + * def __init__(self): + * self.co_filename = '' + * self.real_path = '' # <<<<<<<<<<<<<< + * self.always_skip_code = False + * + */ + __Pyx_INCREF(__pyx_kp_s__2); + __Pyx_GIVEREF(__pyx_kp_s__2); + __Pyx_GOTREF(__pyx_v_self->real_path); + __Pyx_DECREF(__pyx_v_self->real_path); + __pyx_v_self->real_path = __pyx_kp_s__2; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":85 + * self.co_filename = '' + * self.real_path = '' + * self.always_skip_code = False # <<<<<<<<<<<<<< + * + * # If breakpoints are found but new_code is None, + */ + __pyx_v_self->always_skip_code = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":90 + * # this means we weren't able to actually add the code + * # where needed, so, fallback to tracing. + * self.breakpoint_found = False # <<<<<<<<<<<<<< + * self.new_code = None + * self.breakpoints_mtime = -1 + */ + __pyx_v_self->breakpoint_found = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":91 + * # where needed, so, fallback to tracing. + * self.breakpoint_found = False + * self.new_code = None # <<<<<<<<<<<<<< + * self.breakpoints_mtime = -1 + * + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->new_code); + __Pyx_DECREF(__pyx_v_self->new_code); + __pyx_v_self->new_code = Py_None; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":92 + * self.breakpoint_found = False + * self.new_code = None + * self.breakpoints_mtime = -1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_self->breakpoints_mtime = -1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":82 + * cdef public int breakpoints_mtime + * + * def __init__(self): # <<<<<<<<<<<<<< + * self.co_filename = '' + * self.real_path = '' + */ + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":71 + * cdef class FuncCodeInfo: + * + * cdef public str co_filename # <<<<<<<<<<<<<< + * cdef public str real_path + * cdef bint always_skip_code + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->co_filename); + __pyx_r = __pyx_v_self->co_filename; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->co_filename); + __Pyx_DECREF(__pyx_v_self->co_filename); + __pyx_v_self->co_filename = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.co_filename.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_4__del__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->co_filename); + __Pyx_DECREF(__pyx_v_self->co_filename); + __pyx_v_self->co_filename = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":72 + * + * cdef public str co_filename + * cdef public str real_path # <<<<<<<<<<<<<< + * cdef bint always_skip_code + * cdef public bint breakpoint_found + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->real_path); + __pyx_r = __pyx_v_self->real_path; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = __pyx_v_value; + __Pyx_INCREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->real_path); + __Pyx_DECREF(__pyx_v_self->real_path); + __pyx_v_self->real_path = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.real_path.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_4__del__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->real_path); + __Pyx_DECREF(__pyx_v_self->real_path); + __pyx_v_self->real_path = ((PyObject*)Py_None); + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":74 + * cdef public str real_path + * cdef bint always_skip_code + * cdef public bint breakpoint_found # <<<<<<<<<<<<<< + * cdef public object new_code + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->breakpoint_found); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.breakpoint_found.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 74, __pyx_L1_error) + __pyx_v_self->breakpoint_found = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.breakpoint_found.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":75 + * cdef bint always_skip_code + * cdef public bint breakpoint_found + * cdef public object new_code # <<<<<<<<<<<<<< + * + * # When breakpoints_mtime != PyDb.mtime the validity of breakpoints have + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->new_code); + __pyx_r = __pyx_v_self->new_code; + goto __pyx_L0; + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->new_code); + __Pyx_DECREF(__pyx_v_self->new_code); + __pyx_v_self->new_code = __pyx_v_value; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_4__del__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_4__del__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->new_code); + __Pyx_DECREF(__pyx_v_self->new_code); + __pyx_v_self->new_code = Py_None; + + /* function exit code */ + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":80 + * # to be re-evaluated (if invalid a new FuncCodeInfo must be created and + * # tracing can't be disabled for the related frames). + * cdef public int breakpoints_mtime # <<<<<<<<<<<<<< + * + * def __init__(self): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime___get__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime___get__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->breakpoints_mtime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.breakpoints_mtime.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_2__set__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_2__set__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 80, __pyx_L1_error) + __pyx_v_self->breakpoints_mtime = __pyx_t_1; + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.breakpoints_mtime.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_3__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_2__reduce_cython__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_2__reduce_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.always_skip_code, self.breakpoint_found, self.breakpoints_mtime, self.co_filename, self.new_code, self.real_path) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->always_skip_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->breakpoint_found); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->breakpoints_mtime); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); + __Pyx_INCREF(__pyx_v_self->co_filename); + __Pyx_GIVEREF(__pyx_v_self->co_filename); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_self->co_filename); + __Pyx_INCREF(__pyx_v_self->new_code); + __Pyx_GIVEREF(__pyx_v_self->new_code); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_self->new_code); + __Pyx_INCREF(__pyx_v_self->real_path); + __Pyx_GIVEREF(__pyx_v_self->real_path); + PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_v_self->real_path); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.always_skip_code, self.breakpoint_found, self.breakpoints_mtime, self.co_filename, self.new_code, self.real_path) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_4 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_v__dict = __pyx_t_4; + __pyx_t_4 = 0; + + /* "(tree fragment)":7 + * state = (self.always_skip_code, self.breakpoint_found, self.breakpoints_mtime, self.co_filename, self.new_code, self.real_path) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_5 = (__pyx_v__dict != Py_None); + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v__dict); + __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.co_filename is not None or self.new_code is not None or self.real_path is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.always_skip_code, self.breakpoint_found, self.breakpoints_mtime, self.co_filename, self.new_code, self.real_path) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.co_filename is not None or self.new_code is not None or self.real_path is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, None), state + */ + /*else*/ { + __pyx_t_5 = (__pyx_v_self->co_filename != ((PyObject*)Py_None)); + __pyx_t_7 = (__pyx_t_5 != 0); + if (!__pyx_t_7) { + } else { + __pyx_t_6 = __pyx_t_7; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_7 = (__pyx_v_self->new_code != Py_None); + __pyx_t_5 = (__pyx_t_7 != 0); + if (!__pyx_t_5) { + } else { + __pyx_t_6 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = (__pyx_v_self->real_path != ((PyObject*)Py_None)); + __pyx_t_7 = (__pyx_t_5 != 0); + __pyx_t_6 = __pyx_t_7; + __pyx_L4_bool_binop_done:; + __pyx_v_use_setstate = __pyx_t_6; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.co_filename is not None or self.new_code is not None or self.real_path is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, None), state + * else: + */ + __pyx_t_6 = (__pyx_v_use_setstate != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":13 + * use_setstate = self.co_filename is not None or self.new_code is not None or self.real_path is not None + * if use_setstate: + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pyx_unpickle_FuncCodeInfo); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_237773445); + __Pyx_GIVEREF(__pyx_int_237773445); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_237773445); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + PyTuple_SET_ITEM(__pyx_t_4, 2, Py_None); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.co_filename is not None or self.new_code is not None or self.real_path is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, None), state + * else: + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_FuncCodeInfo__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_pyx_unpickle_FuncCodeInfo); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_INCREF(__pyx_int_237773445); + __Pyx_GIVEREF(__pyx_int_237773445); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_237773445); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_state); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4); + __pyx_t_2 = 0; + __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_FuncCodeInfo__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_5__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_4__setstate_cython__(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_4__setstate_cython__(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":17 + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_FuncCodeInfo__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_FuncCodeInfo__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_FuncCodeInfo, (type(self), 0xe2c2285, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_FuncCodeInfo__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":95 + * + * + * def dummy_trace_dispatch(frame, str event, arg): # <<<<<<<<<<<<<< + * if event == 'call': + * if frame.f_trace is not None: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_3dummy_trace_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_3dummy_trace_dispatch = {"dummy_trace_dispatch", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_3dummy_trace_dispatch, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_3dummy_trace_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_arg = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("dummy_trace_dispatch (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_event,&__pyx_n_s_arg,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_event)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("dummy_trace_dispatch", 1, 3, 3, 1); __PYX_ERR(0, 95, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_arg)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("dummy_trace_dispatch", 1, 3, 3, 2); __PYX_ERR(0, 95, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dummy_trace_dispatch") < 0)) __PYX_ERR(0, 95, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frame = values[0]; + __pyx_v_event = ((PyObject*)values[1]); + __pyx_v_arg = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("dummy_trace_dispatch", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 95, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.dummy_trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_event), (&PyString_Type), 1, "event", 1))) __PYX_ERR(0, 95, __pyx_L1_error) + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_2dummy_trace_dispatch(__pyx_self, __pyx_v_frame, __pyx_v_event, __pyx_v_arg); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_2dummy_trace_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_event, PyObject *__pyx_v_arg) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannySetupContext("dummy_trace_dispatch", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":96 + * + * def dummy_trace_dispatch(frame, str event, arg): + * if event == 'call': # <<<<<<<<<<<<<< + * if frame.f_trace is not None: + * return frame.f_trace(frame, event, arg) + */ + __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_event, __pyx_n_s_call, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":97 + * def dummy_trace_dispatch(frame, str event, arg): + * if event == 'call': + * if frame.f_trace is not None: # <<<<<<<<<<<<<< + * return frame.f_trace(frame, event, arg) + * return None + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 97, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = (__pyx_t_3 != Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_1 = (__pyx_t_2 != 0); + if (__pyx_t_1) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":98 + * if event == 'call': + * if frame.f_trace is not None: + * return frame.f_trace(frame, event, arg) # <<<<<<<<<<<<<< + * return None + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_frame, __pyx_v_event, __pyx_v_arg}; + __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_3); + } else + #endif + { + __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 98, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_frame); + __Pyx_INCREF(__pyx_v_event); + __Pyx_GIVEREF(__pyx_v_event); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_event); + __Pyx_INCREF(__pyx_v_arg); + __Pyx_GIVEREF(__pyx_v_arg); + PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_arg); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 98, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":97 + * def dummy_trace_dispatch(frame, str event, arg): + * if event == 'call': + * if frame.f_trace is not None: # <<<<<<<<<<<<<< + * return frame.f_trace(frame, event, arg) + * return None + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":96 + * + * def dummy_trace_dispatch(frame, str event, arg): + * if event == 'call': # <<<<<<<<<<<<<< + * if frame.f_trace is not None: + * return frame.f_trace(frame, event, arg) + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":99 + * if frame.f_trace is not None: + * return frame.f_trace(frame, event, arg) + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":95 + * + * + * def dummy_trace_dispatch(frame, str event, arg): # <<<<<<<<<<<<<< + * if event == 'call': + * if frame.f_trace is not None: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.dummy_trace_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":102 + * + * + * def get_thread_info_py() -> ThreadInfo: # <<<<<<<<<<<<<< + * return get_thread_info() + * + */ + +/* Python wrapper */ +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_5get_thread_info_py(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_5get_thread_info_py = {"get_thread_info_py", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_5get_thread_info_py, METH_NOARGS, 0}; +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_5get_thread_info_py(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_thread_info_py (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_4get_thread_info_py(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_4get_thread_info_py(CYTHON_UNUSED PyObject *__pyx_self) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("get_thread_info_py", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":103 + * + * def get_thread_info_py() -> ThreadInfo: + * return get_thread_info() # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_t_1 = ((PyObject *)__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_thread_info()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":102 + * + * + * def get_thread_info_py() -> ThreadInfo: # <<<<<<<<<<<<<< + * return get_thread_info() + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_thread_info_py", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":106 + * + * + * cdef ThreadInfo get_thread_info(): # <<<<<<<<<<<<<< + * ''' + * Provides thread-related info. + */ + +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_thread_info(void) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_thread_info = 0; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_t_12; + char const *__pyx_t_13; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + __Pyx_RefNannySetupContext("get_thread_info", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":113 + * ''' + * cdef ThreadInfo thread_info + * try: # <<<<<<<<<<<<<< + * # Note: changing to a `dict[thread.ident] = thread_info` had almost no + * # effect in the performance. + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":116 + * # Note: changing to a `dict[thread.ident] = thread_info` had almost no + * # effect in the performance. + * thread_info = _thread_local_info.thread_info # <<<<<<<<<<<<<< + * except: + * thread_info = ThreadInfo() + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_thread_local_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_thread_info); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo))))) __PYX_ERR(0, 116, __pyx_L3_error) + __pyx_v_thread_info = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":113 + * ''' + * cdef ThreadInfo thread_info + * try: # <<<<<<<<<<<<<< + * # Note: changing to a `dict[thread.ident] = thread_info` had almost no + * # effect in the performance. + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":117 + * # effect in the performance. + * thread_info = _thread_local_info.thread_info + * except: # <<<<<<<<<<<<<< + * thread_info = ThreadInfo() + * thread_info.inside_frame_eval += 1 + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_thread_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(0, 117, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_6); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":118 + * thread_info = _thread_local_info.thread_info + * except: + * thread_info = ThreadInfo() # <<<<<<<<<<<<<< + * thread_info.inside_frame_eval += 1 + * try: + */ + __pyx_t_7 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 118, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_XDECREF_SET(__pyx_v_thread_info, ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_t_7)); + __pyx_t_7 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":119 + * except: + * thread_info = ThreadInfo() + * thread_info.inside_frame_eval += 1 # <<<<<<<<<<<<<< + * try: + * _thread_local_info.thread_info = thread_info + */ + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval + 1); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":120 + * thread_info = ThreadInfo() + * thread_info.inside_frame_eval += 1 + * try: # <<<<<<<<<<<<<< + * _thread_local_info.thread_info = thread_info + * + */ + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":121 + * thread_info.inside_frame_eval += 1 + * try: + * _thread_local_info.thread_info = thread_info # <<<<<<<<<<<<<< + * + * # Note: _code_extra_index is not actually thread-related, + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_thread_local_info); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 121, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_PyObject_SetAttrStr(__pyx_t_7, __pyx_n_s_thread_info, ((PyObject *)__pyx_v_thread_info)) < 0) __PYX_ERR(0, 121, __pyx_L14_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":126 + * # but this is a good point to initialize it. + * global _code_extra_index + * if _code_extra_index == -1: # <<<<<<<<<<<<<< + * _code_extra_index = _PyEval_RequestCodeExtraIndex(release_co_extra) + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_code_extra_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 126, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyInt_EqObjC(__pyx_t_7, __pyx_int_neg_1, -1L, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 126, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 126, __pyx_L14_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_9) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":127 + * global _code_extra_index + * if _code_extra_index == -1: + * _code_extra_index = _PyEval_RequestCodeExtraIndex(release_co_extra) # <<<<<<<<<<<<<< + * + * thread_info.initialize_if_possible() + */ + __pyx_t_8 = __Pyx_PyInt_From_int(_PyEval_RequestCodeExtraIndex(release_co_extra)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 127, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_code_extra_index, __pyx_t_8) < 0) __PYX_ERR(0, 127, __pyx_L14_error) + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":126 + * # but this is a good point to initialize it. + * global _code_extra_index + * if _code_extra_index == -1: # <<<<<<<<<<<<<< + * _code_extra_index = _PyEval_RequestCodeExtraIndex(release_co_extra) + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":129 + * _code_extra_index = _PyEval_RequestCodeExtraIndex(release_co_extra) + * + * thread_info.initialize_if_possible() # <<<<<<<<<<<<<< + * finally: + * thread_info.inside_frame_eval -= 1 + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_thread_info), __pyx_n_s_initialize_if_possible); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_10 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_10)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + } + } + __pyx_t_8 = (__pyx_t_10) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_10) : __Pyx_PyObject_CallNoArg(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 129, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":131 + * thread_info.initialize_if_possible() + * finally: + * thread_info.inside_frame_eval -= 1 # <<<<<<<<<<<<<< + * + * return thread_info + */ + /*finally:*/ { + /*normal exit:*/{ + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval - 1); + goto __pyx_L15; + } + __pyx_L14_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __pyx_t_11 = __pyx_lineno; __pyx_t_12 = __pyx_clineno; __pyx_t_13 = __pyx_filename; + { + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval - 1); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_18, __pyx_t_19); + } + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ErrRestore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; + __pyx_lineno = __pyx_t_11; __pyx_clineno = __pyx_t_12; __pyx_filename = __pyx_t_13; + goto __pyx_L5_except_error; + } + __pyx_L15:; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L4_exception_handled; + } + __pyx_L5_except_error:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":113 + * ''' + * cdef ThreadInfo thread_info + * try: # <<<<<<<<<<<<<< + * # Note: changing to a `dict[thread.ident] = thread_info` had almost no + * # effect in the performance. + */ + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":133 + * thread_info.inside_frame_eval -= 1 + * + * return thread_info # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_thread_info)); + __pyx_r = __pyx_v_thread_info; + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":106 + * + * + * cdef ThreadInfo get_thread_info(): # <<<<<<<<<<<<<< + * ''' + * Provides thread-related info. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_thread_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_thread_info); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":136 + * + * + * def decref_py(obj): # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_7decref_py(PyObject *__pyx_self, PyObject *__pyx_v_obj); /*proto*/ +static char __pyx_doc_18_pydevd_frame_eval_22pydevd_frame_evaluator_6decref_py[] = "\n Helper to be called from Python.\n "; +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_7decref_py = {"decref_py", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_7decref_py, METH_O, __pyx_doc_18_pydevd_frame_eval_22pydevd_frame_evaluator_6decref_py}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_7decref_py(PyObject *__pyx_self, PyObject *__pyx_v_obj) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("decref_py (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_6decref_py(__pyx_self, ((PyObject *)__pyx_v_obj)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_6decref_py(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_obj) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("decref_py", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":140 + * Helper to be called from Python. + * ''' + * Py_DECREF(obj) # <<<<<<<<<<<<<< + * + * + */ + Py_DECREF(__pyx_v_obj); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":136 + * + * + * def decref_py(obj): # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":143 + * + * + * def get_func_code_info_py(frame, code_obj) -> FuncCodeInfo: # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + +/* Python wrapper */ +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_9get_func_code_info_py(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_18_pydevd_frame_eval_22pydevd_frame_evaluator_8get_func_code_info_py[] = "\n Helper to be called from Python.\n "; +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_9get_func_code_info_py = {"get_func_code_info_py", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_9get_func_code_info_py, METH_VARARGS|METH_KEYWORDS, __pyx_doc_18_pydevd_frame_eval_22pydevd_frame_evaluator_8get_func_code_info_py}; +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_9get_func_code_info_py(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frame = 0; + PyObject *__pyx_v_code_obj = 0; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_func_code_info_py (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_frame,&__pyx_n_s_code_obj,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_frame)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_code_obj)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_func_code_info_py", 1, 2, 2, 1); __PYX_ERR(0, 143, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_func_code_info_py") < 0)) __PYX_ERR(0, 143, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_frame = values[0]; + __pyx_v_code_obj = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_func_code_info_py", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 143, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_func_code_info_py", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_8get_func_code_info_py(__pyx_self, __pyx_v_frame, __pyx_v_code_obj); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_8get_func_code_info_py(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_frame, PyObject *__pyx_v_code_obj) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("get_func_code_info_py", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":147 + * Helper to be called from Python. + * ''' + * return get_func_code_info( frame, code_obj) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_t_1 = ((PyObject *)__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_func_code_info(((PyFrameObject *)__pyx_v_frame), ((PyCodeObject *)__pyx_v_code_obj))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":143 + * + * + * def get_func_code_info_py(frame, code_obj) -> FuncCodeInfo: # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_func_code_info_py", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":152 + * _code_extra_index: Py_SIZE = -1 + * + * cdef FuncCodeInfo get_func_code_info(PyFrameObject * frame_obj, PyCodeObject * code_obj): # <<<<<<<<<<<<<< + * ''' + * Provides code-object related info. + */ + +static struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_func_code_info(PyFrameObject *__pyx_v_frame_obj, PyCodeObject *__pyx_v_code_obj) { + PyObject *__pyx_v_main_debugger = 0; + PyObject *__pyx_v_extra; + PyObject *__pyx_v_extra_obj; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_func_code_info_obj = NULL; + PyObject *__pyx_v_co_filename = 0; + CYTHON_UNUSED PyObject *__pyx_v_co_name = 0; + PyObject *__pyx_v_break_at_lines = 0; + PyObject *__pyx_v_cache_file_type = 0; + PyObject *__pyx_v_cache_file_type_key = 0; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_func_code_info = NULL; + PyObject *__pyx_v_abs_path_real_path_and_base = NULL; + PyObject *__pyx_v_file_type = NULL; + CYTHON_UNUSED int __pyx_v_was_break; + PyObject *__pyx_v_breakpoints = 0; + PyObject *__pyx_v_code_obj_py = 0; + PyObject *__pyx_v_new_code = NULL; + CYTHON_UNUSED PyObject *__pyx_v_offset = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_success = NULL; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + PyObject *(*__pyx_t_15)(PyObject *); + PyObject *(*__pyx_t_16)(PyObject *); + int __pyx_t_17; + __Pyx_RefNannySetupContext("get_func_code_info", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":167 + * # print('get_func_code_info', f_code.co_name, f_code.co_filename) + * + * cdef object main_debugger = GlobalDebuggerHolder.global_dbg # <<<<<<<<<<<<<< + * + * cdef PyObject * extra + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_GlobalDebuggerHolder); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_global_dbg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_main_debugger = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":170 + * + * cdef PyObject * extra + * _PyCode_GetExtra( code_obj, _code_extra_index, & extra) # <<<<<<<<<<<<<< + * if extra is not NULL: + * extra_obj = extra + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_code_extra_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + (void)(_PyCode_GetExtra(((PyObject *)__pyx_v_code_obj), __pyx_t_3, (&__pyx_v_extra))); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":171 + * cdef PyObject * extra + * _PyCode_GetExtra( code_obj, _code_extra_index, & extra) + * if extra is not NULL: # <<<<<<<<<<<<<< + * extra_obj = extra + * if extra_obj is not NULL: + */ + __pyx_t_4 = ((__pyx_v_extra != NULL) != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":172 + * _PyCode_GetExtra( code_obj, _code_extra_index, & extra) + * if extra is not NULL: + * extra_obj = extra # <<<<<<<<<<<<<< + * if extra_obj is not NULL: + * func_code_info_obj = extra_obj + */ + __pyx_v_extra_obj = ((PyObject *)__pyx_v_extra); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":173 + * if extra is not NULL: + * extra_obj = extra + * if extra_obj is not NULL: # <<<<<<<<<<<<<< + * func_code_info_obj = extra_obj + * if func_code_info_obj.breakpoints_mtime == main_debugger.mtime: + */ + __pyx_t_4 = ((__pyx_v_extra_obj != NULL) != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":174 + * extra_obj = extra + * if extra_obj is not NULL: + * func_code_info_obj = extra_obj # <<<<<<<<<<<<<< + * if func_code_info_obj.breakpoints_mtime == main_debugger.mtime: + * # if DEBUG: + */ + __pyx_t_2 = ((PyObject *)__pyx_v_extra_obj); + __Pyx_INCREF(__pyx_t_2); + __pyx_v_func_code_info_obj = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":175 + * if extra_obj is not NULL: + * func_code_info_obj = extra_obj + * if func_code_info_obj.breakpoints_mtime == main_debugger.mtime: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_func_code_info: matched mtime', f_code.co_name, f_code.co_filename) + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_func_code_info_obj->breakpoints_mtime); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_mtime); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 175, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 175, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":179 + * # print('get_func_code_info: matched mtime', f_code.co_name, f_code.co_filename) + * + * return func_code_info_obj # <<<<<<<<<<<<<< + * + * cdef str co_filename = code_obj.co_filename + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_func_code_info_obj)); + __pyx_r = __pyx_v_func_code_info_obj; + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":175 + * if extra_obj is not NULL: + * func_code_info_obj = extra_obj + * if func_code_info_obj.breakpoints_mtime == main_debugger.mtime: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_func_code_info: matched mtime', f_code.co_name, f_code.co_filename) + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":173 + * if extra is not NULL: + * extra_obj = extra + * if extra_obj is not NULL: # <<<<<<<<<<<<<< + * func_code_info_obj = extra_obj + * if func_code_info_obj.breakpoints_mtime == main_debugger.mtime: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":171 + * cdef PyObject * extra + * _PyCode_GetExtra( code_obj, _code_extra_index, & extra) + * if extra is not NULL: # <<<<<<<<<<<<<< + * extra_obj = extra + * if extra_obj is not NULL: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":181 + * return func_code_info_obj + * + * cdef str co_filename = code_obj.co_filename # <<<<<<<<<<<<<< + * cdef str co_name = code_obj.co_name + * cdef set break_at_lines + */ + __pyx_t_5 = ((PyObject *)__pyx_v_code_obj->co_filename); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_co_filename = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":182 + * + * cdef str co_filename = code_obj.co_filename + * cdef str co_name = code_obj.co_name # <<<<<<<<<<<<<< + * cdef set break_at_lines + * cdef dict cache_file_type + */ + __pyx_t_5 = ((PyObject *)__pyx_v_code_obj->co_name); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_co_name = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":187 + * cdef tuple cache_file_type_key + * + * func_code_info = FuncCodeInfo() # <<<<<<<<<<<<<< + * func_code_info.breakpoints_mtime = main_debugger.mtime + * + */ + __pyx_t_5 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 187, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_func_code_info = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":188 + * + * func_code_info = FuncCodeInfo() + * func_code_info.breakpoints_mtime = main_debugger.mtime # <<<<<<<<<<<<<< + * + * func_code_info.co_filename = co_filename + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_mtime); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 188, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_func_code_info->breakpoints_mtime = __pyx_t_6; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":190 + * func_code_info.breakpoints_mtime = main_debugger.mtime + * + * func_code_info.co_filename = co_filename # <<<<<<<<<<<<<< + * + * if not func_code_info.always_skip_code: + */ + __Pyx_INCREF(__pyx_v_co_filename); + __Pyx_GIVEREF(__pyx_v_co_filename); + __Pyx_GOTREF(__pyx_v_func_code_info->co_filename); + __Pyx_DECREF(__pyx_v_func_code_info->co_filename); + __pyx_v_func_code_info->co_filename = __pyx_v_co_filename; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":192 + * func_code_info.co_filename = co_filename + * + * if not func_code_info.always_skip_code: # <<<<<<<<<<<<<< + * try: + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + */ + __pyx_t_4 = ((!(__pyx_v_func_code_info->always_skip_code != 0)) != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":193 + * + * if not func_code_info.always_skip_code: + * try: # <<<<<<<<<<<<<< + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":194 + * if not func_code_info.always_skip_code: + * try: + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] # <<<<<<<<<<<<<< + * except: + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(co_filename) + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 194, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_t_5, __pyx_v_co_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_abs_path_real_path_and_base = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":193 + * + * if not func_code_info.always_skip_code: + * try: # <<<<<<<<<<<<<< + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + * except: + */ + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L12_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":195 + * try: + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + * except: # <<<<<<<<<<<<<< + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(co_filename) + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_func_code_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_2) < 0) __PYX_ERR(0, 195, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_2); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":196 + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + * except: + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(co_filename) # <<<<<<<<<<<<<< + * + * func_code_info.real_path = abs_path_real_path_and_base[1] + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 196, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_10 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_v_co_filename) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_co_filename); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 196, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v_abs_path_real_path_and_base, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":193 + * + * if not func_code_info.always_skip_code: + * try: # <<<<<<<<<<<<<< + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + * except: + */ + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + __pyx_L12_try_end:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":198 + * abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(co_filename) + * + * func_code_info.real_path = abs_path_real_path_and_base[1] # <<<<<<<<<<<<<< + * + * cache_file_type = main_debugger.get_cache_file_type() + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_abs_path_real_path_and_base, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 198, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (!(likely(PyString_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 198, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_func_code_info->real_path); + __Pyx_DECREF(__pyx_v_func_code_info->real_path); + __pyx_v_func_code_info->real_path = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":200 + * func_code_info.real_path = abs_path_real_path_and_base[1] + * + * cache_file_type = main_debugger.get_cache_file_type() # <<<<<<<<<<<<<< + * # Note: this cache key must be the same from PyDB.get_file_type() -- see it for comments + * # on the cache. + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_get_cache_file_type); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 200, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!(likely(PyDict_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 200, __pyx_L1_error) + __pyx_v_cache_file_type = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":203 + * # Note: this cache key must be the same from PyDB.get_file_type() -- see it for comments + * # on the cache. + * cache_file_type_key = (frame_obj.f_code.co_firstlineno, abs_path_real_path_and_base[0], frame_obj.f_code) # <<<<<<<<<<<<<< + * try: + * file_type = cache_file_type[cache_file_type_key] # Make it faster + */ + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_frame_obj->f_code->co_firstlineno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_abs_path_real_path_and_base, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_frame_obj->f_code)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_frame_obj->f_code)); + PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_frame_obj->f_code)); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_v_cache_file_type_key = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":204 + * # on the cache. + * cache_file_type_key = (frame_obj.f_code.co_firstlineno, abs_path_real_path_and_base[0], frame_obj.f_code) + * try: # <<<<<<<<<<<<<< + * file_type = cache_file_type[cache_file_type_key] # Make it faster + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":205 + * cache_file_type_key = (frame_obj.f_code.co_firstlineno, abs_path_real_path_and_base[0], frame_obj.f_code) + * try: + * file_type = cache_file_type[cache_file_type_key] # Make it faster # <<<<<<<<<<<<<< + * except: + * file_type = main_debugger.get_file_type(frame_obj, abs_path_real_path_and_base) # we don't want to debug anything related to pydevd + */ + if (unlikely(__pyx_v_cache_file_type == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 205, __pyx_L15_error) + } + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_cache_file_type, __pyx_v_cache_file_type_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L15_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_file_type = __pyx_t_1; + __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":204 + * # on the cache. + * cache_file_type_key = (frame_obj.f_code.co_firstlineno, abs_path_real_path_and_base[0], frame_obj.f_code) + * try: # <<<<<<<<<<<<<< + * file_type = cache_file_type[cache_file_type_key] # Make it faster + * except: + */ + } + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L20_try_end; + __pyx_L15_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":206 + * try: + * file_type = cache_file_type[cache_file_type_key] # Make it faster + * except: # <<<<<<<<<<<<<< + * file_type = main_debugger.get_file_type(frame_obj, abs_path_real_path_and_base) # we don't want to debug anything related to pydevd + * + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_func_code_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_2) < 0) __PYX_ERR(0, 206, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_2); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":207 + * file_type = cache_file_type[cache_file_type_key] # Make it faster + * except: + * file_type = main_debugger.get_file_type(frame_obj, abs_path_real_path_and_base) # we don't want to debug anything related to pydevd # <<<<<<<<<<<<<< + * + * if file_type is not None: + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_get_file_type); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 207, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, ((PyObject *)__pyx_v_frame_obj), __pyx_v_abs_path_real_path_and_base}; + __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 207, __pyx_L17_except_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) { + PyObject *__pyx_temp[3] = {__pyx_t_12, ((PyObject *)__pyx_v_frame_obj), __pyx_v_abs_path_real_path_and_base}; + __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 207, __pyx_L17_except_error) + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else + #endif + { + __pyx_t_13 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 207, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_13); + if (__pyx_t_12) { + __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_frame_obj)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_frame_obj)); + PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_6, ((PyObject *)__pyx_v_frame_obj)); + __Pyx_INCREF(__pyx_v_abs_path_real_path_and_base); + __Pyx_GIVEREF(__pyx_v_abs_path_real_path_and_base); + PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_6, __pyx_v_abs_path_real_path_and_base); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 207, __pyx_L17_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF_SET(__pyx_v_file_type, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L16_exception_handled; + } + __pyx_L17_except_error:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":204 + * # on the cache. + * cache_file_type_key = (frame_obj.f_code.co_firstlineno, abs_path_real_path_and_base[0], frame_obj.f_code) + * try: # <<<<<<<<<<<<<< + * file_type = cache_file_type[cache_file_type_key] # Make it faster + * except: + */ + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_8, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L16_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_8, __pyx_t_7); + __pyx_L20_try_end:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":209 + * file_type = main_debugger.get_file_type(frame_obj, abs_path_real_path_and_base) # we don't want to debug anything related to pydevd + * + * if file_type is not None: # <<<<<<<<<<<<<< + * func_code_info.always_skip_code = True + * + */ + __pyx_t_4 = (__pyx_v_file_type != Py_None); + __pyx_t_14 = (__pyx_t_4 != 0); + if (__pyx_t_14) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":210 + * + * if file_type is not None: + * func_code_info.always_skip_code = True # <<<<<<<<<<<<<< + * + * if not func_code_info.always_skip_code: + */ + __pyx_v_func_code_info->always_skip_code = 1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":209 + * file_type = main_debugger.get_file_type(frame_obj, abs_path_real_path_and_base) # we don't want to debug anything related to pydevd + * + * if file_type is not None: # <<<<<<<<<<<<<< + * func_code_info.always_skip_code = True + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":192 + * func_code_info.co_filename = co_filename + * + * if not func_code_info.always_skip_code: # <<<<<<<<<<<<<< + * try: + * abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":212 + * func_code_info.always_skip_code = True + * + * if not func_code_info.always_skip_code: # <<<<<<<<<<<<<< + * was_break: bool = False + * if main_debugger is not None: + */ + __pyx_t_14 = ((!(__pyx_v_func_code_info->always_skip_code != 0)) != 0); + if (__pyx_t_14) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":213 + * + * if not func_code_info.always_skip_code: + * was_break: bool = False # <<<<<<<<<<<<<< + * if main_debugger is not None: + * breakpoints: dict = main_debugger.breakpoints.get(func_code_info.real_path) + */ + __pyx_v_was_break = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":214 + * if not func_code_info.always_skip_code: + * was_break: bool = False + * if main_debugger is not None: # <<<<<<<<<<<<<< + * breakpoints: dict = main_debugger.breakpoints.get(func_code_info.real_path) + * # print('\n---') + */ + __pyx_t_14 = (__pyx_v_main_debugger != Py_None); + __pyx_t_4 = (__pyx_t_14 != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":215 + * was_break: bool = False + * if main_debugger is not None: + * breakpoints: dict = main_debugger.breakpoints.get(func_code_info.real_path) # <<<<<<<<<<<<<< + * # print('\n---') + * # print(main_debugger.breakpoints) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_breakpoints); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + } + } + __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_v_func_code_info->real_path) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_func_code_info->real_path); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(PyDict_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_v_breakpoints = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":220 + * # print(func_code_info.real_path) + * # print(main_debugger.breakpoints.get(func_code_info.real_path)) + * code_obj_py: object = code_obj # <<<<<<<<<<<<<< + * if breakpoints: + * # if DEBUG: + */ + __pyx_t_2 = ((PyObject *)__pyx_v_code_obj); + __Pyx_INCREF(__pyx_t_2); + __pyx_v_code_obj_py = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":221 + * # print(main_debugger.breakpoints.get(func_code_info.real_path)) + * code_obj_py: object = code_obj + * if breakpoints: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('found breakpoints', code_obj_py.co_name, breakpoints) + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_breakpoints); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 221, __pyx_L1_error) + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":224 + * # if DEBUG: + * # print('found breakpoints', code_obj_py.co_name, breakpoints) + * break_at_lines = set() # <<<<<<<<<<<<<< + * new_code = None + * for offset, line in dis.findlinestarts(code_obj_py): + */ + __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 224, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_break_at_lines = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":225 + * # print('found breakpoints', code_obj_py.co_name, breakpoints) + * break_at_lines = set() + * new_code = None # <<<<<<<<<<<<<< + * for offset, line in dis.findlinestarts(code_obj_py): + * if line in breakpoints: + */ + __Pyx_INCREF(Py_None); + __pyx_v_new_code = Py_None; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":226 + * break_at_lines = set() + * new_code = None + * for offset, line in dis.findlinestarts(code_obj_py): # <<<<<<<<<<<<<< + * if line in breakpoints: + * # breakpoint = breakpoints[line] + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_dis); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_findlinestarts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_1, __pyx_v_code_obj_py) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_code_obj_py); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = 0; + __pyx_t_15 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_15 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 226, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (likely(!__pyx_t_15)) { + if (likely(PyList_CheckExact(__pyx_t_5))) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 226, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } else { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 226, __pyx_L1_error) + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + #endif + } + } else { + __pyx_t_2 = __pyx_t_15(__pyx_t_5); + if (unlikely(!__pyx_t_2)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 226, __pyx_L1_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 226, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 226, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_16 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_16(__pyx_t_11); if (unlikely(!__pyx_t_1)) goto __pyx_L29_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_10 = __pyx_t_16(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L29_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_11), 2) < 0) __PYX_ERR(0, 226, __pyx_L1_error) + __pyx_t_16 = NULL; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L30_unpacking_done; + __pyx_L29_unpacking_failed:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_16 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 226, __pyx_L1_error) + __pyx_L30_unpacking_done:; + } + __Pyx_XDECREF_SET(__pyx_v_offset, __pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_10); + __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":227 + * new_code = None + * for offset, line in dis.findlinestarts(code_obj_py): + * if line in breakpoints: # <<<<<<<<<<<<<< + * # breakpoint = breakpoints[line] + * # if DEBUG: + */ + if (unlikely(__pyx_v_breakpoints == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + __PYX_ERR(0, 227, __pyx_L1_error) + } + __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_line, __pyx_v_breakpoints, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 227, __pyx_L1_error) + __pyx_t_14 = (__pyx_t_4 != 0); + if (__pyx_t_14) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":231 + * # if DEBUG: + * # print('created breakpoint', code_obj_py.co_name, line) + * func_code_info.breakpoint_found = True # <<<<<<<<<<<<<< + * break_at_lines.add(line) + * + */ + __pyx_v_func_code_info->breakpoint_found = 1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":232 + * # print('created breakpoint', code_obj_py.co_name, line) + * func_code_info.breakpoint_found = True + * break_at_lines.add(line) # <<<<<<<<<<<<<< + * + * success, new_code = insert_code( + */ + __pyx_t_17 = PySet_Add(__pyx_v_break_at_lines, __pyx_v_line); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 232, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":234 + * break_at_lines.add(line) + * + * success, new_code = insert_code( # <<<<<<<<<<<<<< + * code_obj_py, create_pydev_trace_code_wrapper(line), line, tuple(break_at_lines)) + * code_obj_py = new_code + */ + __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_insert_code); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":235 + * + * success, new_code = insert_code( + * code_obj_py, create_pydev_trace_code_wrapper(line), line, tuple(break_at_lines)) # <<<<<<<<<<<<<< + * code_obj_py = new_code + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_create_pydev_trace_code_wrapper); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + } + } + __pyx_t_1 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_13, __pyx_v_line) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_line); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = PySequence_Tuple(__pyx_v_break_at_lines); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 235, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_13 = NULL; + __pyx_t_6 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_10); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_10, function); + __pyx_t_6 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[5] = {__pyx_t_13, __pyx_v_code_obj_py, __pyx_t_1, __pyx_v_line, __pyx_t_11}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { + PyObject *__pyx_temp[5] = {__pyx_t_13, __pyx_v_code_obj_py, __pyx_t_1, __pyx_v_line, __pyx_t_11}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_6, 4+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } else + #endif + { + __pyx_t_12 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_13); __pyx_t_13 = NULL; + } + __Pyx_INCREF(__pyx_v_code_obj_py); + __Pyx_GIVEREF(__pyx_v_code_obj_py); + PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_6, __pyx_v_code_obj_py); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_6, __pyx_t_1); + __Pyx_INCREF(__pyx_v_line); + __Pyx_GIVEREF(__pyx_v_line); + PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_6, __pyx_v_line); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_6, __pyx_t_11); + __pyx_t_1 = 0; + __pyx_t_11 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 234, __pyx_L1_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_12 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_12); + #else + __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_12); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 234, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_16 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_16(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L32_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_12 = __pyx_t_16(__pyx_t_11); if (unlikely(!__pyx_t_12)) goto __pyx_L32_unpacking_failed; + __Pyx_GOTREF(__pyx_t_12); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_16(__pyx_t_11), 2) < 0) __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_t_16 = NULL; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L33_unpacking_done; + __pyx_L32_unpacking_failed:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_16 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 234, __pyx_L1_error) + __pyx_L33_unpacking_done:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":234 + * break_at_lines.add(line) + * + * success, new_code = insert_code( # <<<<<<<<<<<<<< + * code_obj_py, create_pydev_trace_code_wrapper(line), line, tuple(break_at_lines)) + * code_obj_py = new_code + */ + __Pyx_XDECREF_SET(__pyx_v_success, __pyx_t_10); + __pyx_t_10 = 0; + __Pyx_DECREF_SET(__pyx_v_new_code, __pyx_t_12); + __pyx_t_12 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":236 + * success, new_code = insert_code( + * code_obj_py, create_pydev_trace_code_wrapper(line), line, tuple(break_at_lines)) + * code_obj_py = new_code # <<<<<<<<<<<<<< + * + * if not success: + */ + __Pyx_INCREF(__pyx_v_new_code); + __Pyx_DECREF_SET(__pyx_v_code_obj_py, __pyx_v_new_code); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":238 + * code_obj_py = new_code + * + * if not success: # <<<<<<<<<<<<<< + * func_code_info.new_code = None + * break + */ + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_success); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 238, __pyx_L1_error) + __pyx_t_4 = ((!__pyx_t_14) != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":239 + * + * if not success: + * func_code_info.new_code = None # <<<<<<<<<<<<<< + * break + * else: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_func_code_info->new_code); + __Pyx_DECREF(__pyx_v_func_code_info->new_code); + __pyx_v_func_code_info->new_code = Py_None; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":240 + * if not success: + * func_code_info.new_code = None + * break # <<<<<<<<<<<<<< + * else: + * # Ok, all succeeded, set to generated code object. + */ + goto __pyx_L28_break; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":238 + * code_obj_py = new_code + * + * if not success: # <<<<<<<<<<<<<< + * func_code_info.new_code = None + * break + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":227 + * new_code = None + * for offset, line in dis.findlinestarts(code_obj_py): + * if line in breakpoints: # <<<<<<<<<<<<<< + * # breakpoint = breakpoints[line] + * # if DEBUG: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":226 + * break_at_lines = set() + * new_code = None + * for offset, line in dis.findlinestarts(code_obj_py): # <<<<<<<<<<<<<< + * if line in breakpoints: + * # breakpoint = breakpoints[line] + */ + } + /*else*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":243 + * else: + * # Ok, all succeeded, set to generated code object. + * func_code_info.new_code = new_code # <<<<<<<<<<<<<< + * + * + */ + __Pyx_INCREF(__pyx_v_new_code); + __Pyx_GIVEREF(__pyx_v_new_code); + __Pyx_GOTREF(__pyx_v_func_code_info->new_code); + __Pyx_DECREF(__pyx_v_func_code_info->new_code); + __pyx_v_func_code_info->new_code = __pyx_v_new_code; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":226 + * break_at_lines = set() + * new_code = None + * for offset, line in dis.findlinestarts(code_obj_py): # <<<<<<<<<<<<<< + * if line in breakpoints: + * # breakpoint = breakpoints[line] + */ + __pyx_L28_break:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":221 + * # print(main_debugger.breakpoints.get(func_code_info.real_path)) + * code_obj_py: object = code_obj + * if breakpoints: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('found breakpoints', code_obj_py.co_name, breakpoints) + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":214 + * if not func_code_info.always_skip_code: + * was_break: bool = False + * if main_debugger is not None: # <<<<<<<<<<<<<< + * breakpoints: dict = main_debugger.breakpoints.get(func_code_info.real_path) + * # print('\n---') + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":212 + * func_code_info.always_skip_code = True + * + * if not func_code_info.always_skip_code: # <<<<<<<<<<<<<< + * was_break: bool = False + * if main_debugger is not None: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":246 + * + * + * Py_INCREF(func_code_info) # <<<<<<<<<<<<<< + * _PyCode_SetExtra( code_obj, _code_extra_index, func_code_info) + * + */ + Py_INCREF(((PyObject *)__pyx_v_func_code_info)); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":247 + * + * Py_INCREF(func_code_info) + * _PyCode_SetExtra( code_obj, _code_extra_index, func_code_info) # <<<<<<<<<<<<<< + * + * return func_code_info + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_code_extra_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 247, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 247, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + (void)(_PyCode_SetExtra(((PyObject *)__pyx_v_code_obj), __pyx_t_3, ((PyObject *)__pyx_v_func_code_info))); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":249 + * _PyCode_SetExtra( code_obj, _code_extra_index, func_code_info) + * + * return func_code_info # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_func_code_info)); + __pyx_r = __pyx_v_func_code_info; + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":152 + * _code_extra_index: Py_SIZE = -1 + * + * cdef FuncCodeInfo get_func_code_info(PyFrameObject * frame_obj, PyCodeObject * code_obj): # <<<<<<<<<<<<<< + * ''' + * Provides code-object related info. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_func_code_info", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_main_debugger); + __Pyx_XDECREF((PyObject *)__pyx_v_func_code_info_obj); + __Pyx_XDECREF(__pyx_v_co_filename); + __Pyx_XDECREF(__pyx_v_co_name); + __Pyx_XDECREF(__pyx_v_break_at_lines); + __Pyx_XDECREF(__pyx_v_cache_file_type); + __Pyx_XDECREF(__pyx_v_cache_file_type_key); + __Pyx_XDECREF((PyObject *)__pyx_v_func_code_info); + __Pyx_XDECREF(__pyx_v_abs_path_real_path_and_base); + __Pyx_XDECREF(__pyx_v_file_type); + __Pyx_XDECREF(__pyx_v_breakpoints); + __Pyx_XDECREF(__pyx_v_code_obj_py); + __Pyx_XDECREF(__pyx_v_new_code); + __Pyx_XDECREF(__pyx_v_offset); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_success); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":252 + * + * + * cdef PyObject * get_bytecode_while_frame_eval(PyFrameObject * frame_obj, int exc): # <<<<<<<<<<<<<< + * ''' + * This function makes the actual evaluation and changes the bytecode to a version + */ + +static PyObject *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval(PyFrameObject *__pyx_v_frame_obj, int __pyx_v_exc) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v_thread_info = 0; + CYTHON_UNUSED int __pyx_v_STATE_SUSPEND; + int __pyx_v_CMD_STEP_INTO; + int __pyx_v_CMD_STEP_OVER; + int __pyx_v_CMD_STEP_OVER_MY_CODE; + int __pyx_v_CMD_STEP_INTO_MY_CODE; + int __pyx_v_can_skip; + struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *__pyx_v_additional_info = 0; + PyObject *__pyx_v_main_debugger = 0; + PyObject *__pyx_v_frame = NULL; + PyObject *__pyx_v_trace_func = NULL; + PyObject *__pyx_v_apply_to_global = NULL; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v_func_code_info = 0; + PyObject *__pyx_v_old = NULL; + PyObject *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + int __pyx_t_13; + char const *__pyx_t_14; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18; + __Pyx_RefNannySetupContext("get_bytecode_while_frame_eval", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":257 + * where programmatic breakpoints are added. + * ''' + * if GlobalDebuggerHolder is None or _thread_local_info is None or exc: # <<<<<<<<<<<<<< + * # Sometimes during process shutdown these global variables become None + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_GlobalDebuggerHolder); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = (__pyx_t_2 == Py_None); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = (__pyx_t_3 != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_thread_local_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 257, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = (__pyx_t_2 == Py_None); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = (__pyx_t_4 != 0); + if (!__pyx_t_3) { + } else { + __pyx_t_1 = __pyx_t_3; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_3 = (__pyx_v_exc != 0); + __pyx_t_1 = __pyx_t_3; + __pyx_L4_bool_binop_done:; + if (__pyx_t_1) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":259 + * if GlobalDebuggerHolder is None or _thread_local_info is None or exc: + * # Sometimes during process shutdown these global variables become None + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * + * # co_filename: str = frame_obj.f_code.co_filename + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":257 + * where programmatic breakpoints are added. + * ''' + * if GlobalDebuggerHolder is None or _thread_local_info is None or exc: # <<<<<<<<<<<<<< + * # Sometimes during process shutdown these global variables become None + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":266 + * + * cdef ThreadInfo thread_info + * cdef int STATE_SUSPEND = 2 # <<<<<<<<<<<<<< + * cdef int CMD_STEP_INTO = 107 + * cdef int CMD_STEP_OVER = 108 + */ + __pyx_v_STATE_SUSPEND = 2; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":267 + * cdef ThreadInfo thread_info + * cdef int STATE_SUSPEND = 2 + * cdef int CMD_STEP_INTO = 107 # <<<<<<<<<<<<<< + * cdef int CMD_STEP_OVER = 108 + * cdef int CMD_STEP_OVER_MY_CODE = 159 + */ + __pyx_v_CMD_STEP_INTO = 0x6B; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":268 + * cdef int STATE_SUSPEND = 2 + * cdef int CMD_STEP_INTO = 107 + * cdef int CMD_STEP_OVER = 108 # <<<<<<<<<<<<<< + * cdef int CMD_STEP_OVER_MY_CODE = 159 + * cdef int CMD_STEP_INTO_MY_CODE = 144 + */ + __pyx_v_CMD_STEP_OVER = 0x6C; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":269 + * cdef int CMD_STEP_INTO = 107 + * cdef int CMD_STEP_OVER = 108 + * cdef int CMD_STEP_OVER_MY_CODE = 159 # <<<<<<<<<<<<<< + * cdef int CMD_STEP_INTO_MY_CODE = 144 + * cdef bint can_skip = True + */ + __pyx_v_CMD_STEP_OVER_MY_CODE = 0x9F; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":270 + * cdef int CMD_STEP_OVER = 108 + * cdef int CMD_STEP_OVER_MY_CODE = 159 + * cdef int CMD_STEP_INTO_MY_CODE = 144 # <<<<<<<<<<<<<< + * cdef bint can_skip = True + * try: + */ + __pyx_v_CMD_STEP_INTO_MY_CODE = 0x90; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":271 + * cdef int CMD_STEP_OVER_MY_CODE = 159 + * cdef int CMD_STEP_INTO_MY_CODE = 144 + * cdef bint can_skip = True # <<<<<<<<<<<<<< + * try: + * thread_info = _thread_local_info.thread_info + */ + __pyx_v_can_skip = 1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":272 + * cdef int CMD_STEP_INTO_MY_CODE = 144 + * cdef bint can_skip = True + * try: # <<<<<<<<<<<<<< + * thread_info = _thread_local_info.thread_info + * except: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":273 + * cdef bint can_skip = True + * try: + * thread_info = _thread_local_info.thread_info # <<<<<<<<<<<<<< + * except: + * thread_info = get_thread_info() + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_thread_local_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 273, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_thread_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 273, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo))))) __PYX_ERR(0, 273, __pyx_L7_error) + __pyx_v_thread_info = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_t_8); + __pyx_t_8 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":272 + * cdef int CMD_STEP_INTO_MY_CODE = 144 + * cdef bint can_skip = True + * try: # <<<<<<<<<<<<<< + * thread_info = _thread_local_info.thread_info + * except: + */ + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L12_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":274 + * try: + * thread_info = _thread_local_info.thread_info + * except: # <<<<<<<<<<<<<< + * thread_info = get_thread_info() + * if thread_info is None: + */ + /*except:*/ { + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.get_bytecode_while_frame_eval", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_2, &__pyx_t_9) < 0) __PYX_ERR(0, 274, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_9); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":275 + * thread_info = _thread_local_info.thread_info + * except: + * thread_info = get_thread_info() # <<<<<<<<<<<<<< + * if thread_info is None: + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __pyx_t_10 = ((PyObject *)__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_thread_info()); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 275, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XDECREF_SET(__pyx_v_thread_info, ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_t_10)); + __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":276 + * except: + * thread_info = get_thread_info() + * if thread_info is None: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + */ + __pyx_t_1 = (((PyObject *)__pyx_v_thread_info) == Py_None); + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":277 + * thread_info = get_thread_info() + * if thread_info is None: + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * + * if thread_info.inside_frame_eval: + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L10_except_return; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":276 + * except: + * thread_info = get_thread_info() + * if thread_info is None: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + */ + } + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":272 + * cdef int CMD_STEP_INTO_MY_CODE = 144 + * cdef bint can_skip = True + * try: # <<<<<<<<<<<<<< + * thread_info = _thread_local_info.thread_info + * except: + */ + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L10_except_return:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L0; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L12_try_end:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":279 + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + * if thread_info.inside_frame_eval: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + */ + __pyx_t_3 = (__pyx_v_thread_info->inside_frame_eval != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":280 + * + * if thread_info.inside_frame_eval: + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * + * if not thread_info.fully_initialized: + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":279 + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + * if thread_info.inside_frame_eval: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":282 + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + * if not thread_info.fully_initialized: # <<<<<<<<<<<<<< + * thread_info.initialize_if_possible() + * if not thread_info.fully_initialized: + */ + __pyx_t_3 = ((!(__pyx_v_thread_info->fully_initialized != 0)) != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":283 + * + * if not thread_info.fully_initialized: + * thread_info.initialize_if_possible() # <<<<<<<<<<<<<< + * if not thread_info.fully_initialized: + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_thread_info), __pyx_n_s_initialize_if_possible); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_9 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 283, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":284 + * if not thread_info.fully_initialized: + * thread_info.initialize_if_possible() + * if not thread_info.fully_initialized: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + */ + __pyx_t_3 = ((!(__pyx_v_thread_info->fully_initialized != 0)) != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":285 + * thread_info.initialize_if_possible() + * if not thread_info.fully_initialized: + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * + * # Can only get additional_info when fully initialized. + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":284 + * if not thread_info.fully_initialized: + * thread_info.initialize_if_possible() + * if not thread_info.fully_initialized: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":282 + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * + * if not thread_info.fully_initialized: # <<<<<<<<<<<<<< + * thread_info.initialize_if_possible() + * if not thread_info.fully_initialized: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":288 + * + * # Can only get additional_info when fully initialized. + * cdef PyDBAdditionalThreadInfo additional_info = thread_info.additional_info # <<<<<<<<<<<<<< + * if thread_info.is_pydevd_thread or additional_info.is_tracing: + * # Make sure that we don't trace pydevd threads or inside our own calls. + */ + __pyx_t_9 = ((PyObject *)__pyx_v_thread_info->additional_info); + __Pyx_INCREF(__pyx_t_9); + __pyx_v_additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_9); + __pyx_t_9 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":289 + * # Can only get additional_info when fully initialized. + * cdef PyDBAdditionalThreadInfo additional_info = thread_info.additional_info + * if thread_info.is_pydevd_thread or additional_info.is_tracing: # <<<<<<<<<<<<<< + * # Make sure that we don't trace pydevd threads or inside our own calls. + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __pyx_t_1 = (__pyx_v_thread_info->is_pydevd_thread != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L20_bool_binop_done; + } + __pyx_t_1 = (__pyx_v_additional_info->is_tracing != 0); + __pyx_t_3 = __pyx_t_1; + __pyx_L20_bool_binop_done:; + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":291 + * if thread_info.is_pydevd_thread or additional_info.is_tracing: + * # Make sure that we don't trace pydevd threads or inside our own calls. + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * + * # frame = frame_obj + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":289 + * # Can only get additional_info when fully initialized. + * cdef PyDBAdditionalThreadInfo additional_info = thread_info.additional_info + * if thread_info.is_pydevd_thread or additional_info.is_tracing: # <<<<<<<<<<<<<< + * # Make sure that we don't trace pydevd threads or inside our own calls. + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":298 + * # print('get_bytecode_while_frame_eval', frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename) + * + * thread_info.inside_frame_eval += 1 # <<<<<<<<<<<<<< + * additional_info.is_tracing = True + * try: + */ + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval + 1); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":299 + * + * thread_info.inside_frame_eval += 1 + * additional_info.is_tracing = True # <<<<<<<<<<<<<< + * try: + * main_debugger: object = GlobalDebuggerHolder.global_dbg + */ + __pyx_v_additional_info->is_tracing = 1; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":300 + * thread_info.inside_frame_eval += 1 + * additional_info.is_tracing = True + * try: # <<<<<<<<<<<<<< + * main_debugger: object = GlobalDebuggerHolder.global_dbg + * if main_debugger is None: + */ + /*try:*/ { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":301 + * additional_info.is_tracing = True + * try: + * main_debugger: object = GlobalDebuggerHolder.global_dbg # <<<<<<<<<<<<<< + * if main_debugger is None: + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_GlobalDebuggerHolder); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 301, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_global_dbg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 301, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_v_main_debugger = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":302 + * try: + * main_debugger: object = GlobalDebuggerHolder.global_dbg + * if main_debugger is None: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * frame = frame_obj + */ + __pyx_t_3 = (__pyx_v_main_debugger == Py_None); + __pyx_t_1 = (__pyx_t_3 != 0); + if (__pyx_t_1) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":303 + * main_debugger: object = GlobalDebuggerHolder.global_dbg + * if main_debugger is None: + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * frame = frame_obj + * + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + goto __pyx_L22_return; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":302 + * try: + * main_debugger: object = GlobalDebuggerHolder.global_dbg + * if main_debugger is None: # <<<<<<<<<<<<<< + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * frame = frame_obj + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":304 + * if main_debugger is None: + * return _PyEval_EvalFrameDefault(frame_obj, exc) + * frame = frame_obj # <<<<<<<<<<<<<< + * + * if thread_info.thread_trace_func is None: + */ + __pyx_t_2 = ((PyObject *)__pyx_v_frame_obj); + __Pyx_INCREF(__pyx_t_2); + __pyx_v_frame = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":306 + * frame = frame_obj + * + * if thread_info.thread_trace_func is None: # <<<<<<<<<<<<<< + * trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) + * if apply_to_global: + */ + __pyx_t_1 = (__pyx_v_thread_info->thread_trace_func == Py_None); + __pyx_t_3 = (__pyx_t_1 != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":307 + * + * if thread_info.thread_trace_func is None: + * trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) # <<<<<<<<<<<<<< + * if apply_to_global: + * thread_info.thread_trace_func = trace_func + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_fix_top_level_trace_and_get_trac); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_main_debugger, __pyx_v_frame}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_main_debugger, __pyx_v_frame}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_GOTREF(__pyx_t_2); + } else + #endif + { + __pyx_t_10 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_11, __pyx_v_main_debugger); + __Pyx_INCREF(__pyx_v_frame); + __Pyx_GIVEREF(__pyx_v_frame); + PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_11, __pyx_v_frame); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + __PYX_ERR(0, 307, __pyx_L23_error) + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_9 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 307, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_8); if (unlikely(!__pyx_t_9)) goto __pyx_L27_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_8); if (unlikely(!__pyx_t_10)) goto __pyx_L27_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_8), 2) < 0) __PYX_ERR(0, 307, __pyx_L23_error) + __pyx_t_12 = NULL; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L28_unpacking_done; + __pyx_L27_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_12 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + __PYX_ERR(0, 307, __pyx_L23_error) + __pyx_L28_unpacking_done:; + } + __pyx_v_trace_func = __pyx_t_9; + __pyx_t_9 = 0; + __pyx_v_apply_to_global = __pyx_t_10; + __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":308 + * if thread_info.thread_trace_func is None: + * trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) + * if apply_to_global: # <<<<<<<<<<<<<< + * thread_info.thread_trace_func = trace_func + * + */ + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_apply_to_global); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 308, __pyx_L23_error) + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":309 + * trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) + * if apply_to_global: + * thread_info.thread_trace_func = trace_func # <<<<<<<<<<<<<< + * + * if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ + */ + __Pyx_INCREF(__pyx_v_trace_func); + __Pyx_GIVEREF(__pyx_v_trace_func); + __Pyx_GOTREF(__pyx_v_thread_info->thread_trace_func); + __Pyx_DECREF(__pyx_v_thread_info->thread_trace_func); + __pyx_v_thread_info->thread_trace_func = __pyx_v_trace_func; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":308 + * if thread_info.thread_trace_func is None: + * trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) + * if apply_to_global: # <<<<<<<<<<<<<< + * thread_info.thread_trace_func = trace_func + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":306 + * frame = frame_obj + * + * if thread_info.thread_trace_func is None: # <<<<<<<<<<<<<< + * trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) + * if apply_to_global: + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":311 + * thread_info.thread_trace_func = trace_func + * + * if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ # <<<<<<<<<<<<<< + * main_debugger.break_on_caught_exceptions or \ + * main_debugger.has_plugin_exception_breaks or \ + */ + __pyx_t_11 = __pyx_v_additional_info->pydev_step_cmd; + __pyx_t_4 = ((__pyx_t_11 == __pyx_v_CMD_STEP_INTO) != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_1 = __pyx_t_4; + goto __pyx_L33_bool_binop_done; + } + __pyx_t_4 = ((__pyx_t_11 == __pyx_v_CMD_STEP_INTO_MY_CODE) != 0); + __pyx_t_1 = __pyx_t_4; + __pyx_L33_bool_binop_done:; + __pyx_t_4 = (__pyx_t_1 != 0); + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L31_bool_binop_done; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":312 + * + * if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ + * main_debugger.break_on_caught_exceptions or \ # <<<<<<<<<<<<<< + * main_debugger.has_plugin_exception_breaks or \ + * main_debugger.signature_factory or \ + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_break_on_caught_exceptions); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 312, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 312, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L31_bool_binop_done; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":313 + * if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ + * main_debugger.break_on_caught_exceptions or \ + * main_debugger.has_plugin_exception_breaks or \ # <<<<<<<<<<<<<< + * main_debugger.signature_factory or \ + * additional_info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and main_debugger.show_return_values and frame.f_back is additional_info.pydev_step_stop: + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_exception_breaks); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 313, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 313, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L31_bool_binop_done; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":314 + * main_debugger.break_on_caught_exceptions or \ + * main_debugger.has_plugin_exception_breaks or \ + * main_debugger.signature_factory or \ # <<<<<<<<<<<<<< + * additional_info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and main_debugger.show_return_values and frame.f_back is additional_info.pydev_step_stop: + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_signature_factory); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 314, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L31_bool_binop_done; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":315 + * main_debugger.has_plugin_exception_breaks or \ + * main_debugger.signature_factory or \ + * additional_info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and main_debugger.show_return_values and frame.f_back is additional_info.pydev_step_stop: # <<<<<<<<<<<<<< + * + * # if DEBUG: + */ + __pyx_t_11 = __pyx_v_additional_info->pydev_step_cmd; + __pyx_t_1 = ((__pyx_t_11 == __pyx_v_CMD_STEP_OVER) != 0); + if (!__pyx_t_1) { + } else { + __pyx_t_4 = __pyx_t_1; + goto __pyx_L39_bool_binop_done; + } + __pyx_t_1 = ((__pyx_t_11 == __pyx_v_CMD_STEP_OVER_MY_CODE) != 0); + __pyx_t_4 = __pyx_t_1; + __pyx_L39_bool_binop_done:; + __pyx_t_1 = (__pyx_t_4 != 0); + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L31_bool_binop_done; + } + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_show_return_values); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 315, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + } else { + __pyx_t_3 = __pyx_t_1; + goto __pyx_L31_bool_binop_done; + } + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_frame, __pyx_n_s_f_back); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = (__pyx_t_2 == __pyx_v_additional_info->pydev_step_stop); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = (__pyx_t_1 != 0); + __pyx_t_3 = __pyx_t_4; + __pyx_L31_bool_binop_done:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":311 + * thread_info.thread_trace_func = trace_func + * + * if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ # <<<<<<<<<<<<<< + * main_debugger.break_on_caught_exceptions or \ + * main_debugger.has_plugin_exception_breaks or \ + */ + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":319 + * # if DEBUG: + * # print('get_bytecode_while_frame_eval enabled trace') + * if thread_info.thread_trace_func is not None: # <<<<<<<<<<<<<< + * frame.f_trace = thread_info.thread_trace_func + * else: + */ + __pyx_t_3 = (__pyx_v_thread_info->thread_trace_func != Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":320 + * # print('get_bytecode_while_frame_eval enabled trace') + * if thread_info.thread_trace_func is not None: + * frame.f_trace = thread_info.thread_trace_func # <<<<<<<<<<<<<< + * else: + * frame.f_trace = main_debugger.trace_dispatch + */ + __pyx_t_2 = __pyx_v_thread_info->thread_trace_func; + __Pyx_INCREF(__pyx_t_2); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_2) < 0) __PYX_ERR(0, 320, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":319 + * # if DEBUG: + * # print('get_bytecode_while_frame_eval enabled trace') + * if thread_info.thread_trace_func is not None: # <<<<<<<<<<<<<< + * frame.f_trace = thread_info.thread_trace_func + * else: + */ + goto __pyx_L42; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":322 + * frame.f_trace = thread_info.thread_trace_func + * else: + * frame.f_trace = main_debugger.trace_dispatch # <<<<<<<<<<<<<< + * else: + * func_code_info: FuncCodeInfo = get_func_code_info(frame_obj, frame_obj.f_code) + */ + /*else*/ { + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 322, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = __pyx_t_2; + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_10) < 0) __PYX_ERR(0, 322, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __pyx_L42:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":311 + * thread_info.thread_trace_func = trace_func + * + * if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ # <<<<<<<<<<<<<< + * main_debugger.break_on_caught_exceptions or \ + * main_debugger.has_plugin_exception_breaks or \ + */ + goto __pyx_L30; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":324 + * frame.f_trace = main_debugger.trace_dispatch + * else: + * func_code_info: FuncCodeInfo = get_func_code_info(frame_obj, frame_obj.f_code) # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_bytecode_while_frame_eval always skip', func_code_info.always_skip_code) + */ + /*else*/ { + __pyx_t_10 = ((PyObject *)__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_func_code_info(__pyx_v_frame_obj, __pyx_v_frame_obj->f_code)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 324, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_v_func_code_info = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":327 + * # if DEBUG: + * # print('get_bytecode_while_frame_eval always skip', func_code_info.always_skip_code) + * if not func_code_info.always_skip_code: # <<<<<<<<<<<<<< + * + * if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks: + */ + __pyx_t_4 = ((!(__pyx_v_func_code_info->always_skip_code != 0)) != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":329 + * if not func_code_info.always_skip_code: + * + * if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks: # <<<<<<<<<<<<<< + * can_skip = main_debugger.plugin.can_skip(main_debugger, frame_obj) + * + */ + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_line_breaks); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 329, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 329, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (!__pyx_t_3) { + } else { + __pyx_t_4 = __pyx_t_3; + goto __pyx_L45_bool_binop_done; + } + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_has_plugin_exception_breaks); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 329, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 329, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_4 = __pyx_t_3; + __pyx_L45_bool_binop_done:; + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":330 + * + * if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks: + * can_skip = main_debugger.plugin.can_skip(main_debugger, frame_obj) # <<<<<<<<<<<<<< + * + * if not can_skip: + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_plugin); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_can_skip); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_11 = 0; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_11 = 1; + } + } + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_main_debugger, ((PyObject *)__pyx_v_frame_obj)}; + __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { + PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_main_debugger, ((PyObject *)__pyx_v_frame_obj)}; + __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GOTREF(__pyx_t_10); + } else + #endif + { + __pyx_t_8 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_2) { + __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); __pyx_t_2 = NULL; + } + __Pyx_INCREF(__pyx_v_main_debugger); + __Pyx_GIVEREF(__pyx_v_main_debugger); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_11, __pyx_v_main_debugger); + __Pyx_INCREF(((PyObject *)__pyx_v_frame_obj)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_frame_obj)); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_11, ((PyObject *)__pyx_v_frame_obj)); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 330, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_v_can_skip = __pyx_t_4; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":332 + * can_skip = main_debugger.plugin.can_skip(main_debugger, frame_obj) + * + * if not can_skip: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_bytecode_while_frame_eval not can_skip') + */ + __pyx_t_4 = ((!(__pyx_v_can_skip != 0)) != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":335 + * # if DEBUG: + * # print('get_bytecode_while_frame_eval not can_skip') + * if thread_info.thread_trace_func is not None: # <<<<<<<<<<<<<< + * frame.f_trace = thread_info.thread_trace_func + * else: + */ + __pyx_t_4 = (__pyx_v_thread_info->thread_trace_func != Py_None); + __pyx_t_3 = (__pyx_t_4 != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":336 + * # print('get_bytecode_while_frame_eval not can_skip') + * if thread_info.thread_trace_func is not None: + * frame.f_trace = thread_info.thread_trace_func # <<<<<<<<<<<<<< + * else: + * frame.f_trace = main_debugger.trace_dispatch + */ + __pyx_t_10 = __pyx_v_thread_info->thread_trace_func; + __Pyx_INCREF(__pyx_t_10); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_10) < 0) __PYX_ERR(0, 336, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":335 + * # if DEBUG: + * # print('get_bytecode_while_frame_eval not can_skip') + * if thread_info.thread_trace_func is not None: # <<<<<<<<<<<<<< + * frame.f_trace = thread_info.thread_trace_func + * else: + */ + goto __pyx_L48; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":338 + * frame.f_trace = thread_info.thread_trace_func + * else: + * frame.f_trace = main_debugger.trace_dispatch # <<<<<<<<<<<<<< + * + * if can_skip and func_code_info.breakpoint_found: + */ + /*else*/ { + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 338, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __pyx_t_10; + __Pyx_INCREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_9) < 0) __PYX_ERR(0, 338, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __pyx_L48:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":332 + * can_skip = main_debugger.plugin.can_skip(main_debugger, frame_obj) + * + * if not can_skip: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_bytecode_while_frame_eval not can_skip') + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":329 + * if not func_code_info.always_skip_code: + * + * if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks: # <<<<<<<<<<<<<< + * can_skip = main_debugger.plugin.can_skip(main_debugger, frame_obj) + * + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":340 + * frame.f_trace = main_debugger.trace_dispatch + * + * if can_skip and func_code_info.breakpoint_found: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_bytecode_while_frame_eval new_code', func_code_info.new_code) + */ + __pyx_t_4 = (__pyx_v_can_skip != 0); + if (__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L50_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_func_code_info->breakpoint_found != 0); + __pyx_t_3 = __pyx_t_4; + __pyx_L50_bool_binop_done:; + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":347 + * # this means we weren't able to actually add the code + * # where needed, so, fallback to tracing. + * if func_code_info.new_code is None: # <<<<<<<<<<<<<< + * if thread_info.thread_trace_func is not None: + * frame.f_trace = thread_info.thread_trace_func + */ + __pyx_t_3 = (__pyx_v_func_code_info->new_code == Py_None); + __pyx_t_4 = (__pyx_t_3 != 0); + if (__pyx_t_4) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":348 + * # where needed, so, fallback to tracing. + * if func_code_info.new_code is None: + * if thread_info.thread_trace_func is not None: # <<<<<<<<<<<<<< + * frame.f_trace = thread_info.thread_trace_func + * else: + */ + __pyx_t_4 = (__pyx_v_thread_info->thread_trace_func != Py_None); + __pyx_t_3 = (__pyx_t_4 != 0); + if (__pyx_t_3) { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":349 + * if func_code_info.new_code is None: + * if thread_info.thread_trace_func is not None: + * frame.f_trace = thread_info.thread_trace_func # <<<<<<<<<<<<<< + * else: + * frame.f_trace = main_debugger.trace_dispatch + */ + __pyx_t_9 = __pyx_v_thread_info->thread_trace_func; + __Pyx_INCREF(__pyx_t_9); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_9) < 0) __PYX_ERR(0, 349, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":348 + * # where needed, so, fallback to tracing. + * if func_code_info.new_code is None: + * if thread_info.thread_trace_func is not None: # <<<<<<<<<<<<<< + * frame.f_trace = thread_info.thread_trace_func + * else: + */ + goto __pyx_L53; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":351 + * frame.f_trace = thread_info.thread_trace_func + * else: + * frame.f_trace = main_debugger.trace_dispatch # <<<<<<<<<<<<<< + * else: + * # print('Using frame eval break for', frame_obj.f_code.co_name) + */ + /*else*/ { + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_main_debugger, __pyx_n_s_trace_dispatch); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 351, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_t_9; + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__Pyx_PyObject_SetAttrStr(__pyx_v_frame, __pyx_n_s_f_trace, __pyx_t_10) < 0) __PYX_ERR(0, 351, __pyx_L23_error) + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __pyx_L53:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":347 + * # this means we weren't able to actually add the code + * # where needed, so, fallback to tracing. + * if func_code_info.new_code is None: # <<<<<<<<<<<<<< + * if thread_info.thread_trace_func is not None: + * frame.f_trace = thread_info.thread_trace_func + */ + goto __pyx_L52; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":354 + * else: + * # print('Using frame eval break for', frame_obj.f_code.co_name) + * update_globals_dict( frame_obj.f_globals) # <<<<<<<<<<<<<< + * Py_INCREF(func_code_info.new_code) + * old = frame_obj.f_code + */ + /*else*/ { + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_update_globals_dict); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 354, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + } + } + __pyx_t_10 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, ((PyObject *)__pyx_v_frame_obj->f_globals)) : __Pyx_PyObject_CallOneArg(__pyx_t_9, ((PyObject *)__pyx_v_frame_obj->f_globals)); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 354, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":355 + * # print('Using frame eval break for', frame_obj.f_code.co_name) + * update_globals_dict( frame_obj.f_globals) + * Py_INCREF(func_code_info.new_code) # <<<<<<<<<<<<<< + * old = frame_obj.f_code + * frame_obj.f_code = func_code_info.new_code + */ + __pyx_t_10 = __pyx_v_func_code_info->new_code; + __Pyx_INCREF(__pyx_t_10); + Py_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":356 + * update_globals_dict( frame_obj.f_globals) + * Py_INCREF(func_code_info.new_code) + * old = frame_obj.f_code # <<<<<<<<<<<<<< + * frame_obj.f_code = func_code_info.new_code + * Py_DECREF(old) + */ + __pyx_t_10 = ((PyObject *)__pyx_v_frame_obj->f_code); + __Pyx_INCREF(__pyx_t_10); + __pyx_v_old = __pyx_t_10; + __pyx_t_10 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":357 + * Py_INCREF(func_code_info.new_code) + * old = frame_obj.f_code + * frame_obj.f_code = func_code_info.new_code # <<<<<<<<<<<<<< + * Py_DECREF(old) + * + */ + __pyx_v_frame_obj->f_code = ((PyCodeObject *)__pyx_v_func_code_info->new_code); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":358 + * old = frame_obj.f_code + * frame_obj.f_code = func_code_info.new_code + * Py_DECREF(old) # <<<<<<<<<<<<<< + * + * finally: + */ + Py_DECREF(__pyx_v_old); + } + __pyx_L52:; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":340 + * frame.f_trace = main_debugger.trace_dispatch + * + * if can_skip and func_code_info.breakpoint_found: # <<<<<<<<<<<<<< + * # if DEBUG: + * # print('get_bytecode_while_frame_eval new_code', func_code_info.new_code) + */ + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":327 + * # if DEBUG: + * # print('get_bytecode_while_frame_eval always skip', func_code_info.always_skip_code) + * if not func_code_info.always_skip_code: # <<<<<<<<<<<<<< + * + * if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks: + */ + } + } + __pyx_L30:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":361 + * + * finally: + * thread_info.inside_frame_eval -= 1 # <<<<<<<<<<<<<< + * additional_info.is_tracing = False + * + */ + /*finally:*/ { + /*normal exit:*/{ + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval - 1); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":362 + * finally: + * thread_info.inside_frame_eval -= 1 + * additional_info.is_tracing = False # <<<<<<<<<<<<<< + * + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __pyx_v_additional_info->is_tracing = 0; + goto __pyx_L24; + } + __pyx_L23_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __pyx_t_11 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename; + { + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":361 + * + * finally: + * thread_info.inside_frame_eval -= 1 # <<<<<<<<<<<<<< + * additional_info.is_tracing = False + * + */ + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval - 1); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":362 + * finally: + * thread_info.inside_frame_eval -= 1 + * additional_info.is_tracing = False # <<<<<<<<<<<<<< + * + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __pyx_v_additional_info->is_tracing = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17); + } + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestore(__pyx_t_7, __pyx_t_6, __pyx_t_5); + __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __pyx_lineno = __pyx_t_11; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14; + goto __pyx_L1_error; + } + __pyx_L22_return: { + __pyx_t_18 = __pyx_r; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":361 + * + * finally: + * thread_info.inside_frame_eval -= 1 # <<<<<<<<<<<<<< + * additional_info.is_tracing = False + * + */ + __pyx_v_thread_info->inside_frame_eval = (__pyx_v_thread_info->inside_frame_eval - 1); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":362 + * finally: + * thread_info.inside_frame_eval -= 1 + * additional_info.is_tracing = False # <<<<<<<<<<<<<< + * + * return _PyEval_EvalFrameDefault(frame_obj, exc) + */ + __pyx_v_additional_info->is_tracing = 0; + __pyx_r = __pyx_t_18; + goto __pyx_L0; + } + __pyx_L24:; + } + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":364 + * additional_info.is_tracing = False + * + * return _PyEval_EvalFrameDefault(frame_obj, exc) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = _PyEval_EvalFrameDefault(__pyx_v_frame_obj, __pyx_v_exc); + goto __pyx_L0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":252 + * + * + * cdef PyObject * get_bytecode_while_frame_eval(PyFrameObject * frame_obj, int exc): # <<<<<<<<<<<<<< + * ''' + * This function makes the actual evaluation and changes the bytecode to a version + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_WriteUnraisable("_pydevd_frame_eval.pydevd_frame_evaluator.get_bytecode_while_frame_eval", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_thread_info); + __Pyx_XDECREF((PyObject *)__pyx_v_additional_info); + __Pyx_XDECREF(__pyx_v_main_debugger); + __Pyx_XDECREF(__pyx_v_frame); + __Pyx_XDECREF(__pyx_v_trace_func); + __Pyx_XDECREF(__pyx_v_apply_to_global); + __Pyx_XDECREF((PyObject *)__pyx_v_func_code_info); + __Pyx_XDECREF(__pyx_v_old); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":367 + * + * + * def frame_eval_func(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = get_bytecode_while_frame_eval + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_11frame_eval_func(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_11frame_eval_func = {"frame_eval_func", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_11frame_eval_func, METH_NOARGS, 0}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_11frame_eval_func(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("frame_eval_func (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10frame_eval_func(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_10frame_eval_func(CYTHON_UNUSED PyObject *__pyx_self) { + PyThreadState *__pyx_v_state; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannySetupContext("frame_eval_func", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":368 + * + * def frame_eval_func(): + * cdef PyThreadState *state = PyThreadState_Get() # <<<<<<<<<<<<<< + * state.interp.eval_frame = get_bytecode_while_frame_eval + * global dummy_tracing_holder + */ + __pyx_v_state = PyThreadState_Get(); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":369 + * def frame_eval_func(): + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = get_bytecode_while_frame_eval # <<<<<<<<<<<<<< + * global dummy_tracing_holder + * dummy_tracing_holder.set_trace_func(dummy_trace_dispatch) + */ + __pyx_v_state->interp->eval_frame = __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator_get_bytecode_while_frame_eval; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":371 + * state.interp.eval_frame = get_bytecode_while_frame_eval + * global dummy_tracing_holder + * dummy_tracing_holder.set_trace_func(dummy_trace_dispatch) # <<<<<<<<<<<<<< + * + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_dummy_tracing_holder); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_set_trace_func); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_dummy_trace_dispatch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":367 + * + * + * def frame_eval_func(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = get_bytecode_while_frame_eval + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.frame_eval_func", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":374 + * + * + * def stop_frame_eval(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = _PyEval_EvalFrameDefault + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_13stop_frame_eval(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_13stop_frame_eval = {"stop_frame_eval", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_13stop_frame_eval, METH_NOARGS, 0}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_13stop_frame_eval(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("stop_frame_eval (wrapper)", 0); + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12stop_frame_eval(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_12stop_frame_eval(CYTHON_UNUSED PyObject *__pyx_self) { + PyThreadState *__pyx_v_state; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("stop_frame_eval", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":375 + * + * def stop_frame_eval(): + * cdef PyThreadState *state = PyThreadState_Get() # <<<<<<<<<<<<<< + * state.interp.eval_frame = _PyEval_EvalFrameDefault + */ + __pyx_v_state = PyThreadState_Get(); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":376 + * def stop_frame_eval(): + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = _PyEval_EvalFrameDefault # <<<<<<<<<<<<<< + */ + __pyx_v_state->interp->eval_frame = _PyEval_EvalFrameDefault; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":374 + * + * + * def stop_frame_eval(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = _PyEval_EvalFrameDefault + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_ThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_15__pyx_unpickle_ThreadInfo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_15__pyx_unpickle_ThreadInfo = {"__pyx_unpickle_ThreadInfo", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_15__pyx_unpickle_ThreadInfo, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_15__pyx_unpickle_ThreadInfo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_ThreadInfo (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_ThreadInfo", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_ThreadInfo", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_ThreadInfo") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_ThreadInfo", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.__pyx_unpickle_ThreadInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_14__pyx_unpickle_ThreadInfo(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_14__pyx_unpickle_ThreadInfo(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_ThreadInfo", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x2ccfa67: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0x2ccfa67) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0x2ccfa67: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) + * __pyx_result = ThreadInfo.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0x2ccfa67: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = ThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0x2c, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0x2ccfa67: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) + * __pyx_result = ThreadInfo.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) + * __pyx_result = ThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = ThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_ThreadInfo__set_state(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0x2ccfa67 = (additional_info, fully_initialized, inside_frame_eval, is_pydevd_thread, thread_trace_func))" % __pyx_checksum) + * __pyx_result = ThreadInfo.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_ThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.__pyx_unpickle_ThreadInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_ThreadInfo__set_state(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_ThreadInfo__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[5]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo))))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->additional_info); + __Pyx_DECREF(((PyObject *)__pyx_v___pyx_result->additional_info)); + __pyx_v___pyx_result->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->fully_initialized = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->inside_frame_eval = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->is_pydevd_thread = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->thread_trace_func); + __Pyx_DECREF(__pyx_v___pyx_result->thread_trace_func); + __pyx_v___pyx_result->thread_trace_func = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[5]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 13, __pyx_L1_error) + } + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = ((__pyx_t_4 > 5) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_2 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + __pyx_t_2 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[5]) # <<<<<<<<<<<<<< + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 14, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[5]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.__pyx_unpickle_ThreadInfo__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_FuncCodeInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_17__pyx_unpickle_FuncCodeInfo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_17__pyx_unpickle_FuncCodeInfo = {"__pyx_unpickle_FuncCodeInfo", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_17__pyx_unpickle_FuncCodeInfo, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_17__pyx_unpickle_FuncCodeInfo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_FuncCodeInfo (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_FuncCodeInfo", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_FuncCodeInfo", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_FuncCodeInfo") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_FuncCodeInfo", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L3_error:; + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.__pyx_unpickle_FuncCodeInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_16__pyx_unpickle_FuncCodeInfo(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_18_pydevd_frame_eval_22pydevd_frame_evaluator_16__pyx_unpickle_FuncCodeInfo(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + __Pyx_RefNannySetupContext("__pyx_unpickle_FuncCodeInfo", 0); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xe2c2285: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) + */ + __pyx_t_1 = ((__pyx_v___pyx_checksum != 0xe2c2285) != 0); + if (__pyx_t_1) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum != 0xe2c2285: + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) + * __pyx_result = FuncCodeInfo.__new__(__pyx_type) + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_2); + __pyx_v___pyx_PickleError = __pyx_t_2; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum != 0xe2c2285: + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) # <<<<<<<<<<<<<< + * __pyx_result = FuncCodeInfo.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_s_vs_0xe2, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_v___pyx_PickleError); + __pyx_t_2 = __pyx_v___pyx_PickleError; __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __PYX_ERR(1, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum != 0xe2c2285: # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) + * __pyx_result = FuncCodeInfo.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo), __pyx_n_s_new); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v___pyx_type); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v___pyx_result = __pyx_t_3; + __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) + * __pyx_result = FuncCodeInfo.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_1 = (__pyx_v___pyx_state != Py_None); + __pyx_t_6 = (__pyx_t_1 != 0); + if (__pyx_t_6) { + + /* "(tree fragment)":9 + * __pyx_result = FuncCodeInfo.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error) + __pyx_t_3 = __pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_FuncCodeInfo__set_state(((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError("Incompatible checksums (%s vs 0xe2c2285 = (always_skip_code, breakpoint_found, breakpoints_mtime, co_filename, new_code, real_path))" % __pyx_checksum) + * __pyx_result = FuncCodeInfo.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_FuncCodeInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.__pyx_unpickle_FuncCodeInfo", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_18_pydevd_frame_eval_22pydevd_frame_evaluator___pyx_unpickle_FuncCodeInfo__set_state(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + __Pyx_RefNannySetupContext("__pyx_unpickle_FuncCodeInfo__set_state", 0); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->always_skip_code = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->breakpoint_found = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->breakpoints_mtime = __pyx_t_3; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->co_filename); + __Pyx_DECREF(__pyx_v___pyx_result->co_filename); + __pyx_v___pyx_result->co_filename = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->new_code); + __Pyx_DECREF(__pyx_v___pyx_result->new_code); + __pyx_v___pyx_result->new_code = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->real_path); + __Pyx_DECREF(__pyx_v___pyx_result->real_path); + __pyx_v___pyx_result->real_path = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 13, __pyx_L1_error) + } + __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_5 = ((__pyx_t_4 > 6) != 0); + if (__pyx_t_5) { + } else { + __pyx_t_2 = __pyx_t_5; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + __pyx_t_2 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[6]) # <<<<<<<<<<<<<< + */ + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 14, __pyx_L1_error) + } + __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_9 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + } + } + __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_FuncCodeInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_FuncCodeInfo__set_state(FuncCodeInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.always_skip_code = __pyx_state[0]; __pyx_result.breakpoint_found = __pyx_state[1]; __pyx_result.breakpoints_mtime = __pyx_state[2]; __pyx_result.co_filename = __pyx_state[3]; __pyx_result.new_code = __pyx_state[4]; __pyx_result.real_path = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_pydevd_frame_eval.pydevd_frame_evaluator.__pyx_unpickle_FuncCodeInfo__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)o); + p->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)Py_None); Py_INCREF(Py_None); + p->thread_trace_func = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo(PyObject *o) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *p = (struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->additional_info); + Py_CLEAR(p->thread_trace_func); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *p = (struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)o; + if (p->additional_info) { + e = (*v)(((PyObject *)p->additional_info), a); if (e) return e; + } + if (p->thread_trace_func) { + e = (*v)(p->thread_trace_func, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *p = (struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo *)o; + tmp = ((PyObject*)p->additional_info); + p->additional_info = ((struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->thread_trace_func); + p->thread_trace_func = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_additional_info(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_additional_info(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_3__set__(o, v); + } + else { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_15additional_info_5__del__(o); + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_is_pydevd_thread(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_is_pydevd_thread(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_16is_pydevd_thread_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_inside_frame_eval(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_inside_frame_eval(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17inside_frame_eval_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_fully_initialized(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_fully_initialized(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17fully_initialized_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_thread_trace_func(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_thread_trace_func(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_3__set__(o, v); + } + else { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_17thread_trace_func_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo[] = { + {"initialize_if_possible", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_3initialize_if_possible, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_5__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_7__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo[] = { + {(char *)"additional_info", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_additional_info, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_additional_info, (char *)0, 0}, + {(char *)"is_pydevd_thread", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_is_pydevd_thread, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_is_pydevd_thread, (char *)0, 0}, + {(char *)"inside_frame_eval", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_inside_frame_eval, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_inside_frame_eval, (char *)0, 0}, + {(char *)"fully_initialized", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_fully_initialized, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_fully_initialized, (char *)0, 0}, + {(char *)"thread_trace_func", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_thread_trace_func, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_thread_trace_func, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_frame_eval.pydevd_frame_evaluator.ThreadInfo", /*tp_name*/ + sizeof(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo, /*tp_traverse*/ + __pyx_tp_clear_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_10ThreadInfo_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyObject *__pyx_tp_new_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *p; + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + p = ((struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)o); + p->co_filename = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->real_path = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->new_code = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo(PyObject *o) { + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *p = (struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->co_filename); + Py_CLEAR(p->real_path); + Py_CLEAR(p->new_code); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *p = (struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)o; + if (p->new_code) { + e = (*v)(p->new_code, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *p = (struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo *)o; + tmp = ((PyObject*)p->new_code); + p->new_code = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_co_filename(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_co_filename(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_3__set__(o, v); + } + else { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_11co_filename_5__del__(o); + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_real_path(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_real_path(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_3__set__(o, v); + } + else { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_9real_path_5__del__(o); + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoint_found(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoint_found(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_16breakpoint_found_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_new_code(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_new_code(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_3__set__(o, v); + } + else { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_8new_code_5__del__(o); + } +} + +static PyObject *__pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoints_mtime(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_1__get__(o); +} + +static int __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoints_mtime(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_17breakpoints_mtime_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo[] = { + {"__reduce_cython__", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_3__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_5__setstate_cython__, METH_O, 0}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo[] = { + {(char *)"co_filename", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_co_filename, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_co_filename, (char *)0, 0}, + {(char *)"real_path", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_real_path, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_real_path, (char *)0, 0}, + {(char *)"breakpoint_found", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoint_found, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoint_found, (char *)0, 0}, + {(char *)"new_code", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_new_code, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_new_code, (char *)0, 0}, + {(char *)"breakpoints_mtime", __pyx_getprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoints_mtime, __pyx_setprop_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_breakpoints_mtime, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo = { + PyVarObject_HEAD_INIT(0, 0) + "_pydevd_frame_eval.pydevd_frame_evaluator.FuncCodeInfo", /*tp_name*/ + sizeof(struct __pyx_obj_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo, /*tp_traverse*/ + __pyx_tp_clear_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_18_pydevd_frame_eval_22pydevd_frame_evaluator_12FuncCodeInfo_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + 0, /*tp_finalize*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_pydevd_frame_evaluator(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_pydevd_frame_evaluator}, + {0, NULL} +}; +#endif + +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + "pydevd_frame_evaluator", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1}, + {&__pyx_n_s_FuncCodeInfo, __pyx_k_FuncCodeInfo, sizeof(__pyx_k_FuncCodeInfo), 0, 0, 1, 1}, + {&__pyx_n_s_GlobalDebuggerHolder, __pyx_k_GlobalDebuggerHolder, sizeof(__pyx_k_GlobalDebuggerHolder), 0, 0, 1, 1}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0x2c, __pyx_k_Incompatible_checksums_s_vs_0x2c, sizeof(__pyx_k_Incompatible_checksums_s_vs_0x2c), 0, 0, 1, 0}, + {&__pyx_kp_s_Incompatible_checksums_s_vs_0xe2, __pyx_k_Incompatible_checksums_s_vs_0xe2, sizeof(__pyx_k_Incompatible_checksums_s_vs_0xe2), 0, 0, 1, 0}, + {&__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER, __pyx_k_NORM_PATHS_AND_BASE_CONTAINER, sizeof(__pyx_k_NORM_PATHS_AND_BASE_CONTAINER), 0, 0, 1, 1}, + {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_ThreadInfo, __pyx_k_ThreadInfo, sizeof(__pyx_k_ThreadInfo), 0, 0, 1, 1}, + {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0}, + {&__pyx_n_s_active, __pyx_k_active, sizeof(__pyx_k_active), 0, 0, 1, 1}, + {&__pyx_n_s_additional_info, __pyx_k_additional_info, sizeof(__pyx_k_additional_info), 0, 0, 1, 1}, + {&__pyx_n_s_arg, __pyx_k_arg, sizeof(__pyx_k_arg), 0, 0, 1, 1}, + {&__pyx_n_s_break_on_caught_exceptions, __pyx_k_break_on_caught_exceptions, sizeof(__pyx_k_break_on_caught_exceptions), 0, 0, 1, 1}, + {&__pyx_n_s_breakpoints, __pyx_k_breakpoints, sizeof(__pyx_k_breakpoints), 0, 0, 1, 1}, + {&__pyx_n_s_call, __pyx_k_call, sizeof(__pyx_k_call), 0, 0, 1, 1}, + {&__pyx_n_s_can_skip, __pyx_k_can_skip, sizeof(__pyx_k_can_skip), 0, 0, 1, 1}, + {&__pyx_n_s_clear_thread_local_info, __pyx_k_clear_thread_local_info, sizeof(__pyx_k_clear_thread_local_info), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_code_extra_index, __pyx_k_code_extra_index, sizeof(__pyx_k_code_extra_index), 0, 0, 1, 1}, + {&__pyx_n_s_code_obj, __pyx_k_code_obj, sizeof(__pyx_k_code_obj), 0, 0, 1, 1}, + {&__pyx_n_s_create_pydev_trace_code_wrapper, __pyx_k_create_pydev_trace_code_wrapper, sizeof(__pyx_k_create_pydev_trace_code_wrapper), 0, 0, 1, 1}, + {&__pyx_n_s_decref_py, __pyx_k_decref_py, sizeof(__pyx_k_decref_py), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_n_s_dis, __pyx_k_dis, sizeof(__pyx_k_dis), 0, 0, 1, 1}, + {&__pyx_n_s_dummy_trace_dispatch, __pyx_k_dummy_trace_dispatch, sizeof(__pyx_k_dummy_trace_dispatch), 0, 0, 1, 1}, + {&__pyx_n_s_dummy_tracing_holder, __pyx_k_dummy_tracing_holder, sizeof(__pyx_k_dummy_tracing_holder), 0, 0, 1, 1}, + {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1}, + {&__pyx_n_s_event, __pyx_k_event, sizeof(__pyx_k_event), 0, 0, 1, 1}, + {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1}, + {&__pyx_n_s_f_back, __pyx_k_f_back, sizeof(__pyx_k_f_back), 0, 0, 1, 1}, + {&__pyx_n_s_f_trace, __pyx_k_f_trace, sizeof(__pyx_k_f_trace), 0, 0, 1, 1}, + {&__pyx_n_s_findlinestarts, __pyx_k_findlinestarts, sizeof(__pyx_k_findlinestarts), 0, 0, 1, 1}, + {&__pyx_n_s_fix_top_level_trace_and_get_trac, __pyx_k_fix_top_level_trace_and_get_trac, sizeof(__pyx_k_fix_top_level_trace_and_get_trac), 0, 0, 1, 1}, + {&__pyx_n_s_frame, __pyx_k_frame, sizeof(__pyx_k_frame), 0, 0, 1, 1}, + {&__pyx_n_s_frame_eval_func, __pyx_k_frame_eval_func, sizeof(__pyx_k_frame_eval_func), 0, 0, 1, 1}, + {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, + {&__pyx_n_s_get_abs_path_real_path_and_base, __pyx_k_get_abs_path_real_path_and_base, sizeof(__pyx_k_get_abs_path_real_path_and_base), 0, 0, 1, 1}, + {&__pyx_n_s_get_cache_file_type, __pyx_k_get_cache_file_type, sizeof(__pyx_k_get_cache_file_type), 0, 0, 1, 1}, + {&__pyx_n_s_get_file_type, __pyx_k_get_file_type, sizeof(__pyx_k_get_file_type), 0, 0, 1, 1}, + {&__pyx_n_s_get_func_code_info_py, __pyx_k_get_func_code_info_py, sizeof(__pyx_k_get_func_code_info_py), 0, 0, 1, 1}, + {&__pyx_n_s_get_ident, __pyx_k_get_ident, sizeof(__pyx_k_get_ident), 0, 0, 1, 1}, + {&__pyx_n_s_get_thread_info_py, __pyx_k_get_thread_info_py, sizeof(__pyx_k_get_thread_info_py), 0, 0, 1, 1}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_global_dbg, __pyx_k_global_dbg, sizeof(__pyx_k_global_dbg), 0, 0, 1, 1}, + {&__pyx_n_s_has_plugin_exception_breaks, __pyx_k_has_plugin_exception_breaks, sizeof(__pyx_k_has_plugin_exception_breaks), 0, 0, 1, 1}, + {&__pyx_n_s_has_plugin_line_breaks, __pyx_k_has_plugin_line_breaks, sizeof(__pyx_k_has_plugin_line_breaks), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_initialize_if_possible, __pyx_k_initialize_if_possible, sizeof(__pyx_k_initialize_if_possible), 0, 0, 1, 1}, + {&__pyx_n_s_insert_code, __pyx_k_insert_code, sizeof(__pyx_k_insert_code), 0, 0, 1, 1}, + {&__pyx_n_s_is_pydev_daemon_thread, __pyx_k_is_pydev_daemon_thread, sizeof(__pyx_k_is_pydev_daemon_thread), 0, 0, 1, 1}, + {&__pyx_n_s_local, __pyx_k_local, sizeof(__pyx_k_local), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_mtime, __pyx_k_mtime, sizeof(__pyx_k_mtime), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, + {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 0, 0, 1, 1}, + {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_s_plugin, __pyx_k_plugin, sizeof(__pyx_k_plugin), 0, 0, 1, 1}, + {&__pyx_n_s_pydev_imps__pydev_saved_modules, __pyx_k_pydev_imps__pydev_saved_modules, sizeof(__pyx_k_pydev_imps__pydev_saved_modules), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_additional, __pyx_k_pydevd_bundle_pydevd_additional, sizeof(__pyx_k_pydevd_bundle_pydevd_additional), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_comm, __pyx_k_pydevd_bundle_pydevd_comm, sizeof(__pyx_k_pydevd_bundle_pydevd_comm), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_bundle_pydevd_trace_disp, __pyx_k_pydevd_bundle_pydevd_trace_disp, sizeof(__pyx_k_pydevd_bundle_pydevd_trace_disp), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_file_utils, __pyx_k_pydevd_file_utils, sizeof(__pyx_k_pydevd_file_utils), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_frame_eval_pydevd_frame, __pyx_k_pydevd_frame_eval_pydevd_frame, sizeof(__pyx_k_pydevd_frame_eval_pydevd_frame), 0, 0, 1, 1}, + {&__pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_k_pydevd_frame_eval_pydevd_frame_2, sizeof(__pyx_k_pydevd_frame_eval_pydevd_frame_2), 0, 0, 1, 0}, + {&__pyx_n_s_pydevd_frame_eval_pydevd_frame_3, __pyx_k_pydevd_frame_eval_pydevd_frame_3, sizeof(__pyx_k_pydevd_frame_eval_pydevd_frame_3), 0, 0, 1, 1}, + {&__pyx_n_s_pydevd_frame_eval_pydevd_modify, __pyx_k_pydevd_frame_eval_pydevd_modify, sizeof(__pyx_k_pydevd_frame_eval_pydevd_modify), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_FuncCodeInfo, __pyx_k_pyx_unpickle_FuncCodeInfo, sizeof(__pyx_k_pyx_unpickle_FuncCodeInfo), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_ThreadInfo, __pyx_k_pyx_unpickle_ThreadInfo, sizeof(__pyx_k_pyx_unpickle_ThreadInfo), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_set_additional_thread_info_lock, __pyx_k_set_additional_thread_info_lock, sizeof(__pyx_k_set_additional_thread_info_lock), 0, 0, 1, 1}, + {&__pyx_n_s_set_trace_func, __pyx_k_set_trace_func, sizeof(__pyx_k_set_trace_func), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_show_return_values, __pyx_k_show_return_values, sizeof(__pyx_k_show_return_values), 0, 0, 1, 1}, + {&__pyx_n_s_signature_factory, __pyx_k_signature_factory, sizeof(__pyx_k_signature_factory), 0, 0, 1, 1}, + {&__pyx_n_s_state, __pyx_k_state, sizeof(__pyx_k_state), 0, 0, 1, 1}, + {&__pyx_n_s_stop_frame_eval, __pyx_k_stop_frame_eval, sizeof(__pyx_k_stop_frame_eval), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_thread, __pyx_k_thread, sizeof(__pyx_k_thread), 0, 0, 1, 1}, + {&__pyx_n_s_thread_info, __pyx_k_thread_info, sizeof(__pyx_k_thread_info), 0, 0, 1, 1}, + {&__pyx_n_s_thread_local_info, __pyx_k_thread_local_info, sizeof(__pyx_k_thread_local_info), 0, 0, 1, 1}, + {&__pyx_n_s_threading, __pyx_k_threading, sizeof(__pyx_k_threading), 0, 0, 1, 1}, + {&__pyx_n_s_trace_dispatch, __pyx_k_trace_dispatch, sizeof(__pyx_k_trace_dispatch), 0, 0, 1, 1}, + {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_n_s_update_globals_dict, __pyx_k_update_globals_dict, sizeof(__pyx_k_update_globals_dict), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 54, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":56 + * raise AttributeError() + * except: + * with _set_additional_thread_info_lock: # <<<<<<<<<<<<<< + * # If it's not there, set it within a lock to avoid any racing + * # conditions. + */ + __pyx_tuple_ = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":16 + * _thread_local_info = threading.local() + * + * def clear_thread_local_info(): # <<<<<<<<<<<<<< + * global _thread_local_info + * _thread_local_info = threading.local() + */ + __pyx_codeobj__3 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_clear_thread_local_info, 16, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__3)) __PYX_ERR(0, 16, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":95 + * + * + * def dummy_trace_dispatch(frame, str event, arg): # <<<<<<<<<<<<<< + * if event == 'call': + * if frame.f_trace is not None: + */ + __pyx_tuple__4 = PyTuple_Pack(3, __pyx_n_s_frame, __pyx_n_s_event, __pyx_n_s_arg); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 95, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_dummy_trace_dispatch, 95, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 95, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":102 + * + * + * def get_thread_info_py() -> ThreadInfo: # <<<<<<<<<<<<<< + * return get_thread_info() + * + */ + __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_get_thread_info_py, 102, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 102, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":136 + * + * + * def decref_py(obj): # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_n_s_obj); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_decref_py, 136, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 136, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":143 + * + * + * def get_func_code_info_py(frame, code_obj) -> FuncCodeInfo: # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_frame, __pyx_n_s_code_obj); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_get_func_code_info_py, 143, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(0, 143, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":367 + * + * + * def frame_eval_func(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = get_bytecode_while_frame_eval + */ + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_n_s_state); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_frame_eval_func, 367, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 367, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":374 + * + * + * def stop_frame_eval(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = _PyEval_EvalFrameDefault + */ + __pyx_tuple__13 = PyTuple_Pack(1, __pyx_n_s_state); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pydevd_frame_eval_pydevd_frame_2, __pyx_n_s_stop_frame_eval, 374, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 374, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __pyx_unpickle_ThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_tuple__15 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_ThreadInfo, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(1, 1, __pyx_L1_error) + __pyx_tuple__17 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__17); + __Pyx_GIVEREF(__pyx_tuple__17); + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_FuncCodeInfo, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_46987879 = PyInt_FromLong(46987879L); if (unlikely(!__pyx_int_46987879)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_237773445 = PyInt_FromLong(237773445L); if (unlikely(!__pyx_int_237773445)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo) < 0) __PYX_ERR(0, 21, __pyx_L1_error) + __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo.tp_dictoffset && __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_ThreadInfo, (PyObject *)&__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo) < 0) __PYX_ERR(0, 21, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo) < 0) __PYX_ERR(0, 21, __pyx_L1_error) + __pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo = &__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_ThreadInfo; + if (PyType_Ready(&__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo.tp_print = 0; + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo.tp_dictoffset && __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_FuncCodeInfo, (PyObject *)&__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo) < 0) __PYX_ERR(0, 69, __pyx_L1_error) + __pyx_ptype_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo = &__pyx_type_18_pydevd_frame_eval_22pydevd_frame_evaluator_FuncCodeInfo; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule("_pydevd_bundle.pydevd_cython"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo = __Pyx_ImportType(__pyx_t_1, "_pydevd_bundle.pydevd_cython", "PyDBAdditionalThreadInfo", sizeof(struct __pyx_obj_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_14_pydevd_bundle_13pydevd_cython_PyDBAdditionalThreadInfo) __PYX_ERR(2, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION < 3 +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC void +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#else +#ifdef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initpydevd_frame_evaluator(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initpydevd_frame_evaluator(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_pydevd_frame_evaluator(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_pydevd_frame_evaluator(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_pydevd_frame_evaluator(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'pydevd_frame_evaluator' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_pydevd_frame_evaluator(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("pydevd_frame_evaluator", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_b); + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main__pydevd_frame_eval__pydevd_frame_evaluator) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "_pydevd_frame_eval.pydevd_frame_evaluator")) { + if (unlikely(PyDict_SetItemString(modules, "_pydevd_frame_eval.pydevd_frame_evaluator", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error; + if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error; + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":2 + * from __future__ import print_function + * import dis # <<<<<<<<<<<<<< + * from _pydev_imps._pydev_saved_modules import threading, thread + * from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder + */ + __pyx_t_1 = __Pyx_Import(__pyx_n_s_dis, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_dis, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":3 + * from __future__ import print_function + * import dis + * from _pydev_imps._pydev_saved_modules import threading, thread # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder + * from _pydevd_frame_eval.pydevd_frame_tracing import create_pydev_trace_code_wrapper, update_globals_dict, dummy_tracing_holder + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_threading); + __Pyx_GIVEREF(__pyx_n_s_threading); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_threading); + __Pyx_INCREF(__pyx_n_s_thread); + __Pyx_GIVEREF(__pyx_n_s_thread); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_thread); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydev_imps__pydev_saved_modules, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_threading); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_threading, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_thread); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_thread, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":4 + * import dis + * from _pydev_imps._pydev_saved_modules import threading, thread + * from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder # <<<<<<<<<<<<<< + * from _pydevd_frame_eval.pydevd_frame_tracing import create_pydev_trace_code_wrapper, update_globals_dict, dummy_tracing_holder + * from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_GlobalDebuggerHolder); + __Pyx_GIVEREF(__pyx_n_s_GlobalDebuggerHolder); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_GlobalDebuggerHolder); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_comm, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_GlobalDebuggerHolder); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_GlobalDebuggerHolder, __pyx_t_2) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":5 + * from _pydev_imps._pydev_saved_modules import threading, thread + * from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder + * from _pydevd_frame_eval.pydevd_frame_tracing import create_pydev_trace_code_wrapper, update_globals_dict, dummy_tracing_holder # <<<<<<<<<<<<<< + * from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_file, NORM_PATHS_AND_BASE_CONTAINER + */ + __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_create_pydev_trace_code_wrapper); + __Pyx_GIVEREF(__pyx_n_s_create_pydev_trace_code_wrapper); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_create_pydev_trace_code_wrapper); + __Pyx_INCREF(__pyx_n_s_update_globals_dict); + __Pyx_GIVEREF(__pyx_n_s_update_globals_dict); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_update_globals_dict); + __Pyx_INCREF(__pyx_n_s_dummy_tracing_holder); + __Pyx_GIVEREF(__pyx_n_s_dummy_tracing_holder); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_dummy_tracing_holder); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydevd_frame_eval_pydevd_frame, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_create_pydev_trace_code_wrapper); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_create_pydev_trace_code_wrapper, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_update_globals_dict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_update_globals_dict, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_dummy_tracing_holder); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_dummy_tracing_holder, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":6 + * from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder + * from _pydevd_frame_eval.pydevd_frame_tracing import create_pydev_trace_code_wrapper, update_globals_dict, dummy_tracing_holder + * from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code # <<<<<<<<<<<<<< + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_file, NORM_PATHS_AND_BASE_CONTAINER + * from _pydevd_bundle.pydevd_trace_dispatch import fix_top_level_trace_and_get_trace_func + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_insert_code); + __Pyx_GIVEREF(__pyx_n_s_insert_code); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_insert_code); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_frame_eval_pydevd_modify, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_insert_code); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_insert_code, __pyx_t_2) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":7 + * from _pydevd_frame_eval.pydevd_frame_tracing import create_pydev_trace_code_wrapper, update_globals_dict, dummy_tracing_holder + * from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_file, NORM_PATHS_AND_BASE_CONTAINER # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_trace_dispatch import fix_top_level_trace_and_get_trace_func + * + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_get_abs_path_real_path_and_base); + __Pyx_GIVEREF(__pyx_n_s_get_abs_path_real_path_and_base); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_get_abs_path_real_path_and_base); + __Pyx_INCREF(__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); + __Pyx_GIVEREF(__pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydevd_file_utils, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_get_abs_path_real_path_and_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_abs_path_real_path_and_base, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_NORM_PATHS_AND_BASE_CONTAINER, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":8 + * from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code + * from pydevd_file_utils import get_abs_path_real_path_and_base_from_file, NORM_PATHS_AND_BASE_CONTAINER + * from _pydevd_bundle.pydevd_trace_dispatch import fix_top_level_trace_and_get_trace_func # <<<<<<<<<<<<<< + * + * from _pydevd_bundle.pydevd_additional_thread_info import _set_additional_thread_info_lock + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_fix_top_level_trace_and_get_trac); + __Pyx_GIVEREF(__pyx_n_s_fix_top_level_trace_and_get_trac); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_fix_top_level_trace_and_get_trac); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_trace_disp, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_fix_top_level_trace_and_get_trac); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_fix_top_level_trace_and_get_trac, __pyx_t_2) < 0) __PYX_ERR(0, 8, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":10 + * from _pydevd_bundle.pydevd_trace_dispatch import fix_top_level_trace_and_get_trace_func + * + * from _pydevd_bundle.pydevd_additional_thread_info import _set_additional_thread_info_lock # <<<<<<<<<<<<<< + * from _pydevd_bundle.pydevd_cython cimport PyDBAdditionalThreadInfo + * + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_set_additional_thread_info_lock); + __Pyx_GIVEREF(__pyx_n_s_set_additional_thread_info_lock); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_set_additional_thread_info_lock); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_pydevd_bundle_pydevd_additional, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_set_additional_thread_info_lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_additional_thread_info_lock, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":14 + * + * + * _thread_local_info = threading.local() # <<<<<<<<<<<<<< + * + * def clear_thread_local_info(): + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_threading); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_local); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_thread_local_info, __pyx_t_2) < 0) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":16 + * _thread_local_info = threading.local() + * + * def clear_thread_local_info(): # <<<<<<<<<<<<<< + * global _thread_local_info + * _thread_local_info = threading.local() + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_1clear_thread_local_info, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_clear_thread_local_info, __pyx_t_2) < 0) __PYX_ERR(0, 16, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":95 + * + * + * def dummy_trace_dispatch(frame, str event, arg): # <<<<<<<<<<<<<< + * if event == 'call': + * if frame.f_trace is not None: + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_3dummy_trace_dispatch, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 95, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_dummy_trace_dispatch, __pyx_t_2) < 0) __PYX_ERR(0, 95, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":102 + * + * + * def get_thread_info_py() -> ThreadInfo: # <<<<<<<<<<<<<< + * return get_thread_info() + * + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_5get_thread_info_py, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_thread_info_py, __pyx_t_2) < 0) __PYX_ERR(0, 102, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":136 + * + * + * def decref_py(obj): # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_7decref_py, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_decref_py, __pyx_t_2) < 0) __PYX_ERR(0, 136, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":143 + * + * + * def get_func_code_info_py(frame, code_obj) -> FuncCodeInfo: # <<<<<<<<<<<<<< + * ''' + * Helper to be called from Python. + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_9get_func_code_info_py, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_func_code_info_py, __pyx_t_2) < 0) __PYX_ERR(0, 143, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":150 + * + * + * _code_extra_index: Py_SIZE = -1 # <<<<<<<<<<<<<< + * + * cdef FuncCodeInfo get_func_code_info(PyFrameObject * frame_obj, PyCodeObject * code_obj): + */ + if (PyDict_SetItem(__pyx_d, __pyx_n_s_code_extra_index, __pyx_int_neg_1) < 0) __PYX_ERR(0, 150, __pyx_L1_error) + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":367 + * + * + * def frame_eval_func(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = get_bytecode_while_frame_eval + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_11frame_eval_func, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_frame_eval_func, __pyx_t_2) < 0) __PYX_ERR(0, 367, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":374 + * + * + * def stop_frame_eval(): # <<<<<<<<<<<<<< + * cdef PyThreadState *state = PyThreadState_Get() + * state.interp.eval_frame = _PyEval_EvalFrameDefault + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_13stop_frame_eval, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_stop_frame_eval, __pyx_t_2) < 0) __PYX_ERR(0, 374, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_ThreadInfo(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_15__pyx_unpickle_ThreadInfo, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_ThreadInfo, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":11 + * __pyx_unpickle_ThreadInfo__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_ThreadInfo__set_state(ThreadInfo __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.additional_info = __pyx_state[0]; __pyx_result.fully_initialized = __pyx_state[1]; __pyx_result.inside_frame_eval = __pyx_state[2]; __pyx_result.is_pydevd_thread = __pyx_state[3]; __pyx_result.thread_trace_func = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + */ + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_18_pydevd_frame_eval_22pydevd_frame_evaluator_17__pyx_unpickle_FuncCodeInfo, NULL, __pyx_n_s_pydevd_frame_eval_pydevd_frame_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_FuncCodeInfo, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "_pydevd_frame_eval/pydevd_frame_evaluator.pyx":1 + * from __future__ import print_function # <<<<<<<<<<<<<< + * import dis + * from _pydev_imps._pydev_saved_modules import threading, thread + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + if (__pyx_m) { + if (__pyx_d) { + __Pyx_AddTraceback("init _pydevd_frame_eval.pydevd_frame_evaluator", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + Py_CLEAR(__pyx_m); + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init _pydevd_frame_eval.pydevd_frame_evaluator"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); + if (unlikely(!result)) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { + return NULL; + } + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif +#endif + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = PyCFunction_GET_FUNCTION(func); + self = PyCFunction_GET_SELF(func); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallNoArg */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, NULL, 0); + } +#endif +#ifdef __Pyx_CyFunction_USED + if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) +#else + if (likely(PyCFunction_Check(func))) +#endif + { + if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { + return __Pyx_PyObject_CallMethO(func, NULL); + } + } + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); +} +#endif + +/* PyCFunctionFastCall */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { + PyCFunctionObject *func = (PyCFunctionObject*)func_obj; + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + int flags = PyCFunction_GET_FLAGS(func); + assert(PyCFunction_Check(func)); + assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); + assert(nargs >= 0); + assert(nargs == 0 || args != NULL); + /* _PyCFunction_FastCallDict() must not be called with an exception set, + because it may clear it (directly or indirectly) and so the + caller loses its exception */ + assert(!PyErr_Occurred()); + if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { + return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); + } +} +#endif + +/* PyObjectCallOneArg */ +#if CYTHON_COMPILING_IN_CPYTHON +static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_New(1); + if (unlikely(!args)) return NULL; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, &arg, 1); + } +#endif + if (likely(PyCFunction_Check(func))) { + if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { + return __Pyx_PyObject_CallMethO(func, arg); +#if CYTHON_FAST_PYCCALL + } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) { + return __Pyx_PyCFunction_FastCall(func, &arg, 1); +#endif + } + } + return __Pyx__PyObject_CallOneArg(func, arg); +} +#else +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_Pack(1, arg); + if (unlikely(!args)) return NULL; + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +#endif + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* KeywordStringCheck */ +static int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + +/* PyObjectCall2Args */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args, *result = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyFunction_FastCall(function, args, 2); + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyCFunction_FastCall(function, args, 2); + } + #endif + args = PyTuple_New(2); + if (unlikely(!args)) goto done; + Py_INCREF(arg1); + PyTuple_SET_ITEM(args, 0, arg1); + Py_INCREF(arg2); + PyTuple_SET_ITEM(args, 1, arg2); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); +done: + return result; +} + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; icurexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; + if (unlikely(PyTuple_Check(err))) + return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} +#endif + +/* GetAttr */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_USE_TYPE_SLOTS +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* GetAttr3 */ +static PyObject *__Pyx_GetAttr3Default(PyObject *d) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + Py_INCREF(d); + return d; +} +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { + PyObject *r = __Pyx_GetAttr(o, n); + return (likely(r)) ? r : __Pyx_GetAttr3Default(d); +} + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + __Pyx_PyThreadState_declare + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + #endif + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} +#endif + +/* GetException */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) +#endif +{ + PyObject *local_type, *local_value, *local_tb; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* PyObjectSetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +#endif + return PyObject_SetAttr(obj, attr_name, value); +} +#endif + +/* None */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +/* ExtTypeTest */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(__Pyx_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* RaiseDoubleKeywords */ +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + continue; + } + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = (**name == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +/* ArgTypeTest */ +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* PyIntCompare */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) { + if (op1 == op2) { + Py_RETURN_TRUE; + } + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long a = PyInt_AS_LONG(op1); + if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + int unequal; + unsigned long uintval; + Py_ssize_t size = Py_SIZE(op1); + const digit* digits = ((PyLongObject*)op1)->ob_digit; + if (intval == 0) { + if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } else if (intval < 0) { + if (size >= 0) + Py_RETURN_FALSE; + intval = -intval; + size = -size; + } else { + if (size <= 0) + Py_RETURN_FALSE; + } + uintval = (unsigned long) intval; +#if PyLong_SHIFT * 4 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 4)) { + unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 3 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 3)) { + unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 2 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 2)) { + unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif +#if PyLong_SHIFT * 1 < SIZEOF_LONG*8 + if (uintval >> (PyLong_SHIFT * 1)) { + unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) + | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)); + } else +#endif + unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK)); + if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; + double a = PyFloat_AS_DOUBLE(op1); + if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE; + } + return ( + PyObject_RichCompare(op1, op2, Py_EQ)); +} + +/* DictGetItem */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* GetItemInt */ +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* RaiseTooManyValuesToUnpack */ +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); +} + +/* RaiseNeedMoreValuesToUnpack */ +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", + index, (index == 1) ? "" : "s"); +} + +/* IterFinish */ +static CYTHON_INLINE int __Pyx_IterFinish(void) { +#if CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* exc_type = tstate->curexc_type; + if (unlikely(exc_type)) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) { + PyObject *exc_value, *exc_tb; + exc_value = tstate->curexc_value; + exc_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + Py_DECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_tb); + return 0; + } else { + return -1; + } + } + return 0; +#else + if (unlikely(PyErr_Occurred())) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +#endif +} + +/* UnpackItemEndCheck */ +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else { + return __Pyx_IterFinish(); + } + return 0; +} + +/* WriteUnraisableException */ +static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, + int full_traceback, CYTHON_UNUSED int nogil) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_PyThreadState_declare +#ifdef WITH_THREAD + PyGILState_STATE state; + if (nogil) + state = PyGILState_Ensure(); +#ifdef _MSC_VER + else state = (PyGILState_STATE)-1; +#endif +#endif + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + if (full_traceback) { + Py_XINCREF(old_exc); + Py_XINCREF(old_val); + Py_XINCREF(old_tb); + __Pyx_ErrRestore(old_exc, old_val, old_tb); + PyErr_PrintEx(1); + } + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +#ifdef WITH_THREAD + if (nogil) + PyGILState_Release(state); +#endif +} + +/* Import */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (!py_import) + goto bad; + #endif + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, 1); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif + } + } +bad: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +/* ImportFrom */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + +/* HasAttr */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { + PyObject *r; + if (unlikely(!__Pyx_PyBaseString_Check(n))) { + PyErr_SetString(PyExc_TypeError, + "hasattr(): attribute name must be string"); + return -1; + } + r = __Pyx_GetAttr(o, n); + if (unlikely(!r)) { + PyErr_Clear(); + return 0; + } else { + Py_DECREF(r); + return 1; + } +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, attr_name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(attr_name)); +#endif + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* SetupReduce */ +static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD; + setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD; + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD; + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto GOOD; +BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} + +/* TypeImport */ +#ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, + size_t size, enum __Pyx_ImportType_CheckSize check_size) +{ + PyObject *result = 0; + char warning[200]; + Py_ssize_t basicsize; +#ifdef Py_LIMITED_API + PyObject *py_basicsize; +#endif + result = PyObject_GetAttrString(module, class_name); + if (!result) + goto bad; + if (!PyType_Check(result)) { + PyErr_Format(PyExc_TypeError, + "%.200s.%.200s is not a type object", + module_name, class_name); + goto bad; + } +#ifndef Py_LIMITED_API + basicsize = ((PyTypeObject *)result)->tp_basicsize; +#else + py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); + if (!py_basicsize) + goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) + goto bad; +#endif + if ((size_t)basicsize < size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(result); + return NULL; +} +#endif + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); + } +} + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + int val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (int) -1; + } + } else { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(long) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(long) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } +#endif + if (sizeof(long) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + long val; + PyObject *v = __Pyx_PyNumber_IntOrLong(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (long) -1; + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = a->tp_base; + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; ip) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + ++t; + } + return 0; +} + +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type %.200s). " + "The ability to return an instance of a strict subclass of int " + "is deprecated, and may be removed in a future version of Python.", + Py_TYPE(result)->tp_name)) { + Py_DECREF(result); + return NULL; + } + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + type_name, type_name, Py_TYPE(result)->tp_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +#endif /* Py_PYTHON_H */ diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pxd b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pxd new file mode 100644 index 0000000..bceae73 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pxd @@ -0,0 +1,102 @@ +from cpython.mem cimport PyMem_Malloc, PyMem_Free + +cdef extern from *: + ctypedef void PyObject + ctypedef struct PyCodeObject: + int co_argcount; # arguments, except *args */ + int co_kwonlyargcount; # keyword only arguments */ + int co_nlocals; # local variables */ + int co_stacksize; # entries needed for evaluation stack */ + int co_flags; # CO_..., see below */ + int co_firstlineno; # first source line number */ + PyObject *co_code; # instruction opcodes */ + PyObject *co_consts; # list (constants used) */ + PyObject *co_names; # list of strings (names used) */ + PyObject *co_varnames; # tuple of strings (local variable names) */ + PyObject *co_freevars; # tuple of strings (free variable names) */ + PyObject *co_cellvars; # tuple of strings (cell variable names) */ + unsigned char *co_cell2arg; # Maps cell vars which are arguments. */ + PyObject *co_filename; # unicode (where it was loaded from) */ + PyObject *co_name; # unicode (name, for reference) */ + PyObject *co_lnotab; # string (encoding addr<->lineno mapping) See + # Objects/lnotab_notes.txt for details. */ + void *co_zombieframe; # for optimization only (see frameobject.c) */ + PyObject *co_weakreflist; # to support weakrefs to code objects */ + void *co_extra; + +cdef extern from "frameobject.h": + ctypedef struct PyFrameObject: + PyCodeObject *f_code # code segment + PyObject *f_builtins # builtin symbol table (PyDictObject) + PyObject *f_globals # global symbol table (PyDictObject) */ + PyObject *f_locals # local symbol table (any mapping) */ + PyObject **f_valuestack # + PyObject **f_stacktop + PyObject *f_trace # Trace function */ + PyObject *f_exc_type + PyObject *f_exc_value + PyObject *f_exc_traceback + PyObject *f_gen; + + int f_lasti; #/* Last instruction if called */ + int f_lineno; #/* Current line number */ + int f_iblock; #/* index in f_blockstack */ + char f_executing; #/* whether the frame is still executing */ + PyObject *f_localsplus[1]; + +cdef extern from "release_mem.h": + void release_co_extra(void *) + +cdef extern from "code.h": + ctypedef void freefunc(void *) + int _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra) + int _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra) + +cdef extern from "Python.h": + void Py_INCREF(object o) + void Py_DECREF(object o) + object PyImport_ImportModule(char *name) + PyObject* PyObject_CallFunction(PyObject *callable, const char *format, ...) + object PyObject_GetAttrString(object o, char *attr_name) + +cdef extern from "pystate.h": + ctypedef PyObject* _PyFrameEvalFunction(PyFrameObject *frame, int exc) + + ctypedef struct PyInterpreterState: + PyInterpreterState *next + PyInterpreterState *tstate_head + + PyObject *modules + + PyObject *modules_by_index + PyObject *sysdict + PyObject *builtins + PyObject *importlib + + PyObject *codec_search_path + PyObject *codec_search_cache + PyObject *codec_error_registry + int codecs_initialized + int fscodec_initialized + + int dlopenflags + + PyObject *builtins_copy + PyObject *import_func + # Initialized to PyEval_EvalFrameDefault(). + _PyFrameEvalFunction eval_frame + + ctypedef struct PyThreadState: + PyThreadState *prev + PyThreadState *next + PyInterpreterState *interp + # ... + + PyThreadState *PyThreadState_Get() + +cdef extern from "ceval.h": + int _PyEval_RequestCodeExtraIndex(freefunc) + PyFrameObject *PyEval_GetFrame() + PyObject* PyEval_CallFunction(PyObject *callable, const char *format, ...) + + PyObject* _PyEval_EvalFrameDefault(PyFrameObject *frame, int exc) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pyx b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pyx new file mode 100644 index 0000000..5797784 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.pyx @@ -0,0 +1,376 @@ +from __future__ import print_function +import dis +from _pydev_imps._pydev_saved_modules import threading, thread +from _pydevd_bundle.pydevd_comm import GlobalDebuggerHolder +from _pydevd_frame_eval.pydevd_frame_tracing import create_pydev_trace_code_wrapper, update_globals_dict, dummy_tracing_holder +from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code +from pydevd_file_utils import get_abs_path_real_path_and_base_from_file, NORM_PATHS_AND_BASE_CONTAINER +from _pydevd_bundle.pydevd_trace_dispatch import fix_top_level_trace_and_get_trace_func + +from _pydevd_bundle.pydevd_additional_thread_info import _set_additional_thread_info_lock +from _pydevd_bundle.pydevd_cython cimport PyDBAdditionalThreadInfo + + +_thread_local_info = threading.local() + +def clear_thread_local_info(): + global _thread_local_info + _thread_local_info = threading.local() + + +cdef class ThreadInfo: + + cdef public PyDBAdditionalThreadInfo additional_info + cdef public bint is_pydevd_thread + cdef public int inside_frame_eval + cdef public bint fully_initialized + cdef public object thread_trace_func + + def __init__(self): + self.additional_info = None + self.is_pydevd_thread = False + self.inside_frame_eval = 0 + self.fully_initialized = False + self.thread_trace_func = None + + def initialize_if_possible(self): + # Don't call threading.currentThread because if we're too early in the process + # we may create a dummy thread. + self.inside_frame_eval += 1 + + try: + thread_ident = threading.get_ident() # Note this is py3 only, if py2 needed to be supported, _get_ident would be needed. + t = threading._active.get(thread_ident) + if t is None: + return # Cannot initialize until thread becomes active. + + if getattr(t, 'is_pydev_daemon_thread', False): + self.is_pydevd_thread = True + self.fully_initialized = True + else: + try: + additional_info = t.additional_info + if additional_info is None: + raise AttributeError() + except: + with _set_additional_thread_info_lock: + # If it's not there, set it within a lock to avoid any racing + # conditions. + additional_info = getattr(thread, 'additional_info', None) + if additional_info is None: + additional_info = PyDBAdditionalThreadInfo() + t.additional_info = additional_info + self.additional_info = additional_info + self.fully_initialized = True + finally: + self.inside_frame_eval -= 1 + + +cdef class FuncCodeInfo: + + cdef public str co_filename + cdef public str real_path + cdef bint always_skip_code + cdef public bint breakpoint_found + cdef public object new_code + + # When breakpoints_mtime != PyDb.mtime the validity of breakpoints have + # to be re-evaluated (if invalid a new FuncCodeInfo must be created and + # tracing can't be disabled for the related frames). + cdef public int breakpoints_mtime + + def __init__(self): + self.co_filename = '' + self.real_path = '' + self.always_skip_code = False + + # If breakpoints are found but new_code is None, + # this means we weren't able to actually add the code + # where needed, so, fallback to tracing. + self.breakpoint_found = False + self.new_code = None + self.breakpoints_mtime = -1 + + +def dummy_trace_dispatch(frame, str event, arg): + if event == 'call': + if frame.f_trace is not None: + return frame.f_trace(frame, event, arg) + return None + + +def get_thread_info_py() -> ThreadInfo: + return get_thread_info() + + +cdef ThreadInfo get_thread_info(): + ''' + Provides thread-related info. + + May return None if the thread is still not active. + ''' + cdef ThreadInfo thread_info + try: + # Note: changing to a `dict[thread.ident] = thread_info` had almost no + # effect in the performance. + thread_info = _thread_local_info.thread_info + except: + thread_info = ThreadInfo() + thread_info.inside_frame_eval += 1 + try: + _thread_local_info.thread_info = thread_info + + # Note: _code_extra_index is not actually thread-related, + # but this is a good point to initialize it. + global _code_extra_index + if _code_extra_index == -1: + _code_extra_index = _PyEval_RequestCodeExtraIndex(release_co_extra) + + thread_info.initialize_if_possible() + finally: + thread_info.inside_frame_eval -= 1 + + return thread_info + + +def decref_py(obj): + ''' + Helper to be called from Python. + ''' + Py_DECREF(obj) + + +def get_func_code_info_py(frame, code_obj) -> FuncCodeInfo: + ''' + Helper to be called from Python. + ''' + return get_func_code_info( frame, code_obj) + + +_code_extra_index: Py_SIZE = -1 + +cdef FuncCodeInfo get_func_code_info(PyFrameObject * frame_obj, PyCodeObject * code_obj): + ''' + Provides code-object related info. + + Stores the gathered info in a cache in the code object itself. Note that + multiple threads can get the same info. + + get_thread_info() *must* be called at least once before get_func_code_info() + to initialize _code_extra_index. + ''' + # f_code = code_obj + # DEBUG = f_code.co_filename.endswith('_debugger_case_multiprocessing.py') + # if DEBUG: + # print('get_func_code_info', f_code.co_name, f_code.co_filename) + + cdef object main_debugger = GlobalDebuggerHolder.global_dbg + + cdef PyObject * extra + _PyCode_GetExtra( code_obj, _code_extra_index, & extra) + if extra is not NULL: + extra_obj = extra + if extra_obj is not NULL: + func_code_info_obj = extra_obj + if func_code_info_obj.breakpoints_mtime == main_debugger.mtime: + # if DEBUG: + # print('get_func_code_info: matched mtime', f_code.co_name, f_code.co_filename) + + return func_code_info_obj + + cdef str co_filename = code_obj.co_filename + cdef str co_name = code_obj.co_name + cdef set break_at_lines + cdef dict cache_file_type + cdef tuple cache_file_type_key + + func_code_info = FuncCodeInfo() + func_code_info.breakpoints_mtime = main_debugger.mtime + + func_code_info.co_filename = co_filename + + if not func_code_info.always_skip_code: + try: + abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[co_filename] + except: + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(co_filename) + + func_code_info.real_path = abs_path_real_path_and_base[1] + + cache_file_type = main_debugger.get_cache_file_type() + # Note: this cache key must be the same from PyDB.get_file_type() -- see it for comments + # on the cache. + cache_file_type_key = (frame_obj.f_code.co_firstlineno, abs_path_real_path_and_base[0], frame_obj.f_code) + try: + file_type = cache_file_type[cache_file_type_key] # Make it faster + except: + file_type = main_debugger.get_file_type(frame_obj, abs_path_real_path_and_base) # we don't want to debug anything related to pydevd + + if file_type is not None: + func_code_info.always_skip_code = True + + if not func_code_info.always_skip_code: + was_break: bool = False + if main_debugger is not None: + breakpoints: dict = main_debugger.breakpoints.get(func_code_info.real_path) + # print('\n---') + # print(main_debugger.breakpoints) + # print(func_code_info.real_path) + # print(main_debugger.breakpoints.get(func_code_info.real_path)) + code_obj_py: object = code_obj + if breakpoints: + # if DEBUG: + # print('found breakpoints', code_obj_py.co_name, breakpoints) + break_at_lines = set() + new_code = None + for offset, line in dis.findlinestarts(code_obj_py): + if line in breakpoints: + # breakpoint = breakpoints[line] + # if DEBUG: + # print('created breakpoint', code_obj_py.co_name, line) + func_code_info.breakpoint_found = True + break_at_lines.add(line) + + success, new_code = insert_code( + code_obj_py, create_pydev_trace_code_wrapper(line), line, tuple(break_at_lines)) + code_obj_py = new_code + + if not success: + func_code_info.new_code = None + break + else: + # Ok, all succeeded, set to generated code object. + func_code_info.new_code = new_code + + + Py_INCREF(func_code_info) + _PyCode_SetExtra( code_obj, _code_extra_index, func_code_info) + + return func_code_info + + +cdef PyObject * get_bytecode_while_frame_eval(PyFrameObject * frame_obj, int exc): + ''' + This function makes the actual evaluation and changes the bytecode to a version + where programmatic breakpoints are added. + ''' + if GlobalDebuggerHolder is None or _thread_local_info is None or exc: + # Sometimes during process shutdown these global variables become None + return _PyEval_EvalFrameDefault(frame_obj, exc) + + # co_filename: str = frame_obj.f_code.co_filename + # if co_filename.endswith('threading.py'): + # return _PyEval_EvalFrameDefault(frame_obj, exc) + + cdef ThreadInfo thread_info + cdef int STATE_SUSPEND = 2 + cdef int CMD_STEP_INTO = 107 + cdef int CMD_STEP_OVER = 108 + cdef int CMD_STEP_OVER_MY_CODE = 159 + cdef int CMD_STEP_INTO_MY_CODE = 144 + cdef bint can_skip = True + try: + thread_info = _thread_local_info.thread_info + except: + thread_info = get_thread_info() + if thread_info is None: + return _PyEval_EvalFrameDefault(frame_obj, exc) + + if thread_info.inside_frame_eval: + return _PyEval_EvalFrameDefault(frame_obj, exc) + + if not thread_info.fully_initialized: + thread_info.initialize_if_possible() + if not thread_info.fully_initialized: + return _PyEval_EvalFrameDefault(frame_obj, exc) + + # Can only get additional_info when fully initialized. + cdef PyDBAdditionalThreadInfo additional_info = thread_info.additional_info + if thread_info.is_pydevd_thread or additional_info.is_tracing: + # Make sure that we don't trace pydevd threads or inside our own calls. + return _PyEval_EvalFrameDefault(frame_obj, exc) + + # frame = frame_obj + # DEBUG = frame.f_code.co_filename.endswith('_debugger_case_tracing.py') + # if DEBUG: + # print('get_bytecode_while_frame_eval', frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename) + + thread_info.inside_frame_eval += 1 + additional_info.is_tracing = True + try: + main_debugger: object = GlobalDebuggerHolder.global_dbg + if main_debugger is None: + return _PyEval_EvalFrameDefault(frame_obj, exc) + frame = frame_obj + + if thread_info.thread_trace_func is None: + trace_func, apply_to_global = fix_top_level_trace_and_get_trace_func(main_debugger, frame) + if apply_to_global: + thread_info.thread_trace_func = trace_func + + if additional_info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE) or \ + main_debugger.break_on_caught_exceptions or \ + main_debugger.has_plugin_exception_breaks or \ + main_debugger.signature_factory or \ + additional_info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE) and main_debugger.show_return_values and frame.f_back is additional_info.pydev_step_stop: + + # if DEBUG: + # print('get_bytecode_while_frame_eval enabled trace') + if thread_info.thread_trace_func is not None: + frame.f_trace = thread_info.thread_trace_func + else: + frame.f_trace = main_debugger.trace_dispatch + else: + func_code_info: FuncCodeInfo = get_func_code_info(frame_obj, frame_obj.f_code) + # if DEBUG: + # print('get_bytecode_while_frame_eval always skip', func_code_info.always_skip_code) + if not func_code_info.always_skip_code: + + if main_debugger.has_plugin_line_breaks or main_debugger.has_plugin_exception_breaks: + can_skip = main_debugger.plugin.can_skip(main_debugger, frame_obj) + + if not can_skip: + # if DEBUG: + # print('get_bytecode_while_frame_eval not can_skip') + if thread_info.thread_trace_func is not None: + frame.f_trace = thread_info.thread_trace_func + else: + frame.f_trace = main_debugger.trace_dispatch + + if can_skip and func_code_info.breakpoint_found: + # if DEBUG: + # print('get_bytecode_while_frame_eval new_code', func_code_info.new_code) + + # If breakpoints are found but new_code is None, + # this means we weren't able to actually add the code + # where needed, so, fallback to tracing. + if func_code_info.new_code is None: + if thread_info.thread_trace_func is not None: + frame.f_trace = thread_info.thread_trace_func + else: + frame.f_trace = main_debugger.trace_dispatch + else: + # print('Using frame eval break for', frame_obj.f_code.co_name) + update_globals_dict( frame_obj.f_globals) + Py_INCREF(func_code_info.new_code) + old = frame_obj.f_code + frame_obj.f_code = func_code_info.new_code + Py_DECREF(old) + + finally: + thread_info.inside_frame_eval -= 1 + additional_info.is_tracing = False + + return _PyEval_EvalFrameDefault(frame_obj, exc) + + +def frame_eval_func(): + cdef PyThreadState *state = PyThreadState_Get() + state.interp.eval_frame = get_bytecode_while_frame_eval + global dummy_tracing_holder + dummy_tracing_holder.set_trace_func(dummy_trace_dispatch) + + +def stop_frame_eval(): + cdef PyThreadState *state = PyThreadState_Get() + state.interp.eval_frame = _PyEval_EvalFrameDefault diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_tracing.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_tracing.py new file mode 100644 index 0000000..0968b04 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_tracing.py @@ -0,0 +1,83 @@ +import sys + +from _pydev_bundle import pydev_log +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_comm import get_global_debugger +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER + + +class DummyTracingHolder: + dummy_trace_func = None + + def set_trace_func(self, trace_func): + self.dummy_trace_func = trace_func + + +dummy_tracing_holder = DummyTracingHolder() + + +def update_globals_dict(globals_dict): + new_globals = {'_pydev_stop_at_break': _pydev_stop_at_break} + globals_dict.update(new_globals) + + +def _get_line_for_frame(frame): + # it's absolutely necessary to reset tracing function for frame in order to get the real line number + tracing_func = frame.f_trace + frame.f_trace = None + line = frame.f_lineno + frame.f_trace = tracing_func + return line + + +def _pydev_stop_at_break(line): + frame = sys._getframe(1) + t = threading.currentThread() + if t.additional_info.is_tracing: + return False + + t.additional_info.is_tracing = True + try: + debugger = get_global_debugger() + + try: + abs_path_real_path_and_base = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + except: + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(frame) + filename = abs_path_real_path_and_base[1] + + try: + python_breakpoint = debugger.breakpoints[filename][line] + except: + # print("Couldn't find breakpoint in the file %s on line %s" % (frame.f_code.co_filename, line)) + # Could be KeyError if line is not there or TypeError if breakpoints_for_file is None. + # Note: using catch-all exception for performance reasons (if the user adds a breakpoint + # and then removes it after hitting it once, this method added for the programmatic + # breakpoint will keep on being called and one of those exceptions will always be raised + # here). + return + + if python_breakpoint: + pydev_log.debug("Suspending at breakpoint in file: {} on line {}".format(frame.f_code.co_filename, line)) + t.additional_info.trace_suspend_type = 'frame_eval' + + pydevd_frame_eval_cython_wrapper = sys.modules['_pydevd_frame_eval.pydevd_frame_eval_cython_wrapper'] + thread_info = pydevd_frame_eval_cython_wrapper.get_thread_info_py() + if thread_info.thread_trace_func is not None: + frame.f_trace = thread_info.thread_trace_func + else: + debugger = get_global_debugger() + frame.f_trace = debugger.get_thread_local_trace_func() + + finally: + t.additional_info.is_tracing = False + + +def create_pydev_trace_code_wrapper(line): + pydev_trace_code_wrapper_code = compile(''' +# Note: _pydev_stop_at_break must be added to the frame locals. +global _pydev_stop_at_break +_pydev_stop_at_break(%s) +''' % (line,), '', 'exec') + return pydev_trace_code_wrapper_code + diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_modify_bytecode.py b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_modify_bytecode.py new file mode 100644 index 0000000..a892b03 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/pydevd_modify_bytecode.py @@ -0,0 +1,290 @@ +import dis +from opcode import opmap, EXTENDED_ARG, HAVE_ARGUMENT +from types import CodeType +from _pydev_bundle import pydev_log + +MAX_BYTE = 255 +RETURN_VALUE_SIZE = 2 + + +def _add_attr_values_from_insert_to_original(original_code, insert_code, insert_code_list, attribute_name, op_list): + """ + This function appends values of the attribute `attribute_name` of the inserted code to the original values, + and changes indexes inside inserted code. If some bytecode instruction in the inserted code used to call argument + number i, after modification it calls argument n + i, where n - length of the values in the original code. + So it helps to avoid variables mixing between two pieces of code. + + :param original_code: code to modify + :param insert_code: code to insert + :param insert_code_obj: bytes sequence of inserted code, which should be modified too + :param attribute_name: name of attribute to modify ('co_names', 'co_consts' or 'co_varnames') + :param op_list: sequence of bytecodes whose arguments should be changed + :return: modified bytes sequence of the code to insert and new values of the attribute `attribute_name` for + original code + """ + orig_value = getattr(original_code, attribute_name) + insert_value = getattr(insert_code, attribute_name) + orig_names_len = len(orig_value) + code_with_new_values = list(insert_code_list) + offset = 0 + while offset < len(code_with_new_values): + op = code_with_new_values[offset] + if op in op_list: + new_val = code_with_new_values[offset + 1] + orig_names_len + if new_val > MAX_BYTE: + code_with_new_values[offset + 1] = new_val & MAX_BYTE + code_with_new_values = code_with_new_values[:offset] + [EXTENDED_ARG, new_val >> 8] + \ + code_with_new_values[offset:] + offset += 2 + else: + code_with_new_values[offset + 1] = new_val + offset += 2 + new_values = orig_value + insert_value + return bytes(code_with_new_values), new_values + + +def _modify_new_lines(code_to_modify, offset, code_to_insert): + """ + Update new lines: the bytecode inserted should be the last instruction of the previous line. + :return: bytes sequence of code with updated lines offsets + """ + # There's a nice overview of co_lnotab in + # https://github.com/python/cpython/blob/3.6/Objects/lnotab_notes.txt + + new_list = list(code_to_modify.co_lnotab) + if not new_list: + # Could happen on a lambda (in this case, a breakpoint in the lambda should fallback to + # tracing). + return None + + # As all numbers are relative, what we want is to hide the code we inserted in the previous line + # (it should be the last thing right before we increment the line so that we have a line event + # right after the inserted code). + bytecode_delta = len(code_to_insert) + + byte_increments = code_to_modify.co_lnotab[0::2] + line_increments = code_to_modify.co_lnotab[1::2] + + if offset == 0: + new_list[0] += bytecode_delta + else: + addr = 0 + it = zip(byte_increments, line_increments) + for i, (byte_incr, _line_incr) in enumerate(it): + addr += byte_incr + if addr == offset: + new_list[i * 2] += bytecode_delta + break + + return bytes(new_list) + + +def _unpack_opargs(code, inserted_code_list, current_index): + """ + Modified version of `_unpack_opargs` function from module `dis`. + We have to use it, because sometimes code can be in an inconsistent state: if EXTENDED_ARG + operator was introduced into the code, but it hasn't been inserted into `code_list` yet. + In this case we can't use standard `_unpack_opargs` and we should check whether there are + some new operators in `inserted_code_list`. + """ + extended_arg = 0 + for i in range(0, len(code), 2): + op = code[i] + if op >= HAVE_ARGUMENT: + if not extended_arg: + # in case if we added EXTENDED_ARG, but haven't inserted it to the source code yet. + for code_index in range(current_index, len(inserted_code_list)): + inserted_offset, inserted_code = inserted_code_list[code_index] + if inserted_offset == i and inserted_code[0] == EXTENDED_ARG: + extended_arg = inserted_code[1] << 8 + arg = code[i + 1] | extended_arg + extended_arg = (arg << 8) if op == EXTENDED_ARG else 0 + else: + arg = None + yield (i, op, arg) + + +def _update_label_offsets(code_obj, breakpoint_offset, breakpoint_code_list): + """ + Update labels for the relative and absolute jump targets + :param code_obj: code to modify + :param breakpoint_offset: offset for the inserted code + :param breakpoint_code_list: size of the inserted code + :return: bytes sequence with modified labels; list of tuples (resulting offset, list of code instructions) with + information about all inserted pieces of code + """ + inserted_code = list() + # the list with all inserted pieces of code + inserted_code.append((breakpoint_offset, breakpoint_code_list)) + code_list = list(code_obj) + j = 0 + + while j < len(inserted_code): + current_offset, current_code_list = inserted_code[j] + offsets_for_modification = [] + + for offset, op, arg in _unpack_opargs(code_list, inserted_code, j): + if arg is not None: + if op in dis.hasjrel: + # has relative jump target + label = offset + 2 + arg + if offset < current_offset < label: + # change labels for relative jump targets if code was inserted inside + offsets_for_modification.append(offset) + elif op in dis.hasjabs: + # change label for absolute jump if code was inserted before it + if current_offset < arg: + offsets_for_modification.append(offset) + for i in range(0, len(code_list), 2): + op = code_list[i] + if i in offsets_for_modification and op >= dis.HAVE_ARGUMENT: + new_arg = code_list[i + 1] + len(current_code_list) + if new_arg <= MAX_BYTE: + code_list[i + 1] = new_arg + else: + # handle bytes overflow + if i - 2 > 0 and code_list[i - 2] == EXTENDED_ARG and code_list[i - 1] < MAX_BYTE: + # if new argument > 255 and EXTENDED_ARG already exists we need to increase it's argument + code_list[i - 1] += 1 + else: + # if there isn't EXTENDED_ARG operator yet we have to insert the new operator + extended_arg_code = [EXTENDED_ARG, new_arg >> 8] + inserted_code.append((i, extended_arg_code)) + code_list[i + 1] = new_arg & MAX_BYTE + + code_list = code_list[:current_offset] + current_code_list + code_list[current_offset:] + + for k in range(len(inserted_code)): + offset, inserted_code_list = inserted_code[k] + if current_offset < offset: + inserted_code[k] = (offset + len(current_code_list), inserted_code_list) + j += 1 + + return bytes(code_list), inserted_code + + +def _return_none_fun(): + return None + + +def add_jump_instruction(jump_arg, code_to_insert): + """ + Note: although it's adding a POP_JUMP_IF_TRUE, it's actually no longer used now + (we could only return the return and possibly the load of the 'None' before the + return -- not done yet because it needs work to fix all related tests). + """ + extended_arg_list = [] + if jump_arg > MAX_BYTE: + extended_arg_list += [EXTENDED_ARG, jump_arg >> 8] + jump_arg = jump_arg & MAX_BYTE + + # remove 'RETURN_VALUE' instruction and add 'POP_JUMP_IF_TRUE' with (if needed) 'EXTENDED_ARG' + return list(code_to_insert.co_code[:-RETURN_VALUE_SIZE]) + extended_arg_list + [opmap['POP_JUMP_IF_TRUE'], jump_arg] + + +_created = {} + + +def insert_code(code_to_modify, code_to_insert, before_line, all_lines_with_breaks=()): + ''' + :param all_lines_with_breaks: + tuple(int) a tuple with all the breaks in the given code object (this method is expected + to be called multiple times with different lines to add multiple breakpoints, so, the + variable `before_line` should have the current breakpoint an the all_lines_with_breaks + should have all the breakpoints added so far (including the `before_line`). + ''' + if not all_lines_with_breaks: + # Backward-compatibility with signature which received only one line. + all_lines_with_breaks = (before_line,) + + # The cache is needed for generator functions, because after each yield a new frame + # is created but the former code object is used (so, check if code_to_modify is + # already there and if not cache based on the new code generated). + + # print('inserting code', before_line, all_lines_with_breaks) + # dis.dis(code_to_modify) + + ok_and_new_code = _created.get((code_to_modify, all_lines_with_breaks)) + if ok_and_new_code is not None: + return ok_and_new_code + + ok, new_code = _insert_code(code_to_modify, code_to_insert, before_line) + + # print('insert code ok', ok) + # dis.dis(new_code) + + # Note: caching with new code! + cache_key = new_code, all_lines_with_breaks + _created[cache_key] = (ok, new_code) + return _created[cache_key] + + +def _insert_code(code_to_modify, code_to_insert, before_line): + """ + Insert piece of code `code_to_insert` to `code_to_modify` right inside the line `before_line` before the + instruction on this line by modifying original bytecode + + :param code_to_modify: Code to modify + :param code_to_insert: Code to insert + :param before_line: Number of line for code insertion + :return: boolean flag whether insertion was successful, modified code + """ + linestarts = dict(dis.findlinestarts(code_to_modify)) + if not linestarts: + return False, code_to_modify + + if code_to_modify.co_name == '': + # There's a peculiarity here: if a breakpoint is added in the first line of a module, we + # can't replace the code because we require a line event to stop and the line event + # was already generated, so, fallback to tracing. + if before_line == min(linestarts.values()): + return False, code_to_modify + + if before_line not in linestarts.values(): + return False, code_to_modify + + offset = None + for off, line_no in linestarts.items(): + if line_no == before_line: + offset = off + break + + code_to_insert_list = add_jump_instruction(offset, code_to_insert) + try: + code_to_insert_list, new_names = \ + _add_attr_values_from_insert_to_original(code_to_modify, code_to_insert, code_to_insert_list, 'co_names', + dis.hasname) + code_to_insert_list, new_consts = \ + _add_attr_values_from_insert_to_original(code_to_modify, code_to_insert, code_to_insert_list, 'co_consts', + [opmap['LOAD_CONST']]) + code_to_insert_list, new_vars = \ + _add_attr_values_from_insert_to_original(code_to_modify, code_to_insert, code_to_insert_list, 'co_varnames', + dis.haslocal) + new_bytes, all_inserted_code = _update_label_offsets(code_to_modify.co_code, offset, list(code_to_insert_list)) + + new_lnotab = _modify_new_lines(code_to_modify, offset, code_to_insert_list) + if new_lnotab is None: + return False, code_to_modify + + except ValueError: + pydev_log.exception() + return False, code_to_modify + + new_code = CodeType( + code_to_modify.co_argcount, # integer + code_to_modify.co_kwonlyargcount, # integer + len(new_vars), # integer + code_to_modify.co_stacksize, # integer + code_to_modify.co_flags, # integer + new_bytes, # bytes + new_consts, # tuple + new_names, # tuple + new_vars, # tuple + code_to_modify.co_filename, # string + code_to_modify.co_name, # string + code_to_modify.co_firstlineno, # integer + new_lnotab, # bytes + code_to_modify.co_freevars, # tuple + code_to_modify.co_cellvars # tuple + ) + return True, new_code diff --git a/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/release_mem.h b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/release_mem.h new file mode 100644 index 0000000..256e644 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/_pydevd_frame_eval/release_mem.h @@ -0,0 +1,5 @@ +#include "Python.h" + +void release_co_extra(void *obj) { + Py_DECREF(obj); +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/appveyor.yml b/adapter/python/ptvsd/_vendored/pydevd/appveyor.yml new file mode 100644 index 0000000..6f82a39 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/appveyor.yml @@ -0,0 +1,85 @@ +environment: + + matrix: + + # For Python versions available on Appveyor, see + # http://www.appveyor.com/docs/installed-software#python + # The list here is complete (excluding Python 2.6, which + # isn't covered by this document) at the time of writing. + + # Note: some envs commented out to have a faster test suite. + + - PYTHON_FOLDER: "C:\\Python27" + PYDEVD_USE_CYTHON: YES + - PYTHON_FOLDER: "C:\\Python27" + PYDEVD_USE_CYTHON: NO + + #- PYTHON_FOLDER: "C:\\Python33" + #- PYTHON_FOLDER: "C:\\Python34" + #- PYTHON_FOLDER: "C:\\Python35" + #- PYTHON_FOLDER: "C:\\Python27-x64" + #- PYTHON_FOLDER: "C:\\Python33-x64" + # DISTUTILS_USE_SDK: "1" + #- PYTHON_FOLDER: "C:\\Python34-x64" + # DISTUTILS_USE_SDK: "1" + + - PYTHON_FOLDER: "C:\\Python35-x64" + PYDEVD_USE_CYTHON: YES +# - PYTHON_FOLDER: "C:\\Python35-x64" +# PYDEVD_USE_CYTHON: NO + +# - PYTHON_FOLDER: "C:\\Python36-x64" +# PYDEVD_USE_CYTHON: YES + - PYTHON_FOLDER: "C:\\Python36-x64" + PYDEVD_USE_CYTHON: NO + + - PYTHON_FOLDER: "C:\\Python37-x64" + PYDEVD_USE_CYTHON: YES + - PYTHON_FOLDER: "C:\\Python37-x64" + PYDEVD_USE_CYTHON: NO + + # Disable IronPython tests (must be investigated in appveyor). + #- PYTHON_FOLDER: "C:\\Python36-x64" + # PYDEVD_USE_CYTHON: NO + # TEST_IRONPYTHON: YES + +install: + # Note: we can't use powershell for everything as it'll fail if anything is written to stderr (which is expected + # in some cases), so, using cmd on case where writing to stderr is Ok. + - cmd: "set PYTHON_EXE=%PYTHON_FOLDER%\\python.exe" + - ps: if ($env:TEST_IRONPYTHON -eq "YES"){Start-FileDownload https://github.com/IronLanguages/main/releases/download/ipy-2.7.5/IronPython-2.7.5.zip -FileName ironpython.zip} + - cmd: IF "%TEST_IRONPYTHON%"=="YES" (7z x ironpython.zip -oironpython) + - cmd: IF "%TEST_IRONPYTHON%"=="YES" (ironpython\IronPython-2.7.5\ipy.exe -X:Frames -X:ExceptionDetail -X:ShowClrExceptions -m ensurepip) + - cmd: IF "%TEST_IRONPYTHON%"=="YES" (ironpython\IronPython-2.7.5\ipy.exe -X:Frames -X:ExceptionDetail -X:ShowClrExceptions -m pip install pytest) + # Regular python: + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install --upgrade pip) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install wheel --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install cython --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install numpy) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install pytest --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install pytest-xdist --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install psutil) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install gevent --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install ipython --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install untangle --no-warn-script-location) + - cmd: IF "%TEST_IRONPYTHON%"=="" IF %PYTHON_FOLDER%=="C:\\Python27" (%PYTHON_EXE% -m pip install django>=1.7,<1.8) + - cmd: IF "%TEST_IRONPYTHON%"=="" IF %PYTHON_FOLDER%=="C:\\Python37-x64" (%PYTHON_EXE% -m pip install cherrypy) + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pip install scapy==2.4.0 --no-warn-script-location) + - cmd: "set PYTHONPATH=%PYTHONPATH%;%APPVEYOR_BUILD_FOLDER%" + +build_script: + - "%PYTHON_EXE% build_tools/build.py" + +test_script: + - cmd: IF "%TEST_IRONPYTHON%"=="YES" (ironpython\IronPython-2.7.5\ipy.exe -X:Frames -X:ExceptionDetail -X:ShowClrExceptions -m pytest --assert=plain -k "not samples") + - cmd: IF "%TEST_IRONPYTHON%"=="" (%PYTHON_EXE% -m pytest -n auto) + +artifacts: + # bdist_wheel puts your built wheel in the dist directory + # - path: dist\* + - path: build\lib.* + +#on_success: +# You can use this step to upload your artifacts to a public website. +# See Appveyor's documentation for more details. Or you can simply +# access your wheels from the Appveyor "artifacts" tab for your build. \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/build.py b/adapter/python/ptvsd/_vendored/pydevd/build_tools/build.py new file mode 100644 index 0000000..6dbdcd1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/build.py @@ -0,0 +1,174 @@ +''' +Helper to build pydevd. + +It should: + * recreate our generated files + * compile cython deps (properly setting up the environment first). + +Note that it's used in the CI to build the cython deps based on the PYDEVD_USE_CYTHON environment variable. +''' +from __future__ import print_function + +import os +import subprocess +import sys + +from generate_code import remove_if_exists, root_dir, is_python_64bit, generate_dont_trace_files, generate_cython_module + + +def validate_pair(ob): + try: + if not (len(ob) == 2): + print("Unexpected result:", ob, file=sys.stderr) + raise ValueError + except: + return False + return True + + +def consume(it): + try: + while True: + next(it) + except StopIteration: + pass + +def get_environment_from_batch_command(env_cmd, initial=None): + """ + Take a command (either a single command or list of arguments) + and return the environment created after running that command. + Note that if the command must be a batch file or .cmd file, or the + changes to the environment will not be captured. + + If initial is supplied, it is used as the initial environment passed + to the child process. + """ + if not isinstance(env_cmd, (list, tuple)): + env_cmd = [env_cmd] + if not os.path.exists(env_cmd[0]): + raise RuntimeError('Error: %s does not exist' % (env_cmd[0],)) + + # construct the command that will alter the environment + env_cmd = subprocess.list2cmdline(env_cmd) + # create a tag so we can tell in the output when the proc is done + tag = 'Done running command' + # construct a cmd.exe command to do accomplish this + cmd = 'cmd.exe /s /c "{env_cmd} && echo "{tag}" && set"'.format(**vars()) + # launch the process + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial) + # parse the output sent to stdout + lines = proc.stdout + # consume whatever output occurs until the tag is reached + for line in lines: + line = line.decode('utf-8') + if 'The specified configuration type is missing.' in line: + raise AssertionError('Error executing %s. View http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/ for details.' % (env_cmd)) + if tag in line: + break + if sys.version_info[0] > 2: + # define a way to handle each KEY=VALUE line + handle_line = lambda l: l.decode('utf-8').rstrip().split('=', 1) + else: + # define a way to handle each KEY=VALUE line + handle_line = lambda l: l.rstrip().split('=', 1) + # parse key/values into pairs + pairs = map(handle_line, lines) + # make sure the pairs are valid + valid_pairs = filter(validate_pair, pairs) + # construct a dictionary of the pairs + result = dict(valid_pairs) + # let the process finish + proc.communicate() + return result + + +def remove_binaries(suffixes): + for f in os.listdir(os.path.join(root_dir, '_pydevd_bundle')): + for suffix in suffixes: + if f.endswith(suffix): + remove_if_exists(os.path.join(root_dir, '_pydevd_bundle', f)) + + +def build(): + if '--no-remove-binaries' not in sys.argv: + remove_binaries(['.pyd', '.so']) + + os.chdir(root_dir) + + env=None + if sys.platform == 'win32': + # "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat" + # set MSSdk=1 + # set DISTUTILS_USE_SDK=1 + # set VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools + + + env = os.environ.copy() + if sys.version_info[:2] in ((2, 6), (2, 7), (3, 5), (3, 6), (3, 7)): + import setuptools # We have to import it first for the compiler to be found + from distutils import msvc9compiler + + if sys.version_info[:2] in ((2, 6), (2, 7)): + vcvarsall = msvc9compiler.find_vcvarsall(9.0) + elif sys.version_info[:2] in ((3, 5), (3, 6), (3, 7)): + vcvarsall = msvc9compiler.find_vcvarsall(14.0) + if vcvarsall is None or not os.path.exists(vcvarsall): + raise RuntimeError('Error finding vcvarsall.') + + if is_python_64bit(): + env.update(get_environment_from_batch_command( + [vcvarsall, 'amd64'], + initial=os.environ.copy())) + else: + env.update(get_environment_from_batch_command( + [vcvarsall, 'x86'], + initial=os.environ.copy())) + + elif sys.version_info[:2] in ((3,3), (3,4)): + if is_python_64bit(): + env.update(get_environment_from_batch_command( + [r"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd", '/x64'], + initial=os.environ.copy())) + else: + env.update(get_environment_from_batch_command( + [r"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd", '/x86'], + initial=os.environ.copy())) + + else: + raise AssertionError('Unable to setup environment for Python: %s' % (sys.version,)) + + env['MSSdk'] = '1' + env['DISTUTILS_USE_SDK'] = '1' + + additional_args = [] + for arg in sys.argv: + if arg.startswith('--target-pyd-name='): + additional_args.append(arg) + if arg.startswith('--target-pyd-frame-eval='): + additional_args.append(arg) + break + else: + additional_args.append('--force-cython') # Build always forces cython! + + args = [ + sys.executable, os.path.join(os.path.dirname(__file__), '..', 'setup_cython.py'), 'build_ext', '--inplace', + ]+additional_args + print('Calling args: %s' % (args,)) + subprocess.check_call(args, env=env,) + + +if __name__ == '__main__': + use_cython = os.getenv('PYDEVD_USE_CYTHON', None) + if use_cython == 'YES': + build() + elif use_cython == 'NO': + remove_binaries(['.pyd', '.so']) + elif use_cython is None: + # Regular process + if '--no-regenerate-files' not in sys.argv: + generate_dont_trace_files() + generate_cython_module() + build() + else: + raise RuntimeError('Unexpected value for PYDEVD_USE_CYTHON: %s (accepted: YES, NO)' % (use_cython,)) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/build_binaries_osx.py b/adapter/python/ptvsd/_vendored/pydevd/build_tools/build_binaries_osx.py new file mode 100644 index 0000000..795b2d4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/build_binaries_osx.py @@ -0,0 +1,62 @@ + +from __future__ import unicode_literals + +import os +import subprocess +import sys + +miniconda64_envs = os.getenv('MINICONDA64_ENVS') +python_installations = [ + r'%s/py26_64/bin/python' % miniconda64_envs, + r'%s/py27_64/bin/python' % miniconda64_envs, + r'%s/py34_64/bin/python' % miniconda64_envs, + r'%s/py35_64/bin/python' % miniconda64_envs, + r'%s/py36_64/bin/python' % miniconda64_envs, + r'%s/py37_64/bin/python' % miniconda64_envs, + ] +root_dir = os.path.dirname(os.path.dirname(__file__)) + + +def list_binaries(): + for f in os.listdir(os.path.join(root_dir, '_pydevd_bundle')): + if f.endswith('.so'): + yield f + + +def extract_version(python_install): + return python_install.split('/')[-3][2:] + + +def main(): + from generate_code import generate_dont_trace_files + from generate_code import generate_cython_module + + # First, make sure that our code is up to date. + generate_dont_trace_files() + generate_cython_module() + + for python_install in python_installations: + assert os.path.exists(python_install) + + from build import remove_binaries + remove_binaries(['.so']) + + for f in list_binaries(): + raise AssertionError('Binary not removed: %s' % (f,)) + + for i, python_install in enumerate(python_installations): + new_name = 'pydevd_cython_%s_%s' % (sys.platform, extract_version(python_install)) + args = [ + python_install, os.path.join(root_dir, 'build_tools', 'build.py'), '--no-remove-binaries', '--target-pyd-name=%s' % new_name, '--force-cython'] + if i != 0: + args.append('--no-regenerate-files') + version_number = extract_version(python_install) + if version_number.startswith('36') or version_number.startswith('37'): + name_frame_eval = 'pydevd_frame_evaluator_%s_%s' % (sys.platform, extract_version(python_install)) + args.append('--target-pyd-frame-eval=%s' % name_frame_eval) + print('Calling: %s' % (' '.join(args))) + subprocess.check_call(args) + + +if __name__ == '__main__': + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/build_binaries_windows.py b/adapter/python/ptvsd/_vendored/pydevd/build_tools/build_binaries_windows.py new file mode 100644 index 0000000..75dab9a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/build_binaries_windows.py @@ -0,0 +1,88 @@ +r''' +Creating the needed environments for creating the pre-compiled distribution on Windows: + +See: + +build_tools\pydevd_release_process.txt + +for building binaries/release process. +''' + +from __future__ import unicode_literals +import os +import subprocess +import sys + +miniconda_envs = os.getenv('MINICONDA_ENVS', r'C:\bin\Miniconda\envs') + +python_installations = [ + r'%s\py27_32\python.exe' % miniconda_envs, + r'%s\py34_32\python.exe' % miniconda_envs, + r'%s\py35_32\python.exe' % miniconda_envs, + r'%s\py36_32\python.exe' % miniconda_envs, + r'%s\py37_32\python.exe' % miniconda_envs, + + r'%s\py27_64\python.exe' % miniconda_envs, + r'%s\py34_64\python.exe' % miniconda_envs, + r'%s\py35_64\python.exe' % miniconda_envs, + r'%s\py36_64\python.exe' % miniconda_envs, + r'%s\py37_64\python.exe' % miniconda_envs, +] + +root_dir = os.path.dirname(os.path.dirname(__file__)) + + +def list_binaries(): + for f in os.listdir(os.path.join(root_dir, '_pydevd_bundle')): + if f.endswith('.pyd'): + yield f + + +def extract_version(python_install): + return python_install.split('\\')[-2][2:] + + +def main(): + from generate_code import generate_dont_trace_files + from generate_code import generate_cython_module + + # First, make sure that our code is up to date. + generate_dont_trace_files() + generate_cython_module() + + for python_install in python_installations: + assert os.path.exists(python_install), '%s does not exist.' % (python_install,) + + from build import remove_binaries + remove_binaries(['.pyd']) + + for f in list_binaries(): + raise AssertionError('Binary not removed: %s' % (f,)) + + for i, python_install in enumerate(python_installations): + print() + print('*'*80) + print('*'*80) + print() + new_name = 'pydevd_cython_%s_%s' % (sys.platform, extract_version(python_install)) + args = [ + python_install, os.path.join(root_dir, 'build_tools', 'build.py'), '--no-remove-binaries', '--target-pyd-name=%s' % new_name, '--force-cython'] + if i != 0: + args.append('--no-regenerate-files') + version_number = extract_version(python_install) + if version_number.startswith('36') or version_number.startswith('37'): + name_frame_eval = 'pydevd_frame_evaluator_%s_%s' % (sys.platform, extract_version(python_install)) + args.append('--target-pyd-frame-eval=%s' % name_frame_eval) + print('Calling: %s' % (' '.join(args))) + subprocess.check_call(args) + + +if __name__ == '__main__': + main() + +# To run do: +# See: +# +# build_tools\pydevd_release_process.txt +# +# for building binaries/release process. diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/generate_code.py b/adapter/python/ptvsd/_vendored/pydevd/build_tools/generate_code.py new file mode 100644 index 0000000..dc54573 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/generate_code.py @@ -0,0 +1,214 @@ +''' +This module should be run to recreate the files that we generate automatically +(i.e.: modules that shouldn't be traced and cython .pyx) +''' + +from __future__ import print_function + +import os +import struct +import re + + +def is_python_64bit(): + return (struct.calcsize('P') == 8) + + +root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + + +def get_cython_contents(filename): + if filename.endswith('.pyc'): + filename = filename[:-1] + + state = 'regular' + + replacements = [] + + new_contents = [] + with open(filename, 'r') as stream: + for line in stream: + strip = line.strip() + if state == 'regular': + if strip == '# IFDEF CYTHON': + state = 'cython' + + new_contents.append('%s -- DONT EDIT THIS FILE (it is automatically generated)\n' % line.replace('\n', '').replace('\r', '')) + continue + + new_contents.append(line) + + elif state == 'cython': + if strip == '# ELSE': + state = 'nocython' + new_contents.append(line) + continue + + elif strip == '# ENDIF': + state = 'regular' + new_contents.append(line) + continue + + if strip == '#': + continue + + assert strip.startswith('# '), 'Line inside # IFDEF CYTHON must start with "# ". Found: %s' % (strip,) + strip = strip.replace('# ', '', 1).strip() + + if strip.startswith('cython_inline_constant:'): + strip = strip.replace('cython_inline_constant:', '') + word_to_replace, replacement = strip.split('=') + replacements.append((word_to_replace.strip(), replacement.strip())) + continue + + line = line.replace('# ', '', 1) + new_contents.append(line) + + elif state == 'nocython': + if strip == '# ENDIF': + state = 'regular' + new_contents.append(line) + continue + new_contents.append('# %s' % line) + + assert state == 'regular', 'Error: # IFDEF CYTHON found without # ENDIF' + + ret = ''.join(new_contents) + + for (word_to_replace, replacement) in replacements: + ret = re.sub(r"\b%s\b" % (word_to_replace,), replacement, ret) + + return ret + + +def _generate_cython_from_files(target, modules): + contents = ['''from __future__ import print_function + +# Important: Autogenerated file. + +# DO NOT edit manually! +# DO NOT edit manually! +'''] + + for mod in modules: + contents.append(get_cython_contents(mod.__file__)) + + with open(target, 'w') as stream: + stream.write(''.join(contents)) + + +def generate_dont_trace_files(): + template = '''# Important: Autogenerated file. + +# DO NOT edit manually! +# DO NOT edit manually! + +from _pydevd_bundle.pydevd_constants import IS_PY3K + +LIB_FILE = 1 +PYDEV_FILE = 2 + +DONT_TRACE = { + # commonly used things from the stdlib that we don't want to trace + 'Queue.py':LIB_FILE, + 'queue.py':LIB_FILE, + 'socket.py':LIB_FILE, + 'weakref.py':LIB_FILE, + '_weakrefset.py':LIB_FILE, + 'linecache.py':LIB_FILE, + 'threading.py':LIB_FILE, + 'dis.py':LIB_FILE, + + # things from pydev that we don't want to trace + '_pydev_execfile.py':PYDEV_FILE, +%(pydev_files)s +} + +if IS_PY3K: + # if we try to trace io.py it seems it can get halted (see http://bugs.python.org/issue4716) + DONT_TRACE['io.py'] = LIB_FILE + + # Don't trace common encodings too + DONT_TRACE['cp1252.py'] = LIB_FILE + DONT_TRACE['utf_8.py'] = LIB_FILE + DONT_TRACE['codecs.py'] = LIB_FILE +''' + + pydev_files = [] + + for root, dirs, files in os.walk(root_dir): + for d in [ + '.git', + '.settings', + 'build', + 'build_tools', + 'dist', + 'pydevd.egg-info', + 'pydevd_attach_to_process', + 'pydev_sitecustomize', + 'stubs', + 'tests', + 'tests_mainloop', + 'tests_python', + 'tests_runfiles', + 'test_pydevd_reload', + 'third_party', + '__pycache__', + '_pydev_runfiles', + 'pydev_ipython', + ]: + try: + dirs.remove(d) + except: + pass + + for f in files: + if f.endswith('.py'): + if f not in ( + '__init__.py', + 'runfiles.py', + 'pydev_coverage.py', + 'pydev_pysrc.py', + 'setup.py', + 'setup_cython.py', + 'interpreterInfo.py', + 'conftest.py', + ): + pydev_files.append(" '%s': PYDEV_FILE," % (f,)) + + contents = template % (dict(pydev_files='\n'.join(sorted(pydev_files)))) + assert 'pydevd.py' in contents + assert 'pydevd_dont_trace.py' in contents + with open(os.path.join(root_dir, '_pydevd_bundle', 'pydevd_dont_trace_files.py'), 'w') as stream: + stream.write(contents) + + +def remove_if_exists(f): + try: + if os.path.exists(f): + os.remove(f) + except: + import traceback;traceback.print_exc() + + +def generate_cython_module(): + remove_if_exists(os.path.join(root_dir, '_pydevd_bundle', 'pydevd_cython.pyx')) + + target = os.path.join(root_dir, '_pydevd_bundle', 'pydevd_cython.pyx') + curr = os.environ.get('PYDEVD_USE_CYTHON') + try: + os.environ['PYDEVD_USE_CYTHON'] = 'NO' + + from _pydevd_bundle import pydevd_additional_thread_info_regular + from _pydevd_bundle import pydevd_frame, pydevd_trace_dispatch_regular + _generate_cython_from_files(target, [pydevd_additional_thread_info_regular, pydevd_frame, pydevd_trace_dispatch_regular]) + finally: + if curr is None: + del os.environ['PYDEVD_USE_CYTHON'] + else: + os.environ['PYDEVD_USE_CYTHON'] = curr + + +if __name__ == '__main__': + generate_dont_trace_files() + generate_cython_module() diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/names_to_rename.py b/adapter/python/ptvsd/_vendored/pydevd/build_tools/names_to_rename.py new file mode 100644 index 0000000..97d061a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/names_to_rename.py @@ -0,0 +1,318 @@ +''' +Helper module to hold the names to rename while doing refactoring to convert to pep8. +''' +NAMES = ''' +# sendCaughtExceptionStack +# sendBreakpointConditionException +# setSuspend +# processThreadNotAlive +# sendCaughtExceptionStackProceeded +# doWaitSuspend +# SetTraceForFrameAndParents +# prepareToRun +# processCommandLine +# initStdoutRedirect +# initStderrRedirect +# OnRun +# doKillPydevThread +# stopTrace +# handleExcept +# processCommand +# processNetCommand +# addCommand +# StartClient +# getNextSeq +# makeMessage +# StartServer +# threadToXML +# makeErrorMessage +# makeThreadCreatedMessage +# makeCustomFrameCreatedMessage +# makeListThreadsMessage +# makeVariableChangedMessage +# makeIoMessage +# makeVersionMessage +# makeThreadKilledMessage +# makeThreadSuspendStr +# makeValidXmlValue +# makeThreadSuspendMessage +# makeThreadRunMessage +# makeGetVariableMessage +# makeGetArrayMessage +# makeGetFrameMessage +# makeEvaluateExpressionMessage +# makeGetCompletionsMessage +# makeGetFileContents +# makeSendBreakpointExceptionMessage +# makeSendCurrExceptionTraceMessage +# makeSendCurrExceptionTraceProceededMessage +# makeSendConsoleMessage +# makeCustomOperationMessage +# makeLoadSourceMessage +# makeShowConsoleMessage +# makeExitMessage +# canBeExecutedBy +# doIt +# additionalInfo +# cmdFactory +# GetExceptionTracebackStr +# _GetStackStr +# _InternalSetTrace +# ReplaceSysSetTraceFunc +# RestoreSysSetTraceFunc + + + +# AddContent +# AddException +# AddObserver +# # Call -- skip +# # Call1 -- skip +# # Call2 -- skip +# # Call3 -- skip +# # Call4 -- skip +# ChangePythonPath +# CheckArgs +# CheckChar +# CompleteFromDir +# CreateDbFrame +# CustomFramesContainerInit +# DictContains +# DictItems +# DictIterItems +# DictIterValues +# DictKeys +# DictPop +# DictValues + + +# DoExit +# DoFind +# EndRedirect +# # Exec -- skip +# ExecuteTestsInParallel +# # Find -- skip +# FinishDebuggingSession +# FlattenTestSuite +# GenerateCompletionsAsXML +# GenerateImportsTipForModule +# GenerateTip + + +# testAddExec +# testComplete +# testCompleteDoesNotDoPythonMatches +# testCompletionSocketsAndMessages +# testConsoleHello +# testConsoleRequests +# testDotNetLibraries +# testEdit +# testGetCompletions +# testGetNamespace +# testGetReferrers1 +# testGetReferrers2 +# testGetReferrers3 +# testGetReferrers4 +# testGetReferrers5 +# testGetReferrers6 +# testGetReferrers7 +# testGettingInfoOnJython +# testGui +# testHistory +# testImports +# testImports1 +# testImports1a +# testImports1b +# testImports1c +# testImports2 +# testImports2a +# testImports2b +# testImports2c +# testImports3 +# testImports4 +# testImports5 +# testInspect +# testIt +# testMessage +# testPrint +# testProperty +# testProperty2 +# testProperty3 +# testQuestionMark +# testSearch +# testSearchOnJython +# testServer +# testTipOnString +# toXML +# updateCustomFrame +# varToXML + +# +# GetContents +# GetCoverageFiles +# GetFile +# GetFileNameAndBaseFromFile +# GetFilenameAndBase +# GetFrame +# GetGlobalDebugger # -- renamed but kept backward-compatibility +# GetNormPathsAndBase +# GetNormPathsAndBaseFromFile +# GetTestsToRun -- skip +# GetThreadId +# GetVmType +# IPythonEditor -- skip +# ImportName +# InitializeServer +# IterFrames + + +# Method1 -- skip +# Method1a -- skip +# Method2 -- skip +# Method3 -- skip + +# NewConsolidate +# NormFileToClient +# NormFileToServer +# # Notify -- skip +# # NotifyFinished -- skip +# OnFunButton +# # OnInit -- skip +# OnTimeToClose +# PydevdFindThreadById +# PydevdLog +# # RequestInput -- skip + + +# Search -- manual: search_definition +# ServerProxy -- skip +# SetGlobalDebugger + +# SetServer +# SetUp +# SetTrace -- skip + + +# SetVmType +# SetupType +# StartCoverageSupport +# StartCoverageSupportFromParams +# StartPydevNosePluginSingleton +# StartRedirect +# ToTuple + +# addAdditionalFrameById +# removeAdditionalFrameById +# removeCustomFrame +# addCustomFrame +# addError -- skip +# addExec +# addFailure -- skip +# addSuccess -- skip +# assertArgs +# assertIn + +# basicAsStr +# changeAttrExpression +# # changeVariable -- skip (part of public API for console) +# checkOutput +# checkOutputRedirect +# clearBuffer + +# # connectToDebugger -- skip (part of public API for console) +# connectToServer +# consoleExec +# createConnections +# createStdIn +# customOperation +# dirObj +# doAddExec +# doExecCode +# dumpFrames + +# # enableGui -- skip (part of public API for console) +# evalInContext +# evaluateExpression +# # execLine -- skip (part of public API for console) +# # execMultipleLines -- skip (part of public API for console) +# findFrame +# orig_findFrame +# finishExec +# fixGetpass + +# forceServerKill +# formatArg +# formatCompletionMessage +# formatParamClassName +# frameVarsToXML +# fullyNormalizePath + +# getArray -- skip (part of public API for console) +# getAsDoc +# getCapturedOutput +# getCompletions -- skip (part of public API for console) + +# getCompletionsMessage +# getCustomFrame +# # getDescription -- skip (part of public API for console) +# getDictionary +# # getFrame -- skip (part of public API for console) +# getFrameName + + + +# getFrameStack +# getFreeAddresses +# getInternalQueue +# getIoFromError +# getNamespace +# getTestName +# getTokenAndData +# getType + +# getVariable -- skip (part of public API for console) + +# # haveAliveThreads -> has_threads_alive +# initializeNetwork +# isThreadAlive +# # iterFrames -> _iter_frames +# # keyStr -> key_to_str +# killAllPydevThreads +# longRunning +# # metA -- skip +# nativePath + +# needMore +# needMoreForCode +# # notifyCommands -- skip (part of public API) +# # notifyConnected -- skip (part of public API) +# # notifyStartTest -- skip (part of public API) +# # notifyTest -- skip (part of public API) +# # notifyTestRunFinished -- skip (part of public API) +# # notifyTestsCollected -- skip (part of public API) +# postInternalCommand +# processInternalCommands +# readMsg + + +# redirectStdout +# removeInvalidChars +# reportCond +# resolveCompoundVariable +# resolveVar +# restoreStdout +# sendKillMsg +# sendSignatureCallTrace +# setTracingForUntracedContexts +# startClientThread +# startDebuggerServerThread +# startExec + +# startTest -- skip +# stopTest -- skip +# setUp -- skip +# setUpClass -- skip +# setUpModule -- skip +# tearDown -- skip + +''' \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/pydevd_release_process.txt b/adapter/python/ptvsd/_vendored/pydevd/build_tools/pydevd_release_process.txt new file mode 100644 index 0000000..a1c89fb --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/pydevd_release_process.txt @@ -0,0 +1,59 @@ +1. Update version +================= + +__version_info__ in pydevd.py + + +2. Generate new version +====================== + +cd /D x:\PyDev.Debugger + +rm dist/pydevd* + +C:\tools\Miniconda32\Scripts\activate py27_32 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda32\Scripts\activate py34_32 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda32\Scripts\activate py35_32 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda32\Scripts\activate py36_32 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda\Scripts\activate py27_64 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda\Scripts\activate py34_64 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda\Scripts\activate py35_64 +python setup.py sdist bdist_wheel +deactivate +dir dist + +C:\tools\Miniconda\Scripts\activate py36_64 +python setup.py sdist bdist_wheel +deactivate +dir dist + +# Note: uploading with twine gives an error in the end, but apparently it works (check final result in pypi). +twine upload dist/pydevd* + +git tag pydev_debugger_1_2_0 -a -m "PyDev.Debugger 1.2.0" +git push --tags + diff --git a/adapter/python/ptvsd/_vendored/pydevd/build_tools/rename_pep8.py b/adapter/python/ptvsd/_vendored/pydevd/build_tools/rename_pep8.py new file mode 100644 index 0000000..6e545da --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/build_tools/rename_pep8.py @@ -0,0 +1,123 @@ +''' +Helper module to do refactoring to convert names to pep8. +''' +import re +import os +import names_to_rename + +_CAMEL_RE = re.compile(r'(?<=[a-z])([A-Z])') +_CAMEL_DEF_RE = re.compile(r'(def )((([A-Z0-9]+|[a-z0-9])[a-z][a-z0-9]*[A-Z]|[a-z0-9]*[A-Z][A-Z0-9]*[a-z])[A-Za-z0-9]*)') + +def _normalize(name): + return _CAMEL_RE.sub(lambda x: '_' + x.group(1).lower(), name).lower() + +def find_matches_in_contents(contents): + return [x[1] for x in re.findall(_CAMEL_DEF_RE, contents)] + +def iter_files_in_dir(dirname): + for root, dirs, files in os.walk(dirname): + for name in ('pydevd_attach_to_process', '.git', 'stubs', 'pydev_ipython', 'third_party', 'pydev_ipython'): + try: + dirs.remove(name) + except: + pass + for filename in files: + if filename.endswith('.py') and filename not in ('rename_pep8.py', 'names_to_rename.py'): + path = os.path.join(root, filename) + with open(path, 'rb') as stream: + initial_contents = stream.read() + + yield path, initial_contents + +def find_matches(): + found = set() + for path, initial_contents in iter_files_in_dir(os.path.dirname(os.path.dirname(__file__))): + found.update(find_matches_in_contents(initial_contents)) + print '\n'.join(sorted(found)) + print 'Total', len(found) + +def substitute_contents(re_name_to_new_val, initial_contents): + contents = initial_contents + for key, val in re_name_to_new_val.iteritems(): + contents = re.sub(key, val, contents) + return contents + +def make_replace(): + re_name_to_new_val = load_re_to_new_val(names_to_rename.NAMES) + # traverse root directory, and list directories as dirs and files as files + for path, initial_contents in iter_files_in_dir(os.path.dirname(os.path.dirname(__file__))): + contents = substitute_contents(re_name_to_new_val, initial_contents) + if contents != initial_contents: + print 'Changed something at: %s' % (path,) + + for val in re_name_to_new_val.itervalues(): + # Check in initial contents to see if it already existed! + if re.findall(r'\b%s\b' % (val,), initial_contents): + raise AssertionError('Error in:\n%s\n%s is already being used (and changes may conflict).' % (path, val,)) + + with open(path, 'wb') as stream: + stream.write(contents) + + +def load_re_to_new_val(names): + name_to_new_val = {} + for n in names.splitlines(): + n = n.strip() + if not n.startswith('#') and n: + name_to_new_val[r'\b'+n+r'\b'] = _normalize(n) + return name_to_new_val + +def test(): + assert _normalize('RestoreSysSetTraceFunc') == 'restore_sys_set_trace_func' + assert _normalize('restoreSysSetTraceFunc') == 'restore_sys_set_trace_func' + assert _normalize('Restore') == 'restore' + matches = find_matches_in_contents(''' + def CamelCase() + def camelCase() + def ignore() + def ignore_this() + def Camel() + def CamelCaseAnother() + ''') + assert matches == ['CamelCase', 'camelCase', 'Camel', 'CamelCaseAnother'] + re_name_to_new_val = load_re_to_new_val(''' +# Call -- skip +# Call1 -- skip +# Call2 -- skip +# Call3 -- skip +# Call4 -- skip +CustomFramesContainerInit +DictContains +DictItems +DictIterItems +DictIterValues +DictKeys +DictPop +DictValues +''') + assert re_name_to_new_val == {'\\bDictPop\\b': 'dict_pop', '\\bDictItems\\b': 'dict_items', '\\bDictIterValues\\b': 'dict_iter_values', '\\bDictKeys\\b': 'dict_keys', '\\bDictContains\\b': 'dict_contains', '\\bDictIterItems\\b': 'dict_iter_items', '\\bCustomFramesContainerInit\\b': 'custom_frames_container_init', '\\bDictValues\\b': 'dict_values'} + assert substitute_contents(re_name_to_new_val, ''' +CustomFramesContainerInit +DictContains +DictItems +DictIterItems +DictIterValues +DictKeys +DictPop +DictValues +''') == ''' +custom_frames_container_init +dict_contains +dict_items +dict_iter_items +dict_iter_values +dict_keys +dict_pop +dict_values +''' + +if __name__ == '__main__': +# find_matches() + make_replace() +# test() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/conftest.py b/adapter/python/ptvsd/_vendored/pydevd/conftest.py new file mode 100644 index 0000000..b817202 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/conftest.py @@ -0,0 +1,281 @@ +import pytest +import sys +from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_IRONPYTHON +from tests_python.debug_constants import TEST_CYTHON +from tests_python.debug_constants import PYDEVD_TEST_VM +import site +import os +from _pydev_bundle import pydev_log + + +def pytest_report_header(config): + print('PYDEVD_USE_CYTHON: %s' % (TEST_CYTHON,)) + print('PYDEVD_TEST_VM: %s' % (PYDEVD_TEST_VM,)) + try: + import multiprocessing + except ImportError: + pass + else: + print('Number of processors: %s' % (multiprocessing.cpu_count(),)) + + print('Relevant system paths:') + print('sys.executable: %s' % (sys.executable,)) + print('sys.prefix: %s' % (sys.prefix,)) + + if hasattr(sys, 'base_prefix'): + print('sys.base_prefix: %s' % (sys.base_prefix,)) + + if hasattr(sys, 'real_prefix'): + print('sys.real_prefix: %s' % (sys.real_prefix,)) + + if hasattr(site, 'getusersitepackages'): + print('site.getusersitepackages(): %s' % (site.getusersitepackages(),)) + + if hasattr(site, 'getsitepackages'): + print('site.getsitepackages(): %s' % (site.getsitepackages(),)) + + for path in sys.path: + if os.path.exists(path) and os.path.basename(path) == 'site-packages': + print('Folder with "site-packages" in sys.path: %s' % (path,)) + + +_started_monitoring_threads = False + + +def _start_monitoring_threads(): + # After the session finishes, wait 20 seconds to see if everything finished properly + # and if it doesn't report an error. + global _started_monitoring_threads + if _started_monitoring_threads: + return + + _started_monitoring_threads = True + import threading + if hasattr(sys, '_current_frames') and hasattr(threading, 'enumerate'): + import time + import traceback + + class DumpThreads(threading.Thread): + + def run(self): + time.sleep(20) + + thread_id_to_name = {} + try: + for t in threading.enumerate(): + thread_id_to_name[t.ident] = '%s (daemon: %s)' % (t.name, t.daemon) + except: + pass + + stack_trace = [ + '===============================================================================', + 'pydev pyunit runner: Threads still found running after tests finished', + '================================= Thread Dump ================================='] + + for thread_id, stack in sys._current_frames().items(): + stack_trace.append('\n-------------------------------------------------------------------------------') + stack_trace.append(" Thread %s" % thread_id_to_name.get(thread_id, thread_id)) + stack_trace.append('') + + if 'self' in stack.f_locals: + sys.stderr.write(str(stack.f_locals['self']) + '\n') + + for filename, lineno, name, line in traceback.extract_stack(stack): + stack_trace.append(' File "%s", line %d, in %s' % (filename, lineno, name)) + if line: + stack_trace.append(" %s" % (line.strip())) + stack_trace.append('\n=============================== END Thread Dump ===============================') + sys.stderr.write('\n'.join(stack_trace)) + + # Force thread run to finish + import os + os._exit(123) + + dump_current_frames_thread = DumpThreads() + dump_current_frames_thread.setDaemon(True) # Daemon so that this thread doesn't halt it! + dump_current_frames_thread.start() + + +def pytest_unconfigure(): + _start_monitoring_threads() + + +@pytest.yield_fixture(scope="session", autouse=True) +def check_no_threads(): + yield + _start_monitoring_threads() + + +# see: http://goo.gl/kTQMs +SYMBOLS = { + 'customary' : ('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'), + 'customary_ext' : ('byte', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', + 'zetta', 'iotta'), + 'iec' : ('Bi', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'), + 'iec_ext' : ('byte', 'kibi', 'mebi', 'gibi', 'tebi', 'pebi', 'exbi', + 'zebi', 'yobi'), +} + + +def bytes2human(n, format='%(value).1f %(symbol)s', symbols='customary'): + """ + Bytes-to-human / human-to-bytes converter. + Based on: http://goo.gl/kTQMs + Working with Python 2.x and 3.x. + + Author: Giampaolo Rodola' + License: MIT + """ + + """ + Convert n bytes into a human readable string based on format. + symbols can be either "customary", "customary_ext", "iec" or "iec_ext", + see: http://goo.gl/kTQMs + + >>> bytes2human(0) + '0.0 B' + >>> bytes2human(0.9) + '0.0 B' + >>> bytes2human(1) + '1.0 B' + >>> bytes2human(1.9) + '1.0 B' + >>> bytes2human(1024) + '1.0 K' + >>> bytes2human(1048576) + '1.0 M' + >>> bytes2human(1099511627776127398123789121) + '909.5 Y' + + >>> bytes2human(9856, symbols="customary") + '9.6 K' + >>> bytes2human(9856, symbols="customary_ext") + '9.6 kilo' + >>> bytes2human(9856, symbols="iec") + '9.6 Ki' + >>> bytes2human(9856, symbols="iec_ext") + '9.6 kibi' + + >>> bytes2human(10000, "%(value).1f %(symbol)s/sec") + '9.8 K/sec' + + >>> # precision can be adjusted by playing with %f operator + >>> bytes2human(10000, format="%(value).5f %(symbol)s") + '9.76562 K' + """ + n = int(n) + if n < 0: + raise ValueError("n < 0") + symbols = SYMBOLS[symbols] + prefix = {} + for i, s in enumerate(symbols[1:]): + prefix[s] = 1 << (i + 1) * 10 + for symbol in reversed(symbols[1:]): + if n >= prefix[symbol]: + value = float(n) / prefix[symbol] + return format % locals() + return format % dict(symbol=symbols[0], value=n) + + +def format_memory_info(memory_info, curr_proc_memory_info): + return 'Total: %s, Available: %s, Used: %s %%, Curr process: %s' % ( + bytes2human(memory_info.total), bytes2human(memory_info.available), memory_info.percent, format_process_memory_info(curr_proc_memory_info)) + + +def format_process_memory_info(proc_memory_info): + return bytes2human(proc_memory_info.rss) + + +DEBUG_MEMORY_INFO = False + +_global_collect_info = False + + +@pytest.yield_fixture(autouse=True) +def before_after_each_function(request): + global _global_collect_info + + try: + import psutil # Don't fail if not there + except ImportError: + yield + return + + current_pids = set(proc.pid for proc in psutil.process_iter()) + before_curr_proc_memory_info = psutil.Process().memory_info() + + if _global_collect_info and DEBUG_MEMORY_INFO: + try: + from pympler import summary, muppy + sum1 = summary.summarize(muppy.get_objects()) + except: + pydev_log.exception() + + sys.stdout.write( +''' +=============================================================================== +Memory before: %s +%s +=============================================================================== +''' % (request.function, format_memory_info(psutil.virtual_memory(), before_curr_proc_memory_info))) + yield + + processes_info = [] + for proc in psutil.process_iter(): + if proc.pid not in current_pids: + try: + processes_info.append( + 'New Process: %s(%s) - %s' % ( + proc.name(), + proc.pid, + format_process_memory_info(proc.memory_info()) + ) + ) + except psutil.NoSuchProcess: + pass # The process could've died in the meanwhile + + after_curr_proc_memory_info = psutil.Process().memory_info() + + if DEBUG_MEMORY_INFO: + try: + if after_curr_proc_memory_info.rss - before_curr_proc_memory_info.rss > 10 * 1000 * 1000: + # 10 MB leak + if _global_collect_info: + sum2 = summary.summarize(muppy.get_objects()) + diff = summary.get_diff(sum1, sum2) + sys.stdout.write('===============================================================================\n') + sys.stdout.write('Leak info:\n') + sys.stdout.write('===============================================================================\n') + summary.print_(diff) + sys.stdout.write('===============================================================================\n') + + _global_collect_info = True + # We'll only really collect the info on the next test (i.e.: if at one test + # we used too much memory, the next one will start collecting) + else: + _global_collect_info = False + except: + pydev_log.exception() + + sys.stdout.write( +''' +=============================================================================== +Memory after: %s +%s%s +=============================================================================== + + +''' % ( + request.function, + format_memory_info(psutil.virtual_memory(), after_curr_proc_memory_info), + '' if not processes_info else '\nLeaked processes:\n' + '\n'.join(processes_info)), + ) + + +from tests_python.regression_check import data_regression, datadir, original_datadir + +if IS_JYTHON or IS_IRONPYTHON: + + # On Jython and IronPython, it's a no-op. + def before_after_each_function(): + pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/gradle/wrapper/gradle-wrapper.jar b/adapter/python/ptvsd/_vendored/pydevd/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/gradle/wrapper/gradle-wrapper.jar differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/gradle/wrapper/gradle-wrapper.properties b/adapter/python/ptvsd/_vendored/pydevd/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9ee9ac9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Feb 04 13:39:02 CET 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip diff --git a/adapter/python/ptvsd/_vendored/pydevd/gradlew b/adapter/python/ptvsd/_vendored/pydevd/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/adapter/python/ptvsd/_vendored/pydevd/gradlew.bat b/adapter/python/ptvsd/_vendored/pydevd/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/adapter/python/ptvsd/_vendored/pydevd/interpreterInfo.py b/adapter/python/ptvsd/_vendored/pydevd/interpreterInfo.py new file mode 100644 index 0000000..40c4ebe --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/interpreterInfo.py @@ -0,0 +1,256 @@ +''' +This module was created to get information available in the interpreter, such as libraries, +paths, etc. + +what is what: +sys.builtin_module_names: contains the builtin modules embeeded in python (rigth now, we specify all manually). +sys.prefix: A string giving the site-specific directory prefix where the platform independent Python files are installed + +format is something as +EXECUTABLE:python.exe|libs@compiled_dlls$builtin_mods + +all internal are separated by | +''' +import sys + +try: + import os.path + def fully_normalize_path(path): + '''fixes the path so that the format of the path really reflects the directories in the system + ''' + return os.path.normpath(path) + join = os.path.join +except: # ImportError or AttributeError. + # See: http://stackoverflow.com/questions/10254353/error-while-installing-jython-for-pydev + def fully_normalize_path(path): + '''fixes the path so that the format of the path really reflects the directories in the system + ''' + return path + + def join(a, b): + if a.endswith('/') or a.endswith('\\'): + return a + b + return a + '/' + b + + +IS_PYTHON_3_ONWARDS = 0 + +try: + IS_PYTHON_3_ONWARDS = sys.version_info[0] >= 3 +except: + # That's OK, not all versions of python have sys.version_info + pass + +try: + # Just check if False and True are defined (depends on version, not whether it's jython/python) + False + True +except: + exec ('True, False = 1,0') # An exec is used so that python 3k does not give a syntax error + +if sys.platform == "cygwin": + + try: + import ctypes # use from the system if available + except ImportError: + sys.path.append(join(sys.path[0], 'third_party/wrapped_for_pydev')) + import ctypes + + def native_path(path): + MAX_PATH = 512 # On cygwin NT, its 260 lately, but just need BIG ENOUGH buffer + '''Get the native form of the path, like c:\\Foo for /cygdrive/c/Foo''' + + retval = ctypes.create_string_buffer(MAX_PATH) + path = fully_normalize_path(path) + path = tobytes(path) + CCP_POSIX_TO_WIN_A = 0 + cygwin1dll = ctypes.cdll.LoadLibrary( 'cygwin1.dll' ) + cygwin1dll.cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, retval, MAX_PATH) + + return retval.value + +else: + def native_path(path): + return fully_normalize_path(path) + + + +def __getfilesystemencoding(): + ''' + Note: there's a copy of this method in _pydev_filesystem_encoding.py + ''' + try: + ret = sys.getfilesystemencoding() + if not ret: + raise RuntimeError('Unable to get encoding.') + return ret + except: + try: + # Handle Jython + from java.lang import System # @UnresolvedImport + env = System.getProperty("os.name").lower() + if env.find('win') != -1: + return 'ISO-8859-1' # mbcs does not work on Jython, so, use a (hopefully) suitable replacement + return 'utf-8' + except: + pass + + # Only available from 2.3 onwards. + if sys.platform == 'win32': + return 'mbcs' + return 'utf-8' + +def getfilesystemencoding(): + try: + ret = __getfilesystemencoding() + + #Check if the encoding is actually there to be used! + if hasattr('', 'encode'): + ''.encode(ret) + if hasattr('', 'decode'): + ''.decode(ret) + + return ret + except: + return 'utf-8' + +file_system_encoding = getfilesystemencoding() + +if IS_PYTHON_3_ONWARDS: + unicode_type = str + bytes_type = bytes + +else: + unicode_type = unicode + bytes_type = str + + +def tounicode(s): + if hasattr(s, 'decode'): + if not isinstance(s, unicode_type): + # Depending on the platform variant we may have decode on string or not. + return s.decode(file_system_encoding) + return s + +def tobytes(s): + if hasattr(s, 'encode'): + if not isinstance(s, bytes_type): + return s.encode(file_system_encoding) + return s + +def toasciimxl(s): + # output for xml without a declared encoding + + # As the output is xml, we have to encode chars (< and > are ok as they're not accepted in the filesystem name -- + # if it was allowed, we'd have to do things more selectively so that < and > don't get wrongly replaced). + s = s.replace("&", "&") + + try: + ret = s.encode('ascii', 'xmlcharrefreplace') + except: + # use workaround + ret = '' + for c in s: + try: + ret += c.encode('ascii') + except: + try: + # Python 2: unicode is a valid identifier + ret += unicode("&#%d;") % ord(c) + except: + # Python 3: a string is already unicode, so, just doing it directly should work. + ret += "&#%d;" % ord(c) + return ret + + +if __name__ == '__main__': + try: + # just give some time to get the reading threads attached (just in case) + import time + time.sleep(0.1) + except: + pass + + try: + executable = tounicode(native_path(sys.executable)) + except: + executable = tounicode(sys.executable) + + if sys.platform == "cygwin" and not executable.endswith(tounicode('.exe')): + executable += tounicode('.exe') + + + try: + major = str(sys.version_info[0]) + minor = str(sys.version_info[1]) + except AttributeError: + # older versions of python don't have version_info + import string + s = string.split(sys.version, ' ')[0] + s = string.split(s, '.') + major = s[0] + minor = s[1] + + s = tounicode('%s.%s') % (tounicode(major), tounicode(minor)) + + contents = [tounicode('')] + contents.append(tounicode('%s') % (tounicode(s),)) + + contents.append(tounicode('%s') % tounicode(executable)) + + # this is the new implementation to get the system folders + # (still need to check if it works in linux) + # (previously, we were getting the executable dir, but that is not always correct...) + prefix = tounicode(native_path(sys.prefix)) + # print_ 'prefix is', prefix + + + result = [] + + path_used = sys.path + try: + path_used = path_used[1:] # Use a copy (and don't include the directory of this script as a path.) + except: + pass # just ignore it... + + for p in path_used: + p = tounicode(native_path(p)) + + try: + import string # to be compatible with older versions + if string.find(p, prefix) == 0: # was startswith + result.append((p, True)) + else: + result.append((p, False)) + except (ImportError, AttributeError): + # python 3k also does not have it + # jython may not have it (depending on how are things configured) + if p.startswith(prefix): # was startswith + result.append((p, True)) + else: + result.append((p, False)) + + for p, b in result: + if b: + contents.append(tounicode('%s') % (p,)) + else: + contents.append(tounicode('%s') % (p,)) + + # no compiled libs + # nor forced libs + + for builtinMod in sys.builtin_module_names: + contents.append(tounicode('%s') % tounicode(builtinMod)) + + + contents.append(tounicode('')) + unic = tounicode('\n').join(contents) + inasciixml = toasciimxl(unic) + if IS_PYTHON_3_ONWARDS: + # This is the 'official' way of writing binary output in Py3K (see: http://bugs.python.org/issue4571) + sys.stdout.buffer.write(inasciixml) + else: + sys.stdout.write(inasciixml) + + sys.stdout.flush() + sys.stderr.flush() diff --git a/adapter/python/ptvsd/_vendored/pydevd/jython_test_deps/ant.jar b/adapter/python/ptvsd/_vendored/pydevd/jython_test_deps/ant.jar new file mode 100644 index 0000000..24641e7 Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/jython_test_deps/ant.jar differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/jython_test_deps/junit.jar b/adapter/python/ptvsd/_vendored/pydevd/jython_test_deps/junit.jar new file mode 100644 index 0000000..5b4bb84 Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/jython_test_deps/junit.jar differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pycompletionserver.py b/adapter/python/ptvsd/_vendored/pydevd/pycompletionserver.py new file mode 100644 index 0000000..d73c902 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pycompletionserver.py @@ -0,0 +1,405 @@ +''' +Entry-point module to start the code-completion server for PyDev. + +@author Fabio Zadrozny +''' +import sys +IS_PYTHON_3_ONWARDS = sys.version_info[0] >= 3 + +if not IS_PYTHON_3_ONWARDS: + import __builtin__ +else: + import builtins as __builtin__ # Python 3.0 + +from _pydevd_bundle.pydevd_constants import IS_JYTHON + +if IS_JYTHON: + import java.lang # @UnresolvedImport + SERVER_NAME = 'jycompletionserver' + from _pydev_bundle import _pydev_jy_imports_tipper + _pydev_imports_tipper = _pydev_jy_imports_tipper + +else: + # it is python + SERVER_NAME = 'pycompletionserver' + from _pydev_bundle import _pydev_imports_tipper + + +from _pydev_imps._pydev_saved_modules import socket + +import sys +if sys.platform == "darwin": + # See: https://sourceforge.net/projects/pydev/forums/forum/293649/topic/3454227 + try: + import _CF # Don't fail if it doesn't work -- do it because it must be loaded on the main thread! @UnresolvedImport @UnusedImport + except: + pass + + +# initial sys.path +_sys_path = [] +for p in sys.path: + # changed to be compatible with 1.5 + _sys_path.append(p) + +# initial sys.modules +_sys_modules = {} +for name, mod in sys.modules.items(): + _sys_modules[name] = mod + + +import traceback + +from _pydev_imps._pydev_saved_modules import time + +try: + import StringIO +except: + import io as StringIO #Python 3.0 + +try: + from urllib import quote_plus, unquote_plus +except ImportError: + from urllib.parse import quote_plus, unquote_plus #Python 3.0 + +INFO1 = 1 +INFO2 = 2 +WARN = 4 +ERROR = 8 + +DEBUG = INFO1 | ERROR + +def dbg(s, prior): + if prior & DEBUG != 0: + sys.stdout.write('%s\n' % (s,)) +# f = open('c:/temp/test.txt', 'a') +# print_ >> f, s +# f.close() + +from _pydev_bundle import pydev_localhost +HOST = pydev_localhost.get_localhost() # Symbolic name meaning the local host + +MSG_KILL_SERVER = '@@KILL_SERVER_END@@' +MSG_COMPLETIONS = '@@COMPLETIONS' +MSG_END = 'END@@' +MSG_INVALID_REQUEST = '@@INVALID_REQUEST' +MSG_JYTHON_INVALID_REQUEST = '@@JYTHON_INVALID_REQUEST' +MSG_CHANGE_DIR = '@@CHANGE_DIR:' +MSG_OK = '@@MSG_OK_END@@' +MSG_IMPORTS = '@@IMPORTS:' +MSG_PYTHONPATH = '@@PYTHONPATH_END@@' +MSG_CHANGE_PYTHONPATH = '@@CHANGE_PYTHONPATH:' +MSG_JEDI = '@@MSG_JEDI:' +MSG_SEARCH = '@@SEARCH' + +BUFFER_SIZE = 1024 + + + +currDirModule = None + +def complete_from_dir(directory): + ''' + This is necessary so that we get the imports from the same directory where the file + we are completing is located. + ''' + global currDirModule + if currDirModule is not None: + if len(sys.path) > 0 and sys.path[0] == currDirModule: + del sys.path[0] + + currDirModule = directory + sys.path.insert(0, directory) + + +def change_python_path(pythonpath): + '''Changes the pythonpath (clears all the previous pythonpath) + + @param pythonpath: string with paths separated by | + ''' + + split = pythonpath.split('|') + sys.path = [] + for path in split: + path = path.strip() + if len(path) > 0: + sys.path.append(path) + + +class Processor: + + def __init__(self): + # nothing to do + return + + def remove_invalid_chars(self, msg): + try: + msg = str(msg) + except UnicodeDecodeError: + pass + + if msg: + try: + return quote_plus(msg) + except: + sys.stdout.write('error making quote plus in %s\n' % (msg,)) + raise + return ' ' + + def format_completion_message(self, defFile, completionsList): + ''' + Format the completions suggestions in the following format: + @@COMPLETIONS(modFile(token,description),(token,description),(token,description))END@@ + ''' + compMsg = [] + compMsg.append('%s' % defFile) + for tup in completionsList: + compMsg.append(',') + + compMsg.append('(') + compMsg.append(str(self.remove_invalid_chars(tup[0]))) # token + compMsg.append(',') + compMsg.append(self.remove_invalid_chars(tup[1])) # description + + if(len(tup) > 2): + compMsg.append(',') + compMsg.append(self.remove_invalid_chars(tup[2])) # args - only if function. + + if(len(tup) > 3): + compMsg.append(',') + compMsg.append(self.remove_invalid_chars(tup[3])) # TYPE + + compMsg.append(')') + + return '%s(%s)%s' % (MSG_COMPLETIONS, ''.join(compMsg), MSG_END) + +class Exit(Exception): + pass + +class CompletionServer: + + def __init__(self, port): + self.ended = False + self.port = port + self.socket = None # socket to send messages. + self.exit_process_on_kill = True + self.processor = Processor() + + + def connect_to_server(self): + from _pydev_imps._pydev_saved_modules import socket + + self.socket = s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + s.connect((HOST, self.port)) + except: + sys.stderr.write('Error on connect_to_server with parameters: host: %s port: %s\n' % (HOST, self.port)) + raise + + def get_completions_message(self, defFile, completionsList): + ''' + get message with completions. + ''' + return self.processor.format_completion_message(defFile, completionsList) + + def get_token_and_data(self, data): + ''' + When we receive this, we have 'token):data' + ''' + token = '' + for c in data: + if c != ')': + token = token + c + else: + break; + + return token, data.lstrip(token + '):') + + def emulated_sendall(self, msg): + MSGLEN = 1024 * 20 + + totalsent = 0 + while totalsent < MSGLEN: + sent = self.socket.send(msg[totalsent:]) + if sent == 0: + return + totalsent = totalsent + sent + + + def send(self, msg): + if not hasattr(self.socket, 'sendall'): + #Older versions (jython 2.1) + self.emulated_sendall(msg) + else: + if IS_PYTHON_3_ONWARDS: + self.socket.sendall(bytearray(msg, 'utf-8')) + else: + self.socket.sendall(msg) + + + def run(self): + # Echo server program + try: + from _pydev_bundle import _pydev_log + log = _pydev_log.Log() + + dbg(SERVER_NAME + ' connecting to java server on %s (%s)' % (HOST, self.port) , INFO1) + # after being connected, create a socket as a client. + self.connect_to_server() + + dbg(SERVER_NAME + ' Connected to java server', INFO1) + + + while not self.ended: + data = '' + + while data.find(MSG_END) == -1: + received = self.socket.recv(BUFFER_SIZE) + if len(received) == 0: + raise Exit() # ok, connection ended + if IS_PYTHON_3_ONWARDS: + data = data + received.decode('utf-8') + else: + data = data + received + + try: + try: + if data.find(MSG_KILL_SERVER) != -1: + dbg(SERVER_NAME + ' kill message received', INFO1) + # break if we received kill message. + self.ended = True + raise Exit() + + dbg(SERVER_NAME + ' starting keep alive thread', INFO2) + + if data.find(MSG_PYTHONPATH) != -1: + comps = [] + for p in _sys_path: + comps.append((p, ' ')) + self.send(self.get_completions_message(None, comps)) + + else: + data = data[:data.rfind(MSG_END)] + + if data.startswith(MSG_IMPORTS): + data = data[len(MSG_IMPORTS):] + data = unquote_plus(data) + defFile, comps = _pydev_imports_tipper.generate_tip(data, log) + self.send(self.get_completions_message(defFile, comps)) + + elif data.startswith(MSG_CHANGE_PYTHONPATH): + data = data[len(MSG_CHANGE_PYTHONPATH):] + data = unquote_plus(data) + change_python_path(data) + self.send(MSG_OK) + + elif data.startswith(MSG_JEDI): + data = data[len(MSG_JEDI):] + data = unquote_plus(data) + line, column, encoding, path, source = data.split('|', 4) + try: + import jedi # @UnresolvedImport + except: + self.send(self.get_completions_message(None, [('Error on import jedi', 'Error importing jedi', '')])) + else: + script = jedi.Script( + # Line +1 because it expects lines 1-based (and col 0-based) + source=source, + line=int(line) + 1, + column=int(column), + source_encoding=encoding, + path=path, + ) + lst = [] + for completion in script.completions(): + t = completion.type + if t == 'class': + t = '1' + + elif t == 'function': + t = '2' + + elif t == 'import': + t = '0' + + elif t == 'keyword': + continue # Keywords are already handled in PyDev + + elif t == 'statement': + t = '3' + + else: + t = '-1' + + # gen list(tuple(name, doc, args, type)) + lst.append((completion.name, '', '', t)) + self.send(self.get_completions_message('empty', lst)) + + elif data.startswith(MSG_SEARCH): + data = data[len(MSG_SEARCH):] + data = unquote_plus(data) + (f, line, col), foundAs = _pydev_imports_tipper.search_definition(data) + self.send(self.get_completions_message(f, [(line, col, foundAs)])) + + elif data.startswith(MSG_CHANGE_DIR): + data = data[len(MSG_CHANGE_DIR):] + data = unquote_plus(data) + complete_from_dir(data) + self.send(MSG_OK) + + else: + self.send(MSG_INVALID_REQUEST) + except Exit: + e = sys.exc_info()[1] + msg = self.get_completions_message(None, [('Exit:', 'SystemExit', '')]) + try: + self.send(msg) + except socket.error: + pass # Ok, may be closed already + + raise e # raise original error. + + except: + dbg(SERVER_NAME + ' exception occurred', ERROR) + s = StringIO.StringIO() + traceback.print_exc(file=s) + + err = s.getvalue() + dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) + msg = self.get_completions_message(None, [('ERROR:', '%s\nLog:%s' % (err, log.get_contents()), '')]) + try: + self.send(msg) + except socket.error: + pass # Ok, may be closed already + + + finally: + log.clear_log() + + self.socket.close() + self.ended = True + raise Exit() # connection broken + + + except Exit: + if self.exit_process_on_kill: + sys.exit(0) + # No need to log SystemExit error + except: + s = StringIO.StringIO() + exc_info = sys.exc_info() + + traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) + err = s.getvalue() + dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) + raise + + + +if __name__ == '__main__': + + port = int(sys.argv[1]) # this is from where we want to receive messages. + + t = CompletionServer(port) + dbg(SERVER_NAME + ' will start', INFO1) + t.run() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_app_engine_debug_startup.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_app_engine_debug_startup.py new file mode 100644 index 0000000..464f0dd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_app_engine_debug_startup.py @@ -0,0 +1,21 @@ +if False: + config = None + + +# See: https://docs.google.com/document/d/1CCSaRiIWCLgbD3OwmuKsRoHHDfBffbROWyVWWL0ZXN4/edit +if ':' not in config.version_id: + # The default server version_id does not contain ':' + import json + import os + import sys + + startup = config.python_config.startup_args + if not startup: + raise AssertionError('Expected --python_startup_args to be passed from the pydev debugger.') + + setup = json.loads(startup) + pydevd_path = setup['pydevd'] + sys.path.append(os.path.dirname(pydevd_path)) + + import pydevd + pydevd.settrace(setup['client'], port=setup['port'], suspend=False, trace_only_current_thread=False) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_coverage.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_coverage.py new file mode 100644 index 0000000..b98731c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_coverage.py @@ -0,0 +1,96 @@ +''' +Entry point module to run code-coverage. +''' + + +def is_valid_py_file(path): + ''' + Checks whether the file can be read by the coverage module. This is especially + needed for .pyx files and .py files with syntax errors. + ''' + import os + + is_valid = False + if os.path.isfile(path) and not os.path.splitext(path)[1] == '.pyx': + try: + with open(path, 'rb') as f: + compile(f.read(), path, 'exec') + is_valid = True + except: + pass + return is_valid + + +def execute(): + import os + import sys + + files = None + if 'combine' not in sys.argv: + + if '--pydev-analyze' in sys.argv: + + #Ok, what we want here is having the files passed through stdin (because + #there may be too many files for passing in the command line -- we could + #just pass a dir and make the find files here, but as that's already + #given in the java side, let's just gather that info here). + sys.argv.remove('--pydev-analyze') + try: + s = raw_input() # @UndefinedVariable + except: + s = input() + s = s.replace('\r', '') + s = s.replace('\n', '') + + files = [] + invalid_files = [] + for v in s.split('|'): + if is_valid_py_file(v): + files.append(v) + else: + invalid_files.append(v) + if invalid_files: + sys.stderr.write('Invalid files not passed to coverage: %s\n' + % ', '.join(invalid_files)) + + # Note that in this case we'll already be in the working dir with the coverage files, + # so, the coverage file location is not passed. + + else: + # For all commands, the coverage file is configured in pydev, and passed as the first + # argument in the command line, so, let's make sure this gets to the coverage module. + os.environ['COVERAGE_FILE'] = sys.argv[1] + del sys.argv[1] + + try: + import coverage #@UnresolvedImport + except: + sys.stderr.write('Error: coverage module could not be imported\n') + sys.stderr.write('Please make sure that the coverage module ' + '(http://nedbatchelder.com/code/coverage/)\n') + sys.stderr.write('is properly installed in your interpreter: %s\n' % (sys.executable,)) + + import traceback;traceback.print_exc() + return + + if hasattr(coverage, '__version__'): + version = tuple(map(int, coverage.__version__.split('.')[:2])) + if version < (4, 3): + sys.stderr.write('Error: minimum supported coverage version is 4.3.' + '\nFound: %s\nLocation: %s\n' + % ('.'.join(str(x) for x in version), coverage.__file__)) + sys.exit(1) + else: + sys.stderr.write('Warning: Could not determine version of python module coverage.' + '\nEnsure coverage version is >= 4.3\n') + + from coverage.cmdline import main #@UnresolvedImport + + if files is not None: + sys.argv.append('xml') + sys.argv += files + + main() + +if __name__ == '__main__': + execute() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/README b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/README new file mode 100644 index 0000000..185d417 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/README @@ -0,0 +1,8 @@ +# Parts of IPython, files from: https://github.com/ipython/ipython/tree/rel-1.0.0/IPython +# The files in this package are extracted from IPython to aid the main loop integration +# See tests_mainloop for some manually runable tests + +# What we are doing is reusing the "inputhook" functionality (i.e. what in IPython +# ends up on PyOS_InputHook) and using it in the pydevconsole context. +# Rather that having the callbacks called in PyOS_InputHook, we use a custom XML-RPC +# Server (HookableXMLRPCServer) that calls the inputhook when idle diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhook.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhook.py new file mode 100644 index 0000000..f12b7f7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhook.py @@ -0,0 +1,588 @@ +# coding: utf-8 +""" +Inputhook management for GUI event loop integration. +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import sys +import select + +#----------------------------------------------------------------------------- +# Constants +#----------------------------------------------------------------------------- + +# Constants for identifying the GUI toolkits. +GUI_WX = 'wx' +GUI_QT = 'qt' +GUI_QT4 = 'qt4' +GUI_QT5 = 'qt5' +GUI_GTK = 'gtk' +GUI_TK = 'tk' +GUI_OSX = 'osx' +GUI_GLUT = 'glut' +GUI_PYGLET = 'pyglet' +GUI_GTK3 = 'gtk3' +GUI_NONE = 'none' # i.e. disable + +#----------------------------------------------------------------------------- +# Utilities +#----------------------------------------------------------------------------- + +def ignore_CTRL_C(): + """Ignore CTRL+C (not implemented).""" + pass + +def allow_CTRL_C(): + """Take CTRL+C into account (not implemented).""" + pass + +#----------------------------------------------------------------------------- +# Main InputHookManager class +#----------------------------------------------------------------------------- + + +class InputHookManager(object): + """Manage PyOS_InputHook for different GUI toolkits. + + This class installs various hooks under ``PyOSInputHook`` to handle + GUI event loop integration. + """ + + def __init__(self): + self._return_control_callback = None + self._apps = {} + self._reset() + self.pyplot_imported = False + + def _reset(self): + self._callback_pyfunctype = None + self._callback = None + self._current_gui = None + + def set_return_control_callback(self, return_control_callback): + self._return_control_callback = return_control_callback + + def get_return_control_callback(self): + return self._return_control_callback + + def return_control(self): + return self._return_control_callback() + + def get_inputhook(self): + return self._callback + + def set_inputhook(self, callback): + """Set inputhook to callback.""" + # We don't (in the context of PyDev console) actually set PyOS_InputHook, but rather + # while waiting for input on xmlrpc we run this code + self._callback = callback + + def clear_inputhook(self, app=None): + """Clear input hook. + + Parameters + ---------- + app : optional, ignored + This parameter is allowed only so that clear_inputhook() can be + called with a similar interface as all the ``enable_*`` methods. But + the actual value of the parameter is ignored. This uniform interface + makes it easier to have user-level entry points in the main IPython + app like :meth:`enable_gui`.""" + self._reset() + + def clear_app_refs(self, gui=None): + """Clear IPython's internal reference to an application instance. + + Whenever we create an app for a user on qt4 or wx, we hold a + reference to the app. This is needed because in some cases bad things + can happen if a user doesn't hold a reference themselves. This + method is provided to clear the references we are holding. + + Parameters + ---------- + gui : None or str + If None, clear all app references. If ('wx', 'qt4') clear + the app for that toolkit. References are not held for gtk or tk + as those toolkits don't have the notion of an app. + """ + if gui is None: + self._apps = {} + elif gui in self._apps: + del self._apps[gui] + + def enable_wx(self, app=None): + """Enable event loop integration with wxPython. + + Parameters + ---------- + app : WX Application, optional. + Running application to use. If not given, we probe WX for an + existing application object, and create a new one if none is found. + + Notes + ----- + This methods sets the ``PyOS_InputHook`` for wxPython, which allows + the wxPython to integrate with terminal based applications like + IPython. + + If ``app`` is not given we probe for an existing one, and return it if + found. If no existing app is found, we create an :class:`wx.App` as + follows:: + + import wx + app = wx.App(redirect=False, clearSigInt=False) + """ + import wx + from distutils.version import LooseVersion as V + wx_version = V(wx.__version__).version # @UndefinedVariable + + if wx_version < [2, 8]: + raise ValueError("requires wxPython >= 2.8, but you have %s" % wx.__version__) # @UndefinedVariable + + from pydev_ipython.inputhookwx import inputhook_wx + self.set_inputhook(inputhook_wx) + self._current_gui = GUI_WX + + if app is None: + app = wx.GetApp() # @UndefinedVariable + if app is None: + app = wx.App(redirect=False, clearSigInt=False) # @UndefinedVariable + app._in_event_loop = True + self._apps[GUI_WX] = app + return app + + def disable_wx(self): + """Disable event loop integration with wxPython. + + This merely sets PyOS_InputHook to NULL. + """ + if GUI_WX in self._apps: + self._apps[GUI_WX]._in_event_loop = False + self.clear_inputhook() + + def enable_qt(self, app=None): + from pydev_ipython.qt_for_kernel import QT_API, QT_API_PYQT5 + if QT_API == QT_API_PYQT5: + self.enable_qt5(app) + else: + self.enable_qt4(app) + + def enable_qt4(self, app=None): + """Enable event loop integration with PyQt4. + + Parameters + ---------- + app : Qt Application, optional. + Running application to use. If not given, we probe Qt for an + existing application object, and create a new one if none is found. + + Notes + ----- + This methods sets the PyOS_InputHook for PyQt4, which allows + the PyQt4 to integrate with terminal based applications like + IPython. + + If ``app`` is not given we probe for an existing one, and return it if + found. If no existing app is found, we create an :class:`QApplication` + as follows:: + + from PyQt4 import QtCore + app = QtGui.QApplication(sys.argv) + """ + from pydev_ipython.inputhookqt4 import create_inputhook_qt4 + app, inputhook_qt4 = create_inputhook_qt4(self, app) + self.set_inputhook(inputhook_qt4) + + self._current_gui = GUI_QT4 + app._in_event_loop = True + self._apps[GUI_QT4] = app + return app + + def disable_qt4(self): + """Disable event loop integration with PyQt4. + + This merely sets PyOS_InputHook to NULL. + """ + if GUI_QT4 in self._apps: + self._apps[GUI_QT4]._in_event_loop = False + self.clear_inputhook() + + def enable_qt5(self, app=None): + from pydev_ipython.inputhookqt5 import create_inputhook_qt5 + app, inputhook_qt5 = create_inputhook_qt5(self, app) + self.set_inputhook(inputhook_qt5) + + self._current_gui = GUI_QT5 + app._in_event_loop = True + self._apps[GUI_QT5] = app + return app + + def disable_qt5(self): + if GUI_QT5 in self._apps: + self._apps[GUI_QT5]._in_event_loop = False + self.clear_inputhook() + + def enable_gtk(self, app=None): + """Enable event loop integration with PyGTK. + + Parameters + ---------- + app : ignored + Ignored, it's only a placeholder to keep the call signature of all + gui activation methods consistent, which simplifies the logic of + supporting magics. + + Notes + ----- + This methods sets the PyOS_InputHook for PyGTK, which allows + the PyGTK to integrate with terminal based applications like + IPython. + """ + from pydev_ipython.inputhookgtk import create_inputhook_gtk + self.set_inputhook(create_inputhook_gtk(self._stdin_file)) + self._current_gui = GUI_GTK + + def disable_gtk(self): + """Disable event loop integration with PyGTK. + + This merely sets PyOS_InputHook to NULL. + """ + self.clear_inputhook() + + def enable_tk(self, app=None): + """Enable event loop integration with Tk. + + Parameters + ---------- + app : toplevel :class:`Tkinter.Tk` widget, optional. + Running toplevel widget to use. If not given, we probe Tk for an + existing one, and create a new one if none is found. + + Notes + ----- + If you have already created a :class:`Tkinter.Tk` object, the only + thing done by this method is to register with the + :class:`InputHookManager`, since creating that object automatically + sets ``PyOS_InputHook``. + """ + self._current_gui = GUI_TK + if app is None: + try: + import Tkinter as _TK + except: + # Python 3 + import tkinter as _TK # @UnresolvedImport + app = _TK.Tk() + app.withdraw() + self._apps[GUI_TK] = app + + from pydev_ipython.inputhooktk import create_inputhook_tk + self.set_inputhook(create_inputhook_tk(app)) + return app + + def disable_tk(self): + """Disable event loop integration with Tkinter. + + This merely sets PyOS_InputHook to NULL. + """ + self.clear_inputhook() + + + def enable_glut(self, app=None): + """ Enable event loop integration with GLUT. + + Parameters + ---------- + + app : ignored + Ignored, it's only a placeholder to keep the call signature of all + gui activation methods consistent, which simplifies the logic of + supporting magics. + + Notes + ----- + + This methods sets the PyOS_InputHook for GLUT, which allows the GLUT to + integrate with terminal based applications like IPython. Due to GLUT + limitations, it is currently not possible to start the event loop + without first creating a window. You should thus not create another + window but use instead the created one. See 'gui-glut.py' in the + docs/examples/lib directory. + + The default screen mode is set to: + glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH + """ + + import OpenGL.GLUT as glut # @UnresolvedImport + from pydev_ipython.inputhookglut import glut_display_mode, \ + glut_close, glut_display, \ + glut_idle, inputhook_glut + + if GUI_GLUT not in self._apps: + glut.glutInit(sys.argv) + glut.glutInitDisplayMode(glut_display_mode) + # This is specific to freeglut + if bool(glut.glutSetOption): + glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, + glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS) + glut.glutCreateWindow(sys.argv[0]) + glut.glutReshapeWindow(1, 1) + glut.glutHideWindow() + glut.glutWMCloseFunc(glut_close) + glut.glutDisplayFunc(glut_display) + glut.glutIdleFunc(glut_idle) + else: + glut.glutWMCloseFunc(glut_close) + glut.glutDisplayFunc(glut_display) + glut.glutIdleFunc(glut_idle) + self.set_inputhook(inputhook_glut) + self._current_gui = GUI_GLUT + self._apps[GUI_GLUT] = True + + + def disable_glut(self): + """Disable event loop integration with glut. + + This sets PyOS_InputHook to NULL and set the display function to a + dummy one and set the timer to a dummy timer that will be triggered + very far in the future. + """ + import OpenGL.GLUT as glut # @UnresolvedImport + from glut_support import glutMainLoopEvent # @UnresolvedImport + + glut.glutHideWindow() # This is an event to be processed below + glutMainLoopEvent() + self.clear_inputhook() + + def enable_pyglet(self, app=None): + """Enable event loop integration with pyglet. + + Parameters + ---------- + app : ignored + Ignored, it's only a placeholder to keep the call signature of all + gui activation methods consistent, which simplifies the logic of + supporting magics. + + Notes + ----- + This methods sets the ``PyOS_InputHook`` for pyglet, which allows + pyglet to integrate with terminal based applications like + IPython. + + """ + from pydev_ipython.inputhookpyglet import inputhook_pyglet + self.set_inputhook(inputhook_pyglet) + self._current_gui = GUI_PYGLET + return app + + def disable_pyglet(self): + """Disable event loop integration with pyglet. + + This merely sets PyOS_InputHook to NULL. + """ + self.clear_inputhook() + + def enable_gtk3(self, app=None): + """Enable event loop integration with Gtk3 (gir bindings). + + Parameters + ---------- + app : ignored + Ignored, it's only a placeholder to keep the call signature of all + gui activation methods consistent, which simplifies the logic of + supporting magics. + + Notes + ----- + This methods sets the PyOS_InputHook for Gtk3, which allows + the Gtk3 to integrate with terminal based applications like + IPython. + """ + from pydev_ipython.inputhookgtk3 import create_inputhook_gtk3 + self.set_inputhook(create_inputhook_gtk3(self._stdin_file)) + self._current_gui = GUI_GTK + + def disable_gtk3(self): + """Disable event loop integration with PyGTK. + + This merely sets PyOS_InputHook to NULL. + """ + self.clear_inputhook() + + def enable_mac(self, app=None): + """ Enable event loop integration with MacOSX. + + We call function pyplot.pause, which updates and displays active + figure during pause. It's not MacOSX-specific, but it enables to + avoid inputhooks in native MacOSX backend. + Also we shouldn't import pyplot, until user does it. Cause it's + possible to choose backend before importing pyplot for the first + time only. + """ + def inputhook_mac(app=None): + if self.pyplot_imported: + pyplot = sys.modules['matplotlib.pyplot'] + try: + pyplot.pause(0.01) + except: + pass + else: + if 'matplotlib.pyplot' in sys.modules: + self.pyplot_imported = True + + self.set_inputhook(inputhook_mac) + self._current_gui = GUI_OSX + + def disable_mac(self): + self.clear_inputhook() + + def current_gui(self): + """Return a string indicating the currently active GUI or None.""" + return self._current_gui + +inputhook_manager = InputHookManager() + +enable_wx = inputhook_manager.enable_wx +disable_wx = inputhook_manager.disable_wx +enable_qt = inputhook_manager.enable_qt +enable_qt4 = inputhook_manager.enable_qt4 +disable_qt4 = inputhook_manager.disable_qt4 +enable_qt5 = inputhook_manager.enable_qt5 +disable_qt5 = inputhook_manager.disable_qt5 +enable_gtk = inputhook_manager.enable_gtk +disable_gtk = inputhook_manager.disable_gtk +enable_tk = inputhook_manager.enable_tk +disable_tk = inputhook_manager.disable_tk +enable_glut = inputhook_manager.enable_glut +disable_glut = inputhook_manager.disable_glut +enable_pyglet = inputhook_manager.enable_pyglet +disable_pyglet = inputhook_manager.disable_pyglet +enable_gtk3 = inputhook_manager.enable_gtk3 +disable_gtk3 = inputhook_manager.disable_gtk3 +enable_mac = inputhook_manager.enable_mac +disable_mac = inputhook_manager.disable_mac +clear_inputhook = inputhook_manager.clear_inputhook +set_inputhook = inputhook_manager.set_inputhook +current_gui = inputhook_manager.current_gui +clear_app_refs = inputhook_manager.clear_app_refs + +# We maintain this as stdin_ready so that the individual inputhooks +# can diverge as little as possible from their IPython sources +stdin_ready = inputhook_manager.return_control +set_return_control_callback = inputhook_manager.set_return_control_callback +get_return_control_callback = inputhook_manager.get_return_control_callback +get_inputhook = inputhook_manager.get_inputhook + +# Convenience function to switch amongst them +def enable_gui(gui=None, app=None): + """Switch amongst GUI input hooks by name. + + This is just a utility wrapper around the methods of the InputHookManager + object. + + Parameters + ---------- + gui : optional, string or None + If None (or 'none'), clears input hook, otherwise it must be one + of the recognized GUI names (see ``GUI_*`` constants in module). + + app : optional, existing application object. + For toolkits that have the concept of a global app, you can supply an + existing one. If not given, the toolkit will be probed for one, and if + none is found, a new one will be created. Note that GTK does not have + this concept, and passing an app if ``gui=="GTK"`` will raise an error. + + Returns + ------- + The output of the underlying gui switch routine, typically the actual + PyOS_InputHook wrapper object or the GUI toolkit app created, if there was + one. + """ + + if get_return_control_callback() is None: + raise ValueError("A return_control_callback must be supplied as a reference before a gui can be enabled") + + guis = {GUI_NONE: clear_inputhook, + GUI_OSX: enable_mac, + GUI_TK: enable_tk, + GUI_GTK: enable_gtk, + GUI_WX: enable_wx, + GUI_QT: enable_qt, + GUI_QT4: enable_qt4, + GUI_QT5: enable_qt5, + GUI_GLUT: enable_glut, + GUI_PYGLET: enable_pyglet, + GUI_GTK3: enable_gtk3, + } + try: + gui_hook = guis[gui] + except KeyError: + if gui is None or gui == '': + gui_hook = clear_inputhook + else: + e = "Invalid GUI request %r, valid ones are:%s" % (gui, guis.keys()) + raise ValueError(e) + return gui_hook(app) + +__all__ = [ + "GUI_WX", + "GUI_QT", + "GUI_QT4", + "GUI_QT5", + "GUI_GTK", + "GUI_TK", + "GUI_OSX", + "GUI_GLUT", + "GUI_PYGLET", + "GUI_GTK3", + "GUI_NONE", + + + "ignore_CTRL_C", + "allow_CTRL_C", + + "InputHookManager", + + "inputhook_manager", + + "enable_wx", + "disable_wx", + "enable_qt", + "enable_qt4", + "disable_qt4", + "enable_qt5", + "disable_qt5", + "enable_gtk", + "disable_gtk", + "enable_tk", + "disable_tk", + "enable_glut", + "disable_glut", + "enable_pyglet", + "disable_pyglet", + "enable_gtk3", + "disable_gtk3", + "enable_mac", + "disable_mac", + "clear_inputhook", + "set_inputhook", + "current_gui", + "clear_app_refs", + + "stdin_ready", + "set_return_control_callback", + "get_return_control_callback", + "get_inputhook", + + "enable_gui"] diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookglut.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookglut.py new file mode 100644 index 0000000..bbd6882 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookglut.py @@ -0,0 +1,153 @@ +# coding: utf-8 +""" +GLUT Inputhook support functions +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +# GLUT is quite an old library and it is difficult to ensure proper +# integration within IPython since original GLUT does not allow to handle +# events one by one. Instead, it requires for the mainloop to be entered +# and never returned (there is not even a function to exit he +# mainloop). Fortunately, there are alternatives such as freeglut +# (available for linux and windows) and the OSX implementation gives +# access to a glutCheckLoop() function that blocks itself until a new +# event is received. This means we have to setup the idle callback to +# ensure we got at least one event that will unblock the function. +# +# Furthermore, it is not possible to install these handlers without a window +# being first created. We choose to make this window invisible. This means that +# display mode options are set at this level and user won't be able to change +# them later without modifying the code. This should probably be made available +# via IPython options system. + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- +import os +import sys +from _pydev_imps._pydev_saved_modules import time +import signal +import OpenGL.GLUT as glut # @UnresolvedImport +import OpenGL.platform as platform # @UnresolvedImport +from timeit import default_timer as clock +from pydev_ipython.inputhook import stdin_ready + +#----------------------------------------------------------------------------- +# Constants +#----------------------------------------------------------------------------- + +# Frame per second : 60 +# Should probably be an IPython option +glut_fps = 60 + + +# Display mode : double buffeed + rgba + depth +# Should probably be an IPython option +glut_display_mode = (glut.GLUT_DOUBLE | + glut.GLUT_RGBA | + glut.GLUT_DEPTH) + +glutMainLoopEvent = None +if sys.platform == 'darwin': + try: + glutCheckLoop = platform.createBaseFunction( + 'glutCheckLoop', dll=platform.GLUT, resultType=None, + argTypes=[], + doc='glutCheckLoop( ) -> None', + argNames=(), + ) + except AttributeError: + raise RuntimeError( + '''Your glut implementation does not allow interactive sessions''' + '''Consider installing freeglut.''') + glutMainLoopEvent = glutCheckLoop +elif glut.HAVE_FREEGLUT: + glutMainLoopEvent = glut.glutMainLoopEvent +else: + raise RuntimeError( + '''Your glut implementation does not allow interactive sessions. ''' + '''Consider installing freeglut.''') + + +#----------------------------------------------------------------------------- +# Callback functions +#----------------------------------------------------------------------------- + +def glut_display(): + # Dummy display function + pass + +def glut_idle(): + # Dummy idle function + pass + +def glut_close(): + # Close function only hides the current window + glut.glutHideWindow() + glutMainLoopEvent() + +def glut_int_handler(signum, frame): + # Catch sigint and print the defautl message + signal.signal(signal.SIGINT, signal.default_int_handler) + print '\nKeyboardInterrupt' + # Need to reprint the prompt at this stage + + + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- +def inputhook_glut(): + """Run the pyglet event loop by processing pending events only. + + This keeps processing pending events until stdin is ready. After + processing all pending events, a call to time.sleep is inserted. This is + needed, otherwise, CPU usage is at 100%. This sleep time should be tuned + though for best performance. + """ + # We need to protect against a user pressing Control-C when IPython is + # idle and this is running. We trap KeyboardInterrupt and pass. + + signal.signal(signal.SIGINT, glut_int_handler) + + try: + t = clock() + + # Make sure the default window is set after a window has been closed + if glut.glutGetWindow() == 0: + glut.glutSetWindow( 1 ) + glutMainLoopEvent() + return 0 + + while not stdin_ready(): + glutMainLoopEvent() + # We need to sleep at this point to keep the idle CPU load + # low. However, if sleep to long, GUI response is poor. As + # a compromise, we watch how often GUI events are being processed + # and switch between a short and long sleep time. Here are some + # stats useful in helping to tune this. + # time CPU load + # 0.001 13% + # 0.005 3% + # 0.01 1.5% + # 0.05 0.5% + used_time = clock() - t + if used_time > 10.0: + # print 'Sleep for 1 s' # dbg + time.sleep(1.0) + elif used_time > 0.1: + # Few GUI events coming in, so we can sleep longer + # print 'Sleep for 0.05 s' # dbg + time.sleep(0.05) + else: + # Many GUI events coming in, so sleep only very little + time.sleep(0.001) + except KeyboardInterrupt: + pass + return 0 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookgtk.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookgtk.py new file mode 100644 index 0000000..53006cd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookgtk.py @@ -0,0 +1,36 @@ +# encoding: utf-8 +""" +Enable pygtk to be used interacive by setting PyOS_InputHook. + +Authors: Brian Granger +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import gtk, gobject # @UnresolvedImport + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + + +def _main_quit(*args, **kwargs): + gtk.main_quit() + return False + +def create_inputhook_gtk(stdin_file): + def inputhook_gtk(): + gobject.io_add_watch(stdin_file, gobject.IO_IN, _main_quit) + gtk.main() + return 0 + return inputhook_gtk + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookgtk3.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookgtk3.py new file mode 100644 index 0000000..f2ca39f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookgtk3.py @@ -0,0 +1,35 @@ +# encoding: utf-8 +""" +Enable Gtk3 to be used interacive by IPython. + +Authors: Thomi Richards +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2012, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from gi.repository import Gtk, GLib # @UnresolvedImport + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +def _main_quit(*args, **kwargs): + Gtk.main_quit() + return False + + +def create_inputhook_gtk3(stdin_file): + def inputhook_gtk3(): + GLib.io_add_watch(stdin_file, GLib.IO_IN, _main_quit) + Gtk.main() + return 0 + return inputhook_gtk3 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookpyglet.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookpyglet.py new file mode 100644 index 0000000..bf08afd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookpyglet.py @@ -0,0 +1,92 @@ +# encoding: utf-8 +""" +Enable pyglet to be used interacive by setting PyOS_InputHook. + +Authors +------- + +* Nicolas P. Rougier +* Fernando Perez +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +import sys +from _pydev_imps._pydev_saved_modules import time +from timeit import default_timer as clock +import pyglet # @UnresolvedImport +from pydev_ipython.inputhook import stdin_ready + + +# On linux only, window.flip() has a bug that causes an AttributeError on +# window close. For details, see: +# http://groups.google.com/group/pyglet-users/browse_thread/thread/47c1aab9aa4a3d23/c22f9e819826799e?#c22f9e819826799e + +if sys.platform.startswith('linux'): + def flip(window): + try: + window.flip() + except AttributeError: + pass +else: + def flip(window): + window.flip() + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +def inputhook_pyglet(): + """Run the pyglet event loop by processing pending events only. + + This keeps processing pending events until stdin is ready. After + processing all pending events, a call to time.sleep is inserted. This is + needed, otherwise, CPU usage is at 100%. This sleep time should be tuned + though for best performance. + """ + # We need to protect against a user pressing Control-C when IPython is + # idle and this is running. We trap KeyboardInterrupt and pass. + try: + t = clock() + while not stdin_ready(): + pyglet.clock.tick() + for window in pyglet.app.windows: + window.switch_to() + window.dispatch_events() + window.dispatch_event('on_draw') + flip(window) + + # We need to sleep at this point to keep the idle CPU load + # low. However, if sleep to long, GUI response is poor. As + # a compromise, we watch how often GUI events are being processed + # and switch between a short and long sleep time. Here are some + # stats useful in helping to tune this. + # time CPU load + # 0.001 13% + # 0.005 3% + # 0.01 1.5% + # 0.05 0.5% + used_time = clock() - t + if used_time > 10.0: + # print 'Sleep for 1 s' # dbg + time.sleep(1.0) + elif used_time > 0.1: + # Few GUI events coming in, so we can sleep longer + # print 'Sleep for 0.05 s' # dbg + time.sleep(0.05) + else: + # Many GUI events coming in, so sleep only very little + time.sleep(0.001) + except KeyboardInterrupt: + pass + return 0 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookqt4.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookqt4.py new file mode 100644 index 0000000..b7e1cf0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookqt4.py @@ -0,0 +1,196 @@ +# -*- coding: utf-8 -*- +""" +Qt4's inputhook support function + +Author: Christian Boos +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +import signal + +import threading + + +from pydev_ipython.qt_for_kernel import QtCore, QtGui +from pydev_ipython.inputhook import allow_CTRL_C, ignore_CTRL_C, stdin_ready + +# To minimise future merging complexity, rather than edit the entire code base below +# we fake InteractiveShell here +class InteractiveShell: + _instance = None + @classmethod + def instance(cls): + if cls._instance is None: + cls._instance = cls() + return cls._instance + def set_hook(self, *args, **kwargs): + # We don't consider the pre_prompt_hook because we don't have + # KeyboardInterrupts to consider since we are running under PyDev + pass + + +#----------------------------------------------------------------------------- +# Module Globals +#----------------------------------------------------------------------------- + +got_kbdint = False +sigint_timer = None + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +def create_inputhook_qt4(mgr, app=None): + """Create an input hook for running the Qt4 application event loop. + + Parameters + ---------- + mgr : an InputHookManager + + app : Qt Application, optional. + Running application to use. If not given, we probe Qt for an + existing application object, and create a new one if none is found. + + Returns + ------- + A pair consisting of a Qt Application (either the one given or the + one found or created) and a inputhook. + + Notes + ----- + We use a custom input hook instead of PyQt4's default one, as it + interacts better with the readline packages (issue #481). + + The inputhook function works in tandem with a 'pre_prompt_hook' + which automatically restores the hook as an inputhook in case the + latter has been temporarily disabled after having intercepted a + KeyboardInterrupt. + """ + + if app is None: + app = QtCore.QCoreApplication.instance() + if app is None: + app = QtGui.QApplication([" "]) + + # Re-use previously created inputhook if any + ip = InteractiveShell.instance() + if hasattr(ip, '_inputhook_qt4'): + return app, ip._inputhook_qt4 + + # Otherwise create the inputhook_qt4/preprompthook_qt4 pair of + # hooks (they both share the got_kbdint flag) + + def inputhook_qt4(): + """PyOS_InputHook python hook for Qt4. + + Process pending Qt events and if there's no pending keyboard + input, spend a short slice of time (50ms) running the Qt event + loop. + + As a Python ctypes callback can't raise an exception, we catch + the KeyboardInterrupt and temporarily deactivate the hook, + which will let a *second* CTRL+C be processed normally and go + back to a clean prompt line. + """ + try: + allow_CTRL_C() + app = QtCore.QCoreApplication.instance() + if not app: # shouldn't happen, but safer if it happens anyway... + return 0 + app.processEvents(QtCore.QEventLoop.AllEvents, 300) + if not stdin_ready(): + # Generally a program would run QCoreApplication::exec() + # from main() to enter and process the Qt event loop until + # quit() or exit() is called and the program terminates. + # + # For our input hook integration, we need to repeatedly + # enter and process the Qt event loop for only a short + # amount of time (say 50ms) to ensure that Python stays + # responsive to other user inputs. + # + # A naive approach would be to repeatedly call + # QCoreApplication::exec(), using a timer to quit after a + # short amount of time. Unfortunately, QCoreApplication + # emits an aboutToQuit signal before stopping, which has + # the undesirable effect of closing all modal windows. + # + # To work around this problem, we instead create a + # QEventLoop and call QEventLoop::exec(). Other than + # setting some state variables which do not seem to be + # used anywhere, the only thing QCoreApplication adds is + # the aboutToQuit signal which is precisely what we are + # trying to avoid. + timer = QtCore.QTimer() + event_loop = QtCore.QEventLoop() + timer.timeout.connect(event_loop.quit) + while not stdin_ready(): + timer.start(50) + event_loop.exec_() + timer.stop() + except KeyboardInterrupt: + global got_kbdint, sigint_timer + + ignore_CTRL_C() + got_kbdint = True + mgr.clear_inputhook() + + # This generates a second SIGINT so the user doesn't have to + # press CTRL+C twice to get a clean prompt. + # + # Since we can't catch the resulting KeyboardInterrupt here + # (because this is a ctypes callback), we use a timer to + # generate the SIGINT after we leave this callback. + # + # Unfortunately this doesn't work on Windows (SIGINT kills + # Python and CTRL_C_EVENT doesn't work). + if(os.name == 'posix'): + pid = os.getpid() + if(not sigint_timer): + sigint_timer = threading.Timer(.01, os.kill, + args=[pid, signal.SIGINT] ) + sigint_timer.start() + else: + print("\nKeyboardInterrupt - Ctrl-C again for new prompt") + + + except: # NO exceptions are allowed to escape from a ctypes callback + ignore_CTRL_C() + from traceback import print_exc + print_exc() + print("Got exception from inputhook_qt4, unregistering.") + mgr.clear_inputhook() + finally: + allow_CTRL_C() + return 0 + + def preprompthook_qt4(ishell): + """'pre_prompt_hook' used to restore the Qt4 input hook + + (in case the latter was temporarily deactivated after a + CTRL+C) + """ + global got_kbdint, sigint_timer + + if(sigint_timer): + sigint_timer.cancel() + sigint_timer = None + + if got_kbdint: + mgr.set_inputhook(inputhook_qt4) + got_kbdint = False + + ip._inputhook_qt4 = inputhook_qt4 + ip.set_hook('pre_prompt_hook', preprompthook_qt4) + + return app, inputhook_qt4 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookqt5.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookqt5.py new file mode 100644 index 0000000..77b938b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookqt5.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- +""" +Qt5's inputhook support function + +Author: Christian Boos +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import os +import signal + +import threading + + +from pydev_ipython.qt_for_kernel import QtCore, QtGui +from pydev_ipython.inputhook import allow_CTRL_C, ignore_CTRL_C, stdin_ready + +# To minimise future merging complexity, rather than edit the entire code base below +# we fake InteractiveShell here +class InteractiveShell: + _instance = None + @classmethod + def instance(cls): + if cls._instance is None: + cls._instance = cls() + return cls._instance + def set_hook(self, *args, **kwargs): + # We don't consider the pre_prompt_hook because we don't have + # KeyboardInterrupts to consider since we are running under PyDev + pass + + +#----------------------------------------------------------------------------- +# Module Globals +#----------------------------------------------------------------------------- + +got_kbdint = False +sigint_timer = None + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +def create_inputhook_qt5(mgr, app=None): + """Create an input hook for running the Qt5 application event loop. + + Parameters + ---------- + mgr : an InputHookManager + + app : Qt Application, optional. + Running application to use. If not given, we probe Qt for an + existing application object, and create a new one if none is found. + + Returns + ------- + A pair consisting of a Qt Application (either the one given or the + one found or created) and a inputhook. + + Notes + ----- + We use a custom input hook instead of PyQt5's default one, as it + interacts better with the readline packages (issue #481). + + The inputhook function works in tandem with a 'pre_prompt_hook' + which automatically restores the hook as an inputhook in case the + latter has been temporarily disabled after having intercepted a + KeyboardInterrupt. + """ + + if app is None: + app = QtCore.QCoreApplication.instance() + if app is None: + from PyQt5 import QtWidgets + app = QtWidgets.QApplication([" "]) + + # Re-use previously created inputhook if any + ip = InteractiveShell.instance() + if hasattr(ip, '_inputhook_qt5'): + return app, ip._inputhook_qt5 + + # Otherwise create the inputhook_qt5/preprompthook_qt5 pair of + # hooks (they both share the got_kbdint flag) + + def inputhook_qt5(): + """PyOS_InputHook python hook for Qt5. + + Process pending Qt events and if there's no pending keyboard + input, spend a short slice of time (50ms) running the Qt event + loop. + + As a Python ctypes callback can't raise an exception, we catch + the KeyboardInterrupt and temporarily deactivate the hook, + which will let a *second* CTRL+C be processed normally and go + back to a clean prompt line. + """ + try: + allow_CTRL_C() + app = QtCore.QCoreApplication.instance() + if not app: # shouldn't happen, but safer if it happens anyway... + return 0 + app.processEvents(QtCore.QEventLoop.AllEvents, 300) + if not stdin_ready(): + # Generally a program would run QCoreApplication::exec() + # from main() to enter and process the Qt event loop until + # quit() or exit() is called and the program terminates. + # + # For our input hook integration, we need to repeatedly + # enter and process the Qt event loop for only a short + # amount of time (say 50ms) to ensure that Python stays + # responsive to other user inputs. + # + # A naive approach would be to repeatedly call + # QCoreApplication::exec(), using a timer to quit after a + # short amount of time. Unfortunately, QCoreApplication + # emits an aboutToQuit signal before stopping, which has + # the undesirable effect of closing all modal windows. + # + # To work around this problem, we instead create a + # QEventLoop and call QEventLoop::exec(). Other than + # setting some state variables which do not seem to be + # used anywhere, the only thing QCoreApplication adds is + # the aboutToQuit signal which is precisely what we are + # trying to avoid. + timer = QtCore.QTimer() + event_loop = QtCore.QEventLoop() + timer.timeout.connect(event_loop.quit) + while not stdin_ready(): + timer.start(50) + event_loop.exec_() + timer.stop() + except KeyboardInterrupt: + global got_kbdint, sigint_timer + + ignore_CTRL_C() + got_kbdint = True + mgr.clear_inputhook() + + # This generates a second SIGINT so the user doesn't have to + # press CTRL+C twice to get a clean prompt. + # + # Since we can't catch the resulting KeyboardInterrupt here + # (because this is a ctypes callback), we use a timer to + # generate the SIGINT after we leave this callback. + # + # Unfortunately this doesn't work on Windows (SIGINT kills + # Python and CTRL_C_EVENT doesn't work). + if(os.name == 'posix'): + pid = os.getpid() + if(not sigint_timer): + sigint_timer = threading.Timer(.01, os.kill, + args=[pid, signal.SIGINT] ) + sigint_timer.start() + else: + print("\nKeyboardInterrupt - Ctrl-C again for new prompt") + + + except: # NO exceptions are allowed to escape from a ctypes callback + ignore_CTRL_C() + from traceback import print_exc + print_exc() + print("Got exception from inputhook_qt5, unregistering.") + mgr.clear_inputhook() + finally: + allow_CTRL_C() + return 0 + + def preprompthook_qt5(ishell): + """'pre_prompt_hook' used to restore the Qt5 input hook + + (in case the latter was temporarily deactivated after a + CTRL+C) + """ + global got_kbdint, sigint_timer + + if(sigint_timer): + sigint_timer.cancel() + sigint_timer = None + + if got_kbdint: + mgr.set_inputhook(inputhook_qt5) + got_kbdint = False + + ip._inputhook_qt5 = inputhook_qt5 + ip.set_hook('pre_prompt_hook', preprompthook_qt5) + + return app, inputhook_qt5 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhooktk.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhooktk.py new file mode 100644 index 0000000..e245cc0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhooktk.py @@ -0,0 +1,23 @@ +# encoding: utf-8 +# Unlike what IPython does, we need to have an explicit inputhook because tkinter handles +# input hook in the C Source code + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from pydev_ipython.inputhook import stdin_ready + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +TCL_DONT_WAIT = 1 << 1 + +def create_inputhook_tk(app): + def inputhook_tk(): + while app.dooneevent(TCL_DONT_WAIT) == 1: + if stdin_ready(): + break + return 0 + return inputhook_tk diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookwx.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookwx.py new file mode 100644 index 0000000..88fe2c6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/inputhookwx.py @@ -0,0 +1,166 @@ +# encoding: utf-8 +""" +Enable wxPython to be used interacive by setting PyOS_InputHook. + +Authors: Robin Dunn, Brian Granger, Ondrej Certik +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2008-2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import sys +import signal +from _pydev_imps._pydev_saved_modules import time +from timeit import default_timer as clock +import wx + +from pydev_ipython.inputhook import stdin_ready + + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +def inputhook_wx1(): + """Run the wx event loop by processing pending events only. + + This approach seems to work, but its performance is not great as it + relies on having PyOS_InputHook called regularly. + """ + try: + app = wx.GetApp() # @UndefinedVariable + if app is not None: + assert wx.Thread_IsMain() # @UndefinedVariable + + # Make a temporary event loop and process system events until + # there are no more waiting, then allow idle events (which + # will also deal with pending or posted wx events.) + evtloop = wx.EventLoop() # @UndefinedVariable + ea = wx.EventLoopActivator(evtloop) # @UndefinedVariable + while evtloop.Pending(): + evtloop.Dispatch() + app.ProcessIdle() + del ea + except KeyboardInterrupt: + pass + return 0 + +class EventLoopTimer(wx.Timer): # @UndefinedVariable + + def __init__(self, func): + self.func = func + wx.Timer.__init__(self) # @UndefinedVariable + + def Notify(self): + self.func() + +class EventLoopRunner(object): + + def Run(self, time): + self.evtloop = wx.EventLoop() # @UndefinedVariable + self.timer = EventLoopTimer(self.check_stdin) + self.timer.Start(time) + self.evtloop.Run() + + def check_stdin(self): + if stdin_ready(): + self.timer.Stop() + self.evtloop.Exit() + +def inputhook_wx2(): + """Run the wx event loop, polling for stdin. + + This version runs the wx eventloop for an undetermined amount of time, + during which it periodically checks to see if anything is ready on + stdin. If anything is ready on stdin, the event loop exits. + + The argument to elr.Run controls how often the event loop looks at stdin. + This determines the responsiveness at the keyboard. A setting of 1000 + enables a user to type at most 1 char per second. I have found that a + setting of 10 gives good keyboard response. We can shorten it further, + but eventually performance would suffer from calling select/kbhit too + often. + """ + try: + app = wx.GetApp() # @UndefinedVariable + if app is not None: + assert wx.Thread_IsMain() # @UndefinedVariable + elr = EventLoopRunner() + # As this time is made shorter, keyboard response improves, but idle + # CPU load goes up. 10 ms seems like a good compromise. + elr.Run(time=10) # CHANGE time here to control polling interval + except KeyboardInterrupt: + pass + return 0 + +def inputhook_wx3(): + """Run the wx event loop by processing pending events only. + + This is like inputhook_wx1, but it keeps processing pending events + until stdin is ready. After processing all pending events, a call to + time.sleep is inserted. This is needed, otherwise, CPU usage is at 100%. + This sleep time should be tuned though for best performance. + """ + # We need to protect against a user pressing Control-C when IPython is + # idle and this is running. We trap KeyboardInterrupt and pass. + try: + app = wx.GetApp() # @UndefinedVariable + if app is not None: + assert wx.Thread_IsMain() # @UndefinedVariable + + # The import of wx on Linux sets the handler for signal.SIGINT + # to 0. This is a bug in wx or gtk. We fix by just setting it + # back to the Python default. + if not callable(signal.getsignal(signal.SIGINT)): + signal.signal(signal.SIGINT, signal.default_int_handler) + + evtloop = wx.EventLoop() # @UndefinedVariable + ea = wx.EventLoopActivator(evtloop) # @UndefinedVariable + t = clock() + while not stdin_ready(): + while evtloop.Pending(): + t = clock() + evtloop.Dispatch() + app.ProcessIdle() + # We need to sleep at this point to keep the idle CPU load + # low. However, if sleep to long, GUI response is poor. As + # a compromise, we watch how often GUI events are being processed + # and switch between a short and long sleep time. Here are some + # stats useful in helping to tune this. + # time CPU load + # 0.001 13% + # 0.005 3% + # 0.01 1.5% + # 0.05 0.5% + used_time = clock() - t + if used_time > 10.0: + # print 'Sleep for 1 s' # dbg + time.sleep(1.0) + elif used_time > 0.1: + # Few GUI events coming in, so we can sleep longer + # print 'Sleep for 0.05 s' # dbg + time.sleep(0.05) + else: + # Many GUI events coming in, so sleep only very little + time.sleep(0.001) + del ea + except KeyboardInterrupt: + pass + return 0 + +if sys.platform == 'darwin': + # On OSX, evtloop.Pending() always returns True, regardless of there being + # any events pending. As such we can't use implementations 1 or 3 of the + # inputhook as those depend on a pending/dispatch loop. + inputhook_wx = inputhook_wx2 +else: + # This is our default implementation + inputhook_wx = inputhook_wx3 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/matplotlibtools.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/matplotlibtools.py new file mode 100644 index 0000000..769cff2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/matplotlibtools.py @@ -0,0 +1,151 @@ + +import sys +from _pydev_bundle import pydev_log + +backends = {'tk': 'TkAgg', + 'gtk': 'GTKAgg', + 'wx': 'WXAgg', + 'qt': 'Qt4Agg', # qt3 not supported + 'qt4': 'Qt4Agg', + 'qt5': 'Qt5Agg', + 'osx': 'MacOSX'} + +# We also need a reverse backends2guis mapping that will properly choose which +# GUI support to activate based on the desired matplotlib backend. For the +# most part it's just a reverse of the above dict, but we also need to add a +# few others that map to the same GUI manually: +backend2gui = dict(zip(backends.values(), backends.keys())) +backend2gui['Qt4Agg'] = 'qt4' +backend2gui['Qt5Agg'] = 'qt5' +# In the reverse mapping, there are a few extra valid matplotlib backends that +# map to the same GUI support +backend2gui['GTK'] = backend2gui['GTKCairo'] = 'gtk' +backend2gui['WX'] = 'wx' +backend2gui['CocoaAgg'] = 'osx' + + +def do_enable_gui(guiname): + from _pydev_bundle.pydev_versioncheck import versionok_for_gui + if versionok_for_gui(): + try: + from pydev_ipython.inputhook import enable_gui + enable_gui(guiname) + except: + sys.stderr.write("Failed to enable GUI event loop integration for '%s'\n" % guiname) + pydev_log.exception() + elif guiname not in ['none', '', None]: + # Only print a warning if the guiname was going to do something + sys.stderr.write("Debug console: Python version does not support GUI event loop integration for '%s'\n" % guiname) + # Return value does not matter, so return back what was sent + return guiname + + +def find_gui_and_backend(): + """Return the gui and mpl backend.""" + matplotlib = sys.modules['matplotlib'] + # WARNING: this assumes matplotlib 1.1 or newer!! + backend = matplotlib.rcParams['backend'] + # In this case, we need to find what the appropriate gui selection call + # should be for IPython, so we can activate inputhook accordingly + gui = backend2gui.get(backend, None) + return gui, backend + + +def is_interactive_backend(backend): + """ Check if backend is interactive """ + matplotlib = sys.modules['matplotlib'] + from matplotlib.rcsetup import interactive_bk, non_interactive_bk # @UnresolvedImport + if backend in interactive_bk: + return True + elif backend in non_interactive_bk: + return False + else: + return matplotlib.is_interactive() + + +def patch_use(enable_gui_function): + """ Patch matplotlib function 'use' """ + matplotlib = sys.modules['matplotlib'] + + def patched_use(*args, **kwargs): + matplotlib.real_use(*args, **kwargs) + gui, backend = find_gui_and_backend() + enable_gui_function(gui) + + matplotlib.real_use = matplotlib.use + matplotlib.use = patched_use + + +def patch_is_interactive(): + """ Patch matplotlib function 'use' """ + matplotlib = sys.modules['matplotlib'] + + def patched_is_interactive(): + return matplotlib.rcParams['interactive'] + + matplotlib.real_is_interactive = matplotlib.is_interactive + matplotlib.is_interactive = patched_is_interactive + + +def activate_matplotlib(enable_gui_function): + """Set interactive to True for interactive backends. + enable_gui_function - Function which enables gui, should be run in the main thread. + """ + matplotlib = sys.modules['matplotlib'] + gui, backend = find_gui_and_backend() + is_interactive = is_interactive_backend(backend) + if is_interactive: + enable_gui_function(gui) + if not matplotlib.is_interactive(): + sys.stdout.write("Backend %s is interactive backend. Turning interactive mode on.\n" % backend) + matplotlib.interactive(True) + else: + if matplotlib.is_interactive(): + sys.stdout.write("Backend %s is non-interactive backend. Turning interactive mode off.\n" % backend) + matplotlib.interactive(False) + patch_use(enable_gui_function) + patch_is_interactive() + + +def flag_calls(func): + """Wrap a function to detect and flag when it gets called. + + This is a decorator which takes a function and wraps it in a function with + a 'called' attribute. wrapper.called is initialized to False. + + The wrapper.called attribute is set to False right before each call to the + wrapped function, so if the call fails it remains False. After the call + completes, wrapper.called is set to True and the output is returned. + + Testing for truth in wrapper.called allows you to determine if a call to + func() was attempted and succeeded.""" + + # don't wrap twice + if hasattr(func, 'called'): + return func + + def wrapper(*args, **kw): + wrapper.called = False + out = func(*args, **kw) + wrapper.called = True + return out + + wrapper.called = False + wrapper.__doc__ = func.__doc__ + return wrapper + + +def activate_pylab(): + pylab = sys.modules['pylab'] + pylab.show._needmain = False + # We need to detect at runtime whether show() is called by the user. + # For this, we wrap it into a decorator which adds a 'called' flag. + pylab.draw_if_interactive = flag_calls(pylab.draw_if_interactive) + + +def activate_pyplot(): + pyplot = sys.modules['matplotlib.pyplot'] + pyplot.show._needmain = False + # We need to detect at runtime whether show() is called by the user. + # For this, we wrap it into a decorator which adds a 'called' flag. + pyplot.draw_if_interactive = flag_calls(pyplot.draw_if_interactive) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt.py new file mode 100644 index 0000000..222c81b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt.py @@ -0,0 +1,23 @@ +""" A Qt API selector that can be used to switch between PyQt and PySide. + +This uses the ETS 4.0 selection pattern of: +PySide first, PyQt with API v2. second. + +Do not use this if you need PyQt with the old QString/QVariant API. +""" + +import os + +from pydev_ipython.qt_loaders import (load_qt, QT_API_PYSIDE, + QT_API_PYQT, QT_API_PYQT5) + +QT_API = os.environ.get('QT_API', None) +if QT_API not in [QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5, None]: + raise RuntimeError("Invalid Qt API %r, valid values are: %r, %r" % + (QT_API, QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5)) +if QT_API is None: + api_opts = [QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5] +else: + api_opts = [QT_API] + +QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt_for_kernel.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt_for_kernel.py new file mode 100644 index 0000000..d18a218 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt_for_kernel.py @@ -0,0 +1,118 @@ +""" Import Qt in a manner suitable for an IPython kernel. + +This is the import used for the `gui=qt` or `matplotlib=qt` initialization. + +Import Priority: + +if Qt4 has been imported anywhere else: + use that + +if matplotlib has been imported and doesn't support v2 (<= 1.0.1): + use PyQt4 @v1 + +Next, ask ETS' QT_API env variable + +if QT_API not set: + ask matplotlib via rcParams['backend.qt4'] + if it said PyQt: + use PyQt4 @v1 + elif it said PySide: + use PySide + + else: (matplotlib said nothing) + # this is the default path - nobody told us anything + try: + PyQt @v1 + except: + fallback on PySide +else: + use PyQt @v2 or PySide, depending on QT_API + because ETS doesn't work with PyQt @v1. + +""" + +import os +import sys + +from pydev_ipython.version import check_version +from pydev_ipython.qt_loaders import (load_qt, QT_API_PYSIDE, + QT_API_PYQT, QT_API_PYQT_DEFAULT, + loaded_api, QT_API_PYQT5) + +#Constraints placed on an imported matplotlib +def matplotlib_options(mpl): + if mpl is None: + return + + # #PyDev-779: In pysrc/pydev_ipython/qt_for_kernel.py, matplotlib_options should be replaced with latest from ipython + # (i.e.: properly check backend to decide upon qt4/qt5). + + backend = mpl.rcParams.get('backend', None) + if backend == 'Qt4Agg': + mpqt = mpl.rcParams.get('backend.qt4', None) + if mpqt is None: + return None + if mpqt.lower() == 'pyside': + return [QT_API_PYSIDE] + elif mpqt.lower() == 'pyqt4': + return [QT_API_PYQT_DEFAULT] + elif mpqt.lower() == 'pyqt4v2': + return [QT_API_PYQT] + raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" % + mpqt) + + elif backend == 'Qt5Agg': + mpqt = mpl.rcParams.get('backend.qt5', None) + if mpqt is None: + return None + if mpqt.lower() == 'pyqt5': + return [QT_API_PYQT5] + raise ImportError("unhandled value for backend.qt5 from matplotlib: %r" % + mpqt) + + + # Fallback without checking backend (previous code) + mpqt = mpl.rcParams.get('backend.qt4', None) + if mpqt is None: + mpqt = mpl.rcParams.get('backend.qt5', None) + + if mpqt is None: + return None + if mpqt.lower() == 'pyside': + return [QT_API_PYSIDE] + elif mpqt.lower() == 'pyqt4': + return [QT_API_PYQT_DEFAULT] + elif mpqt.lower() == 'pyqt5': + return [QT_API_PYQT5] + raise ImportError("unhandled value for qt backend from matplotlib: %r" % + mpqt) + + +def get_options(): + """Return a list of acceptable QT APIs, in decreasing order of + preference + """ + #already imported Qt somewhere. Use that + loaded = loaded_api() + if loaded is not None: + return [loaded] + + mpl = sys.modules.get('matplotlib', None) + + if mpl is not None and not check_version(mpl.__version__, '1.0.2'): + #1.0.1 only supports PyQt4 v1 + return [QT_API_PYQT_DEFAULT] + + if os.environ.get('QT_API', None) is None: + #no ETS variable. Ask mpl, then use either + return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE, QT_API_PYQT5] + + #ETS variable present. Will fallback to external.qt + return None + +api_opts = get_options() +if api_opts is not None: + QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts) + +else: # use ETS variable + from pydev_ipython.qt import QtCore, QtGui, QtSvg, QT_API diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt_loaders.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt_loaders.py new file mode 100644 index 0000000..2a77b1a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/qt_loaders.py @@ -0,0 +1,281 @@ +""" +This module contains factory functions that attempt +to return Qt submodules from the various python Qt bindings. + +It also protects against double-importing Qt with different +bindings, which is unstable and likely to crash + +This is used primarily by qt and qt_for_kernel, and shouldn't +be accessed directly from the outside +""" +import sys +from functools import partial + +from pydev_ipython.version import check_version + +# Available APIs. +QT_API_PYQT = 'pyqt' +QT_API_PYQTv1 = 'pyqtv1' +QT_API_PYQT_DEFAULT = 'pyqtdefault' # don't set SIP explicitly +QT_API_PYSIDE = 'pyside' +QT_API_PYQT5 = 'pyqt5' + + +class ImportDenier(object): + """Import Hook that will guard against bad Qt imports + once IPython commits to a specific binding + """ + + def __init__(self): + self.__forbidden = set() + + def forbid(self, module_name): + sys.modules.pop(module_name, None) + self.__forbidden.add(module_name) + + def find_module(self, fullname, path=None): + if path: + return + if fullname in self.__forbidden: + return self + + def load_module(self, fullname): + raise ImportError(""" + Importing %s disabled by IPython, which has + already imported an Incompatible QT Binding: %s + """ % (fullname, loaded_api())) + +ID = ImportDenier() +sys.meta_path.append(ID) + + +def commit_api(api): + """Commit to a particular API, and trigger ImportErrors on subsequent + dangerous imports""" + + if api == QT_API_PYSIDE: + ID.forbid('PyQt4') + ID.forbid('PyQt5') + else: + ID.forbid('PySide') + + +def loaded_api(): + """Return which API is loaded, if any + + If this returns anything besides None, + importing any other Qt binding is unsafe. + + Returns + ------- + None, 'pyside', 'pyqt', or 'pyqtv1' + """ + if 'PyQt4.QtCore' in sys.modules: + if qtapi_version() == 2: + return QT_API_PYQT + else: + return QT_API_PYQTv1 + elif 'PySide.QtCore' in sys.modules: + return QT_API_PYSIDE + elif 'PyQt5.QtCore' in sys.modules: + return QT_API_PYQT5 + return None + + +def has_binding(api): + """Safely check for PyQt4 or PySide, without importing + submodules + + Parameters + ---------- + api : str [ 'pyqtv1' | 'pyqt' | 'pyside' | 'pyqtdefault'] + Which module to check for + + Returns + ------- + True if the relevant module appears to be importable + """ + # we can't import an incomplete pyside and pyqt4 + # this will cause a crash in sip (#1431) + # check for complete presence before importing + module_name = {QT_API_PYSIDE: 'PySide', + QT_API_PYQT: 'PyQt4', + QT_API_PYQTv1: 'PyQt4', + QT_API_PYQT_DEFAULT: 'PyQt4', + QT_API_PYQT5: 'PyQt5', + } + module_name = module_name[api] + + import imp + try: + #importing top level PyQt4/PySide module is ok... + mod = __import__(module_name) + #...importing submodules is not + imp.find_module('QtCore', mod.__path__) + imp.find_module('QtGui', mod.__path__) + imp.find_module('QtSvg', mod.__path__) + + #we can also safely check PySide version + if api == QT_API_PYSIDE: + return check_version(mod.__version__, '1.0.3') + else: + return True + except ImportError: + return False + + +def qtapi_version(): + """Return which QString API has been set, if any + + Returns + ------- + The QString API version (1 or 2), or None if not set + """ + try: + import sip + except ImportError: + return + try: + return sip.getapi('QString') + except ValueError: + return + + +def can_import(api): + """Safely query whether an API is importable, without importing it""" + if not has_binding(api): + return False + + current = loaded_api() + if api == QT_API_PYQT_DEFAULT: + return current in [QT_API_PYQT, QT_API_PYQTv1, QT_API_PYQT5, None] + else: + return current in [api, None] + + +def import_pyqt4(version=2): + """ + Import PyQt4 + + Parameters + ---------- + version : 1, 2, or None + Which QString/QVariant API to use. Set to None to use the system + default + + ImportErrors raised within this function are non-recoverable + """ + # The new-style string API (version=2) automatically + # converts QStrings to Unicode Python strings. Also, automatically unpacks + # QVariants to their underlying objects. + import sip + + if version is not None: + sip.setapi('QString', version) + sip.setapi('QVariant', version) + + from PyQt4 import QtGui, QtCore, QtSvg + + if not check_version(QtCore.PYQT_VERSION_STR, '4.7'): + raise ImportError("IPython requires PyQt4 >= 4.7, found %s" % + QtCore.PYQT_VERSION_STR) + + # Alias PyQt-specific functions for PySide compatibility. + QtCore.Signal = QtCore.pyqtSignal + QtCore.Slot = QtCore.pyqtSlot + + # query for the API version (in case version == None) + version = sip.getapi('QString') + api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT + return QtCore, QtGui, QtSvg, api + +def import_pyqt5(): + """ + Import PyQt5 + + ImportErrors raised within this function are non-recoverable + """ + from PyQt5 import QtGui, QtCore, QtSvg + + # Alias PyQt-specific functions for PySide compatibility. + QtCore.Signal = QtCore.pyqtSignal + QtCore.Slot = QtCore.pyqtSlot + + return QtCore, QtGui, QtSvg, QT_API_PYQT5 + + +def import_pyside(): + """ + Import PySide + + ImportErrors raised within this function are non-recoverable + """ + from PySide import QtGui, QtCore, QtSvg # @UnresolvedImport + return QtCore, QtGui, QtSvg, QT_API_PYSIDE + + +def load_qt(api_options): + """ + Attempt to import Qt, given a preference list + of permissible bindings + + It is safe to call this function multiple times. + + Parameters + ---------- + api_options: List of strings + The order of APIs to try. Valid items are 'pyside', + 'pyqt', and 'pyqtv1' + + Returns + ------- + + A tuple of QtCore, QtGui, QtSvg, QT_API + The first three are the Qt modules. The last is the + string indicating which module was loaded. + + Raises + ------ + ImportError, if it isn't possible to import any requested + bindings (either becaues they aren't installed, or because + an incompatible library has already been installed) + """ + loaders = {QT_API_PYSIDE: import_pyside, + QT_API_PYQT: import_pyqt4, + QT_API_PYQTv1: partial(import_pyqt4, version=1), + QT_API_PYQT_DEFAULT: partial(import_pyqt4, version=None), + QT_API_PYQT5: import_pyqt5, + } + + for api in api_options: + + if api not in loaders: + raise RuntimeError( + "Invalid Qt API %r, valid values are: %r, %r, %r, %r, %r" % + (api, QT_API_PYSIDE, QT_API_PYQT, + QT_API_PYQTv1, QT_API_PYQT_DEFAULT, QT_API_PYQT5)) + + if not can_import(api): + continue + + #cannot safely recover from an ImportError during this + result = loaders[api]() + api = result[-1] # changed if api = QT_API_PYQT_DEFAULT + commit_api(api) + return result + else: + raise ImportError(""" + Could not load requested Qt binding. Please ensure that + PyQt4 >= 4.7 or PySide >= 1.0.3 is available, + and only one is imported per session. + + Currently-imported Qt library: %r + PyQt4 installed: %s + PyQt5 installed: %s + PySide >= 1.0.3 installed: %s + Tried to load: %r + """ % (loaded_api(), + has_binding(QT_API_PYQT), + has_binding(QT_API_PYQT5), + has_binding(QT_API_PYSIDE), + api_options)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/version.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/version.py new file mode 100644 index 0000000..1de0047 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_ipython/version.py @@ -0,0 +1,36 @@ +# encoding: utf-8 +""" +Utilities for version comparison + +It is a bit ridiculous that we need these. +""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2013 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from distutils.version import LooseVersion + +#----------------------------------------------------------------------------- +# Code +#----------------------------------------------------------------------------- + +def check_version(v, check): + """check version string v >= check + + If dev/prerelease tags result in TypeError for string-number comparison, + it is assumed that the dependency is satisfied. + Users on dev branches are responsible for keeping their own packages up to date. + """ + try: + return LooseVersion(v) >= LooseVersion(check) + except TypeError: + return True + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_pysrc.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_pysrc.py new file mode 100644 index 0000000..b9ed49e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_pysrc.py @@ -0,0 +1 @@ +'''An empty file in pysrc that can be imported (from sitecustomize) to find the location of pysrc''' \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_run_in_console.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_run_in_console.py new file mode 100644 index 0000000..e7d0236 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_run_in_console.py @@ -0,0 +1,156 @@ +''' +Entry point module to run a file in the interactive console. +''' +import os +import sys +import traceback +from pydevconsole import InterpreterInterface, process_exec_queue, start_console_server, init_mpl_in_console +from _pydev_imps._pydev_saved_modules import threading, _queue + +from _pydev_bundle import pydev_imports +from _pydevd_bundle.pydevd_utils import save_main_module +from _pydev_bundle.pydev_console_utils import StdIn +from pydevd_file_utils import get_fullname + + +def run_file(file, globals=None, locals=None, is_module=False): + module_name = None + entry_point_fn = None + if is_module: + file, _, entry_point_fn = file.partition(':') + module_name = file + filename = get_fullname(file) + if filename is None: + sys.stderr.write("No module named %s\n" % file) + return + else: + file = filename + + if os.path.isdir(file): + new_target = os.path.join(file, '__main__.py') + if os.path.isfile(new_target): + file = new_target + + if globals is None: + m = save_main_module(file, 'pydev_run_in_console') + + globals = m.__dict__ + try: + globals['__builtins__'] = __builtins__ + except NameError: + pass # Not there on Jython... + + if locals is None: + locals = globals + + if not is_module: + sys.path.insert(0, os.path.split(file)[0]) + + print('Running %s' % file) + try: + if not is_module: + pydev_imports.execfile(file, globals, locals) # execute the script + else: + # treat ':' as a seperator between module and entry point function + # if there is no entry point we run we same as with -m switch. Otherwise we perform + # an import and execute the entry point + if entry_point_fn: + mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=globals, locals=locals) + func = getattr(mod, entry_point_fn) + func() + else: + # Run with the -m switch + import runpy + if hasattr(runpy, '_run_module_as_main'): + runpy._run_module_as_main(module_name) + else: + runpy.run_module(module_name) + except: + traceback.print_exc() + + return globals + + +def skip_successful_exit(*args): + """ System exit in file shouldn't kill interpreter (i.e. in `timeit`)""" + if len(args) == 1 and args[0] in (0, None): + pass + else: + raise SystemExit(*args) + + +def process_args(argv): + setup_args = {'file': '', 'module': False} + + setup_args['port'] = argv[1] + del argv[1] + setup_args['client_port'] = argv[1] + del argv[1] + + module_flag = "--module" + if module_flag in argv: + i = argv.index(module_flag) + if i != -1: + setup_args['module'] = True + setup_args['file'] = argv[i + 1] + del sys.argv[i] + else: + setup_args['file'] = argv[1] + + del argv[0] + + return setup_args + + +#======================================================================================================================= +# main +#======================================================================================================================= +if __name__ == '__main__': + setup = process_args(sys.argv) + + port = setup['port'] + client_port = setup['client_port'] + file = setup['file'] + is_module = setup['module'] + + from _pydev_bundle import pydev_localhost + + if int(port) == 0 and int(client_port) == 0: + (h, p) = pydev_localhost.get_socket_name() + client_port = p + + host = pydev_localhost.get_localhost() + + #replace exit (see comments on method) + #note that this does not work in jython!!! (sys method can't be replaced). + sys.exit = skip_successful_exit + + connect_status_queue = _queue.Queue() + interpreter = InterpreterInterface(host, int(client_port), threading.currentThread(), connect_status_queue=connect_status_queue) + + server_thread = threading.Thread(target=start_console_server, + name='ServerThread', + args=(host, int(port), interpreter)) + server_thread.setDaemon(True) + server_thread.start() + + sys.stdin = StdIn(interpreter, host, client_port, sys.stdin) + + init_mpl_in_console(interpreter) + + try: + success = connect_status_queue.get(True, 60) + if not success: + raise ValueError() + except: + sys.stderr.write("Console server didn't start\n") + sys.stderr.flush() + sys.exit(1) + + globals = run_file(file, None, None, is_module) + + interpreter.get_namespace().update(globals) + + interpreter.ShowConsole() + + process_exec_queue(interpreter) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_sitecustomize/__not_in_default_pythonpath.txt b/adapter/python/ptvsd/_vendored/pydevd/pydev_sitecustomize/__not_in_default_pythonpath.txt new file mode 100644 index 0000000..29cdc5b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_sitecustomize/__not_in_default_pythonpath.txt @@ -0,0 +1 @@ +(no __init__.py file) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydev_sitecustomize/sitecustomize.py b/adapter/python/ptvsd/_vendored/pydevd/pydev_sitecustomize/sitecustomize.py new file mode 100644 index 0000000..8b51eba --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydev_sitecustomize/sitecustomize.py @@ -0,0 +1,237 @@ +''' + This module will: + - change the input() and raw_input() commands to change \r\n or \r into \n + - execute the user site customize -- if available + - change raw_input() and input() to also remove any trailing \r + + Up to PyDev 3.4 it also was setting the default encoding, but it was removed because of differences when + running from a shell (i.e.: now we just set the PYTHONIOENCODING related to that -- which is properly + treated on Py 2.7 onwards). +''' +DEBUG = 0 #0 or 1 because of jython + +import sys +encoding = None + +IS_PYTHON_3_ONWARDS = 0 + +try: + IS_PYTHON_3_ONWARDS = sys.version_info[0] >= 3 +except: + #That's OK, not all versions of python have sys.version_info + if DEBUG: + import traceback;traceback.print_exc() #@Reimport + +#----------------------------------------------------------------------------------------------------------------------- +#Line buffering +if IS_PYTHON_3_ONWARDS: + #Python 3 has a bug (http://bugs.python.org/issue4705) in which -u doesn't properly make output/input unbuffered + #so, we need to enable that ourselves here. + try: + sys.stdout._line_buffering = True + except: + pass + try: + sys.stderr._line_buffering = True + except: + pass + try: + sys.stdin._line_buffering = True + except: + pass + + +try: + import org.python.core.PyDictionary #@UnresolvedImport @UnusedImport -- just to check if it could be valid + def dict_contains(d, key): + return d.has_key(key) +except: + try: + #Py3k does not have has_key anymore, and older versions don't have __contains__ + dict_contains = dict.__contains__ + except: + try: + dict_contains = dict.has_key + except NameError: + def dict_contains(d, key): + return d.has_key(key) + +def install_breakpointhook(): + def custom_sitecustomize_breakpointhook(*args, **kwargs): + import os + hookname = os.getenv('PYTHONBREAKPOINT') + if ( + hookname is not None + and len(hookname) > 0 + and hasattr(sys, '__breakpointhook__') + and sys.__breakpointhook__ != custom_sitecustomize_breakpointhook + ): + sys.__breakpointhook__(*args, **kwargs) + else: + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + import pydevd + kwargs.setdefault('stop_at_frame', sys._getframe().f_back) + pydevd.settrace(*args, **kwargs) + + if sys.version_info[0:2] >= (3, 7): + # There are some choices on how to provide the breakpoint hook. Namely, we can provide a + # PYTHONBREAKPOINT which provides the import path for a method to be executed or we + # can override sys.breakpointhook. + # pydevd overrides sys.breakpointhook instead of providing an environment variable because + # it's possible that the debugger starts the user program but is not available in the + # PYTHONPATH (and would thus fail to be imported if PYTHONBREAKPOINT was set to pydevd.settrace). + # Note that the implementation still takes PYTHONBREAKPOINT in account (so, if it was provided + # by someone else, it'd still work). + sys.breakpointhook = custom_sitecustomize_breakpointhook + else: + if sys.version_info[0] >= 3: + import builtins as __builtin__ # Py3 + else: + import __builtin__ + + # In older versions, breakpoint() isn't really available, so, install the hook directly + # in the builtins. + __builtin__.breakpoint = custom_sitecustomize_breakpointhook + sys.__breakpointhook__ = custom_sitecustomize_breakpointhook + +# Install the breakpoint hook at import time. +install_breakpointhook() + +#----------------------------------------------------------------------------------------------------------------------- +#now that we've finished the needed pydev sitecustomize, let's run the default one (if available) + +#Ok, some weirdness going on in Python 3k: when removing this module from the sys.module to import the 'real' +#sitecustomize, all the variables in this scope become None (as if it was garbage-collected), so, the the reference +#below is now being kept to create a cyclic reference so that it neven dies) +__pydev_sitecustomize_module__ = sys.modules.get('sitecustomize') #A ref to this module + + +#remove the pydev site customize (and the pythonpath for it) +paths_removed = [] +try: + for c in sys.path[:]: + #Pydev controls the whole classpath in Jython already, so, we don't want a a duplicate for + #what we've already added there (this is needed to support Jython 2.5b1 onwards -- otherwise, as + #we added the sitecustomize to the pythonpath and to the classpath, we'd have to remove it from the + #classpath too -- and I don't think there's a way to do that... or not?) + if c.find('pydev_sitecustomize') != -1 or c == '__classpath__' or c == '__pyclasspath__' or \ + c == '__classpath__/' or c == '__pyclasspath__/' or c == '__classpath__\\' or c == '__pyclasspath__\\': + sys.path.remove(c) + if c.find('pydev_sitecustomize') == -1: + #We'll re-add any paths removed but the pydev_sitecustomize we added from pydev. + paths_removed.append(c) + + if dict_contains(sys.modules, 'sitecustomize'): + del sys.modules['sitecustomize'] #this module +except: + #print the error... should never happen (so, always show, and not only on debug)! + import traceback;traceback.print_exc() #@Reimport +else: + #Now, execute the default sitecustomize + try: + import sitecustomize #@UnusedImport + sitecustomize.__pydev_sitecustomize_module__ = __pydev_sitecustomize_module__ + except: + pass + + if not dict_contains(sys.modules, 'sitecustomize'): + #If there was no sitecustomize, re-add the pydev sitecustomize (pypy gives a KeyError if it's not there) + sys.modules['sitecustomize'] = __pydev_sitecustomize_module__ + + try: + if paths_removed: + if sys is None: + import sys + if sys is not None: + #And after executing the default sitecustomize, restore the paths (if we didn't remove it before, + #the import sitecustomize would recurse). + sys.path.extend(paths_removed) + except: + #print the error... should never happen (so, always show, and not only on debug)! + import traceback;traceback.print_exc() #@Reimport + + + + +if sys.version_info[0] < 3: + try: + #Redefine input and raw_input only after the original sitecustomize was executed + #(because otherwise, the original raw_input and input would still not be defined) + import __builtin__ + original_raw_input = __builtin__.raw_input + original_input = __builtin__.input + + + def raw_input(prompt=''): + #the original raw_input would only remove a trailing \n, so, at + #this point if we had a \r\n the \r would remain (which is valid for eclipse) + #so, let's remove the remaining \r which python didn't expect. + ret = original_raw_input(prompt) + + if ret.endswith('\r'): + return ret[:-1] + + return ret + raw_input.__doc__ = original_raw_input.__doc__ + + def input(prompt=''): + #input must also be rebinded for using the new raw_input defined + return eval(raw_input(prompt)) + input.__doc__ = original_input.__doc__ + + + __builtin__.raw_input = raw_input + __builtin__.input = input + + except: + #Don't report errors at this stage + if DEBUG: + import traceback;traceback.print_exc() #@Reimport + +else: + try: + import builtins #Python 3.0 does not have the __builtin__ module @UnresolvedImport + original_input = builtins.input + def input(prompt=''): + #the original input would only remove a trailing \n, so, at + #this point if we had a \r\n the \r would remain (which is valid for eclipse) + #so, let's remove the remaining \r which python didn't expect. + ret = original_input(prompt) + + if ret.endswith('\r'): + return ret[:-1] + + return ret + input.__doc__ = original_input.__doc__ + builtins.input = input + except: + #Don't report errors at this stage + if DEBUG: + import traceback;traceback.print_exc() #@Reimport + + + +try: + #The original getpass doesn't work from the eclipse console, so, let's put a replacement + #here (note that it'll not go into echo mode in the console, so, what' the user writes + #will actually be seen) + #Note: same thing from the fix_getpass module -- but we don't want to import it in this + #custom sitecustomize. + def fix_get_pass(): + try: + import getpass + except ImportError: + return #If we can't import it, we can't fix it + import warnings + fallback = getattr(getpass, 'fallback_getpass', None) # >= 2.6 + if not fallback: + fallback = getpass.default_getpass # <= 2.5 + getpass.getpass = fallback + if hasattr(getpass, 'GetPassWarning'): + warnings.simplefilter("ignore", category=getpass.GetPassWarning) + fix_get_pass() + +except: + #Don't report errors at this stage + if DEBUG: + import traceback;traceback.print_exc() #@Reimport diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevconsole.py b/adapter/python/ptvsd/_vendored/pydevd/pydevconsole.py new file mode 100644 index 0000000..0bdebdf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevconsole.py @@ -0,0 +1,620 @@ +''' +Entry point module to start the interactive console. +''' +from _pydev_imps._pydev_saved_modules import thread +from _pydevd_bundle.pydevd_constants import IS_JYTHON, dict_iter_items +start_new_thread = thread.start_new_thread + +try: + from code import InteractiveConsole +except ImportError: + from _pydevd_bundle.pydevconsole_code_for_ironpython import InteractiveConsole + +from code import compile_command +from code import InteractiveInterpreter + +import os +import sys + +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle.pydevd_constants import INTERACTIVE_MODE_AVAILABLE, dict_keys + +import traceback +from _pydev_bundle import pydev_log + +from _pydevd_bundle import pydevd_vars, pydevd_save_locals + +from _pydev_bundle.pydev_imports import Exec, _queue + +try: + import __builtin__ +except: + import builtins as __builtin__ # @UnresolvedImport + +from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface, BaseStdIn +from _pydev_bundle.pydev_console_utils import CodeFragment + +IS_PYTHON_3_ONWARDS = sys.version_info[0] >= 3 +IS_PY24 = sys.version_info[0] == 2 and sys.version_info[1] == 4 + + +class Command: + + def __init__(self, interpreter, code_fragment): + """ + :type code_fragment: CodeFragment + :type interpreter: InteractiveConsole + """ + self.interpreter = interpreter + self.code_fragment = code_fragment + self.more = None + + def symbol_for_fragment(code_fragment): + if code_fragment.is_single_line: + symbol = 'single' + else: + if IS_JYTHON: + symbol = 'single' # Jython doesn't support exec + else: + symbol = 'exec' + return symbol + + symbol_for_fragment = staticmethod(symbol_for_fragment) + + def run(self): + text = self.code_fragment.text + symbol = self.symbol_for_fragment(self.code_fragment) + + self.more = self.interpreter.runsource(text, '', symbol) + + +try: + try: + execfile # Not in Py3k + except NameError: + from _pydev_bundle.pydev_imports import execfile + + __builtin__.execfile = execfile +except: + pass + +# Pull in runfile, the interface to UMD that wraps execfile +from _pydev_bundle.pydev_umd import runfile, _set_globals_function +if sys.version_info[0] >= 3: + import builtins # @UnresolvedImport + builtins.runfile = runfile +else: + import __builtin__ + __builtin__.runfile = runfile + + +#======================================================================================================================= +# InterpreterInterface +#======================================================================================================================= +class InterpreterInterface(BaseInterpreterInterface): + ''' + The methods in this class should be registered in the xml-rpc server. + ''' + + def __init__(self, host, client_port, mainThread, connect_status_queue=None): + BaseInterpreterInterface.__init__(self, mainThread, connect_status_queue) + self.client_port = client_port + self.host = host + self.namespace = {} + self.interpreter = InteractiveConsole(self.namespace) + self._input_error_printed = False + + def do_add_exec(self, codeFragment): + command = Command(self.interpreter, codeFragment) + command.run() + return command.more + + def get_namespace(self): + return self.namespace + + def getCompletions(self, text, act_tok): + try: + from _pydev_bundle._pydev_completer import Completer + + completer = Completer(self.namespace, None) + return completer.complete(act_tok) + except: + pydev_log.exception() + return [] + + def close(self): + sys.exit(0) + + def get_greeting_msg(self): + return 'PyDev console: starting.\n' + + +class _ProcessExecQueueHelper: + _debug_hook = None + _return_control_osc = False + + +def set_debug_hook(debug_hook): + _ProcessExecQueueHelper._debug_hook = debug_hook + + +def activate_mpl_if_already_imported(interpreter): + if interpreter.mpl_modules_for_patching: + for module in dict_keys(interpreter.mpl_modules_for_patching): + if module in sys.modules: + activate_function = interpreter.mpl_modules_for_patching.pop(module) + activate_function() + + +def init_set_return_control_back(interpreter): + from pydev_ipython.inputhook import set_return_control_callback + + def return_control(): + ''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find + out if they should cede control and return ''' + if _ProcessExecQueueHelper._debug_hook: + # Some of the input hooks check return control without doing + # a single operation, so we don't return True on every + # call when the debug hook is in place to allow the GUI to run + # XXX: Eventually the inputhook code will have diverged enough + # from the IPython source that it will be worthwhile rewriting + # it rather than pretending to maintain the old API + _ProcessExecQueueHelper._return_control_osc = not _ProcessExecQueueHelper._return_control_osc + if _ProcessExecQueueHelper._return_control_osc: + return True + + if not interpreter.exec_queue.empty(): + return True + return False + + set_return_control_callback(return_control) + + +def init_mpl_in_console(interpreter): + init_set_return_control_back(interpreter) + + if not INTERACTIVE_MODE_AVAILABLE: + return + + activate_mpl_if_already_imported(interpreter) + from _pydev_bundle.pydev_import_hook import import_hook_manager + for mod in dict_keys(interpreter.mpl_modules_for_patching): + import_hook_manager.add_module_name(mod, interpreter.mpl_modules_for_patching.pop(mod)) + + +if sys.platform != 'win32': + + if not hasattr(os, 'kill'): # Jython may not have it. + + def pid_exists(pid): + return True + + else: + + def pid_exists(pid): + # Note that this function in the face of errors will conservatively consider that + # the pid is still running (because we'll exit the current process when it's + # no longer running, so, we need to be 100% sure it actually exited). + + import errno + if pid == 0: + # According to "man 2 kill" PID 0 has a special meaning: + # it refers to <> so we don't want to go any further. + # If we get here it means this UNIX platform *does* have + # a process with id 0. + return True + try: + os.kill(pid, 0) + except OSError as err: + if err.errno == errno.ESRCH: + # ESRCH == No such process + return False + elif err.errno == errno.EPERM: + # EPERM clearly means there's a process to deny access to + return True + else: + # According to "man 2 kill" possible error values are + # (EINVAL, EPERM, ESRCH) therefore we should never get + # here. If we do, although it's an error, consider it + # exists (see first comment in this function). + return True + else: + return True + +else: + + def pid_exists(pid): + # Note that this function in the face of errors will conservatively consider that + # the pid is still running (because we'll exit the current process when it's + # no longer running, so, we need to be 100% sure it actually exited). + import ctypes + kernel32 = ctypes.windll.kernel32 + + PROCESS_QUERY_INFORMATION = 0x0400 + PROCESS_QUERY_LIMITED_INFORMATION = 0x1000 + ERROR_INVALID_PARAMETER = 0x57 + STILL_ACTIVE = 259 + + process = kernel32.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, 0, pid) + if not process: + err = kernel32.GetLastError() + if err == ERROR_INVALID_PARAMETER: + # Means it doesn't exist (pid parameter is wrong). + return False + + # There was some unexpected error (such as access denied), so + # consider it exists (although it could be something else, but we don't want + # to raise any errors -- so, just consider it exists). + return True + + try: + zero = ctypes.c_int(0) + exit_code = ctypes.pointer(zero) + + exit_code_suceeded = kernel32.GetExitCodeProcess(process, exit_code) + if not exit_code_suceeded: + # There was some unexpected error (such as access denied), so + # consider it exists (although it could be something else, but we don't want + # to raise any errors -- so, just consider it exists). + return True + + elif bool(exit_code.contents.value) and int(exit_code.contents.value) != STILL_ACTIVE: + return False + finally: + kernel32.CloseHandle(process) + + return True + + +def process_exec_queue(interpreter): + init_mpl_in_console(interpreter) + from pydev_ipython.inputhook import get_inputhook + try: + kill_if_pid_not_alive = int(os.environ.get('PYDEV_ECLIPSE_PID', '-1')) + except: + kill_if_pid_not_alive = -1 + + while 1: + if kill_if_pid_not_alive != -1: + if not pid_exists(kill_if_pid_not_alive): + exit() + + # Running the request may have changed the inputhook in use + inputhook = get_inputhook() + + if _ProcessExecQueueHelper._debug_hook: + _ProcessExecQueueHelper._debug_hook() + + if inputhook: + try: + # Note: it'll block here until return_control returns True. + inputhook() + except: + pydev_log.exception() + try: + try: + code_fragment = interpreter.exec_queue.get(block=True, timeout=1 / 20.) # 20 calls/second + except _queue.Empty: + continue + + if callable(code_fragment): + # It can be a callable (i.e.: something that must run in the main + # thread can be put in the queue for later execution). + code_fragment() + else: + more = interpreter.add_exec(code_fragment) + except KeyboardInterrupt: + interpreter.buffer = None + continue + except SystemExit: + raise + except: + pydev_log.exception('Error processing queue on pydevconsole.') + exit() + + +if 'IPYTHONENABLE' in os.environ: + IPYTHON = os.environ['IPYTHONENABLE'] == 'True' +else: + # By default, don't use IPython because occasionally changes + # in IPython break pydevd. + IPYTHON = False + +try: + try: + exitfunc = sys.exitfunc + except AttributeError: + exitfunc = None + + if IPYTHON: + from _pydev_bundle.pydev_ipython_console import InterpreterInterface + if exitfunc is not None: + sys.exitfunc = exitfunc + else: + try: + delattr(sys, 'exitfunc') + except: + pass +except: + IPYTHON = False + pass + + +#======================================================================================================================= +# _DoExit +#======================================================================================================================= +def do_exit(*args): + ''' + We have to override the exit because calling sys.exit will only actually exit the main thread, + and as we're in a Xml-rpc server, that won't work. + ''' + + try: + import java.lang.System + + java.lang.System.exit(1) + except ImportError: + if len(args) == 1: + os._exit(args[0]) + else: + os._exit(0) + + +#======================================================================================================================= +# start_console_server +#======================================================================================================================= +def start_console_server(host, port, interpreter): + try: + if port == 0: + host = '' + + # I.e.: supporting the internal Jython version in PyDev to create a Jython interactive console inside Eclipse. + from _pydev_bundle.pydev_imports import SimpleXMLRPCServer as XMLRPCServer # @Reimport + + try: + if IS_PY24: + server = XMLRPCServer((host, port), logRequests=False) + else: + server = XMLRPCServer((host, port), logRequests=False, allow_none=True) + + except: + sys.stderr.write('Error starting server with host: "%s", port: "%s", client_port: "%s"\n' % (host, port, interpreter.client_port)) + sys.stderr.flush() + raise + + # Tell UMD the proper default namespace + _set_globals_function(interpreter.get_namespace) + + server.register_function(interpreter.execLine) + server.register_function(interpreter.execMultipleLines) + server.register_function(interpreter.getCompletions) + server.register_function(interpreter.getFrame) + server.register_function(interpreter.getVariable) + server.register_function(interpreter.changeVariable) + server.register_function(interpreter.getDescription) + server.register_function(interpreter.close) + server.register_function(interpreter.interrupt) + server.register_function(interpreter.handshake) + server.register_function(interpreter.connectToDebugger) + server.register_function(interpreter.hello) + server.register_function(interpreter.getArray) + server.register_function(interpreter.evaluate) + server.register_function(interpreter.ShowConsole) + server.register_function(interpreter.loadFullValue) + + # Functions for GUI main loop integration + server.register_function(interpreter.enableGui) + + if port == 0: + (h, port) = server.socket.getsockname() + + print(port) + print(interpreter.client_port) + + while True: + try: + server.serve_forever() + except: + # Ugly code to be py2/3 compatible + # https://sw-brainwy.rhcloud.com/tracker/PyDev/534: + # Unhandled "interrupted system call" error in the pydevconsol.py + e = sys.exc_info()[1] + retry = False + try: + retry = e.args[0] == 4 # errno.EINTR + except: + pass + if not retry: + raise + # Otherwise, keep on going + return server + except: + pydev_log.exception() + # Notify about error to avoid long waiting + connection_queue = interpreter.get_connect_status_queue() + if connection_queue is not None: + connection_queue.put(False) + + +def start_server(host, port, client_port): + # replace exit (see comments on method) + # note that this does not work in jython!!! (sys method can't be replaced). + sys.exit = do_exit + + interpreter = InterpreterInterface(host, client_port, threading.currentThread()) + + start_new_thread(start_console_server, (host, port, interpreter)) + + process_exec_queue(interpreter) + + +def get_ipython_hidden_vars(): + if IPYTHON and hasattr(__builtin__, 'interpreter'): + interpreter = get_interpreter() + return interpreter.get_ipython_hidden_vars_dict() + + +def get_interpreter(): + try: + interpreterInterface = getattr(__builtin__, 'interpreter') + except AttributeError: + interpreterInterface = InterpreterInterface(None, None, threading.currentThread()) + __builtin__.interpreter = interpreterInterface + sys.stderr.write(interpreterInterface.get_greeting_msg()) + sys.stderr.flush() + + return interpreterInterface + + +def get_completions(text, token, globals, locals): + interpreterInterface = get_interpreter() + + interpreterInterface.interpreter.update(globals, locals) + + return interpreterInterface.getCompletions(text, token) + +#=============================================================================== +# Debugger integration +#=============================================================================== + + +def exec_code(code, globals, locals, debugger): + interpreterInterface = get_interpreter() + interpreterInterface.interpreter.update(globals, locals) + + res = interpreterInterface.need_more(code) + + if res: + return True + + interpreterInterface.add_exec(code, debugger) + + return False + + +class ConsoleWriter(InteractiveInterpreter): + skip = 0 + + def __init__(self, locals=None): + InteractiveInterpreter.__init__(self, locals) + + def write(self, data): + # if (data.find("global_vars") == -1 and data.find("pydevd") == -1): + if self.skip > 0: + self.skip -= 1 + else: + if data == "Traceback (most recent call last):\n": + self.skip = 1 + sys.stderr.write(data) + + def showsyntaxerror(self, filename=None): + """Display the syntax error that just occurred.""" + # Override for avoid using sys.excepthook PY-12600 + type, value, tb = sys.exc_info() + sys.last_type = type + sys.last_value = value + sys.last_traceback = tb + if filename and type is SyntaxError: + # Work hard to stuff the correct filename in the exception + try: + msg, (dummy_filename, lineno, offset, line) = value.args + except ValueError: + # Not the format we expect; leave it alone + pass + else: + # Stuff in the right filename + value = SyntaxError(msg, (filename, lineno, offset, line)) + sys.last_value = value + list = traceback.format_exception_only(type, value) + sys.stderr.write(''.join(list)) + + def showtraceback(self, *args, **kwargs): + """Display the exception that just occurred.""" + # Override for avoid using sys.excepthook PY-12600 + try: + type, value, tb = sys.exc_info() + sys.last_type = type + sys.last_value = value + sys.last_traceback = tb + tblist = traceback.extract_tb(tb) + del tblist[:1] + lines = traceback.format_list(tblist) + if lines: + lines.insert(0, "Traceback (most recent call last):\n") + lines.extend(traceback.format_exception_only(type, value)) + finally: + tblist = tb = None + sys.stderr.write(''.join(lines)) + + +def console_exec(thread_id, frame_id, expression, dbg): + """returns 'False' in case expression is partially correct + """ + frame = dbg.find_frame(thread_id, frame_id) + + is_multiline = expression.count('@LINE@') > 1 + expression = str(expression.replace('@LINE@', '\n')) + + # Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329 + # (Names not resolved in generator expression in method) + # See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html + updated_globals = {} + updated_globals.update(frame.f_globals) + updated_globals.update(frame.f_locals) # locals later because it has precedence over the actual globals + + if IPYTHON: + need_more = exec_code(CodeFragment(expression), updated_globals, frame.f_locals, dbg) + if not need_more: + pydevd_save_locals.save_locals(frame) + return need_more + + interpreter = ConsoleWriter() + + if not is_multiline: + try: + code = compile_command(expression) + except (OverflowError, SyntaxError, ValueError): + # Case 1 + interpreter.showsyntaxerror() + return False + if code is None: + # Case 2 + return True + else: + code = expression + + # Case 3 + + try: + Exec(code, updated_globals, frame.f_locals) + + except SystemExit: + raise + except: + interpreter.showtraceback() + else: + pydevd_save_locals.save_locals(frame) + return False + + +#======================================================================================================================= +# main +#======================================================================================================================= +if __name__ == '__main__': + # Important: don't use this module directly as the __main__ module, rather, import itself as pydevconsole + # so that we don't get multiple pydevconsole modules if it's executed directly (otherwise we'd have multiple + # representations of its classes). + # See: https://sw-brainwy.rhcloud.com/tracker/PyDev/446: + # 'Variables' and 'Expressions' views stopped working when debugging interactive console + import pydevconsole + sys.stdin = pydevconsole.BaseStdIn(sys.stdin) + port, client_port = sys.argv[1:3] + from _pydev_bundle import pydev_localhost + + if int(port) == 0 and int(client_port) == 0: + (h, p) = pydev_localhost.get_socket_name() + + client_port = p + + pydevconsole.start_server(pydev_localhost.get_localhost(), int(port), int(client_port)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd.py new file mode 100644 index 0000000..dc7616a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd.py @@ -0,0 +1,2690 @@ +''' +Entry point module (keep at root): + +This module starts the debugger. +''' +import sys # @NoMove +if sys.version_info[:2] < (2, 6): + raise RuntimeError('The PyDev.Debugger requires Python 2.6 onwards to be run. If you need to use an older Python version, use an older version of the debugger.') + +import atexit +from collections import defaultdict +from contextlib import contextmanager +from functools import partial +import itertools +import os +import traceback +import weakref +import getpass as getpass_mod +import functools + +from _pydev_bundle import pydev_imports, pydev_log +from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding +from _pydev_bundle.pydev_is_thread_alive import is_thread_alive +from _pydev_bundle.pydev_override import overrides +from _pydev_imps._pydev_saved_modules import thread +from _pydev_imps._pydev_saved_modules import threading +from _pydev_imps._pydev_saved_modules import time +from _pydevd_bundle import pydevd_extension_utils +from _pydevd_bundle.pydevd_filtering import FilesFiltering +from _pydevd_bundle import pydevd_io, pydevd_vm_type +from _pydevd_bundle import pydevd_utils +from _pydev_bundle.pydev_console_utils import DebugConsoleStdIn +from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info +from _pydevd_bundle.pydevd_breakpoints import ExceptionBreakpoint, get_exception_breakpoint +from _pydevd_bundle.pydevd_comm_constants import (CMD_THREAD_SUSPEND, CMD_STEP_INTO, CMD_SET_BREAK, + CMD_STEP_INTO_MY_CODE, CMD_STEP_OVER, CMD_SMART_STEP_INTO, CMD_RUN_TO_LINE, + CMD_SET_NEXT_STATEMENT, CMD_STEP_RETURN, CMD_ADD_EXCEPTION_BREAK, CMD_STEP_RETURN_MY_CODE, + CMD_STEP_OVER_MY_CODE) +from _pydevd_bundle.pydevd_constants import (IS_JYTH_LESS25, get_thread_id, get_current_thread_id, + dict_keys, dict_iter_items, DebugInfoHolder, PYTHON_SUSPEND, STATE_SUSPEND, STATE_RUN, get_frame, + clear_cached_thread_id, INTERACTIVE_MODE_AVAILABLE, SHOW_DEBUG_INFO_ENV, IS_PY34_OR_GREATER, IS_PY2, NULL, + NO_FTRACE, IS_IRONPYTHON, JSON_PROTOCOL, IS_CPYTHON, USE_CUSTOM_SYS_CURRENT_FRAMES_MAP, call_only_once) +from _pydevd_bundle.pydevd_defaults import PydevdCustomization +from _pydevd_bundle.pydevd_custom_frames import CustomFramesContainer, custom_frames_container_init +from _pydevd_bundle.pydevd_dont_trace_files import DONT_TRACE, PYDEV_FILE, LIB_FILE +from _pydevd_bundle.pydevd_extension_api import DebuggerEventHandler +from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, remove_exception_from_frame +from _pydevd_bundle.pydevd_kill_all_pydevd_threads import kill_all_pydev_threads +from _pydevd_bundle.pydevd_net_command_factory_xml import NetCommandFactory +from _pydevd_bundle.pydevd_trace_dispatch import ( + trace_dispatch as _trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func) +from _pydevd_bundle.pydevd_utils import save_main_module, is_current_thread_main_thread +from _pydevd_frame_eval.pydevd_frame_eval_main import ( + frame_eval_func, dummy_trace_dispatch) +import pydev_ipython # @UnusedImport +from _pydevd_bundle.pydevd_source_mapping import SourceMapping +from pydevd_concurrency_analyser.pydevd_concurrency_logger import ThreadingLogger, AsyncioLogger, send_message, cur_time +from pydevd_concurrency_analyser.pydevd_thread_wrappers import wrap_threads +from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame, NORM_PATHS_AND_BASE_CONTAINER, get_abs_path_real_path_and_base_from_file +from pydevd_file_utils import get_fullname, rPath, get_package_dir +import pydevd_tracing +from _pydevd_bundle.pydevd_comm import (InternalThreadCommand, InternalThreadCommandForAnyThread, + create_server_socket) +from _pydevd_bundle.pydevd_comm import(InternalConsoleExec, + PyDBDaemonThread, _queue, ReaderThread, GetGlobalDebugger, get_global_debugger, + set_global_debugger, WriterThread, + start_client, start_server, InternalGetBreakpointException, InternalSendCurrExceptionTrace, + InternalSendCurrExceptionTraceProceeded, run_as_pydevd_daemon_thread) + +from _pydevd_bundle.pydevd_breakpoints import stop_on_unhandled_exception +from _pydevd_bundle.pydevd_collect_try_except_info import collect_try_except_info +from _pydevd_bundle.pydevd_suspended_frames import SuspendedFramesManager +from socket import SHUT_RDWR +from _pydevd_bundle.pydevd_api import PyDevdAPI + +if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + from _pydevd_bundle.pydevd_additional_thread_info_regular import _tid_to_last_frame + +__version_info__ = (1, 3, 3) +__version_info_str__ = [] +for v in __version_info__: + __version_info_str__.append(str(v)) + +__version__ = '.'.join(__version_info_str__) + +# IMPORTANT: pydevd_constants must be the 1st thing defined because it'll keep a reference to the original sys._getframe + + +def install_breakpointhook(pydevd_breakpointhook=None): + if pydevd_breakpointhook is None: + + def pydevd_breakpointhook(*args, **kwargs): + hookname = os.getenv('PYTHONBREAKPOINT') + if ( + hookname is not None + and len(hookname) > 0 + and hasattr(sys, '__breakpointhook__') + and sys.__breakpointhook__ != pydevd_breakpointhook + ): + sys.__breakpointhook__(*args, **kwargs) + else: + settrace(*args, **kwargs) + + if sys.version_info[0:2] >= (3, 7): + # There are some choices on how to provide the breakpoint hook. Namely, we can provide a + # PYTHONBREAKPOINT which provides the import path for a method to be executed or we + # can override sys.breakpointhook. + # pydevd overrides sys.breakpointhook instead of providing an environment variable because + # it's possible that the debugger starts the user program but is not available in the + # PYTHONPATH (and would thus fail to be imported if PYTHONBREAKPOINT was set to pydevd.settrace). + # Note that the implementation still takes PYTHONBREAKPOINT in account (so, if it was provided + # by someone else, it'd still work). + sys.breakpointhook = pydevd_breakpointhook + else: + if sys.version_info[0] >= 3: + import builtins as __builtin__ # Py3 noqa + else: + import __builtin__ # noqa + + # In older versions, breakpoint() isn't really available, so, install the hook directly + # in the builtins. + __builtin__.breakpoint = pydevd_breakpointhook + sys.__breakpointhook__ = pydevd_breakpointhook + + +# Install the breakpoint hook at import time. +install_breakpointhook() + +SUPPORT_PLUGINS = not IS_JYTH_LESS25 +PluginManager = None +if SUPPORT_PLUGINS: + from _pydevd_bundle.pydevd_plugin_utils import PluginManager + +threadingEnumerate = threading.enumerate +threadingCurrentThread = threading.currentThread + +try: + 'dummy'.encode('utf-8') # Added because otherwise Jython 2.2.1 wasn't finding the encoding (if it wasn't loaded in the main thread). +except: + pass + +_debugger_setup = False +bufferStdOutToServer = False +bufferStdErrToServer = False + +file_system_encoding = getfilesystemencoding() + +_CACHE_FILE_TYPE = {} + + +#======================================================================================================================= +# PyDBCommandThread +#======================================================================================================================= +class PyDBCommandThread(PyDBDaemonThread): + + def __init__(self, py_db): + PyDBDaemonThread.__init__(self) + self._py_db_command_thread_event = py_db._py_db_command_thread_event + self.py_db = py_db + self.setName('pydevd.CommandThread') + + @overrides(PyDBDaemonThread._on_run) + def _on_run(self): + # Delay a bit this initialization to wait for the main program to start. + time.sleep(0.3) + + if self.killReceived: + return + + try: + while not self.killReceived: + try: + self.py_db.process_internal_commands() + except: + pydev_log.info('Finishing debug communication...(2)') + self._py_db_command_thread_event.clear() + self._py_db_command_thread_event.wait(0.3) + except: + try: + pydev_log.debug(sys.exc_info()[0]) + except: + # In interpreter shutdown many things can go wrong (any module variables may + # be None, streams can be closed, etc). + pass + + # only got this error in interpreter shutdown + # pydev_log.info('Finishing debug communication...(3)') + + +#======================================================================================================================= +# CheckAliveThread +# Non-daemon thread: guarantees that all data is written even if program is finished +#======================================================================================================================= +class CheckAliveThread(PyDBDaemonThread): + + def __init__(self, py_db): + PyDBDaemonThread.__init__(self) + self.py_db = py_db + self.setName('pydevd.CheckAliveThread') + self.daemon = False + + @overrides(PyDBDaemonThread._on_run) + def _on_run(self): + while not self.killReceived: + time.sleep(0.3) + if not self.py_db.has_threads_alive() and self.py_db.writer.empty(): + try: + pydev_log.debug("No threads alive, finishing debug session") + self.py_db.finish_debugging_session() + kill_all_pydev_threads() + self.wait_pydb_threads_to_finish() + except: + pydev_log.exception() + + self.killReceived = True + return + + self.py_db.check_output_redirect() + + def wait_pydb_threads_to_finish(self, timeout=0.5): + pydev_log.debug("Waiting for pydb daemon threads to finish") + pydb_daemon_threads = self.created_pydb_daemon_threads + started_at = time.time() + while time.time() < started_at + timeout: + if len(pydb_daemon_threads) == 1 and pydb_daemon_threads.get(self, None): + return + time.sleep(1 / 30.) + pydev_log.debug("The following pydb threads may not have finished correctly: %s", + ', '.join([t.getName() for t in pydb_daemon_threads if t is not self])) + + def join(self, timeout=None): + # If someone tries to join this thread, mark it to be killed. + # This is the case for CherryPy when auto-reload is turned on. + self.do_kill_pydev_thread() + PyDBDaemonThread.join(self, timeout=timeout) + + +class AbstractSingleNotificationBehavior(object): + ''' + The basic usage should be: + + # Increment the request time for the suspend. + single_notification_behavior.increment_suspend_time() + + # Notify that this is a pause request (when a pause, not a breakpoint). + single_notification_behavior.on_pause() + + # Mark threads to be suspended. + set_suspend(...) + + # On do_wait_suspend, use notify_thread_suspended: + def do_wait_suspend(...): + with single_notification_behavior.notify_thread_suspended(thread_id): + ... + ''' + + __slots__ = [ + '_last_resume_notification_time', + '_last_suspend_notification_time', + '_lock', + '_next_request_time', + '_suspend_time_request', + '_suspended_thread_ids', + '_pause_requested', + ] + + NOTIFY_OF_PAUSE_TIMEOUT = .5 + + def __init__(self): + self._next_request_time = partial(next, itertools.count()) + self._last_suspend_notification_time = -1 + self._last_resume_notification_time = -1 + self._suspend_time_request = self._next_request_time() + self._lock = thread.allocate_lock() + self._suspended_thread_ids = set() + self._pause_requested = False + + def send_suspend_notification(self, thread_id, stop_reason): + raise AssertionError('abstract: subclasses must override.') + + def send_resume_notification(self, thread_id): + raise AssertionError('abstract: subclasses must override.') + + def increment_suspend_time(self): + with self._lock: + self._suspend_time_request = self._next_request_time() + + def on_pause(self): + # Upon a pause, we should force sending new suspend notifications + # if no notification is sent after some time and there's some thread already stopped. + with self._lock: + self._pause_requested = True + global_suspend_time = self._suspend_time_request + run_as_pydevd_daemon_thread(self._notify_after_timeout, global_suspend_time) + + def _notify_after_timeout(self, global_suspend_time): + time.sleep(self.NOTIFY_OF_PAUSE_TIMEOUT) + with self._lock: + if self._suspended_thread_ids: + if global_suspend_time > self._last_suspend_notification_time: + self._last_suspend_notification_time = global_suspend_time + # Notify about any thread which is currently suspended. + self.send_suspend_notification(next(iter(self._suspended_thread_ids)), CMD_THREAD_SUSPEND) + + @contextmanager + def notify_thread_suspended(self, thread_id, stop_reason): + with self._lock: + pause_requested = self._pause_requested + if pause_requested: + # When a suspend notification is sent, reset the pause flag. + self._pause_requested = False + + self._suspended_thread_ids.add(thread_id) + + # CMD_THREAD_SUSPEND should always be a side-effect of a break, so, only + # issue for a CMD_THREAD_SUSPEND if a pause is pending. + if stop_reason != CMD_THREAD_SUSPEND or pause_requested: + if self._suspend_time_request > self._last_suspend_notification_time: + self._last_suspend_notification_time = self._suspend_time_request + self.send_suspend_notification(thread_id, stop_reason) + try: + yield # At this point the thread must be actually suspended. + finally: + # on resume (step, continue all): + with self._lock: + self._suspended_thread_ids.remove(thread_id) + if self._last_resume_notification_time < self._last_suspend_notification_time: + self._last_resume_notification_time = self._last_suspend_notification_time + self.send_resume_notification(thread_id) + + +class ThreadsSuspendedSingleNotification(AbstractSingleNotificationBehavior): + + __slots__ = AbstractSingleNotificationBehavior.__slots__ + [ + 'multi_threads_single_notification', '_py_db', '_callbacks', '_callbacks_lock'] + + def __init__(self, py_db): + AbstractSingleNotificationBehavior.__init__(self) + # If True, pydevd will send a single notification when all threads are suspended/resumed. + self.multi_threads_single_notification = False + self._py_db = weakref.ref(py_db) + self._callbacks_lock = threading.Lock() + self._callbacks = [] + + def add_on_resumed_callback(self, callback): + with self._callbacks_lock: + self._callbacks.append(callback) + + @overrides(AbstractSingleNotificationBehavior.send_resume_notification) + def send_resume_notification(self, thread_id): + py_db = self._py_db() + if py_db is not None: + py_db.writer.add_command(py_db.cmd_factory.make_thread_resume_single_notification(thread_id)) + + with self._callbacks_lock: + callbacks = self._callbacks + self._callbacks = [] + + for callback in callbacks: + callback() + + @overrides(AbstractSingleNotificationBehavior.send_suspend_notification) + def send_suspend_notification(self, thread_id, stop_reason): + py_db = self._py_db() + if py_db is not None: + py_db.writer.add_command(py_db.cmd_factory.make_thread_suspend_single_notification(py_db, thread_id, stop_reason)) + + @overrides(AbstractSingleNotificationBehavior.notify_thread_suspended) + @contextmanager + def notify_thread_suspended(self, thread_id, stop_reason): + if self.multi_threads_single_notification: + with AbstractSingleNotificationBehavior.notify_thread_suspended(self, thread_id, stop_reason): + yield + else: + yield + + +class PyDB(object): + """ Main debugging class + Lots of stuff going on here: + + PyDB starts two threads on startup that connect to remote debugger (RDB) + The threads continuously read & write commands to RDB. + PyDB communicates with these threads through command queues. + Every RDB command is processed by calling process_net_command. + Every PyDB net command is sent to the net by posting NetCommand to WriterThread queue + + Some commands need to be executed on the right thread (suspend/resume & friends) + These are placed on the internal command queue. + """ + + def __init__(self, set_as_global=True): + if set_as_global: + pydevd_tracing.replace_sys_set_trace_func() + + self.reader = None + self.writer = None + self._waiting_for_connection_thread = None + self._on_configuration_done_event = threading.Event() + self.output_checker_thread = None + self.py_db_command_thread = None + self.quitting = None + self.cmd_factory = NetCommandFactory() + self._cmd_queue = defaultdict(_queue.Queue) # Key is thread id or '*', value is Queue + self.suspended_frames_manager = SuspendedFramesManager() + self._files_filtering = FilesFiltering() + self.source_mapping = SourceMapping() + + # These are the breakpoints received by the PyDevdAPI. They are meant to store + # the breakpoints in the api -- its actual contents are managed by the api. + self.api_received_breakpoints = {} + + # These are the breakpoints meant to be consumed during runtime. + self.breakpoints = {} + + # Set communication protocol + PyDevdAPI().set_protocol(self, 0, PydevdCustomization.DEFAULT_PROTOCOL) + + # mtime to be raised when breakpoints change + self.mtime = 0 + + self.file_to_id_to_line_breakpoint = {} + self.file_to_id_to_plugin_breakpoint = {} + + # Note: breakpoints dict should not be mutated: a copy should be created + # and later it should be assigned back (to prevent concurrency issues). + self.break_on_uncaught_exceptions = {} + self.break_on_caught_exceptions = {} + + self.ready_to_run = False + self._main_lock = thread.allocate_lock() + self._lock_running_thread_ids = thread.allocate_lock() + self._py_db_command_thread_event = threading.Event() + if set_as_global: + CustomFramesContainer._py_db_command_thread_event = self._py_db_command_thread_event + + self._finish_debugging_session = False + self._termination_event_set = False + self.signature_factory = None + self.SetTrace = pydevd_tracing.SetTrace + self.skip_on_exceptions_thrown_in_same_context = False + self.ignore_exceptions_thrown_in_lines_with_ignore_exception = True + + # Suspend debugger even if breakpoint condition raises an exception. + # May be changed with CMD_PYDEVD_JSON_CONFIG. + self.skip_suspend_on_breakpoint_exception = () # By default suspend on any Exception. + self.skip_print_breakpoint_exception = () # By default print on any Exception. + + # By default user can step into properties getter/setter/deleter methods + self.disable_property_trace = False + self.disable_property_getter_trace = False + self.disable_property_setter_trace = False + self.disable_property_deleter_trace = False + + # this is a dict of thread ids pointing to thread ids. Whenever a command is passed to the java end that + # acknowledges that a thread was created, the thread id should be passed here -- and if at some time we do not + # find that thread alive anymore, we must remove it from this list and make the java side know that the thread + # was killed. + self._running_thread_ids = {} + # Note: also access '_enable_thread_notifications' with '_lock_running_thread_ids' + self._enable_thread_notifications = False + + self._set_breakpoints_with_id = False + + # This attribute holds the file-> lines which have an @IgnoreException. + self.filename_to_lines_where_exceptions_are_ignored = {} + + # working with plugins (lazily initialized) + self.plugin = None + self.has_plugin_line_breaks = False + self.has_plugin_exception_breaks = False + self.thread_analyser = None + self.asyncio_analyser = None + + # matplotlib support in debugger and debug console + self.mpl_in_use = False + self.mpl_hooks_in_debug_console = False + self.mpl_modules_for_patching = {} + + self._filename_to_not_in_scope = {} + self.first_breakpoint_reached = False + self._exclude_filters_enabled = self._files_filtering.use_exclude_filters() + self._is_libraries_filter_enabled = self._files_filtering.use_libraries_filter() + self.is_files_filter_enabled = self._exclude_filters_enabled or self._is_libraries_filter_enabled + self.show_return_values = False + self.remove_return_values_flag = False + self.redirect_output = False + + # this flag disables frame evaluation even if it's available + self.use_frame_eval = True + + # If True, pydevd will send a single notification when all threads are suspended/resumed. + self._threads_suspended_single_notification = ThreadsSuspendedSingleNotification(self) + + # If True a step command will do a step in one thread and will also resume all other threads. + self.stepping_resumes_all_threads = False + + self._local_thread_trace_func = threading.local() + + # Bind many locals to the debugger because upon teardown those names may become None + # in the namespace (and thus can't be relied upon unless the reference was previously + # saved). + if IS_IRONPYTHON: + + # A partial() cannot be used in IronPython for sys.settrace. + def new_trace_dispatch(frame, event, arg): + return _trace_dispatch(self, frame, event, arg) + + self.trace_dispatch = new_trace_dispatch + else: + self.trace_dispatch = partial(_trace_dispatch, self) + self.fix_top_level_trace_and_get_trace_func = fix_top_level_trace_and_get_trace_func + self.frame_eval_func = frame_eval_func + self.dummy_trace_dispatch = dummy_trace_dispatch + + # Note: this is different from pydevd_constants.thread_get_ident because we want Jython + # to be None here because it also doesn't have threading._active. + try: + self.threading_get_ident = threading.get_ident # Python 3 + self.threading_active = threading._active + except: + try: + self.threading_get_ident = threading._get_ident # Python 2 noqa + self.threading_active = threading._active + except: + self.threading_get_ident = None # Jython + self.threading_active = None + self.threading_current_thread = threading.currentThread + self.set_additional_thread_info = set_additional_thread_info + self.stop_on_unhandled_exception = stop_on_unhandled_exception + self.collect_try_except_info = collect_try_except_info + self.get_exception_breakpoint = get_exception_breakpoint + self._dont_trace_get_file_type = DONT_TRACE.get + self.PYDEV_FILE = PYDEV_FILE + self.LIB_FILE = LIB_FILE + + self._in_project_scope_cache = {} + self._exclude_by_filter_cache = {} + self._apply_filter_cache = {} + self._ignore_system_exit_codes = set() + + if set_as_global: + # Set as the global instance only after it's initialized. + set_global_debugger(self) + + def on_configuration_done(self): + ''' + Note: only called when using the DAP (Debug Adapter Protocol). + ''' + self._on_configuration_done_event.set() + + def on_disconnect(self): + ''' + Note: only called when using the DAP (Debug Adapter Protocol). + ''' + self._on_configuration_done_event.clear() + + def set_ignore_system_exit_codes(self, ignore_system_exit_codes): + assert isinstance(ignore_system_exit_codes, (list, tuple, set)) + self._ignore_system_exit_codes = set(ignore_system_exit_codes) + + def ignore_system_exit_code(self, system_exit_exc): + if hasattr(system_exit_exc, 'code'): + return system_exit_exc.code in self._ignore_system_exit_codes + else: + return system_exit_exc in self._ignore_system_exit_codes + + def block_until_configuration_done(self): + self._on_configuration_done_event.wait() + + def add_fake_frame(self, thread_id, frame_id, frame): + self.suspended_frames_manager.add_fake_frame(thread_id, frame_id, frame) + + def handle_breakpoint_condition(self, info, pybreakpoint, new_frame): + condition = pybreakpoint.condition + try: + if pybreakpoint.handle_hit_condition(new_frame): + return True + + if not condition: + return False + + return eval(condition, new_frame.f_globals, new_frame.f_locals) + except Exception as e: + if IS_PY2: + # Must be bytes on py2. + if isinstance(condition, unicode): # noqa + condition = condition.encode('utf-8') + + if not isinstance(e, self.skip_print_breakpoint_exception): + sys.stderr.write('Error while evaluating expression: %s\n' % (condition,)) + + etype, value, tb = sys.exc_info() + traceback.print_exception(etype, value, tb.tb_next) + + if not isinstance(e, self.skip_suspend_on_breakpoint_exception): + try: + # add exception_type and stacktrace into thread additional info + etype, value, tb = sys.exc_info() + error = ''.join(traceback.format_exception_only(etype, value)) + stack = traceback.extract_stack(f=tb.tb_frame.f_back) + + # On self.set_suspend(thread, CMD_SET_BREAK) this info will be + # sent to the client. + info.conditional_breakpoint_exception = \ + ('Condition:\n' + condition + '\n\nError:\n' + error, stack) + except: + pydev_log.exception() + return True + + return False + + finally: + etype, value, tb = None, None, None + + def handle_breakpoint_expression(self, pybreakpoint, info, new_frame): + try: + try: + val = eval(pybreakpoint.expression, new_frame.f_globals, new_frame.f_locals) + except: + val = sys.exc_info()[1] + finally: + if val is not None: + info.pydev_message = str(val) + + def _internal_get_file_type(self, abs_real_path_and_basename): + basename = abs_real_path_and_basename[-1] + if basename.startswith(' ..." can appear and should be ignored for the user. + return self.PYDEV_FILE + return self._dont_trace_get_file_type(basename) + + def dont_trace_external_files(self, abs_path): + ''' + :param abs_path: + The result from get_abs_path_real_path_and_base_from_file or + get_abs_path_real_path_and_base_from_frame. + + :return + True : + If files should NOT be traced. + + False: + If files should be traced. + ''' + # By default all external files are traced. Note: this function is expected to + # be changed for another function in PyDevdAPI.set_dont_trace_start_end_patterns. + return False + + def get_file_type(self, frame, abs_real_path_and_basename=None, _cache_file_type=_CACHE_FILE_TYPE): + ''' + :param abs_real_path_and_basename: + The result from get_abs_path_real_path_and_base_from_file or + get_abs_path_real_path_and_base_from_frame. + + :return + _pydevd_bundle.pydevd_dont_trace_files.PYDEV_FILE: + If it's a file internal to the debugger which shouldn't be + traced nor shown to the user. + + _pydevd_bundle.pydevd_dont_trace_files.LIB_FILE: + If it's a file in a library which shouldn't be traced. + + None: + If it's a regular user file which should be traced. + ''' + if abs_real_path_and_basename is None: + try: + # Make fast path faster! + abs_real_path_and_basename = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + except: + abs_real_path_and_basename = get_abs_path_real_path_and_base_from_frame(frame) + + # Note 1: we have to take into account that we may have files as '', and that in + # this case the cache key can't rely only on the filename. With the current cache, there's + # still a potential miss if 2 functions which have exactly the same content are compiled + # with '', but in practice as we only separate the one from python -c from the rest + # this shouldn't be a problem in practice. + + # Note 2: firstlineno added to make misses faster in the first comparison. + + # Note 3: this cache key is repeated in pydevd_frame_evaluator.pyx:get_func_code_info (for + # speedups). + cache_key = (frame.f_code.co_firstlineno, abs_real_path_and_basename[0], frame.f_code) + try: + return _cache_file_type[cache_key] + except: + if abs_real_path_and_basename[0] == '': + + # Consider it an untraceable file unless there's no back frame (ignoring + # internal files and runpy.py). + f = frame.f_back + while f is not None: + if (self.get_file_type(f) != self.PYDEV_FILE and + get_abs_path_real_path_and_base_from_file(f.f_code.co_filename)[2] != 'runpy.py'): + # We found some back frame that's not internal, which means we must consider + # this a library file. + # This is done because we only want to trace files as if they don't + # have any back frame (which is the case for python -c ...), for all other + # cases we don't want to trace them because we can't show the source to the + # user (at least for now...). + + # Note that we return as a LIB_FILE and not PYDEV_FILE because we still want + # to show it in the stack. + _cache_file_type[cache_key] = LIB_FILE + return LIB_FILE + f = f.f_back + else: + # This is a top-level file (used in python -c), so, trace it as usual... we + # still won't be able to show the sources, but some tests require this to work. + _cache_file_type[cache_key] = None + return None + + file_type = self._internal_get_file_type(abs_real_path_and_basename) + if file_type is None: + if self.dont_trace_external_files(abs_real_path_and_basename[0]): + file_type = PYDEV_FILE + _cache_file_type[cache_key] = file_type + return file_type + + def is_cache_file_type_empty(self): + return not _CACHE_FILE_TYPE + + def get_cache_file_type(self, _cache=_CACHE_FILE_TYPE): # i.e.: Make it local. + return _cache + + def get_thread_local_trace_func(self): + try: + thread_trace_func = self._local_thread_trace_func.thread_trace_func + except AttributeError: + thread_trace_func = self.trace_dispatch + return thread_trace_func + + def enable_tracing(self, thread_trace_func=None, apply_to_all_threads=False): + ''' + Enables tracing. + + If in regular mode (tracing), will set the tracing function to the tracing + function for this thread -- by default it's `PyDB.trace_dispatch`, but after + `PyDB.enable_tracing` is called with a `thread_trace_func`, the given function will + be the default for the given thread. + + :param bool apply_to_all_threads: + If True we'll set the tracing function in all threads, not only in the current thread. + If False only the tracing for the current function should be changed. + In general apply_to_all_threads should only be true if this is the first time + this function is called on a multi-threaded program (either programmatically or attach + to pid). + ''' + if self.frame_eval_func is not None: + self.frame_eval_func() + pydevd_tracing.SetTrace(self.dummy_trace_dispatch) + + if IS_CPYTHON and apply_to_all_threads: + pydevd_tracing.set_trace_to_threads(self.dummy_trace_dispatch) + return + + if apply_to_all_threads: + # If applying to all threads, don't use the local thread trace function. + assert thread_trace_func is not None + else: + if thread_trace_func is None: + thread_trace_func = self.get_thread_local_trace_func() + else: + self._local_thread_trace_func.thread_trace_func = thread_trace_func + + pydevd_tracing.SetTrace(thread_trace_func) + if IS_CPYTHON and apply_to_all_threads: + pydevd_tracing.set_trace_to_threads(thread_trace_func) + + def disable_tracing(self): + pydevd_tracing.SetTrace(None) + + def on_breakpoints_changed(self, removed=False): + ''' + When breakpoints change, we have to re-evaluate all the assumptions we've made so far. + ''' + if not self.ready_to_run: + # No need to do anything if we're still not running. + return + + self.mtime += 1 + if not removed: + # When removing breakpoints we can leave tracing as was, but if a breakpoint was added + # we have to reset the tracing for the existing functions to be re-evaluated. + self.set_tracing_for_untraced_contexts() + + def set_tracing_for_untraced_contexts(self): + # Enable the tracing for existing threads (because there may be frames being executed that + # are currently untraced). + + if IS_CPYTHON: + # Note: use sys._current_frames instead of threading.enumerate() because this way + # we also see C/C++ threads, not only the ones visible to the threading module. + tid_to_frame = sys._current_frames() + + ignore_thread_ids = set( + t.ident for t in threadingEnumerate() + if getattr(t, 'is_pydev_daemon_thread', False) or getattr(t, 'pydev_do_not_trace', False) + ) + + for thread_id, frame in tid_to_frame.items(): + if thread_id not in ignore_thread_ids: + self.set_trace_for_frame_and_parents(frame) + + else: + try: + threads = threadingEnumerate() + for t in threads: + if getattr(t, 'is_pydev_daemon_thread', False) or getattr(t, 'pydev_do_not_trace', False): + continue + + additional_info = set_additional_thread_info(t) + frame = additional_info.get_topmost_frame(t) + try: + if frame is not None: + self.set_trace_for_frame_and_parents(frame) + finally: + frame = None + finally: + frame = None + t = None + threads = None + additional_info = None + + @property + def multi_threads_single_notification(self): + return self._threads_suspended_single_notification.multi_threads_single_notification + + @multi_threads_single_notification.setter + def multi_threads_single_notification(self, notify): + self._threads_suspended_single_notification.multi_threads_single_notification = notify + + @property + def threads_suspended_single_notification(self): + return self._threads_suspended_single_notification + + def get_plugin_lazy_init(self): + if self.plugin is None and SUPPORT_PLUGINS: + self.plugin = PluginManager(self) + return self.plugin + + def in_project_scope(self, frame, filename=None): + ''' + Note: in general this method should not be used (apply_files_filter should be used + in most cases as it also handles the project scope check). + + :param frame: + The frame we want to check. + + :param filename: + Must be the result from get_abs_path_real_path_and_base_from_frame(frame)[0] (can + be used to speed this function a bit if it's already available to the caller, but + in general it's not needed). + ''' + try: + if filename is None: + try: + # Make fast path faster! + abs_real_path_and_basename = NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + except: + abs_real_path_and_basename = get_abs_path_real_path_and_base_from_frame(frame) + + filename = abs_real_path_and_basename[0] + + cache_key = (frame.f_code.co_firstlineno, filename, frame.f_code) + + return self._in_project_scope_cache[cache_key] + except KeyError: + cache = self._in_project_scope_cache + try: + abs_real_path_and_basename # If we've gotten it previously, use it again. + except NameError: + abs_real_path_and_basename = get_abs_path_real_path_and_base_from_frame(frame) + + # pydevd files are never considered to be in the project scope. + file_type = self.get_file_type(frame, abs_real_path_and_basename) + if file_type == self.PYDEV_FILE: + cache[cache_key] = False + + elif file_type == self.LIB_FILE and filename == '': + # This means it's a which should be considered to be a library file and + # shouldn't be considered as a part of the project. + # (i.e.: lib files must be traced if they're put inside a project). + cache[cache_key] = False + + else: + cache[cache_key] = self._files_filtering.in_project_roots(filename) + + return cache[cache_key] + + def _clear_filters_caches(self): + self._in_project_scope_cache.clear() + self._exclude_by_filter_cache.clear() + self._apply_filter_cache.clear() + self._exclude_filters_enabled = self._files_filtering.use_exclude_filters() + self._is_libraries_filter_enabled = self._files_filtering.use_libraries_filter() + self.is_files_filter_enabled = self._exclude_filters_enabled or self._is_libraries_filter_enabled + + def clear_dont_trace_start_end_patterns_caches(self): + # When start/end patterns are changed we must clear all caches which would be + # affected by a change in get_file_type() and reset the tracing function + # as places which were traced may no longer need to be traced and vice-versa. + self.on_breakpoints_changed() + _CACHE_FILE_TYPE.clear() + self._clear_filters_caches() + self._clear_skip_caches() + + def _exclude_by_filter(self, frame, filename): + ''' + :param str filename: + The filename to filter. + + :return: True if it should be excluded, False if it should be included and None + if no rule matched the given file. + ''' + cache_key = (filename, frame.f_code.co_name) + try: + return self._exclude_by_filter_cache[cache_key] + except KeyError: + cache = self._exclude_by_filter_cache + + # pydevd files are always filtered out + if self.get_file_type(frame) == self.PYDEV_FILE: + cache[cache_key] = True + else: + module_name = None + if self._files_filtering.require_module: + module_name = frame.f_globals.get('__name__', '') + cache[cache_key] = self._files_filtering.exclude_by_filter(filename, module_name) + + return cache[cache_key] + + def apply_files_filter(self, frame, filename, force_check_project_scope): + ''' + Should only be called if `self.is_files_filter_enabled == True`. + + Note that it covers both the filter by specific paths includes/excludes as well + as the check which filters out libraries if not in the project scope. + + :param force_check_project_scope: + Check that the file is in the project scope even if the global setting + is off. + + :return bool: + True if it should be excluded when stepping and False if it should be + included. + ''' + cache_key = (frame.f_code.co_firstlineno, filename, force_check_project_scope, frame.f_code) + try: + return self._apply_filter_cache[cache_key] + except KeyError: + if self.plugin is not None and (self.has_plugin_line_breaks or self.has_plugin_exception_breaks): + # If it's explicitly needed by some plugin, we can't skip it. + if not self.plugin.can_skip(self, frame): + pydev_log.debug_once('File traced (included by plugins): %s', filename) + self._apply_filter_cache[cache_key] = False + return False + + if self._exclude_filters_enabled: + exclude_by_filter = self._exclude_by_filter(frame, filename) + if exclude_by_filter is not None: + if exclude_by_filter: + # ignore files matching stepping filters + pydev_log.debug_once('File not traced (excluded by filters): %s', filename) + + self._apply_filter_cache[cache_key] = True + return True + else: + pydev_log.debug_once('File traced (explicitly included by filters): %s', filename) + + self._apply_filter_cache[cache_key] = False + return False + + if (self._is_libraries_filter_enabled or force_check_project_scope) and not self.in_project_scope(frame): + # ignore library files while stepping + self._apply_filter_cache[cache_key] = True + if force_check_project_scope: + pydev_log.debug_once('File not traced (not in project): %s', filename) + else: + pydev_log.debug_once('File not traced (not in project - force_check_project_scope): %s', filename) + + return True + + if force_check_project_scope: + pydev_log.debug_once('File traced: %s (force_check_project_scope)', filename) + else: + pydev_log.debug_once('File traced: %s', filename) + self._apply_filter_cache[cache_key] = False + return False + + def exclude_exception_by_filter(self, exception_breakpoint, trace, is_uncaught): + if not exception_breakpoint.ignore_libraries and not self._exclude_filters_enabled: + return False + + if trace is None: + return True + + # We need to get the place where it was raised if it's an uncaught exception... + if is_uncaught: + while trace.tb_next is not None: + trace = trace.tb_next + + ignore_libraries = exception_breakpoint.ignore_libraries + exclude_filters_enabled = self._exclude_filters_enabled + + if (ignore_libraries and not self.in_project_scope(trace.tb_frame)) \ + or (exclude_filters_enabled and self._exclude_by_filter(trace.tb_frame, trace.tb_frame.f_code.co_filename)): + return True + + return False + + def set_project_roots(self, project_roots): + self._files_filtering.set_project_roots(project_roots) + self._clear_skip_caches() + self._clear_filters_caches() + + def set_exclude_filters(self, exclude_filters): + self._files_filtering.set_exclude_filters(exclude_filters) + self._clear_skip_caches() + self._clear_filters_caches() + + def set_use_libraries_filter(self, use_libraries_filter): + self._files_filtering.set_use_libraries_filter(use_libraries_filter) + self._clear_skip_caches() + self._clear_filters_caches() + + def get_use_libraries_filter(self): + return self._files_filtering.use_libraries_filter() + + def get_require_module_for_filters(self): + return self._files_filtering.require_module + + def has_threads_alive(self): + for t in pydevd_utils.get_non_pydevd_threads(): + if isinstance(t, PyDBDaemonThread): + pydev_log.error_once( + 'Error in debugger: Found PyDBDaemonThread not marked with is_pydev_daemon_thread=True.\n') + + if is_thread_alive(t): + if not t.isDaemon() or hasattr(t, "__pydevd_main_thread"): + return True + + return False + + def finish_debugging_session(self): + self._finish_debugging_session = True + + def initialize_network(self, sock, terminate_on_socket_close=True): + assert sock is not None + try: + sock.settimeout(None) # infinite, no timeouts from now on - jython does not have it + except: + pass + curr_reader = getattr(self, 'reader', None) + curr_writer = getattr(self, 'writer', None) + if curr_reader: + curr_reader.do_kill_pydev_thread() + if curr_writer: + curr_writer.do_kill_pydev_thread() + + self.writer = WriterThread(sock, terminate_on_socket_close=terminate_on_socket_close) + self.reader = ReaderThread(sock, terminate_on_socket_close=terminate_on_socket_close) + self.writer.start() + self.reader.start() + + time.sleep(0.1) # give threads time to start + + def connect(self, host, port): + if host: + s = start_client(host, port) + else: + s = start_server(port) + + self.initialize_network(s) + + def create_wait_for_connection_thread(self): + if self._waiting_for_connection_thread is not None: + raise AssertionError('There is already another thread waiting for a connection.') + + self._waiting_for_connection_thread = self._WaitForConnectionThread(self) + self._waiting_for_connection_thread.start() + + class _WaitForConnectionThread(PyDBDaemonThread): + + def __init__(self, py_db): + PyDBDaemonThread.__init__(self) + self.py_db = py_db + self._server_socket = None + + def run(self): + host = SetupHolder.setup['client'] + port = SetupHolder.setup['port'] + + self._server_socket = create_server_socket(host=host, port=port) + + while not self.killReceived: + try: + s = self._server_socket + if s is None: + return + + s.listen(1) + new_socket, _addr = s.accept() + if self.killReceived: + pydev_log.info("Connection (from wait_for_attach) accepted but ignored as kill was already received.") + return + + pydev_log.info("Connection (from wait_for_attach) accepted.") + reader = getattr(self.py_db, 'reader', None) + if reader is not None: + # This is needed if a new connection is done without the client properly + # sending a disconnect for the previous connection. + api = PyDevdAPI() + api.request_disconnect(self.py_db, resume_threads=False) + + self.py_db.initialize_network(new_socket, terminate_on_socket_close=False) + + except: + if DebugInfoHolder.DEBUG_TRACE_LEVEL > 0: + pydev_log.exception() + pydev_log.debug("Exiting _WaitForConnectionThread: %s\n", port) + + def do_kill_pydev_thread(self): + PyDBDaemonThread.do_kill_pydev_thread(self) + s = self._server_socket + try: + s.shutdown(SHUT_RDWR) + except: + pass + try: + s.close() + except: + pass + self._server_socket = None + + def get_internal_queue(self, thread_id): + """ returns internal command queue for a given thread. + if new queue is created, notify the RDB about it """ + if thread_id.startswith('__frame__'): + thread_id = thread_id[thread_id.rfind('|') + 1:] + return self._cmd_queue[thread_id] + + def post_method_as_internal_command(self, thread_id, method, *args, **kwargs): + if thread_id == '*': + internal_cmd = InternalThreadCommandForAnyThread(thread_id, method, *args, **kwargs) + else: + internal_cmd = InternalThreadCommand(thread_id, method, *args, **kwargs) + self.post_internal_command(internal_cmd, thread_id) + + def post_internal_command(self, int_cmd, thread_id): + """ if thread_id is *, post to the '*' queue""" + queue = self.get_internal_queue(thread_id) + queue.put(int_cmd) + + def enable_output_redirection(self, redirect_stdout, redirect_stderr): + global bufferStdOutToServer + global bufferStdErrToServer + + bufferStdOutToServer = redirect_stdout + bufferStdErrToServer = redirect_stderr + self.redirect_output = redirect_stdout or redirect_stderr + if bufferStdOutToServer: + init_stdout_redirect() + if bufferStdErrToServer: + init_stderr_redirect() + + def check_output_redirect(self): + global bufferStdOutToServer + global bufferStdErrToServer + + if bufferStdOutToServer: + init_stdout_redirect() + + if bufferStdErrToServer: + init_stderr_redirect() + + def init_matplotlib_in_debug_console(self): + # import hook and patches for matplotlib support in debug console + from _pydev_bundle.pydev_import_hook import import_hook_manager + if is_current_thread_main_thread(): + for module in dict_keys(self.mpl_modules_for_patching): + import_hook_manager.add_module_name(module, self.mpl_modules_for_patching.pop(module)) + + def init_matplotlib_support(self): + # prepare debugger for integration with matplotlib GUI event loop + from pydev_ipython.matplotlibtools import activate_matplotlib, activate_pylab, activate_pyplot, do_enable_gui + + # enable_gui_function in activate_matplotlib should be called in main thread. Unlike integrated console, + # in the debug console we have no interpreter instance with exec_queue, but we run this code in the main + # thread and can call it directly. + class _MatplotlibHelper: + _return_control_osc = False + + def return_control(): + # Some of the input hooks (e.g. Qt4Agg) check return control without doing + # a single operation, so we don't return True on every + # call when the debug hook is in place to allow the GUI to run + _MatplotlibHelper._return_control_osc = not _MatplotlibHelper._return_control_osc + return _MatplotlibHelper._return_control_osc + + from pydev_ipython.inputhook import set_return_control_callback + set_return_control_callback(return_control) + + self.mpl_modules_for_patching = {"matplotlib": lambda: activate_matplotlib(do_enable_gui), + "matplotlib.pyplot": activate_pyplot, + "pylab": activate_pylab } + + def _activate_mpl_if_needed(self): + if len(self.mpl_modules_for_patching) > 0: + if is_current_thread_main_thread(): # Note that we call only in the main thread. + for module in dict_keys(self.mpl_modules_for_patching): + if module in sys.modules: + activate_function = self.mpl_modules_for_patching.pop(module, None) + if activate_function is not None: + activate_function() + self.mpl_in_use = True + + def _call_mpl_hook(self): + try: + from pydev_ipython.inputhook import get_inputhook + inputhook = get_inputhook() + if inputhook: + inputhook() + except: + pass + + def notify_skipped_step_in_because_of_filters(self, frame): + self.writer.add_command(self.cmd_factory.make_skipped_step_in_because_of_filters(self, frame)) + + def notify_thread_created(self, thread_id, thread, use_lock=True): + if self.writer is None: + # Protect about threads being created before the communication structure is in place + # (note that they will appear later on anyways as pydevd does reconcile live/dead threads + # when processing internal commands, albeit it may take longer and in general this should + # not be usual as it's expected that the debugger is live before other threads are created). + return + + with self._lock_running_thread_ids if use_lock else NULL: + if not self._enable_thread_notifications: + return + + if thread_id in self._running_thread_ids: + return + + additional_info = set_additional_thread_info(thread) + if additional_info.pydev_notify_kill: + # After we notify it should be killed, make sure we don't notify it's alive (on a racing condition + # this could happen as we may notify before the thread is stopped internally). + return + + self._running_thread_ids[thread_id] = thread + + self.writer.add_command(self.cmd_factory.make_thread_created_message(thread)) + + def notify_thread_not_alive(self, thread_id, use_lock=True): + """ if thread is not alive, cancel trace_dispatch processing """ + if self.writer is None: + return + + with self._lock_running_thread_ids if use_lock else NULL: + if not self._enable_thread_notifications: + return + + thread = self._running_thread_ids.pop(thread_id, None) + if thread is None: + return + + additional_info = set_additional_thread_info(thread) + was_notified = additional_info.pydev_notify_kill + if not was_notified: + additional_info.pydev_notify_kill = True + + self.writer.add_command(self.cmd_factory.make_thread_killed_message(thread_id)) + + def set_enable_thread_notifications(self, enable): + with self._lock_running_thread_ids: + if self._enable_thread_notifications != enable: + self._enable_thread_notifications = enable + + if enable: + # As it was previously disabled, we have to notify about existing threads again + # (so, clear the cache related to that). + self._running_thread_ids = {} + + def process_internal_commands(self): + '''This function processes internal commands + ''' + with self._main_lock: + self.check_output_redirect() + + program_threads_alive = {} + all_threads = threadingEnumerate() + program_threads_dead = [] + with self._lock_running_thread_ids: + reset_cache = not self._running_thread_ids + + for t in all_threads: + if getattr(t, 'is_pydev_daemon_thread', False): + pass # I.e.: skip the DummyThreads created from pydev daemon threads + elif isinstance(t, PyDBDaemonThread): + pydev_log.error_once('Error in debugger: Found PyDBDaemonThread not marked with is_pydev_daemon_thread=True.') + + elif is_thread_alive(t): + if reset_cache: + # Fix multiprocessing debug with breakpoints in both main and child processes + # (https://youtrack.jetbrains.com/issue/PY-17092) When the new process is created, the main + # thread in the new process already has the attribute 'pydevd_id', so the new thread doesn't + # get new id with its process number and the debugger loses access to both threads. + # Therefore we should update thread_id for every main thread in the new process. + clear_cached_thread_id(t) + + thread_id = get_thread_id(t) + program_threads_alive[thread_id] = t + + self.notify_thread_created(thread_id, t, use_lock=False) + + # Compute and notify about threads which are no longer alive. + thread_ids = list(self._running_thread_ids.keys()) + for thread_id in thread_ids: + if thread_id not in program_threads_alive: + program_threads_dead.append(thread_id) + + for thread_id in program_threads_dead: + self.notify_thread_not_alive(thread_id, use_lock=False) + + # Without self._lock_running_thread_ids + if len(program_threads_alive) == 0: + self.finish_debugging_session() + for t in all_threads: + if hasattr(t, 'do_kill_pydev_thread'): + t.do_kill_pydev_thread() + else: + # Actually process the commands now (make sure we don't have a lock for _lock_running_thread_ids + # acquired at this point as it could lead to a deadlock if some command evaluated tried to + # create a thread and wait for it -- which would try to notify about it getting that lock). + curr_thread_id = get_current_thread_id(threadingCurrentThread()) + + for thread_id in (curr_thread_id, '*'): + queue = self.get_internal_queue(thread_id) + + # some commands must be processed by the thread itself... if that's the case, + # we will re-add the commands to the queue after executing. + cmds_to_add_back = [] + + try: + while True: + int_cmd = queue.get(False) + + if not self.mpl_hooks_in_debug_console and isinstance(int_cmd, InternalConsoleExec): + # add import hooks for matplotlib patches if only debug console was started + try: + self.init_matplotlib_in_debug_console() + self.mpl_in_use = True + except: + pydev_log.debug("Matplotlib support in debug console failed", traceback.format_exc()) + self.mpl_hooks_in_debug_console = True + + if int_cmd.can_be_executed_by(curr_thread_id): + pydev_log.verbose("processing internal command ", int_cmd) + int_cmd.do_it(self) + else: + pydev_log.verbose("NOT processing internal command ", int_cmd) + cmds_to_add_back.append(int_cmd) + + except _queue.Empty: # @UndefinedVariable + # this is how we exit + for int_cmd in cmds_to_add_back: + queue.put(int_cmd) + + def consolidate_breakpoints(self, file, id_to_breakpoint, breakpoints): + break_dict = {} + for _breakpoint_id, pybreakpoint in dict_iter_items(id_to_breakpoint): + break_dict[pybreakpoint.line] = pybreakpoint + + breakpoints[file] = break_dict + self._clear_skip_caches() + + def _clear_skip_caches(self): + global_cache_skips.clear() + global_cache_frame_skips.clear() + + def add_break_on_exception( + self, + exception, + condition, + expression, + notify_on_handled_exceptions, + notify_on_unhandled_exceptions, + notify_on_first_raise_only, + ignore_libraries=False + ): + try: + eb = ExceptionBreakpoint( + exception, + condition, + expression, + notify_on_handled_exceptions, + notify_on_unhandled_exceptions, + notify_on_first_raise_only, + ignore_libraries + ) + except ImportError: + pydev_log.critical("Error unable to add break on exception for: %s (exception could not be imported).", exception) + return None + + if eb.notify_on_unhandled_exceptions: + cp = self.break_on_uncaught_exceptions.copy() + cp[exception] = eb + if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: + pydev_log.critical("Exceptions to hook on terminate: %s.", cp) + self.break_on_uncaught_exceptions = cp + + if eb.notify_on_handled_exceptions: + cp = self.break_on_caught_exceptions.copy() + cp[exception] = eb + if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: + pydev_log.critical("Exceptions to hook always: %s.", cp) + self.break_on_caught_exceptions = cp + + return eb + + def _mark_suspend(self, thread, stop_reason): + info = set_additional_thread_info(thread) + info.suspend_type = PYTHON_SUSPEND + thread.stop_reason = stop_reason + + # Note: don't set the 'pydev_original_step_cmd' here if unset. + + if info.pydev_step_cmd == -1: + # If the step command is not specified, set it to step into + # to make sure it'll break as soon as possible. + info.pydev_step_cmd = CMD_STEP_INTO + + # Mark as suspend as the last thing. + info.pydev_state = STATE_SUSPEND + + return info + + def set_suspend(self, thread, stop_reason, suspend_other_threads=False, is_pause=False): + ''' + :param thread: + The thread which should be suspended. + + :param stop_reason: + Reason why the thread was suspended. + + :param suspend_other_threads: + Whether to force other threads to be suspended (i.e.: when hitting a breakpoint + with a suspend all threads policy). + + :param is_pause: + If this is a pause to suspend all threads, any thread can be considered as the 'main' + thread paused. + ''' + self._threads_suspended_single_notification.increment_suspend_time() + if is_pause: + self._threads_suspended_single_notification.on_pause() + + info = self._mark_suspend(thread, stop_reason) + + if is_pause: + # Must set tracing after setting the state to suspend. + frame = info.get_topmost_frame(thread) + if frame is not None: + try: + self.set_trace_for_frame_and_parents(frame) + finally: + frame = None + + # If conditional breakpoint raises any exception during evaluation send the details to the client. + if stop_reason == CMD_SET_BREAK and info.conditional_breakpoint_exception is not None: + conditional_breakpoint_exception_tuple = info.conditional_breakpoint_exception + info.conditional_breakpoint_exception = None + self._send_breakpoint_condition_exception(thread, conditional_breakpoint_exception_tuple) + + if not suspend_other_threads and self.multi_threads_single_notification: + # In the mode which gives a single notification when all threads are + # stopped, stop all threads whenever a set_suspend is issued. + suspend_other_threads = True + + if suspend_other_threads: + # Suspend all other threads. + all_threads = pydevd_utils.get_non_pydevd_threads() + for t in all_threads: + if getattr(t, 'pydev_do_not_trace', None): + pass # skip some other threads, i.e. ipython history saving thread from debug console + else: + if t is thread: + continue + info = self._mark_suspend(t, CMD_THREAD_SUSPEND) + frame = info.get_topmost_frame(t) + + # Reset the time as in this case this was not the main thread suspended. + if frame is not None: + try: + self.set_trace_for_frame_and_parents(frame) + finally: + frame = None + + def _send_breakpoint_condition_exception(self, thread, conditional_breakpoint_exception_tuple): + """If conditional breakpoint raises an exception during evaluation + send exception details to java + """ + thread_id = get_thread_id(thread) + # conditional_breakpoint_exception_tuple - should contain 2 values (exception_type, stacktrace) + if conditional_breakpoint_exception_tuple and len(conditional_breakpoint_exception_tuple) == 2: + exc_type, stacktrace = conditional_breakpoint_exception_tuple + int_cmd = InternalGetBreakpointException(thread_id, exc_type, stacktrace) + self.post_internal_command(int_cmd, thread_id) + + def send_caught_exception_stack(self, thread, arg, curr_frame_id): + """Sends details on the exception which was caught (and where we stopped) to the java side. + + arg is: exception type, description, traceback object + """ + thread_id = get_thread_id(thread) + int_cmd = InternalSendCurrExceptionTrace(thread_id, arg, curr_frame_id) + self.post_internal_command(int_cmd, thread_id) + + def send_caught_exception_stack_proceeded(self, thread): + """Sends that some thread was resumed and is no longer showing an exception trace. + """ + thread_id = get_thread_id(thread) + int_cmd = InternalSendCurrExceptionTraceProceeded(thread_id) + self.post_internal_command(int_cmd, thread_id) + self.process_internal_commands() + + def send_process_created_message(self): + """Sends a message that a new process has been created. + """ + if self.writer is None or self.cmd_factory is None: + return + cmd = self.cmd_factory.make_process_created_message() + self.writer.add_command(cmd) + + def set_next_statement(self, frame, event, func_name, next_line): + stop = False + response_msg = "" + old_line = frame.f_lineno + if event == 'line' or event == 'exception': + # If we're already in the correct context, we have to stop it now, because we can act only on + # line events -- if a return was the next statement it wouldn't work (so, we have this code + # repeated at pydevd_frame). + + curr_func_name = frame.f_code.co_name + + # global context is set with an empty name + if curr_func_name in ('?', ''): + curr_func_name = '' + + if func_name == '*' or curr_func_name == func_name: + line = next_line + frame.f_trace = self.trace_dispatch + frame.f_lineno = line + stop = True + else: + response_msg = "jump is available only within the bottom frame" + return stop, old_line, response_msg + + def cancel_async_evaluation(self, thread_id, frame_id): + self._main_lock.acquire() + try: + all_threads = threadingEnumerate() + for t in all_threads: + if getattr(t, 'is_pydev_daemon_thread', False) and hasattr(t, 'cancel_event') and t.thread_id == thread_id and \ + t.frame_id == frame_id: + t.cancel_event.set() + except: + pydev_log.exception() + finally: + self._main_lock.release() + + def find_frame(self, thread_id, frame_id): + """ returns a frame on the thread that has a given frame_id """ + return self.suspended_frames_manager.find_frame(thread_id, frame_id) + + def do_wait_suspend(self, thread, frame, event, arg, is_unhandled_exception=False): # @UnusedVariable + """ busy waits until the thread state changes to RUN + it expects thread's state as attributes of the thread. + Upon running, processes any outstanding Stepping commands. + + :param is_unhandled_exception: + If True we should use the line of the exception instead of the current line in the frame + as the paused location on the top-level frame (exception info must be passed on 'arg'). + """ + # print('do_wait_suspend %s %s %s %s' % (frame.f_lineno, frame.f_code.co_name, frame.f_code.co_filename, event)) + if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP: + _tid_to_last_frame[thread.ident] = sys._getframe() + self.process_internal_commands() + + thread_id = get_current_thread_id(thread) + + # Send the suspend message + message = thread.additional_info.pydev_message + suspend_type = thread.additional_info.trace_suspend_type + thread.additional_info.trace_suspend_type = 'trace' # Reset to trace mode for next call. + frame_id_to_lineno = {} + stop_reason = thread.stop_reason + if is_unhandled_exception: + # arg must be the exception info (tuple(exc_type, exc, traceback)) + tb = arg[2] + while tb is not None: + frame_id_to_lineno[id(tb.tb_frame)] = tb.tb_lineno + tb = tb.tb_next + + with self.suspended_frames_manager.track_frames(self) as frames_tracker: + frames_tracker.track(thread_id, frame, frame_id_to_lineno) + cmd = frames_tracker.create_thread_suspend_command(thread_id, stop_reason, message, suspend_type) + self.writer.add_command(cmd) + + with CustomFramesContainer.custom_frames_lock: # @UndefinedVariable + from_this_thread = [] + + for frame_custom_thread_id, custom_frame in dict_iter_items(CustomFramesContainer.custom_frames): + if custom_frame.thread_id == thread.ident: + frames_tracker.track(thread_id, custom_frame.frame, frame_id_to_lineno, frame_custom_thread_id=frame_custom_thread_id) + # print('Frame created as thread: %s' % (frame_custom_thread_id,)) + + self.writer.add_command(self.cmd_factory.make_custom_frame_created_message( + frame_custom_thread_id, custom_frame.name)) + + self.writer.add_command( + frames_tracker.create_thread_suspend_command(frame_custom_thread_id, CMD_THREAD_SUSPEND, "", suspend_type)) + + from_this_thread.append(frame_custom_thread_id) + + with self._threads_suspended_single_notification.notify_thread_suspended(thread_id, stop_reason): + keep_suspended = self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker) + + if keep_suspended: + # This means that we should pause again after a set next statement. + self._threads_suspended_single_notification.increment_suspend_time() + self.do_wait_suspend(thread, frame, event, arg, is_unhandled_exception) + + def _do_wait_suspend(self, thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker): + info = thread.additional_info + keep_suspended = False + + with self._main_lock: # Use lock to check if suspended state changed + activate_matplotlib = info.pydev_state == STATE_SUSPEND and not self._finish_debugging_session + + in_main_thread = is_current_thread_main_thread() + if activate_matplotlib and in_main_thread: + # before every stop check if matplotlib modules were imported inside script code + self._activate_mpl_if_needed() + + while True: + with self._main_lock: # Use lock to check if suspended state changed + if info.pydev_state != STATE_SUSPEND or self._finish_debugging_session: + break + + if in_main_thread and self.mpl_in_use: + # call input hooks if only matplotlib is in use + self._call_mpl_hook() + + self.process_internal_commands() + time.sleep(0.01) + + self.cancel_async_evaluation(get_current_thread_id(thread), str(id(frame))) + + # process any stepping instructions + if info.pydev_step_cmd in (CMD_STEP_INTO, CMD_STEP_INTO_MY_CODE): + info.pydev_step_stop = None + info.pydev_smart_step_stop = None + self.set_trace_for_frame_and_parents(frame) + + elif info.pydev_step_cmd in (CMD_STEP_OVER, CMD_STEP_OVER_MY_CODE): + info.pydev_step_stop = frame + info.pydev_smart_step_stop = None + self.set_trace_for_frame_and_parents(frame) + + elif info.pydev_step_cmd == CMD_SMART_STEP_INTO: + info.pydev_step_stop = None + info.pydev_smart_step_stop = frame + self.set_trace_for_frame_and_parents(frame) + + elif info.pydev_step_cmd == CMD_RUN_TO_LINE or info.pydev_step_cmd == CMD_SET_NEXT_STATEMENT: + self.set_trace_for_frame_and_parents(frame) + stop = False + response_msg = "" + try: + stop, _old_line, response_msg = self.set_next_statement(frame, event, info.pydev_func_name, info.pydev_next_line) + except ValueError as e: + response_msg = "%s" % e + finally: + seq = info.pydev_message + cmd = self.cmd_factory.make_set_next_stmnt_status_message(seq, stop, response_msg) + self.writer.add_command(cmd) + info.pydev_message = '' + + if stop: + # Uninstall the current frames tracker before running it. + frames_tracker.untrack_all() + cmd = self.cmd_factory.make_thread_run_message(get_current_thread_id(thread), info.pydev_step_cmd) + self.writer.add_command(cmd) + info.pydev_state = STATE_SUSPEND + thread.stop_reason = CMD_SET_NEXT_STATEMENT + keep_suspended = True + + else: + # Set next did not work... + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + info.pydev_state = STATE_SUSPEND + thread.stop_reason = CMD_THREAD_SUSPEND + # return to the suspend state and wait for other command (without sending any + # additional notification to the client). + return self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker) + + elif info.pydev_step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE): + back_frame = frame.f_back + force_check_project_scope = info.pydev_step_cmd == CMD_STEP_RETURN_MY_CODE + + if force_check_project_scope or self.is_files_filter_enabled: + while back_frame is not None: + if self.apply_files_filter(back_frame, back_frame.f_code.co_filename, force_check_project_scope): + frame = back_frame + back_frame = back_frame.f_back + else: + break + + if back_frame is not None: + # steps back to the same frame (in a return call it will stop in the 'back frame' for the user) + info.pydev_step_stop = frame + self.set_trace_for_frame_and_parents(frame) + else: + # No back frame?!? -- this happens in jython when we have some frame created from an awt event + # (the previous frame would be the awt event, but this doesn't make part of 'jython', only 'java') + # so, if we're doing a step return in this situation, it's the same as just making it run + info.pydev_step_stop = None + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + info.pydev_state = STATE_RUN + + del frame + cmd = self.cmd_factory.make_thread_run_message(get_current_thread_id(thread), info.pydev_step_cmd) + self.writer.add_command(cmd) + + with CustomFramesContainer.custom_frames_lock: + # The ones that remained on last_running must now be removed. + for frame_id in from_this_thread: + # print('Removing created frame: %s' % (frame_id,)) + self.writer.add_command(self.cmd_factory.make_thread_killed_message(frame_id)) + + return keep_suspended + + def do_stop_on_unhandled_exception(self, thread, frame, frames_byid, arg): + pydev_log.debug("We are stopping in unhandled exception.") + try: + add_exception_to_frame(frame, arg) + self.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) + self.do_wait_suspend(thread, frame, 'exception', arg, is_unhandled_exception=True) + except: + pydev_log.exception("We've got an error while stopping in unhandled exception: %s.", arg[0]) + finally: + remove_exception_from_frame(frame) + frame = None + + def set_trace_for_frame_and_parents(self, frame, **kwargs): + disable = kwargs.pop('disable', False) + assert not kwargs + + while frame is not None: + # Don't change the tracing on debugger-related files + file_type = self.get_file_type(frame) + + if file_type is None: + if disable: + pydev_log.debug('Disable tracing of frame: %s - %s', frame.f_code.co_filename, frame.f_code.co_name) + if frame.f_trace is not None and frame.f_trace is not NO_FTRACE: + frame.f_trace = NO_FTRACE + + elif frame.f_trace is not self.trace_dispatch: + pydev_log.debug('Set tracing of frame: %s - %s', frame.f_code.co_filename, frame.f_code.co_name) + frame.f_trace = self.trace_dispatch + else: + pydev_log.debug('SKIP set tracing of frame: %s - %s', frame.f_code.co_filename, frame.f_code.co_name) + + frame = frame.f_back + + del frame + + def _create_pydb_command_thread(self): + curr_pydb_command_thread = self.py_db_command_thread + if curr_pydb_command_thread is not None: + curr_pydb_command_thread.do_kill_pydev_thread() + + new_pydb_command_thread = self.py_db_command_thread = PyDBCommandThread(self) + new_pydb_command_thread.start() + + def _create_check_output_thread(self): + curr_output_checker_thread = self.output_checker_thread + if curr_output_checker_thread is not None: + curr_output_checker_thread.do_kill_pydev_thread() + + output_checker_thread = self.output_checker_thread = CheckAliveThread(self) + output_checker_thread.start() + + def start_auxiliary_daemon_threads(self): + self._create_pydb_command_thread() + self._create_check_output_thread() + + def prepare_to_run(self): + ''' Shared code to prepare debugging by installing traces and registering threads ''' + self.patch_threads() + self.start_auxiliary_daemon_threads() + + def patch_threads(self): + try: + # not available in jython! + threading.settrace(self.trace_dispatch) # for all future threads + except: + pass + + from _pydev_bundle.pydev_monkey import patch_thread_modules + patch_thread_modules() + + def run(self, file, globals=None, locals=None, is_module=False, set_trace=True): + module_name = None + entry_point_fn = '' + if is_module: + # When launching with `python -m `, python automatically adds + # an empty path to the PYTHONPATH which resolves files in the current + # directory, so, depending how pydevd itself is launched, we may need + # to manually add such an entry to properly resolve modules in the + # current directory (see: https://github.com/Microsoft/ptvsd/issues/1010). + if '' not in sys.path: + sys.path.insert(0, '') + file, _, entry_point_fn = file.partition(':') + module_name = file + filename = get_fullname(file) + if filename is None: + mod_dir = get_package_dir(module_name) + if mod_dir is None: + sys.stderr.write("No module named %s\n" % file) + return + else: + filename = get_fullname("%s.__main__" % module_name) + if filename is None: + sys.stderr.write("No module named %s\n" % file) + return + else: + file = filename + else: + file = filename + mod_dir = os.path.dirname(filename) + main_py = os.path.join(mod_dir, '__main__.py') + main_pyc = os.path.join(mod_dir, '__main__.pyc') + if filename.endswith('__init__.pyc'): + if os.path.exists(main_pyc): + filename = main_pyc + elif os.path.exists(main_py): + filename = main_py + elif filename.endswith('__init__.py'): + if os.path.exists(main_pyc) and not os.path.exists(main_py): + filename = main_pyc + elif os.path.exists(main_py): + filename = main_py + + sys.argv[0] = filename + + if os.path.isdir(file): + new_target = os.path.join(file, '__main__.py') + if os.path.isfile(new_target): + file = new_target + + m = None + if globals is None: + m = save_main_module(file, 'pydevd') + globals = m.__dict__ + try: + globals['__builtins__'] = __builtins__ + except NameError: + pass # Not there on Jython... + + if locals is None: + locals = globals + + # Predefined (writable) attributes: __name__ is the module's name; + # __doc__ is the module's documentation string, or None if unavailable; + # __file__ is the pathname of the file from which the module was loaded, + # if it was loaded from a file. The __file__ attribute is not present for + # C modules that are statically linked into the interpreter; for extension modules + # loaded dynamically from a shared library, it is the pathname of the shared library file. + + # I think this is an ugly hack, bug it works (seems to) for the bug that says that sys.path should be the same in + # debug and run. + if sys.path[0] != '' and m is not None and m.__file__.startswith(sys.path[0]): + # print >> sys.stderr, 'Deleting: ', sys.path[0] + del sys.path[0] + + if not is_module: + # now, the local directory has to be added to the pythonpath + # sys.path.insert(0, os.getcwd()) + # Changed: it's not the local directory, but the directory of the file launched + # The file being run must be in the pythonpath (even if it was not before) + sys.path.insert(0, os.path.split(rPath(file))[0]) + + if set_trace: + + while not self.ready_to_run: + time.sleep(0.1) # busy wait until we receive run command + + # call prepare_to_run when we already have all information about breakpoints + self.prepare_to_run() + + t = threadingCurrentThread() + thread_id = get_current_thread_id(t) + + if self.thread_analyser is not None: + wrap_threads() + self.thread_analyser.set_start_time(cur_time()) + send_message("threading_event", 0, t.getName(), thread_id, "thread", "start", file, 1, None, parent=thread_id) + + if self.asyncio_analyser is not None: + # we don't have main thread in asyncio graph, so we should add a fake event + send_message("asyncio_event", 0, "Task", "Task", "thread", "stop", file, 1, frame=None, parent=None) + + try: + if INTERACTIVE_MODE_AVAILABLE: + self.init_matplotlib_support() + except: + sys.stderr.write("Matplotlib support in debugger failed\n") + pydev_log.exception() + + if hasattr(sys, 'exc_clear'): + # we should clean exception information in Python 2, before user's code execution + sys.exc_clear() + + # Notify that the main thread is created. + self.notify_thread_created(thread_id, t) + + # Note: important: set the tracing right before calling _exec. + if set_trace: + self.enable_tracing() + + return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) + + def _exec(self, is_module, entry_point_fn, module_name, file, globals, locals): + ''' + This function should have frames tracked by unhandled exceptions (the `_exec` name is important). + ''' + if not is_module: + pydev_imports.execfile(file, globals, locals) # execute the script + else: + # treat ':' as a separator between module and entry point function + # if there is no entry point we run we same as with -m switch. Otherwise we perform + # an import and execute the entry point + if entry_point_fn: + mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=globals, locals=locals) + func = getattr(mod, entry_point_fn) + func() + else: + # Run with the -m switch + import runpy + if hasattr(runpy, '_run_module_as_main'): + # Newer versions of Python actually use this when the -m switch is used. + if sys.version_info[:2] <= (2, 6): + runpy._run_module_as_main(module_name, set_argv0=False) + else: + runpy._run_module_as_main(module_name, alter_argv=False) + else: + runpy.run_module(module_name) + return globals + + def exiting(self): + # Either or both standard streams can be closed at this point, + # in which case flush() will fail. + try: + sys.stdout.flush() + except: + pass + try: + sys.stderr.flush() + except: + pass + + self.check_output_redirect() + cmd = self.cmd_factory.make_exit_message() + self.writer.add_command(cmd) + + def wait_for_commands(self, globals): + self._activate_mpl_if_needed() + + thread = threading.currentThread() + from _pydevd_bundle import pydevd_frame_utils + frame = pydevd_frame_utils.Frame(None, -1, pydevd_frame_utils.FCode("Console", + os.path.abspath(os.path.dirname(__file__))), globals, globals) + thread_id = get_current_thread_id(thread) + self.add_fake_frame(thread_id, id(frame), frame) + + cmd = self.cmd_factory.make_show_console_message(self, thread_id, frame) + self.writer.add_command(cmd) + + while True: + if self.mpl_in_use: + # call input hooks if only matplotlib is in use + self._call_mpl_hook() + self.process_internal_commands() + time.sleep(0.01) + + +def set_debug(setup): + setup['DEBUG_RECORD_SOCKET_READS'] = True + setup['DEBUG_TRACE_BREAKPOINTS'] = 1 + setup['DEBUG_TRACE_LEVEL'] = 3 + + +def enable_qt_support(qt_support_mode): + from _pydev_bundle import pydev_monkey_qt + pydev_monkey_qt.patch_qt(qt_support_mode) + + +def dump_threads(stream=None): + ''' + Helper to dump thread info (default is printing to stderr). + ''' + pydevd_utils.dump_threads(stream) + + +def usage(doExit=0): + sys.stdout.write('Usage:\n') + sys.stdout.write('pydevd.py --port N [(--client hostname) | --server] --file executable [file_options]\n') + if doExit: + sys.exit(0) + + +class _CustomWriter(object): + + def __init__(self, out_ctx, wrap_stream, wrap_buffer, on_write=None): + ''' + :param out_ctx: + 1=stdout and 2=stderr + + :param wrap_stream: + Either sys.stdout or sys.stderr. + + :param bool wrap_buffer: + If True the buffer attribute (which wraps writing bytes) should be + wrapped. + + :param callable(str) on_write: + May be a custom callable to be called when to write something. + If not passed the default implementation will create an io message + and send it through the debugger. + ''' + self.encoding = getattr(wrap_stream, 'encoding', os.environ.get('PYTHONIOENCODING', 'utf-8')) + self._out_ctx = out_ctx + if wrap_buffer: + self.buffer = _CustomWriter(out_ctx, wrap_stream, wrap_buffer=False, on_write=on_write) + self._on_write = on_write + + def flush(self): + pass # no-op here + + def write(self, s): + if self._on_write is not None: + self._on_write(s) + return + + if s: + if IS_PY2: + # Need s in bytes + if isinstance(s, unicode): # noqa + # Note: python 2.6 does not accept the "errors" keyword. + s = s.encode('utf-8', 'replace') + else: + # Need s in str + if isinstance(s, bytes): + s = s.decode(self.encoding, errors='replace') + + py_db = get_global_debugger() + if py_db is not None: + # Note that the actual message contents will be a xml with utf-8, although + # the entry is str on py3 and bytes on py2. + cmd = py_db.cmd_factory.make_io_message(s, self._out_ctx) + py_db.writer.add_command(cmd) + + +def init_stdout_redirect(on_write=None): + if not hasattr(sys, '_pydevd_out_buffer_'): + wrap_buffer = True if not IS_PY2 else False + original = sys.stdout + sys._pydevd_out_buffer_ = _CustomWriter(1, original, wrap_buffer, on_write) + sys.stdout_original = original + sys.stdout = pydevd_io.IORedirector(original, sys._pydevd_out_buffer_, wrap_buffer) # @UndefinedVariable + + +def init_stderr_redirect(on_write=None): + if not hasattr(sys, '_pydevd_err_buffer_'): + wrap_buffer = True if not IS_PY2 else False + original = sys.stderr + sys._pydevd_err_buffer_ = _CustomWriter(2, original, wrap_buffer, on_write) + sys.stderr_original = original + sys.stderr = pydevd_io.IORedirector(original, sys._pydevd_err_buffer_, wrap_buffer) # @UndefinedVariable + + +def _enable_attach(address): + ''' + Starts accepting connections at the given host/port. The debugger will not be initialized nor + configured, it'll only start accepting connections (and will have the tracing setup in this + thread). + + Meant to be used with the DAP (Debug Adapter Protocol) with _wait_for_attach(). + + :param address: (host, port) + :type address: tuple(str, int) + ''' + host = address[0] + port = int(address[1]) + + if _debugger_setup: + if port != SetupHolder.setup['port']: + raise AssertionError('Unable to listen in port: %s (already listening in port: %s)' % (port, SetupHolder.setup['port'])) + settrace(host=host, port=port, suspend=False, wait_for_ready_to_run=False, block_until_connected=False) + + +def _wait_for_attach(): + ''' + Meant to be called after _enable_attach() -- the current thread will only unblock after a + connection is in place and the the DAP (Debug Adapter Protocol) sends the ConfigurationDone + request. + ''' + py_db = get_global_debugger() + if py_db is None: + raise AssertionError('Debugger still not created. Please use _enable_attach() before using _wait_for_attach().') + + py_db.block_until_configuration_done() + + +#======================================================================================================================= +# settrace +#======================================================================================================================= +def settrace( + host=None, + stdoutToServer=False, + stderrToServer=False, + port=5678, + suspend=True, + trace_only_current_thread=False, + overwrite_prev_trace=False, + patch_multiprocessing=False, + stop_at_frame=None, + block_until_connected=True, + wait_for_ready_to_run=True, + ): + '''Sets the tracing function with the pydev debug function and initializes needed facilities. + + @param host: the user may specify another host, if the debug server is not in the same machine (default is the local + host) + + @param stdoutToServer: when this is true, the stdout is passed to the debug server + + @param stderrToServer: when this is true, the stderr is passed to the debug server + so that they are printed in its console and not in this process console. + + @param port: specifies which port to use for communicating with the server (note that the server must be started + in the same port). @note: currently it's hard-coded at 5678 in the client + + @param suspend: whether a breakpoint should be emulated as soon as this function is called. + + @param trace_only_current_thread: determines if only the current thread will be traced or all current and future + threads will also have the tracing enabled. + + @param overwrite_prev_trace: deprecated + + @param patch_multiprocessing: if True we'll patch the functions which create new processes so that launched + processes are debugged. + + @param stop_at_frame: if passed it'll stop at the given frame, otherwise it'll stop in the function which + called this method. + + @param wait_for_ready_to_run: if True settrace will block until the ready_to_run flag is set to True, + otherwise, it'll set ready_to_run to True and this function won't block. + + Note that if wait_for_ready_to_run == False, there are no guarantees that the debugger is synchronized + with what's configured in the client (IDE), the only guarantee is that when leaving this function + the debugger will be already connected. + ''' + with _set_trace_lock: + _locked_settrace( + host, + stdoutToServer, + stderrToServer, + port, + suspend, + trace_only_current_thread, + patch_multiprocessing, + stop_at_frame, + block_until_connected, + wait_for_ready_to_run, + ) + + +_set_trace_lock = thread.allocate_lock() + + +def _locked_settrace( + host, + stdoutToServer, + stderrToServer, + port, + suspend, + trace_only_current_thread, + patch_multiprocessing, + stop_at_frame, + block_until_connected, + wait_for_ready_to_run, + ): + if patch_multiprocessing: + try: + from _pydev_bundle import pydev_monkey + except: + pass + else: + pydev_monkey.patch_new_process_functions() + + if host is None: + from _pydev_bundle import pydev_localhost + host = pydev_localhost.get_localhost() + + global _debugger_setup + global bufferStdOutToServer + global bufferStdErrToServer + + if not _debugger_setup: + pydevd_vm_type.setup_type() + + if SetupHolder.setup is None: + setup = { + 'client': host, # dispatch expects client to be set to the host address when server is False + 'server': False, + 'port': int(port), + 'multiprocess': patch_multiprocessing, + } + SetupHolder.setup = setup + + debugger = get_global_debugger() + if debugger is None: + debugger = PyDB() + if block_until_connected: + debugger.connect(host, port) # Note: connect can raise error. + else: + # Create a dummy writer and wait for the real connection. + debugger.writer = WriterThread(NULL, terminate_on_socket_close=False) + debugger.create_wait_for_connection_thread() + + # Mark connected only if it actually succeeded. + _debugger_setup = True + bufferStdOutToServer = stdoutToServer + bufferStdErrToServer = stderrToServer + + if bufferStdOutToServer: + init_stdout_redirect() + + if bufferStdErrToServer: + init_stderr_redirect() + + patch_stdin() + + t = threadingCurrentThread() + additional_info = set_additional_thread_info(t) + + if not wait_for_ready_to_run: + debugger.ready_to_run = True + + while not debugger.ready_to_run: + time.sleep(0.1) # busy wait until we receive run command + + debugger.start_auxiliary_daemon_threads() + + if trace_only_current_thread: + debugger.enable_tracing() + else: + # Trace future threads. + debugger.patch_threads() + + debugger.enable_tracing(debugger.trace_dispatch, apply_to_all_threads=True) + + # As this is the first connection, also set tracing for any untraced threads + debugger.set_tracing_for_untraced_contexts() + + debugger.set_trace_for_frame_and_parents(get_frame().f_back) + + with CustomFramesContainer.custom_frames_lock: # @UndefinedVariable + for _frameId, custom_frame in dict_iter_items(CustomFramesContainer.custom_frames): + debugger.set_trace_for_frame_and_parents(custom_frame.frame) + + # Stop the tracing as the last thing before the actual shutdown for a clean exit. + atexit.register(stoptrace) + + else: + # ok, we're already in debug mode, with all set, so, let's just set the break + debugger = get_global_debugger() + + debugger.set_trace_for_frame_and_parents(get_frame().f_back) + + t = threadingCurrentThread() + additional_info = set_additional_thread_info(t) + + if trace_only_current_thread: + debugger.enable_tracing() + else: + # Trace future threads. + debugger.patch_threads() + debugger.enable_tracing(debugger.trace_dispatch, apply_to_all_threads=True) + + # Suspend as the last thing after all tracing is in place. + if suspend: + if stop_at_frame is not None: + # If the step was set we have to go to run state and + # set the proper frame for it to stop. + additional_info.pydev_state = STATE_RUN + additional_info.pydev_original_step_cmd = CMD_STEP_OVER + additional_info.pydev_step_cmd = CMD_STEP_OVER + additional_info.pydev_step_stop = stop_at_frame + additional_info.suspend_type = PYTHON_SUSPEND + else: + # Ask to break as soon as possible. + debugger.set_suspend(t, CMD_SET_BREAK) + + +def stoptrace(): + global _debugger_setup + if _debugger_setup: + pydevd_tracing.restore_sys_set_trace_func() + sys.settrace(None) + try: + # not available in jython! + threading.settrace(None) # for all future threads + except: + pass + + from _pydev_bundle.pydev_monkey import undo_patch_thread_modules + undo_patch_thread_modules() + + debugger = get_global_debugger() + + if debugger: + + debugger.set_trace_for_frame_and_parents(get_frame(), disable=True) + debugger.exiting() + + kill_all_pydev_threads() + + _debugger_setup = False + + +class Dispatcher(object): + + def __init__(self): + self.port = None + + def connect(self, host, port): + self.host = host + self.port = port + self.client = start_client(self.host, self.port) + self.reader = DispatchReader(self) + self.reader.pydev_do_not_trace = False # we run reader in the same thread so we don't want to loose tracing + self.reader.run() + + def close(self): + try: + self.reader.do_kill_pydev_thread() + except : + pass + + +class DispatchReader(ReaderThread): + + def __init__(self, dispatcher): + self.dispatcher = dispatcher + ReaderThread.__init__(self, self.dispatcher.client) + + @overrides(ReaderThread._on_run) + def _on_run(self): + dummy_thread = threading.currentThread() + dummy_thread.is_pydev_daemon_thread = False + return ReaderThread._on_run(self) + + def handle_except(self): + ReaderThread.handle_except(self) + + def process_command(self, cmd_id, seq, text): + if cmd_id == 99: + self.dispatcher.port = int(text) + self.killReceived = True + + +DISPATCH_APPROACH_NEW_CONNECTION = 1 # Used by PyDev +DISPATCH_APPROACH_EXISTING_CONNECTION = 2 # Used by PyCharm +DISPATCH_APPROACH = DISPATCH_APPROACH_NEW_CONNECTION + + +def dispatch(): + setup = SetupHolder.setup + host = setup['client'] + port = setup['port'] + if DISPATCH_APPROACH == DISPATCH_APPROACH_EXISTING_CONNECTION: + dispatcher = Dispatcher() + try: + dispatcher.connect(host, port) + port = dispatcher.port + finally: + dispatcher.close() + return host, port + + +def settrace_forked(): + ''' + When creating a fork from a process in the debugger, we need to reset the whole debugger environment! + ''' + from _pydevd_bundle.pydevd_constants import GlobalDebuggerHolder + GlobalDebuggerHolder.global_dbg = None + threading.current_thread().additional_info = None + PyDBDaemonThread.created_pydb_daemon_threads = {} + + from _pydevd_frame_eval.pydevd_frame_eval_main import clear_thread_local_info + host, port = dispatch() + + import pydevd_tracing + pydevd_tracing.restore_sys_set_trace_func() + + if port is not None: + global _debugger_setup + _debugger_setup = False + + custom_frames_container_init() + + if clear_thread_local_info is not None: + clear_thread_local_info() + + settrace( + host, + port=port, + suspend=False, + trace_only_current_thread=False, + overwrite_prev_trace=True, + patch_multiprocessing=True, + ) + + +#======================================================================================================================= +# SetupHolder +#======================================================================================================================= +class SetupHolder: + + setup = None + + +def apply_debugger_options(setup_options): + """ + + :type setup_options: dict[str, bool] + """ + default_options = {'save-signatures': False, 'qt-support': ''} + default_options.update(setup_options) + setup_options = default_options + + debugger = GetGlobalDebugger() + if setup_options['save-signatures']: + if pydevd_vm_type.get_vm_type() == pydevd_vm_type.PydevdVmType.JYTHON: + sys.stderr.write("Collecting run-time type information is not supported for Jython\n") + else: + # Only import it if we're going to use it! + from _pydevd_bundle.pydevd_signature import SignatureFactory + debugger.signature_factory = SignatureFactory() + + if setup_options['qt-support']: + enable_qt_support(setup_options['qt-support']) + + +@call_only_once +def patch_stdin(): + _internal_patch_stdin(None, sys, getpass_mod) + + +def _internal_patch_stdin(py_db=None, sys=None, getpass_mod=None): + ''' + Note: don't use this function directly, use `patch_stdin()` instead. + (this function is only meant to be used on test-cases to avoid patching the actual globals). + ''' + # Patch stdin so that we notify when readline() is called. + original_sys_stdin = sys.stdin + debug_console_stdin = DebugConsoleStdIn(py_db, original_sys_stdin) + sys.stdin = debug_console_stdin + + _original_getpass = getpass_mod.getpass + + @functools.wraps(_original_getpass) + def getpass(*args, **kwargs): + with DebugConsoleStdIn.notify_input_requested(debug_console_stdin): + try: + curr_stdin = sys.stdin + if curr_stdin is debug_console_stdin: + sys.stdin = original_sys_stdin + return _original_getpass(*args, **kwargs) + finally: + sys.stdin = curr_stdin + + getpass_mod.getpass = getpass + +# Dispatch on_debugger_modules_loaded here, after all primary py_db modules are loaded + + +for handler in pydevd_extension_utils.extensions_of_type(DebuggerEventHandler): + handler.on_debugger_modules_loaded(debugger_version=__version__) + + +#======================================================================================================================= +# main +#======================================================================================================================= +def main(): + + # parse the command line. --file is our last argument that is required + try: + from _pydevd_bundle.pydevd_command_line_handling import process_command_line + setup = process_command_line(sys.argv) + SetupHolder.setup = setup + except ValueError: + pydev_log.exception() + usage(1) + + if setup['print-in-debugger-startup']: + try: + pid = ' (pid: %s)' % os.getpid() + except: + pid = '' + sys.stderr.write("pydev debugger: starting%s\n" % pid) + + pydev_log.debug("Executing file %s" % setup['file']) + pydev_log.debug("arguments: %s" % str(sys.argv)) + + pydevd_vm_type.setup_type(setup.get('vm_type', None)) + + if SHOW_DEBUG_INFO_ENV: + set_debug(setup) + + DebugInfoHolder.DEBUG_RECORD_SOCKET_READS = setup.get('DEBUG_RECORD_SOCKET_READS', DebugInfoHolder.DEBUG_RECORD_SOCKET_READS) + DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = setup.get('DEBUG_TRACE_BREAKPOINTS', DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS) + DebugInfoHolder.DEBUG_TRACE_LEVEL = setup.get('DEBUG_TRACE_LEVEL', DebugInfoHolder.DEBUG_TRACE_LEVEL) + + port = setup['port'] + host = setup['client'] + f = setup['file'] + fix_app_engine_debug = False + + debugger = get_global_debugger() + if debugger is None: + debugger = PyDB() + + try: + from _pydev_bundle import pydev_monkey + except: + pass # Not usable on jython 2.1 + else: + if setup['multiprocess']: # PyDev + pydev_monkey.patch_new_process_functions() + + elif setup['multiproc']: # PyCharm + pydev_log.debug("Started in multiproc mode\n") + global DISPATCH_APPROACH + DISPATCH_APPROACH = DISPATCH_APPROACH_EXISTING_CONNECTION + + dispatcher = Dispatcher() + try: + dispatcher.connect(host, port) + if dispatcher.port is not None: + port = dispatcher.port + pydev_log.debug("Received port %d\n" % port) + pydev_log.info("pydev debugger: process %d is connecting\n" % os.getpid()) + + try: + pydev_monkey.patch_new_process_functions() + except: + pydev_log.exception("Error patching process functions.") + else: + pydev_log.critical("pydev debugger: couldn't get port for new debug process.") + finally: + dispatcher.close() + else: + try: + pydev_monkey.patch_new_process_functions_with_warning() + except: + pydev_log.exception("Error patching process functions.") + + # Only do this patching if we're not running with multiprocess turned on. + if f.find('dev_appserver.py') != -1: + if os.path.basename(f).startswith('dev_appserver.py'): + appserver_dir = os.path.dirname(f) + version_file = os.path.join(appserver_dir, 'VERSION') + if os.path.exists(version_file): + try: + stream = open(version_file, 'r') + try: + for line in stream.read().splitlines(): + line = line.strip() + if line.startswith('release:'): + line = line[8:].strip() + version = line.replace('"', '') + version = version.split('.') + if int(version[0]) > 1: + fix_app_engine_debug = True + + elif int(version[0]) == 1: + if int(version[1]) >= 7: + # Only fix from 1.7 onwards + fix_app_engine_debug = True + break + finally: + stream.close() + except: + pydev_log.exception() + + try: + # In the default run (i.e.: run directly on debug mode), we try to patch stackless as soon as possible + # on a run where we have a remote debug, we may have to be more careful because patching stackless means + # that if the user already had a stackless.set_schedule_callback installed, he'd loose it and would need + # to call it again (because stackless provides no way of getting the last function which was registered + # in set_schedule_callback). + # + # So, ideally, if there's an application using stackless and the application wants to use the remote debugger + # and benefit from stackless debugging, the application itself must call: + # + # import pydevd_stackless + # pydevd_stackless.patch_stackless() + # + # itself to be able to benefit from seeing the tasklets created before the remote debugger is attached. + from _pydevd_bundle import pydevd_stackless + pydevd_stackless.patch_stackless() + except: + # It's ok not having stackless there... + try: + if hasattr(sys, 'exc_clear'): + sys.exc_clear() # the exception information should be cleaned in Python 2 + except: + pass + + is_module = setup['module'] + patch_stdin() + + if setup['json-dap']: + PyDevdAPI().set_protocol(debugger, 0, JSON_PROTOCOL) + + if fix_app_engine_debug: + sys.stderr.write("pydev debugger: google app engine integration enabled\n") + curr_dir = os.path.dirname(__file__) + app_engine_startup_file = os.path.join(curr_dir, 'pydev_app_engine_debug_startup.py') + + sys.argv.insert(1, '--python_startup_script=' + app_engine_startup_file) + import json + setup['pydevd'] = __file__ + sys.argv.insert(2, '--python_startup_args=%s' % json.dumps(setup),) + sys.argv.insert(3, '--automatic_restart=no') + sys.argv.insert(4, '--max_module_instances=1') + + # Run the dev_appserver + debugger.run(setup['file'], None, None, is_module, set_trace=False) + else: + if setup['save-threading']: + debugger.thread_analyser = ThreadingLogger() + if setup['save-asyncio']: + if IS_PY34_OR_GREATER: + debugger.asyncio_analyser = AsyncioLogger() + + apply_debugger_options(setup) + + try: + debugger.connect(host, port) + except: + sys.stderr.write("Could not connect to %s: %s\n" % (host, port)) + pydev_log.exception() + sys.exit(1) + + global _debugger_setup + _debugger_setup = True # Mark that the debugger is setup when started from the ide. + + globals = debugger.run(setup['file'], None, None, is_module) + + if setup['cmd-line']: + debugger.wait_for_commands(globals) + + +if __name__ == '__main__': + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/README.txt b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/README.txt new file mode 100644 index 0000000..138c103 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/README.txt @@ -0,0 +1,11 @@ +This folder contains the utilities to attach a target process to the pydev debugger. + +The main module to be called for the attach is: + +attach_pydevd.py + +it should be called as; + +python attach_pydevd.py --port 5678 --pid 1234 + +Note that the client is responsible for having a remote debugger alive in the given port for the attach to work. \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_always_live_program.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_always_live_program.py new file mode 100644 index 0000000..6369508 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_always_live_program.py @@ -0,0 +1,32 @@ +import sys +import struct +print('Executable: %s' % sys.executable) +import os +def loop_in_thread(): + while True: + import time + time.sleep(.5) + sys.stdout.write('#') + sys.stdout.flush() + +import threading +threading.Thread(target=loop_in_thread).start() + + +def is_python_64bit(): + return (struct.calcsize('P') == 8) + +print('Is 64: %s' % is_python_64bit()) + +if __name__ == '__main__': + print('pid:%s' % (os.getpid())) + i = 0 + while True: + i += 1 + import time + time.sleep(.5) + sys.stdout.write('.') + sys.stdout.flush() + if i % 40 == 0: + sys.stdout.write('\n') + sys.stdout.flush() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_check.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_check.py new file mode 100644 index 0000000..82f8e12 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_check.py @@ -0,0 +1,2 @@ +import add_code_to_python_process +print add_code_to_python_process.run_python_code(3736, "print(20)", connect_debugger_tracing=False) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process.py new file mode 100644 index 0000000..daeee93 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process.py @@ -0,0 +1,9 @@ +import subprocess +import sys +print(sys.executable) + +if __name__ == '__main__': + p = subprocess.Popen([sys.executable, '-u', '_always_live_program.py']) + import attach_pydevd + attach_pydevd.main(attach_pydevd.process_command_line(['--pid', str(p.pid), '--protocol', 'http'])) + p.wait() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process_linux.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process_linux.py new file mode 100644 index 0000000..842e71a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/_test_attach_to_process_linux.py @@ -0,0 +1,74 @@ +''' +This module is just for testing concepts. It should be erased later on. + +Experiments: + +// gdb -p 4957 +// call dlopen("/home/fabioz/Desktop/dev/PyDev.Debugger/pydevd_attach_to_process/linux/attach_linux.so", 2) +// call dlsym($1, "hello") +// call hello() + + +// call open("/home/fabioz/Desktop/dev/PyDev.Debugger/pydevd_attach_to_process/linux/attach_linux.so", 2) +// call mmap(0, 6672, 1 | 2 | 4, 1, 3 , 0) +// add-symbol-file +// cat /proc/pid/maps + +// call dlopen("/home/fabioz/Desktop/dev/PyDev.Debugger/pydevd_attach_to_process/linux/attach_linux.so", 1|8) +// call dlsym($1, "hello") +// call hello() +''' + +import subprocess +import sys +import os +import time + +if __name__ == '__main__': + + linux_dir = os.path.join(os.path.dirname(__file__), 'linux') + os.chdir(linux_dir) + so_location = os.path.join(linux_dir, 'attach_linux.so') + try: + os.remove(so_location) + except: + pass + subprocess.call('g++ -shared -o attach_linux.so -fPIC -nostartfiles attach_linux.c'.split()) + print('Finished compiling') + assert os.path.exists('/home/fabioz/Desktop/dev/PyDev.Debugger/pydevd_attach_to_process/linux/attach_linux.so') + os.chdir(os.path.dirname(linux_dir)) +# import attach_pydevd +# attach_pydevd.main(attach_pydevd.process_command_line(['--pid', str(p.pid)])) + p = subprocess.Popen([sys.executable, '-u', '_always_live_program.py']) + print('Size of file: %s' % (os.stat(so_location).st_size)) + + # (gdb) set architecture + # Requires an argument. Valid arguments are i386, i386:x86-64, i386:x64-32, i8086, i386:intel, i386:x86-64:intel, i386:x64-32:intel, i386:nacl, i386:x86-64:nacl, i386:x64-32:nacl, auto. + + cmd = [ + 'gdb', + '--pid', + str(p.pid), + '--batch', + ] + + arch = 'i386:x86-64' + if arch: + cmd.extend(["--eval-command='set architecture %s'" % arch]) + + cmd.extend([ + "--eval-command='call dlopen(\"/home/fabioz/Desktop/dev/PyDev.Debugger/pydevd_attach_to_process/linux/attach_linux.so\", 2)'", + "--eval-command='call (int)DoAttach(1, \"print(\\\"check11111check\\\")\", 0)'", + # "--eval-command='call (int)SetSysTraceFunc(1, 0)'", -- never call this way, always use "--command='...gdb_threads_settrace.py'", + # So that threads are all stopped! + ]) + + print(' '.join(cmd)) + time.sleep(.5) + env = os.environ.copy() + env.pop('PYTHONIOENCODING', None) + env.pop('PYTHONPATH', None) + p2 = subprocess.call(' '.join(cmd), env=env, shell=True) + + time.sleep(1) + p.kill() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py new file mode 100644 index 0000000..d2f8e40 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/add_code_to_python_process.py @@ -0,0 +1,637 @@ +r''' +Copyright: Brainwy Software Ltda. + +License: EPL. +============= + +Works for Windows relying on a fork of winappdbg which works in py2/3 (at least for the part we're interested in). + +See: https://github.com/fabioz/winappdbg (py3 branch). +Note that the official branch for winappdbg is: https://github.com/MarioVilas/winappdbg, which should be used when it works in Py3. +A private copy is added here to make deployment easier, but changes should always be done upstream first. + +Works for Linux relying on gdb. + +Limitations: +============ + + Linux: + ------ + + 1. It possible that ptrace is disabled: /etc/sysctl.d/10-ptrace.conf + + Note that even enabling it in /etc/sysctl.d/10-ptrace.conf (i.e.: making the + ptrace_scope=0), it's possible that we need to run the application that'll use ptrace (or + gdb in this case) as root (so, we must sudo the python which'll run this module). + + 2. It currently doesn't work in debug builds (i.e.: python_d) + + +Other implementations: +- pyrasite.com: + GPL + Windows/linux (in Linux it also uses gdb to connect -- although specifics are different as we use a dll to execute + code with other threads stopped). It's Windows approach is more limited because it doesn't seem to deal properly with + Python 3 if threading is disabled. + +- https://github.com/google/pyringe: + Apache v2. + Only linux/Python 2. + +- http://pytools.codeplex.com: + Apache V2 + Windows Only (but supports mixed mode debugging) + Our own code relies heavily on a part of it: http://pytools.codeplex.com/SourceControl/latest#Python/Product/PyDebugAttach/PyDebugAttach.cpp + to overcome some limitations of attaching and running code in the target python executable on Python 3. + See: attach.cpp + +Linux: References if we wanted to use a pure-python debugger: + https://bitbucket.org/haypo/python-ptrace/ + http://stackoverflow.com/questions/7841573/how-to-get-an-error-message-for-errno-value-in-python + Jugaad: + https://www.defcon.org/images/defcon-19/dc-19-presentations/Jakhar/DEFCON-19-Jakhar-Jugaad-Linux-Thread-Injection.pdf + https://github.com/aseemjakhar/jugaad + +Something else (general and not Python related): +- http://www.codeproject.com/Articles/4610/Three-Ways-to-Inject-Your-Code-into-Another-Proces + +Other references: +- https://github.com/haypo/faulthandler +- http://nedbatchelder.com/text/trace-function.html +- https://github.com/python-git/python/blob/master/Python/sysmodule.c (sys_settrace) +- https://github.com/python-git/python/blob/master/Python/ceval.c (PyEval_SetTrace) +- https://github.com/python-git/python/blob/master/Python/thread.c (PyThread_get_key_value) + + +To build the dlls needed on windows, visual studio express 13 was used (see compile_dll.bat) + +See: attach_pydevd.py to attach the pydev debugger to a running python process. +''' + +# Note: to work with nasm compiling asm to code and decompiling to see asm with shellcode: +# x:\nasm\nasm-2.07-win32\nasm-2.07\nasm.exe +# nasm.asm&x:\nasm\nasm-2.07-win32\nasm-2.07\ndisasm.exe -b arch nasm +import ctypes +import os +import struct +import subprocess +import sys +import time + + +class AutoExit(object): + + def __init__(self, on_exit): + self.on_exit = on_exit + + def __enter__(self): + pass + + def __exit__(self, *args): + self.on_exit() + + +class GenShellCodeHelper(object): + + def __init__(self, is_64): + from winappdbg import compat + self.is_64 = is_64 + self._code = [] + if not is_64: + self._translations = { + 'push esi': b'\x56', + 'push eax': b'\x50', + 'push ebp': b'\x55', + 'push ebx': b'\x53', + + 'pop esi': b'\x5E', + 'pop eax': b'\x58', + 'pop ebp': b'\x5D', + 'pop ebx': b'\x5B', + + 'mov esi': b'\xBE', + 'mov eax': b'\xB8', + 'mov ebp': b'\xBD', + 'mov ebx': b'\xBB', + + 'call ebp': b'\xFF\xD5', + 'call eax': b'\xFF\xD0', + 'call ebx': b'\xFF\xD3', + + 'mov ebx,eax': b'\x89\xC3', + 'mov eax,ebx': b'\x89\xD8', + 'mov ebp,esp': b'\x89\xE5', + 'mov esp,ebp': b'\x89\xEC', + 'push dword': b'\x68', + + 'mov ebp,eax': b'\x89\xC5', + 'mov eax,ebp': b'\x89\xE8', + + 'ret': b'\xc3', + } + else: + # Translate 64 bits + self._translations = { + 'push rsi': b'\x56', + 'push rax': b'\x50', + 'push rbp': b'\x55', + 'push rbx': b'\x53', + 'push rsp': b'\x54', + 'push rdi': b'\x57', + + 'pop rsi': b'\x5E', + 'pop rax': b'\x58', + 'pop rbp': b'\x5D', + 'pop rbx': b'\x5B', + 'pop rsp': b'\x5C', + 'pop rdi': b'\x5F', + + 'mov rsi': b'\x48\xBE', + 'mov rax': b'\x48\xB8', + 'mov rbp': b'\x48\xBD', + 'mov rbx': b'\x48\xBB', + 'mov rdi': b'\x48\xBF', + 'mov rcx': b'\x48\xB9', + 'mov rdx': b'\x48\xBA', + + 'call rbp': b'\xFF\xD5', + 'call rax': b'\xFF\xD0', + 'call rbx': b'\xFF\xD3', + + 'mov rbx,rax': b'\x48\x89\xC3', + 'mov rax,rbx': b'\x48\x89\xD8', + 'mov rbp,rsp': b'\x48\x89\xE5', + 'mov rsp,rbp': b'\x48\x89\xEC', + 'mov rcx,rbp': b'\x48\x89\xE9', + + 'mov rbp,rax': b'\x48\x89\xC5', + 'mov rax,rbp': b'\x48\x89\xE8', + + 'mov rdi,rbp': b'\x48\x89\xEF', + + 'ret': b'\xc3', + } + + def push_addr(self, addr): + self._code.append(self.translate('push dword')) + self._code.append(addr) + + def push(self, register): + self._code.append(self.translate('push %s' % register)) + return AutoExit(lambda: self.pop(register)) + + def pop(self, register): + self._code.append(self.translate('pop %s' % register)) + + def mov_to_register_addr(self, register, addr): + self._code.append(self.translate('mov %s' % register)) + self._code.append(addr) + + def mov_register_to_from(self, register_to, register_from): + self._code.append(self.translate('mov %s,%s' % (register_to, register_from))) + + def call(self, register): + self._code.append(self.translate('call %s' % register)) + + def preserve_stack(self): + self.mov_register_to_from('ebp', 'esp') + return AutoExit(lambda: self.restore_stack()) + + def restore_stack(self): + self.mov_register_to_from('esp', 'ebp') + + def ret(self): + self._code.append(self.translate('ret')) + + def get_code(self): + return b''.join(self._code) + + def translate(self, code): + return self._translations[code] + + def pack_address(self, address): + if self.is_64: + return struct.pack(' + # main(process_command_line(sys.argv[1:])) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\attach_pydevd.py", line 68, in main + # setup['pid'], python_code, connect_debugger_tracing=True, show_debug_info=show_debug_info_on_target_process) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\add_code_to_python_process.py", line 392, in run_python_code_windows + # return_code = process.read_int(return_code_address) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\winappdbg\process.py", line 1673, in read_int + # return self.__read_c_type(lpBaseAddress, b'@l', ctypes.c_int) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\winappdbg\process.py", line 1568, in __read_c_type + # packed = self.read(address, size) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\winappdbg\process.py", line 1598, in read + # if not self.is_buffer(lpBaseAddress, nSize): + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\winappdbg\process.py", line 2843, in is_buffer + # mbi = self.mquery(address) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\winappdbg\process.py", line 2533, in mquery + # return win32.VirtualQueryEx(hProcess, lpAddress) + # File "X:\pydev\plugins\org.python.pydev.core\pysrc\pydevd_attach_to_process\winappdbg\win32\kernel32.py", line 3742, in VirtualQueryEx + # raise ctypes.WinError() + # PermissionError: [WinError 5] Access is denied. + # Process finished with exitValue: 1 + + process.write_int(attach_info_address, attach_info) + + helper = GenShellCodeHelper(is_64) + if is_64: + # Interesting read: http://msdn.microsoft.com/en-us/library/ms235286.aspx + # Overview of x64 Calling Conventions (for windows: Linux is different!) + # Register Usage: http://msdn.microsoft.com/en-us/library/9z1stfyw.aspx + # The registers RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile and must be considered destroyed on function calls (unless otherwise safety-provable by analysis such as whole program optimization). + # + # The registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15 are considered nonvolatile and must be saved and restored by a function that uses them. + # + # Important: RCX: first int argument + + with helper.push('rdi'): # This one REALLY must be pushed/poped + with helper.push('rsp'): + with helper.push('rbp'): + with helper.push('rbx'): + + with helper.push('rdi'): # Note: pop is automatic. + helper.mov_to_register_addr('rcx', helper.pack_address(code_address)) + helper.mov_to_register_addr('rdx', helper.pack_address(attach_info_address)) + helper.mov_to_register_addr('rbx', helper.pack_address(attach_func)) + helper.call('rbx') + + else: + with helper.push('eax'): # Note: pop is automatic. + with helper.push('ebp'): + with helper.push('ebx'): + + with helper.preserve_stack(): + # Put our code as a parameter in the stack (on x86, we push parameters to + # the stack) + helper.push_addr(helper.pack_address(attach_info_address)) + helper.push_addr(helper.pack_address(code_address)) + helper.mov_to_register_addr('ebx', helper.pack_address(attach_func)) + helper.call('ebx') + + helper.ret() + + code = helper.get_code() + + # Uncomment to see the disassembled version of what we just did... +# with open('f.asm', 'wb') as stream: +# stream.write(code) +# +# exe = r'x:\nasm\nasm-2.07-win32\nasm-2.07\ndisasm.exe' +# if is_64: +# arch = '64' +# else: +# arch = '32' +# +# subprocess.call((exe + ' -b %s f.asm' % arch).split()) + + print('Injecting code to target process') + thread, _thread_address = process.inject_code(code, 0) + + timeout = None # Could receive timeout in millis. + print('Waiting for code to complete') + thread.wait(timeout) + + # return_code = process.read_int(attach_info_address) + # if return_code == 0: + # print('Attach finished successfully.') + # else: + # print('Error when injecting code in target process. Error code: %s (on windows)' % (return_code,)) + + process.free(thread.pInjectedMemory) + process.free(code_address) + process.free(attach_info_address) + return 0 + + +def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show_debug_info=0): + assert '\'' not in python_code, 'Having a single quote messes with our command.' + filedir = os.path.dirname(__file__) + + # Valid arguments for arch are i386, i386:x86-64, i386:x64-32, i8086, + # i386:intel, i386:x86-64:intel, i386:x64-32:intel, i386:nacl, + # i386:x86-64:nacl, i386:x64-32:nacl, auto. + + if is_python_64bit(): + suffix = 'amd64' + arch = 'i386:x86-64' + else: + suffix = 'x86' + arch = 'i386' + + print('Attaching with arch: %s' % (arch,)) + + target_dll = os.path.join(filedir, 'attach_linux_%s.so' % suffix) + target_dll = os.path.abspath(os.path.normpath(target_dll)) + if not os.path.exists(target_dll): + raise RuntimeError('Could not find dll file to inject: %s' % target_dll) + + # Note: we currently don't support debug builds + is_debug = 0 + # Note that the space in the beginning of each line in the multi-line is important! + cmd = [ + 'gdb', + '--nw', # no gui interface + '--nh', # no ~/.gdbinit + '--nx', # no .gdbinit +# '--quiet', # no version number on startup + '--pid', + str(pid), + '--batch', +# '--batch-silent', + ] + + cmd.extend(["--eval-command='set scheduler-locking off'"]) # If on we'll deadlock. + + cmd.extend(["--eval-command='set architecture %s'" % arch]) + + cmd.extend([ + "--eval-command='call dlopen(\"%s\", 2)'" % target_dll, + "--eval-command='call (int)DoAttach(%s, \"%s\", %s)'" % ( + is_debug, python_code, show_debug_info) + ]) + + # print ' '.join(cmd) + + env = os.environ.copy() + # Remove the PYTHONPATH (if gdb has a builtin Python it could fail if we + # have the PYTHONPATH for a different python version or some forced encoding). + env.pop('PYTHONIOENCODING', None) + env.pop('PYTHONPATH', None) + print('Running: %s' % (' '.join(cmd))) + p = subprocess.Popen( + ' '.join(cmd), + shell=True, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + print('Running gdb in target process.') + out, err = p.communicate() + print('stdout: %s' % (out,)) + print('stderr: %s' % (err,)) + return out, err + + +def find_helper_script(filedir, script_name): + target_filename = os.path.join(filedir, 'linux_and_mac', script_name) + target_filename = os.path.normpath(target_filename) + if not os.path.exists(target_filename): + raise RuntimeError('Could not find helper script: %s' % target_filename) + + return target_filename + + +def run_python_code_mac(pid, python_code, connect_debugger_tracing=False, show_debug_info=0): + assert '\'' not in python_code, 'Having a single quote messes with our command.' + filedir = os.path.dirname(__file__) + + # Valid arguments for arch are i386, i386:x86-64, i386:x64-32, i8086, + # i386:intel, i386:x86-64:intel, i386:x64-32:intel, i386:nacl, + # i386:x86-64:nacl, i386:x64-32:nacl, auto. + + if is_python_64bit(): + suffix = 'x86_64.dylib' + arch = 'i386:x86-64' + else: + suffix = 'x86.dylib' + arch = 'i386' + + print('Attaching with arch: %s' % (arch,)) + + target_dll = os.path.join(filedir, 'attach_%s' % suffix) + target_dll = os.path.normpath(target_dll) + if not os.path.exists(target_dll): + raise RuntimeError('Could not find dll file to inject: %s' % target_dll) + + lldb_prepare_file = find_helper_script(filedir, 'lldb_prepare.py') + # Note: we currently don't support debug builds + + is_debug = 0 + # Note that the space in the beginning of each line in the multi-line is important! + cmd = [ + 'lldb', + '--no-lldbinit', # Do not automatically parse any '.lldbinit' files. + # '--attach-pid', + # str(pid), + # '--arch', + # arch, + '--script-language', + 'Python' + # '--batch-silent', + ] + + cmd.extend([ + "-o 'process attach --pid %d'" % pid, + "-o 'command script import \"%s\"'" % (lldb_prepare_file,), + "-o 'load_lib_and_attach \"%s\" %s \"%s\" %s'" % (target_dll, + is_debug, python_code, show_debug_info), + ]) + + cmd.extend([ + "-o 'process detach'", + "-o 'script import os; os._exit(1)'", + ]) + + # print ' '.join(cmd) + + env = os.environ.copy() + # Remove the PYTHONPATH (if gdb has a builtin Python it could fail if we + # have the PYTHONPATH for a different python version or some forced encoding). + env.pop('PYTHONIOENCODING', None) + env.pop('PYTHONPATH', None) + print('Running: %s' % (' '.join(cmd))) + p = subprocess.Popen( + ' '.join(cmd), + shell=True, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + print('Running lldb in target process.') + out, err = p.communicate() + print('stdout: %s' % (out,)) + print('stderr: %s' % (err,)) + return out, err + + +if sys.platform == 'win32': + run_python_code = run_python_code_windows +elif is_mac(): + run_python_code = run_python_code_mac +else: + run_python_code = run_python_code_linux + + +def test(): + print('Running with: %s' % (sys.executable,)) + code = ''' +import os, time, sys +print(os.getpid()) +#from threading import Thread +#Thread(target=str).start() +if __name__ == '__main__': + while True: + time.sleep(.5) + sys.stdout.write('.\\n') + sys.stdout.flush() +''' + + p = subprocess.Popen([sys.executable, '-u', '-c', code]) + try: + code = 'print("It worked!")\n' + + # Real code will be something as: + # code = '''import sys;sys.path.append(r'X:\winappdbg-code\examples'); import imported;''' + run_python_code(p.pid, python_code=code) + + time.sleep(3) + finally: + p.kill() + + +def main(args): + # Otherwise, assume the first parameter is the pid and anything else is code to be executed + # in the target process. + pid = int(args[0]) + del args[0] + python_code = ';'.join(args) + + # Note: on Linux the python code may not have a single quote char: ' + run_python_code(pid, python_code) + + +if __name__ == '__main__': + args = sys.argv[1:] + if not args: + print('Expected pid and Python code to execute in target process.') + else: + if '--test' == args[0]: + test() + else: + main(args) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_amd64.dll b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_amd64.dll new file mode 100644 index 0000000..ee992ed Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_amd64.dll differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_amd64.pdb b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_amd64.pdb new file mode 100644 index 0000000..36f5b91 Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_amd64.pdb differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_pydevd.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_pydevd.py new file mode 100644 index 0000000..0147b08 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_pydevd.py @@ -0,0 +1,72 @@ +import sys +import os + + +def process_command_line(argv): + setup = {} + setup['port'] = 5678 # Default port for PyDev remote debugger + setup['pid'] = 0 + setup['host'] = '127.0.0.1' + setup['protocol'] = '' + + i = 0 + while i < len(argv): + if argv[i] == '--port': + del argv[i] + setup['port'] = int(argv[i]) + del argv[i] + + elif argv[i] == '--pid': + del argv[i] + setup['pid'] = int(argv[i]) + del argv[i] + + elif argv[i] == '--host': + del argv[i] + setup['host'] = argv[i] + del argv[i] + + elif argv[i] == '--protocol': + del argv[i] + setup['protocol'] = argv[i] + del argv[i] + + if not setup['pid']: + sys.stderr.write('Expected --pid to be passed.\n') + sys.exit(1) + return setup + + +def main(setup): + import add_code_to_python_process + show_debug_info_on_target_process = 0 + + pydevd_dirname = os.path.dirname(os.path.dirname(__file__)) + + if sys.platform == 'win32': + setup['pythonpath'] = pydevd_dirname.replace('\\', '/') + setup['pythonpath2'] = os.path.dirname(__file__).replace('\\', '/') + python_code = '''import sys; +sys.path.append("%(pythonpath)s"); +sys.path.append("%(pythonpath2)s"); +import attach_script; +attach_script.attach(port=%(port)s, host="%(host)s", protocol="%(protocol)s"); +'''.replace('\r\n', '').replace('\r', '').replace('\n', '') + else: + setup['pythonpath'] = pydevd_dirname + setup['pythonpath2'] = os.path.dirname(__file__) + # We have to pass it a bit differently for gdb + python_code = '''import sys; +sys.path.append(\\\"%(pythonpath)s\\\"); +sys.path.append(\\\"%(pythonpath2)s\\\"); +import attach_script; +attach_script.attach(port=%(port)s, host=\\\"%(host)s\\\", protocol=\\\"%(protocol)s\\\"); +'''.replace('\r\n', '').replace('\r', '').replace('\n', '') + + python_code = python_code % setup + add_code_to_python_process.run_python_code( + setup['pid'], python_code, connect_debugger_tracing=True, show_debug_info=show_debug_info_on_target_process) + + +if __name__ == '__main__': + main(process_command_line(sys.argv[1:])) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_script.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_script.py new file mode 100644 index 0000000..06a871f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_script.py @@ -0,0 +1,237 @@ + + +def load_python_helper_lib(): + import sys + try: + import ctypes + except ImportError: + ctypes = None + + # Note: we cannot use import platform because it may end up importing threading, + # but that should be ok because at this point we can only be in CPython (other + # implementations wouldn't get to this point in the attach process). + # IS_CPYTHON = platform.python_implementation() == 'CPython' + IS_CPYTHON = True + + import os + IS_64BIT_PROCESS = sys.maxsize > (2 ** 32) + IS_WINDOWS = sys.platform == 'win32' + IS_LINUX = sys.platform in ('linux', 'linux2') + IS_MAC = sys.platform == 'darwin' + + if not IS_CPYTHON or ctypes is None or sys.version_info[:2] > (3, 7): + return None + + if IS_WINDOWS: + if IS_64BIT_PROCESS: + suffix = 'amd64' + else: + suffix = 'x86' + + filename = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'pydevd_attach_to_process', 'attach_%s.dll' % (suffix,)) + + elif IS_LINUX: + if IS_64BIT_PROCESS: + suffix = 'amd64' + else: + suffix = 'x86' + + filename = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'pydevd_attach_to_process', 'attach_linux_%s.so' % (suffix,)) + + elif IS_MAC: + if IS_64BIT_PROCESS: + suffix = 'x86_64.dylib' + else: + suffix = 'x86.dylib' + + filename = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'pydevd_attach_to_process', 'attach_%s' % (suffix,)) + + else: + return None + + if not os.path.exists(filename): + return None + + try: + # Load as pydll so that we don't release the gil. + lib = ctypes.pydll.LoadLibrary(filename) + return lib + except: + return None + + +def get_main_thread_instance(threading): + if hasattr(threading, 'main_thread'): + return threading.main_thread() + else: + # On Python 2 we don't really have an API to get the main thread, + # so, we just get it from the 'shutdown' bound method. + return threading._shutdown.im_self + + +def get_main_thread_id(unlikely_thread_id=None): + ''' + :param unlikely_thread_id: + Pass to mark some thread id as not likely the main thread. + + :return tuple(thread_id, critical_warning) + ''' + import sys + import os + + current_frames = sys._current_frames() + possible_thread_ids = [] + for thread_ident, frame in current_frames.items(): + while frame.f_back is not None: + frame = frame.f_back + + basename = os.path.basename(frame.f_code.co_filename) + if basename.endswith(('.pyc', '.pyo')): + basename = basename[:-1] + + if (frame.f_code.co_name, basename) in [ + ('_run_module_as_main', 'runpy.py'), + ('run_module_as_main', 'runpy.py'), + ('run_module', 'runpy.py'), + ('run_path', 'runpy.py'), + ]: + # This is the case for python -m (this is an ideal match, so, + # let's return it). + return thread_ident, '' + + if frame.f_code.co_name == '': + if frame.f_globals.get('__name__') == '__main__': + possible_thread_ids.insert(0, thread_ident) # Add with higher priority + continue + + # Usually the main thread will be started in the , whereas others would + # be started in another place (but when Python is embedded, this may not be + # correct, so, just add to the available possibilities as we'll have to choose + # one if there are multiple). + possible_thread_ids.append(thread_ident) + + if len(possible_thread_ids) > 0: + if len(possible_thread_ids) == 1: + return possible_thread_ids[0], '' # Ideal: only one match + + while unlikely_thread_id in possible_thread_ids: + possible_thread_ids.remove(unlikely_thread_id) + + if len(possible_thread_ids) == 1: + return possible_thread_ids[0], '' # Ideal: only one match + + elif len(possible_thread_ids) > 1: + # Bad: we can't really be certain of anything at this point. + return possible_thread_ids[0], \ + 'Multiple thread ids found (%s). Choosing main thread id randomly (%s).' % ( + possible_thread_ids, possible_thread_ids[0]) + + # If we got here we couldn't discover the main thread id. + return None, 'Unable to discover main thread id.' + + +def fix_main_thread_id(on_warn=lambda msg:None, on_exception=lambda msg:None, on_critical=lambda msg:None): + # This means that we weren't able to import threading in the main thread (which most + # likely means that the main thread is paused or in some very long operation). + # In this case we'll import threading here and hotfix what may be wrong in the threading + # module (if we're on Windows where we create a thread to do the attach and on Linux + # we are not certain on which thread we're executing this code). + # + # The code below is a workaround for https://bugs.python.org/issue37416 + import sys + import threading + + try: + with threading._active_limbo_lock: + main_thread_instance = get_main_thread_instance(threading) + + if sys.platform == 'win32': + # On windows this code would be called in a secondary thread, so, + # the current thread is unlikely to be the main thread. + if hasattr(threading, '_get_ident'): + unlikely_thread_id = threading._get_ident() # py2 + else: + unlikely_thread_id = threading.get_ident() # py3 + else: + unlikely_thread_id = None + + main_thread_id, critical_warning = get_main_thread_id(unlikely_thread_id) + + if main_thread_id is not None: + main_thread_id_attr = '_ident' + if not hasattr(main_thread_instance, main_thread_id_attr): + main_thread_id_attr = '_Thread__ident' + assert hasattr(main_thread_instance, main_thread_id_attr) + + if main_thread_id != getattr(main_thread_instance, main_thread_id_attr): + # Note that we also have to reset the '_tstack_lock' for a regular lock. + # This is needed to avoid an error on shutdown because this lock is bound + # to the thread state and will be released when the secondary thread + # that initialized the lock is finished -- making an assert fail during + # process shutdown. + main_thread_instance._tstate_lock = threading._allocate_lock() + main_thread_instance._tstate_lock.acquire() + + # Actually patch the thread ident as well as the threading._active dict + # (we should have the _active_limbo_lock to do that). + threading._active.pop(getattr(main_thread_instance, main_thread_id_attr), None) + setattr(main_thread_instance, main_thread_id_attr, main_thread_id) + threading._active[getattr(main_thread_instance, main_thread_id_attr)] = main_thread_instance + + # Note: only import from pydevd after the patching is done (we want to do the minimum + # possible when doing that patching). + on_warn('The threading module was not imported by user code in the main thread. The debugger will attempt to work around https://bugs.python.org/issue37416.') + + if critical_warning: + on_critical('Issue found when debugger was trying to work around https://bugs.python.org/issue37416:\n%s' % (critical_warning,)) + except: + on_exception('Error patching main thread id.') + + +def attach(port, host, protocol=''): + try: + import sys + fix_main_thread = 'threading' not in sys.modules + + if fix_main_thread: + + def on_warn(msg): + from _pydev_bundle import pydev_log + pydev_log.warn(msg) + + def on_exception(msg): + from _pydev_bundle import pydev_log + pydev_log.exception(msg) + + def on_critical(msg): + from _pydev_bundle import pydev_log + pydev_log.critical(msg) + + fix_main_thread_id(on_warn=on_warn, on_exception=on_exception, on_critical=on_critical) + + else: + from _pydev_bundle import pydev_log # @Reimport + pydev_log.debug('The threading module is already imported by user code.') + + if protocol: + from _pydevd_bundle import pydevd_defaults + pydevd_defaults.PydevdCustomization.DEFAULT_PROTOCOL = protocol + + import pydevd + pydevd.stoptrace() # I.e.: disconnect if already connected + # pydevd.DebugInfoHolder.DEBUG_RECORD_SOCKET_READS = True + # pydevd.DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = 3 + # pydevd.DebugInfoHolder.DEBUG_TRACE_LEVEL = 3 + pydevd.settrace( + port=port, + host=host, + stdoutToServer=True, + stderrToServer=True, + overwrite_prev_trace=True, + suspend=False, + trace_only_current_thread=False, + patch_multiprocessing=False, + ) + except: + import traceback + traceback.print_exc() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.dll b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.dll new file mode 100644 index 0000000..9e9c1ee Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.dll differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.dylib b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.dylib new file mode 100644 index 0000000..cd5abab Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.dylib differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.pdb b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.pdb new file mode 100644 index 0000000..ebd8012 Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86.pdb differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib new file mode 100644 index 0000000..09e5d3e Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/attach_x86_64.dylib differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace.hpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace.hpp new file mode 100644 index 0000000..12659e2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace.hpp @@ -0,0 +1,230 @@ +#ifndef _PY_SETTRACE_HPP_ +#define _PY_SETTRACE_HPP_ + +#include "ref_utils.hpp" +#include "py_utils.hpp" +#include "python.h" +#include "py_settrace_37.hpp" +#include + + +#ifdef _WIN32 + +typedef HMODULE MODULE_TYPE; +#else // LINUX ----------------------------------------------------------------- + +typedef void* MODULE_TYPE; +typedef ssize_t SSIZE_T; +typedef unsigned int DWORD; + +#endif + +DWORD GetPythonThreadId(PythonVersion version, PyThreadState* curThread) { + DWORD threadId = 0; + if (PyThreadState_25_27::IsFor(version)) { + threadId = (DWORD)((PyThreadState_25_27*)curThread)->thread_id; + } else if (PyThreadState_30_33::IsFor(version)) { + threadId = (DWORD)((PyThreadState_30_33*)curThread)->thread_id; + } else if (PyThreadState_34_36::IsFor(version)) { + threadId = (DWORD)((PyThreadState_34_36*)curThread)->thread_id; + } else if (PyThreadState_37::IsFor(version)) { + threadId = (DWORD)((PyThreadState_37*)curThread)->thread_id; + } + return threadId; +} + + +/** + * This function may be called to set a tracing function to existing python threads. + */ +int InternalSetSysTraceFunc( + MODULE_TYPE module, + bool isDebug, + bool showDebugInfo, + PyObjectHolder* traceFunc, + PyObjectHolder* setTraceFunc, + unsigned int threadId, + PyObjectHolder* pyNone) +{ + + if(showDebugInfo){ + PRINT("InternalSetSysTraceFunc started."); + } + + DEFINE_PROC(isInit, Py_IsInitialized*, "Py_IsInitialized", 100); + if (!isInit()) { + PRINT("Py_IsInitialized returned false."); + return 110; + } + + auto version = GetPythonVersion(module); + + // found initialized Python runtime, gather and check the APIs we need for a successful attach... + + DEFINE_PROC(interpHead, PyInterpreterState_Head*, "PyInterpreterState_Head", 120); + DEFINE_PROC(gilEnsure, PyGILState_Ensure*, "PyGILState_Ensure", 130); + DEFINE_PROC(gilRelease, PyGILState_Release*, "PyGILState_Release", 140); + DEFINE_PROC(threadHead, PyInterpreterState_ThreadHead*, "PyInterpreterState_ThreadHead", 150); + DEFINE_PROC(threadNext, PyThreadState_Next*, "PyThreadState_Next", 160); + DEFINE_PROC(threadSwap, PyThreadState_Swap*, "PyThreadState_Swap", 170); + DEFINE_PROC(call, PyObject_CallFunctionObjArgs*, "PyObject_CallFunctionObjArgs", 180); + + PyInt_FromLong* intFromLong; + + if (version >= PythonVersion_30) { + DEFINE_PROC(intFromLongPy3, PyInt_FromLong*, "PyLong_FromLong", 190); + intFromLong = intFromLongPy3; + } else { + DEFINE_PROC(intFromLongPy2, PyInt_FromLong*, "PyInt_FromLong", 200); + intFromLong = intFromLongPy2; + } + + DEFINE_PROC(pyGetAttr, PyObject_GetAttrString*, "PyObject_GetAttrString", 250); + DEFINE_PROC(pyHasAttr, PyObject_HasAttrString*, "PyObject_HasAttrString", 260); + DEFINE_PROC_NO_CHECK(PyCFrame_Type, PyTypeObject*, "PyCFrame_Type", 300); // optional + + DEFINE_PROC_NO_CHECK(curPythonThread, PyThreadState**, "_PyThreadState_Current", 310); // optional + DEFINE_PROC_NO_CHECK(getPythonThread, _PyThreadState_UncheckedGet*, "_PyThreadState_UncheckedGet", 320); // optional + + if (curPythonThread == nullptr && getPythonThread == nullptr) { + // we're missing some APIs, we cannot attach. + PRINT("Error, missing Python threading API!!"); + return 330; + } + + auto head = interpHead(); + if (head == nullptr) { + // this interpreter is loaded but not initialized. + PRINT("Interpreter not initialized!"); + return 340; + } + + GilHolder gilLock(gilEnsure, gilRelease); // acquire and hold the GIL until done... + + + int retVal = 0; + // find what index is holding onto the thread state... + auto curPyThread = getPythonThread ? getPythonThread() : *curPythonThread; + + if(curPyThread == nullptr){ + PRINT("Getting the current python thread returned nullptr."); + return 345; + } + + + if (version < PythonVersion_37) + { + DEFINE_PROC(errOccurred, PyErr_Occurred*, "PyErr_Occurred", 210); + DEFINE_PROC(pyErrFetch, PyErr_Fetch*, "PyErr_Fetch", 220); + DEFINE_PROC(pyErrRestore, PyErr_Restore*, "PyErr_Restore", 230); + DEFINE_PROC(getThreadTls, PyThread_get_key_value*, "PyThread_get_key_value", 270); + DEFINE_PROC(setThreadTls, PyThread_set_key_value*, "PyThread_set_key_value", 280); + DEFINE_PROC(delThreadTls, PyThread_delete_key_value*, "PyThread_delete_key_value", 290); + int threadStateIndex = -1; + for (int i = 0; i < 100000; i++) { + void* value = getThreadTls(i); + if (value == curPyThread) { + threadStateIndex = i; + break; + } + } + + if(threadStateIndex == -1){ + printf("Unable to find threadStateIndex for the current thread. curPyThread: %p\n", curPyThread); + return 350; + } + + + bool found = false; + for (auto curThread = threadHead(head); curThread != nullptr; curThread = threadNext(curThread)) { + if (GetPythonThreadId(version, curThread) != threadId) { + continue; + } + found = true; + + + // switch to our new thread so we can call sys.settrace on it... + // all of the work here needs to be minimal - in particular we shouldn't + // ever evaluate user defined code as we could end up switching to this + // thread on the main thread and corrupting state. + delThreadTls(threadStateIndex); + setThreadTls(threadStateIndex, curThread); + auto prevThread = threadSwap(curThread); + + // save and restore the error in case something funky happens... + auto errOccured = errOccurred(); + PyObject* type = nullptr; + PyObject* value = nullptr; + PyObject* traceback = nullptr; + if (errOccured) { + pyErrFetch(&type, &value, &traceback); + retVal = 1; + } + + if(showDebugInfo){ + printf("setting trace for thread: %d\n", threadId); + } + + DecRef(call(setTraceFunc->ToPython(), traceFunc->ToPython(), nullptr), isDebug); + + if (errOccured) { + pyErrRestore(type, value, traceback); + } + + delThreadTls(threadStateIndex); + setThreadTls(threadStateIndex, prevThread); + threadSwap(prevThread); + break; + } + + if(!found) { + retVal = 500; + } + } + else + { + // See comments on py_settrace_37.hpp for why we need a different implementation in Python 3.7 onwards. + DEFINE_PROC(pyUnicode_InternFromString, PyUnicode_InternFromString*, "PyUnicode_InternFromString", 520); + DEFINE_PROC(pyObject_FastCallDict, _PyObject_FastCallDict*, "_PyObject_FastCallDict", 530); + DEFINE_PROC(pyTraceBack_Here, PyTraceBack_Here*, "PyTraceBack_Here", 540); + DEFINE_PROC(pyEval_SetTrace, PyEval_SetTrace*, "PyEval_SetTrace", 550); + + bool found = false; + for (PyThreadState* curThread = threadHead(head); curThread != nullptr; curThread = threadNext(curThread)) { + if (GetPythonThreadId(version, curThread) != threadId) { + continue; + } + found = true; + + if(showDebugInfo){ + printf("setting trace for thread: %d\n", threadId); + } + + if(!InternalIsTraceInitialized_37()) + { + InternalInitializeSettrace_37 *internalInitializeSettrace_37 = new InternalInitializeSettrace_37(); + + IncRef(pyNone->ToPython()); + internalInitializeSettrace_37->pyNone = pyNone->ToPython(); + + internalInitializeSettrace_37->pyUnicode_InternFromString = pyUnicode_InternFromString; + internalInitializeSettrace_37->pyObject_FastCallDict = pyObject_FastCallDict; + internalInitializeSettrace_37->isDebug = isDebug; + internalInitializeSettrace_37->pyTraceBack_Here = pyTraceBack_Here; + internalInitializeSettrace_37->pyEval_SetTrace = pyEval_SetTrace; + + InternalTraceInit_37(internalInitializeSettrace_37); + } + InternalPySetTrace_37(curThread, traceFunc, isDebug); + break; + } + if(!found) { + retVal = 501; + } + } + + return retVal; + +} + +#endif // _PY_SETTRACE_HPP_ diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace_37.hpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace_37.hpp new file mode 100644 index 0000000..c1118b3 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_settrace_37.hpp @@ -0,0 +1,176 @@ +#ifndef _PY_SETTRACE_37_HPP_ +#define _PY_SETTRACE_37_HPP_ + +#include "python.h" +#include "py_utils.hpp" + +// On Python 3.7 onwards the thread state is not kept in PyThread_set_key_value (rather +// it uses PyThread_tss_set using PyThread_tss_set(&_PyRuntime.gilstate.autoTSSkey, (void *)tstate) +// and we don't have access to that key from here (thus, we can't use the previous approach which +// made CPython think that the current thread had the thread state where we wanted to set the tracing). +// +// So, the solution implemented here is not faking that change and reimplementing PyEval_SetTrace. +// The implementation is mostly the same from the one in CPython, but we have one shortcoming: +// +// When CPython sets the tracing for a thread it increments _Py_TracingPossible (actually +// _PyRuntime.ceval.tracing_possible). This implementation has one issue: it only works on +// deltas when the tracing is set (so, a settrace(func) will increase the _Py_TracingPossible global value and a +// settrace(None) will decrease it, but when a thread dies it's kept as is and is not decreased). +// -- as we don't currently have access to _PyRuntime we have to create a thread, set the tracing +// and let it die so that the count is increased (this is really hacky, but better than having +// to create a local copy of the whole _PyRuntime (defined in pystate.h with several inner structs) +// which would need to be kept up to date for each new CPython version just to increment that variable). + + +struct InternalInitializeSettrace_37 { + PyUnicode_InternFromString* pyUnicode_InternFromString; + PyObject* pyNone; + _PyObject_FastCallDict* pyObject_FastCallDict; + PyTraceBack_Here* pyTraceBack_Here; + PyEval_SetTrace* pyEval_SetTrace; + bool isDebug; +}; + +/** + * Helper information to access CPython internals. + */ +static InternalInitializeSettrace_37 *internalInitializeSettrace_37 = NULL; + +/* + * Cached interned string objects used for calling the profile and + * trace functions. Initialized by InternalTraceInit_37(). + */ +static PyObject *InternalWhatstrings_37[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + + +static int +InternalIsTraceInitialized_37() +{ + return internalInitializeSettrace_37 != NULL; +} + + +static int +InternalTraceInit_37(InternalInitializeSettrace_37 *p_internalInitializeSettrace_37) +{ + internalInitializeSettrace_37 = p_internalInitializeSettrace_37; + static const char * const whatnames[8] = { + "call", "exception", "line", "return", + "c_call", "c_exception", "c_return", + "opcode" + }; + PyObject *name; + int i; + for (i = 0; i < 8; ++i) { + if (InternalWhatstrings_37[i] == NULL) { + name = internalInitializeSettrace_37->pyUnicode_InternFromString(whatnames[i]); + if (name == NULL) + return -1; + InternalWhatstrings_37[i] = name; + } + } + return 0; +} + + +static PyObject * +InternalCallTrampoline_37(PyObject* callback, + PyFrameObject *frame, int what, PyObject *arg) +{ + PyObject *result; + PyObject *stack[3]; + +// Note: this is commented out from CPython (we shouldn't need it and it adds a reasonable overhead). +// if (PyFrame_FastToLocalsWithError(frame) < 0) { +// return NULL; +// } +// + stack[0] = (PyObject *)frame; + stack[1] = InternalWhatstrings_37[what]; + stack[2] = (arg != NULL) ? arg : internalInitializeSettrace_37->pyNone; + + // call the Python-level function + // result = _PyObject_FastCall(callback, stack, 3); + // + // Note that _PyObject_FastCall is actually a define: + // #define _PyObject_FastCall(func, args, nargs) _PyObject_FastCallDict((func), (args), (nargs), NULL) + + result = internalInitializeSettrace_37->pyObject_FastCallDict(callback, stack, 3, NULL); + + +// Note: this is commented out from CPython (we shouldn't need it and it adds a reasonable overhead). +// PyFrame_LocalsToFast(frame, 1); + + if (result == NULL) { + internalInitializeSettrace_37->pyTraceBack_Here(frame); + } + + return result; +} + +static int +InternalTraceTrampoline_37(PyObject *self, PyFrameObject *frame, + int what, PyObject *arg) +{ + PyObject *callback; + PyObject *result; + + if (what == PyTrace_CALL){ + callback = self; + } else { + callback = frame->f_trace; + } + + if (callback == NULL){ + return 0; + } + + result = InternalCallTrampoline_37(callback, frame, what, arg); + if (result == NULL) { + // Note: calling the original sys.settrace here. + internalInitializeSettrace_37->pyEval_SetTrace(NULL, NULL); + PyObject *temp_f_trace = frame->f_trace; + frame->f_trace = NULL; + if(temp_f_trace != NULL){ + DecRef(temp_f_trace, internalInitializeSettrace_37->isDebug); + } + return -1; + } + if (result != internalInitializeSettrace_37->pyNone) { + PyObject *tmp = frame->f_trace; + frame->f_trace = result; + DecRef(tmp, internalInitializeSettrace_37->isDebug); + } + else { + DecRef(result, internalInitializeSettrace_37->isDebug); + } + return 0; +} + +void InternalPySetTrace_37(PyThreadState* curThread, PyObjectHolder* traceFunc, bool isDebug) +{ + PyThreadState_37* tstate = reinterpret_cast(curThread); + PyObject *temp = tstate->c_traceobj; + + // We can't increase _Py_TracingPossible. Everything else should be equal to CPython. + // runtime->ceval.tracing_possible += (func != NULL) - (tstate->c_tracefunc != NULL); + + PyObject *arg = traceFunc->ToPython(); + IncRef(arg); + tstate->c_tracefunc = NULL; + tstate->c_traceobj = NULL; + /* Must make sure that profiling is not ignored if 'temp' is freed */ + tstate->use_tracing = tstate->c_profilefunc != NULL; + if(temp != NULL){ + DecRef(temp, isDebug); + } + tstate->c_tracefunc = InternalTraceTrampoline_37; + tstate->c_traceobj = arg; + /* Flag that tracing or profiling is turned on */ + tstate->use_tracing = ((InternalTraceTrampoline_37 != NULL) + || (tstate->c_profilefunc != NULL)); + +} + + +#endif //_PY_SETTRACE_37_HPP_ \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_utils.hpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_utils.hpp new file mode 100644 index 0000000..455a4bc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_utils.hpp @@ -0,0 +1,77 @@ +#ifndef _PY_UTILS_HPP_ +#define _PY_UTILS_HPP_ + +typedef int (Py_IsInitialized)(); +typedef PyInterpreterState* (PyInterpreterState_Head)(); +typedef enum { PyGILState_LOCKED, PyGILState_UNLOCKED } PyGILState_STATE; +typedef PyGILState_STATE(PyGILState_Ensure)(); +typedef void (PyGILState_Release)(PyGILState_STATE); +typedef int (PyRun_SimpleString)(const char *command); +typedef PyThreadState* (PyInterpreterState_ThreadHead)(PyInterpreterState* interp); +typedef PyThreadState* (PyThreadState_Next)(PyThreadState *tstate); +typedef PyThreadState* (PyThreadState_Swap)(PyThreadState *tstate); +typedef PyThreadState* (_PyThreadState_UncheckedGet)(); +typedef PyObject* (PyObject_CallFunctionObjArgs)(PyObject *callable, ...); // call w/ varargs, last arg should be nullptr +typedef PyObject* (PyInt_FromLong)(long); +typedef PyObject* (PyErr_Occurred)(); +typedef void (PyErr_Fetch)(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback); +typedef void (PyErr_Restore)(PyObject *type, PyObject *value, PyObject *traceback); +typedef PyObject* (PyImport_ImportModule) (const char *name); +typedef PyObject* (PyImport_ImportModuleNoBlock) (const char *name); +typedef PyObject* (PyObject_GetAttrString)(PyObject *o, const char *attr_name); +typedef PyObject* (PyObject_HasAttrString)(PyObject *o, const char *attr_name); +typedef void* (PyThread_get_key_value)(int); +typedef int (PyThread_set_key_value)(int, void*); +typedef void (PyThread_delete_key_value)(int); +typedef int (PyObject_Not) (PyObject *o); +typedef PyObject* (PyDict_New)(); +typedef PyObject* (PyUnicode_InternFromString)(const char *u); +typedef PyObject * (_PyObject_FastCallDict)( + PyObject *callable, PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs); +typedef int (PyTraceBack_Here)(PyFrameObject *frame); + +typedef void (PyEval_SetTrace)(Py_tracefunc, PyObject *); +typedef int (*Py_tracefunc)(PyObject *, PyFrameObject *frame, int, PyObject *); + +// holder to ensure we release the GIL even in error conditions +class GilHolder { + PyGILState_STATE _gilState; + PyGILState_Release* _release; +public: + GilHolder(PyGILState_Ensure* acquire, PyGILState_Release* release) { + _gilState = acquire(); + _release = release; + } + + ~GilHolder() { + _release(_gilState); + } +}; + +#ifdef _WIN32 + +#define PRINT(msg) {std::cout << msg << std::endl << std::flush;} + +#define DEFINE_PROC_NO_CHECK(func, funcType, funcNameStr, errorCode) \ + funcType func=reinterpret_cast(GetProcAddress(module, funcNameStr)); + +#define DEFINE_PROC(func, funcType, funcNameStr, errorCode) \ + DEFINE_PROC_NO_CHECK(func, funcType, funcNameStr, errorCode); \ + if(func == nullptr){std::cout << funcNameStr << " not found." << std::endl << std::flush; return errorCode;}; + +#else // LINUX ----------------------------------------------------------------- + +#define PRINT(msg) {printf(msg); printf("\n");} + +#define CHECK_NULL(ptr, msg, errorCode) if(ptr == nullptr){printf(msg); return errorCode;} + +#define DEFINE_PROC_NO_CHECK(func, funcType, funcNameStr, errorCode) \ + funcType func; *(void**)(&func) = dlsym(module, funcNameStr); + +#define DEFINE_PROC(func, funcType, funcNameStr, errorCode) \ + DEFINE_PROC_NO_CHECK(func, funcType, funcNameStr, errorCode); \ + if(func == nullptr){printf(funcNameStr); printf(" not found.\n"); return errorCode;}; + +#endif //_WIN32 + +#endif //_PY_UTILS_HPP_ \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_version.hpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_version.hpp new file mode 100644 index 0000000..6e6146f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/py_version.hpp @@ -0,0 +1,74 @@ + +#ifndef __PY_VERSION_HPP__ +#define __PY_VERSION_HPP__ + + +#include + +enum PythonVersion { + PythonVersion_Unknown, + PythonVersion_25 = 0x0205, + PythonVersion_26 = 0x0206, + PythonVersion_27 = 0x0207, + PythonVersion_30 = 0x0300, + PythonVersion_31 = 0x0301, + PythonVersion_32 = 0x0302, + PythonVersion_33 = 0x0303, + PythonVersion_34 = 0x0304, + PythonVersion_35 = 0x0305, + PythonVersion_36 = 0x0306, + PythonVersion_37 = 0x0307 +}; + + +#ifdef _WIN32 + +typedef const char* (GetVersionFunc)(); + +static PythonVersion GetPythonVersion(HMODULE hMod) { + auto versionFunc = reinterpret_cast(GetProcAddress(hMod, "Py_GetVersion")); + if (versionFunc == nullptr) { + return PythonVersion_Unknown; + } + const char* version = versionFunc(); + + +#else // LINUX ----------------------------------------------------------------- + +typedef const char* (*GetVersionFunc) (); + +static PythonVersion GetPythonVersion(void *module) { + GetVersionFunc versionFunc; + *(void**)(&versionFunc) = dlsym(module, "Py_GetVersion"); + if(versionFunc == nullptr) { + return PythonVersion_Unknown; + } + const char* version = versionFunc(); + +#endif //_WIN32 + + if (version != nullptr && strlen(version) >= 3 && version[1] == '.') { + if (version[0] == '2') { + switch (version[2]) { + case '5': return PythonVersion_25; + case '6': return PythonVersion_26; + case '7': return PythonVersion_27; + } + } + else if (version[0] == '3') { + switch (version[2]) { + case '0': return PythonVersion_30; + case '1': return PythonVersion_31; + case '2': return PythonVersion_32; + case '3': return PythonVersion_33; + case '4': return PythonVersion_34; + case '5': return PythonVersion_35; + case '6': return PythonVersion_36; + case '7': return PythonVersion_37; + } + } + } + return PythonVersion_Unknown; +} + +#endif \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/python.h b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/python.h new file mode 100644 index 0000000..b69bd90 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/python.h @@ -0,0 +1,684 @@ +// Python Tools for Visual Studio +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +#ifndef __PYTHON_H__ +#define __PYTHON_H__ + +#include "../common/py_version.hpp" + +#ifndef _WIN32 +typedef unsigned int DWORD; +typedef ssize_t SSIZE_T; +#endif +typedef SSIZE_T Py_ssize_t; + +// defines limited header of Python API for compatible access across a number of Pythons. + +class PyTypeObject; +class PyThreadState; + +#define PyObject_HEAD \ + size_t ob_refcnt; \ + PyTypeObject *ob_type; + +#define PyObject_VAR_HEAD \ + PyObject_HEAD \ + size_t ob_size; /* Number of items in variable part */ + +class PyObject { +public: + PyObject_HEAD +}; + +class PyVarObject : public PyObject { +public: + size_t ob_size; /* Number of items in variable part */ +}; + +// 2.4 - 2.7 compatible +class PyCodeObject25_27 : public PyObject { +public: + int co_argcount; /* #arguments, except *args */ + int co_nlocals; /* #local variables */ + int co_stacksize; /* #entries needed for evaluation stack */ + int co_flags; /* CO_..., see below */ + PyObject *co_code; /* instruction opcodes */ + PyObject *co_consts; /* list (constants used) */ + PyObject *co_names; /* list of strings (names used) */ + PyObject *co_varnames; /* tuple of strings (local variable names) */ + PyObject *co_freevars; /* tuple of strings (free variable names) */ + PyObject *co_cellvars; /* tuple of strings (cell variable names) */ + /* The rest doesn't count for hash/cmp */ + PyObject *co_filename; /* string (where it was loaded from) */ + PyObject *co_name; /* string (name, for reference) */ + int co_firstlineno; /* first source line number */ + PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 2 && (minorVersion >= 5 && minorVersion <= 7); + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_25 && version <= PythonVersion_27; + } +}; + +// 3.0-3.2 +class PyCodeObject30_32 : public PyObject { +public: + int co_argcount; /* #arguments, except *args */ + int co_kwonlyargcount; /* #keyword only arguments */ + int co_nlocals; /* #local variables */ + int co_stacksize; /* #entries needed for evaluation stack */ + int co_flags; /* CO_..., see below */ + PyObject *co_code; /* instruction opcodes */ + PyObject *co_consts; /* list (constants used) */ + PyObject *co_names; /* list of strings (names used) */ + PyObject *co_varnames; /* tuple of strings (local variable names) */ + PyObject *co_freevars; /* tuple of strings (free variable names) */ + PyObject *co_cellvars; /* tuple of strings (cell variable names) */ + /* The rest doesn't count for hash or comparisons */ + PyObject *co_filename; /* unicode (where it was loaded from) */ + PyObject *co_name; /* unicode (name, for reference) */ + int co_firstlineno; /* first source line number */ + PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */ + void *co_zombieframe; /* for optimization only (see frameobject.c) */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && (minorVersion >= 0 && minorVersion <= 2); + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_30 && version <= PythonVersion_32; + } +}; + +// 3.3-3.5 +class PyCodeObject33_35 : public PyObject { +public: + int co_argcount; /* #arguments, except *args */ + int co_kwonlyargcount; /* #keyword only arguments */ + int co_nlocals; /* #local variables */ + int co_stacksize; /* #entries needed for evaluation stack */ + int co_flags; /* CO_..., see below */ + PyObject *co_code; /* instruction opcodes */ + PyObject *co_consts; /* list (constants used) */ + PyObject *co_names; /* list of strings (names used) */ + PyObject *co_varnames; /* tuple of strings (local variable names) */ + PyObject *co_freevars; /* tuple of strings (free variable names) */ + PyObject *co_cellvars; /* tuple of strings (cell variable names) */ + /* The rest doesn't count for hash or comparisons */ + unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ + PyObject *co_filename; /* unicode (where it was loaded from) */ + PyObject *co_name; /* unicode (name, for reference) */ + int co_firstlineno; /* first source line number */ + PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */ + void *co_zombieframe; /* for optimization only (see frameobject.c) */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && (minorVersion >= 3 && minorVersion <= 5); + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_33 && version <= PythonVersion_35; + } +}; + +// 3.6 +class PyCodeObject36 : public PyObject { +public: + int co_argcount; /* #arguments, except *args */ + int co_kwonlyargcount; /* #keyword only arguments */ + int co_nlocals; /* #local variables */ + int co_stacksize; /* #entries needed for evaluation stack */ + int co_flags; /* CO_..., see below */ + int co_firstlineno; /* first source line number */ + PyObject *co_code; /* instruction opcodes */ + PyObject *co_consts; /* list (constants used) */ + PyObject *co_names; /* list of strings (names used) */ + PyObject *co_varnames; /* tuple of strings (local variable names) */ + PyObject *co_freevars; /* tuple of strings (free variable names) */ + PyObject *co_cellvars; /* tuple of strings (cell variable names) */ + /* The rest doesn't count for hash or comparisons */ + unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ + PyObject *co_filename; /* unicode (where it was loaded from) */ + PyObject *co_name; /* unicode (name, for reference) */ + PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */ + void *co_zombieframe; /* for optimization only (see frameobject.c) */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && minorVersion == 6; + } + + static bool IsFor(PythonVersion version) { + return version == PythonVersion_36; + } +}; + +// 3.7 +class PyCodeObject37 : public PyObject { +public: + int co_argcount; /* #arguments, except *args */ + int co_kwonlyargcount; /* #keyword only arguments */ + int co_nlocals; /* #local variables */ + int co_stacksize; /* #entries needed for evaluation stack */ + int co_flags; /* CO_..., see below */ + int co_firstlineno; /* first source line number */ + PyObject *co_code; /* instruction opcodes */ + PyObject *co_consts; /* list (constants used) */ + PyObject *co_names; /* list of strings (names used) */ + PyObject *co_varnames; /* tuple of strings (local variable names) */ + PyObject *co_freevars; /* tuple of strings (free variable names) */ + PyObject *co_cellvars; /* tuple of strings (cell variable names) */ + /* The rest doesn't count for hash or comparisons */ + SSIZE_T *co_cell2arg; /* Maps cell vars which are arguments. */ + PyObject *co_filename; /* unicode (where it was loaded from) */ + PyObject *co_name; /* unicode (name, for reference) */ + PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */ + void *co_zombieframe; /* for optimization only (see frameobject.c) */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && minorVersion >= 7; + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_37; + } +}; + +// 2.5 - 3.7 +class PyFunctionObject : public PyObject { +public: + PyObject *func_code; /* A code object */ +}; + +// 2.5 - 2.7 compatible +class PyStringObject : public PyVarObject { +public: + long ob_shash; + int ob_sstate; + char ob_sval[1]; + + /* Invariants: + * ob_sval contains space for 'ob_size+1' elements. + * ob_sval[ob_size] == 0. + * ob_shash is the hash of the string or -1 if not computed yet. + * ob_sstate != 0 iff the string object is in stringobject.c's + * 'interned' dictionary; in this case the two references + * from 'interned' to this object are *not counted* in ob_refcnt. + */ +}; + +// 2.4 - 3.7 compatible +typedef struct { + PyObject_HEAD + size_t length; /* Length of raw Unicode data in buffer */ + wchar_t *str; /* Raw Unicode buffer */ + long hash; /* Hash value; -1 if not set */ +} PyUnicodeObject; + +// 2.4 - 3.7 compatible +class PyFrameObject : public PyVarObject { +public: + PyFrameObject *f_back; /* previous frame, or nullptr */ + PyObject *f_code; /* code segment */ + PyObject *f_builtins; /* builtin symbol table (PyDictObject) */ + PyObject *f_globals; /* global symbol table (PyDictObject) */ + PyObject *f_locals; /* local symbol table (any mapping) */ + PyObject **f_valuestack; /* points after the last local */ + /* Next free slot in f_valuestack. Frame creation sets to f_valuestack. + Frame evaluation usually NULLs it, but a frame that yields sets it + to the current stack top. */ + PyObject **f_stacktop; + PyObject *f_trace; /* Trace function */ +}; + +#define CO_MAXBLOCKS 20 +typedef struct { + int b_type; /* what kind of block this is */ + int b_handler; /* where to jump to find handler */ + int b_level; /* value stack level to pop to */ +} PyTryBlock; + +class PyFrameObject25_33 : public PyFrameObject { +public: + PyObject * f_exc_type, *f_exc_value, *f_exc_traceback; + PyThreadState* f_tstate; + int f_lasti; /* Last instruction if called */ + /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when + f_trace is set) -- at other times use PyCode_Addr2Line instead. */ + int f_lineno; /* Current line number */ + int f_iblock; /* index in f_blockstack */ + PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ + PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ + + static bool IsFor(int majorVersion, int minorVersion) { + return (majorVersion == 2 && (minorVersion >= 5 && minorVersion <= 7)) || + (majorVersion == 3 && (minorVersion >= 0 && minorVersion <= 3)); + } +}; + +class PyFrameObject34_36 : public PyFrameObject { +public: + PyObject * f_exc_type, *f_exc_value, *f_exc_traceback; + /* Borrowed reference to a generator, or nullptr */ + PyObject *f_gen; + + int f_lasti; /* Last instruction if called */ + /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when + f_trace is set) -- at other times use PyCode_Addr2Line instead. */ + int f_lineno; /* Current line number */ + int f_iblock; /* index in f_blockstack */ + char f_executing; /* whether the frame is still executing */ + PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ + PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && minorVersion >= 4 && minorVersion <= 6; + } +}; + +class PyFrameObject37 : public PyFrameObject { +public: + char f_trace_lines; /* Emit per-line trace events? */ + char f_trace_opcodes; /* Emit per-opcode trace events? */ + /* Borrowed reference to a generator, or nullptr */ + PyObject *f_gen; + + int f_lasti; /* Last instruction if called */ + /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when + f_trace is set) -- at other times use PyCode_Addr2Line instead. */ + int f_lineno; /* Current line number */ + int f_iblock; /* index in f_blockstack */ + char f_executing; /* whether the frame is still executing */ + PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ + PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && minorVersion >= 7; + } +}; + + +typedef void (*destructor)(PyObject *); + +// 2.4 - 3.7 +class PyMethodDef { +public: + char *ml_name; /* The name of the built-in function/method */ +}; + + +// +// 2.5 - 3.7 +// While these are compatible there are fields only available on later versions. +class PyTypeObject : public PyVarObject { +public: + const char *tp_name; /* For printing, in format "." */ + size_t tp_basicsize, tp_itemsize; /* For allocation */ + + /* Methods to implement standard operations */ + + destructor tp_dealloc; + void *tp_print; + void *tp_getattr; + void *tp_setattr; + union { + void *tp_compare; /* 2.4 - 3.4 */ + void *tp_as_async; /* 3.5 - 3.7 */ + }; + void *tp_repr; + + /* Method suites for standard classes */ + + void *tp_as_number; + void *tp_as_sequence; + void *tp_as_mapping; + + /* More standard operations (here for binary compatibility) */ + + void *tp_hash; + void *tp_call; + void *tp_str; + void *tp_getattro; + void *tp_setattro; + + /* Functions to access object as input/output buffer */ + void *tp_as_buffer; + + /* Flags to define presence of optional/expanded features */ + long tp_flags; + + const char *tp_doc; /* Documentation string */ + + /* Assigned meaning in release 2.0 */ + /* call function for all accessible objects */ + void *tp_traverse; + + /* delete references to contained objects */ + void *tp_clear; + + /* Assigned meaning in release 2.1 */ + /* rich comparisons */ + void *tp_richcompare; + + /* weak reference enabler */ + size_t tp_weaklistoffset; + + /* Added in release 2.2 */ + /* Iterators */ + void *tp_iter; + void *tp_iternext; + + /* Attribute descriptor and subclassing stuff */ + PyMethodDef *tp_methods; + struct PyMemberDef *tp_members; + struct PyGetSetDef *tp_getset; + struct _typeobject *tp_base; + PyObject *tp_dict; + void *tp_descr_get; + void *tp_descr_set; + size_t tp_dictoffset; + void *tp_init; + void *tp_alloc; + void *tp_new; + void *tp_free; /* Low-level free-memory routine */ + void *tp_is_gc; /* For PyObject_IS_GC */ + PyObject *tp_bases; + PyObject *tp_mro; /* method resolution order */ + PyObject *tp_cache; + PyObject *tp_subclasses; + PyObject *tp_weaklist; + void *tp_del; + + /* Type attribute cache version tag. Added in version 2.6 */ + unsigned int tp_version_tag; +}; + +// 2.4 - 3.7 +class PyTupleObject : public PyVarObject { +public: + PyObject *ob_item[1]; + + /* ob_item contains space for 'ob_size' elements. + * Items must normally not be nullptr, except during construction when + * the tuple is not yet visible outside the function that builds it. + */ +}; + +// 2.4 - 3.7 +class PyCFunctionObject : public PyObject { +public: + PyMethodDef *m_ml; /* Description of the C function to call */ + PyObject *m_self; /* Passed as 'self' arg to the C func, can be nullptr */ + PyObject *m_module; /* The __module__ attribute, can be anything */ +}; + +typedef int (*Py_tracefunc)(PyObject *, PyFrameObject *, int, PyObject *); + +#define PyTrace_CALL 0 +#define PyTrace_EXCEPTION 1 +#define PyTrace_LINE 2 +#define PyTrace_RETURN 3 +#define PyTrace_C_CALL 4 +#define PyTrace_C_EXCEPTION 5 +#define PyTrace_C_RETURN 6 + +class PyInterpreterState { +}; + +class PyThreadState { }; + +class PyThreadState_25_27 : public PyThreadState { +public: + /* See Python/ceval.c for comments explaining most fields */ + + PyThreadState *next; + PyInterpreterState *interp; + + PyFrameObject *frame; + int recursion_depth; + /* 'tracing' keeps track of the execution depth when tracing/profiling. + This is to prevent the actual trace/profile code from being recorded in + the trace/profile. */ + int tracing; + int use_tracing; + + Py_tracefunc c_profilefunc; + Py_tracefunc c_tracefunc; + PyObject *c_profileobj; + PyObject *c_traceobj; + + PyObject *curexc_type; + PyObject *curexc_value; + PyObject *curexc_traceback; + + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + + PyObject *dict; /* Stores per-thread state */ + + /* tick_counter is incremented whenever the check_interval ticker + * reaches zero. The purpose is to give a useful measure of the number + * of interpreted bytecode instructions in a given thread. This + * extremely lightweight statistic collector may be of interest to + * profilers (like psyco.jit()), although nothing in the core uses it. + */ + int tick_counter; + + int gilstate_counter; + + PyObject *async_exc; /* Asynchronous exception to raise */ + long thread_id; /* Thread id where this tstate was created */ + + /* XXX signal handlers should also be here */ + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 2 && (minorVersion >= 5 && minorVersion <= 7); + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_25 && version <= PythonVersion_27; + } +}; + +class PyThreadState_30_33 : public PyThreadState { +public: + PyThreadState *next; + PyInterpreterState *interp; + + PyFrameObject *frame; + int recursion_depth; + char overflowed; /* The stack has overflowed. Allow 50 more calls + to handle the runtime error. */ + char recursion_critical; /* The current calls must not cause + a stack overflow. */ + /* 'tracing' keeps track of the execution depth when tracing/profiling. + This is to prevent the actual trace/profile code from being recorded in + the trace/profile. */ + int tracing; + int use_tracing; + + Py_tracefunc c_profilefunc; + Py_tracefunc c_tracefunc; + PyObject *c_profileobj; + PyObject *c_traceobj; + + PyObject *curexc_type; + PyObject *curexc_value; + PyObject *curexc_traceback; + + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + + PyObject *dict; /* Stores per-thread state */ + + /* tick_counter is incremented whenever the check_interval ticker + * reaches zero. The purpose is to give a useful measure of the number + * of interpreted bytecode instructions in a given thread. This + * extremely lightweight statistic collector may be of interest to + * profilers (like psyco.jit()), although nothing in the core uses it. + */ + int tick_counter; + + int gilstate_counter; + + PyObject *async_exc; /* Asynchronous exception to raise */ + long thread_id; /* Thread id where this tstate was created */ + + /* XXX signal handlers should also be here */ + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && (minorVersion >= 0 && minorVersion <= 3); + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_30 && version <= PythonVersion_33; + } +}; + +class PyThreadState_34_36 : public PyThreadState { +public: + PyThreadState *prev; + PyThreadState *next; + PyInterpreterState *interp; + + PyFrameObject *frame; + int recursion_depth; + char overflowed; /* The stack has overflowed. Allow 50 more calls + to handle the runtime error. */ + char recursion_critical; /* The current calls must not cause + a stack overflow. */ + /* 'tracing' keeps track of the execution depth when tracing/profiling. + This is to prevent the actual trace/profile code from being recorded in + the trace/profile. */ + int tracing; + int use_tracing; + + Py_tracefunc c_profilefunc; + Py_tracefunc c_tracefunc; + PyObject *c_profileobj; + PyObject *c_traceobj; + + PyObject *curexc_type; + PyObject *curexc_value; + PyObject *curexc_traceback; + + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + + PyObject *dict; /* Stores per-thread state */ + + int gilstate_counter; + + PyObject *async_exc; /* Asynchronous exception to raise */ + + long thread_id; /* Thread id where this tstate was created */ + /* XXX signal handlers should also be here */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && minorVersion >= 4 && minorVersion <= 6; + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_34 && version <= PythonVersion_36; + } +}; + +struct _PyErr_StackItem { + PyObject *exc_type, *exc_value, *exc_traceback; + struct _PyErr_StackItem *previous_item; +}; + +class PyThreadState_37 : public PyThreadState { +public: + PyThreadState * prev; + PyThreadState *next; + PyInterpreterState *interp; + + PyFrameObject *frame; + int recursion_depth; + char overflowed; /* The stack has overflowed. Allow 50 more calls + to handle the runtime error. */ + char recursion_critical; /* The current calls must not cause + a stack overflow. */ + /* 'tracing' keeps track of the execution depth when tracing/profiling. + This is to prevent the actual trace/profile code from being recorded in + the trace/profile. */ + int stackcheck_counter; + + int tracing; + int use_tracing; + + Py_tracefunc c_profilefunc; + Py_tracefunc c_tracefunc; + PyObject *c_profileobj; + PyObject *c_traceobj; + + PyObject *curexc_type; + PyObject *curexc_value; + PyObject *curexc_traceback; + + _PyErr_StackItem exc_state; + _PyErr_StackItem *exc_info; + + PyObject *dict; /* Stores per-thread state */ + + int gilstate_counter; + + PyObject *async_exc; /* Asynchronous exception to raise */ + + unsigned long thread_id; /* Thread id where this tstate was created */ + + static bool IsFor(int majorVersion, int minorVersion) { + return majorVersion == 3 && minorVersion >= 7; + } + + static bool IsFor(PythonVersion version) { + return version >= PythonVersion_37; + } +}; + +class PyIntObject : public PyObject { +public: + long ob_ival; +}; + +class Py3kLongObject : public PyVarObject { +public: + DWORD ob_digit[1]; +}; + +class PyOldStyleClassObject : public PyObject { +public: + PyObject *cl_bases; /* A tuple of class objects */ + PyObject *cl_dict; /* A dictionary */ + PyObject *cl_name; /* A string */ + /* The following three are functions or nullptr */ + PyObject *cl_getattr; + PyObject *cl_setattr; + PyObject *cl_delattr; +}; + +class PyInstanceObject : public PyObject { +public: + PyOldStyleClassObject *in_class; /* The class object */ + PyObject *in_dict; /* A dictionary */ + PyObject *in_weakreflist; /* List of weak references */ +}; + +#endif diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/ref_utils.hpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/ref_utils.hpp new file mode 100644 index 0000000..d1fa07d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/common/ref_utils.hpp @@ -0,0 +1,63 @@ +#ifndef _REF_UTILS_HPP_ +#define _REF_UTILS_HPP_ + + +PyObject* GetPyObjectPointerNoDebugInfo(bool isDebug, PyObject* object) { + if (object != nullptr && isDebug) { + // debug builds have 2 extra pointers at the front that we don't care about + return (PyObject*)((size_t*)object + 2); + } + return object; +} + +void DecRef(PyObject* object, bool isDebug) { + auto noDebug = GetPyObjectPointerNoDebugInfo(isDebug, object); + + if (noDebug != nullptr && --noDebug->ob_refcnt == 0) { + ((PyTypeObject*)GetPyObjectPointerNoDebugInfo(isDebug, noDebug->ob_type))->tp_dealloc(object); + } +} + +void IncRef(PyObject* object) { + object->ob_refcnt++; +} + +class PyObjectHolder { +private: + PyObject* _object; +public: + bool _isDebug; + + PyObjectHolder(bool isDebug) { + _object = nullptr; + _isDebug = isDebug; + } + + PyObjectHolder(bool isDebug, PyObject *object) { + _object = object; + _isDebug = isDebug; + }; + + PyObjectHolder(bool isDebug, PyObject *object, bool addRef) { + _object = object; + _isDebug = isDebug; + if (_object != nullptr && addRef) { + GetPyObjectPointerNoDebugInfo(_isDebug, _object)->ob_refcnt++; + } + }; + + PyObject* ToPython() { + return _object; + } + + ~PyObjectHolder() { + DecRef(_object, _isDebug); + } + + PyObject* operator* () { + return GetPyObjectPointerNoDebugInfo(_isDebug, _object); + } +}; + + +#endif //_REF_UTILS_HPP_ \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/.gitignore b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/.gitignore new file mode 100644 index 0000000..826fe93 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/.gitignore @@ -0,0 +1,4 @@ +/attach_x86.dylib +/attach_x86_64.dylib +/attach_linux_x86.o +/attach_linux_x86_64.o diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/attach.cpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/attach.cpp new file mode 100644 index 0000000..6502c06 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/attach.cpp @@ -0,0 +1,111 @@ +// This is much simpler than the windows version because we're using gdb and +// we assume that gdb will call things in the correct thread already. + +//compile with: g++ -shared -o attach_linux.so -fPIC -nostartfiles attach_linux.c + + +#include +#include +#include +#include + +#include "../common/python.h" +#include "../common/ref_utils.hpp" +#include "../common/py_utils.hpp" +#include "../common/py_settrace.hpp" +//#include used for usleep + +// Exported function: hello(): Just to print something and check that we've been +// able to connect. +extern "C" int hello(void); + +int hello() +{ + printf("Hello world!\n"); + + void *module = dlopen(nullptr, 0x2); + + void *hndl = dlsym (module, "PyGILState_Ensure"); + if(hndl == nullptr){ + printf("nullptr\n"); + + }else{ + printf("Worked (found PyGILState_Ensure)!\n"); + } + + printf("%d", GetPythonVersion(module)); + + + return 2; +} + + +// Internal function to keep on the tracing +int _PYDEVD_ExecWithGILSetSysStrace(bool showDebugInfo, bool isDebug); + +// Implementation details below +typedef PyObject* (PyImport_ImportModuleNoBlock) (const char *name); +typedef int (*PyEval_ThreadsInitialized)(); +typedef unsigned long (*_PyEval_GetSwitchInterval)(void); +typedef void (*_PyEval_SetSwitchInterval)(unsigned long microseconds); + +// isDebug is pretty important! Must be true on python debug builds (python_d) +// If this value is passed wrongly the program will crash. +extern "C" int DoAttach(bool isDebug, const char *command, bool showDebugInfo); + +int DoAttach(bool isDebug, const char *command, bool showDebugInfo) +{ + void *module = dlopen(nullptr, 0x2); + DEFINE_PROC(isInitFunc, Py_IsInitialized*, "Py_IsInitialized", 1); + DEFINE_PROC(gilEnsure, PyGILState_Ensure*, "PyGILState_Ensure", 51); + DEFINE_PROC(gilRelease, PyGILState_Release*, "PyGILState_Release", 51); + + + if(!isInitFunc()){ + if(showDebugInfo){ + printf("Py_IsInitialized returned false.\n"); + } + return 2; + } + + PythonVersion version = GetPythonVersion(module); + + DEFINE_PROC(interpHead, PyInterpreterState_Head*, "PyInterpreterState_Head", 51); + + auto head = interpHead(); + if (head == nullptr) { + // this interpreter is loaded but not initialized. + if(showDebugInfo){ + printf("Interpreter not initialized!\n"); + } + return 54; + } + + // Note: unlike windows where we have to do many things to enable threading + // to work to get the gil, here we'll be executing in an existing thread, + // so, it's mostly a matter of getting the GIL and running it and we shouldn't + // have any more problems. + + DEFINE_PROC(pyRun_SimpleString, PyRun_SimpleString*, "PyRun_SimpleString", 51); + + GilHolder gilLock(gilEnsure, gilRelease); // acquire and hold the GIL until done... + + pyRun_SimpleString(command); + return 0; +} + + +// This is the function which enables us to set the sys.settrace for all the threads +// which are already running. +extern "C" int AttachDebuggerTracing(bool showDebugInfo, void* pSetTraceFunc, void* pTraceFunc, unsigned int threadId, void* pPyNone); + +int AttachDebuggerTracing(bool showDebugInfo, void* pSetTraceFunc, void* pTraceFunc, unsigned int threadId, void* pPyNone) +{ + void *module = dlopen(nullptr, 0x2); + bool isDebug = false; + PyObjectHolder traceFunc(isDebug, (PyObject*) pTraceFunc, true); + PyObjectHolder setTraceFunc(isDebug, (PyObject*) pSetTraceFunc, true); + PyObjectHolder pyNone(isDebug, reinterpret_cast(pPyNone), true); + return InternalSetSysTraceFunc(module, isDebug, showDebugInfo, &traceFunc, &setTraceFunc, threadId, &pyNone); +} + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_linux.sh b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_linux.sh new file mode 100644 index 0000000..3a1ebc2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_linux.sh @@ -0,0 +1,9 @@ +g++ -m64 -shared -o attach_linux_amd64.so -fPIC -nostartfiles attach.cpp +mv attach_linux_amd64.so ../attach_linux_amd64.so +echo Compiled amd64 + +echo Note: may need "sudo apt-get install libx32gcc-4.8-dev" and "sudo apt-get install libc6-dev-i386" and "sudo apt-get install g++-multilib" to compile 32 bits + +g++ -m32 -shared -o attach_linux_x86.so -fPIC -nostartfiles attach.cpp +mv attach_linux_x86.so ../attach_linux_x86.so +echo Compiled x86 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_mac.sh b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_mac.sh new file mode 100644 index 0000000..cc5375e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/compile_mac.sh @@ -0,0 +1,11 @@ +g++ -fPIC -D_REENTRANT -std=c++11 -arch x86_64 -c -o attach_x86_64.o attach.cpp +g++ -dynamiclib -nostartfiles -arch x86_64 -o attach_x86_64.dylib attach_x86_64.o -lc +rm attach_x86_64.o +mv attach_x86_64.dylib ../attach_x86_64.dylib + + +g++ -fPIC -D_REENTRANT -std=c++11 -arch i386 -c -o attach_x86.o attach.cpp +g++ -dynamiclib -nostartfiles -arch i386 -o attach_x86.dylib attach_x86.o -lc +rm attach_x86.o +mv attach_x86.dylib ../attach_x86.dylib + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py new file mode 100644 index 0000000..8a22054 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac/lldb_prepare.py @@ -0,0 +1,54 @@ +# This file is meant to be run inside lldb +# It registers command to load library and invoke attach function +# Also it marks process threads to to distinguish them from debugger +# threads later while settings trace in threads + +def load_lib_and_attach(debugger, command, result, internal_dict): + import shlex + args = shlex.split(command) + + dll = args[0] + is_debug = args[1] + python_code = args[2] + show_debug_info = args[3] + + import lldb + options = lldb.SBExpressionOptions() + options.SetFetchDynamicValue() + options.SetTryAllThreads(run_others=False) + options.SetTimeoutInMicroSeconds(timeout=10000000) + + print(dll) + target = debugger.GetSelectedTarget() + res = target.EvaluateExpression("(void*)dlopen(\"%s\", 2);" % ( + dll), options) + error = res.GetError() + if error: + print(error) + + print(python_code) + res = target.EvaluateExpression("(int)DoAttach(%s, \"%s\", %s);" % ( + is_debug, python_code.replace('"', "'"), show_debug_info), options) + error = res.GetError() + if error: + print(error) + +def __lldb_init_module(debugger, internal_dict): + import lldb + + debugger.HandleCommand('command script add -f lldb_prepare.load_lib_and_attach load_lib_and_attach') + + try: + target = debugger.GetSelectedTarget() + if target: + process = target.GetProcess() + if process: + for thread in process: + # print('Marking process thread %d'%thread.GetThreadID()) + internal_dict['_thread_%d' % thread.GetThreadID()] = True + # thread.Suspend() + except: + import traceback;traceback.print_exc() + + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__init__.py new file mode 100644 index 0000000..aa138cc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/__init__.py @@ -0,0 +1,263 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Windows application debugging engine for Python. + +by Mario Vilas (mvilas at gmail.com) + +Project: U{http://sourceforge.net/projects/winappdbg/} + +Web: U{http://winappdbg.sourceforge.net/} + +Blog: U{http://breakingcode.wordpress.com} + +@group Debugging: + Debug, EventHandler, EventSift, DebugLog + +@group Instrumentation: + System, Process, Thread, Module, Window, Registry + +@group Disassemblers: + Disassembler, + BeaEngine, DistormEngine, PyDasmEngine + +@group Crash reporting: + Crash, CrashDump, CrashDAO, CrashDictionary + +@group Memory search: + Search, + Pattern, + BytePattern, + TextPattern, + RegExpPattern, + HexPattern + +@group Debug events: + Event, + NoEvent, + CreateProcessEvent, + CreateThreadEvent, + ExitProcessEvent, + ExitThreadEvent, + LoadDLLEvent, + UnloadDLLEvent, + OutputDebugStringEvent, + RIPEvent, + ExceptionEvent + +@group Win32 API wrappers: + win32, Handle, ProcessHandle, ThreadHandle, FileHandle + +@group Helpers: + HexInput, HexOutput, HexDump, Color, Table, Logger, + PathOperations, + MemoryAddresses, + CustomAddressIterator, + DataAddressIterator, + ImageAddressIterator, + MappedAddressIterator, + ExecutableAddressIterator, + ReadableAddressIterator, + WriteableAddressIterator, + ExecutableAndWriteableAddressIterator, + DebugRegister, + Regenerator + +@group Warnings: + MixedBitsWarning, BreakpointWarning, BreakpointCallbackWarning, + EventCallbackWarning, DebugSymbolsWarning, CrashWarning + +@group Deprecated classes: + CrashContainer, CrashTable, CrashTableMSSQL, + VolatileCrashContainer, DummyCrashContainer + +@type version_number: float +@var version_number: This WinAppDbg major and minor version, + as a floating point number. Use this for compatibility checking. + +@type version: str +@var version: This WinAppDbg release version, + as a printable string. Use this to show to the user. + +@undocumented: plugins +""" + +__revision__ = "$Id$" + +# List of all public symbols +__all__ = [ + # Library version + 'version', + 'version_number', + + # from breakpoint import * +## 'Breakpoint', +## 'CodeBreakpoint', +## 'PageBreakpoint', +## 'HardwareBreakpoint', +## 'Hook', +## 'ApiHook', +## 'BufferWatch', + 'BreakpointWarning', + 'BreakpointCallbackWarning', + + # from crash import * + 'Crash', + 'CrashWarning', + 'CrashDictionary', + 'CrashContainer', + 'CrashTable', + 'CrashTableMSSQL', + 'VolatileCrashContainer', + 'DummyCrashContainer', + + # from debug import * + 'Debug', + 'MixedBitsWarning', + + # from disasm import * + 'Disassembler', + 'BeaEngine', + 'DistormEngine', + 'PyDasmEngine', + + # from event import * + 'EventHandler', + 'EventSift', +## 'EventFactory', +## 'EventDispatcher', + 'EventCallbackWarning', + 'Event', +## 'NoEvent', + 'CreateProcessEvent', + 'CreateThreadEvent', + 'ExitProcessEvent', + 'ExitThreadEvent', + 'LoadDLLEvent', + 'UnloadDLLEvent', + 'OutputDebugStringEvent', + 'RIPEvent', + 'ExceptionEvent', + + # from interactive import * +## 'ConsoleDebugger', + + # from module import * + 'Module', + 'DebugSymbolsWarning', + + # from process import * + 'Process', + + # from system import * + 'System', + + # from search import * + 'Search', + 'Pattern', + 'BytePattern', + 'TextPattern', + 'RegExpPattern', + 'HexPattern', + + # from registry import * + 'Registry', + + # from textio import * + 'HexDump', + 'HexInput', + 'HexOutput', + 'Color', + 'Table', + 'CrashDump', + 'DebugLog', + 'Logger', + + # from thread import * + 'Thread', + + # from util import * + 'PathOperations', + 'MemoryAddresses', + 'CustomAddressIterator', + 'DataAddressIterator', + 'ImageAddressIterator', + 'MappedAddressIterator', + 'ExecutableAddressIterator', + 'ReadableAddressIterator', + 'WriteableAddressIterator', + 'ExecutableAndWriteableAddressIterator', + 'DebugRegister', + + # from window import * + 'Window', + + # import win32 + 'win32', + + # from win32 import Handle, ProcessHandle, ThreadHandle, FileHandle + 'Handle', + 'ProcessHandle', + 'ThreadHandle', + 'FileHandle', + ] + +# Import all public symbols +from winappdbg.breakpoint import * +from winappdbg.crash import * +from winappdbg.debug import * +from winappdbg.disasm import * +from winappdbg.event import * +from winappdbg.interactive import * +from winappdbg.module import * +from winappdbg.process import * +from winappdbg.registry import * +from winappdbg.system import * +from winappdbg.search import * +from winappdbg.textio import * +from winappdbg.thread import * +from winappdbg.util import * +from winappdbg.window import * + +import winappdbg.win32 +from winappdbg.win32 import Handle, ProcessHandle, ThreadHandle, FileHandle + +try: + from sql import * + __all__.append('CrashDAO') +except ImportError: + import warnings + warnings.warn("No SQL database support present (missing dependencies?)", + ImportWarning) + +# Library version +version_number = 1.5 +version = "Version %s" % version_number diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py new file mode 100644 index 0000000..3b9ca73 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/breakpoint.py @@ -0,0 +1,4822 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Breakpoints. + +@group Breakpoints: + Breakpoint, CodeBreakpoint, PageBreakpoint, HardwareBreakpoint, + BufferWatch, Hook, ApiHook + +@group Warnings: + BreakpointWarning, BreakpointCallbackWarning +""" + +__revision__ = "$Id$" + +__all__ = [ + + # Base class for breakpoints + 'Breakpoint', + + # Breakpoint implementations + 'CodeBreakpoint', + 'PageBreakpoint', + 'HardwareBreakpoint', + + # Hooks and watches + 'Hook', + 'ApiHook', + 'BufferWatch', + + # Warnings + 'BreakpointWarning', + 'BreakpointCallbackWarning', + + ] + +from winappdbg import win32 +from winappdbg import compat +import sys +from winappdbg.process import Process, Thread +from winappdbg.util import DebugRegister, MemoryAddresses +from winappdbg.textio import HexDump + +import ctypes +import warnings +import traceback + +#============================================================================== + +class BreakpointWarning (UserWarning): + """ + This warning is issued when a non-fatal error occurs that's related to + breakpoints. + """ + +class BreakpointCallbackWarning (RuntimeWarning): + """ + This warning is issued when an uncaught exception was raised by a + breakpoint's user-defined callback. + """ + +#============================================================================== + +class Breakpoint (object): + """ + Base class for breakpoints. + Here's the breakpoints state machine. + + @see: L{CodeBreakpoint}, L{PageBreakpoint}, L{HardwareBreakpoint} + + @group Breakpoint states: + DISABLED, ENABLED, ONESHOT, RUNNING + @group State machine: + hit, disable, enable, one_shot, running, + is_disabled, is_enabled, is_one_shot, is_running, + get_state, get_state_name + @group Information: + get_address, get_size, get_span, is_here + @group Conditional breakpoints: + is_conditional, is_unconditional, + get_condition, set_condition, eval_condition + @group Automatic breakpoints: + is_automatic, is_interactive, + get_action, set_action, run_action + + @cvar DISABLED: I{Disabled} S{->} Enabled, OneShot + @cvar ENABLED: I{Enabled} S{->} I{Running}, Disabled + @cvar ONESHOT: I{OneShot} S{->} I{Disabled} + @cvar RUNNING: I{Running} S{->} I{Enabled}, Disabled + + @type DISABLED: int + @type ENABLED: int + @type ONESHOT: int + @type RUNNING: int + + @type stateNames: dict E{lb} int S{->} str E{rb} + @cvar stateNames: User-friendly names for each breakpoint state. + + @type typeName: str + @cvar typeName: User friendly breakpoint type string. + """ + + # I don't think transitions Enabled <-> OneShot should be allowed... plus + # it would require special handling to avoid setting the same bp twice + + DISABLED = 0 + ENABLED = 1 + ONESHOT = 2 + RUNNING = 3 + + typeName = 'breakpoint' + + stateNames = { + DISABLED : 'disabled', + ENABLED : 'enabled', + ONESHOT : 'one shot', + RUNNING : 'running', + } + + def __init__(self, address, size = 1, condition = True, action = None): + """ + Breakpoint object. + + @type address: int + @param address: Memory address for breakpoint. + + @type size: int + @param size: Size of breakpoint in bytes (defaults to 1). + + @type condition: function + @param condition: (Optional) Condition callback function. + + The callback signature is:: + + def condition_callback(event): + return True # returns True or False + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @type action: function + @param action: (Optional) Action callback function. + If specified, the event is handled by this callback instead of + being dispatched normally. + + The callback signature is:: + + def action_callback(event): + pass # no return value + + Where B{event} is an L{Event} object. + """ + self.__address = address + self.__size = size + self.__state = self.DISABLED + + self.set_condition(condition) + self.set_action(action) + + def __repr__(self): + if self.is_disabled(): + state = 'Disabled' + else: + state = 'Active (%s)' % self.get_state_name() + if self.is_conditional(): + condition = 'conditional' + else: + condition = 'unconditional' + name = self.typeName + size = self.get_size() + if size == 1: + address = HexDump.address( self.get_address() ) + else: + begin = self.get_address() + end = begin + size + begin = HexDump.address(begin) + end = HexDump.address(end) + address = "range %s-%s" % (begin, end) + msg = "<%s %s %s at remote address %s>" + msg = msg % (state, condition, name, address) + return msg + +#------------------------------------------------------------------------------ + + def is_disabled(self): + """ + @rtype: bool + @return: C{True} if the breakpoint is in L{DISABLED} state. + """ + return self.get_state() == self.DISABLED + + def is_enabled(self): + """ + @rtype: bool + @return: C{True} if the breakpoint is in L{ENABLED} state. + """ + return self.get_state() == self.ENABLED + + def is_one_shot(self): + """ + @rtype: bool + @return: C{True} if the breakpoint is in L{ONESHOT} state. + """ + return self.get_state() == self.ONESHOT + + def is_running(self): + """ + @rtype: bool + @return: C{True} if the breakpoint is in L{RUNNING} state. + """ + return self.get_state() == self.RUNNING + + def is_here(self, address): + """ + @rtype: bool + @return: C{True} if the address is within the range of the breakpoint. + """ + begin = self.get_address() + end = begin + self.get_size() + return begin <= address < end + + def get_address(self): + """ + @rtype: int + @return: The target memory address for the breakpoint. + """ + return self.__address + + def get_size(self): + """ + @rtype: int + @return: The size in bytes of the breakpoint. + """ + return self.__size + + def get_span(self): + """ + @rtype: tuple( int, int ) + @return: + Starting and ending address of the memory range + covered by the breakpoint. + """ + address = self.get_address() + size = self.get_size() + return ( address, address + size ) + + def get_state(self): + """ + @rtype: int + @return: The current state of the breakpoint + (L{DISABLED}, L{ENABLED}, L{ONESHOT}, L{RUNNING}). + """ + return self.__state + + def get_state_name(self): + """ + @rtype: str + @return: The name of the current state of the breakpoint. + """ + return self.stateNames[ self.get_state() ] + +#------------------------------------------------------------------------------ + + def is_conditional(self): + """ + @see: L{__init__} + @rtype: bool + @return: C{True} if the breakpoint has a condition callback defined. + """ + # Do not evaluate as boolean! Test for identity with True instead. + return self.__condition is not True + + def is_unconditional(self): + """ + @rtype: bool + @return: C{True} if the breakpoint doesn't have a condition callback defined. + """ + # Do not evaluate as boolean! Test for identity with True instead. + return self.__condition is True + + def get_condition(self): + """ + @rtype: bool, function + @return: Returns the condition callback for conditional breakpoints. + Returns C{True} for unconditional breakpoints. + """ + return self.__condition + + def set_condition(self, condition = True): + """ + Sets a new condition callback for the breakpoint. + + @see: L{__init__} + + @type condition: function + @param condition: (Optional) Condition callback function. + """ + if condition is None: + self.__condition = True + else: + self.__condition = condition + + def eval_condition(self, event): + """ + Evaluates the breakpoint condition, if any was set. + + @type event: L{Event} + @param event: Debug event triggered by the breakpoint. + + @rtype: bool + @return: C{True} to dispatch the event, C{False} otherwise. + """ + condition = self.get_condition() + if condition is True: # shortcut for unconditional breakpoints + return True + if callable(condition): + try: + return bool( condition(event) ) + except Exception: + e = sys.exc_info()[1] + msg = ("Breakpoint condition callback %r" + " raised an exception: %s") + msg = msg % (condition, traceback.format_exc(e)) + warnings.warn(msg, BreakpointCallbackWarning) + return False + return bool( condition ) # force evaluation now + +#------------------------------------------------------------------------------ + + def is_automatic(self): + """ + @rtype: bool + @return: C{True} if the breakpoint has an action callback defined. + """ + return self.__action is not None + + def is_interactive(self): + """ + @rtype: bool + @return: + C{True} if the breakpoint doesn't have an action callback defined. + """ + return self.__action is None + + def get_action(self): + """ + @rtype: bool, function + @return: Returns the action callback for automatic breakpoints. + Returns C{None} for interactive breakpoints. + """ + return self.__action + + def set_action(self, action = None): + """ + Sets a new action callback for the breakpoint. + + @type action: function + @param action: (Optional) Action callback function. + """ + self.__action = action + + def run_action(self, event): + """ + Executes the breakpoint action callback, if any was set. + + @type event: L{Event} + @param event: Debug event triggered by the breakpoint. + """ + action = self.get_action() + if action is not None: + try: + return bool( action(event) ) + except Exception: + e = sys.exc_info()[1] + msg = ("Breakpoint action callback %r" + " raised an exception: %s") + msg = msg % (action, traceback.format_exc(e)) + warnings.warn(msg, BreakpointCallbackWarning) + return False + return True + +#------------------------------------------------------------------------------ + + def __bad_transition(self, state): + """ + Raises an C{AssertionError} exception for an invalid state transition. + + @see: L{stateNames} + + @type state: int + @param state: Intended breakpoint state. + + @raise Exception: Always. + """ + statemsg = "" + oldState = self.stateNames[ self.get_state() ] + newState = self.stateNames[ state ] + msg = "Invalid state transition (%s -> %s)" \ + " for breakpoint at address %s" + msg = msg % (oldState, newState, HexDump.address(self.get_address())) + raise AssertionError(msg) + + def disable(self, aProcess, aThread): + """ + Transition to L{DISABLED} state. + - When hit: OneShot S{->} Disabled + - Forced by user: Enabled, OneShot, Running S{->} Disabled + - Transition from running state may require special handling + by the breakpoint implementation class. + + @type aProcess: L{Process} + @param aProcess: Process object. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ +## if self.__state not in (self.ENABLED, self.ONESHOT, self.RUNNING): +## self.__bad_transition(self.DISABLED) + self.__state = self.DISABLED + + def enable(self, aProcess, aThread): + """ + Transition to L{ENABLED} state. + - When hit: Running S{->} Enabled + - Forced by user: Disabled, Running S{->} Enabled + - Transition from running state may require special handling + by the breakpoint implementation class. + + @type aProcess: L{Process} + @param aProcess: Process object. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ +## if self.__state not in (self.DISABLED, self.RUNNING): +## self.__bad_transition(self.ENABLED) + self.__state = self.ENABLED + + def one_shot(self, aProcess, aThread): + """ + Transition to L{ONESHOT} state. + - Forced by user: Disabled S{->} OneShot + + @type aProcess: L{Process} + @param aProcess: Process object. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ +## if self.__state != self.DISABLED: +## self.__bad_transition(self.ONESHOT) + self.__state = self.ONESHOT + + def running(self, aProcess, aThread): + """ + Transition to L{RUNNING} state. + - When hit: Enabled S{->} Running + + @type aProcess: L{Process} + @param aProcess: Process object. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ + if self.__state != self.ENABLED: + self.__bad_transition(self.RUNNING) + self.__state = self.RUNNING + + def hit(self, event): + """ + Notify a breakpoint that it's been hit. + + This triggers the corresponding state transition and sets the + C{breakpoint} property of the given L{Event} object. + + @see: L{disable}, L{enable}, L{one_shot}, L{running} + + @type event: L{Event} + @param event: Debug event to handle (depends on the breakpoint type). + + @raise AssertionError: Disabled breakpoints can't be hit. + """ + aProcess = event.get_process() + aThread = event.get_thread() + state = self.get_state() + + event.breakpoint = self + + if state == self.ENABLED: + self.running(aProcess, aThread) + + elif state == self.RUNNING: + self.enable(aProcess, aThread) + + elif state == self.ONESHOT: + self.disable(aProcess, aThread) + + elif state == self.DISABLED: + # this should not happen + msg = "Hit a disabled breakpoint at address %s" + msg = msg % HexDump.address( self.get_address() ) + warnings.warn(msg, BreakpointWarning) + +#============================================================================== + +# XXX TODO +# Check if the user is trying to set a code breakpoint on a memory mapped file, +# so we don't end up writing the int3 instruction in the file by accident. + +class CodeBreakpoint (Breakpoint): + """ + Code execution breakpoints (using an int3 opcode). + + @see: L{Debug.break_at} + + @type bpInstruction: str + @cvar bpInstruction: Breakpoint instruction for the current processor. + """ + + typeName = 'code breakpoint' + + if win32.arch in (win32.ARCH_I386, win32.ARCH_AMD64): + bpInstruction = '\xCC' # int 3 + + def __init__(self, address, condition = True, action = None): + """ + Code breakpoint object. + + @see: L{Breakpoint.__init__} + + @type address: int + @param address: Memory address for breakpoint. + + @type condition: function + @param condition: (Optional) Condition callback function. + + @type action: function + @param action: (Optional) Action callback function. + """ + if win32.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + msg = "Code breakpoints not supported for %s" % win32.arch + raise NotImplementedError(msg) + Breakpoint.__init__(self, address, len(self.bpInstruction), + condition, action) + self.__previousValue = self.bpInstruction + + def __set_bp(self, aProcess): + """ + Writes a breakpoint instruction at the target address. + + @type aProcess: L{Process} + @param aProcess: Process object. + """ + address = self.get_address() + self.__previousValue = aProcess.read(address, len(self.bpInstruction)) + if self.__previousValue == self.bpInstruction: + msg = "Possible overlapping code breakpoints at %s" + msg = msg % HexDump.address(address) + warnings.warn(msg, BreakpointWarning) + aProcess.write(address, self.bpInstruction) + + def __clear_bp(self, aProcess): + """ + Restores the original byte at the target address. + + @type aProcess: L{Process} + @param aProcess: Process object. + """ + address = self.get_address() + currentValue = aProcess.read(address, len(self.bpInstruction)) + if currentValue == self.bpInstruction: + # Only restore the previous value if the int3 is still there. + aProcess.write(self.get_address(), self.__previousValue) + else: + self.__previousValue = currentValue + msg = "Overwritten code breakpoint at %s" + msg = msg % HexDump.address(address) + warnings.warn(msg, BreakpointWarning) + + def disable(self, aProcess, aThread): + if not self.is_disabled() and not self.is_running(): + self.__clear_bp(aProcess) + super(CodeBreakpoint, self).disable(aProcess, aThread) + + def enable(self, aProcess, aThread): + if not self.is_enabled() and not self.is_one_shot(): + self.__set_bp(aProcess) + super(CodeBreakpoint, self).enable(aProcess, aThread) + + def one_shot(self, aProcess, aThread): + if not self.is_enabled() and not self.is_one_shot(): + self.__set_bp(aProcess) + super(CodeBreakpoint, self).one_shot(aProcess, aThread) + + # FIXME race condition here (however unlikely) + # If another thread runs on over the target address while + # the breakpoint is in RUNNING state, we'll miss it. There + # is a solution to this but it's somewhat complicated, so + # I'm leaving it for another version of the debugger. :( + def running(self, aProcess, aThread): + if self.is_enabled(): + self.__clear_bp(aProcess) + aThread.set_tf() + super(CodeBreakpoint, self).running(aProcess, aThread) + +#============================================================================== + +# TODO: +# * If the original page was already a guard page, the exception should be +# passed to the debugee instead of being handled by the debugger. +# * If the original page was already a guard page, it should NOT be converted +# to a no-access page when disabling the breakpoint. +# * If the page permissions were modified after the breakpoint was enabled, +# no change should be done on them when disabling the breakpoint. For this +# we need to remember the original page permissions instead of blindly +# setting and clearing the guard page bit on them. +# * Some pages seem to be "magic" and resist all attempts at changing their +# protect bits (for example the pages where the PEB and TEB reside). Maybe +# a more descriptive error message could be shown in this case. + +class PageBreakpoint (Breakpoint): + """ + Page access breakpoint (using guard pages). + + @see: L{Debug.watch_buffer} + + @group Information: + get_size_in_pages + """ + + typeName = 'page breakpoint' + +#------------------------------------------------------------------------------ + + def __init__(self, address, pages = 1, condition = True, action = None): + """ + Page breakpoint object. + + @see: L{Breakpoint.__init__} + + @type address: int + @param address: Memory address for breakpoint. + + @type pages: int + @param address: Size of breakpoint in pages. + + @type condition: function + @param condition: (Optional) Condition callback function. + + @type action: function + @param action: (Optional) Action callback function. + """ + Breakpoint.__init__(self, address, pages * MemoryAddresses.pageSize, + condition, action) +## if (address & 0x00000FFF) != 0: + floordiv_align = long(address) // long(MemoryAddresses.pageSize) + truediv_align = float(address) / float(MemoryAddresses.pageSize) + if floordiv_align != truediv_align: + msg = "Address of page breakpoint " \ + "must be aligned to a page size boundary " \ + "(value %s received)" % HexDump.address(address) + raise ValueError(msg) + + def get_size_in_pages(self): + """ + @rtype: int + @return: The size in pages of the breakpoint. + """ + # The size is always a multiple of the page size. + return self.get_size() // MemoryAddresses.pageSize + + def __set_bp(self, aProcess): + """ + Sets the target pages as guard pages. + + @type aProcess: L{Process} + @param aProcess: Process object. + """ + lpAddress = self.get_address() + dwSize = self.get_size() + flNewProtect = aProcess.mquery(lpAddress).Protect + flNewProtect = flNewProtect | win32.PAGE_GUARD + aProcess.mprotect(lpAddress, dwSize, flNewProtect) + + def __clear_bp(self, aProcess): + """ + Restores the original permissions of the target pages. + + @type aProcess: L{Process} + @param aProcess: Process object. + """ + lpAddress = self.get_address() + flNewProtect = aProcess.mquery(lpAddress).Protect + flNewProtect = flNewProtect & (0xFFFFFFFF ^ win32.PAGE_GUARD) # DWORD + aProcess.mprotect(lpAddress, self.get_size(), flNewProtect) + + def disable(self, aProcess, aThread): + if not self.is_disabled(): + self.__clear_bp(aProcess) + super(PageBreakpoint, self).disable(aProcess, aThread) + + def enable(self, aProcess, aThread): + if win32.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + msg = "Only one-shot page breakpoints are supported for %s" + raise NotImplementedError(msg % win32.arch) + if not self.is_enabled() and not self.is_one_shot(): + self.__set_bp(aProcess) + super(PageBreakpoint, self).enable(aProcess, aThread) + + def one_shot(self, aProcess, aThread): + if not self.is_enabled() and not self.is_one_shot(): + self.__set_bp(aProcess) + super(PageBreakpoint, self).one_shot(aProcess, aThread) + + def running(self, aProcess, aThread): + aThread.set_tf() + super(PageBreakpoint, self).running(aProcess, aThread) + +#============================================================================== + +class HardwareBreakpoint (Breakpoint): + """ + Hardware breakpoint (using debug registers). + + @see: L{Debug.watch_variable} + + @group Information: + get_slot, get_trigger, get_watch + + @group Trigger flags: + BREAK_ON_EXECUTION, BREAK_ON_WRITE, BREAK_ON_ACCESS + + @group Watch size flags: + WATCH_BYTE, WATCH_WORD, WATCH_DWORD, WATCH_QWORD + + @type BREAK_ON_EXECUTION: int + @cvar BREAK_ON_EXECUTION: Break on execution. + + @type BREAK_ON_WRITE: int + @cvar BREAK_ON_WRITE: Break on write. + + @type BREAK_ON_ACCESS: int + @cvar BREAK_ON_ACCESS: Break on read or write. + + @type WATCH_BYTE: int + @cvar WATCH_BYTE: Watch a byte. + + @type WATCH_WORD: int + @cvar WATCH_WORD: Watch a word (2 bytes). + + @type WATCH_DWORD: int + @cvar WATCH_DWORD: Watch a double word (4 bytes). + + @type WATCH_QWORD: int + @cvar WATCH_QWORD: Watch one quad word (8 bytes). + + @type validTriggers: tuple + @cvar validTriggers: Valid trigger flag values. + + @type validWatchSizes: tuple + @cvar validWatchSizes: Valid watch flag values. + """ + + typeName = 'hardware breakpoint' + + BREAK_ON_EXECUTION = DebugRegister.BREAK_ON_EXECUTION + BREAK_ON_WRITE = DebugRegister.BREAK_ON_WRITE + BREAK_ON_ACCESS = DebugRegister.BREAK_ON_ACCESS + + WATCH_BYTE = DebugRegister.WATCH_BYTE + WATCH_WORD = DebugRegister.WATCH_WORD + WATCH_DWORD = DebugRegister.WATCH_DWORD + WATCH_QWORD = DebugRegister.WATCH_QWORD + + validTriggers = ( + BREAK_ON_EXECUTION, + BREAK_ON_WRITE, + BREAK_ON_ACCESS, + ) + + validWatchSizes = ( + WATCH_BYTE, + WATCH_WORD, + WATCH_DWORD, + WATCH_QWORD, + ) + + def __init__(self, address, triggerFlag = BREAK_ON_ACCESS, + sizeFlag = WATCH_DWORD, + condition = True, + action = None): + """ + Hardware breakpoint object. + + @see: L{Breakpoint.__init__} + + @type address: int + @param address: Memory address for breakpoint. + + @type triggerFlag: int + @param triggerFlag: Trigger of breakpoint. Must be one of the following: + + - L{BREAK_ON_EXECUTION} + + Break on code execution. + + - L{BREAK_ON_WRITE} + + Break on memory read or write. + + - L{BREAK_ON_ACCESS} + + Break on memory write. + + @type sizeFlag: int + @param sizeFlag: Size of breakpoint. Must be one of the following: + + - L{WATCH_BYTE} + + One (1) byte in size. + + - L{WATCH_WORD} + + Two (2) bytes in size. + + - L{WATCH_DWORD} + + Four (4) bytes in size. + + - L{WATCH_QWORD} + + Eight (8) bytes in size. + + @type condition: function + @param condition: (Optional) Condition callback function. + + @type action: function + @param action: (Optional) Action callback function. + """ + if win32.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + msg = "Hardware breakpoints not supported for %s" % win32.arch + raise NotImplementedError(msg) + if sizeFlag == self.WATCH_BYTE: + size = 1 + elif sizeFlag == self.WATCH_WORD: + size = 2 + elif sizeFlag == self.WATCH_DWORD: + size = 4 + elif sizeFlag == self.WATCH_QWORD: + size = 8 + else: + msg = "Invalid size flag for hardware breakpoint (%s)" + msg = msg % repr(sizeFlag) + raise ValueError(msg) + + if triggerFlag not in self.validTriggers: + msg = "Invalid trigger flag for hardware breakpoint (%s)" + msg = msg % repr(triggerFlag) + raise ValueError(msg) + + Breakpoint.__init__(self, address, size, condition, action) + self.__trigger = triggerFlag + self.__watch = sizeFlag + self.__slot = None + + def __clear_bp(self, aThread): + """ + Clears this breakpoint from the debug registers. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ + if self.__slot is not None: + aThread.suspend() + try: + ctx = aThread.get_context(win32.CONTEXT_DEBUG_REGISTERS) + DebugRegister.clear_bp(ctx, self.__slot) + aThread.set_context(ctx) + self.__slot = None + finally: + aThread.resume() + + def __set_bp(self, aThread): + """ + Sets this breakpoint in the debug registers. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ + if self.__slot is None: + aThread.suspend() + try: + ctx = aThread.get_context(win32.CONTEXT_DEBUG_REGISTERS) + self.__slot = DebugRegister.find_slot(ctx) + if self.__slot is None: + msg = "No available hardware breakpoint slots for thread ID %d" + msg = msg % aThread.get_tid() + raise RuntimeError(msg) + DebugRegister.set_bp(ctx, self.__slot, self.get_address(), + self.__trigger, self.__watch) + aThread.set_context(ctx) + finally: + aThread.resume() + + def get_slot(self): + """ + @rtype: int + @return: The debug register number used by this breakpoint, + or C{None} if the breakpoint is not active. + """ + return self.__slot + + def get_trigger(self): + """ + @see: L{validTriggers} + @rtype: int + @return: The breakpoint trigger flag. + """ + return self.__trigger + + def get_watch(self): + """ + @see: L{validWatchSizes} + @rtype: int + @return: The breakpoint watch flag. + """ + return self.__watch + + def disable(self, aProcess, aThread): + if not self.is_disabled(): + self.__clear_bp(aThread) + super(HardwareBreakpoint, self).disable(aProcess, aThread) + + def enable(self, aProcess, aThread): + if not self.is_enabled() and not self.is_one_shot(): + self.__set_bp(aThread) + super(HardwareBreakpoint, self).enable(aProcess, aThread) + + def one_shot(self, aProcess, aThread): + if not self.is_enabled() and not self.is_one_shot(): + self.__set_bp(aThread) + super(HardwareBreakpoint, self).one_shot(aProcess, aThread) + + def running(self, aProcess, aThread): + self.__clear_bp(aThread) + super(HardwareBreakpoint, self).running(aProcess, aThread) + aThread.set_tf() + +#============================================================================== + +# XXX FIXME +# +# The implementation of function hooks is very simple. A breakpoint is set at +# the entry point. Each time it's hit the "pre" callback is executed. If a +# "post" callback was defined, a one-shot breakpoint is set at the return +# address - and when that breakpoint hits, the "post" callback is executed. +# +# Functions hooks, as they are implemented now, don't work correctly for +# recursive functions. The problem is we don't know when to remove the +# breakpoint at the return address. Also there could be more than one return +# address. +# +# One possible solution would involve a dictionary of lists, where the key +# would be the thread ID and the value a stack of return addresses. But we +# still don't know what to do if the "wrong" return address is hit for some +# reason (maybe check the stack pointer?). Or if both a code and a hardware +# breakpoint are hit simultaneously. +# +# For now, the workaround for the user is to set only the "pre" callback for +# functions that are known to be recursive. +# +# If an exception is thrown by a hooked function and caught by one of it's +# parent functions, the "post" callback won't be called and weird stuff may +# happen. A possible solution is to put a breakpoint in the system call that +# unwinds the stack, to detect this case and remove the "post" breakpoint. +# +# Hooks may also behave oddly if the return address is overwritten by a buffer +# overflow bug (this is similar to the exception problem). But it's probably a +# minor issue since when you're fuzzing a function for overflows you're usually +# not interested in the return value anyway. + +# TODO: an API to modify the hooked function's arguments + +class Hook (object): + """ + Factory class to produce hook objects. Used by L{Debug.hook_function} and + L{Debug.stalk_function}. + + When you try to instance this class, one of the architecture specific + implementations is returned instead. + + Instances act as an action callback for code breakpoints set at the + beginning of a function. It automatically retrieves the parameters from + the stack, sets a breakpoint at the return address and retrieves the + return value from the function call. + + @see: L{_Hook_i386}, L{_Hook_amd64} + + @type useHardwareBreakpoints: bool + @cvar useHardwareBreakpoints: C{True} to try to use hardware breakpoints, + C{False} otherwise. + """ + + # This is a factory class that returns + # the architecture specific implementation. + def __new__(cls, *argv, **argd): + try: + arch = argd['arch'] + del argd['arch'] + except KeyError: + try: + arch = argv[4] + argv = argv[:4] + argv[5:] + except IndexError: + raise TypeError("Missing 'arch' argument!") + if arch is None: + arch = win32.arch + if arch == win32.ARCH_I386: + return _Hook_i386(*argv, **argd) + if arch == win32.ARCH_AMD64: + return _Hook_amd64(*argv, **argd) + return object.__new__(cls, *argv, **argd) + + # XXX FIXME + # + # Hardware breakpoints don't work correctly (or al all) in old VirtualBox + # versions (3.0 and below). + # + # Maybe there should be a way to autodetect the buggy VirtualBox versions + # and tell Hook objects not to use hardware breakpoints? + # + # For now the workaround is to manually set this variable to True when + # WinAppDbg is installed on a physical machine. + # + useHardwareBreakpoints = False + + def __init__(self, preCB = None, postCB = None, + paramCount = None, signature = None, + arch = None): + """ + @type preCB: function + @param preCB: (Optional) Callback triggered on function entry. + + The signature for the callback should be something like this:: + + def pre_LoadLibraryEx(event, ra, lpFilename, hFile, dwFlags): + + # return address + ra = params[0] + + # function arguments start from here... + szFilename = event.get_process().peek_string(lpFilename) + + # (...) + + Note that all pointer types are treated like void pointers, so your + callback won't get the string or structure pointed to by it, but + the remote memory address instead. This is so to prevent the ctypes + library from being "too helpful" and trying to dereference the + pointer. To get the actual data being pointed to, use one of the + L{Process.read} methods. + + @type postCB: function + @param postCB: (Optional) Callback triggered on function exit. + + The signature for the callback should be something like this:: + + def post_LoadLibraryEx(event, return_value): + + # (...) + + @type paramCount: int + @param paramCount: + (Optional) Number of parameters for the C{preCB} callback, + not counting the return address. Parameters are read from + the stack and assumed to be DWORDs in 32 bits and QWORDs in 64. + + This is a faster way to pull stack parameters in 32 bits, but in 64 + bits (or with some odd APIs in 32 bits) it won't be useful, since + not all arguments to the hooked function will be of the same size. + + For a more reliable and cross-platform way of hooking use the + C{signature} argument instead. + + @type signature: tuple + @param signature: + (Optional) Tuple of C{ctypes} data types that constitute the + hooked function signature. When the function is called, this will + be used to parse the arguments from the stack. Overrides the + C{paramCount} argument. + + @type arch: str + @param arch: (Optional) Target architecture. Defaults to the current + architecture. See: L{win32.arch} + """ + self.__preCB = preCB + self.__postCB = postCB + self.__paramStack = dict() # tid -> list of tuple( arg, arg, arg... ) + + self._paramCount = paramCount + + if win32.arch != win32.ARCH_I386: + self.useHardwareBreakpoints = False + + if win32.bits == 64 and paramCount and not signature: + signature = (win32.QWORD,) * paramCount + + if signature: + self._signature = self._calc_signature(signature) + else: + self._signature = None + + def _cast_signature_pointers_to_void(self, signature): + c_void_p = ctypes.c_void_p + c_char_p = ctypes.c_char_p + c_wchar_p = ctypes.c_wchar_p + _Pointer = ctypes._Pointer + cast = ctypes.cast + for i in compat.xrange(len(signature)): + t = signature[i] + if t is not c_void_p and (issubclass(t, _Pointer) \ + or t in [c_char_p, c_wchar_p]): + signature[i] = cast(t, c_void_p) + + def _calc_signature(self, signature): + raise NotImplementedError( + "Hook signatures are not supported for architecture: %s" \ + % win32.arch) + + def _get_return_address(self, aProcess, aThread): + return None + + def _get_function_arguments(self, aProcess, aThread): + if self._signature or self._paramCount: + raise NotImplementedError( + "Hook signatures are not supported for architecture: %s" \ + % win32.arch) + return () + + def _get_return_value(self, aThread): + return None + + # By using break_at() to set a process-wide breakpoint on the function's + # return address, we might hit a race condition when more than one thread + # is being debugged. + # + # Hardware breakpoints should be used instead. But since a thread can run + # out of those, we need to fall back to this method when needed. + + def __call__(self, event): + """ + Handles the breakpoint event on entry of the function. + + @type event: L{ExceptionEvent} + @param event: Breakpoint hit event. + + @raise WindowsError: An error occured. + """ + debug = event.debug + + dwProcessId = event.get_pid() + dwThreadId = event.get_tid() + aProcess = event.get_process() + aThread = event.get_thread() + + # Get the return address and function arguments. + ra = self._get_return_address(aProcess, aThread) + params = self._get_function_arguments(aProcess, aThread) + + # Keep the function arguments for later use. + self.__push_params(dwThreadId, params) + + # If we need to hook the return from the function... + bHookedReturn = False + if ra is not None and self.__postCB is not None: + + # Try to set a one shot hardware breakpoint at the return address. + useHardwareBreakpoints = self.useHardwareBreakpoints + if useHardwareBreakpoints: + try: + debug.define_hardware_breakpoint( + dwThreadId, + ra, + event.debug.BP_BREAK_ON_EXECUTION, + event.debug.BP_WATCH_BYTE, + True, + self.__postCallAction_hwbp + ) + debug.enable_one_shot_hardware_breakpoint(dwThreadId, ra) + bHookedReturn = True + except Exception: + e = sys.exc_info()[1] + useHardwareBreakpoints = False + msg = ("Failed to set hardware breakpoint" + " at address %s for thread ID %d") + msg = msg % (HexDump.address(ra), dwThreadId) + warnings.warn(msg, BreakpointWarning) + + # If not possible, set a code breakpoint instead. + if not useHardwareBreakpoints: + try: + debug.break_at(dwProcessId, ra, + self.__postCallAction_codebp) + bHookedReturn = True + except Exception: + e = sys.exc_info()[1] + msg = ("Failed to set code breakpoint" + " at address %s for process ID %d") + msg = msg % (HexDump.address(ra), dwProcessId) + warnings.warn(msg, BreakpointWarning) + + # Call the "pre" callback. + try: + self.__callHandler(self.__preCB, event, ra, *params) + + # If no "post" callback is defined, forget the function arguments. + finally: + if not bHookedReturn: + self.__pop_params(dwThreadId) + + def __postCallAction_hwbp(self, event): + """ + Handles hardware breakpoint events on return from the function. + + @type event: L{ExceptionEvent} + @param event: Single step event. + """ + + # Remove the one shot hardware breakpoint + # at the return address location in the stack. + tid = event.get_tid() + address = event.breakpoint.get_address() + event.debug.erase_hardware_breakpoint(tid, address) + + # Call the "post" callback. + try: + self.__postCallAction(event) + + # Forget the parameters. + finally: + self.__pop_params(tid) + + def __postCallAction_codebp(self, event): + """ + Handles code breakpoint events on return from the function. + + @type event: L{ExceptionEvent} + @param event: Breakpoint hit event. + """ + + # If the breakpoint was accidentally hit by another thread, + # pass it to the debugger instead of calling the "post" callback. + # + # XXX FIXME: + # I suppose this check will fail under some weird conditions... + # + tid = event.get_tid() + if tid not in self.__paramStack: + return True + + # Remove the code breakpoint at the return address. + pid = event.get_pid() + address = event.breakpoint.get_address() + event.debug.dont_break_at(pid, address) + + # Call the "post" callback. + try: + self.__postCallAction(event) + + # Forget the parameters. + finally: + self.__pop_params(tid) + + def __postCallAction(self, event): + """ + Calls the "post" callback. + + @type event: L{ExceptionEvent} + @param event: Breakpoint hit event. + """ + aThread = event.get_thread() + retval = self._get_return_value(aThread) + self.__callHandler(self.__postCB, event, retval) + + def __callHandler(self, callback, event, *params): + """ + Calls a "pre" or "post" handler, if set. + + @type callback: function + @param callback: Callback function to call. + + @type event: L{ExceptionEvent} + @param event: Breakpoint hit event. + + @type params: tuple + @param params: Parameters for the callback function. + """ + if callback is not None: + event.hook = self + callback(event, *params) + + def __push_params(self, tid, params): + """ + Remembers the arguments tuple for the last call to the hooked function + from this thread. + + @type tid: int + @param tid: Thread global ID. + + @type params: tuple( arg, arg, arg... ) + @param params: Tuple of arguments. + """ + stack = self.__paramStack.get( tid, [] ) + stack.append(params) + self.__paramStack[tid] = stack + + def __pop_params(self, tid): + """ + Forgets the arguments tuple for the last call to the hooked function + from this thread. + + @type tid: int + @param tid: Thread global ID. + """ + stack = self.__paramStack[tid] + stack.pop() + if not stack: + del self.__paramStack[tid] + + def get_params(self, tid): + """ + Returns the parameters found in the stack when the hooked function + was last called by this thread. + + @type tid: int + @param tid: Thread global ID. + + @rtype: tuple( arg, arg, arg... ) + @return: Tuple of arguments. + """ + try: + params = self.get_params_stack(tid)[-1] + except IndexError: + msg = "Hooked function called from thread %d already returned" + raise IndexError(msg % tid) + return params + + def get_params_stack(self, tid): + """ + Returns the parameters found in the stack each time the hooked function + was called by this thread and hasn't returned yet. + + @type tid: int + @param tid: Thread global ID. + + @rtype: list of tuple( arg, arg, arg... ) + @return: List of argument tuples. + """ + try: + stack = self.__paramStack[tid] + except KeyError: + msg = "Hooked function was not called from thread %d" + raise KeyError(msg % tid) + return stack + + def hook(self, debug, pid, address): + """ + Installs the function hook at a given process and address. + + @see: L{unhook} + + @warning: Do not call from an function hook callback. + + @type debug: L{Debug} + @param debug: Debug object. + + @type pid: int + @param pid: Process ID. + + @type address: int + @param address: Function address. + """ + return debug.break_at(pid, address, self) + + def unhook(self, debug, pid, address): + """ + Removes the function hook at a given process and address. + + @see: L{hook} + + @warning: Do not call from an function hook callback. + + @type debug: L{Debug} + @param debug: Debug object. + + @type pid: int + @param pid: Process ID. + + @type address: int + @param address: Function address. + """ + return debug.dont_break_at(pid, address) + +class _Hook_i386 (Hook): + """ + Implementation details for L{Hook} on the L{win32.ARCH_I386} architecture. + """ + + # We don't want to inherit the parent class __new__ method. + __new__ = object.__new__ + + def _calc_signature(self, signature): + self._cast_signature_pointers_to_void(signature) + class Arguments (ctypes.Structure): + _fields_ = [ ("arg_%s" % i, signature[i]) \ + for i in compat.xrange(len(signature) - 1, -1, -1) ] + return Arguments + + def _get_return_address(self, aProcess, aThread): + return aProcess.read_pointer( aThread.get_sp() ) + + def _get_function_arguments(self, aProcess, aThread): + if self._signature: + params = aThread.read_stack_structure(self._signature, + offset = win32.sizeof(win32.LPVOID)) + elif self._paramCount: + params = aThread.read_stack_dwords(self._paramCount, + offset = win32.sizeof(win32.LPVOID)) + else: + params = () + return params + + def _get_return_value(self, aThread): + ctx = aThread.get_context(win32.CONTEXT_INTEGER) + return ctx['Eax'] + +class _Hook_amd64 (Hook): + """ + Implementation details for L{Hook} on the L{win32.ARCH_AMD64} architecture. + """ + + # We don't want to inherit the parent class __new__ method. + __new__ = object.__new__ + + # Make a list of floating point types. + __float_types = ( + ctypes.c_double, + ctypes.c_float, + ) + # Long doubles are not supported in old versions of ctypes! + try: + __float_types += (ctypes.c_longdouble,) + except AttributeError: + pass + + def _calc_signature(self, signature): + self._cast_signature_pointers_to_void(signature) + + float_types = self.__float_types + c_sizeof = ctypes.sizeof + reg_size = c_sizeof(ctypes.c_size_t) + + reg_int_sig = [] + reg_float_sig = [] + stack_sig = [] + + for i in compat.xrange(len(signature)): + arg = signature[i] + name = "arg_%d" % i + stack_sig.insert( 0, (name, arg) ) + if i < 4: + if type(arg) in float_types: + reg_float_sig.append( (name, arg) ) + elif c_sizeof(arg) <= reg_size: + reg_int_sig.append( (name, arg) ) + else: + msg = ("Hook signatures don't support structures" + " within the first 4 arguments of a function" + " for the %s architecture") % win32.arch + raise NotImplementedError(msg) + + if reg_int_sig: + class RegisterArguments (ctypes.Structure): + _fields_ = reg_int_sig + else: + RegisterArguments = None + if reg_float_sig: + class FloatArguments (ctypes.Structure): + _fields_ = reg_float_sig + else: + FloatArguments = None + if stack_sig: + class StackArguments (ctypes.Structure): + _fields_ = stack_sig + else: + StackArguments = None + + return (len(signature), + RegisterArguments, + FloatArguments, + StackArguments) + + def _get_return_address(self, aProcess, aThread): + return aProcess.read_pointer( aThread.get_sp() ) + + def _get_function_arguments(self, aProcess, aThread): + if self._signature: + (args_count, + RegisterArguments, + FloatArguments, + StackArguments) = self._signature + arguments = {} + if StackArguments: + address = aThread.get_sp() + win32.sizeof(win32.LPVOID) + stack_struct = aProcess.read_structure(address, + StackArguments) + stack_args = dict( + [ (name, stack_struct.__getattribute__(name)) + for (name, type) in stack_struct._fields_ ] + ) + arguments.update(stack_args) + flags = 0 + if RegisterArguments: + flags = flags | win32.CONTEXT_INTEGER + if FloatArguments: + flags = flags | win32.CONTEXT_MMX_REGISTERS + if flags: + ctx = aThread.get_context(flags) + if RegisterArguments: + buffer = (win32.QWORD * 4)(ctx['Rcx'], ctx['Rdx'], + ctx['R8'], ctx['R9']) + reg_args = self._get_arguments_from_buffer(buffer, + RegisterArguments) + arguments.update(reg_args) + if FloatArguments: + buffer = (win32.M128A * 4)(ctx['XMM0'], ctx['XMM1'], + ctx['XMM2'], ctx['XMM3']) + float_args = self._get_arguments_from_buffer(buffer, + FloatArguments) + arguments.update(float_args) + params = tuple( [ arguments["arg_%d" % i] + for i in compat.xrange(args_count) ] ) + else: + params = () + return params + + def _get_arguments_from_buffer(self, buffer, structure): + b_ptr = ctypes.pointer(buffer) + v_ptr = ctypes.cast(b_ptr, ctypes.c_void_p) + s_ptr = ctypes.cast(v_ptr, ctypes.POINTER(structure)) + struct = s_ptr.contents + return dict( + [ (name, struct.__getattribute__(name)) + for (name, type) in struct._fields_ ] + ) + + def _get_return_value(self, aThread): + ctx = aThread.get_context(win32.CONTEXT_INTEGER) + return ctx['Rax'] + +#------------------------------------------------------------------------------ + +# This class acts as a factory of Hook objects, one per target process. +# Said objects are deleted by the unhook() method. + +class ApiHook (object): + """ + Used by L{EventHandler}. + + This class acts as an action callback for code breakpoints set at the + beginning of a function. It automatically retrieves the parameters from + the stack, sets a breakpoint at the return address and retrieves the + return value from the function call. + + @see: L{EventHandler.apiHooks} + + @type modName: str + @ivar modName: Module name. + + @type procName: str + @ivar procName: Procedure name. + """ + + def __init__(self, eventHandler, modName, procName, paramCount = None, + signature = None): + """ + @type eventHandler: L{EventHandler} + @param eventHandler: Event handler instance. This is where the hook + callbacks are to be defined (see below). + + @type modName: str + @param modName: Module name. + + @type procName: str + @param procName: Procedure name. + The pre and post callbacks will be deduced from it. + + For example, if the procedure is "LoadLibraryEx" the callback + routines will be "pre_LoadLibraryEx" and "post_LoadLibraryEx". + + The signature for the callbacks should be something like this:: + + def pre_LoadLibraryEx(self, event, ra, lpFilename, hFile, dwFlags): + + # return address + ra = params[0] + + # function arguments start from here... + szFilename = event.get_process().peek_string(lpFilename) + + # (...) + + def post_LoadLibraryEx(self, event, return_value): + + # (...) + + Note that all pointer types are treated like void pointers, so your + callback won't get the string or structure pointed to by it, but + the remote memory address instead. This is so to prevent the ctypes + library from being "too helpful" and trying to dereference the + pointer. To get the actual data being pointed to, use one of the + L{Process.read} methods. + + @type paramCount: int + @param paramCount: + (Optional) Number of parameters for the C{preCB} callback, + not counting the return address. Parameters are read from + the stack and assumed to be DWORDs in 32 bits and QWORDs in 64. + + This is a faster way to pull stack parameters in 32 bits, but in 64 + bits (or with some odd APIs in 32 bits) it won't be useful, since + not all arguments to the hooked function will be of the same size. + + For a more reliable and cross-platform way of hooking use the + C{signature} argument instead. + + @type signature: tuple + @param signature: + (Optional) Tuple of C{ctypes} data types that constitute the + hooked function signature. When the function is called, this will + be used to parse the arguments from the stack. Overrides the + C{paramCount} argument. + """ + self.__modName = modName + self.__procName = procName + self.__paramCount = paramCount + self.__signature = signature + self.__preCB = getattr(eventHandler, 'pre_%s' % procName, None) + self.__postCB = getattr(eventHandler, 'post_%s' % procName, None) + self.__hook = dict() + + def __call__(self, event): + """ + Handles the breakpoint event on entry of the function. + + @type event: L{ExceptionEvent} + @param event: Breakpoint hit event. + + @raise WindowsError: An error occured. + """ + pid = event.get_pid() + try: + hook = self.__hook[pid] + except KeyError: + hook = Hook(self.__preCB, self.__postCB, + self.__paramCount, self.__signature, + event.get_process().get_arch() ) + self.__hook[pid] = hook + return hook(event) + + @property + def modName(self): + return self.__modName + + @property + def procName(self): + return self.__procName + + def hook(self, debug, pid): + """ + Installs the API hook on a given process and module. + + @warning: Do not call from an API hook callback. + + @type debug: L{Debug} + @param debug: Debug object. + + @type pid: int + @param pid: Process ID. + """ + label = "%s!%s" % (self.__modName, self.__procName) + try: + hook = self.__hook[pid] + except KeyError: + try: + aProcess = debug.system.get_process(pid) + except KeyError: + aProcess = Process(pid) + hook = Hook(self.__preCB, self.__postCB, + self.__paramCount, self.__signature, + aProcess.get_arch() ) + self.__hook[pid] = hook + hook.hook(debug, pid, label) + + def unhook(self, debug, pid): + """ + Removes the API hook from the given process and module. + + @warning: Do not call from an API hook callback. + + @type debug: L{Debug} + @param debug: Debug object. + + @type pid: int + @param pid: Process ID. + """ + try: + hook = self.__hook[pid] + except KeyError: + return + label = "%s!%s" % (self.__modName, self.__procName) + hook.unhook(debug, pid, label) + del self.__hook[pid] + +#============================================================================== + +class BufferWatch (object): + """ + Returned by L{Debug.watch_buffer}. + + This object uniquely references a buffer being watched, even if there are + multiple watches set on the exact memory region. + + @type pid: int + @ivar pid: Process ID. + + @type start: int + @ivar start: Memory address of the start of the buffer. + + @type end: int + @ivar end: Memory address of the end of the buffer. + + @type action: callable + @ivar action: Action callback. + + @type oneshot: bool + @ivar oneshot: C{True} for one shot breakpoints, C{False} otherwise. + """ + + def __init__(self, pid, start, end, action = None, oneshot = False): + self.__pid = pid + self.__start = start + self.__end = end + self.__action = action + self.__oneshot = oneshot + + @property + def pid(self): + return self.__pid + + @property + def start(self): + return self.__start + + @property + def end(self): + return self.__end + + @property + def action(self): + return self.__action + + @property + def oneshot(self): + return self.__oneshot + + def match(self, address): + """ + Determine if the given memory address lies within the watched buffer. + + @rtype: bool + @return: C{True} if the given memory address lies within the watched + buffer, C{False} otherwise. + """ + return self.__start <= address < self.__end + +#============================================================================== + +class _BufferWatchCondition (object): + """ + Used by L{Debug.watch_buffer}. + + This class acts as a condition callback for page breakpoints. + It emulates page breakpoints that can overlap and/or take up less + than a page's size. + """ + + def __init__(self): + self.__ranges = list() # list of BufferWatch in definition order + + def add(self, bw): + """ + Adds a buffer watch identifier. + + @type bw: L{BufferWatch} + @param bw: + Buffer watch identifier. + """ + self.__ranges.append(bw) + + def remove(self, bw): + """ + Removes a buffer watch identifier. + + @type bw: L{BufferWatch} + @param bw: + Buffer watch identifier. + + @raise KeyError: The buffer watch identifier was already removed. + """ + try: + self.__ranges.remove(bw) + except KeyError: + if not bw.oneshot: + raise + + def remove_last_match(self, address, size): + """ + Removes the last buffer from the watch object + to match the given address and size. + + @type address: int + @param address: Memory address of buffer to stop watching. + + @type size: int + @param size: Size in bytes of buffer to stop watching. + + @rtype: int + @return: Number of matching elements found. Only the last one to be + added is actually deleted upon calling this method. + + This counter allows you to know if there are more matching elements + and how many. + """ + count = 0 + start = address + end = address + size - 1 + matched = None + for item in self.__ranges: + if item.match(start) and item.match(end): + matched = item + count += 1 + self.__ranges.remove(matched) + return count + + def count(self): + """ + @rtype: int + @return: Number of buffers being watched. + """ + return len(self.__ranges) + + def __call__(self, event): + """ + Breakpoint condition callback. + + This method will also call the action callbacks for each + buffer being watched. + + @type event: L{ExceptionEvent} + @param event: Guard page exception event. + + @rtype: bool + @return: C{True} if the address being accessed belongs + to at least one of the buffers that was being watched + and had no action callback. + """ + address = event.get_exception_information(1) + bCondition = False + for bw in self.__ranges: + bMatched = bw.match(address) + try: + action = bw.action + if bMatched and action is not None: + try: + action(event) + except Exception: + e = sys.exc_info()[1] + msg = ("Breakpoint action callback %r" + " raised an exception: %s") + msg = msg % (action, traceback.format_exc(e)) + warnings.warn(msg, BreakpointCallbackWarning) + else: + bCondition = bCondition or bMatched + finally: + if bMatched and bw.oneshot: + event.debug.dont_watch_buffer(bw) + return bCondition + +#============================================================================== + +class _BreakpointContainer (object): + """ + Encapsulates the capability to contain Breakpoint objects. + + @group Breakpoints: + break_at, watch_variable, watch_buffer, hook_function, + dont_break_at, dont_watch_variable, dont_watch_buffer, + dont_hook_function, unhook_function, + break_on_error, dont_break_on_error + + @group Stalking: + stalk_at, stalk_variable, stalk_buffer, stalk_function, + dont_stalk_at, dont_stalk_variable, dont_stalk_buffer, + dont_stalk_function + + @group Tracing: + is_tracing, get_traced_tids, + start_tracing, stop_tracing, + start_tracing_process, stop_tracing_process, + start_tracing_all, stop_tracing_all + + @group Symbols: + resolve_label, resolve_exported_function + + @group Advanced breakpoint use: + define_code_breakpoint, + define_page_breakpoint, + define_hardware_breakpoint, + has_code_breakpoint, + has_page_breakpoint, + has_hardware_breakpoint, + get_code_breakpoint, + get_page_breakpoint, + get_hardware_breakpoint, + erase_code_breakpoint, + erase_page_breakpoint, + erase_hardware_breakpoint, + enable_code_breakpoint, + enable_page_breakpoint, + enable_hardware_breakpoint, + enable_one_shot_code_breakpoint, + enable_one_shot_page_breakpoint, + enable_one_shot_hardware_breakpoint, + disable_code_breakpoint, + disable_page_breakpoint, + disable_hardware_breakpoint + + @group Listing breakpoints: + get_all_breakpoints, + get_all_code_breakpoints, + get_all_page_breakpoints, + get_all_hardware_breakpoints, + get_process_breakpoints, + get_process_code_breakpoints, + get_process_page_breakpoints, + get_process_hardware_breakpoints, + get_thread_hardware_breakpoints, + get_all_deferred_code_breakpoints, + get_process_deferred_code_breakpoints + + @group Batch operations on breakpoints: + enable_all_breakpoints, + enable_one_shot_all_breakpoints, + disable_all_breakpoints, + erase_all_breakpoints, + enable_process_breakpoints, + enable_one_shot_process_breakpoints, + disable_process_breakpoints, + erase_process_breakpoints + + @group Breakpoint types: + BP_TYPE_ANY, BP_TYPE_CODE, BP_TYPE_PAGE, BP_TYPE_HARDWARE + @group Breakpoint states: + BP_STATE_DISABLED, BP_STATE_ENABLED, BP_STATE_ONESHOT, BP_STATE_RUNNING + @group Memory breakpoint trigger flags: + BP_BREAK_ON_EXECUTION, BP_BREAK_ON_WRITE, BP_BREAK_ON_ACCESS + @group Memory breakpoint size flags: + BP_WATCH_BYTE, BP_WATCH_WORD, BP_WATCH_DWORD, BP_WATCH_QWORD + + @type BP_TYPE_ANY: int + @cvar BP_TYPE_ANY: To get all breakpoints + @type BP_TYPE_CODE: int + @cvar BP_TYPE_CODE: To get code breakpoints only + @type BP_TYPE_PAGE: int + @cvar BP_TYPE_PAGE: To get page breakpoints only + @type BP_TYPE_HARDWARE: int + @cvar BP_TYPE_HARDWARE: To get hardware breakpoints only + + @type BP_STATE_DISABLED: int + @cvar BP_STATE_DISABLED: Breakpoint is disabled. + @type BP_STATE_ENABLED: int + @cvar BP_STATE_ENABLED: Breakpoint is enabled. + @type BP_STATE_ONESHOT: int + @cvar BP_STATE_ONESHOT: Breakpoint is enabled for one shot. + @type BP_STATE_RUNNING: int + @cvar BP_STATE_RUNNING: Breakpoint is running (recently hit). + + @type BP_BREAK_ON_EXECUTION: int + @cvar BP_BREAK_ON_EXECUTION: Break on code execution. + @type BP_BREAK_ON_WRITE: int + @cvar BP_BREAK_ON_WRITE: Break on memory write. + @type BP_BREAK_ON_ACCESS: int + @cvar BP_BREAK_ON_ACCESS: Break on memory read or write. + """ + + # Breakpoint types + BP_TYPE_ANY = 0 # to get all breakpoints + BP_TYPE_CODE = 1 + BP_TYPE_PAGE = 2 + BP_TYPE_HARDWARE = 3 + + # Breakpoint states + BP_STATE_DISABLED = Breakpoint.DISABLED + BP_STATE_ENABLED = Breakpoint.ENABLED + BP_STATE_ONESHOT = Breakpoint.ONESHOT + BP_STATE_RUNNING = Breakpoint.RUNNING + + # Memory breakpoint trigger flags + BP_BREAK_ON_EXECUTION = HardwareBreakpoint.BREAK_ON_EXECUTION + BP_BREAK_ON_WRITE = HardwareBreakpoint.BREAK_ON_WRITE + BP_BREAK_ON_ACCESS = HardwareBreakpoint.BREAK_ON_ACCESS + + # Memory breakpoint size flags + BP_WATCH_BYTE = HardwareBreakpoint.WATCH_BYTE + BP_WATCH_WORD = HardwareBreakpoint.WATCH_WORD + BP_WATCH_QWORD = HardwareBreakpoint.WATCH_QWORD + BP_WATCH_DWORD = HardwareBreakpoint.WATCH_DWORD + + def __init__(self): + self.__codeBP = dict() # (pid, address) -> CodeBreakpoint + self.__pageBP = dict() # (pid, address) -> PageBreakpoint + self.__hardwareBP = dict() # tid -> [ HardwareBreakpoint ] + self.__runningBP = dict() # tid -> set( Breakpoint ) + self.__tracing = set() # set( tid ) + self.__deferredBP = dict() # pid -> label -> (action, oneshot) + +#------------------------------------------------------------------------------ + + # This operates on the dictionary of running breakpoints. + # Since the bps are meant to stay alive no cleanup is done here. + + def __get_running_bp_set(self, tid): + "Auxiliary method." + return self.__runningBP.get(tid, ()) + + def __add_running_bp(self, tid, bp): + "Auxiliary method." + if tid not in self.__runningBP: + self.__runningBP[tid] = set() + self.__runningBP[tid].add(bp) + + def __del_running_bp(self, tid, bp): + "Auxiliary method." + self.__runningBP[tid].remove(bp) + if not self.__runningBP[tid]: + del self.__runningBP[tid] + + def __del_running_bp_from_all_threads(self, bp): + "Auxiliary method." + for (tid, bpset) in compat.iteritems(self.__runningBP): + if bp in bpset: + bpset.remove(bp) + self.system.get_thread(tid).clear_tf() + +#------------------------------------------------------------------------------ + + # This is the cleanup code. Mostly called on response to exit/unload debug + # events. If possible it shouldn't raise exceptions on runtime errors. + # The main goal here is to avoid memory or handle leaks. + + def __cleanup_breakpoint(self, event, bp): + "Auxiliary method." + try: + process = event.get_process() + thread = event.get_thread() + bp.disable(process, thread) # clear the debug regs / trap flag + except Exception: + pass + bp.set_condition(True) # break possible circular reference + bp.set_action(None) # break possible circular reference + + def __cleanup_thread(self, event): + """ + Auxiliary method for L{_notify_exit_thread} + and L{_notify_exit_process}. + """ + tid = event.get_tid() + + # Cleanup running breakpoints + try: + for bp in self.__runningBP[tid]: + self.__cleanup_breakpoint(event, bp) + del self.__runningBP[tid] + except KeyError: + pass + + # Cleanup hardware breakpoints + try: + for bp in self.__hardwareBP[tid]: + self.__cleanup_breakpoint(event, bp) + del self.__hardwareBP[tid] + except KeyError: + pass + + # Cleanup set of threads being traced + if tid in self.__tracing: + self.__tracing.remove(tid) + + def __cleanup_process(self, event): + """ + Auxiliary method for L{_notify_exit_process}. + """ + pid = event.get_pid() + process = event.get_process() + + # Cleanup code breakpoints + for (bp_pid, bp_address) in compat.keys(self.__codeBP): + if bp_pid == pid: + bp = self.__codeBP[ (bp_pid, bp_address) ] + self.__cleanup_breakpoint(event, bp) + del self.__codeBP[ (bp_pid, bp_address) ] + + # Cleanup page breakpoints + for (bp_pid, bp_address) in compat.keys(self.__pageBP): + if bp_pid == pid: + bp = self.__pageBP[ (bp_pid, bp_address) ] + self.__cleanup_breakpoint(event, bp) + del self.__pageBP[ (bp_pid, bp_address) ] + + # Cleanup deferred code breakpoints + try: + del self.__deferredBP[pid] + except KeyError: + pass + + def __cleanup_module(self, event): + """ + Auxiliary method for L{_notify_unload_dll}. + """ + pid = event.get_pid() + process = event.get_process() + module = event.get_module() + + # Cleanup thread breakpoints on this module + for tid in process.iter_thread_ids(): + thread = process.get_thread(tid) + + # Running breakpoints + if tid in self.__runningBP: + bplist = list(self.__runningBP[tid]) + for bp in bplist: + bp_address = bp.get_address() + if process.get_module_at_address(bp_address) == module: + self.__cleanup_breakpoint(event, bp) + self.__runningBP[tid].remove(bp) + + # Hardware breakpoints + if tid in self.__hardwareBP: + bplist = list(self.__hardwareBP[tid]) + for bp in bplist: + bp_address = bp.get_address() + if process.get_module_at_address(bp_address) == module: + self.__cleanup_breakpoint(event, bp) + self.__hardwareBP[tid].remove(bp) + + # Cleanup code breakpoints on this module + for (bp_pid, bp_address) in compat.keys(self.__codeBP): + if bp_pid == pid: + if process.get_module_at_address(bp_address) == module: + bp = self.__codeBP[ (bp_pid, bp_address) ] + self.__cleanup_breakpoint(event, bp) + del self.__codeBP[ (bp_pid, bp_address) ] + + # Cleanup page breakpoints on this module + for (bp_pid, bp_address) in compat.keys(self.__pageBP): + if bp_pid == pid: + if process.get_module_at_address(bp_address) == module: + bp = self.__pageBP[ (bp_pid, bp_address) ] + self.__cleanup_breakpoint(event, bp) + del self.__pageBP[ (bp_pid, bp_address) ] + +#------------------------------------------------------------------------------ + + # Defining breakpoints. + + # Code breakpoints. + def define_code_breakpoint(self, dwProcessId, address, condition = True, + action = None): + """ + Creates a disabled code breakpoint at the given address. + + @see: + L{has_code_breakpoint}, + L{get_code_breakpoint}, + L{enable_code_breakpoint}, + L{enable_one_shot_code_breakpoint}, + L{disable_code_breakpoint}, + L{erase_code_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of the code instruction to break at. + + @type condition: function + @param condition: (Optional) Condition callback function. + + The callback signature is:: + + def condition_callback(event): + return True # returns True or False + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @type action: function + @param action: (Optional) Action callback function. + If specified, the event is handled by this callback instead of + being dispatched normally. + + The callback signature is:: + + def action_callback(event): + pass # no return value + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @rtype: L{CodeBreakpoint} + @return: The code breakpoint object. + """ + process = self.system.get_process(dwProcessId) + bp = CodeBreakpoint(address, condition, action) + + key = (dwProcessId, bp.get_address()) + if key in self.__codeBP: + msg = "Already exists (PID %d) : %r" + raise KeyError(msg % (dwProcessId, self.__codeBP[key])) + self.__codeBP[key] = bp + return bp + + # Page breakpoints. + def define_page_breakpoint(self, dwProcessId, address, pages = 1, + condition = True, + action = None): + """ + Creates a disabled page breakpoint at the given address. + + @see: + L{has_page_breakpoint}, + L{get_page_breakpoint}, + L{enable_page_breakpoint}, + L{enable_one_shot_page_breakpoint}, + L{disable_page_breakpoint}, + L{erase_page_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of the first page to watch. + + @type pages: int + @param pages: Number of pages to watch. + + @type condition: function + @param condition: (Optional) Condition callback function. + + The callback signature is:: + + def condition_callback(event): + return True # returns True or False + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @type action: function + @param action: (Optional) Action callback function. + If specified, the event is handled by this callback instead of + being dispatched normally. + + The callback signature is:: + + def action_callback(event): + pass # no return value + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @rtype: L{PageBreakpoint} + @return: The page breakpoint object. + """ + process = self.system.get_process(dwProcessId) + bp = PageBreakpoint(address, pages, condition, action) + begin = bp.get_address() + end = begin + bp.get_size() + + address = begin + pageSize = MemoryAddresses.pageSize + while address < end: + key = (dwProcessId, address) + if key in self.__pageBP: + msg = "Already exists (PID %d) : %r" + msg = msg % (dwProcessId, self.__pageBP[key]) + raise KeyError(msg) + address = address + pageSize + + address = begin + while address < end: + key = (dwProcessId, address) + self.__pageBP[key] = bp + address = address + pageSize + return bp + + # Hardware breakpoints. + def define_hardware_breakpoint(self, dwThreadId, address, + triggerFlag = BP_BREAK_ON_ACCESS, + sizeFlag = BP_WATCH_DWORD, + condition = True, + action = None): + """ + Creates a disabled hardware breakpoint at the given address. + + @see: + L{has_hardware_breakpoint}, + L{get_hardware_breakpoint}, + L{enable_hardware_breakpoint}, + L{enable_one_shot_hardware_breakpoint}, + L{disable_hardware_breakpoint}, + L{erase_hardware_breakpoint} + + @note: + Hardware breakpoints do not seem to work properly on VirtualBox. + See U{http://www.virtualbox.org/ticket/477}. + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address to watch. + + @type triggerFlag: int + @param triggerFlag: Trigger of breakpoint. Must be one of the following: + + - L{BP_BREAK_ON_EXECUTION} + + Break on code execution. + + - L{BP_BREAK_ON_WRITE} + + Break on memory read or write. + + - L{BP_BREAK_ON_ACCESS} + + Break on memory write. + + @type sizeFlag: int + @param sizeFlag: Size of breakpoint. Must be one of the following: + + - L{BP_WATCH_BYTE} + + One (1) byte in size. + + - L{BP_WATCH_WORD} + + Two (2) bytes in size. + + - L{BP_WATCH_DWORD} + + Four (4) bytes in size. + + - L{BP_WATCH_QWORD} + + Eight (8) bytes in size. + + @type condition: function + @param condition: (Optional) Condition callback function. + + The callback signature is:: + + def condition_callback(event): + return True # returns True or False + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @type action: function + @param action: (Optional) Action callback function. + If specified, the event is handled by this callback instead of + being dispatched normally. + + The callback signature is:: + + def action_callback(event): + pass # no return value + + Where B{event} is an L{Event} object, + and the return value is a boolean + (C{True} to dispatch the event, C{False} otherwise). + + @rtype: L{HardwareBreakpoint} + @return: The hardware breakpoint object. + """ + thread = self.system.get_thread(dwThreadId) + bp = HardwareBreakpoint(address, triggerFlag, sizeFlag, condition, + action) + begin = bp.get_address() + end = begin + bp.get_size() + + if dwThreadId in self.__hardwareBP: + bpSet = self.__hardwareBP[dwThreadId] + for oldbp in bpSet: + old_begin = oldbp.get_address() + old_end = old_begin + oldbp.get_size() + if MemoryAddresses.do_ranges_intersect(begin, end, old_begin, + old_end): + msg = "Already exists (TID %d) : %r" % (dwThreadId, oldbp) + raise KeyError(msg) + else: + bpSet = set() + self.__hardwareBP[dwThreadId] = bpSet + bpSet.add(bp) + return bp + +#------------------------------------------------------------------------------ + + # Checking breakpoint definitions. + + def has_code_breakpoint(self, dwProcessId, address): + """ + Checks if a code breakpoint is defined at the given address. + + @see: + L{define_code_breakpoint}, + L{get_code_breakpoint}, + L{erase_code_breakpoint}, + L{enable_code_breakpoint}, + L{enable_one_shot_code_breakpoint}, + L{disable_code_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + + @rtype: bool + @return: C{True} if the breakpoint is defined, C{False} otherwise. + """ + return (dwProcessId, address) in self.__codeBP + + def has_page_breakpoint(self, dwProcessId, address): + """ + Checks if a page breakpoint is defined at the given address. + + @see: + L{define_page_breakpoint}, + L{get_page_breakpoint}, + L{erase_page_breakpoint}, + L{enable_page_breakpoint}, + L{enable_one_shot_page_breakpoint}, + L{disable_page_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + + @rtype: bool + @return: C{True} if the breakpoint is defined, C{False} otherwise. + """ + return (dwProcessId, address) in self.__pageBP + + def has_hardware_breakpoint(self, dwThreadId, address): + """ + Checks if a hardware breakpoint is defined at the given address. + + @see: + L{define_hardware_breakpoint}, + L{get_hardware_breakpoint}, + L{erase_hardware_breakpoint}, + L{enable_hardware_breakpoint}, + L{enable_one_shot_hardware_breakpoint}, + L{disable_hardware_breakpoint} + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address of breakpoint. + + @rtype: bool + @return: C{True} if the breakpoint is defined, C{False} otherwise. + """ + if dwThreadId in self.__hardwareBP: + bpSet = self.__hardwareBP[dwThreadId] + for bp in bpSet: + if bp.get_address() == address: + return True + return False + +#------------------------------------------------------------------------------ + + # Getting breakpoints. + + def get_code_breakpoint(self, dwProcessId, address): + """ + Returns the internally used breakpoint object, + for the code breakpoint defined at the given address. + + @warning: It's usually best to call the L{Debug} methods + instead of accessing the breakpoint objects directly. + + @see: + L{define_code_breakpoint}, + L{has_code_breakpoint}, + L{enable_code_breakpoint}, + L{enable_one_shot_code_breakpoint}, + L{disable_code_breakpoint}, + L{erase_code_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address where the breakpoint is defined. + + @rtype: L{CodeBreakpoint} + @return: The code breakpoint object. + """ + key = (dwProcessId, address) + if key not in self.__codeBP: + msg = "No breakpoint at process %d, address %s" + address = HexDump.address(address) + raise KeyError(msg % (dwProcessId, address)) + return self.__codeBP[key] + + def get_page_breakpoint(self, dwProcessId, address): + """ + Returns the internally used breakpoint object, + for the page breakpoint defined at the given address. + + @warning: It's usually best to call the L{Debug} methods + instead of accessing the breakpoint objects directly. + + @see: + L{define_page_breakpoint}, + L{has_page_breakpoint}, + L{enable_page_breakpoint}, + L{enable_one_shot_page_breakpoint}, + L{disable_page_breakpoint}, + L{erase_page_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address where the breakpoint is defined. + + @rtype: L{PageBreakpoint} + @return: The page breakpoint object. + """ + key = (dwProcessId, address) + if key not in self.__pageBP: + msg = "No breakpoint at process %d, address %s" + address = HexDump.addresS(address) + raise KeyError(msg % (dwProcessId, address)) + return self.__pageBP[key] + + def get_hardware_breakpoint(self, dwThreadId, address): + """ + Returns the internally used breakpoint object, + for the code breakpoint defined at the given address. + + @warning: It's usually best to call the L{Debug} methods + instead of accessing the breakpoint objects directly. + + @see: + L{define_hardware_breakpoint}, + L{has_hardware_breakpoint}, + L{get_code_breakpoint}, + L{enable_hardware_breakpoint}, + L{enable_one_shot_hardware_breakpoint}, + L{disable_hardware_breakpoint}, + L{erase_hardware_breakpoint} + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address where the breakpoint is defined. + + @rtype: L{HardwareBreakpoint} + @return: The hardware breakpoint object. + """ + if dwThreadId not in self.__hardwareBP: + msg = "No hardware breakpoints set for thread %d" + raise KeyError(msg % dwThreadId) + for bp in self.__hardwareBP[dwThreadId]: + if bp.is_here(address): + return bp + msg = "No hardware breakpoint at thread %d, address %s" + raise KeyError(msg % (dwThreadId, HexDump.address(address))) + +#------------------------------------------------------------------------------ + + # Enabling and disabling breakpoints. + + def enable_code_breakpoint(self, dwProcessId, address): + """ + Enables the code breakpoint at the given address. + + @see: + L{define_code_breakpoint}, + L{has_code_breakpoint}, + L{enable_one_shot_code_breakpoint}, + L{disable_code_breakpoint} + L{erase_code_breakpoint}, + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + p = self.system.get_process(dwProcessId) + bp = self.get_code_breakpoint(dwProcessId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.enable(p, None) # XXX HACK thread is not used + + def enable_page_breakpoint(self, dwProcessId, address): + """ + Enables the page breakpoint at the given address. + + @see: + L{define_page_breakpoint}, + L{has_page_breakpoint}, + L{get_page_breakpoint}, + L{enable_one_shot_page_breakpoint}, + L{disable_page_breakpoint} + L{erase_page_breakpoint}, + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + p = self.system.get_process(dwProcessId) + bp = self.get_page_breakpoint(dwProcessId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.enable(p, None) # XXX HACK thread is not used + + def enable_hardware_breakpoint(self, dwThreadId, address): + """ + Enables the hardware breakpoint at the given address. + + @see: + L{define_hardware_breakpoint}, + L{has_hardware_breakpoint}, + L{get_hardware_breakpoint}, + L{enable_one_shot_hardware_breakpoint}, + L{disable_hardware_breakpoint} + L{erase_hardware_breakpoint}, + + @note: Do not set hardware breakpoints while processing the system + breakpoint event. + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + t = self.system.get_thread(dwThreadId) + bp = self.get_hardware_breakpoint(dwThreadId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.enable(None, t) # XXX HACK process is not used + + def enable_one_shot_code_breakpoint(self, dwProcessId, address): + """ + Enables the code breakpoint at the given address for only one shot. + + @see: + L{define_code_breakpoint}, + L{has_code_breakpoint}, + L{get_code_breakpoint}, + L{enable_code_breakpoint}, + L{disable_code_breakpoint} + L{erase_code_breakpoint}, + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + p = self.system.get_process(dwProcessId) + bp = self.get_code_breakpoint(dwProcessId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.one_shot(p, None) # XXX HACK thread is not used + + def enable_one_shot_page_breakpoint(self, dwProcessId, address): + """ + Enables the page breakpoint at the given address for only one shot. + + @see: + L{define_page_breakpoint}, + L{has_page_breakpoint}, + L{get_page_breakpoint}, + L{enable_page_breakpoint}, + L{disable_page_breakpoint} + L{erase_page_breakpoint}, + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + p = self.system.get_process(dwProcessId) + bp = self.get_page_breakpoint(dwProcessId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.one_shot(p, None) # XXX HACK thread is not used + + def enable_one_shot_hardware_breakpoint(self, dwThreadId, address): + """ + Enables the hardware breakpoint at the given address for only one shot. + + @see: + L{define_hardware_breakpoint}, + L{has_hardware_breakpoint}, + L{get_hardware_breakpoint}, + L{enable_hardware_breakpoint}, + L{disable_hardware_breakpoint} + L{erase_hardware_breakpoint}, + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + t = self.system.get_thread(dwThreadId) + bp = self.get_hardware_breakpoint(dwThreadId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.one_shot(None, t) # XXX HACK process is not used + + def disable_code_breakpoint(self, dwProcessId, address): + """ + Disables the code breakpoint at the given address. + + @see: + L{define_code_breakpoint}, + L{has_code_breakpoint}, + L{get_code_breakpoint}, + L{enable_code_breakpoint} + L{enable_one_shot_code_breakpoint}, + L{erase_code_breakpoint}, + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + p = self.system.get_process(dwProcessId) + bp = self.get_code_breakpoint(dwProcessId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.disable(p, None) # XXX HACK thread is not used + + def disable_page_breakpoint(self, dwProcessId, address): + """ + Disables the page breakpoint at the given address. + + @see: + L{define_page_breakpoint}, + L{has_page_breakpoint}, + L{get_page_breakpoint}, + L{enable_page_breakpoint} + L{enable_one_shot_page_breakpoint}, + L{erase_page_breakpoint}, + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + p = self.system.get_process(dwProcessId) + bp = self.get_page_breakpoint(dwProcessId, address) + if bp.is_running(): + self.__del_running_bp_from_all_threads(bp) + bp.disable(p, None) # XXX HACK thread is not used + + def disable_hardware_breakpoint(self, dwThreadId, address): + """ + Disables the hardware breakpoint at the given address. + + @see: + L{define_hardware_breakpoint}, + L{has_hardware_breakpoint}, + L{get_hardware_breakpoint}, + L{enable_hardware_breakpoint} + L{enable_one_shot_hardware_breakpoint}, + L{erase_hardware_breakpoint}, + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + t = self.system.get_thread(dwThreadId) + p = t.get_process() + bp = self.get_hardware_breakpoint(dwThreadId, address) + if bp.is_running(): + self.__del_running_bp(dwThreadId, bp) + bp.disable(p, t) + +#------------------------------------------------------------------------------ + + # Undefining (erasing) breakpoints. + + def erase_code_breakpoint(self, dwProcessId, address): + """ + Erases the code breakpoint at the given address. + + @see: + L{define_code_breakpoint}, + L{has_code_breakpoint}, + L{get_code_breakpoint}, + L{enable_code_breakpoint}, + L{enable_one_shot_code_breakpoint}, + L{disable_code_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + bp = self.get_code_breakpoint(dwProcessId, address) + if not bp.is_disabled(): + self.disable_code_breakpoint(dwProcessId, address) + del self.__codeBP[ (dwProcessId, address) ] + + def erase_page_breakpoint(self, dwProcessId, address): + """ + Erases the page breakpoint at the given address. + + @see: + L{define_page_breakpoint}, + L{has_page_breakpoint}, + L{get_page_breakpoint}, + L{enable_page_breakpoint}, + L{enable_one_shot_page_breakpoint}, + L{disable_page_breakpoint} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + bp = self.get_page_breakpoint(dwProcessId, address) + begin = bp.get_address() + end = begin + bp.get_size() + if not bp.is_disabled(): + self.disable_page_breakpoint(dwProcessId, address) + address = begin + pageSize = MemoryAddresses.pageSize + while address < end: + del self.__pageBP[ (dwProcessId, address) ] + address = address + pageSize + + def erase_hardware_breakpoint(self, dwThreadId, address): + """ + Erases the hardware breakpoint at the given address. + + @see: + L{define_hardware_breakpoint}, + L{has_hardware_breakpoint}, + L{get_hardware_breakpoint}, + L{enable_hardware_breakpoint}, + L{enable_one_shot_hardware_breakpoint}, + L{disable_hardware_breakpoint} + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @type address: int + @param address: Memory address of breakpoint. + """ + bp = self.get_hardware_breakpoint(dwThreadId, address) + if not bp.is_disabled(): + self.disable_hardware_breakpoint(dwThreadId, address) + bpSet = self.__hardwareBP[dwThreadId] + bpSet.remove(bp) + if not bpSet: + del self.__hardwareBP[dwThreadId] + +#------------------------------------------------------------------------------ + + # Listing breakpoints. + + def get_all_breakpoints(self): + """ + Returns all breakpoint objects as a list of tuples. + + Each tuple contains: + - Process global ID to which the breakpoint applies. + - Thread global ID to which the breakpoint applies, or C{None}. + - The L{Breakpoint} object itself. + + @note: If you're only interested in a specific breakpoint type, or in + breakpoints for a specific process or thread, it's probably faster + to call one of the following methods: + - L{get_all_code_breakpoints} + - L{get_all_page_breakpoints} + - L{get_all_hardware_breakpoints} + - L{get_process_code_breakpoints} + - L{get_process_page_breakpoints} + - L{get_process_hardware_breakpoints} + - L{get_thread_hardware_breakpoints} + + @rtype: list of tuple( pid, tid, bp ) + @return: List of all breakpoints. + """ + bplist = list() + + # Get the code breakpoints. + for (pid, bp) in self.get_all_code_breakpoints(): + bplist.append( (pid, None, bp) ) + + # Get the page breakpoints. + for (pid, bp) in self.get_all_page_breakpoints(): + bplist.append( (pid, None, bp) ) + + # Get the hardware breakpoints. + for (tid, bp) in self.get_all_hardware_breakpoints(): + pid = self.system.get_thread(tid).get_pid() + bplist.append( (pid, tid, bp) ) + + # Return the list of breakpoints. + return bplist + + def get_all_code_breakpoints(self): + """ + @rtype: list of tuple( int, L{CodeBreakpoint} ) + @return: All code breakpoints as a list of tuples (pid, bp). + """ + return [ (pid, bp) for ((pid, address), bp) in compat.iteritems(self.__codeBP) ] + + def get_all_page_breakpoints(self): + """ + @rtype: list of tuple( int, L{PageBreakpoint} ) + @return: All page breakpoints as a list of tuples (pid, bp). + """ +## return list( set( [ (pid, bp) for ((pid, address), bp) in compat.iteritems(self.__pageBP) ] ) ) + result = set() + for ((pid, address), bp) in compat.iteritems(self.__pageBP): + result.add( (pid, bp) ) + return list(result) + + def get_all_hardware_breakpoints(self): + """ + @rtype: list of tuple( int, L{HardwareBreakpoint} ) + @return: All hardware breakpoints as a list of tuples (tid, bp). + """ + result = list() + for (tid, bplist) in compat.iteritems(self.__hardwareBP): + for bp in bplist: + result.append( (tid, bp) ) + return result + + def get_process_breakpoints(self, dwProcessId): + """ + Returns all breakpoint objects for the given process as a list of tuples. + + Each tuple contains: + - Process global ID to which the breakpoint applies. + - Thread global ID to which the breakpoint applies, or C{None}. + - The L{Breakpoint} object itself. + + @note: If you're only interested in a specific breakpoint type, or in + breakpoints for a specific process or thread, it's probably faster + to call one of the following methods: + - L{get_all_code_breakpoints} + - L{get_all_page_breakpoints} + - L{get_all_hardware_breakpoints} + - L{get_process_code_breakpoints} + - L{get_process_page_breakpoints} + - L{get_process_hardware_breakpoints} + - L{get_thread_hardware_breakpoints} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: list of tuple( pid, tid, bp ) + @return: List of all breakpoints for the given process. + """ + bplist = list() + + # Get the code breakpoints. + for bp in self.get_process_code_breakpoints(dwProcessId): + bplist.append( (dwProcessId, None, bp) ) + + # Get the page breakpoints. + for bp in self.get_process_page_breakpoints(dwProcessId): + bplist.append( (dwProcessId, None, bp) ) + + # Get the hardware breakpoints. + for (tid, bp) in self.get_process_hardware_breakpoints(dwProcessId): + pid = self.system.get_thread(tid).get_pid() + bplist.append( (dwProcessId, tid, bp) ) + + # Return the list of breakpoints. + return bplist + + def get_process_code_breakpoints(self, dwProcessId): + """ + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: list of L{CodeBreakpoint} + @return: All code breakpoints for the given process. + """ + return [ bp for ((pid, address), bp) in compat.iteritems(self.__codeBP) \ + if pid == dwProcessId ] + + def get_process_page_breakpoints(self, dwProcessId): + """ + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: list of L{PageBreakpoint} + @return: All page breakpoints for the given process. + """ + return [ bp for ((pid, address), bp) in compat.iteritems(self.__pageBP) \ + if pid == dwProcessId ] + + def get_thread_hardware_breakpoints(self, dwThreadId): + """ + @see: L{get_process_hardware_breakpoints} + + @type dwThreadId: int + @param dwThreadId: Thread global ID. + + @rtype: list of L{HardwareBreakpoint} + @return: All hardware breakpoints for the given thread. + """ + result = list() + for (tid, bplist) in compat.iteritems(self.__hardwareBP): + if tid == dwThreadId: + for bp in bplist: + result.append(bp) + return result + + def get_process_hardware_breakpoints(self, dwProcessId): + """ + @see: L{get_thread_hardware_breakpoints} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: list of tuple( int, L{HardwareBreakpoint} ) + @return: All hardware breakpoints for each thread in the given process + as a list of tuples (tid, bp). + """ + result = list() + aProcess = self.system.get_process(dwProcessId) + for dwThreadId in aProcess.iter_thread_ids(): + if dwThreadId in self.__hardwareBP: + bplist = self.__hardwareBP[dwThreadId] + for bp in bplist: + result.append( (dwThreadId, bp) ) + return result + +## def get_all_hooks(self): +## """ +## @see: L{get_process_hooks} +## +## @rtype: list of tuple( int, int, L{Hook} ) +## @return: All defined hooks as a list of tuples (pid, address, hook). +## """ +## return [ (pid, address, hook) \ +## for ((pid, address), hook) in self.__hook_objects ] +## +## def get_process_hooks(self, dwProcessId): +## """ +## @see: L{get_all_hooks} +## +## @type dwProcessId: int +## @param dwProcessId: Process global ID. +## +## @rtype: list of tuple( int, int, L{Hook} ) +## @return: All hooks for the given process as a list of tuples +## (pid, address, hook). +## """ +## return [ (pid, address, hook) \ +## for ((pid, address), hook) in self.__hook_objects \ +## if pid == dwProcessId ] + +#------------------------------------------------------------------------------ + + # Batch operations on all breakpoints. + + def enable_all_breakpoints(self): + """ + Enables all disabled breakpoints in all processes. + + @see: + enable_code_breakpoint, + enable_page_breakpoint, + enable_hardware_breakpoint + """ + + # disable code breakpoints + for (pid, bp) in self.get_all_code_breakpoints(): + if bp.is_disabled(): + self.enable_code_breakpoint(pid, bp.get_address()) + + # disable page breakpoints + for (pid, bp) in self.get_all_page_breakpoints(): + if bp.is_disabled(): + self.enable_page_breakpoint(pid, bp.get_address()) + + # disable hardware breakpoints + for (tid, bp) in self.get_all_hardware_breakpoints(): + if bp.is_disabled(): + self.enable_hardware_breakpoint(tid, bp.get_address()) + + def enable_one_shot_all_breakpoints(self): + """ + Enables for one shot all disabled breakpoints in all processes. + + @see: + enable_one_shot_code_breakpoint, + enable_one_shot_page_breakpoint, + enable_one_shot_hardware_breakpoint + """ + + # disable code breakpoints for one shot + for (pid, bp) in self.get_all_code_breakpoints(): + if bp.is_disabled(): + self.enable_one_shot_code_breakpoint(pid, bp.get_address()) + + # disable page breakpoints for one shot + for (pid, bp) in self.get_all_page_breakpoints(): + if bp.is_disabled(): + self.enable_one_shot_page_breakpoint(pid, bp.get_address()) + + # disable hardware breakpoints for one shot + for (tid, bp) in self.get_all_hardware_breakpoints(): + if bp.is_disabled(): + self.enable_one_shot_hardware_breakpoint(tid, bp.get_address()) + + def disable_all_breakpoints(self): + """ + Disables all breakpoints in all processes. + + @see: + disable_code_breakpoint, + disable_page_breakpoint, + disable_hardware_breakpoint + """ + + # disable code breakpoints + for (pid, bp) in self.get_all_code_breakpoints(): + self.disable_code_breakpoint(pid, bp.get_address()) + + # disable page breakpoints + for (pid, bp) in self.get_all_page_breakpoints(): + self.disable_page_breakpoint(pid, bp.get_address()) + + # disable hardware breakpoints + for (tid, bp) in self.get_all_hardware_breakpoints(): + self.disable_hardware_breakpoint(tid, bp.get_address()) + + def erase_all_breakpoints(self): + """ + Erases all breakpoints in all processes. + + @see: + erase_code_breakpoint, + erase_page_breakpoint, + erase_hardware_breakpoint + """ + + # This should be faster but let's not trust the GC so much :P + # self.disable_all_breakpoints() + # self.__codeBP = dict() + # self.__pageBP = dict() + # self.__hardwareBP = dict() + # self.__runningBP = dict() + # self.__hook_objects = dict() + +## # erase hooks +## for (pid, address, hook) in self.get_all_hooks(): +## self.dont_hook_function(pid, address) + + # erase code breakpoints + for (pid, bp) in self.get_all_code_breakpoints(): + self.erase_code_breakpoint(pid, bp.get_address()) + + # erase page breakpoints + for (pid, bp) in self.get_all_page_breakpoints(): + self.erase_page_breakpoint(pid, bp.get_address()) + + # erase hardware breakpoints + for (tid, bp) in self.get_all_hardware_breakpoints(): + self.erase_hardware_breakpoint(tid, bp.get_address()) + +#------------------------------------------------------------------------------ + + # Batch operations on breakpoints per process. + + def enable_process_breakpoints(self, dwProcessId): + """ + Enables all disabled breakpoints for the given process. + + @type dwProcessId: int + @param dwProcessId: Process global ID. + """ + + # enable code breakpoints + for bp in self.get_process_code_breakpoints(dwProcessId): + if bp.is_disabled(): + self.enable_code_breakpoint(dwProcessId, bp.get_address()) + + # enable page breakpoints + for bp in self.get_process_page_breakpoints(dwProcessId): + if bp.is_disabled(): + self.enable_page_breakpoint(dwProcessId, bp.get_address()) + + # enable hardware breakpoints + if self.system.has_process(dwProcessId): + aProcess = self.system.get_process(dwProcessId) + else: + aProcess = Process(dwProcessId) + aProcess.scan_threads() + for aThread in aProcess.iter_threads(): + dwThreadId = aThread.get_tid() + for bp in self.get_thread_hardware_breakpoints(dwThreadId): + if bp.is_disabled(): + self.enable_hardware_breakpoint(dwThreadId, bp.get_address()) + + def enable_one_shot_process_breakpoints(self, dwProcessId): + """ + Enables for one shot all disabled breakpoints for the given process. + + @type dwProcessId: int + @param dwProcessId: Process global ID. + """ + + # enable code breakpoints for one shot + for bp in self.get_process_code_breakpoints(dwProcessId): + if bp.is_disabled(): + self.enable_one_shot_code_breakpoint(dwProcessId, bp.get_address()) + + # enable page breakpoints for one shot + for bp in self.get_process_page_breakpoints(dwProcessId): + if bp.is_disabled(): + self.enable_one_shot_page_breakpoint(dwProcessId, bp.get_address()) + + # enable hardware breakpoints for one shot + if self.system.has_process(dwProcessId): + aProcess = self.system.get_process(dwProcessId) + else: + aProcess = Process(dwProcessId) + aProcess.scan_threads() + for aThread in aProcess.iter_threads(): + dwThreadId = aThread.get_tid() + for bp in self.get_thread_hardware_breakpoints(dwThreadId): + if bp.is_disabled(): + self.enable_one_shot_hardware_breakpoint(dwThreadId, bp.get_address()) + + def disable_process_breakpoints(self, dwProcessId): + """ + Disables all breakpoints for the given process. + + @type dwProcessId: int + @param dwProcessId: Process global ID. + """ + + # disable code breakpoints + for bp in self.get_process_code_breakpoints(dwProcessId): + self.disable_code_breakpoint(dwProcessId, bp.get_address()) + + # disable page breakpoints + for bp in self.get_process_page_breakpoints(dwProcessId): + self.disable_page_breakpoint(dwProcessId, bp.get_address()) + + # disable hardware breakpoints + if self.system.has_process(dwProcessId): + aProcess = self.system.get_process(dwProcessId) + else: + aProcess = Process(dwProcessId) + aProcess.scan_threads() + for aThread in aProcess.iter_threads(): + dwThreadId = aThread.get_tid() + for bp in self.get_thread_hardware_breakpoints(dwThreadId): + self.disable_hardware_breakpoint(dwThreadId, bp.get_address()) + + def erase_process_breakpoints(self, dwProcessId): + """ + Erases all breakpoints for the given process. + + @type dwProcessId: int + @param dwProcessId: Process global ID. + """ + + # disable breakpoints first + # if an error occurs, no breakpoint is erased + self.disable_process_breakpoints(dwProcessId) + +## # erase hooks +## for address, hook in self.get_process_hooks(dwProcessId): +## self.dont_hook_function(dwProcessId, address) + + # erase code breakpoints + for bp in self.get_process_code_breakpoints(dwProcessId): + self.erase_code_breakpoint(dwProcessId, bp.get_address()) + + # erase page breakpoints + for bp in self.get_process_page_breakpoints(dwProcessId): + self.erase_page_breakpoint(dwProcessId, bp.get_address()) + + # erase hardware breakpoints + if self.system.has_process(dwProcessId): + aProcess = self.system.get_process(dwProcessId) + else: + aProcess = Process(dwProcessId) + aProcess.scan_threads() + for aThread in aProcess.iter_threads(): + dwThreadId = aThread.get_tid() + for bp in self.get_thread_hardware_breakpoints(dwThreadId): + self.erase_hardware_breakpoint(dwThreadId, bp.get_address()) + +#------------------------------------------------------------------------------ + + # Internal handlers of debug events. + + def _notify_guard_page(self, event): + """ + Notify breakpoints of a guard page exception event. + + @type event: L{ExceptionEvent} + @param event: Guard page exception event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + address = event.get_fault_address() + pid = event.get_pid() + bCallHandler = True + + # Align address to page boundary. + mask = ~(MemoryAddresses.pageSize - 1) + address = address & mask + + # Do we have an active page breakpoint there? + key = (pid, address) + if key in self.__pageBP: + bp = self.__pageBP[key] + if bp.is_enabled() or bp.is_one_shot(): + + # Breakpoint is ours. + event.continueStatus = win32.DBG_CONTINUE +## event.continueStatus = win32.DBG_EXCEPTION_HANDLED + + # Hit the breakpoint. + bp.hit(event) + + # Remember breakpoints in RUNNING state. + if bp.is_running(): + tid = event.get_tid() + self.__add_running_bp(tid, bp) + + # Evaluate the breakpoint condition. + bCondition = bp.eval_condition(event) + + # If the breakpoint is automatic, run the action. + # If not, notify the user. + if bCondition and bp.is_automatic(): + bp.run_action(event) + bCallHandler = False + else: + bCallHandler = bCondition + + # If we don't have a breakpoint here pass the exception to the debugee. + # This is a normally occurring exception so we shouldn't swallow it. + else: + event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + + return bCallHandler + + def _notify_breakpoint(self, event): + """ + Notify breakpoints of a breakpoint exception event. + + @type event: L{ExceptionEvent} + @param event: Breakpoint exception event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + address = event.get_exception_address() + pid = event.get_pid() + bCallHandler = True + + # Do we have an active code breakpoint there? + key = (pid, address) + if key in self.__codeBP: + bp = self.__codeBP[key] + if not bp.is_disabled(): + + # Change the program counter (PC) to the exception address. + # This accounts for the change in PC caused by + # executing the breakpoint instruction, no matter + # the size of it. + aThread = event.get_thread() + aThread.set_pc(address) + + # Swallow the exception. + event.continueStatus = win32.DBG_CONTINUE + + # Hit the breakpoint. + bp.hit(event) + + # Remember breakpoints in RUNNING state. + if bp.is_running(): + tid = event.get_tid() + self.__add_running_bp(tid, bp) + + # Evaluate the breakpoint condition. + bCondition = bp.eval_condition(event) + + # If the breakpoint is automatic, run the action. + # If not, notify the user. + if bCondition and bp.is_automatic(): + bCallHandler = bp.run_action(event) + else: + bCallHandler = bCondition + + # Handle the system breakpoint. + # TODO: examine the stack trace to figure out if it's really a + # system breakpoint or an antidebug trick. The caller should be + # inside ntdll if it's legit. + elif event.get_process().is_system_defined_breakpoint(address): + event.continueStatus = win32.DBG_CONTINUE + + # In hostile mode, if we don't have a breakpoint here pass the + # exception to the debugee. In normal mode assume all breakpoint + # exceptions are to be handled by the debugger. + else: + if self.in_hostile_mode(): + event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + else: + event.continueStatus = win32.DBG_CONTINUE + + return bCallHandler + + def _notify_single_step(self, event): + """ + Notify breakpoints of a single step exception event. + + @type event: L{ExceptionEvent} + @param event: Single step exception event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + pid = event.get_pid() + tid = event.get_tid() + aThread = event.get_thread() + aProcess = event.get_process() + bCallHandler = True + bIsOurs = False + + # In hostile mode set the default to pass the exception to the debugee. + # If we later determine the exception is ours, hide it instead. + old_continueStatus = event.continueStatus + try: + if self.in_hostile_mode(): + event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + + # Single step support is implemented on x86/x64 architectures only. + if self.system.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + return bCallHandler + + # In hostile mode, read the last executed bytes to try to detect + # some antidebug tricks. Skip this check in normal mode because + # it'd slow things down. + # + # FIXME: weird opcode encodings may bypass this check! + # + # bFakeSingleStep: Ice Breakpoint undocumented instruction. + # bHideTrapFlag: Don't let pushf instructions get the real value of + # the trap flag. + # bNextIsPopFlags: Don't let popf instructions clear the trap flag. + # + bFakeSingleStep = False + bLastIsPushFlags = False + bNextIsPopFlags = False + if self.in_hostile_mode(): + pc = aThread.get_pc() + c = aProcess.read_char(pc - 1) + if c == 0xF1: # int1 + bFakeSingleStep = True + elif c == 0x9C: # pushf + bLastIsPushFlags = True + c = aProcess.peek_char(pc) + if c == 0x66: # the only valid prefix for popf + c = aProcess.peek_char(pc + 1) + if c == 0x9D: # popf + if bLastIsPushFlags: + bLastIsPushFlags = False # they cancel each other out + else: + bNextIsPopFlags = True + + # When the thread is in tracing mode, + # don't pass the exception to the debugee + # and set the trap flag again. + if self.is_tracing(tid): + bIsOurs = True + if not bFakeSingleStep: + event.continueStatus = win32.DBG_CONTINUE + aThread.set_tf() + + # Don't let the debugee read or write the trap flag. + # This code works in 32 and 64 bits thanks to the endianness. + if bLastIsPushFlags or bNextIsPopFlags: + sp = aThread.get_sp() + flags = aProcess.read_dword(sp) + if bLastIsPushFlags: + flags &= ~Thread.Flags.Trap + else: # if bNextIsPopFlags: + flags |= Thread.Flags.Trap + aProcess.write_dword(sp, flags) + + # Handle breakpoints in RUNNING state. + running = self.__get_running_bp_set(tid) + if running: + bIsOurs = True + if not bFakeSingleStep: + event.continueStatus = win32.DBG_CONTINUE + bCallHandler = False + while running: + try: + running.pop().hit(event) + except Exception: + e = sys.exc_info()[1] + warnings.warn(str(e), BreakpointWarning) + + # Handle hardware breakpoints. + if tid in self.__hardwareBP: + ctx = aThread.get_context(win32.CONTEXT_DEBUG_REGISTERS) + Dr6 = ctx['Dr6'] + ctx['Dr6'] = Dr6 & DebugRegister.clearHitMask + aThread.set_context(ctx) + bFoundBreakpoint = False + bCondition = False + hwbpList = [ bp for bp in self.__hardwareBP[tid] ] + for bp in hwbpList: + if not bp in self.__hardwareBP[tid]: + continue # it was removed by a user-defined callback + slot = bp.get_slot() + if (slot is not None) and \ + (Dr6 & DebugRegister.hitMask[slot]): + if not bFoundBreakpoint: #set before actions are called + if not bFakeSingleStep: + event.continueStatus = win32.DBG_CONTINUE + bFoundBreakpoint = True + bIsOurs = True + bp.hit(event) + if bp.is_running(): + self.__add_running_bp(tid, bp) + bThisCondition = bp.eval_condition(event) + if bThisCondition and bp.is_automatic(): + bp.run_action(event) + bThisCondition = False + bCondition = bCondition or bThisCondition + if bFoundBreakpoint: + bCallHandler = bCondition + + # Always call the user-defined handler + # when the thread is in tracing mode. + if self.is_tracing(tid): + bCallHandler = True + + # If we're not in hostile mode, by default we assume all single + # step exceptions are caused by the debugger. + if not bIsOurs and not self.in_hostile_mode(): + aThread.clear_tf() + + # If the user hit Control-C while we were inside the try block, + # set the default continueStatus back. + except: + event.continueStatus = old_continueStatus + raise + + return bCallHandler + + def _notify_load_dll(self, event): + """ + Notify the loading of a DLL. + + @type event: L{LoadDLLEvent} + @param event: Load DLL event. + + @rtype: bool + @return: C{True} to call the user-defined handler, C{False} otherwise. + """ + self.__set_deferred_breakpoints(event) + return True + + def _notify_unload_dll(self, event): + """ + Notify the unloading of a DLL. + + @type event: L{UnloadDLLEvent} + @param event: Unload DLL event. + + @rtype: bool + @return: C{True} to call the user-defined handler, C{False} otherwise. + """ + self.__cleanup_module(event) + return True + + def _notify_exit_thread(self, event): + """ + Notify the termination of a thread. + + @type event: L{ExitThreadEvent} + @param event: Exit thread event. + + @rtype: bool + @return: C{True} to call the user-defined handler, C{False} otherwise. + """ + self.__cleanup_thread(event) + return True + + def _notify_exit_process(self, event): + """ + Notify the termination of a process. + + @type event: L{ExitProcessEvent} + @param event: Exit process event. + + @rtype: bool + @return: C{True} to call the user-defined handler, C{False} otherwise. + """ + self.__cleanup_process(event) + self.__cleanup_thread(event) + return True + +#------------------------------------------------------------------------------ + + # This is the high level breakpoint interface. Here we don't have to care + # about defining or enabling breakpoints, and many errors are ignored + # (like for example setting the same breakpoint twice, here the second + # breakpoint replaces the first, much like in WinDBG). It should be easier + # and more intuitive, if less detailed. It also allows the use of deferred + # breakpoints. + +#------------------------------------------------------------------------------ + + # Code breakpoints + + def __set_break(self, pid, address, action, oneshot): + """ + Used by L{break_at} and L{stalk_at}. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_code_breakpoint} for more details. + + @type oneshot: bool + @param oneshot: C{True} for one-shot breakpoints, C{False} otherwise. + + @rtype: L{Breakpoint} + @return: Returns the new L{Breakpoint} object, or C{None} if the label + couldn't be resolved and the breakpoint was deferred. Deferred + breakpoints are set when the DLL they point to is loaded. + """ + if type(address) not in (int, long): + label = address + try: + address = self.system.get_process(pid).resolve_label(address) + if not address: + raise Exception() + except Exception: + try: + deferred = self.__deferredBP[pid] + except KeyError: + deferred = dict() + self.__deferredBP[pid] = deferred + if label in deferred: + msg = "Redefined deferred code breakpoint at %s in process ID %d" + msg = msg % (label, pid) + warnings.warn(msg, BreakpointWarning) + deferred[label] = (action, oneshot) + return None + if self.has_code_breakpoint(pid, address): + bp = self.get_code_breakpoint(pid, address) + if bp.get_action() != action: # can't use "is not", fails for bound methods + bp.set_action(action) + msg = "Redefined code breakpoint at %s in process ID %d" + msg = msg % (label, pid) + warnings.warn(msg, BreakpointWarning) + else: + self.define_code_breakpoint(pid, address, True, action) + bp = self.get_code_breakpoint(pid, address) + if oneshot: + if not bp.is_one_shot(): + self.enable_one_shot_code_breakpoint(pid, address) + else: + if not bp.is_enabled(): + self.enable_code_breakpoint(pid, address) + return bp + + def __clear_break(self, pid, address): + """ + Used by L{dont_break_at} and L{dont_stalk_at}. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + """ + if type(address) not in (int, long): + unknown = True + label = address + try: + deferred = self.__deferredBP[pid] + del deferred[label] + unknown = False + except KeyError: +## traceback.print_last() # XXX DEBUG + pass + aProcess = self.system.get_process(pid) + try: + address = aProcess.resolve_label(label) + if not address: + raise Exception() + except Exception: +## traceback.print_last() # XXX DEBUG + if unknown: + msg = ("Can't clear unknown code breakpoint" + " at %s in process ID %d") + msg = msg % (label, pid) + warnings.warn(msg, BreakpointWarning) + return + if self.has_code_breakpoint(pid, address): + self.erase_code_breakpoint(pid, address) + + def __set_deferred_breakpoints(self, event): + """ + Used internally. Sets all deferred breakpoints for a DLL when it's + loaded. + + @type event: L{LoadDLLEvent} + @param event: Load DLL event. + """ + pid = event.get_pid() + try: + deferred = self.__deferredBP[pid] + except KeyError: + return + aProcess = event.get_process() + for (label, (action, oneshot)) in deferred.items(): + try: + address = aProcess.resolve_label(label) + except Exception: + continue + del deferred[label] + try: + self.__set_break(pid, address, action, oneshot) + except Exception: + msg = "Can't set deferred breakpoint %s at process ID %d" + msg = msg % (label, pid) + warnings.warn(msg, BreakpointWarning) + + def get_all_deferred_code_breakpoints(self): + """ + Returns a list of deferred code breakpoints. + + @rtype: tuple of (int, str, callable, bool) + @return: Tuple containing the following elements: + - Process ID where to set the breakpoint. + - Label pointing to the address where to set the breakpoint. + - Action callback for the breakpoint. + - C{True} of the breakpoint is one-shot, C{False} otherwise. + """ + result = [] + for pid, deferred in compat.iteritems(self.__deferredBP): + for (label, (action, oneshot)) in compat.iteritems(deferred): + result.add( (pid, label, action, oneshot) ) + return result + + def get_process_deferred_code_breakpoints(self, dwProcessId): + """ + Returns a list of deferred code breakpoints. + + @type dwProcessId: int + @param dwProcessId: Process ID. + + @rtype: tuple of (int, str, callable, bool) + @return: Tuple containing the following elements: + - Label pointing to the address where to set the breakpoint. + - Action callback for the breakpoint. + - C{True} of the breakpoint is one-shot, C{False} otherwise. + """ + return [ (label, action, oneshot) + for (label, (action, oneshot)) + in compat.iteritems(self.__deferredBP.get(dwProcessId, {})) ] + + def stalk_at(self, pid, address, action = None): + """ + Sets a one shot code breakpoint at the given process and address. + + If instead of an address you pass a label, the breakpoint may be + deferred until the DLL it points to is loaded. + + @see: L{break_at}, L{dont_stalk_at} + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_code_breakpoint} for more details. + + @rtype: bool + @return: C{True} if the breakpoint was set immediately, or C{False} if + it was deferred. + """ + bp = self.__set_break(pid, address, action, oneshot = True) + return bp is not None + + def break_at(self, pid, address, action = None): + """ + Sets a code breakpoint at the given process and address. + + If instead of an address you pass a label, the breakpoint may be + deferred until the DLL it points to is loaded. + + @see: L{stalk_at}, L{dont_break_at} + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_code_breakpoint} for more details. + + @rtype: bool + @return: C{True} if the breakpoint was set immediately, or C{False} if + it was deferred. + """ + bp = self.__set_break(pid, address, action, oneshot = False) + return bp is not None + + def dont_break_at(self, pid, address): + """ + Clears a code breakpoint set by L{break_at}. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + """ + self.__clear_break(pid, address) + + def dont_stalk_at(self, pid, address): + """ + Clears a code breakpoint set by L{stalk_at}. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + """ + self.__clear_break(pid, address) + +#------------------------------------------------------------------------------ + + # Function hooks + + def hook_function(self, pid, address, + preCB = None, postCB = None, + paramCount = None, signature = None): + """ + Sets a function hook at the given address. + + If instead of an address you pass a label, the hook may be + deferred until the DLL it points to is loaded. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + + @type preCB: function + @param preCB: (Optional) Callback triggered on function entry. + + The signature for the callback should be something like this:: + + def pre_LoadLibraryEx(event, ra, lpFilename, hFile, dwFlags): + + # return address + ra = params[0] + + # function arguments start from here... + szFilename = event.get_process().peek_string(lpFilename) + + # (...) + + Note that all pointer types are treated like void pointers, so your + callback won't get the string or structure pointed to by it, but + the remote memory address instead. This is so to prevent the ctypes + library from being "too helpful" and trying to dereference the + pointer. To get the actual data being pointed to, use one of the + L{Process.read} methods. + + @type postCB: function + @param postCB: (Optional) Callback triggered on function exit. + + The signature for the callback should be something like this:: + + def post_LoadLibraryEx(event, return_value): + + # (...) + + @type paramCount: int + @param paramCount: + (Optional) Number of parameters for the C{preCB} callback, + not counting the return address. Parameters are read from + the stack and assumed to be DWORDs in 32 bits and QWORDs in 64. + + This is a faster way to pull stack parameters in 32 bits, but in 64 + bits (or with some odd APIs in 32 bits) it won't be useful, since + not all arguments to the hooked function will be of the same size. + + For a more reliable and cross-platform way of hooking use the + C{signature} argument instead. + + @type signature: tuple + @param signature: + (Optional) Tuple of C{ctypes} data types that constitute the + hooked function signature. When the function is called, this will + be used to parse the arguments from the stack. Overrides the + C{paramCount} argument. + + @rtype: bool + @return: C{True} if the hook was set immediately, or C{False} if + it was deferred. + """ + try: + aProcess = self.system.get_process(pid) + except KeyError: + aProcess = Process(pid) + arch = aProcess.get_arch() + hookObj = Hook(preCB, postCB, paramCount, signature, arch) + bp = self.break_at(pid, address, hookObj) + return bp is not None + + def stalk_function(self, pid, address, + preCB = None, postCB = None, + paramCount = None, signature = None): + """ + Sets a one-shot function hook at the given address. + + If instead of an address you pass a label, the hook may be + deferred until the DLL it points to is loaded. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + + @type preCB: function + @param preCB: (Optional) Callback triggered on function entry. + + The signature for the callback should be something like this:: + + def pre_LoadLibraryEx(event, ra, lpFilename, hFile, dwFlags): + + # return address + ra = params[0] + + # function arguments start from here... + szFilename = event.get_process().peek_string(lpFilename) + + # (...) + + Note that all pointer types are treated like void pointers, so your + callback won't get the string or structure pointed to by it, but + the remote memory address instead. This is so to prevent the ctypes + library from being "too helpful" and trying to dereference the + pointer. To get the actual data being pointed to, use one of the + L{Process.read} methods. + + @type postCB: function + @param postCB: (Optional) Callback triggered on function exit. + + The signature for the callback should be something like this:: + + def post_LoadLibraryEx(event, return_value): + + # (...) + + @type paramCount: int + @param paramCount: + (Optional) Number of parameters for the C{preCB} callback, + not counting the return address. Parameters are read from + the stack and assumed to be DWORDs in 32 bits and QWORDs in 64. + + This is a faster way to pull stack parameters in 32 bits, but in 64 + bits (or with some odd APIs in 32 bits) it won't be useful, since + not all arguments to the hooked function will be of the same size. + + For a more reliable and cross-platform way of hooking use the + C{signature} argument instead. + + @type signature: tuple + @param signature: + (Optional) Tuple of C{ctypes} data types that constitute the + hooked function signature. When the function is called, this will + be used to parse the arguments from the stack. Overrides the + C{paramCount} argument. + + @rtype: bool + @return: C{True} if the breakpoint was set immediately, or C{False} if + it was deferred. + """ + try: + aProcess = self.system.get_process(pid) + except KeyError: + aProcess = Process(pid) + arch = aProcess.get_arch() + hookObj = Hook(preCB, postCB, paramCount, signature, arch) + bp = self.stalk_at(pid, address, hookObj) + return bp is not None + + def dont_hook_function(self, pid, address): + """ + Removes a function hook set by L{hook_function}. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + """ + self.dont_break_at(pid, address) + + # alias + unhook_function = dont_hook_function + + def dont_stalk_function(self, pid, address): + """ + Removes a function hook set by L{stalk_function}. + + @type pid: int + @param pid: Process global ID. + + @type address: int or str + @param address: + Memory address of code instruction to break at. It can be an + integer value for the actual address or a string with a label + to be resolved. + """ + self.dont_stalk_at(pid, address) + +#------------------------------------------------------------------------------ + + # Variable watches + + def __set_variable_watch(self, tid, address, size, action): + """ + Used by L{watch_variable} and L{stalk_variable}. + + @type tid: int + @param tid: Thread global ID. + + @type address: int + @param address: Memory address of variable to watch. + + @type size: int + @param size: Size of variable to watch. The only supported sizes are: + byte (1), word (2), dword (4) and qword (8). + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_hardware_breakpoint} for more details. + + @rtype: L{HardwareBreakpoint} + @return: Hardware breakpoint at the requested address. + """ + + # TODO + # We should merge the breakpoints instead of overwriting them. + # We'll have the same problem as watch_buffer and we'll need to change + # the API again. + + if size == 1: + sizeFlag = self.BP_WATCH_BYTE + elif size == 2: + sizeFlag = self.BP_WATCH_WORD + elif size == 4: + sizeFlag = self.BP_WATCH_DWORD + elif size == 8: + sizeFlag = self.BP_WATCH_QWORD + else: + raise ValueError("Bad size for variable watch: %r" % size) + + if self.has_hardware_breakpoint(tid, address): + warnings.warn( + "Hardware breakpoint in thread %d at address %s was overwritten!" \ + % (tid, HexDump.address(address, + self.system.get_thread(tid).get_bits())), + BreakpointWarning) + + bp = self.get_hardware_breakpoint(tid, address) + if bp.get_trigger() != self.BP_BREAK_ON_ACCESS or \ + bp.get_watch() != sizeFlag: + self.erase_hardware_breakpoint(tid, address) + self.define_hardware_breakpoint(tid, address, + self.BP_BREAK_ON_ACCESS, sizeFlag, True, action) + bp = self.get_hardware_breakpoint(tid, address) + + else: + self.define_hardware_breakpoint(tid, address, + self.BP_BREAK_ON_ACCESS, sizeFlag, True, action) + bp = self.get_hardware_breakpoint(tid, address) + + return bp + + def __clear_variable_watch(self, tid, address): + """ + Used by L{dont_watch_variable} and L{dont_stalk_variable}. + + @type tid: int + @param tid: Thread global ID. + + @type address: int + @param address: Memory address of variable to stop watching. + """ + if self.has_hardware_breakpoint(tid, address): + self.erase_hardware_breakpoint(tid, address) + + def watch_variable(self, tid, address, size, action = None): + """ + Sets a hardware breakpoint at the given thread, address and size. + + @see: L{dont_watch_variable} + + @type tid: int + @param tid: Thread global ID. + + @type address: int + @param address: Memory address of variable to watch. + + @type size: int + @param size: Size of variable to watch. The only supported sizes are: + byte (1), word (2), dword (4) and qword (8). + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_hardware_breakpoint} for more details. + """ + bp = self.__set_variable_watch(tid, address, size, action) + if not bp.is_enabled(): + self.enable_hardware_breakpoint(tid, address) + + def stalk_variable(self, tid, address, size, action = None): + """ + Sets a one-shot hardware breakpoint at the given thread, + address and size. + + @see: L{dont_watch_variable} + + @type tid: int + @param tid: Thread global ID. + + @type address: int + @param address: Memory address of variable to watch. + + @type size: int + @param size: Size of variable to watch. The only supported sizes are: + byte (1), word (2), dword (4) and qword (8). + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_hardware_breakpoint} for more details. + """ + bp = self.__set_variable_watch(tid, address, size, action) + if not bp.is_one_shot(): + self.enable_one_shot_hardware_breakpoint(tid, address) + + def dont_watch_variable(self, tid, address): + """ + Clears a hardware breakpoint set by L{watch_variable}. + + @type tid: int + @param tid: Thread global ID. + + @type address: int + @param address: Memory address of variable to stop watching. + """ + self.__clear_variable_watch(tid, address) + + def dont_stalk_variable(self, tid, address): + """ + Clears a hardware breakpoint set by L{stalk_variable}. + + @type tid: int + @param tid: Thread global ID. + + @type address: int + @param address: Memory address of variable to stop watching. + """ + self.__clear_variable_watch(tid, address) + +#------------------------------------------------------------------------------ + + # Buffer watches + + def __set_buffer_watch(self, pid, address, size, action, bOneShot): + """ + Used by L{watch_buffer} and L{stalk_buffer}. + + @type pid: int + @param pid: Process global ID. + + @type address: int + @param address: Memory address of buffer to watch. + + @type size: int + @param size: Size in bytes of buffer to watch. + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_page_breakpoint} for more details. + + @type bOneShot: bool + @param bOneShot: + C{True} to set a one-shot breakpoint, + C{False} to set a normal breakpoint. + """ + + # Check the size isn't zero or negative. + if size < 1: + raise ValueError("Bad size for buffer watch: %r" % size) + + # Create the buffer watch identifier. + bw = BufferWatch(pid, address, address + size, action, bOneShot) + + # Get the base address and size in pages required for this buffer. + base = MemoryAddresses.align_address_to_page_start(address) + limit = MemoryAddresses.align_address_to_page_end(address + size) + pages = MemoryAddresses.get_buffer_size_in_pages(address, size) + + try: + + # For each page: + # + if a page breakpoint exists reuse it + # + if it doesn't exist define it + + bset = set() # all breakpoints used + nset = set() # newly defined breakpoints + cset = set() # condition objects + + page_addr = base + pageSize = MemoryAddresses.pageSize + while page_addr < limit: + + # If a breakpoints exists, reuse it. + if self.has_page_breakpoint(pid, page_addr): + bp = self.get_page_breakpoint(pid, page_addr) + if bp not in bset: + condition = bp.get_condition() + if not condition in cset: + if not isinstance(condition,_BufferWatchCondition): + # this shouldn't happen unless you tinkered + # with it or defined your own page breakpoints + # manually. + msg = "Can't watch buffer at page %s" + msg = msg % HexDump.address(page_addr) + raise RuntimeError(msg) + cset.add(condition) + bset.add(bp) + + # If it doesn't, define it. + else: + condition = _BufferWatchCondition() + bp = self.define_page_breakpoint(pid, page_addr, 1, + condition = condition) + bset.add(bp) + nset.add(bp) + cset.add(condition) + + # Next page. + page_addr = page_addr + pageSize + + # For each breakpoint, enable it if needed. + aProcess = self.system.get_process(pid) + for bp in bset: + if bp.is_disabled() or bp.is_one_shot(): + bp.enable(aProcess, None) + + # On error... + except: + + # Erase the newly defined breakpoints. + for bp in nset: + try: + self.erase_page_breakpoint(pid, bp.get_address()) + except: + pass + + # Pass the exception to the caller + raise + + # For each condition object, add the new buffer. + for condition in cset: + condition.add(bw) + + def __clear_buffer_watch_old_method(self, pid, address, size): + """ + Used by L{dont_watch_buffer} and L{dont_stalk_buffer}. + + @warn: Deprecated since WinAppDbg 1.5. + + @type pid: int + @param pid: Process global ID. + + @type address: int + @param address: Memory address of buffer to stop watching. + + @type size: int + @param size: Size in bytes of buffer to stop watching. + """ + warnings.warn("Deprecated since WinAppDbg 1.5", DeprecationWarning) + + # Check the size isn't zero or negative. + if size < 1: + raise ValueError("Bad size for buffer watch: %r" % size) + + # Get the base address and size in pages required for this buffer. + base = MemoryAddresses.align_address_to_page_start(address) + limit = MemoryAddresses.align_address_to_page_end(address + size) + pages = MemoryAddresses.get_buffer_size_in_pages(address, size) + + # For each page, get the breakpoint and it's condition object. + # For each condition, remove the buffer. + # For each breakpoint, if no buffers are on watch, erase it. + cset = set() # condition objects + page_addr = base + pageSize = MemoryAddresses.pageSize + while page_addr < limit: + if self.has_page_breakpoint(pid, page_addr): + bp = self.get_page_breakpoint(pid, page_addr) + condition = bp.get_condition() + if condition not in cset: + if not isinstance(condition, _BufferWatchCondition): + # this shouldn't happen unless you tinkered with it + # or defined your own page breakpoints manually. + continue + cset.add(condition) + condition.remove_last_match(address, size) + if condition.count() == 0: + try: + self.erase_page_breakpoint(pid, bp.get_address()) + except WindowsError: + pass + page_addr = page_addr + pageSize + + def __clear_buffer_watch(self, bw): + """ + Used by L{dont_watch_buffer} and L{dont_stalk_buffer}. + + @type bw: L{BufferWatch} + @param bw: Buffer watch identifier. + """ + + # Get the PID and the start and end addresses of the buffer. + pid = bw.pid + start = bw.start + end = bw.end + + # Get the base address and size in pages required for the buffer. + base = MemoryAddresses.align_address_to_page_start(start) + limit = MemoryAddresses.align_address_to_page_end(end) + pages = MemoryAddresses.get_buffer_size_in_pages(start, end - start) + + # For each page, get the breakpoint and it's condition object. + # For each condition, remove the buffer. + # For each breakpoint, if no buffers are on watch, erase it. + cset = set() # condition objects + page_addr = base + pageSize = MemoryAddresses.pageSize + while page_addr < limit: + if self.has_page_breakpoint(pid, page_addr): + bp = self.get_page_breakpoint(pid, page_addr) + condition = bp.get_condition() + if condition not in cset: + if not isinstance(condition, _BufferWatchCondition): + # this shouldn't happen unless you tinkered with it + # or defined your own page breakpoints manually. + continue + cset.add(condition) + condition.remove(bw) + if condition.count() == 0: + try: + self.erase_page_breakpoint(pid, bp.get_address()) + except WindowsError: + msg = "Cannot remove page breakpoint at address %s" + msg = msg % HexDump.address( bp.get_address() ) + warnings.warn(msg, BreakpointWarning) + page_addr = page_addr + pageSize + + def watch_buffer(self, pid, address, size, action = None): + """ + Sets a page breakpoint and notifies when the given buffer is accessed. + + @see: L{dont_watch_variable} + + @type pid: int + @param pid: Process global ID. + + @type address: int + @param address: Memory address of buffer to watch. + + @type size: int + @param size: Size in bytes of buffer to watch. + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_page_breakpoint} for more details. + + @rtype: L{BufferWatch} + @return: Buffer watch identifier. + """ + self.__set_buffer_watch(pid, address, size, action, False) + + def stalk_buffer(self, pid, address, size, action = None): + """ + Sets a one-shot page breakpoint and notifies + when the given buffer is accessed. + + @see: L{dont_watch_variable} + + @type pid: int + @param pid: Process global ID. + + @type address: int + @param address: Memory address of buffer to watch. + + @type size: int + @param size: Size in bytes of buffer to watch. + + @type action: function + @param action: (Optional) Action callback function. + + See L{define_page_breakpoint} for more details. + + @rtype: L{BufferWatch} + @return: Buffer watch identifier. + """ + self.__set_buffer_watch(pid, address, size, action, True) + + def dont_watch_buffer(self, bw, *argv, **argd): + """ + Clears a page breakpoint set by L{watch_buffer}. + + @type bw: L{BufferWatch} + @param bw: + Buffer watch identifier returned by L{watch_buffer}. + """ + + # The sane way to do it. + if not (argv or argd): + self.__clear_buffer_watch(bw) + + # Backwards compatibility with WinAppDbg 1.4. + else: + argv = list(argv) + argv.insert(0, bw) + if 'pid' in argd: + argv.insert(0, argd.pop('pid')) + if 'address' in argd: + argv.insert(1, argd.pop('address')) + if 'size' in argd: + argv.insert(2, argd.pop('size')) + if argd: + raise TypeError("Wrong arguments for dont_watch_buffer()") + try: + pid, address, size = argv + except ValueError: + raise TypeError("Wrong arguments for dont_watch_buffer()") + self.__clear_buffer_watch_old_method(pid, address, size) + + def dont_stalk_buffer(self, bw, *argv, **argd): + """ + Clears a page breakpoint set by L{stalk_buffer}. + + @type bw: L{BufferWatch} + @param bw: + Buffer watch identifier returned by L{stalk_buffer}. + """ + self.dont_watch_buffer(bw, *argv, **argd) + +#------------------------------------------------------------------------------ + + # Tracing + +# XXX TODO +# Add "action" parameter to tracing mode + + def __start_tracing(self, thread): + """ + @type thread: L{Thread} + @param thread: Thread to start tracing. + """ + tid = thread.get_tid() + if not tid in self.__tracing: + thread.set_tf() + self.__tracing.add(tid) + + def __stop_tracing(self, thread): + """ + @type thread: L{Thread} + @param thread: Thread to stop tracing. + """ + tid = thread.get_tid() + if tid in self.__tracing: + self.__tracing.remove(tid) + if thread.is_alive(): + thread.clear_tf() + + def is_tracing(self, tid): + """ + @type tid: int + @param tid: Thread global ID. + + @rtype: bool + @return: C{True} if the thread is being traced, C{False} otherwise. + """ + return tid in self.__tracing + + def get_traced_tids(self): + """ + Retrieves the list of global IDs of all threads being traced. + + @rtype: list( int... ) + @return: List of thread global IDs. + """ + tids = list(self.__tracing) + tids.sort() + return tids + + def start_tracing(self, tid): + """ + Start tracing mode in the given thread. + + @type tid: int + @param tid: Global ID of thread to start tracing. + """ + if not self.is_tracing(tid): + thread = self.system.get_thread(tid) + self.__start_tracing(thread) + + def stop_tracing(self, tid): + """ + Stop tracing mode in the given thread. + + @type tid: int + @param tid: Global ID of thread to stop tracing. + """ + if self.is_tracing(tid): + thread = self.system.get_thread(tid) + self.__stop_tracing(thread) + + def start_tracing_process(self, pid): + """ + Start tracing mode for all threads in the given process. + + @type pid: int + @param pid: Global ID of process to start tracing. + """ + for thread in self.system.get_process(pid).iter_threads(): + self.__start_tracing(thread) + + def stop_tracing_process(self, pid): + """ + Stop tracing mode for all threads in the given process. + + @type pid: int + @param pid: Global ID of process to stop tracing. + """ + for thread in self.system.get_process(pid).iter_threads(): + self.__stop_tracing(thread) + + def start_tracing_all(self): + """ + Start tracing mode for all threads in all debugees. + """ + for pid in self.get_debugee_pids(): + self.start_tracing_process(pid) + + def stop_tracing_all(self): + """ + Stop tracing mode for all threads in all debugees. + """ + for pid in self.get_debugee_pids(): + self.stop_tracing_process(pid) + +#------------------------------------------------------------------------------ + + # Break on LastError values (only available since Windows Server 2003) + + def break_on_error(self, pid, errorCode): + """ + Sets or clears the system breakpoint for a given Win32 error code. + + Use L{Process.is_system_defined_breakpoint} to tell if a breakpoint + exception was caused by a system breakpoint or by the application + itself (for example because of a failed assertion in the code). + + @note: This functionality is only available since Windows Server 2003. + In 2003 it only breaks on error values set externally to the + kernel32.dll library, but this was fixed in Windows Vista. + + @warn: This method will fail if the debug symbols for ntdll (kernel32 + in Windows 2003) are not present. For more information see: + L{System.fix_symbol_store_path}. + + @see: U{http://www.nynaeve.net/?p=147} + + @type pid: int + @param pid: Process ID. + + @type errorCode: int + @param errorCode: Win32 error code to stop on. Set to C{0} or + C{ERROR_SUCCESS} to clear the breakpoint instead. + + @raise NotImplementedError: + The functionality is not supported in this system. + + @raise WindowsError: + An error occurred while processing this request. + """ + aProcess = self.system.get_process(pid) + address = aProcess.get_break_on_error_ptr() + if not address: + raise NotImplementedError( + "The functionality is not supported in this system.") + aProcess.write_dword(address, errorCode) + + def dont_break_on_error(self, pid): + """ + Alias to L{break_on_error}C{(pid, ERROR_SUCCESS)}. + + @type pid: int + @param pid: Process ID. + + @raise NotImplementedError: + The functionality is not supported in this system. + + @raise WindowsError: + An error occurred while processing this request. + """ + self.break_on_error(pid, 0) + +#------------------------------------------------------------------------------ + + # Simplified symbol resolving, useful for hooking functions + + def resolve_exported_function(self, pid, modName, procName): + """ + Resolves the exported DLL function for the given process. + + @type pid: int + @param pid: Process global ID. + + @type modName: str + @param modName: Name of the module that exports the function. + + @type procName: str + @param procName: Name of the exported function to resolve. + + @rtype: int, None + @return: On success, the address of the exported function. + On failure, returns C{None}. + """ + aProcess = self.system.get_process(pid) + aModule = aProcess.get_module_by_name(modName) + if not aModule: + aProcess.scan_modules() + aModule = aProcess.get_module_by_name(modName) + if aModule: + address = aModule.resolve(procName) + return address + return None + + def resolve_label(self, pid, label): + """ + Resolves a label for the given process. + + @type pid: int + @param pid: Process global ID. + + @type label: str + @param label: Label to resolve. + + @rtype: int + @return: Memory address pointed to by the label. + + @raise ValueError: The label is malformed or impossible to resolve. + @raise RuntimeError: Cannot resolve the module or function. + """ + return self.get_process(pid).resolve_label(label) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/compat.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/compat.py new file mode 100644 index 0000000..ad64901 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/compat.py @@ -0,0 +1,183 @@ +# Partial copy of https://bitbucket.org/gutworth/six/src/8e634686c53a35092dd705172440a9231c90ddd1/six.py?at=default +# With some differences to take into account that the iterXXX version may be defined in user code. + +# Original __author__ = "Benjamin Peterson " +# Base __version__ = "1.7.3" + +# Copyright (c) 2010-2014 Benjamin Peterson +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import sys +import types + + + +# Useful for very coarse version differentiation. +PY2 = sys.version_info[0] == 2 +PY3 = sys.version_info[0] == 3 + +if PY3: + string_types = str, + integer_types = int, + class_types = type, + text_type = str + binary_type = bytes + + MAXSIZE = sys.maxsize +else: + string_types = basestring, + integer_types = (int, long) + class_types = (type, types.ClassType) + text_type = unicode + binary_type = str + + if sys.platform.startswith("java"): + # Jython always uses 32 bits. + MAXSIZE = int((1 << 31) - 1) + else: + # It's possible to have sizeof(long) != sizeof(Py_ssize_t). + class X(object): + def __len__(self): + return 1 << 31 + try: + len(X()) + except OverflowError: + # 32-bit + MAXSIZE = int((1 << 31) - 1) + else: + # 64-bit + MAXSIZE = int((1 << 63) - 1) + del X + + +if PY3: + xrange = range + unicode = str + bytes = bytes + def iterkeys(d, **kw): + if hasattr(d, 'iterkeys'): + return iter(d.iterkeys(**kw)) + return iter(d.keys(**kw)) + + def itervalues(d, **kw): + if hasattr(d, 'itervalues'): + return iter(d.itervalues(**kw)) + return iter(d.values(**kw)) + + def iteritems(d, **kw): + if hasattr(d, 'iteritems'): + return iter(d.iteritems(**kw)) + return iter(d.items(**kw)) + + def iterlists(d, **kw): + if hasattr(d, 'iterlists'): + return iter(d.iterlists(**kw)) + return iter(d.lists(**kw)) + + def keys(d, **kw): + return list(iterkeys(d, **kw)) +else: + unicode = unicode + xrange = xrange + bytes = str + def keys(d, **kw): + return d.keys(**kw) + + def iterkeys(d, **kw): + return iter(d.iterkeys(**kw)) + + def itervalues(d, **kw): + return iter(d.itervalues(**kw)) + + def iteritems(d, **kw): + return iter(d.iteritems(**kw)) + + def iterlists(d, **kw): + return iter(d.iterlists(**kw)) + +if PY3: + import builtins + exec_ = getattr(builtins, "exec") + + + def reraise(tp, value, tb=None): + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + +else: + def exec_(_code_, _globs_=None, _locs_=None): + """Execute code in a namespace.""" + if _globs_ is None: + frame = sys._getframe(1) + _globs_ = frame.f_globals + if _locs_ is None: + _locs_ = frame.f_locals + del frame + elif _locs_ is None: + _locs_ = _globs_ + exec("""exec _code_ in _globs_, _locs_""") + + + exec_("""def reraise(tp, value, tb=None): + raise tp, value, tb +""") + + +if PY3: + import operator + def b(s): + if isinstance(s, str): + return s.encode("latin-1") + assert isinstance(s, bytes) + return s + def u(s): + return s + unichr = chr + if sys.version_info[1] <= 1: + def int2byte(i): + return bytes((i,)) + else: + # This is about 2x faster than the implementation above on 3.2+ + int2byte = operator.methodcaller("to_bytes", 1, "big") + byte2int = operator.itemgetter(0) + indexbytes = operator.getitem + iterbytes = iter + import io + StringIO = io.StringIO + BytesIO = io.BytesIO +else: + def b(s): + return s + # Workaround for standalone backslash + def u(s): + return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") + unichr = unichr + int2byte = chr + def byte2int(bs): + return ord(bs[0]) + def indexbytes(buf, i): + return ord(buf[i]) + def iterbytes(buf): + return (ord(byte) for byte in buf) + import StringIO + StringIO = BytesIO = StringIO.StringIO \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/crash.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/crash.py new file mode 100644 index 0000000..a53172e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/crash.py @@ -0,0 +1,1853 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Crash dump support. + +@group Crash reporting: + Crash, CrashDictionary + +@group Warnings: + CrashWarning + +@group Deprecated classes: + CrashContainer, CrashTable, CrashTableMSSQL, + VolatileCrashContainer, DummyCrashContainer +""" + +__revision__ = "$Id$" + +__all__ = [ + + # Object that represents a crash in the debugee. + 'Crash', + + # Crash storage. + 'CrashDictionary', + + # Warnings. + 'CrashWarning', + + # Backwards compatibility with WinAppDbg 1.4 and before. + 'CrashContainer', + 'CrashTable', + 'CrashTableMSSQL', + 'VolatileCrashContainer', + 'DummyCrashContainer', +] + +from winappdbg import win32 +from winappdbg import compat +from winappdbg.system import System +from winappdbg.textio import HexDump, CrashDump +from winappdbg.util import StaticClass, MemoryAddresses, PathOperations + +import sys +import os +import time +import zlib +import warnings + +# lazy imports +sql = None +anydbm = None + +#============================================================================== + +# Secure alternative to pickle, use it if present. +try: + import cerealizer + pickle = cerealizer + + # There is no optimization function for cerealized objects. + def optimize(picklestring): + return picklestring + + # There is no HIGHEST_PROTOCOL in cerealizer. + HIGHEST_PROTOCOL = 0 + + # Note: it's important NOT to provide backwards compatibility, otherwise + # it'd be just the same as not having this! + # + # To disable this security upgrade simply uncomment the following line: + # + # raise ImportError("Fallback to pickle for backwards compatibility") + +# If cerealizer is not present fallback to the insecure pickle module. +except ImportError: + + # Faster implementation of the pickle module as a C extension. + try: + import cPickle as pickle + + # If all fails fallback to the classic pickle module. + except ImportError: + import pickle + + # Fetch the highest protocol version. + HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL + + # Try to use the pickle optimizer if found. + try: + from pickletools import optimize + except ImportError: + def optimize(picklestring): + return picklestring + +class Marshaller (StaticClass): + """ + Custom pickler for L{Crash} objects. Optimizes the pickled data when using + the standard C{pickle} (or C{cPickle}) module. The pickled data is then + compressed using zlib. + """ + + @staticmethod + def dumps(obj, protocol=HIGHEST_PROTOCOL): + return zlib.compress(optimize(pickle.dumps(obj)), 9) + + @staticmethod + def loads(data): + return pickle.loads(zlib.decompress(data)) + +#============================================================================== + +class CrashWarning (Warning): + """ + An error occurred while gathering crash data. + Some data may be incomplete or missing. + """ + +#============================================================================== + +# Crash object. Must be serializable. +class Crash (object): + """ + Represents a crash, bug, or another interesting event in the debugee. + + @group Basic information: + timeStamp, signature, eventCode, eventName, pid, tid, arch, os, bits, + registers, labelPC, pc, sp, fp + + @group Optional information: + debugString, + modFileName, + lpBaseOfDll, + exceptionCode, + exceptionName, + exceptionDescription, + exceptionAddress, + exceptionLabel, + firstChance, + faultType, + faultAddress, + faultLabel, + isOurBreakpoint, + isSystemBreakpoint, + stackTrace, + stackTracePC, + stackTraceLabels, + stackTracePretty + + @group Extra information: + commandLine, + environment, + environmentData, + registersPeek, + stackRange, + stackFrame, + stackPeek, + faultCode, + faultMem, + faultPeek, + faultDisasm, + memoryMap + + @group Report: + briefReport, fullReport, notesReport, environmentReport, isExploitable + + @group Notes: + addNote, getNotes, iterNotes, hasNotes, clearNotes, notes + + @group Miscellaneous: + fetch_extra_data + + @type timeStamp: float + @ivar timeStamp: Timestamp as returned by time.time(). + + @type signature: object + @ivar signature: Approximately unique signature for the Crash object. + + This signature can be used as an heuristic to determine if two crashes + were caused by the same software error. Ideally it should be treated as + as opaque serializable object that can be tested for equality. + + @type notes: list( str ) + @ivar notes: List of strings, each string is a note. + + @type eventCode: int + @ivar eventCode: Event code as defined by the Win32 API. + + @type eventName: str + @ivar eventName: Event code user-friendly name. + + @type pid: int + @ivar pid: Process global ID. + + @type tid: int + @ivar tid: Thread global ID. + + @type arch: str + @ivar arch: Processor architecture. + + @type os: str + @ivar os: Operating system version. + + May indicate a 64 bit version even if L{arch} and L{bits} indicate 32 + bits. This means the crash occurred inside a WOW64 process. + + @type bits: int + @ivar bits: C{32} or C{64} bits. + + @type commandLine: None or str + @ivar commandLine: Command line for the target process. + + C{None} if unapplicable or unable to retrieve. + + @type environmentData: None or list of str + @ivar environmentData: Environment data for the target process. + + C{None} if unapplicable or unable to retrieve. + + @type environment: None or dict( str S{->} str ) + @ivar environment: Environment variables for the target process. + + C{None} if unapplicable or unable to retrieve. + + @type registers: dict( str S{->} int ) + @ivar registers: Dictionary mapping register names to their values. + + @type registersPeek: None or dict( str S{->} str ) + @ivar registersPeek: Dictionary mapping register names to the data they point to. + + C{None} if unapplicable or unable to retrieve. + + @type labelPC: None or str + @ivar labelPC: Label pointing to the program counter. + + C{None} or invalid if unapplicable or unable to retrieve. + + @type debugString: None or str + @ivar debugString: Debug string sent by the debugee. + + C{None} if unapplicable or unable to retrieve. + + @type exceptionCode: None or int + @ivar exceptionCode: Exception code as defined by the Win32 API. + + C{None} if unapplicable or unable to retrieve. + + @type exceptionName: None or str + @ivar exceptionName: Exception code user-friendly name. + + C{None} if unapplicable or unable to retrieve. + + @type exceptionDescription: None or str + @ivar exceptionDescription: Exception description. + + C{None} if unapplicable or unable to retrieve. + + @type exceptionAddress: None or int + @ivar exceptionAddress: Memory address where the exception occured. + + C{None} if unapplicable or unable to retrieve. + + @type exceptionLabel: None or str + @ivar exceptionLabel: Label pointing to the exception address. + + C{None} or invalid if unapplicable or unable to retrieve. + + @type faultType: None or int + @ivar faultType: Access violation type. + Only applicable to memory faults. + Should be one of the following constants: + + - L{win32.ACCESS_VIOLATION_TYPE_READ} + - L{win32.ACCESS_VIOLATION_TYPE_WRITE} + - L{win32.ACCESS_VIOLATION_TYPE_DEP} + + C{None} if unapplicable or unable to retrieve. + + @type faultAddress: None or int + @ivar faultAddress: Access violation memory address. + Only applicable to memory faults. + + C{None} if unapplicable or unable to retrieve. + + @type faultLabel: None or str + @ivar faultLabel: Label pointing to the access violation memory address. + Only applicable to memory faults. + + C{None} if unapplicable or unable to retrieve. + + @type firstChance: None or bool + @ivar firstChance: + C{True} for first chance exceptions, C{False} for second chance. + + C{None} if unapplicable or unable to retrieve. + + @type isOurBreakpoint: bool + @ivar isOurBreakpoint: + C{True} for breakpoints defined by the L{Debug} class, + C{False} otherwise. + + C{None} if unapplicable. + + @type isSystemBreakpoint: bool + @ivar isSystemBreakpoint: + C{True} for known system-defined breakpoints, + C{False} otherwise. + + C{None} if unapplicable. + + @type modFileName: None or str + @ivar modFileName: File name of module where the program counter points to. + + C{None} or invalid if unapplicable or unable to retrieve. + + @type lpBaseOfDll: None or int + @ivar lpBaseOfDll: Base of module where the program counter points to. + + C{None} if unapplicable or unable to retrieve. + + @type stackTrace: None or tuple of tuple( int, int, str ) + @ivar stackTrace: + Stack trace of the current thread as a tuple of + ( frame pointer, return address, module filename ). + + C{None} or empty if unapplicable or unable to retrieve. + + @type stackTracePretty: None or tuple of tuple( int, str ) + @ivar stackTracePretty: + Stack trace of the current thread as a tuple of + ( frame pointer, return location ). + + C{None} or empty if unapplicable or unable to retrieve. + + @type stackTracePC: None or tuple( int... ) + @ivar stackTracePC: Tuple of return addresses in the stack trace. + + C{None} or empty if unapplicable or unable to retrieve. + + @type stackTraceLabels: None or tuple( str... ) + @ivar stackTraceLabels: + Tuple of labels pointing to the return addresses in the stack trace. + + C{None} or empty if unapplicable or unable to retrieve. + + @type stackRange: tuple( int, int ) + @ivar stackRange: + Stack beginning and end pointers, in memory addresses order. + + C{None} if unapplicable or unable to retrieve. + + @type stackFrame: None or str + @ivar stackFrame: Data pointed to by the stack pointer. + + C{None} or empty if unapplicable or unable to retrieve. + + @type stackPeek: None or dict( int S{->} str ) + @ivar stackPeek: Dictionary mapping stack offsets to the data they point to. + + C{None} or empty if unapplicable or unable to retrieve. + + @type faultCode: None or str + @ivar faultCode: Data pointed to by the program counter. + + C{None} or empty if unapplicable or unable to retrieve. + + @type faultMem: None or str + @ivar faultMem: Data pointed to by the exception address. + + C{None} or empty if unapplicable or unable to retrieve. + + @type faultPeek: None or dict( intS{->} str ) + @ivar faultPeek: Dictionary mapping guessed pointers at L{faultMem} to the data they point to. + + C{None} or empty if unapplicable or unable to retrieve. + + @type faultDisasm: None or tuple of tuple( long, int, str, str ) + @ivar faultDisasm: Dissassembly around the program counter. + + C{None} or empty if unapplicable or unable to retrieve. + + @type memoryMap: None or list of L{win32.MemoryBasicInformation} objects. + @ivar memoryMap: Memory snapshot of the program. May contain the actual + data from the entire process memory if requested. + See L{fetch_extra_data} for more details. + + C{None} or empty if unapplicable or unable to retrieve. + + @type _rowid: int + @ivar _rowid: Row ID in the database. Internally used by the DAO layer. + Only present in crash dumps retrieved from the database. Do not rely + on this property to be present in future versions of WinAppDbg. + """ + + def __init__(self, event): + """ + @type event: L{Event} + @param event: Event object for crash. + """ + + # First of all, take the timestamp. + self.timeStamp = time.time() + + # Notes are initially empty. + self.notes = list() + + # Get the process and thread, but dont't store them in the DB. + process = event.get_process() + thread = event.get_thread() + + # Determine the architecture. + self.os = System.os + self.arch = process.get_arch() + self.bits = process.get_bits() + + # The following properties are always retrieved for all events. + self.eventCode = event.get_event_code() + self.eventName = event.get_event_name() + self.pid = event.get_pid() + self.tid = event.get_tid() + self.registers = dict(thread.get_context()) + self.labelPC = process.get_label_at_address(self.pc) + + # The following properties are only retrieved for some events. + self.commandLine = None + self.environment = None + self.environmentData = None + self.registersPeek = None + self.debugString = None + self.modFileName = None + self.lpBaseOfDll = None + self.exceptionCode = None + self.exceptionName = None + self.exceptionDescription = None + self.exceptionAddress = None + self.exceptionLabel = None + self.firstChance = None + self.faultType = None + self.faultAddress = None + self.faultLabel = None + self.isOurBreakpoint = None + self.isSystemBreakpoint = None + self.stackTrace = None + self.stackTracePC = None + self.stackTraceLabels = None + self.stackTracePretty = None + self.stackRange = None + self.stackFrame = None + self.stackPeek = None + self.faultCode = None + self.faultMem = None + self.faultPeek = None + self.faultDisasm = None + self.memoryMap = None + + # Get information for debug string events. + if self.eventCode == win32.OUTPUT_DEBUG_STRING_EVENT: + self.debugString = event.get_debug_string() + + # Get information for module load and unload events. + # For create and exit process events, get the information + # for the main module. + elif self.eventCode in (win32.CREATE_PROCESS_DEBUG_EVENT, + win32.EXIT_PROCESS_DEBUG_EVENT, + win32.LOAD_DLL_DEBUG_EVENT, + win32.UNLOAD_DLL_DEBUG_EVENT): + aModule = event.get_module() + self.modFileName = event.get_filename() + if not self.modFileName: + self.modFileName = aModule.get_filename() + self.lpBaseOfDll = event.get_module_base() + if not self.lpBaseOfDll: + self.lpBaseOfDll = aModule.get_base() + + # Get some information for exception events. + # To get the remaining information call fetch_extra_data(). + elif self.eventCode == win32.EXCEPTION_DEBUG_EVENT: + + # Exception information. + self.exceptionCode = event.get_exception_code() + self.exceptionName = event.get_exception_name() + self.exceptionDescription = event.get_exception_description() + self.exceptionAddress = event.get_exception_address() + self.firstChance = event.is_first_chance() + self.exceptionLabel = process.get_label_at_address( + self.exceptionAddress) + if self.exceptionCode in (win32.EXCEPTION_ACCESS_VIOLATION, + win32.EXCEPTION_GUARD_PAGE, + win32.EXCEPTION_IN_PAGE_ERROR): + self.faultType = event.get_fault_type() + self.faultAddress = event.get_fault_address() + self.faultLabel = process.get_label_at_address( + self.faultAddress) + elif self.exceptionCode in (win32.EXCEPTION_BREAKPOINT, + win32.EXCEPTION_SINGLE_STEP): + self.isOurBreakpoint = hasattr(event, 'breakpoint') \ + and event.breakpoint + self.isSystemBreakpoint = \ + process.is_system_defined_breakpoint(self.exceptionAddress) + + # Stack trace. + try: + self.stackTracePretty = thread.get_stack_trace_with_labels() + except Exception: + e = sys.exc_info()[1] + warnings.warn( + "Cannot get stack trace with labels, reason: %s" % str(e), + CrashWarning) + try: + self.stackTrace = thread.get_stack_trace() + stackTracePC = [ ra for (_,ra,_) in self.stackTrace ] + self.stackTracePC = tuple(stackTracePC) + stackTraceLabels = [ process.get_label_at_address(ra) \ + for ra in self.stackTracePC ] + self.stackTraceLabels = tuple(stackTraceLabels) + except Exception: + e = sys.exc_info()[1] + warnings.warn("Cannot get stack trace, reason: %s" % str(e), + CrashWarning) + + def fetch_extra_data(self, event, takeMemorySnapshot = 0): + """ + Fetch extra data from the L{Event} object. + + @note: Since this method may take a little longer to run, it's best to + call it only after you've determined the crash is interesting and + you want to save it. + + @type event: L{Event} + @param event: Event object for crash. + + @type takeMemorySnapshot: int + @param takeMemorySnapshot: + Memory snapshot behavior: + - C{0} to take no memory information (default). + - C{1} to take only the memory map. + See L{Process.get_memory_map}. + - C{2} to take a full memory snapshot. + See L{Process.take_memory_snapshot}. + - C{3} to take a live memory snapshot. + See L{Process.generate_memory_snapshot}. + """ + + # Get the process and thread, we'll use them below. + process = event.get_process() + thread = event.get_thread() + + # Get the command line for the target process. + try: + self.commandLine = process.get_command_line() + except Exception: + e = sys.exc_info()[1] + warnings.warn("Cannot get command line, reason: %s" % str(e), + CrashWarning) + + # Get the environment variables for the target process. + try: + self.environmentData = process.get_environment_data() + self.environment = process.parse_environment_data( + self.environmentData) + except Exception: + e = sys.exc_info()[1] + warnings.warn("Cannot get environment, reason: %s" % str(e), + CrashWarning) + + # Data pointed to by registers. + self.registersPeek = thread.peek_pointers_in_registers() + + # Module where execution is taking place. + aModule = process.get_module_at_address(self.pc) + if aModule is not None: + self.modFileName = aModule.get_filename() + self.lpBaseOfDll = aModule.get_base() + + # Contents of the stack frame. + try: + self.stackRange = thread.get_stack_range() + except Exception: + e = sys.exc_info()[1] + warnings.warn("Cannot get stack range, reason: %s" % str(e), + CrashWarning) + try: + self.stackFrame = thread.get_stack_frame() + stackFrame = self.stackFrame + except Exception: + self.stackFrame = thread.peek_stack_data() + stackFrame = self.stackFrame[:64] + if stackFrame: + self.stackPeek = process.peek_pointers_in_data(stackFrame) + + # Code being executed. + self.faultCode = thread.peek_code_bytes() + try: + self.faultDisasm = thread.disassemble_around_pc(32) + except Exception: + e = sys.exc_info()[1] + warnings.warn("Cannot disassemble, reason: %s" % str(e), + CrashWarning) + + # For memory related exceptions, get the memory contents + # of the location that caused the exception to be raised. + if self.eventCode == win32.EXCEPTION_DEBUG_EVENT: + if self.pc != self.exceptionAddress and self.exceptionCode in ( + win32.EXCEPTION_ACCESS_VIOLATION, + win32.EXCEPTION_ARRAY_BOUNDS_EXCEEDED, + win32.EXCEPTION_DATATYPE_MISALIGNMENT, + win32.EXCEPTION_IN_PAGE_ERROR, + win32.EXCEPTION_STACK_OVERFLOW, + win32.EXCEPTION_GUARD_PAGE, + ): + self.faultMem = process.peek(self.exceptionAddress, 64) + if self.faultMem: + self.faultPeek = process.peek_pointers_in_data( + self.faultMem) + + # TODO: maybe add names and versions of DLLs and EXE? + + # Take a snapshot of the process memory. Additionally get the + # memory contents if requested. + if takeMemorySnapshot == 1: + self.memoryMap = process.get_memory_map() + mappedFilenames = process.get_mapped_filenames(self.memoryMap) + for mbi in self.memoryMap: + mbi.filename = mappedFilenames.get(mbi.BaseAddress, None) + mbi.content = None + elif takeMemorySnapshot == 2: + self.memoryMap = process.take_memory_snapshot() + elif takeMemorySnapshot == 3: + self.memoryMap = process.generate_memory_snapshot() + + @property + def pc(self): + """ + Value of the program counter register. + + @rtype: int + """ + try: + return self.registers['Eip'] # i386 + except KeyError: + return self.registers['Rip'] # amd64 + + @property + def sp(self): + """ + Value of the stack pointer register. + + @rtype: int + """ + try: + return self.registers['Esp'] # i386 + except KeyError: + return self.registers['Rsp'] # amd64 + + @property + def fp(self): + """ + Value of the frame pointer register. + + @rtype: int + """ + try: + return self.registers['Ebp'] # i386 + except KeyError: + return self.registers['Rbp'] # amd64 + + def __str__(self): + return self.fullReport() + + def key(self): + """ + Alias of L{signature}. Deprecated since WinAppDbg 1.5. + """ + warnings.warn("Crash.key() method was deprecated in WinAppDbg 1.5", + DeprecationWarning) + return self.signature + + @property + def signature(self): + if self.labelPC: + pc = self.labelPC + else: + pc = self.pc + if self.stackTraceLabels: + trace = self.stackTraceLabels + else: + trace = self.stackTracePC + return ( + self.arch, + self.eventCode, + self.exceptionCode, + pc, + trace, + self.debugString, + ) + # TODO + # add the name and version of the binary where the crash happened? + + def isExploitable(self): + """ + Guess how likely is it that the bug causing the crash can be leveraged + into an exploitable vulnerability. + + @note: Don't take this as an equivalent of a real exploitability + analysis, that can only be done by a human being! This is only + a guideline, useful for example to sort crashes - placing the most + interesting ones at the top. + + @see: The heuristics are similar to those of the B{!exploitable} + extension for I{WinDBG}, which can be downloaded from here: + + U{http://www.codeplex.com/msecdbg} + + @rtype: tuple( str, str, str ) + @return: The first element of the tuple is the result of the analysis, + being one of the following: + + - Not an exception + - Not exploitable + - Not likely exploitable + - Unknown + - Probably exploitable + - Exploitable + + The second element of the tuple is a code to identify the matched + heuristic rule. + + The third element of the tuple is a description string of the + reason behind the result. + """ + + # Terminal rules + + if self.eventCode != win32.EXCEPTION_DEBUG_EVENT: + return ("Not an exception", "NotAnException", "The event is not an exception.") + + if self.stackRange and self.pc is not None and self.stackRange[0] <= self.pc < self.stackRange[1]: + return ("Exploitable", "StackCodeExecution", "Code execution from the stack is considered exploitable.") + + # This rule is NOT from !exploitable + if self.stackRange and self.sp is not None and not (self.stackRange[0] <= self.sp < self.stackRange[1]): + return ("Exploitable", "StackPointerCorruption", "Stack pointer corruption is considered exploitable.") + + if self.exceptionCode == win32.EXCEPTION_ILLEGAL_INSTRUCTION: + return ("Exploitable", "IllegalInstruction", "An illegal instruction exception indicates that the attacker controls execution flow.") + + if self.exceptionCode == win32.EXCEPTION_PRIV_INSTRUCTION: + return ("Exploitable", "PrivilegedInstruction", "A privileged instruction exception indicates that the attacker controls execution flow.") + + if self.exceptionCode == win32.EXCEPTION_GUARD_PAGE: + return ("Exploitable", "GuardPage", "A guard page violation indicates a stack overflow has occured, and the stack of another thread was reached (possibly the overflow length is not controlled by the attacker).") + + if self.exceptionCode == win32.STATUS_STACK_BUFFER_OVERRUN: + return ("Exploitable", "GSViolation", "An overrun of a protected stack buffer has been detected. This is considered exploitable, and must be fixed.") + + if self.exceptionCode == win32.STATUS_HEAP_CORRUPTION: + return ("Exploitable", "HeapCorruption", "Heap Corruption has been detected. This is considered exploitable, and must be fixed.") + + if self.exceptionCode == win32.EXCEPTION_ACCESS_VIOLATION: + nearNull = self.faultAddress is None or MemoryAddresses.align_address_to_page_start(self.faultAddress) == 0 + controlFlow = self.__is_control_flow() + blockDataMove = self.__is_block_data_move() + if self.faultType == win32.EXCEPTION_EXECUTE_FAULT: + if nearNull: + return ("Probably exploitable", "DEPViolation", "User mode DEP access violations are probably exploitable if near NULL.") + else: + return ("Exploitable", "DEPViolation", "User mode DEP access violations are exploitable.") + elif self.faultType == win32.EXCEPTION_WRITE_FAULT: + if nearNull: + return ("Probably exploitable", "WriteAV", "User mode write access violations that are near NULL are probably exploitable.") + else: + return ("Exploitable", "WriteAV", "User mode write access violations that are not near NULL are exploitable.") + elif self.faultType == win32.EXCEPTION_READ_FAULT: + if self.faultAddress == self.pc: + if nearNull: + return ("Probably exploitable", "ReadAVonIP", "Access violations at the instruction pointer are probably exploitable if near NULL.") + else: + return ("Exploitable", "ReadAVonIP", "Access violations at the instruction pointer are exploitable if not near NULL.") + if controlFlow: + if nearNull: + return ("Probably exploitable", "ReadAVonControlFlow", "Access violations near null in control flow instructions are considered probably exploitable.") + else: + return ("Exploitable", "ReadAVonControlFlow", "Access violations not near null in control flow instructions are considered exploitable.") + if blockDataMove: + return ("Probably exploitable", "ReadAVonBlockMove", "This is a read access violation in a block data move, and is therefore classified as probably exploitable.") + + # Rule: Tainted information used to control branch addresses is considered probably exploitable + # Rule: Tainted information used to control the target of a later write is probably exploitable + + # Non terminal rules + + # XXX TODO add rule to check if code is in writeable memory (probably exploitable) + + # XXX TODO maybe we should be returning a list of tuples instead? + + result = ("Unknown", "Unknown", "Exploitability unknown.") + + if self.exceptionCode == win32.EXCEPTION_ACCESS_VIOLATION: + if self.faultType == win32.EXCEPTION_READ_FAULT: + if nearNull: + result = ("Not likely exploitable", "ReadAVNearNull", "This is a user mode read access violation near null, and is probably not exploitable.") + + elif self.exceptionCode == win32.EXCEPTION_INT_DIVIDE_BY_ZERO: + result = ("Not likely exploitable", "DivideByZero", "This is an integer divide by zero, and is probably not exploitable.") + + elif self.exceptionCode == win32.EXCEPTION_FLT_DIVIDE_BY_ZERO: + result = ("Not likely exploitable", "DivideByZero", "This is a floating point divide by zero, and is probably not exploitable.") + + elif self.exceptionCode in (win32.EXCEPTION_BREAKPOINT, win32.STATUS_WX86_BREAKPOINT): + result = ("Unknown", "Breakpoint", "While a breakpoint itself is probably not exploitable, it may also be an indication that an attacker is testing a target. In either case breakpoints should not exist in production code.") + + # Rule: If the stack contains unknown symbols in user mode, call that out + # Rule: Tainted information used to control the source of a later block move unknown, but called out explicitly + # Rule: Tainted information used as an argument to a function is an unknown risk, but called out explicitly + # Rule: Tainted information used to control branch selection is an unknown risk, but called out explicitly + + return result + + def __is_control_flow(self): + """ + Private method to tell if the instruction pointed to by the program + counter is a control flow instruction. + + Currently only works for x86 and amd64 architectures. + """ + jump_instructions = ( + 'jmp', 'jecxz', 'jcxz', + 'ja', 'jnbe', 'jae', 'jnb', 'jb', 'jnae', 'jbe', 'jna', 'jc', 'je', + 'jz', 'jnc', 'jne', 'jnz', 'jnp', 'jpo', 'jp', 'jpe', 'jg', 'jnle', + 'jge', 'jnl', 'jl', 'jnge', 'jle', 'jng', 'jno', 'jns', 'jo', 'js' + ) + call_instructions = ( 'call', 'ret', 'retn' ) + loop_instructions = ( 'loop', 'loopz', 'loopnz', 'loope', 'loopne' ) + control_flow_instructions = call_instructions + loop_instructions + \ + jump_instructions + isControlFlow = False + instruction = None + if self.pc is not None and self.faultDisasm: + for disasm in self.faultDisasm: + if disasm[0] == self.pc: + instruction = disasm[2].lower().strip() + break + if instruction: + for x in control_flow_instructions: + if x in instruction: + isControlFlow = True + break + return isControlFlow + + def __is_block_data_move(self): + """ + Private method to tell if the instruction pointed to by the program + counter is a block data move instruction. + + Currently only works for x86 and amd64 architectures. + """ + block_data_move_instructions = ('movs', 'stos', 'lods') + isBlockDataMove = False + instruction = None + if self.pc is not None and self.faultDisasm: + for disasm in self.faultDisasm: + if disasm[0] == self.pc: + instruction = disasm[2].lower().strip() + break + if instruction: + for x in block_data_move_instructions: + if x in instruction: + isBlockDataMove = True + break + return isBlockDataMove + + def briefReport(self): + """ + @rtype: str + @return: Short description of the event. + """ + if self.exceptionCode is not None: + if self.exceptionCode == win32.EXCEPTION_BREAKPOINT: + if self.isOurBreakpoint: + what = "Breakpoint hit" + elif self.isSystemBreakpoint: + what = "System breakpoint hit" + else: + what = "Assertion failed" + elif self.exceptionDescription: + what = self.exceptionDescription + elif self.exceptionName: + what = self.exceptionName + else: + what = "Exception %s" % \ + HexDump.integer(self.exceptionCode, self.bits) + if self.firstChance: + chance = 'first' + else: + chance = 'second' + if self.exceptionLabel: + where = self.exceptionLabel + elif self.exceptionAddress: + where = HexDump.address(self.exceptionAddress, self.bits) + elif self.labelPC: + where = self.labelPC + else: + where = HexDump.address(self.pc, self.bits) + msg = "%s (%s chance) at %s" % (what, chance, where) + elif self.debugString is not None: + if self.labelPC: + where = self.labelPC + else: + where = HexDump.address(self.pc, self.bits) + msg = "Debug string from %s: %r" % (where, self.debugString) + else: + if self.labelPC: + where = self.labelPC + else: + where = HexDump.address(self.pc, self.bits) + msg = "%s (%s) at %s" % ( + self.eventName, + HexDump.integer(self.eventCode, self.bits), + where + ) + return msg + + def fullReport(self, bShowNotes = True): + """ + @type bShowNotes: bool + @param bShowNotes: C{True} to show the user notes, C{False} otherwise. + + @rtype: str + @return: Long description of the event. + """ + msg = self.briefReport() + msg += '\n' + + if self.bits == 32: + width = 16 + else: + width = 8 + + if self.eventCode == win32.EXCEPTION_DEBUG_EVENT: + (exploitability, expcode, expdescription) = self.isExploitable() + msg += '\nSecurity risk level: %s\n' % exploitability + msg += ' %s\n' % expdescription + + if bShowNotes and self.notes: + msg += '\nNotes:\n' + msg += self.notesReport() + + if self.commandLine: + msg += '\nCommand line: %s\n' % self.commandLine + + if self.environment: + msg += '\nEnvironment:\n' + msg += self.environmentReport() + + if not self.labelPC: + base = HexDump.address(self.lpBaseOfDll, self.bits) + if self.modFileName: + fn = PathOperations.pathname_to_filename(self.modFileName) + msg += '\nRunning in %s (%s)\n' % (fn, base) + else: + msg += '\nRunning in module at %s\n' % base + + if self.registers: + msg += '\nRegisters:\n' + msg += CrashDump.dump_registers(self.registers) + if self.registersPeek: + msg += '\n' + msg += CrashDump.dump_registers_peek(self.registers, + self.registersPeek, + width = width) + + if self.faultDisasm: + msg += '\nCode disassembly:\n' + msg += CrashDump.dump_code(self.faultDisasm, self.pc, + bits = self.bits) + + if self.stackTrace: + msg += '\nStack trace:\n' + if self.stackTracePretty: + msg += CrashDump.dump_stack_trace_with_labels( + self.stackTracePretty, + bits = self.bits) + else: + msg += CrashDump.dump_stack_trace(self.stackTrace, + bits = self.bits) + + if self.stackFrame: + if self.stackPeek: + msg += '\nStack pointers:\n' + msg += CrashDump.dump_stack_peek(self.stackPeek, width = width) + msg += '\nStack dump:\n' + msg += HexDump.hexblock(self.stackFrame, self.sp, + bits = self.bits, width = width) + + if self.faultCode and not self.modFileName: + msg += '\nCode dump:\n' + msg += HexDump.hexblock(self.faultCode, self.pc, + bits = self.bits, width = width) + + if self.faultMem: + if self.faultPeek: + msg += '\nException address pointers:\n' + msg += CrashDump.dump_data_peek(self.faultPeek, + self.exceptionAddress, + bits = self.bits, + width = width) + msg += '\nException address dump:\n' + msg += HexDump.hexblock(self.faultMem, self.exceptionAddress, + bits = self.bits, width = width) + + if self.memoryMap: + msg += '\nMemory map:\n' + mappedFileNames = dict() + for mbi in self.memoryMap: + if hasattr(mbi, 'filename') and mbi.filename: + mappedFileNames[mbi.BaseAddress] = mbi.filename + msg += CrashDump.dump_memory_map(self.memoryMap, mappedFileNames, + bits = self.bits) + + if not msg.endswith('\n\n'): + if not msg.endswith('\n'): + msg += '\n' + msg += '\n' + return msg + + def environmentReport(self): + """ + @rtype: str + @return: The process environment variables, + merged and formatted for a report. + """ + msg = '' + if self.environment: + for key, value in compat.iteritems(self.environment): + msg += ' %s=%s\n' % (key, value) + return msg + + def notesReport(self): + """ + @rtype: str + @return: All notes, merged and formatted for a report. + """ + msg = '' + if self.notes: + for n in self.notes: + n = n.strip('\n') + if '\n' in n: + n = n.strip('\n') + msg += ' * %s\n' % n.pop(0) + for x in n: + msg += ' %s\n' % x + else: + msg += ' * %s\n' % n + return msg + + def addNote(self, msg): + """ + Add a note to the crash event. + + @type msg: str + @param msg: Note text. + """ + self.notes.append(msg) + + def clearNotes(self): + """ + Clear the notes of this crash event. + """ + self.notes = list() + + def getNotes(self): + """ + Get the list of notes of this crash event. + + @rtype: list( str ) + @return: List of notes. + """ + return self.notes + + def iterNotes(self): + """ + Iterate the notes of this crash event. + + @rtype: listiterator + @return: Iterator of the list of notes. + """ + return self.notes.__iter__() + + def hasNotes(self): + """ + @rtype: bool + @return: C{True} if there are notes for this crash event. + """ + return bool( self.notes ) + +#============================================================================== + +class CrashContainer (object): + """ + Old crash dump persistencer using a DBM database. + Doesn't support duplicate crashes. + + @warning: + DBM database support is provided for backwards compatibility with older + versions of WinAppDbg. New applications should not use this class. + Also, DBM databases in Python suffer from multiple problems that can + easily be avoided by switching to a SQL database. + + @see: If you really must use a DBM database, try the standard C{shelve} + module instead: U{http://docs.python.org/library/shelve.html} + + @group Marshalling configuration: + optimizeKeys, optimizeValues, compressKeys, compressValues, escapeKeys, + escapeValues, binaryKeys, binaryValues + + @type optimizeKeys: bool + @cvar optimizeKeys: Ignored by the current implementation. + + Up to WinAppDbg 1.4 this setting caused the database keys to be + optimized when pickled with the standard C{pickle} module. + + But with a DBM database backend that causes inconsistencies, since the + same key can be serialized into multiple optimized pickles, thus losing + uniqueness. + + @type optimizeValues: bool + @cvar optimizeValues: C{True} to optimize the marshalling of keys, C{False} + otherwise. Only used with the C{pickle} module, ignored when using the + more secure C{cerealizer} module. + + @type compressKeys: bool + @cvar compressKeys: C{True} to compress keys when marshalling, C{False} + to leave them uncompressed. + + @type compressValues: bool + @cvar compressValues: C{True} to compress values when marshalling, C{False} + to leave them uncompressed. + + @type escapeKeys: bool + @cvar escapeKeys: C{True} to escape keys when marshalling, C{False} + to leave them uncompressed. + + @type escapeValues: bool + @cvar escapeValues: C{True} to escape values when marshalling, C{False} + to leave them uncompressed. + + @type binaryKeys: bool + @cvar binaryKeys: C{True} to marshall keys to binary format (the Python + C{buffer} type), C{False} to use text marshalled keys (C{str} type). + + @type binaryValues: bool + @cvar binaryValues: C{True} to marshall values to binary format (the Python + C{buffer} type), C{False} to use text marshalled values (C{str} type). + """ + + optimizeKeys = False + optimizeValues = True + compressKeys = False + compressValues = True + escapeKeys = False + escapeValues = False + binaryKeys = False + binaryValues = False + + def __init__(self, filename = None, allowRepeatedKeys = False): + """ + @type filename: str + @param filename: (Optional) File name for crash database. + If no filename is specified, the container is volatile. + + Volatile containers are stored only in memory and + destroyed when they go out of scope. + + @type allowRepeatedKeys: bool + @param allowRepeatedKeys: + Currently not supported, always use C{False}. + """ + if allowRepeatedKeys: + raise NotImplementedError() + self.__filename = filename + if filename: + global anydbm + if not anydbm: + import anydbm + self.__db = anydbm.open(filename, 'c') + self.__keys = dict([ (self.unmarshall_key(mk), mk) + for mk in self.__db.keys() ]) + else: + self.__db = dict() + self.__keys = dict() + + def remove_key(self, key): + """ + Removes the given key from the set of known keys. + + @type key: L{Crash} key. + @param key: Key to remove. + """ + del self.__keys[key] + + def marshall_key(self, key): + """ + Marshalls a Crash key to be used in the database. + + @see: L{__init__} + + @type key: L{Crash} key. + @param key: Key to convert. + + @rtype: str or buffer + @return: Converted key. + """ + if key in self.__keys: + return self.__keys[key] + skey = pickle.dumps(key, protocol = 0) + if self.compressKeys: + skey = zlib.compress(skey, zlib.Z_BEST_COMPRESSION) + if self.escapeKeys: + skey = skey.encode('hex') + if self.binaryKeys: + skey = buffer(skey) + self.__keys[key] = skey + return skey + + def unmarshall_key(self, key): + """ + Unmarshalls a Crash key read from the database. + + @type key: str or buffer + @param key: Key to convert. + + @rtype: L{Crash} key. + @return: Converted key. + """ + key = str(key) + if self.escapeKeys: + key = key.decode('hex') + if self.compressKeys: + key = zlib.decompress(key) + key = pickle.loads(key) + return key + + def marshall_value(self, value, storeMemoryMap = False): + """ + Marshalls a Crash object to be used in the database. + By default the C{memoryMap} member is B{NOT} stored here. + + @warning: Setting the C{storeMemoryMap} argument to C{True} can lead to + a severe performance penalty! + + @type value: L{Crash} + @param value: Object to convert. + + @type storeMemoryMap: bool + @param storeMemoryMap: C{True} to store the memory map, C{False} + otherwise. + + @rtype: str + @return: Converted object. + """ + if hasattr(value, 'memoryMap'): + crash = value + memoryMap = crash.memoryMap + try: + crash.memoryMap = None + if storeMemoryMap and memoryMap is not None: + # convert the generator to a list + crash.memoryMap = list(memoryMap) + if self.optimizeValues: + value = pickle.dumps(crash, protocol = HIGHEST_PROTOCOL) + value = optimize(value) + else: + value = pickle.dumps(crash, protocol = 0) + finally: + crash.memoryMap = memoryMap + del memoryMap + del crash + if self.compressValues: + value = zlib.compress(value, zlib.Z_BEST_COMPRESSION) + if self.escapeValues: + value = value.encode('hex') + if self.binaryValues: + value = buffer(value) + return value + + def unmarshall_value(self, value): + """ + Unmarshalls a Crash object read from the database. + + @type value: str + @param value: Object to convert. + + @rtype: L{Crash} + @return: Converted object. + """ + value = str(value) + if self.escapeValues: + value = value.decode('hex') + if self.compressValues: + value = zlib.decompress(value) + value = pickle.loads(value) + return value + + # The interface is meant to be similar to a Python set. + # However it may not be necessary to implement all of the set methods. + # Other methods like get, has_key, iterkeys and itervalues + # are dictionary-like. + + def __len__(self): + """ + @rtype: int + @return: Count of known keys. + """ + return len(self.__keys) + + def __bool__(self): + """ + @rtype: bool + @return: C{False} if there are no known keys. + """ + return bool(self.__keys) + + def __contains__(self, crash): + """ + @type crash: L{Crash} + @param crash: Crash object. + + @rtype: bool + @return: + C{True} if a Crash object with the same key is in the container. + """ + return self.has_key( crash.key() ) + + def has_key(self, key): + """ + @type key: L{Crash} key. + @param key: Key to find. + + @rtype: bool + @return: C{True} if the key is present in the set of known keys. + """ + return key in self.__keys + + def iterkeys(self): + """ + @rtype: iterator + @return: Iterator of known L{Crash} keys. + """ + return compat.iterkeys(self.__keys) + + class __CrashContainerIterator (object): + """ + Iterator of Crash objects. Returned by L{CrashContainer.__iter__}. + """ + + def __init__(self, container): + """ + @type container: L{CrashContainer} + @param container: Crash set to iterate. + """ + # It's important to keep a reference to the CrashContainer, + # rather than it's underlying database. + # Otherwise the destructor of CrashContainer may close the + # database while we're still iterating it. + # + # TODO: lock the database when iterating it. + # + self.__container = container + self.__keys_iter = compat.iterkeys(container) + + def next(self): + """ + @rtype: L{Crash} + @return: A B{copy} of a Crash object in the L{CrashContainer}. + @raise StopIteration: No more items left. + """ + key = self.__keys_iter.next() + return self.__container.get(key) + + def __del__(self): + "Class destructor. Closes the database when this object is destroyed." + try: + if self.__filename: + self.__db.close() + except: + pass + + def __iter__(self): + """ + @see: L{itervalues} + @rtype: iterator + @return: Iterator of the contained L{Crash} objects. + """ + return self.itervalues() + + def itervalues(self): + """ + @rtype: iterator + @return: Iterator of the contained L{Crash} objects. + + @warning: A B{copy} of each object is returned, + so any changes made to them will be lost. + + To preserve changes do the following: + 1. Keep a reference to the object. + 2. Delete the object from the set. + 3. Modify the object and add it again. + """ + return self.__CrashContainerIterator(self) + + def add(self, crash): + """ + Adds a new crash to the container. + If the crash appears to be already known, it's ignored. + + @see: L{Crash.key} + + @type crash: L{Crash} + @param crash: Crash object to add. + """ + if crash not in self: + key = crash.key() + skey = self.marshall_key(key) + data = self.marshall_value(crash, storeMemoryMap = True) + self.__db[skey] = data + + def __delitem__(self, key): + """ + Removes a crash from the container. + + @type key: L{Crash} unique key. + @param key: Key of the crash to get. + """ + skey = self.marshall_key(key) + del self.__db[skey] + self.remove_key(key) + + def remove(self, crash): + """ + Removes a crash from the container. + + @type crash: L{Crash} + @param crash: Crash object to remove. + """ + del self[ crash.key() ] + + def get(self, key): + """ + Retrieves a crash from the container. + + @type key: L{Crash} unique key. + @param key: Key of the crash to get. + + @rtype: L{Crash} object. + @return: Crash matching the given key. + + @see: L{iterkeys} + @warning: A B{copy} of each object is returned, + so any changes made to them will be lost. + + To preserve changes do the following: + 1. Keep a reference to the object. + 2. Delete the object from the set. + 3. Modify the object and add it again. + """ + skey = self.marshall_key(key) + data = self.__db[skey] + crash = self.unmarshall_value(data) + return crash + + def __getitem__(self, key): + """ + Retrieves a crash from the container. + + @type key: L{Crash} unique key. + @param key: Key of the crash to get. + + @rtype: L{Crash} object. + @return: Crash matching the given key. + + @see: L{iterkeys} + @warning: A B{copy} of each object is returned, + so any changes made to them will be lost. + + To preserve changes do the following: + 1. Keep a reference to the object. + 2. Delete the object from the set. + 3. Modify the object and add it again. + """ + return self.get(key) + +#============================================================================== + +class CrashDictionary(object): + """ + Dictionary-like persistence interface for L{Crash} objects. + + Currently the only implementation is through L{sql.CrashDAO}. + """ + + def __init__(self, url, creator = None, allowRepeatedKeys = True): + """ + @type url: str + @param url: Connection URL of the crash database. + See L{sql.CrashDAO.__init__} for more details. + + @type creator: callable + @param creator: (Optional) Callback function that creates the SQL + database connection. + + Normally it's not necessary to use this argument. However in some + odd cases you may need to customize the database connection, for + example when using the integrated authentication in MSSQL. + + @type allowRepeatedKeys: bool + @param allowRepeatedKeys: + If C{True} all L{Crash} objects are stored. + + If C{False} any L{Crash} object with the same signature as a + previously existing object will be ignored. + """ + global sql + if sql is None: + from winappdbg import sql + self._allowRepeatedKeys = allowRepeatedKeys + self._dao = sql.CrashDAO(url, creator) + + def add(self, crash): + """ + Adds a new crash to the container. + + @note: + When the C{allowRepeatedKeys} parameter of the constructor + is set to C{False}, duplicated crashes are ignored. + + @see: L{Crash.key} + + @type crash: L{Crash} + @param crash: Crash object to add. + """ + self._dao.add(crash, self._allowRepeatedKeys) + + def get(self, key): + """ + Retrieves a crash from the container. + + @type key: L{Crash} signature. + @param key: Heuristic signature of the crash to get. + + @rtype: L{Crash} object. + @return: Crash matching the given signature. If more than one is found, + retrieve the newest one. + + @see: L{iterkeys} + @warning: A B{copy} of each object is returned, + so any changes made to them will be lost. + + To preserve changes do the following: + 1. Keep a reference to the object. + 2. Delete the object from the set. + 3. Modify the object and add it again. + """ + found = self._dao.find(signature=key, limit=1, order=-1) + if not found: + raise KeyError(key) + return found[0] + + def __iter__(self): + """ + @rtype: iterator + @return: Iterator of the contained L{Crash} objects. + """ + offset = 0 + limit = 10 + while 1: + found = self._dao.find(offset=offset, limit=limit) + if not found: + break + offset += len(found) + for crash in found: + yield crash + + def itervalues(self): + """ + @rtype: iterator + @return: Iterator of the contained L{Crash} objects. + """ + return self.__iter__() + + def iterkeys(self): + """ + @rtype: iterator + @return: Iterator of the contained L{Crash} heuristic signatures. + """ + for crash in self: + yield crash.signature # FIXME this gives repeated results! + + def __contains__(self, crash): + """ + @type crash: L{Crash} + @param crash: Crash object. + + @rtype: bool + @return: C{True} if the Crash object is in the container. + """ + return self._dao.count(signature=crash.signature) > 0 + + def has_key(self, key): + """ + @type key: L{Crash} signature. + @param key: Heuristic signature of the crash to get. + + @rtype: bool + @return: C{True} if a matching L{Crash} object is in the container. + """ + return self._dao.count(signature=key) > 0 + + def __len__(self): + """ + @rtype: int + @return: Count of L{Crash} elements in the container. + """ + return self._dao.count() + + def __bool__(self): + """ + @rtype: bool + @return: C{False} if the container is empty. + """ + return bool( len(self) ) + +class CrashTable(CrashDictionary): + """ + Old crash dump persistencer using a SQLite database. + + @warning: + Superceded by L{CrashDictionary} since WinAppDbg 1.5. + New applications should not use this class. + """ + + def __init__(self, location = None, allowRepeatedKeys = True): + """ + @type location: str + @param location: (Optional) Location of the crash database. + If the location is a filename, it's an SQLite database file. + + If no location is specified, the container is volatile. + Volatile containers are stored only in memory and + destroyed when they go out of scope. + + @type allowRepeatedKeys: bool + @param allowRepeatedKeys: + If C{True} all L{Crash} objects are stored. + + If C{False} any L{Crash} object with the same signature as a + previously existing object will be ignored. + """ + warnings.warn( + "The %s class is deprecated since WinAppDbg 1.5." % self.__class__, + DeprecationWarning) + if location: + url = "sqlite:///%s" % location + else: + url = "sqlite://" + super(CrashTable, self).__init__(url, allowRepeatedKeys) + +class CrashTableMSSQL (CrashDictionary): + """ + Old crash dump persistencer using a Microsoft SQL Server database. + + @warning: + Superceded by L{CrashDictionary} since WinAppDbg 1.5. + New applications should not use this class. + """ + + def __init__(self, location = None, allowRepeatedKeys = True): + """ + @type location: str + @param location: Location of the crash database. + It must be an ODBC connection string. + + @type allowRepeatedKeys: bool + @param allowRepeatedKeys: + If C{True} all L{Crash} objects are stored. + + If C{False} any L{Crash} object with the same signature as a + previously existing object will be ignored. + """ + warnings.warn( + "The %s class is deprecated since WinAppDbg 1.5." % self.__class__, + DeprecationWarning) + import urllib + url = "mssql+pyodbc:///?odbc_connect=" + urllib.quote_plus(location) + super(CrashTableMSSQL, self).__init__(url, allowRepeatedKeys) + +class VolatileCrashContainer (CrashTable): + """ + Old in-memory crash dump storage. + + @warning: + Superceded by L{CrashDictionary} since WinAppDbg 1.5. + New applications should not use this class. + """ + + def __init__(self, allowRepeatedKeys = True): + """ + Volatile containers are stored only in memory and + destroyed when they go out of scope. + + @type allowRepeatedKeys: bool + @param allowRepeatedKeys: + If C{True} all L{Crash} objects are stored. + + If C{False} any L{Crash} object with the same key as a + previously existing object will be ignored. + """ + super(VolatileCrashContainer, self).__init__( + allowRepeatedKeys=allowRepeatedKeys) + +class DummyCrashContainer(object): + """ + Fakes a database of volatile Crash objects, + trying to mimic part of it's interface, but + doesn't actually store anything. + + Normally applications don't need to use this. + + @see: L{CrashDictionary} + """ + + def __init__(self, allowRepeatedKeys = True): + """ + Fake containers don't store L{Crash} objects, but they implement the + interface properly. + + @type allowRepeatedKeys: bool + @param allowRepeatedKeys: + Mimics the duplicate filter behavior found in real containers. + """ + self.__keys = set() + self.__count = 0 + self.__allowRepeatedKeys = allowRepeatedKeys + + def __contains__(self, crash): + """ + @type crash: L{Crash} + @param crash: Crash object. + + @rtype: bool + @return: C{True} if the Crash object is in the container. + """ + return crash.signature in self.__keys + + def __len__(self): + """ + @rtype: int + @return: Count of L{Crash} elements in the container. + """ + if self.__allowRepeatedKeys: + return self.__count + return len( self.__keys ) + + def __bool__(self): + """ + @rtype: bool + @return: C{False} if the container is empty. + """ + return bool( len(self) ) + + def add(self, crash): + """ + Adds a new crash to the container. + + @note: + When the C{allowRepeatedKeys} parameter of the constructor + is set to C{False}, duplicated crashes are ignored. + + @see: L{Crash.key} + + @type crash: L{Crash} + @param crash: Crash object to add. + """ + self.__keys.add( crash.signature ) + self.__count += 1 + + def get(self, key): + """ + This method is not supported. + """ + raise NotImplementedError() + + def has_key(self, key): + """ + @type key: L{Crash} signature. + @param key: Heuristic signature of the crash to get. + + @rtype: bool + @return: C{True} if a matching L{Crash} object is in the container. + """ + return self.__keys.has_key( key ) + + def iterkeys(self): + """ + @rtype: iterator + @return: Iterator of the contained L{Crash} object keys. + + @see: L{get} + @warning: A B{copy} of each object is returned, + so any changes made to them will be lost. + + To preserve changes do the following: + 1. Keep a reference to the object. + 2. Delete the object from the set. + 3. Modify the object and add it again. + """ + return iter(self.__keys) + +#============================================================================== +# Register the Crash class with the secure serializer. + +try: + cerealizer.register(Crash) + cerealizer.register(win32.MemoryBasicInformation) +except NameError: + pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/debug.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/debug.py new file mode 100644 index 0000000..8364a5b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/debug.py @@ -0,0 +1,1543 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Debugging. + +@group Debugging: + Debug + +@group Warnings: + MixedBitsWarning +""" + +__revision__ = "$Id$" + +__all__ = [ 'Debug', 'MixedBitsWarning' ] + +import sys +from winappdbg import win32 +from winappdbg.system import System +from winappdbg.process import Process +from winappdbg.thread import Thread +from winappdbg.module import Module +from winappdbg.window import Window +from winappdbg.breakpoint import _BreakpointContainer, CodeBreakpoint +from winappdbg.event import Event, EventHandler, EventDispatcher, EventFactory +from winappdbg.interactive import ConsoleDebugger + +import warnings +##import traceback + +#============================================================================== + +# If you set this warning to be considered as an error, you can stop the +# debugger from attaching to 64-bit processes from a 32-bit Python VM and +# visceversa. +class MixedBitsWarning (RuntimeWarning): + """ + This warning is issued when mixing 32 and 64 bit processes. + """ + +#============================================================================== + +# TODO +# * Add memory read and write operations, similar to those in the Process +# class, but hiding the presence of the code breakpoints. +# * Add a method to get the memory map of a process, but hiding the presence +# of the page breakpoints. +# * Maybe the previous two features should be implemented at the Process class +# instead, but how to communicate with the Debug object without creating +# circular references? Perhaps the "overrides" could be set using private +# members (so users won't see them), but then there's the problem of the +# users being able to access the snapshot (i.e. clear it), which is why it's +# not such a great idea to use the snapshot to store data that really belongs +# to the Debug class. + +class Debug (EventDispatcher, _BreakpointContainer): + """ + The main debugger class. + + @group Debugging: + interactive, attach, detach, detach_from_all, execv, execl, + kill, kill_all, + get_debugee_count, get_debugee_pids, + is_debugee, is_debugee_attached, is_debugee_started, + in_hostile_mode, + add_existing_session + + @group Debugging loop: + loop, stop, next, wait, dispatch, cont + + @undocumented: force_garbage_collection + + @type system: L{System} + @ivar system: A System snapshot that is automatically updated for + processes being debugged. Processes not being debugged in this snapshot + may be outdated. + """ + + # Automatically set to True the first time a Debug object is instanced. + _debug_static_init = False + + def __init__(self, eventHandler = None, bKillOnExit = False, + bHostileCode = False): + """ + Debugger object. + + @type eventHandler: L{EventHandler} + @param eventHandler: + (Optional, recommended) Custom event handler object. + + @type bKillOnExit: bool + @param bKillOnExit: (Optional) Kill on exit mode. + If C{True} debugged processes are killed when the debugger is + stopped. If C{False} when the debugger stops it detaches from all + debugged processes and leaves them running (default). + + @type bHostileCode: bool + @param bHostileCode: (Optional) Hostile code mode. + Set to C{True} to take some basic precautions against anti-debug + tricks. Disabled by default. + + @warn: When hostile mode is enabled, some things may not work as + expected! This is because the anti-anti debug tricks may disrupt + the behavior of the Win32 debugging APIs or WinAppDbg itself. + + @note: The L{eventHandler} parameter may be any callable Python object + (for example a function, or an instance method). + However you'll probably find it more convenient to use an instance + of a subclass of L{EventHandler} here. + + @raise WindowsError: Raises an exception on error. + """ + EventDispatcher.__init__(self, eventHandler) + _BreakpointContainer.__init__(self) + + self.system = System() + self.lastEvent = None + self.__firstDebugee = True + self.__bKillOnExit = bKillOnExit + self.__bHostileCode = bHostileCode + self.__breakOnEP = set() # set of pids + self.__attachedDebugees = set() # set of pids + self.__startedDebugees = set() # set of pids + + if not self._debug_static_init: + self._debug_static_init = True + + # Request debug privileges for the current process. + # Only do this once, and only after instancing a Debug object, + # so passive debuggers don't get detected because of this. + self.system.request_debug_privileges(bIgnoreExceptions = False) + + # Try to fix the symbol store path if it wasn't set. + # But don't enable symbol downloading by default, since it may + # degrade performance severely. + self.system.fix_symbol_store_path(remote = False, force = False) + +## # It's hard not to create circular references, +## # and if we have a destructor, we can end up leaking everything. +## # It's best to code the debugging loop properly to always +## # stop the debugger before going out of scope. +## def __del__(self): +## self.stop() + + def __enter__(self): + """ + Compatibility with the "C{with}" Python statement. + """ + return self + + def __exit__(self, type, value, traceback): + """ + Compatibility with the "C{with}" Python statement. + """ + self.stop() + + def __len__(self): + """ + @rtype: int + @return: Number of processes being debugged. + """ + return self.get_debugee_count() + + # TODO: maybe custom __bool__ to break out of loop() ? + # it already does work (because of __len__) but it'd be + # useful to do it from the event handler anyway + +#------------------------------------------------------------------------------ + + def __setSystemKillOnExitMode(self): + # Make sure the default system behavior on detaching from processes + # versus killing them matches our preferences. This only affects the + # scenario where the Python VM dies unexpectedly without running all + # the finally clauses, or the user failed to either instance the Debug + # object inside a with block or call the stop() method before quitting. + if self.__firstDebugee: + try: + System.set_kill_on_exit_mode(self.__bKillOnExit) + self.__firstDebugee = False + except Exception: + pass + + def attach(self, dwProcessId): + """ + Attaches to an existing process for debugging. + + @see: L{detach}, L{execv}, L{execl} + + @type dwProcessId: int + @param dwProcessId: Global ID of a process to attach to. + + @rtype: L{Process} + @return: A new Process object. Normally you don't need to use it now, + it's best to interact with the process from the event handler. + + @raise WindowsError: Raises an exception on error. + Depending on the circumstances, the debugger may or may not have + attached to the target process. + """ + + # Get the Process object from the snapshot, + # if missing create a new one. + try: + aProcess = self.system.get_process(dwProcessId) + except KeyError: + aProcess = Process(dwProcessId) + + # Warn when mixing 32 and 64 bits. + # This also allows the user to stop attaching altogether, + # depending on how the warnings are configured. + if System.bits != aProcess.get_bits(): + msg = "Mixture of 32 and 64 bits is considered experimental." \ + " Use at your own risk!" + warnings.warn(msg, MixedBitsWarning) + + # Attach to the process. + win32.DebugActiveProcess(dwProcessId) + + # Add the new PID to the set of debugees. + self.__attachedDebugees.add(dwProcessId) + + # Match the system kill-on-exit flag to our own. + self.__setSystemKillOnExitMode() + + # If the Process object was not in the snapshot, add it now. + if not self.system.has_process(dwProcessId): + self.system._add_process(aProcess) + + # Scan the process threads and loaded modules. + # This is prefered because the thread and library events do not + # properly give some information, like the filename for each module. + aProcess.scan_threads() + aProcess.scan_modules() + + # Return the Process object, like the execv() and execl() methods. + return aProcess + + def execv(self, argv, **kwargs): + """ + Starts a new process for debugging. + + This method uses a list of arguments. To use a command line string + instead, use L{execl}. + + @see: L{attach}, L{detach} + + @type argv: list( str... ) + @param argv: List of command line arguments to pass to the debugee. + The first element must be the debugee executable filename. + + @type bBreakOnEntryPoint: bool + @keyword bBreakOnEntryPoint: C{True} to automatically set a breakpoint + at the program entry point. + + @type bConsole: bool + @keyword bConsole: True to inherit the console of the debugger. + Defaults to C{False}. + + @type bFollow: bool + @keyword bFollow: C{True} to automatically attach to child processes. + Defaults to C{False}. + + @type bInheritHandles: bool + @keyword bInheritHandles: C{True} if the new process should inherit + it's parent process' handles. Defaults to C{False}. + + @type bSuspended: bool + @keyword bSuspended: C{True} to suspend the main thread before any code + is executed in the debugee. Defaults to C{False}. + + @keyword dwParentProcessId: C{None} or C{0} if the debugger process + should be the parent process (default), or a process ID to + forcefully set as the debugee's parent (only available for Windows + Vista and above). + + In hostile mode, the default is not the debugger process but the + process ID for "explorer.exe". + + @type iTrustLevel: int or None + @keyword iTrustLevel: Trust level. + Must be one of the following values: + - 0: B{No trust}. May not access certain resources, such as + cryptographic keys and credentials. Only available since + Windows XP and 2003, desktop editions. This is the default + in hostile mode. + - 1: B{Normal trust}. Run with the same privileges as a normal + user, that is, one that doesn't have the I{Administrator} or + I{Power User} user rights. Only available since Windows XP + and 2003, desktop editions. + - 2: B{Full trust}. Run with the exact same privileges as the + current user. This is the default in normal mode. + + @type bAllowElevation: bool + @keyword bAllowElevation: C{True} to allow the child process to keep + UAC elevation, if the debugger itself is running elevated. C{False} + to ensure the child process doesn't run with elevation. Defaults to + C{True}. + + This flag is only meaningful on Windows Vista and above, and if the + debugger itself is running with elevation. It can be used to make + sure the child processes don't run elevated as well. + + This flag DOES NOT force an elevation prompt when the debugger is + not running with elevation. + + Note that running the debugger with elevation (or the Python + interpreter at all for that matter) is not normally required. + You should only need to if the target program requires elevation + to work properly (for example if you try to debug an installer). + + @rtype: L{Process} + @return: A new Process object. Normally you don't need to use it now, + it's best to interact with the process from the event handler. + + @raise WindowsError: Raises an exception on error. + """ + if type(argv) in (str, compat.unicode): + raise TypeError("Debug.execv expects a list, not a string") + lpCmdLine = self.system.argv_to_cmdline(argv) + return self.execl(lpCmdLine, **kwargs) + + def execl(self, lpCmdLine, **kwargs): + """ + Starts a new process for debugging. + + This method uses a command line string. To use a list of arguments + instead, use L{execv}. + + @see: L{attach}, L{detach} + + @type lpCmdLine: str + @param lpCmdLine: Command line string to execute. + The first token must be the debugee executable filename. + Tokens with spaces must be enclosed in double quotes. + Tokens including double quote characters must be escaped with a + backslash. + + @type bBreakOnEntryPoint: bool + @keyword bBreakOnEntryPoint: C{True} to automatically set a breakpoint + at the program entry point. Defaults to C{False}. + + @type bConsole: bool + @keyword bConsole: True to inherit the console of the debugger. + Defaults to C{False}. + + @type bFollow: bool + @keyword bFollow: C{True} to automatically attach to child processes. + Defaults to C{False}. + + @type bInheritHandles: bool + @keyword bInheritHandles: C{True} if the new process should inherit + it's parent process' handles. Defaults to C{False}. + + @type bSuspended: bool + @keyword bSuspended: C{True} to suspend the main thread before any code + is executed in the debugee. Defaults to C{False}. + + @type dwParentProcessId: int or None + @keyword dwParentProcessId: C{None} or C{0} if the debugger process + should be the parent process (default), or a process ID to + forcefully set as the debugee's parent (only available for Windows + Vista and above). + + In hostile mode, the default is not the debugger process but the + process ID for "explorer.exe". + + @type iTrustLevel: int + @keyword iTrustLevel: Trust level. + Must be one of the following values: + - 0: B{No trust}. May not access certain resources, such as + cryptographic keys and credentials. Only available since + Windows XP and 2003, desktop editions. This is the default + in hostile mode. + - 1: B{Normal trust}. Run with the same privileges as a normal + user, that is, one that doesn't have the I{Administrator} or + I{Power User} user rights. Only available since Windows XP + and 2003, desktop editions. + - 2: B{Full trust}. Run with the exact same privileges as the + current user. This is the default in normal mode. + + @type bAllowElevation: bool + @keyword bAllowElevation: C{True} to allow the child process to keep + UAC elevation, if the debugger itself is running elevated. C{False} + to ensure the child process doesn't run with elevation. Defaults to + C{True} in normal mode and C{False} in hostile mode. + + This flag is only meaningful on Windows Vista and above, and if the + debugger itself is running with elevation. It can be used to make + sure the child processes don't run elevated as well. + + This flag DOES NOT force an elevation prompt when the debugger is + not running with elevation. + + Note that running the debugger with elevation (or the Python + interpreter at all for that matter) is not normally required. + You should only need to if the target program requires elevation + to work properly (for example if you try to debug an installer). + + @rtype: L{Process} + @return: A new Process object. Normally you don't need to use it now, + it's best to interact with the process from the event handler. + + @raise WindowsError: Raises an exception on error. + """ + if type(lpCmdLine) not in (str, compat.unicode): + warnings.warn("Debug.execl expects a string") + + # Set the "debug" flag to True. + kwargs['bDebug'] = True + + # Pop the "break on entry point" flag. + bBreakOnEntryPoint = kwargs.pop('bBreakOnEntryPoint', False) + + # Set the default trust level if requested. + if 'iTrustLevel' not in kwargs: + if self.__bHostileCode: + kwargs['iTrustLevel'] = 0 + else: + kwargs['iTrustLevel'] = 2 + + # Set the default UAC elevation flag if requested. + if 'bAllowElevation' not in kwargs: + kwargs['bAllowElevation'] = not self.__bHostileCode + + # In hostile mode the default parent process is explorer.exe. + # Only supported for Windows Vista and above. + if self.__bHostileCode and not kwargs.get('dwParentProcessId', None): + try: + vista_and_above = self.__vista_and_above + except AttributeError: + osi = win32.OSVERSIONINFOEXW() + osi.dwMajorVersion = 6 + osi.dwMinorVersion = 0 + osi.dwPlatformId = win32.VER_PLATFORM_WIN32_NT + mask = 0 + mask = win32.VerSetConditionMask(mask, + win32.VER_MAJORVERSION, + win32.VER_GREATER_EQUAL) + mask = win32.VerSetConditionMask(mask, + win32.VER_MAJORVERSION, + win32.VER_GREATER_EQUAL) + mask = win32.VerSetConditionMask(mask, + win32.VER_PLATFORMID, + win32.VER_EQUAL) + vista_and_above = win32.VerifyVersionInfoW(osi, + win32.VER_MAJORVERSION | \ + win32.VER_MINORVERSION | \ + win32.VER_PLATFORMID, + mask) + self.__vista_and_above = vista_and_above + if vista_and_above: + dwParentProcessId = self.system.get_explorer_pid() + if dwParentProcessId: + kwargs['dwParentProcessId'] = dwParentProcessId + else: + msg = ("Failed to find \"explorer.exe\"!" + " Using the debugger as parent process.") + warnings.warn(msg, RuntimeWarning) + + # Start the new process. + aProcess = None + try: + aProcess = self.system.start_process(lpCmdLine, **kwargs) + dwProcessId = aProcess.get_pid() + + # Match the system kill-on-exit flag to our own. + self.__setSystemKillOnExitMode() + + # Warn when mixing 32 and 64 bits. + # This also allows the user to stop attaching altogether, + # depending on how the warnings are configured. + if System.bits != aProcess.get_bits(): + msg = "Mixture of 32 and 64 bits is considered experimental." \ + " Use at your own risk!" + warnings.warn(msg, MixedBitsWarning) + + # Add the new PID to the set of debugees. + self.__startedDebugees.add(dwProcessId) + + # Add the new PID to the set of "break on EP" debugees if needed. + if bBreakOnEntryPoint: + self.__breakOnEP.add(dwProcessId) + + # Return the Process object. + return aProcess + + # On error kill the new process and raise an exception. + except: + if aProcess is not None: + try: + try: + self.__startedDebugees.remove(aProcess.get_pid()) + except KeyError: + pass + finally: + try: + try: + self.__breakOnEP.remove(aProcess.get_pid()) + except KeyError: + pass + finally: + try: + aProcess.kill() + except Exception: + pass + raise + + def add_existing_session(self, dwProcessId, bStarted = False): + """ + Use this method only when for some reason the debugger's been attached + to the target outside of WinAppDbg (for example when integrating with + other tools). + + You don't normally need to call this method. Most users should call + L{attach}, L{execv} or L{execl} instead. + + @type dwProcessId: int + @param dwProcessId: Global process ID. + + @type bStarted: bool + @param bStarted: C{True} if the process was started by the debugger, + or C{False} if the process was attached to instead. + + @raise WindowsError: The target process does not exist, is not attached + to the debugger anymore. + """ + + # Register the process object with the snapshot. + if not self.system.has_process(dwProcessId): + aProcess = Process(dwProcessId) + self.system._add_process(aProcess) + else: + aProcess = self.system.get_process(dwProcessId) + + # Test for debug privileges on the target process. + # Raises WindowsException on error. + aProcess.get_handle() + + # Register the process ID with the debugger. + if bStarted: + self.__attachedDebugees.add(dwProcessId) + else: + self.__startedDebugees.add(dwProcessId) + + # Match the system kill-on-exit flag to our own. + self.__setSystemKillOnExitMode() + + # Scan the process threads and loaded modules. + # This is prefered because the thread and library events do not + # properly give some information, like the filename for each module. + aProcess.scan_threads() + aProcess.scan_modules() + + def __cleanup_process(self, dwProcessId, bIgnoreExceptions = False): + """ + Perform the necessary cleanup of a process about to be killed or + detached from. + + This private method is called by L{kill} and L{detach}. + + @type dwProcessId: int + @param dwProcessId: Global ID of a process to kill. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when killing the process. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + # If the process is being debugged... + if self.is_debugee(dwProcessId): + + # Make sure a Process object exists or the following calls fail. + if not self.system.has_process(dwProcessId): + aProcess = Process(dwProcessId) + try: + aProcess.get_handle() + except WindowsError: + pass # fails later on with more specific reason + self.system._add_process(aProcess) + + # Erase all breakpoints in the process. + try: + self.erase_process_breakpoints(dwProcessId) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Stop tracing all threads in the process. + try: + self.stop_tracing_process(dwProcessId) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # The process is no longer a debugee. + try: + if dwProcessId in self.__attachedDebugees: + self.__attachedDebugees.remove(dwProcessId) + if dwProcessId in self.__startedDebugees: + self.__startedDebugees.remove(dwProcessId) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Clear and remove the process from the snapshot. + # If the user wants to do something with it after detaching + # a new Process instance should be created. + try: + if self.system.has_process(dwProcessId): + try: + self.system.get_process(dwProcessId).clear() + finally: + self.system._del_process(dwProcessId) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # If the last debugging event is related to this process, forget it. + try: + if self.lastEvent and self.lastEvent.get_pid() == dwProcessId: + self.lastEvent = None + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + def kill(self, dwProcessId, bIgnoreExceptions = False): + """ + Kills a process currently being debugged. + + @see: L{detach} + + @type dwProcessId: int + @param dwProcessId: Global ID of a process to kill. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when killing the process. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + + # Keep a reference to the process. We'll need it later. + try: + aProcess = self.system.get_process(dwProcessId) + except KeyError: + aProcess = Process(dwProcessId) + + # Cleanup all data referring to the process. + self.__cleanup_process(dwProcessId, + bIgnoreExceptions = bIgnoreExceptions) + + # Kill the process. + try: + try: + if self.is_debugee(dwProcessId): + try: + if aProcess.is_alive(): + aProcess.suspend() + finally: + self.detach(dwProcessId, + bIgnoreExceptions = bIgnoreExceptions) + finally: + aProcess.kill() + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Cleanup what remains of the process data. + try: + aProcess.clear() + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + def kill_all(self, bIgnoreExceptions = False): + """ + Kills from all processes currently being debugged. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when killing each process. C{False} to stop and raise an + exception when encountering an error. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + for pid in self.get_debugee_pids(): + self.kill(pid, bIgnoreExceptions = bIgnoreExceptions) + + def detach(self, dwProcessId, bIgnoreExceptions = False): + """ + Detaches from a process currently being debugged. + + @note: On Windows 2000 and below the process is killed. + + @see: L{attach}, L{detach_from_all} + + @type dwProcessId: int + @param dwProcessId: Global ID of a process to detach from. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when detaching. C{False} to stop and raise an exception when + encountering an error. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + + # Keep a reference to the process. We'll need it later. + try: + aProcess = self.system.get_process(dwProcessId) + except KeyError: + aProcess = Process(dwProcessId) + + # Determine if there is support for detaching. + # This check should only fail on Windows 2000 and older. + try: + win32.DebugActiveProcessStop + can_detach = True + except AttributeError: + can_detach = False + + # Continue the last event before detaching. + # XXX not sure about this... + try: + if can_detach and self.lastEvent and \ + self.lastEvent.get_pid() == dwProcessId: + self.cont(self.lastEvent) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Cleanup all data referring to the process. + self.__cleanup_process(dwProcessId, + bIgnoreExceptions = bIgnoreExceptions) + + try: + # Detach from the process. + # On Windows 2000 and before, kill the process. + if can_detach: + try: + win32.DebugActiveProcessStop(dwProcessId) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + else: + try: + aProcess.kill() + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + finally: + + # Cleanup what remains of the process data. + aProcess.clear() + + def detach_from_all(self, bIgnoreExceptions = False): + """ + Detaches from all processes currently being debugged. + + @note: To better handle last debugging event, call L{stop} instead. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when detaching. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + for pid in self.get_debugee_pids(): + self.detach(pid, bIgnoreExceptions = bIgnoreExceptions) + +#------------------------------------------------------------------------------ + + def wait(self, dwMilliseconds = None): + """ + Waits for the next debug event. + + @see: L{cont}, L{dispatch}, L{loop} + + @type dwMilliseconds: int + @param dwMilliseconds: (Optional) Timeout in milliseconds. + Use C{INFINITE} or C{None} for no timeout. + + @rtype: L{Event} + @return: An event that occured in one of the debugees. + + @raise WindowsError: Raises an exception on error. + If no target processes are left to debug, + the error code is L{win32.ERROR_INVALID_HANDLE}. + """ + + # Wait for the next debug event. + raw = win32.WaitForDebugEvent(dwMilliseconds) + event = EventFactory.get(self, raw) + + # Remember it. + self.lastEvent = event + + # Return it. + return event + + def dispatch(self, event = None): + """ + Calls the debug event notify callbacks. + + @see: L{cont}, L{loop}, L{wait} + + @type event: L{Event} + @param event: (Optional) Event object returned by L{wait}. + + @raise WindowsError: Raises an exception on error. + """ + + # If no event object was given, use the last event. + if event is None: + event = self.lastEvent + + # Ignore dummy events. + if not event: + return + + # Determine the default behaviour for this event. + # XXX HACK + # Some undocumented flags are used, but as far as I know in those + # versions of Windows that don't support them they should behave + # like DGB_CONTINUE. + + code = event.get_event_code() + if code == win32.EXCEPTION_DEBUG_EVENT: + + # At this point, by default some exception types are swallowed by + # the debugger, because we don't know yet if it was caused by the + # debugger itself or the debugged process. + # + # Later on (see breakpoint.py) if we determined the exception was + # not caused directly by the debugger itself, we set the default + # back to passing the exception to the debugee. + # + # The "invalid handle" exception is also swallowed by the debugger + # because it's not normally generated by the debugee. But in + # hostile mode we want to pass it to the debugee, as it may be the + # result of an anti-debug trick. In that case it's best to disable + # bad handles detection with Microsoft's gflags.exe utility. See: + # http://msdn.microsoft.com/en-us/library/windows/hardware/ff549557(v=vs.85).aspx + + exc_code = event.get_exception_code() + if exc_code in ( + win32.EXCEPTION_BREAKPOINT, + win32.EXCEPTION_WX86_BREAKPOINT, + win32.EXCEPTION_SINGLE_STEP, + win32.EXCEPTION_GUARD_PAGE, + ): + event.continueStatus = win32.DBG_CONTINUE + elif exc_code == win32.EXCEPTION_INVALID_HANDLE: + if self.__bHostileCode: + event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + else: + event.continueStatus = win32.DBG_CONTINUE + else: + event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + + elif code == win32.RIP_EVENT and \ + event.get_rip_type() == win32.SLE_ERROR: + + # RIP events that signal fatal events should kill the process. + event.continueStatus = win32.DBG_TERMINATE_PROCESS + + else: + + # Other events need this continue code. + # Sometimes other codes can be used and are ignored, sometimes not. + # For example, when using the DBG_EXCEPTION_NOT_HANDLED code, + # debug strings are sent twice (!) + event.continueStatus = win32.DBG_CONTINUE + + # Dispatch the debug event. + return EventDispatcher.dispatch(self, event) + + def cont(self, event = None): + """ + Resumes execution after processing a debug event. + + @see: dispatch(), loop(), wait() + + @type event: L{Event} + @param event: (Optional) Event object returned by L{wait}. + + @raise WindowsError: Raises an exception on error. + """ + + # If no event object was given, use the last event. + if event is None: + event = self.lastEvent + + # Ignore dummy events. + if not event: + return + + # Get the event continue status information. + dwProcessId = event.get_pid() + dwThreadId = event.get_tid() + dwContinueStatus = event.continueStatus + + # Check if the process is still being debugged. + if self.is_debugee(dwProcessId): + + # Try to flush the instruction cache. + try: + if self.system.has_process(dwProcessId): + aProcess = self.system.get_process(dwProcessId) + else: + aProcess = Process(dwProcessId) + aProcess.flush_instruction_cache() + except WindowsError: + pass + + # XXX TODO + # + # Try to execute the UnhandledExceptionFilter for second chance + # exceptions, at least when in hostile mode (in normal mode it + # would be breaking compatibility, as users may actually expect + # second chance exceptions to be raised again). + # + # Reportedly in Windows 7 (maybe in Vista too) this seems to be + # happening already. In XP and below the UnhandledExceptionFilter + # was never called for processes being debugged. + + # Continue execution of the debugee. + win32.ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus) + + # If the event is the last event, forget it. + if event == self.lastEvent: + self.lastEvent = None + + def stop(self, bIgnoreExceptions = True): + """ + Stops debugging all processes. + + If the kill on exit mode is on, debugged processes are killed when the + debugger is stopped. Otherwise when the debugger stops it detaches from + all debugged processes and leaves them running (default). For more + details see: L{__init__} + + @note: This method is better than L{detach_from_all} because it can + gracefully handle the last debugging event before detaching. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when detaching. + """ + + # Determine if we have a last debug event that we need to continue. + try: + event = self.lastEvent + has_event = bool(event) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + has_event = False + + # If we do... + if has_event: + + # Disable all breakpoints in the process before resuming execution. + try: + pid = event.get_pid() + self.disable_process_breakpoints(pid) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Disable all breakpoints in the thread before resuming execution. + try: + tid = event.get_tid() + self.disable_thread_breakpoints(tid) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Resume execution. + try: + event.continueDebugEvent = win32.DBG_CONTINUE + self.cont(event) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Detach from or kill all debuggees. + try: + if self.__bKillOnExit: + self.kill_all(bIgnoreExceptions) + else: + self.detach_from_all(bIgnoreExceptions) + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Cleanup the process snapshots. + try: + self.system.clear() + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + + # Close all Win32 handles the Python garbage collector failed to close. + self.force_garbage_collection(bIgnoreExceptions) + + def next(self): + """ + Handles the next debug event. + + @see: L{cont}, L{dispatch}, L{wait}, L{stop} + + @raise WindowsError: Raises an exception on error. + + If the wait operation causes an error, debugging is stopped + (meaning all debugees are either killed or detached from). + + If the event dispatching causes an error, the event is still + continued before returning. This may happen, for example, if the + event handler raises an exception nobody catches. + """ + try: + event = self.wait() + except Exception: + self.stop() + raise + try: + self.dispatch() + finally: + self.cont() + + def loop(self): + """ + Simple debugging loop. + + This debugging loop is meant to be useful for most simple scripts. + It iterates as long as there is at least one debugee, or an exception + is raised. Multiple calls are allowed. + + This is a trivial example script:: + import sys + debug = Debug() + try: + debug.execv( sys.argv [ 1 : ] ) + debug.loop() + finally: + debug.stop() + + @see: L{next}, L{stop} + + U{http://msdn.microsoft.com/en-us/library/ms681675(VS.85).aspx} + + @raise WindowsError: Raises an exception on error. + + If the wait operation causes an error, debugging is stopped + (meaning all debugees are either killed or detached from). + + If the event dispatching causes an error, the event is still + continued before returning. This may happen, for example, if the + event handler raises an exception nobody catches. + """ + while self: + self.next() + + def get_debugee_count(self): + """ + @rtype: int + @return: Number of processes being debugged. + """ + return len(self.__attachedDebugees) + len(self.__startedDebugees) + + def get_debugee_pids(self): + """ + @rtype: list( int... ) + @return: Global IDs of processes being debugged. + """ + return list(self.__attachedDebugees) + list(self.__startedDebugees) + + def is_debugee(self, dwProcessId): + """ + Determine if the debugger is debugging the given process. + + @see: L{is_debugee_attached}, L{is_debugee_started} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: bool + @return: C{True} if the given process is being debugged + by this L{Debug} instance. + """ + return self.is_debugee_attached(dwProcessId) or \ + self.is_debugee_started(dwProcessId) + + def is_debugee_started(self, dwProcessId): + """ + Determine if the given process was started by the debugger. + + @see: L{is_debugee}, L{is_debugee_attached} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: bool + @return: C{True} if the given process was started for debugging by this + L{Debug} instance. + """ + return dwProcessId in self.__startedDebugees + + def is_debugee_attached(self, dwProcessId): + """ + Determine if the debugger is attached to the given process. + + @see: L{is_debugee}, L{is_debugee_started} + + @type dwProcessId: int + @param dwProcessId: Process global ID. + + @rtype: bool + @return: C{True} if the given process is attached to this + L{Debug} instance. + """ + return dwProcessId in self.__attachedDebugees + + def in_hostile_mode(self): + """ + Determine if we're in hostile mode (anti-anti-debug). + + @rtype: bool + @return: C{True} if this C{Debug} instance was started in hostile mode, + C{False} otherwise. + """ + return self.__bHostileCode + +#------------------------------------------------------------------------------ + + def interactive(self, bConfirmQuit = True, bShowBanner = True): + """ + Start an interactive debugging session. + + @type bConfirmQuit: bool + @param bConfirmQuit: Set to C{True} to ask the user for confirmation + before closing the session, C{False} otherwise. + + @type bShowBanner: bool + @param bShowBanner: Set to C{True} to show a banner before entering + the session and after leaving it, C{False} otherwise. + + @warn: This will temporarily disable the user-defined event handler! + + This method returns when the user closes the session. + """ + print('') + print("-" * 79) + print("Interactive debugging session started.") + print("Use the \"help\" command to list all available commands.") + print("Use the \"quit\" command to close this session.") + print("-" * 79) + if self.lastEvent is None: + print('') + console = ConsoleDebugger() + console.confirm_quit = bConfirmQuit + console.load_history() + try: + console.start_using_debugger(self) + console.loop() + finally: + console.stop_using_debugger() + console.save_history() + print('') + print("-" * 79) + print("Interactive debugging session closed.") + print("-" * 79) + print('') + +#------------------------------------------------------------------------------ + + @staticmethod + def force_garbage_collection(bIgnoreExceptions = True): + """ + Close all Win32 handles the Python garbage collector failed to close. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when detaching. + """ + try: + import gc + gc.collect() + bRecollect = False + for obj in list(gc.garbage): + try: + if isinstance(obj, win32.Handle): + obj.close() + elif isinstance(obj, Event): + obj.debug = None + elif isinstance(obj, Process): + obj.clear() + elif isinstance(obj, Thread): + obj.set_process(None) + obj.clear() + elif isinstance(obj, Module): + obj.set_process(None) + elif isinstance(obj, Window): + obj.set_process(None) + else: + continue + gc.garbage.remove(obj) + del obj + bRecollect = True + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + if bRecollect: + gc.collect() + except Exception: + if not bIgnoreExceptions: + raise + e = sys.exc_info()[1] + warnings.warn(str(e), RuntimeWarning) + +#------------------------------------------------------------------------------ + + def _notify_create_process(self, event): + """ + Notify the creation of a new process. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{CreateProcessEvent} + @param event: Create process event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + dwProcessId = event.get_pid() + if dwProcessId not in self.__attachedDebugees: + if dwProcessId not in self.__startedDebugees: + self.__startedDebugees.add(dwProcessId) + + retval = self.system._notify_create_process(event) + + # Set a breakpoint on the program's entry point if requested. + # Try not to use the Event object's entry point value, as in some cases + # it may be wrong. See: http://pferrie.host22.com/misc/lowlevel3.htm + if dwProcessId in self.__breakOnEP: + try: + lpEntryPoint = event.get_process().get_entry_point() + except Exception: + lpEntryPoint = event.get_start_address() + + # It'd be best to use a hardware breakpoint instead, at least in + # hostile mode. But since the main thread's context gets smashed + # by the loader, I haven't found a way to make it work yet. + self.break_at(dwProcessId, lpEntryPoint) + + # Defeat isDebuggerPresent by patching PEB->BeingDebugged. + # When we do this, some debugging APIs cease to work as expected. + # For example, the system breakpoint isn't hit when we attach. + # For that reason we need to define a code breakpoint at the + # code location where a new thread is spawned by the debugging + # APIs, ntdll!DbgUiRemoteBreakin. + if self.__bHostileCode: + aProcess = event.get_process() + try: + hProcess = aProcess.get_handle(win32.PROCESS_QUERY_INFORMATION) + pbi = win32.NtQueryInformationProcess( + hProcess, win32.ProcessBasicInformation) + ptr = pbi.PebBaseAddress + 2 + if aProcess.peek(ptr, 1) == '\x01': + aProcess.poke(ptr, '\x00') + except WindowsError: + e = sys.exc_info()[1] + warnings.warn( + "Cannot patch PEB->BeingDebugged, reason: %s" % e.strerror) + + return retval + + def _notify_create_thread(self, event): + """ + Notify the creation of a new thread. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{CreateThreadEvent} + @param event: Create thread event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + return event.get_process()._notify_create_thread(event) + + def _notify_load_dll(self, event): + """ + Notify the load of a new module. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{LoadDLLEvent} + @param event: Load DLL event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + + # Pass the event to the breakpoint container. + bCallHandler = _BreakpointContainer._notify_load_dll(self, event) + + # Get the process where the DLL was loaded. + aProcess = event.get_process() + + # Pass the event to the process. + bCallHandler = aProcess._notify_load_dll(event) and bCallHandler + + # Anti-anti-debugging tricks on ntdll.dll. + if self.__bHostileCode: + aModule = event.get_module() + if aModule.match_name('ntdll.dll'): + + # Since we've overwritten the PEB to hide + # ourselves, we no longer have the system + # breakpoint when attaching to the process. + # Set a breakpoint at ntdll!DbgUiRemoteBreakin + # instead (that's where the debug API spawns + # it's auxiliary threads). This also defeats + # a simple anti-debugging trick: the hostile + # process could have overwritten the int3 + # instruction at the system breakpoint. + self.break_at(aProcess.get_pid(), + aProcess.resolve_label('ntdll!DbgUiRemoteBreakin')) + + return bCallHandler + + def _notify_exit_process(self, event): + """ + Notify the termination of a process. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{ExitProcessEvent} + @param event: Exit process event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + bCallHandler1 = _BreakpointContainer._notify_exit_process(self, event) + bCallHandler2 = self.system._notify_exit_process(event) + + try: + self.detach( event.get_pid() ) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror != win32.ERROR_INVALID_PARAMETER: + warnings.warn( + "Failed to detach from dead process, reason: %s" % str(e), + RuntimeWarning) + except Exception: + e = sys.exc_info()[1] + warnings.warn( + "Failed to detach from dead process, reason: %s" % str(e), + RuntimeWarning) + + return bCallHandler1 and bCallHandler2 + + def _notify_exit_thread(self, event): + """ + Notify the termination of a thread. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{ExitThreadEvent} + @param event: Exit thread event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + bCallHandler1 = _BreakpointContainer._notify_exit_thread(self, event) + bCallHandler2 = event.get_process()._notify_exit_thread(event) + return bCallHandler1 and bCallHandler2 + + def _notify_unload_dll(self, event): + """ + Notify the unload of a module. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{UnloadDLLEvent} + @param event: Unload DLL event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + bCallHandler1 = _BreakpointContainer._notify_unload_dll(self, event) + bCallHandler2 = event.get_process()._notify_unload_dll(event) + return bCallHandler1 and bCallHandler2 + + def _notify_rip(self, event): + """ + Notify of a RIP event. + + @warning: This method is meant to be used internally by the debugger. + + @type event: L{RIPEvent} + @param event: RIP event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + event.debug.detach( event.get_pid() ) + return True + + def _notify_debug_control_c(self, event): + """ + Notify of a Debug Ctrl-C exception. + + @warning: This method is meant to be used internally by the debugger. + + @note: This exception is only raised when a debugger is attached, and + applications are not supposed to handle it, so we need to handle it + ourselves or the application may crash. + + @see: U{http://msdn.microsoft.com/en-us/library/aa363082(VS.85).aspx} + + @type event: L{ExceptionEvent} + @param event: Debug Ctrl-C exception event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + if event.is_first_chance(): + event.continueStatus = win32.DBG_EXCEPTION_HANDLED + return True + + def _notify_ms_vc_exception(self, event): + """ + Notify of a Microsoft Visual C exception. + + @warning: This method is meant to be used internally by the debugger. + + @note: This allows the debugger to understand the + Microsoft Visual C thread naming convention. + + @see: U{http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx} + + @type event: L{ExceptionEvent} + @param event: Microsoft Visual C exception event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + dwType = event.get_exception_information(0) + if dwType == 0x1000: + pszName = event.get_exception_information(1) + dwThreadId = event.get_exception_information(2) + dwFlags = event.get_exception_information(3) + + aProcess = event.get_process() + szName = aProcess.peek_string(pszName, fUnicode = False) + if szName: + + if dwThreadId == -1: + dwThreadId = event.get_tid() + + if aProcess.has_thread(dwThreadId): + aThread = aProcess.get_thread(dwThreadId) + else: + aThread = Thread(dwThreadId) + aProcess._add_thread(aThread) + +## if aThread.get_name() is None: +## aThread.set_name(szName) + aThread.set_name(szName) + + return True diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/disasm.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/disasm.py new file mode 100644 index 0000000..230e331 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/disasm.py @@ -0,0 +1,722 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Binary code disassembly. + +@group Disassembler loader: + Disassembler, Engine + +@group Disassembler engines: + BeaEngine, CapstoneEngine, DistormEngine, + LibdisassembleEngine, PyDasmEngine +""" + +from __future__ import with_statement + +__revision__ = "$Id$" + +__all__ = [ + 'Disassembler', + 'Engine', + 'BeaEngine', + 'CapstoneEngine', + 'DistormEngine', + 'LibdisassembleEngine', + 'PyDasmEngine', +] + +from winappdbg.textio import HexDump +from winappdbg import win32 + +import ctypes +import warnings + +# lazy imports +BeaEnginePython = None +distorm3 = None +pydasm = None +libdisassemble = None +capstone = None + +#============================================================================== + +class Engine (object): + """ + Base class for disassembly engine adaptors. + + @type name: str + @cvar name: Engine name to use with the L{Disassembler} class. + + @type desc: str + @cvar desc: User friendly name of the disassembler engine. + + @type url: str + @cvar url: Download URL. + + @type supported: set(str) + @cvar supported: Set of supported processor architectures. + For more details see L{win32.version._get_arch}. + + @type arch: str + @ivar arch: Name of the processor architecture. + """ + + name = "" + desc = "" + url = "" + supported = set() + + def __init__(self, arch = None): + """ + @type arch: str + @param arch: Name of the processor architecture. + If not provided the current processor architecture is assumed. + For more details see L{win32.version._get_arch}. + + @raise NotImplementedError: This disassembler doesn't support the + requested processor architecture. + """ + self.arch = self._validate_arch(arch) + try: + self._import_dependencies() + except ImportError: + msg = "%s is not installed or can't be found. Download it from: %s" + msg = msg % (self.name, self.url) + raise NotImplementedError(msg) + + def _validate_arch(self, arch = None): + """ + @type arch: str + @param arch: Name of the processor architecture. + If not provided the current processor architecture is assumed. + For more details see L{win32.version._get_arch}. + + @rtype: str + @return: Name of the processor architecture. + If not provided the current processor architecture is assumed. + For more details see L{win32.version._get_arch}. + + @raise NotImplementedError: This disassembler doesn't support the + requested processor architecture. + """ + + # Use the default architecture if none specified. + if not arch: + arch = win32.arch + + # Validate the architecture. + if arch not in self.supported: + msg = "The %s engine cannot decode %s code." + msg = msg % (self.name, arch) + raise NotImplementedError(msg) + + # Return the architecture. + return arch + + def _import_dependencies(self): + """ + Loads the dependencies for this disassembler. + + @raise ImportError: This disassembler cannot find or load the + necessary dependencies to make it work. + """ + raise SyntaxError("Subclasses MUST implement this method!") + + def decode(self, address, code): + """ + @type address: int + @param address: Memory address where the code was read from. + + @type code: str + @param code: Machine code to disassemble. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + + @raise NotImplementedError: This disassembler could not be loaded. + This may be due to missing dependencies. + """ + raise NotImplementedError() + +#============================================================================== + +class BeaEngine (Engine): + """ + Integration with the BeaEngine disassembler by Beatrix. + + @see: U{https://sourceforge.net/projects/winappdbg/files/additional%20packages/BeaEngine/} + """ + + name = "BeaEngine" + desc = "BeaEngine disassembler by Beatrix" + url = "https://sourceforge.net/projects/winappdbg/files/additional%20packages/BeaEngine/" + + supported = set(( + win32.ARCH_I386, + win32.ARCH_AMD64, + )) + + def _import_dependencies(self): + + # Load the BeaEngine ctypes wrapper. + global BeaEnginePython + if BeaEnginePython is None: + import BeaEnginePython + + def decode(self, address, code): + addressof = ctypes.addressof + + # Instance the code buffer. + buffer = ctypes.create_string_buffer(code) + buffer_ptr = addressof(buffer) + + # Instance the disassembler structure. + Instruction = BeaEnginePython.DISASM() + Instruction.VirtualAddr = address + Instruction.EIP = buffer_ptr + Instruction.SecurityBlock = buffer_ptr + len(code) + if self.arch == win32.ARCH_I386: + Instruction.Archi = 0 + else: + Instruction.Archi = 0x40 + Instruction.Options = ( BeaEnginePython.Tabulation + + BeaEnginePython.NasmSyntax + + BeaEnginePython.SuffixedNumeral + + BeaEnginePython.ShowSegmentRegs ) + + # Prepare for looping over each instruction. + result = [] + Disasm = BeaEnginePython.Disasm + InstructionPtr = addressof(Instruction) + hexdump = HexDump.hexadecimal + append = result.append + OUT_OF_BLOCK = BeaEnginePython.OUT_OF_BLOCK + UNKNOWN_OPCODE = BeaEnginePython.UNKNOWN_OPCODE + + # For each decoded instruction... + while True: + + # Calculate the current offset into the buffer. + offset = Instruction.EIP - buffer_ptr + + # If we've gone past the buffer, break the loop. + if offset >= len(code): + break + + # Decode the current instruction. + InstrLength = Disasm(InstructionPtr) + + # If BeaEngine detects we've gone past the buffer, break the loop. + if InstrLength == OUT_OF_BLOCK: + break + + # The instruction could not be decoded. + if InstrLength == UNKNOWN_OPCODE: + + # Output a single byte as a "db" instruction. + char = "%.2X" % ord(buffer[offset]) + result.append(( + Instruction.VirtualAddr, + 1, + "db %sh" % char, + char, + )) + Instruction.VirtualAddr += 1 + Instruction.EIP += 1 + + # The instruction was decoded but reading past the buffer's end. + # This can happen when the last instruction is a prefix without an + # opcode. For example: decode(0, '\x66') + elif offset + InstrLength > len(code): + + # Output each byte as a "db" instruction. + for char in buffer[ offset : offset + len(code) ]: + char = "%.2X" % ord(char) + result.append(( + Instruction.VirtualAddr, + 1, + "db %sh" % char, + char, + )) + Instruction.VirtualAddr += 1 + Instruction.EIP += 1 + + # The instruction was decoded correctly. + else: + + # Output the decoded instruction. + append(( + Instruction.VirtualAddr, + InstrLength, + Instruction.CompleteInstr.strip(), + hexdump(buffer.raw[offset:offset+InstrLength]), + )) + Instruction.VirtualAddr += InstrLength + Instruction.EIP += InstrLength + + # Return the list of decoded instructions. + return result + +#============================================================================== + +class DistormEngine (Engine): + """ + Integration with the diStorm disassembler by Gil Dabah. + + @see: U{https://code.google.com/p/distorm3} + """ + + name = "diStorm" + desc = "diStorm disassembler by Gil Dabah" + url = "https://code.google.com/p/distorm3" + + supported = set(( + win32.ARCH_I386, + win32.ARCH_AMD64, + )) + + def _import_dependencies(self): + + # Load the distorm bindings. + global distorm3 + if distorm3 is None: + try: + import distorm3 + except ImportError: + import distorm as distorm3 + + # Load the decoder function. + self.__decode = distorm3.Decode + + # Load the bits flag. + self.__flag = { + win32.ARCH_I386: distorm3.Decode32Bits, + win32.ARCH_AMD64: distorm3.Decode64Bits, + }[self.arch] + + def decode(self, address, code): + return self.__decode(address, code, self.__flag) + +#============================================================================== + +class PyDasmEngine (Engine): + """ + Integration with PyDasm: Python bindings to libdasm. + + @see: U{https://code.google.com/p/libdasm/} + """ + + name = "PyDasm" + desc = "PyDasm: Python bindings to libdasm" + url = "https://code.google.com/p/libdasm/" + + supported = set(( + win32.ARCH_I386, + )) + + def _import_dependencies(self): + + # Load the libdasm bindings. + global pydasm + if pydasm is None: + import pydasm + + def decode(self, address, code): + + # Decode each instruction in the buffer. + result = [] + offset = 0 + while offset < len(code): + + # Try to decode the current instruction. + instruction = pydasm.get_instruction(code[offset:offset+32], + pydasm.MODE_32) + + # Get the memory address of the current instruction. + current = address + offset + + # Illegal opcode or opcode longer than remaining buffer. + if not instruction or instruction.length + offset > len(code): + hexdump = '%.2X' % ord(code[offset]) + disasm = 'db 0x%s' % hexdump + ilen = 1 + + # Correctly decoded instruction. + else: + disasm = pydasm.get_instruction_string(instruction, + pydasm.FORMAT_INTEL, + current) + ilen = instruction.length + hexdump = HexDump.hexadecimal(code[offset:offset+ilen]) + + # Add the decoded instruction to the list. + result.append(( + current, + ilen, + disasm, + hexdump, + )) + + # Move to the next instruction. + offset += ilen + + # Return the list of decoded instructions. + return result + +#============================================================================== + +class LibdisassembleEngine (Engine): + """ + Integration with Immunity libdisassemble. + + @see: U{http://www.immunitysec.com/resources-freesoftware.shtml} + """ + + name = "Libdisassemble" + desc = "Immunity libdisassemble" + url = "http://www.immunitysec.com/resources-freesoftware.shtml" + + supported = set(( + win32.ARCH_I386, + )) + + def _import_dependencies(self): + + # Load the libdisassemble module. + # Since it doesn't come with an installer or an __init__.py file + # users can only install it manually however they feel like it, + # so we'll have to do a bit of guessing to find it. + + global libdisassemble + if libdisassemble is None: + try: + + # If installed properly with __init__.py + import libdisassemble.disassemble as libdisassemble + + except ImportError: + + # If installed by just copying and pasting the files + import disassemble as libdisassemble + + def decode(self, address, code): + + # Decode each instruction in the buffer. + result = [] + offset = 0 + while offset < len(code): + + # Decode the current instruction. + opcode = libdisassemble.Opcode( code[offset:offset+32] ) + length = opcode.getSize() + disasm = opcode.printOpcode('INTEL') + hexdump = HexDump.hexadecimal( code[offset:offset+length] ) + + # Add the decoded instruction to the list. + result.append(( + address + offset, + length, + disasm, + hexdump, + )) + + # Move to the next instruction. + offset += length + + # Return the list of decoded instructions. + return result + +#============================================================================== + +class CapstoneEngine (Engine): + """ + Integration with the Capstone disassembler by Nguyen Anh Quynh. + + @see: U{http://www.capstone-engine.org/} + """ + + name = "Capstone" + desc = "Capstone disassembler by Nguyen Anh Quynh" + url = "http://www.capstone-engine.org/" + + supported = set(( + win32.ARCH_I386, + win32.ARCH_AMD64, + win32.ARCH_THUMB, + win32.ARCH_ARM, + win32.ARCH_ARM64, + )) + + def _import_dependencies(self): + + # Load the Capstone bindings. + global capstone + if capstone is None: + import capstone + + # Load the constants for the requested architecture. + self.__constants = { + win32.ARCH_I386: + (capstone.CS_ARCH_X86, capstone.CS_MODE_32), + win32.ARCH_AMD64: + (capstone.CS_ARCH_X86, capstone.CS_MODE_64), + win32.ARCH_THUMB: + (capstone.CS_ARCH_ARM, capstone.CS_MODE_THUMB), + win32.ARCH_ARM: + (capstone.CS_ARCH_ARM, capstone.CS_MODE_ARM), + win32.ARCH_ARM64: + (capstone.CS_ARCH_ARM64, capstone.CS_MODE_ARM), + } + + # Test for the bug in early versions of Capstone. + # If found, warn the user about it. + try: + self.__bug = not isinstance( + capstone.cs_disasm_quick( + capstone.CS_ARCH_X86, capstone.CS_MODE_32, "\x90", 1)[0], + capstone.capstone.CsInsn) + except AttributeError: + self.__bug = False + if self.__bug: + warnings.warn( + "This version of the Capstone bindings is unstable," + " please upgrade to a newer one!", + RuntimeWarning, stacklevel=4) + + + def decode(self, address, code): + + # Get the constants for the requested architecture. + arch, mode = self.__constants[self.arch] + + # Get the decoder function outside the loop. + decoder = capstone.cs_disasm_quick + + # If the buggy version of the bindings are being used, we need to catch + # all exceptions broadly. If not, we only need to catch CsError. + if self.__bug: + CsError = Exception + else: + CsError = capstone.CsError + + # Create the variables for the instruction length, mnemonic and + # operands. That way they won't be created within the loop, + # minimizing the chances data might be overwritten. + # This only makes sense for the buggy vesion of the bindings, normally + # memory accesses are safe). + length = mnemonic = op_str = None + + # For each instruction... + result = [] + offset = 0 + while offset < len(code): + + # Disassemble a single instruction, because disassembling multiple + # instructions may cause excessive memory usage (Capstone allocates + # approximately 1K of metadata per each decoded instruction). + instr = None + try: + instr = decoder( + arch, mode, code[offset:offset+16], address+offset, 1)[0] + except IndexError: + pass # No instructions decoded. + except CsError: + pass # Any other error. + + # On success add the decoded instruction. + if instr is not None: + + # Get the instruction length, mnemonic and operands. + # Copy the values quickly before someone overwrites them, + # if using the buggy version of the bindings (otherwise it's + # irrelevant in which order we access the properties). + length = instr.size + mnemonic = instr.mnemonic + op_str = instr.op_str + + # Concatenate the mnemonic and the operands. + if op_str: + disasm = "%s %s" % (mnemonic, op_str) + else: + disasm = mnemonic + + # Get the instruction bytes as a hexadecimal dump. + hexdump = HexDump.hexadecimal( code[offset:offset+length] ) + + # On error add a "define constant" instruction. + # The exact instruction depends on the architecture. + else: + + # The number of bytes to skip depends on the architecture. + # On Intel processors we'll skip one byte, since we can't + # really know the instruction length. On the rest of the + # architectures we always know the instruction length. + if self.arch in (win32.ARCH_I386, win32.ARCH_AMD64): + length = 1 + else: + length = 4 + + # Get the skipped bytes as a hexadecimal dump. + skipped = code[offset:offset+length] + hexdump = HexDump.hexadecimal(skipped) + + # Build the "define constant" instruction. + # On Intel processors it's "db". + # On ARM processors it's "dcb". + if self.arch in (win32.ARCH_I386, win32.ARCH_AMD64): + mnemonic = "db " + else: + mnemonic = "dcb " + bytes = [] + for b in skipped: + if b.isalpha(): + bytes.append("'%s'" % b) + else: + bytes.append("0x%x" % ord(b)) + op_str = ", ".join(bytes) + disasm = mnemonic + op_str + + # Add the decoded instruction to the list. + result.append(( + address + offset, + length, + disasm, + hexdump, + )) + + # Update the offset. + offset += length + + # Return the list of decoded instructions. + return result + +#============================================================================== + +# TODO: use a lock to access __decoder +# TODO: look in sys.modules for whichever disassembler is already loaded + +class Disassembler (object): + """ + Generic disassembler. Uses a set of adapters to decide which library to + load for which supported platform. + + @type engines: tuple( L{Engine} ) + @cvar engines: Set of supported engines. If you implement your own adapter + you can add its class here to make it available to L{Disassembler}. + Supported disassemblers are: + """ + + engines = ( + DistormEngine, # diStorm engine goes first for backwards compatibility + BeaEngine, + CapstoneEngine, + LibdisassembleEngine, + PyDasmEngine, + ) + + # Add the list of supported disassemblers to the docstring. + __doc__ += "\n" + for e in engines: + __doc__ += " - %s - %s (U{%s})\n" % (e.name, e.desc, e.url) + del e + + # Cache of already loaded disassemblers. + __decoder = {} + + def __new__(cls, arch = None, engine = None): + """ + Factory class. You can't really instance a L{Disassembler} object, + instead one of the adapter L{Engine} subclasses is returned. + + @type arch: str + @param arch: (Optional) Name of the processor architecture. + If not provided the current processor architecture is assumed. + For more details see L{win32.version._get_arch}. + + @type engine: str + @param engine: (Optional) Name of the disassembler engine. + If not provided a compatible one is loaded automatically. + See: L{Engine.name} + + @raise NotImplementedError: No compatible disassembler was found that + could decode machine code for the requested architecture. This may + be due to missing dependencies. + + @raise ValueError: An unknown engine name was supplied. + """ + + # Use the default architecture if none specified. + if not arch: + arch = win32.arch + + # Return a compatible engine if none specified. + if not engine: + found = False + for clazz in cls.engines: + try: + if arch in clazz.supported: + selected = (clazz.name, arch) + try: + decoder = cls.__decoder[selected] + except KeyError: + decoder = clazz(arch) + cls.__decoder[selected] = decoder + return decoder + except NotImplementedError: + pass + msg = "No disassembler engine available for %s code." % arch + raise NotImplementedError(msg) + + # Return the specified engine. + selected = (engine, arch) + try: + decoder = cls.__decoder[selected] + except KeyError: + found = False + engineLower = engine.lower() + for clazz in cls.engines: + if clazz.name.lower() == engineLower: + found = True + break + if not found: + msg = "Unsupported disassembler engine: %s" % engine + raise ValueError(msg) + if arch not in clazz.supported: + msg = "The %s engine cannot decode %s code." % selected + raise NotImplementedError(msg) + decoder = clazz(arch) + cls.__decoder[selected] = decoder + return decoder diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/event.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/event.py new file mode 100644 index 0000000..af64727 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/event.py @@ -0,0 +1,1869 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Event handling module. + +@see: U{http://apps.sourceforge.net/trac/winappdbg/wiki/Debugging} + +@group Debugging: + EventHandler, EventSift + +@group Debug events: + EventFactory, + EventDispatcher, + Event, + NoEvent, + CreateProcessEvent, + CreateThreadEvent, + ExitProcessEvent, + ExitThreadEvent, + LoadDLLEvent, + UnloadDLLEvent, + OutputDebugStringEvent, + RIPEvent, + ExceptionEvent + +@group Warnings: + EventCallbackWarning +""" + +__revision__ = "$Id$" + +__all__ = [ + # Factory of Event objects and all of it's subclasses. + # Users should not need to instance Event objects directly. + 'EventFactory', + + # Event dispatcher used internally by the Debug class. + 'EventDispatcher', + + # Base classes for user-defined event handlers. + 'EventHandler', + 'EventSift', + + # Warning for uncaught exceptions on event callbacks. + 'EventCallbackWarning', + + # Dummy event object that can be used as a placeholder. + # It's never returned by the EventFactory. + 'NoEvent', + + # Base class for event objects. + 'Event', + + # Event objects. + 'CreateProcessEvent', + 'CreateThreadEvent', + 'ExitProcessEvent', + 'ExitThreadEvent', + 'LoadDLLEvent', + 'UnloadDLLEvent', + 'OutputDebugStringEvent', + 'RIPEvent', + 'ExceptionEvent' + ] + +from winappdbg import win32 +from winappdbg import compat +from winappdbg.win32 import FileHandle, ProcessHandle, ThreadHandle +from winappdbg.breakpoint import ApiHook +from winappdbg.module import Module +from winappdbg.thread import Thread +from winappdbg.process import Process +from winappdbg.textio import HexDump +from winappdbg.util import StaticClass, PathOperations + +import sys +import ctypes +import warnings +import traceback + +#============================================================================== + +class EventCallbackWarning (RuntimeWarning): + """ + This warning is issued when an uncaught exception was raised by a + user-defined event handler. + """ + +#============================================================================== + +class Event (object): + """ + Event object. + + @type eventMethod: str + @cvar eventMethod: + Method name to call when using L{EventHandler} subclasses. + Used internally. + + @type eventName: str + @cvar eventName: + User-friendly name of the event. + + @type eventDescription: str + @cvar eventDescription: + User-friendly description of the event. + + @type debug: L{Debug} + @ivar debug: + Debug object that received the event. + + @type raw: L{DEBUG_EVENT} + @ivar raw: + Raw DEBUG_EVENT structure as used by the Win32 API. + + @type continueStatus: int + @ivar continueStatus: + Continue status to pass to L{win32.ContinueDebugEvent}. + """ + + eventMethod = 'unknown_event' + eventName = 'Unknown event' + eventDescription = 'A debug event of an unknown type has occured.' + + def __init__(self, debug, raw): + """ + @type debug: L{Debug} + @param debug: Debug object that received the event. + + @type raw: L{DEBUG_EVENT} + @param raw: Raw DEBUG_EVENT structure as used by the Win32 API. + """ + self.debug = debug + self.raw = raw + self.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + +## @property +## def debug(self): +## """ +## @rtype debug: L{Debug} +## @return debug: +## Debug object that received the event. +## """ +## return self.__debug() + + def get_event_name(self): + """ + @rtype: str + @return: User-friendly name of the event. + """ + return self.eventName + + def get_event_description(self): + """ + @rtype: str + @return: User-friendly description of the event. + """ + return self.eventDescription + + def get_event_code(self): + """ + @rtype: int + @return: Debug event code as defined in the Win32 API. + """ + return self.raw.dwDebugEventCode + +## # Compatibility with version 1.0 +## # XXX to be removed in version 1.4 +## def get_code(self): +## """ +## Alias of L{get_event_code} for backwards compatibility +## with WinAppDbg version 1.0. +## Will be phased out in the next version. +## +## @rtype: int +## @return: Debug event code as defined in the Win32 API. +## """ +## return self.get_event_code() + + def get_pid(self): + """ + @see: L{get_process} + + @rtype: int + @return: Process global ID where the event occured. + """ + return self.raw.dwProcessId + + def get_tid(self): + """ + @see: L{get_thread} + + @rtype: int + @return: Thread global ID where the event occured. + """ + return self.raw.dwThreadId + + def get_process(self): + """ + @see: L{get_pid} + + @rtype: L{Process} + @return: Process where the event occured. + """ + pid = self.get_pid() + system = self.debug.system + if system.has_process(pid): + process = system.get_process(pid) + else: + # XXX HACK + # The process object was missing for some reason, so make a new one. + process = Process(pid) + system._add_process(process) +## process.scan_threads() # not needed + process.scan_modules() + return process + + def get_thread(self): + """ + @see: L{get_tid} + + @rtype: L{Thread} + @return: Thread where the event occured. + """ + tid = self.get_tid() + process = self.get_process() + if process.has_thread(tid): + thread = process.get_thread(tid) + else: + # XXX HACK + # The thread object was missing for some reason, so make a new one. + thread = Thread(tid) + process._add_thread(thread) + return thread + +#============================================================================== + +class NoEvent (Event): + """ + No event. + + Dummy L{Event} object that can be used as a placeholder when no debug + event has occured yet. It's never returned by the L{EventFactory}. + """ + + eventMethod = 'no_event' + eventName = 'No event' + eventDescription = 'No debug event has occured.' + + def __init__(self, debug, raw = None): + Event.__init__(self, debug, raw) + + def __len__(self): + """ + Always returns C{0}, so when evaluating the object as a boolean it's + always C{False}. This prevents L{Debug.cont} from trying to continue + a dummy event. + """ + return 0 + + def get_event_code(self): + return -1 + + def get_pid(self): + return -1 + + def get_tid(self): + return -1 + + def get_process(self): + return Process(self.get_pid()) + + def get_thread(self): + return Thread(self.get_tid()) + +#============================================================================== + +class ExceptionEvent (Event): + """ + Exception event. + + @type exceptionName: dict( int S{->} str ) + @cvar exceptionName: + Mapping of exception constants to their names. + + @type exceptionDescription: dict( int S{->} str ) + @cvar exceptionDescription: + Mapping of exception constants to user-friendly strings. + + @type breakpoint: L{Breakpoint} + @ivar breakpoint: + If the exception was caused by one of our breakpoints, this member + contains a reference to the breakpoint object. Otherwise it's not + defined. It should only be used from the condition or action callback + routines, instead of the event handler. + + @type hook: L{Hook} + @ivar hook: + If the exception was caused by a function hook, this member contains a + reference to the hook object. Otherwise it's not defined. It should + only be used from the hook callback routines, instead of the event + handler. + """ + + eventName = 'Exception event' + eventDescription = 'An exception was raised by the debugee.' + + __exceptionMethod = { + win32.EXCEPTION_ACCESS_VIOLATION : 'access_violation', + win32.EXCEPTION_ARRAY_BOUNDS_EXCEEDED : 'array_bounds_exceeded', + win32.EXCEPTION_BREAKPOINT : 'breakpoint', + win32.EXCEPTION_DATATYPE_MISALIGNMENT : 'datatype_misalignment', + win32.EXCEPTION_FLT_DENORMAL_OPERAND : 'float_denormal_operand', + win32.EXCEPTION_FLT_DIVIDE_BY_ZERO : 'float_divide_by_zero', + win32.EXCEPTION_FLT_INEXACT_RESULT : 'float_inexact_result', + win32.EXCEPTION_FLT_INVALID_OPERATION : 'float_invalid_operation', + win32.EXCEPTION_FLT_OVERFLOW : 'float_overflow', + win32.EXCEPTION_FLT_STACK_CHECK : 'float_stack_check', + win32.EXCEPTION_FLT_UNDERFLOW : 'float_underflow', + win32.EXCEPTION_ILLEGAL_INSTRUCTION : 'illegal_instruction', + win32.EXCEPTION_IN_PAGE_ERROR : 'in_page_error', + win32.EXCEPTION_INT_DIVIDE_BY_ZERO : 'integer_divide_by_zero', + win32.EXCEPTION_INT_OVERFLOW : 'integer_overflow', + win32.EXCEPTION_INVALID_DISPOSITION : 'invalid_disposition', + win32.EXCEPTION_NONCONTINUABLE_EXCEPTION : 'noncontinuable_exception', + win32.EXCEPTION_PRIV_INSTRUCTION : 'privileged_instruction', + win32.EXCEPTION_SINGLE_STEP : 'single_step', + win32.EXCEPTION_STACK_OVERFLOW : 'stack_overflow', + win32.EXCEPTION_GUARD_PAGE : 'guard_page', + win32.EXCEPTION_INVALID_HANDLE : 'invalid_handle', + win32.EXCEPTION_POSSIBLE_DEADLOCK : 'possible_deadlock', + win32.EXCEPTION_WX86_BREAKPOINT : 'wow64_breakpoint', + win32.CONTROL_C_EXIT : 'control_c_exit', + win32.DBG_CONTROL_C : 'debug_control_c', + win32.MS_VC_EXCEPTION : 'ms_vc_exception', + } + + __exceptionName = { + win32.EXCEPTION_ACCESS_VIOLATION : 'EXCEPTION_ACCESS_VIOLATION', + win32.EXCEPTION_ARRAY_BOUNDS_EXCEEDED : 'EXCEPTION_ARRAY_BOUNDS_EXCEEDED', + win32.EXCEPTION_BREAKPOINT : 'EXCEPTION_BREAKPOINT', + win32.EXCEPTION_DATATYPE_MISALIGNMENT : 'EXCEPTION_DATATYPE_MISALIGNMENT', + win32.EXCEPTION_FLT_DENORMAL_OPERAND : 'EXCEPTION_FLT_DENORMAL_OPERAND', + win32.EXCEPTION_FLT_DIVIDE_BY_ZERO : 'EXCEPTION_FLT_DIVIDE_BY_ZERO', + win32.EXCEPTION_FLT_INEXACT_RESULT : 'EXCEPTION_FLT_INEXACT_RESULT', + win32.EXCEPTION_FLT_INVALID_OPERATION : 'EXCEPTION_FLT_INVALID_OPERATION', + win32.EXCEPTION_FLT_OVERFLOW : 'EXCEPTION_FLT_OVERFLOW', + win32.EXCEPTION_FLT_STACK_CHECK : 'EXCEPTION_FLT_STACK_CHECK', + win32.EXCEPTION_FLT_UNDERFLOW : 'EXCEPTION_FLT_UNDERFLOW', + win32.EXCEPTION_ILLEGAL_INSTRUCTION : 'EXCEPTION_ILLEGAL_INSTRUCTION', + win32.EXCEPTION_IN_PAGE_ERROR : 'EXCEPTION_IN_PAGE_ERROR', + win32.EXCEPTION_INT_DIVIDE_BY_ZERO : 'EXCEPTION_INT_DIVIDE_BY_ZERO', + win32.EXCEPTION_INT_OVERFLOW : 'EXCEPTION_INT_OVERFLOW', + win32.EXCEPTION_INVALID_DISPOSITION : 'EXCEPTION_INVALID_DISPOSITION', + win32.EXCEPTION_NONCONTINUABLE_EXCEPTION : 'EXCEPTION_NONCONTINUABLE_EXCEPTION', + win32.EXCEPTION_PRIV_INSTRUCTION : 'EXCEPTION_PRIV_INSTRUCTION', + win32.EXCEPTION_SINGLE_STEP : 'EXCEPTION_SINGLE_STEP', + win32.EXCEPTION_STACK_OVERFLOW : 'EXCEPTION_STACK_OVERFLOW', + win32.EXCEPTION_GUARD_PAGE : 'EXCEPTION_GUARD_PAGE', + win32.EXCEPTION_INVALID_HANDLE : 'EXCEPTION_INVALID_HANDLE', + win32.EXCEPTION_POSSIBLE_DEADLOCK : 'EXCEPTION_POSSIBLE_DEADLOCK', + win32.EXCEPTION_WX86_BREAKPOINT : 'EXCEPTION_WX86_BREAKPOINT', + win32.CONTROL_C_EXIT : 'CONTROL_C_EXIT', + win32.DBG_CONTROL_C : 'DBG_CONTROL_C', + win32.MS_VC_EXCEPTION : 'MS_VC_EXCEPTION', + } + + __exceptionDescription = { + win32.EXCEPTION_ACCESS_VIOLATION : 'Access violation', + win32.EXCEPTION_ARRAY_BOUNDS_EXCEEDED : 'Array bounds exceeded', + win32.EXCEPTION_BREAKPOINT : 'Breakpoint', + win32.EXCEPTION_DATATYPE_MISALIGNMENT : 'Datatype misalignment', + win32.EXCEPTION_FLT_DENORMAL_OPERAND : 'Float denormal operand', + win32.EXCEPTION_FLT_DIVIDE_BY_ZERO : 'Float divide by zero', + win32.EXCEPTION_FLT_INEXACT_RESULT : 'Float inexact result', + win32.EXCEPTION_FLT_INVALID_OPERATION : 'Float invalid operation', + win32.EXCEPTION_FLT_OVERFLOW : 'Float overflow', + win32.EXCEPTION_FLT_STACK_CHECK : 'Float stack check', + win32.EXCEPTION_FLT_UNDERFLOW : 'Float underflow', + win32.EXCEPTION_ILLEGAL_INSTRUCTION : 'Illegal instruction', + win32.EXCEPTION_IN_PAGE_ERROR : 'In-page error', + win32.EXCEPTION_INT_DIVIDE_BY_ZERO : 'Integer divide by zero', + win32.EXCEPTION_INT_OVERFLOW : 'Integer overflow', + win32.EXCEPTION_INVALID_DISPOSITION : 'Invalid disposition', + win32.EXCEPTION_NONCONTINUABLE_EXCEPTION : 'Noncontinuable exception', + win32.EXCEPTION_PRIV_INSTRUCTION : 'Privileged instruction', + win32.EXCEPTION_SINGLE_STEP : 'Single step event', + win32.EXCEPTION_STACK_OVERFLOW : 'Stack limits overflow', + win32.EXCEPTION_GUARD_PAGE : 'Guard page hit', + win32.EXCEPTION_INVALID_HANDLE : 'Invalid handle', + win32.EXCEPTION_POSSIBLE_DEADLOCK : 'Possible deadlock', + win32.EXCEPTION_WX86_BREAKPOINT : 'WOW64 breakpoint', + win32.CONTROL_C_EXIT : 'Control-C exit', + win32.DBG_CONTROL_C : 'Debug Control-C', + win32.MS_VC_EXCEPTION : 'Microsoft Visual C++ exception', + } + + @property + def eventMethod(self): + return self.__exceptionMethod.get( + self.get_exception_code(), 'unknown_exception') + + def get_exception_name(self): + """ + @rtype: str + @return: Name of the exception as defined by the Win32 API. + """ + code = self.get_exception_code() + unk = HexDump.integer(code) + return self.__exceptionName.get(code, unk) + + def get_exception_description(self): + """ + @rtype: str + @return: User-friendly name of the exception. + """ + code = self.get_exception_code() + description = self.__exceptionDescription.get(code, None) + if description is None: + try: + description = 'Exception code %s (%s)' + description = description % (HexDump.integer(code), + ctypes.FormatError(code)) + except OverflowError: + description = 'Exception code %s' % HexDump.integer(code) + return description + + def is_first_chance(self): + """ + @rtype: bool + @return: C{True} for first chance exceptions, C{False} for last chance. + """ + return self.raw.u.Exception.dwFirstChance != 0 + + def is_last_chance(self): + """ + @rtype: bool + @return: The opposite of L{is_first_chance}. + """ + return not self.is_first_chance() + + def is_noncontinuable(self): + """ + @see: U{http://msdn.microsoft.com/en-us/library/aa363082(VS.85).aspx} + + @rtype: bool + @return: C{True} if the exception is noncontinuable, + C{False} otherwise. + + Attempting to continue a noncontinuable exception results in an + EXCEPTION_NONCONTINUABLE_EXCEPTION exception to be raised. + """ + return bool( self.raw.u.Exception.ExceptionRecord.ExceptionFlags & \ + win32.EXCEPTION_NONCONTINUABLE ) + + def is_continuable(self): + """ + @rtype: bool + @return: The opposite of L{is_noncontinuable}. + """ + return not self.is_noncontinuable() + + def is_user_defined_exception(self): + """ + Determines if this is an user-defined exception. User-defined + exceptions may contain any exception code that is not system reserved. + + Often the exception code is also a valid Win32 error code, but that's + up to the debugged application. + + @rtype: bool + @return: C{True} if the exception is user-defined, C{False} otherwise. + """ + return self.get_exception_code() & 0x10000000 == 0 + + def is_system_defined_exception(self): + """ + @rtype: bool + @return: The opposite of L{is_user_defined_exception}. + """ + return not self.is_user_defined_exception() + + def get_exception_code(self): + """ + @rtype: int + @return: Exception code as defined by the Win32 API. + """ + return self.raw.u.Exception.ExceptionRecord.ExceptionCode + + def get_exception_address(self): + """ + @rtype: int + @return: Memory address where the exception occured. + """ + address = self.raw.u.Exception.ExceptionRecord.ExceptionAddress + if address is None: + address = 0 + return address + + def get_exception_information(self, index): + """ + @type index: int + @param index: Index into the exception information block. + + @rtype: int + @return: Exception information DWORD. + """ + if index < 0 or index > win32.EXCEPTION_MAXIMUM_PARAMETERS: + raise IndexError("Array index out of range: %s" % repr(index)) + info = self.raw.u.Exception.ExceptionRecord.ExceptionInformation + value = info[index] + if value is None: + value = 0 + return value + + def get_exception_information_as_list(self): + """ + @rtype: list( int ) + @return: Exception information block. + """ + info = self.raw.u.Exception.ExceptionRecord.ExceptionInformation + data = list() + for index in compat.xrange(0, win32.EXCEPTION_MAXIMUM_PARAMETERS): + value = info[index] + if value is None: + value = 0 + data.append(value) + return data + + def get_fault_type(self): + """ + @rtype: int + @return: Access violation type. + Should be one of the following constants: + + - L{win32.EXCEPTION_READ_FAULT} + - L{win32.EXCEPTION_WRITE_FAULT} + - L{win32.EXCEPTION_EXECUTE_FAULT} + + @note: This method is only meaningful for access violation exceptions, + in-page memory error exceptions and guard page exceptions. + + @raise NotImplementedError: Wrong kind of exception. + """ + if self.get_exception_code() not in (win32.EXCEPTION_ACCESS_VIOLATION, + win32.EXCEPTION_IN_PAGE_ERROR, win32.EXCEPTION_GUARD_PAGE): + msg = "This method is not meaningful for %s." + raise NotImplementedError(msg % self.get_exception_name()) + return self.get_exception_information(0) + + def get_fault_address(self): + """ + @rtype: int + @return: Access violation memory address. + + @note: This method is only meaningful for access violation exceptions, + in-page memory error exceptions and guard page exceptions. + + @raise NotImplementedError: Wrong kind of exception. + """ + if self.get_exception_code() not in (win32.EXCEPTION_ACCESS_VIOLATION, + win32.EXCEPTION_IN_PAGE_ERROR, win32.EXCEPTION_GUARD_PAGE): + msg = "This method is not meaningful for %s." + raise NotImplementedError(msg % self.get_exception_name()) + return self.get_exception_information(1) + + def get_ntstatus_code(self): + """ + @rtype: int + @return: NTSTATUS status code that caused the exception. + + @note: This method is only meaningful for in-page memory error + exceptions. + + @raise NotImplementedError: Not an in-page memory error. + """ + if self.get_exception_code() != win32.EXCEPTION_IN_PAGE_ERROR: + msg = "This method is only meaningful "\ + "for in-page memory error exceptions." + raise NotImplementedError(msg) + return self.get_exception_information(2) + + def is_nested(self): + """ + @rtype: bool + @return: Returns C{True} if there are additional exception records + associated with this exception. This would mean the exception + is nested, that is, it was triggered while trying to handle + at least one previous exception. + """ + return bool(self.raw.u.Exception.ExceptionRecord.ExceptionRecord) + + def get_raw_exception_record_list(self): + """ + Traverses the exception record linked list and builds a Python list. + + Nested exception records are received for nested exceptions. This + happens when an exception is raised in the debugee while trying to + handle a previous exception. + + @rtype: list( L{win32.EXCEPTION_RECORD} ) + @return: + List of raw exception record structures as used by the Win32 API. + + There is always at least one exception record, so the list is + never empty. All other methods of this class read from the first + exception record only, that is, the most recent exception. + """ + # The first EXCEPTION_RECORD is contained in EXCEPTION_DEBUG_INFO. + # The remaining EXCEPTION_RECORD structures are linked by pointers. + nested = list() + record = self.raw.u.Exception + while True: + record = record.ExceptionRecord + if not record: + break + nested.append(record) + return nested + + def get_nested_exceptions(self): + """ + Traverses the exception record linked list and builds a Python list. + + Nested exception records are received for nested exceptions. This + happens when an exception is raised in the debugee while trying to + handle a previous exception. + + @rtype: list( L{ExceptionEvent} ) + @return: + List of ExceptionEvent objects representing each exception record + found in this event. + + There is always at least one exception record, so the list is + never empty. All other methods of this class read from the first + exception record only, that is, the most recent exception. + """ + # The list always begins with ourselves. + # Just put a reference to "self" as the first element, + # and start looping from the second exception record. + nested = [ self ] + raw = self.raw + dwDebugEventCode = raw.dwDebugEventCode + dwProcessId = raw.dwProcessId + dwThreadId = raw.dwThreadId + dwFirstChance = raw.u.Exception.dwFirstChance + record = raw.u.Exception.ExceptionRecord + while True: + record = record.ExceptionRecord + if not record: + break + raw = win32.DEBUG_EVENT() + raw.dwDebugEventCode = dwDebugEventCode + raw.dwProcessId = dwProcessId + raw.dwThreadId = dwThreadId + raw.u.Exception.ExceptionRecord = record + raw.u.Exception.dwFirstChance = dwFirstChance + event = EventFactory.get(self.debug, raw) + nested.append(event) + return nested + +#============================================================================== + +class CreateThreadEvent (Event): + """ + Thread creation event. + """ + + eventMethod = 'create_thread' + eventName = 'Thread creation event' + eventDescription = 'A new thread has started.' + + def get_thread_handle(self): + """ + @rtype: L{ThreadHandle} + @return: Thread handle received from the system. + Returns C{None} if the handle is not available. + """ + # The handle doesn't need to be closed. + # See http://msdn.microsoft.com/en-us/library/ms681423(VS.85).aspx + hThread = self.raw.u.CreateThread.hThread + if hThread in (0, win32.NULL, win32.INVALID_HANDLE_VALUE): + hThread = None + else: + hThread = ThreadHandle(hThread, False, win32.THREAD_ALL_ACCESS) + return hThread + + def get_teb(self): + """ + @rtype: int + @return: Pointer to the TEB. + """ + return self.raw.u.CreateThread.lpThreadLocalBase + + def get_start_address(self): + """ + @rtype: int + @return: Pointer to the first instruction to execute in this thread. + + Returns C{NULL} when the debugger attached to a process + and the thread already existed. + + See U{http://msdn.microsoft.com/en-us/library/ms679295(VS.85).aspx} + """ + return self.raw.u.CreateThread.lpStartAddress + +#============================================================================== + +class CreateProcessEvent (Event): + """ + Process creation event. + """ + + eventMethod = 'create_process' + eventName = 'Process creation event' + eventDescription = 'A new process has started.' + + def get_file_handle(self): + """ + @rtype: L{FileHandle} or None + @return: File handle to the main module, received from the system. + Returns C{None} if the handle is not available. + """ + # This handle DOES need to be closed. + # Therefore we must cache it so it doesn't + # get closed after the first call. + try: + hFile = self.__hFile + except AttributeError: + hFile = self.raw.u.CreateProcessInfo.hFile + if hFile in (0, win32.NULL, win32.INVALID_HANDLE_VALUE): + hFile = None + else: + hFile = FileHandle(hFile, True) + self.__hFile = hFile + return hFile + + def get_process_handle(self): + """ + @rtype: L{ProcessHandle} + @return: Process handle received from the system. + Returns C{None} if the handle is not available. + """ + # The handle doesn't need to be closed. + # See http://msdn.microsoft.com/en-us/library/ms681423(VS.85).aspx + hProcess = self.raw.u.CreateProcessInfo.hProcess + if hProcess in (0, win32.NULL, win32.INVALID_HANDLE_VALUE): + hProcess = None + else: + hProcess = ProcessHandle(hProcess, False, win32.PROCESS_ALL_ACCESS) + return hProcess + + def get_thread_handle(self): + """ + @rtype: L{ThreadHandle} + @return: Thread handle received from the system. + Returns C{None} if the handle is not available. + """ + # The handle doesn't need to be closed. + # See http://msdn.microsoft.com/en-us/library/ms681423(VS.85).aspx + hThread = self.raw.u.CreateProcessInfo.hThread + if hThread in (0, win32.NULL, win32.INVALID_HANDLE_VALUE): + hThread = None + else: + hThread = ThreadHandle(hThread, False, win32.THREAD_ALL_ACCESS) + return hThread + + def get_start_address(self): + """ + @rtype: int + @return: Pointer to the first instruction to execute in this process. + + Returns C{NULL} when the debugger attaches to a process. + + See U{http://msdn.microsoft.com/en-us/library/ms679295(VS.85).aspx} + """ + return self.raw.u.CreateProcessInfo.lpStartAddress + + def get_image_base(self): + """ + @rtype: int + @return: Base address of the main module. + @warn: This value is taken from the PE file + and may be incorrect because of ASLR! + """ + # TODO try to calculate the real value when ASLR is active. + return self.raw.u.CreateProcessInfo.lpBaseOfImage + + def get_teb(self): + """ + @rtype: int + @return: Pointer to the TEB. + """ + return self.raw.u.CreateProcessInfo.lpThreadLocalBase + + def get_debug_info(self): + """ + @rtype: str + @return: Debugging information. + """ + raw = self.raw.u.CreateProcessInfo + ptr = raw.lpBaseOfImage + raw.dwDebugInfoFileOffset + size = raw.nDebugInfoSize + data = self.get_process().peek(ptr, size) + if len(data) == size: + return data + return None + + def get_filename(self): + """ + @rtype: str, None + @return: This method does it's best to retrieve the filename to + the main module of the process. However, sometimes that's not + possible, and C{None} is returned instead. + """ + + # Try to get the filename from the file handle. + szFilename = None + hFile = self.get_file_handle() + if hFile: + szFilename = hFile.get_filename() + if not szFilename: + + # Try to get it from CREATE_PROCESS_DEBUG_INFO.lpImageName + # It's NULL or *NULL most of the times, see MSDN: + # http://msdn.microsoft.com/en-us/library/ms679286(VS.85).aspx + aProcess = self.get_process() + lpRemoteFilenamePtr = self.raw.u.CreateProcessInfo.lpImageName + if lpRemoteFilenamePtr: + lpFilename = aProcess.peek_uint(lpRemoteFilenamePtr) + fUnicode = bool( self.raw.u.CreateProcessInfo.fUnicode ) + szFilename = aProcess.peek_string(lpFilename, fUnicode) + + # XXX TODO + # Sometimes the filename is relative (ntdll.dll, kernel32.dll). + # It could be converted to an absolute pathname (SearchPath). + + # Try to get it from Process.get_image_name(). + if not szFilename: + szFilename = aProcess.get_image_name() + + # Return the filename, or None on error. + return szFilename + + def get_module_base(self): + """ + @rtype: int + @return: Base address of the main module. + """ + return self.get_image_base() + + def get_module(self): + """ + @rtype: L{Module} + @return: Main module of the process. + """ + return self.get_process().get_module( self.get_module_base() ) + +#============================================================================== + +class ExitThreadEvent (Event): + """ + Thread termination event. + """ + + eventMethod = 'exit_thread' + eventName = 'Thread termination event' + eventDescription = 'A thread has finished executing.' + + def get_exit_code(self): + """ + @rtype: int + @return: Exit code of the thread. + """ + return self.raw.u.ExitThread.dwExitCode + +#============================================================================== + +class ExitProcessEvent (Event): + """ + Process termination event. + """ + + eventMethod = 'exit_process' + eventName = 'Process termination event' + eventDescription = 'A process has finished executing.' + + def get_exit_code(self): + """ + @rtype: int + @return: Exit code of the process. + """ + return self.raw.u.ExitProcess.dwExitCode + + def get_filename(self): + """ + @rtype: None or str + @return: Filename of the main module. + C{None} if the filename is unknown. + """ + return self.get_module().get_filename() + + def get_image_base(self): + """ + @rtype: int + @return: Base address of the main module. + """ + return self.get_module_base() + + def get_module_base(self): + """ + @rtype: int + @return: Base address of the main module. + """ + return self.get_module().get_base() + + def get_module(self): + """ + @rtype: L{Module} + @return: Main module of the process. + """ + return self.get_process().get_main_module() + +#============================================================================== + +class LoadDLLEvent (Event): + """ + Module load event. + """ + + eventMethod = 'load_dll' + eventName = 'Module load event' + eventDescription = 'A new DLL library was loaded by the debugee.' + + def get_module_base(self): + """ + @rtype: int + @return: Base address for the newly loaded DLL. + """ + return self.raw.u.LoadDll.lpBaseOfDll + + def get_module(self): + """ + @rtype: L{Module} + @return: Module object for the newly loaded DLL. + """ + lpBaseOfDll = self.get_module_base() + aProcess = self.get_process() + if aProcess.has_module(lpBaseOfDll): + aModule = aProcess.get_module(lpBaseOfDll) + else: + # XXX HACK + # For some reason the module object is missing, so make a new one. + aModule = Module(lpBaseOfDll, + hFile = self.get_file_handle(), + fileName = self.get_filename(), + process = aProcess) + aProcess._add_module(aModule) + return aModule + + def get_file_handle(self): + """ + @rtype: L{FileHandle} or None + @return: File handle to the newly loaded DLL received from the system. + Returns C{None} if the handle is not available. + """ + # This handle DOES need to be closed. + # Therefore we must cache it so it doesn't + # get closed after the first call. + try: + hFile = self.__hFile + except AttributeError: + hFile = self.raw.u.LoadDll.hFile + if hFile in (0, win32.NULL, win32.INVALID_HANDLE_VALUE): + hFile = None + else: + hFile = FileHandle(hFile, True) + self.__hFile = hFile + return hFile + + def get_filename(self): + """ + @rtype: str, None + @return: This method does it's best to retrieve the filename to + the newly loaded module. However, sometimes that's not + possible, and C{None} is returned instead. + """ + szFilename = None + + # Try to get it from LOAD_DLL_DEBUG_INFO.lpImageName + # It's NULL or *NULL most of the times, see MSDN: + # http://msdn.microsoft.com/en-us/library/ms679286(VS.85).aspx + aProcess = self.get_process() + lpRemoteFilenamePtr = self.raw.u.LoadDll.lpImageName + if lpRemoteFilenamePtr: + lpFilename = aProcess.peek_uint(lpRemoteFilenamePtr) + fUnicode = bool( self.raw.u.LoadDll.fUnicode ) + szFilename = aProcess.peek_string(lpFilename, fUnicode) + if not szFilename: + szFilename = None + + # Try to get the filename from the file handle. + if not szFilename: + hFile = self.get_file_handle() + if hFile: + szFilename = hFile.get_filename() + + # Return the filename, or None on error. + return szFilename + +#============================================================================== + +class UnloadDLLEvent (Event): + """ + Module unload event. + """ + + eventMethod = 'unload_dll' + eventName = 'Module unload event' + eventDescription = 'A DLL library was unloaded by the debugee.' + + def get_module_base(self): + """ + @rtype: int + @return: Base address for the recently unloaded DLL. + """ + return self.raw.u.UnloadDll.lpBaseOfDll + + def get_module(self): + """ + @rtype: L{Module} + @return: Module object for the recently unloaded DLL. + """ + lpBaseOfDll = self.get_module_base() + aProcess = self.get_process() + if aProcess.has_module(lpBaseOfDll): + aModule = aProcess.get_module(lpBaseOfDll) + else: + aModule = Module(lpBaseOfDll, process = aProcess) + aProcess._add_module(aModule) + return aModule + + def get_file_handle(self): + """ + @rtype: None or L{FileHandle} + @return: File handle to the recently unloaded DLL. + Returns C{None} if the handle is not available. + """ + hFile = self.get_module().hFile + if hFile in (0, win32.NULL, win32.INVALID_HANDLE_VALUE): + hFile = None + return hFile + + def get_filename(self): + """ + @rtype: None or str + @return: Filename of the recently unloaded DLL. + C{None} if the filename is unknown. + """ + return self.get_module().get_filename() + +#============================================================================== + +class OutputDebugStringEvent (Event): + """ + Debug string output event. + """ + + eventMethod = 'output_string' + eventName = 'Debug string output event' + eventDescription = 'The debugee sent a message to the debugger.' + + def get_debug_string(self): + """ + @rtype: str, compat.unicode + @return: String sent by the debugee. + It may be ANSI or Unicode and may end with a null character. + """ + return self.get_process().peek_string( + self.raw.u.DebugString.lpDebugStringData, + bool( self.raw.u.DebugString.fUnicode ), + self.raw.u.DebugString.nDebugStringLength) + +#============================================================================== + +class RIPEvent (Event): + """ + RIP event. + """ + + eventMethod = 'rip' + eventName = 'RIP event' + eventDescription = 'An error has occured and the process ' \ + 'can no longer be debugged.' + + def get_rip_error(self): + """ + @rtype: int + @return: RIP error code as defined by the Win32 API. + """ + return self.raw.u.RipInfo.dwError + + def get_rip_type(self): + """ + @rtype: int + @return: RIP type code as defined by the Win32 API. + May be C{0} or one of the following: + - L{win32.SLE_ERROR} + - L{win32.SLE_MINORERROR} + - L{win32.SLE_WARNING} + """ + return self.raw.u.RipInfo.dwType + +#============================================================================== + +class EventFactory (StaticClass): + """ + Factory of L{Event} objects. + + @type baseEvent: L{Event} + @cvar baseEvent: + Base class for Event objects. + It's used for unknown event codes. + + @type eventClasses: dict( int S{->} L{Event} ) + @cvar eventClasses: + Dictionary that maps event codes to L{Event} subclasses. + """ + + baseEvent = Event + eventClasses = { + win32.EXCEPTION_DEBUG_EVENT : ExceptionEvent, # 1 + win32.CREATE_THREAD_DEBUG_EVENT : CreateThreadEvent, # 2 + win32.CREATE_PROCESS_DEBUG_EVENT : CreateProcessEvent, # 3 + win32.EXIT_THREAD_DEBUG_EVENT : ExitThreadEvent, # 4 + win32.EXIT_PROCESS_DEBUG_EVENT : ExitProcessEvent, # 5 + win32.LOAD_DLL_DEBUG_EVENT : LoadDLLEvent, # 6 + win32.UNLOAD_DLL_DEBUG_EVENT : UnloadDLLEvent, # 7 + win32.OUTPUT_DEBUG_STRING_EVENT : OutputDebugStringEvent, # 8 + win32.RIP_EVENT : RIPEvent, # 9 + } + + @classmethod + def get(cls, debug, raw): + """ + @type debug: L{Debug} + @param debug: Debug object that received the event. + + @type raw: L{DEBUG_EVENT} + @param raw: Raw DEBUG_EVENT structure as used by the Win32 API. + + @rtype: L{Event} + @returns: An Event object or one of it's subclasses, + depending on the event type. + """ + eventClass = cls.eventClasses.get(raw.dwDebugEventCode, cls.baseEvent) + return eventClass(debug, raw) + +#============================================================================== + +class EventHandler (object): + """ + Base class for debug event handlers. + + Your program should subclass it to implement it's own event handling. + + The constructor can be overriden as long as you call the superclass + constructor. The special method L{__call__} B{MUST NOT} be overriden. + + The signature for event handlers is the following:: + + def event_handler(self, event): + + Where B{event} is an L{Event} object. + + Each event handler is named after the event they handle. + This is the list of all valid event handler names: + + - I{event} + + Receives an L{Event} object or an object of any of it's subclasses, + and handles any event for which no handler was defined. + + - I{unknown_event} + + Receives an L{Event} object or an object of any of it's subclasses, + and handles any event unknown to the debugging engine. (This is not + likely to happen unless the Win32 debugging API is changed in future + versions of Windows). + + - I{exception} + + Receives an L{ExceptionEvent} object and handles any exception for + which no handler was defined. See above for exception handlers. + + - I{unknown_exception} + + Receives an L{ExceptionEvent} object and handles any exception unknown + to the debugging engine. This usually happens for C++ exceptions, which + are not standardized and may change from one compiler to the next. + + Currently we have partial support for C++ exceptions thrown by Microsoft + compilers. + + Also see: U{RaiseException() + } + + - I{create_thread} + + Receives a L{CreateThreadEvent} object. + + - I{create_process} + + Receives a L{CreateProcessEvent} object. + + - I{exit_thread} + + Receives a L{ExitThreadEvent} object. + + - I{exit_process} + + Receives a L{ExitProcessEvent} object. + + - I{load_dll} + + Receives a L{LoadDLLEvent} object. + + - I{unload_dll} + + Receives an L{UnloadDLLEvent} object. + + - I{output_string} + + Receives an L{OutputDebugStringEvent} object. + + - I{rip} + + Receives a L{RIPEvent} object. + + This is the list of all valid exception handler names + (they all receive an L{ExceptionEvent} object): + + - I{access_violation} + - I{array_bounds_exceeded} + - I{breakpoint} + - I{control_c_exit} + - I{datatype_misalignment} + - I{debug_control_c} + - I{float_denormal_operand} + - I{float_divide_by_zero} + - I{float_inexact_result} + - I{float_invalid_operation} + - I{float_overflow} + - I{float_stack_check} + - I{float_underflow} + - I{guard_page} + - I{illegal_instruction} + - I{in_page_error} + - I{integer_divide_by_zero} + - I{integer_overflow} + - I{invalid_disposition} + - I{invalid_handle} + - I{ms_vc_exception} + - I{noncontinuable_exception} + - I{possible_deadlock} + - I{privileged_instruction} + - I{single_step} + - I{stack_overflow} + - I{wow64_breakpoint} + + + + @type apiHooks: dict( str S{->} list( tuple( str, int ) ) ) + @cvar apiHooks: + Dictionary that maps module names to lists of + tuples of ( procedure name, parameter count ). + + All procedures listed here will be hooked for calls from the debugee. + When this happens, the corresponding event handler can be notified both + when the procedure is entered and when it's left by the debugee. + + For example, let's hook the LoadLibraryEx() API call. + This would be the declaration of apiHooks:: + + from winappdbg import EventHandler + from winappdbg.win32 import * + + # (...) + + class MyEventHandler (EventHandler): + + apiHook = { + + "kernel32.dll" : ( + + # Procedure name Signature + ( "LoadLibraryEx", (PVOID, HANDLE, DWORD) ), + + # (more procedures can go here...) + ), + + # (more libraries can go here...) + } + + # (your method definitions go here...) + + Note that all pointer types are treated like void pointers, so your + callback won't get the string or structure pointed to by it, but the + remote memory address instead. This is so to prevent the ctypes library + from being "too helpful" and trying to dereference the pointer. To get + the actual data being pointed to, use one of the L{Process.read} + methods. + + Now, to intercept calls to LoadLibraryEx define a method like this in + your event handler class:: + + def pre_LoadLibraryEx(self, event, ra, lpFilename, hFile, dwFlags): + szFilename = event.get_process().peek_string(lpFilename) + + # (...) + + Note that the first parameter is always the L{Event} object, and the + second parameter is the return address. The third parameter and above + are the values passed to the hooked function. + + Finally, to intercept returns from calls to LoadLibraryEx define a + method like this:: + + def post_LoadLibraryEx(self, event, retval): + # (...) + + The first parameter is the L{Event} object and the second is the + return value from the hooked function. + """ + +#------------------------------------------------------------------------------ + + # Default (empty) API hooks dictionary. + apiHooks = {} + + def __init__(self): + """ + Class constructor. Don't forget to call it when subclassing! + + Forgetting to call the superclass constructor is a common mistake when + you're new to Python. :) + + Example:: + class MyEventHandler (EventHandler): + + # Override the constructor to use an extra argument. + def __init__(self, myArgument): + + # Do something with the argument, like keeping it + # as an instance variable. + self.myVariable = myArgument + + # Call the superclass constructor. + super(MyEventHandler, self).__init__() + + # The rest of your code below... + """ + + # TODO + # All this does is set up the hooks. + # This code should be moved to the EventDispatcher class. + # Then the hooks can be set up at set_event_handler() instead, making + # this class even simpler. The downside here is deciding where to store + # the ApiHook objects. + + # Convert the tuples into instances of the ApiHook class. + # A new dictionary must be instanced, otherwise we could also be + # affecting all other instances of the EventHandler. + apiHooks = dict() + for lib, hooks in compat.iteritems(self.apiHooks): + hook_objs = [] + for proc, args in hooks: + if type(args) in (int, long): + h = ApiHook(self, lib, proc, paramCount = args) + else: + h = ApiHook(self, lib, proc, signature = args) + hook_objs.append(h) + apiHooks[lib] = hook_objs + self.__apiHooks = apiHooks + + def __get_hooks_for_dll(self, event): + """ + Get the requested API hooks for the current DLL. + + Used by L{__hook_dll} and L{__unhook_dll}. + """ + result = [] + if self.__apiHooks: + path = event.get_module().get_filename() + if path: + lib_name = PathOperations.pathname_to_filename(path).lower() + for hook_lib, hook_api_list in compat.iteritems(self.__apiHooks): + if hook_lib == lib_name: + result.extend(hook_api_list) + return result + + def __hook_dll(self, event): + """ + Hook the requested API calls (in self.apiHooks). + + This method is called automatically whenever a DLL is loaded. + """ + debug = event.debug + pid = event.get_pid() + for hook_api_stub in self.__get_hooks_for_dll(event): + hook_api_stub.hook(debug, pid) + + def __unhook_dll(self, event): + """ + Unhook the requested API calls (in self.apiHooks). + + This method is called automatically whenever a DLL is unloaded. + """ + debug = event.debug + pid = event.get_pid() + for hook_api_stub in self.__get_hooks_for_dll(event): + hook_api_stub.unhook(debug, pid) + + def __call__(self, event): + """ + Dispatch debug events. + + @warn: B{Don't override this method!} + + @type event: L{Event} + @param event: Event object. + """ + try: + code = event.get_event_code() + if code == win32.LOAD_DLL_DEBUG_EVENT: + self.__hook_dll(event) + elif code == win32.UNLOAD_DLL_DEBUG_EVENT: + self.__unhook_dll(event) + finally: + method = EventDispatcher.get_handler_method(self, event) + if method is not None: + return method(event) + +#============================================================================== + +# TODO +# * Make it more generic by adding a few more callbacks. +# That way it will be possible to make a thread sifter too. +# * This interface feels too much like an antipattern. +# When apiHooks is deprecated this will have to be reviewed. + +class EventSift(EventHandler): + """ + Event handler that allows you to use customized event handlers for each + process you're attached to. + + This makes coding the event handlers much easier, because each instance + will only "know" about one process. So you can code your event handler as + if only one process was being debugged, but your debugger can attach to + multiple processes. + + Example:: + from winappdbg import Debug, EventHandler, EventSift + + # This class was written assuming only one process is attached. + # If you used it directly it would break when attaching to another + # process, or when a child process is spawned. + class MyEventHandler (EventHandler): + + def create_process(self, event): + self.first = True + self.name = event.get_process().get_filename() + print "Attached to %s" % self.name + + def breakpoint(self, event): + if self.first: + self.first = False + print "First breakpoint reached at %s" % self.name + + def exit_process(self, event): + print "Detached from %s" % self.name + + # Now when debugging we use the EventSift to be able to work with + # multiple processes while keeping our code simple. :) + if __name__ == "__main__": + handler = EventSift(MyEventHandler) + #handler = MyEventHandler() # try uncommenting this line... + with Debug(handler) as debug: + debug.execl("calc.exe") + debug.execl("notepad.exe") + debug.execl("charmap.exe") + debug.loop() + + Subclasses of C{EventSift} can prevent specific event types from + being forwarded by simply defining a method for it. That means your + subclass can handle some event types globally while letting other types + be handled on per-process basis. To forward events manually you can + call C{self.event(event)}. + + Example:: + class MySift (EventSift): + + # Don't forward this event. + def debug_control_c(self, event): + pass + + # Handle this event globally without forwarding it. + def output_string(self, event): + print "Debug string: %s" % event.get_debug_string() + + # Handle this event globally and then forward it. + def create_process(self, event): + print "New process created, PID: %d" % event.get_pid() + return self.event(event) + + # All other events will be forwarded. + + Note that overriding the C{event} method would cause no events to be + forwarded at all. To prevent this, call the superclass implementation. + + Example:: + + def we_want_to_forward_this_event(event): + "Use whatever logic you want here..." + # (...return True or False...) + + class MySift (EventSift): + + def event(self, event): + + # If the event matches some custom criteria... + if we_want_to_forward_this_event(event): + + # Forward it. + return super(MySift, self).event(event) + + # Otherwise, don't. + + @type cls: class + @ivar cls: + Event handler class. There will be one instance of this class + per debugged process in the L{forward} dictionary. + + @type argv: list + @ivar argv: + Positional arguments to pass to the constructor of L{cls}. + + @type argd: list + @ivar argd: + Keyword arguments to pass to the constructor of L{cls}. + + @type forward: dict + @ivar forward: + Dictionary that maps each debugged process ID to an instance of L{cls}. + """ + + def __init__(self, cls, *argv, **argd): + """ + Maintains an instance of your event handler for each process being + debugged, and forwards the events of each process to each corresponding + instance. + + @warn: If you subclass L{EventSift} and reimplement this method, + don't forget to call the superclass constructor! + + @see: L{event} + + @type cls: class + @param cls: Event handler class. This must be the class itself, not an + instance! All additional arguments passed to the constructor of + the event forwarder will be passed on to the constructor of this + class as well. + """ + self.cls = cls + self.argv = argv + self.argd = argd + self.forward = dict() + super(EventSift, self).__init__() + + # XXX HORRIBLE HACK + # This makes apiHooks work in the inner handlers. + def __call__(self, event): + try: + eventCode = event.get_event_code() + if eventCode in (win32.LOAD_DLL_DEBUG_EVENT, + win32.LOAD_DLL_DEBUG_EVENT): + pid = event.get_pid() + handler = self.forward.get(pid, None) + if handler is None: + handler = self.cls(*self.argv, **self.argd) + self.forward[pid] = handler + if isinstance(handler, EventHandler): + if eventCode == win32.LOAD_DLL_DEBUG_EVENT: + handler.__EventHandler_hook_dll(event) + else: + handler.__EventHandler_unhook_dll(event) + finally: + return super(EventSift, self).__call__(event) + + def event(self, event): + """ + Forwards events to the corresponding instance of your event handler + for this process. + + If you subclass L{EventSift} and reimplement this method, no event + will be forwarded at all unless you call the superclass implementation. + + If your filtering is based on the event type, there's a much easier way + to do it: just implement a handler for it. + """ + eventCode = event.get_event_code() + pid = event.get_pid() + handler = self.forward.get(pid, None) + if handler is None: + handler = self.cls(*self.argv, **self.argd) + if eventCode != win32.EXIT_PROCESS_DEBUG_EVENT: + self.forward[pid] = handler + elif eventCode == win32.EXIT_PROCESS_DEBUG_EVENT: + del self.forward[pid] + return handler(event) + +#============================================================================== + +class EventDispatcher (object): + """ + Implements debug event dispatching capabilities. + + @group Debugging events: + get_event_handler, set_event_handler, get_handler_method + """ + + # Maps event code constants to the names of the pre-notify routines. + # These routines are called BEFORE the user-defined handlers. + # Unknown codes are ignored. + __preEventNotifyCallbackName = { + win32.CREATE_THREAD_DEBUG_EVENT : '_notify_create_thread', + win32.CREATE_PROCESS_DEBUG_EVENT : '_notify_create_process', + win32.LOAD_DLL_DEBUG_EVENT : '_notify_load_dll', + } + + # Maps event code constants to the names of the post-notify routines. + # These routines are called AFTER the user-defined handlers. + # Unknown codes are ignored. + __postEventNotifyCallbackName = { + win32.EXIT_THREAD_DEBUG_EVENT : '_notify_exit_thread', + win32.EXIT_PROCESS_DEBUG_EVENT : '_notify_exit_process', + win32.UNLOAD_DLL_DEBUG_EVENT : '_notify_unload_dll', + win32.RIP_EVENT : '_notify_rip', + } + + # Maps exception code constants to the names of the pre-notify routines. + # These routines are called BEFORE the user-defined handlers. + # Unknown codes are ignored. + __preExceptionNotifyCallbackName = { + win32.EXCEPTION_BREAKPOINT : '_notify_breakpoint', + win32.EXCEPTION_WX86_BREAKPOINT : '_notify_breakpoint', + win32.EXCEPTION_SINGLE_STEP : '_notify_single_step', + win32.EXCEPTION_GUARD_PAGE : '_notify_guard_page', + win32.DBG_CONTROL_C : '_notify_debug_control_c', + win32.MS_VC_EXCEPTION : '_notify_ms_vc_exception', + } + + # Maps exception code constants to the names of the post-notify routines. + # These routines are called AFTER the user-defined handlers. + # Unknown codes are ignored. + __postExceptionNotifyCallbackName = { + } + + def __init__(self, eventHandler = None): + """ + Event dispatcher. + + @type eventHandler: L{EventHandler} + @param eventHandler: (Optional) User-defined event handler. + + @raise TypeError: The event handler is of an incorrect type. + + @note: The L{eventHandler} parameter may be any callable Python object + (for example a function, or an instance method). + However you'll probably find it more convenient to use an instance + of a subclass of L{EventHandler} here. + """ + self.set_event_handler(eventHandler) + + def get_event_handler(self): + """ + Get the event handler. + + @see: L{set_event_handler} + + @rtype: L{EventHandler} + @return: Current event handler object, or C{None}. + """ + return self.__eventHandler + + def set_event_handler(self, eventHandler): + """ + Set the event handler. + + @warn: This is normally not needed. Use with care! + + @type eventHandler: L{EventHandler} + @param eventHandler: New event handler object, or C{None}. + + @rtype: L{EventHandler} + @return: Previous event handler object, or C{None}. + + @raise TypeError: The event handler is of an incorrect type. + + @note: The L{eventHandler} parameter may be any callable Python object + (for example a function, or an instance method). + However you'll probably find it more convenient to use an instance + of a subclass of L{EventHandler} here. + """ + if eventHandler is not None and not callable(eventHandler): + raise TypeError("Event handler must be a callable object") + try: + wrong_type = issubclass(eventHandler, EventHandler) + except TypeError: + wrong_type = False + if wrong_type: + classname = str(eventHandler) + msg = "Event handler must be an instance of class %s" + msg += "rather than the %s class itself. (Missing parens?)" + msg = msg % (classname, classname) + raise TypeError(msg) + try: + previous = self.__eventHandler + except AttributeError: + previous = None + self.__eventHandler = eventHandler + return previous + + @staticmethod + def get_handler_method(eventHandler, event, fallback=None): + """ + Retrieves the appropriate callback method from an L{EventHandler} + instance for the given L{Event} object. + + @type eventHandler: L{EventHandler} + @param eventHandler: + Event handler object whose methods we are examining. + + @type event: L{Event} + @param event: Debugging event to be handled. + + @type fallback: callable + @param fallback: (Optional) If no suitable method is found in the + L{EventHandler} instance, return this value. + + @rtype: callable + @return: Bound method that will handle the debugging event. + Returns C{None} if no such method is defined. + """ + eventCode = event.get_event_code() + method = getattr(eventHandler, 'event', fallback) + if eventCode == win32.EXCEPTION_DEBUG_EVENT: + method = getattr(eventHandler, 'exception', method) + method = getattr(eventHandler, event.eventMethod, method) + return method + + def dispatch(self, event): + """ + Sends event notifications to the L{Debug} object and + the L{EventHandler} object provided by the user. + + The L{Debug} object will forward the notifications to it's contained + snapshot objects (L{System}, L{Process}, L{Thread} and L{Module}) when + appropriate. + + @warning: This method is called automatically from L{Debug.dispatch}. + + @see: L{Debug.cont}, L{Debug.loop}, L{Debug.wait} + + @type event: L{Event} + @param event: Event object passed to L{Debug.dispatch}. + + @raise WindowsError: Raises an exception on error. + """ + returnValue = None + bCallHandler = True + pre_handler = None + post_handler = None + eventCode = event.get_event_code() + + # Get the pre and post notification methods for exceptions. + # If not found, the following steps take care of that. + if eventCode == win32.EXCEPTION_DEBUG_EVENT: + exceptionCode = event.get_exception_code() + pre_name = self.__preExceptionNotifyCallbackName.get( + exceptionCode, None) + post_name = self.__postExceptionNotifyCallbackName.get( + exceptionCode, None) + if pre_name is not None: + pre_handler = getattr(self, pre_name, None) + if post_name is not None: + post_handler = getattr(self, post_name, None) + + # Get the pre notification method for all other events. + # This includes the exception event if no notify method was found + # for this exception code. + if pre_handler is None: + pre_name = self.__preEventNotifyCallbackName.get(eventCode, None) + if pre_name is not None: + pre_handler = getattr(self, pre_name, pre_handler) + + # Get the post notification method for all other events. + # This includes the exception event if no notify method was found + # for this exception code. + if post_handler is None: + post_name = self.__postEventNotifyCallbackName.get(eventCode, None) + if post_name is not None: + post_handler = getattr(self, post_name, post_handler) + + # Call the pre-notify method only if it was defined. + # If an exception is raised don't call the other methods. + if pre_handler is not None: + bCallHandler = pre_handler(event) + + # Call the user-defined event handler only if the pre-notify + # method was not defined, or was and it returned True. + try: + if bCallHandler and self.__eventHandler is not None: + try: + returnValue = self.__eventHandler(event) + except Exception: + e = sys.exc_info()[1] + msg = ("Event handler pre-callback %r" + " raised an exception: %s") + msg = msg % (self.__eventHandler, traceback.format_exc(e)) + warnings.warn(msg, EventCallbackWarning) + returnValue = None + + # Call the post-notify method if defined, even if an exception is + # raised by the user-defined event handler. + finally: + if post_handler is not None: + post_handler(event) + + # Return the value from the call to the user-defined event handler. + # If not defined return None. + return returnValue diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/interactive.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/interactive.py new file mode 100644 index 0000000..f14883a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/interactive.py @@ -0,0 +1,2281 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Acknowledgements: +# Nicolas Economou, for his command line debugger on which this is inspired. +# http://tinyurl.com/nicolaseconomou + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Interactive debugging console. + +@group Debugging: + ConsoleDebugger + +@group Exceptions: + CmdError +""" + +from __future__ import with_statement + +__revision__ = "$Id$" + +__all__ = [ 'ConsoleDebugger', 'CmdError' ] + +# TODO document this module with docstrings. +# TODO command to set a last error breakpoint. +# TODO command to show available plugins. + +from winappdbg import win32 +from winappdbg import compat +from winappdbg.system import System +from winappdbg.util import PathOperations +from winappdbg.event import EventHandler, NoEvent +from winappdbg.textio import HexInput, HexOutput, HexDump, CrashDump, DebugLog + +import os +import sys +import code +import time +import warnings +import traceback + +# too many variables named "cmd" to have a module by the same name :P +from cmd import Cmd + +# lazy imports +readline = None + +#============================================================================== + +class DummyEvent (NoEvent): + "Dummy event object used internally by L{ConsoleDebugger}." + + def get_pid(self): + return self._pid + + def get_tid(self): + return self._tid + + def get_process(self): + return self._process + + def get_thread(self): + return self._thread + +#============================================================================== + +class CmdError (Exception): + """ + Exception raised when a command parsing error occurs. + Used internally by L{ConsoleDebugger}. + """ + +#============================================================================== + +class ConsoleDebugger (Cmd, EventHandler): + """ + Interactive console debugger. + + @see: L{Debug.interactive} + """ + +#------------------------------------------------------------------------------ +# Class variables + + # Exception to raise when an error occurs executing a command. + command_error_exception = CmdError + + # Milliseconds to wait for debug events in the main loop. + dwMilliseconds = 100 + + # History file name. + history_file = '.winappdbg_history' + + # Confirm before quitting? + confirm_quit = True + + # Valid plugin name characters. + valid_plugin_name_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXY' \ + 'abcdefghijklmnopqrstuvwxy' \ + '012345678' \ + '_' + + # Names of the registers. + segment_names = ( 'cs', 'ds', 'es', 'fs', 'gs' ) + + register_alias_64_to_32 = { + 'eax':'Rax', 'ebx':'Rbx', 'ecx':'Rcx', 'edx':'Rdx', + 'eip':'Rip', 'ebp':'Rbp', 'esp':'Rsp', 'esi':'Rsi', 'edi':'Rdi' + } + register_alias_64_to_16 = { 'ax':'Rax', 'bx':'Rbx', 'cx':'Rcx', 'dx':'Rdx' } + register_alias_64_to_8_low = { 'al':'Rax', 'bl':'Rbx', 'cl':'Rcx', 'dl':'Rdx' } + register_alias_64_to_8_high = { 'ah':'Rax', 'bh':'Rbx', 'ch':'Rcx', 'dh':'Rdx' } + register_alias_32_to_16 = { 'ax':'Eax', 'bx':'Ebx', 'cx':'Ecx', 'dx':'Edx' } + register_alias_32_to_8_low = { 'al':'Eax', 'bl':'Ebx', 'cl':'Ecx', 'dl':'Edx' } + register_alias_32_to_8_high = { 'ah':'Eax', 'bh':'Ebx', 'ch':'Ecx', 'dh':'Edx' } + + register_aliases_full_32 = list(segment_names) + register_aliases_full_32.extend(compat.iterkeys(register_alias_32_to_16)) + register_aliases_full_32.extend(compat.iterkeys(register_alias_32_to_8_low)) + register_aliases_full_32.extend(compat.iterkeys(register_alias_32_to_8_high)) + register_aliases_full_32 = tuple(register_aliases_full_32) + + register_aliases_full_64 = list(segment_names) + register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_32)) + register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_16)) + register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_8_low)) + register_aliases_full_64.extend(compat.iterkeys(register_alias_64_to_8_high)) + register_aliases_full_64 = tuple(register_aliases_full_64) + + # Names of the control flow instructions. + jump_instructions = ( + 'jmp', 'jecxz', 'jcxz', + 'ja', 'jnbe', 'jae', 'jnb', 'jb', 'jnae', 'jbe', 'jna', 'jc', 'je', + 'jz', 'jnc', 'jne', 'jnz', 'jnp', 'jpo', 'jp', 'jpe', 'jg', 'jnle', + 'jge', 'jnl', 'jl', 'jnge', 'jle', 'jng', 'jno', 'jns', 'jo', 'js' + ) + call_instructions = ( 'call', 'ret', 'retn' ) + loop_instructions = ( 'loop', 'loopz', 'loopnz', 'loope', 'loopne' ) + control_flow_instructions = call_instructions + loop_instructions + \ + jump_instructions + +#------------------------------------------------------------------------------ +# Instance variables + + def __init__(self): + """ + Interactive console debugger. + + @see: L{Debug.interactive} + """ + Cmd.__init__(self) + EventHandler.__init__(self) + + # Quit the debugger when True. + self.debuggerExit = False + + # Full path to the history file. + self.history_file_full_path = None + + # Last executed command. + self.__lastcmd = "" + +#------------------------------------------------------------------------------ +# Debugger + + # Use this Debug object. + def start_using_debugger(self, debug): + + # Clear the previous Debug object. + self.stop_using_debugger() + + # Keep the Debug object. + self.debug = debug + + # Set ourselves as the event handler for the debugger. + self.prevHandler = debug.set_event_handler(self) + + # Stop using the Debug object given by start_using_debugger(). + # Circular references must be removed, or the destructors never get called. + def stop_using_debugger(self): + if hasattr(self, 'debug'): + debug = self.debug + debug.set_event_handler(self.prevHandler) + del self.prevHandler + del self.debug + return debug + return None + + # Destroy the Debug object. + def destroy_debugger(self, autodetach = True): + debug = self.stop_using_debugger() + if debug is not None: + if not autodetach: + debug.kill_all(bIgnoreExceptions=True) + debug.lastEvent = None + debug.stop() + del debug + + @property + def lastEvent(self): + return self.debug.lastEvent + + def set_fake_last_event(self, process): + if self.lastEvent is None: + self.debug.lastEvent = DummyEvent(self.debug) + self.debug.lastEvent._process = process + self.debug.lastEvent._thread = process.get_thread( + process.get_thread_ids()[0]) + self.debug.lastEvent._pid = process.get_pid() + self.debug.lastEvent._tid = self.lastEvent._thread.get_tid() + +#------------------------------------------------------------------------------ +# Input + +# TODO +# * try to guess breakpoints when insufficient data is given +# * child Cmd instances will have to be used for other prompts, for example +# when assembling or editing memory - it may also be a good idea to think +# if it's possible to make the main Cmd instance also a child, instead of +# the debugger itself - probably the same goes for the EventHandler, maybe +# it can be used as a contained object rather than a parent class. + + # Join a token list into an argument string. + def join_tokens(self, token_list): + return self.debug.system.argv_to_cmdline(token_list) + + # Split an argument string into a token list. + def split_tokens(self, arg, min_count = 0, max_count = None): + token_list = self.debug.system.cmdline_to_argv(arg) + if len(token_list) < min_count: + raise CmdError("missing parameters.") + if max_count and len(token_list) > max_count: + raise CmdError("too many parameters.") + return token_list + + # Token is a thread ID or name. + def input_thread(self, token): + targets = self.input_thread_list( [token] ) + if len(targets) == 0: + raise CmdError("missing thread name or ID") + if len(targets) > 1: + msg = "more than one thread with that name:\n" + for tid in targets: + msg += "\t%d\n" % tid + msg = msg[:-len("\n")] + raise CmdError(msg) + return targets[0] + + # Token list is a list of thread IDs or names. + def input_thread_list(self, token_list): + targets = set() + system = self.debug.system + for token in token_list: + try: + tid = self.input_integer(token) + if not system.has_thread(tid): + raise CmdError("thread not found (%d)" % tid) + targets.add(tid) + except ValueError: + found = set() + for process in system.iter_processes(): + found.update( system.find_threads_by_name(token) ) + if not found: + raise CmdError("thread not found (%s)" % token) + for thread in found: + targets.add( thread.get_tid() ) + targets = list(targets) + targets.sort() + return targets + + # Token is a process ID or name. + def input_process(self, token): + targets = self.input_process_list( [token] ) + if len(targets) == 0: + raise CmdError("missing process name or ID") + if len(targets) > 1: + msg = "more than one process with that name:\n" + for pid in targets: + msg += "\t%d\n" % pid + msg = msg[:-len("\n")] + raise CmdError(msg) + return targets[0] + + # Token list is a list of process IDs or names. + def input_process_list(self, token_list): + targets = set() + system = self.debug.system + for token in token_list: + try: + pid = self.input_integer(token) + if not system.has_process(pid): + raise CmdError("process not found (%d)" % pid) + targets.add(pid) + except ValueError: + found = system.find_processes_by_filename(token) + if not found: + raise CmdError("process not found (%s)" % token) + for (process, _) in found: + targets.add( process.get_pid() ) + targets = list(targets) + targets.sort() + return targets + + # Token is a command line to execute. + def input_command_line(self, command_line): + argv = self.debug.system.cmdline_to_argv(command_line) + if not argv: + raise CmdError("missing command line to execute") + fname = argv[0] + if not os.path.exists(fname): + try: + fname, _ = win32.SearchPath(None, fname, '.exe') + except WindowsError: + raise CmdError("file not found: %s" % fname) + argv[0] = fname + command_line = self.debug.system.argv_to_cmdline(argv) + return command_line + + # Token is an integer. + # Only hexadecimal format is supported. + def input_hexadecimal_integer(self, token): + return int(token, 0x10) + + # Token is an integer. + # It can be in any supported format. + def input_integer(self, token): + return HexInput.integer(token) +## input_integer = input_hexadecimal_integer + + # Token is an address. + # The address can be a integer, a label or a register. + def input_address(self, token, pid = None, tid = None): + address = None + if self.is_register(token): + if tid is None: + if self.lastEvent is None or pid != self.lastEvent.get_pid(): + msg = "can't resolve register (%s) for unknown thread" + raise CmdError(msg % token) + tid = self.lastEvent.get_tid() + address = self.input_register(token, tid) + if address is None: + try: + address = self.input_hexadecimal_integer(token) + except ValueError: + if pid is None: + if self.lastEvent is None: + raise CmdError("no current process set") + process = self.lastEvent.get_process() + elif self.lastEvent is not None and pid == self.lastEvent.get_pid(): + process = self.lastEvent.get_process() + else: + try: + process = self.debug.system.get_process(pid) + except KeyError: + raise CmdError("process not found (%d)" % pid) + try: + address = process.resolve_label(token) + except Exception: + raise CmdError("unknown address (%s)" % token) + return address + + # Token is an address range, or a single address. + # The addresses can be integers, labels or registers. + def input_address_range(self, token_list, pid = None, tid = None): + if len(token_list) == 2: + token_1, token_2 = token_list + address = self.input_address(token_1, pid, tid) + try: + size = self.input_integer(token_2) + except ValueError: + raise CmdError("bad address range: %s %s" % (token_1, token_2)) + elif len(token_list) == 1: + token = token_list[0] + if '-' in token: + try: + token_1, token_2 = token.split('-') + except Exception: + raise CmdError("bad address range: %s" % token) + address = self.input_address(token_1, pid, tid) + size = self.input_address(token_2, pid, tid) - address + else: + address = self.input_address(token, pid, tid) + size = None + return address, size + + # XXX TODO + # Support non-integer registers here. + def is_register(self, token): + if win32.arch == 'i386': + if token in self.register_aliases_full_32: + return True + token = token.title() + for (name, typ) in win32.CONTEXT._fields_: + if name == token: + return win32.sizeof(typ) == win32.sizeof(win32.DWORD) + elif win32.arch == 'amd64': + if token in self.register_aliases_full_64: + return True + token = token.title() + for (name, typ) in win32.CONTEXT._fields_: + if name == token: + return win32.sizeof(typ) == win32.sizeof(win32.DWORD64) + return False + + # The token is a register name. + # Returns None if no register name is matched. + def input_register(self, token, tid = None): + if tid is None: + if self.lastEvent is None: + raise CmdError("no current process set") + thread = self.lastEvent.get_thread() + else: + thread = self.debug.system.get_thread(tid) + ctx = thread.get_context() + + token = token.lower() + title = token.title() + + if title in ctx: + return ctx.get(title) # eax -> Eax + + if ctx.arch == 'i386': + + if token in self.segment_names: + return ctx.get( 'Seg%s' % title ) # cs -> SegCs + + if token in self.register_alias_32_to_16: + return ctx.get( self.register_alias_32_to_16[token] ) & 0xFFFF + + if token in self.register_alias_32_to_8_low: + return ctx.get( self.register_alias_32_to_8_low[token] ) & 0xFF + + if token in self.register_alias_32_to_8_high: + return (ctx.get( self.register_alias_32_to_8_high[token] ) & 0xFF00) >> 8 + + elif ctx.arch == 'amd64': + + if token in self.segment_names: + return ctx.get( 'Seg%s' % title ) # cs -> SegCs + + if token in self.register_alias_64_to_32: + return ctx.get( self.register_alias_64_to_32[token] ) & 0xFFFFFFFF + + if token in self.register_alias_64_to_16: + return ctx.get( self.register_alias_64_to_16[token] ) & 0xFFFF + + if token in self.register_alias_64_to_8_low: + return ctx.get( self.register_alias_64_to_8_low[token] ) & 0xFF + + if token in self.register_alias_64_to_8_high: + return (ctx.get( self.register_alias_64_to_8_high[token] ) & 0xFF00) >> 8 + + return None + + # Token list contains an address or address range. + # The prefix is also parsed looking for process and thread IDs. + def input_full_address_range(self, token_list): + pid, tid = self.get_process_and_thread_ids_from_prefix() + address, size = self.input_address_range(token_list, pid, tid) + return pid, tid, address, size + + # Token list contains a breakpoint. + def input_breakpoint(self, token_list): + pid, tid, address, size = self.input_full_address_range(token_list) + if not self.debug.is_debugee(pid): + raise CmdError("target process is not being debugged") + return pid, tid, address, size + + # Token list contains a memory address, and optional size and process. + # Sets the results as the default for the next display command. + def input_display(self, token_list, default_size = 64): + pid, tid, address, size = self.input_full_address_range(token_list) + if not size: + size = default_size + next_address = HexOutput.integer(address + size) + self.default_display_target = next_address + return pid, tid, address, size + +#------------------------------------------------------------------------------ +# Output + + # Tell the user a module was loaded. + def print_module_load(self, event): + mod = event.get_module() + base = mod.get_base() + name = mod.get_filename() + if not name: + name = '' + msg = "Loaded module (%s) %s" + msg = msg % (HexDump.address(base), name) + print(msg) + + # Tell the user a module was unloaded. + def print_module_unload(self, event): + mod = event.get_module() + base = mod.get_base() + name = mod.get_filename() + if not name: + name = '' + msg = "Unloaded module (%s) %s" + msg = msg % (HexDump.address(base), name) + print(msg) + + # Tell the user a process was started. + def print_process_start(self, event): + pid = event.get_pid() + start = event.get_start_address() + if start: + start = HexOutput.address(start) + print("Started process %d at %s" % (pid, start)) + else: + print("Attached to process %d" % pid) + + # Tell the user a thread was started. + def print_thread_start(self, event): + tid = event.get_tid() + start = event.get_start_address() + if start: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + start = event.get_process().get_label_at_address(start) + print("Started thread %d at %s" % (tid, start)) + else: + print("Attached to thread %d" % tid) + + # Tell the user a process has finished. + def print_process_end(self, event): + pid = event.get_pid() + code = event.get_exit_code() + print("Process %d terminated, exit code %d" % (pid, code)) + + # Tell the user a thread has finished. + def print_thread_end(self, event): + tid = event.get_tid() + code = event.get_exit_code() + print("Thread %d terminated, exit code %d" % (tid, code)) + + # Print(debug strings. + def print_debug_string(self, event): + tid = event.get_tid() + string = event.get_debug_string() + print("Thread %d says: %r" % (tid, string)) + + # Inform the user of any other debugging event. + def print_event(self, event): + code = HexDump.integer( event.get_event_code() ) + name = event.get_event_name() + desc = event.get_event_description() + if code in desc: + print('') + print("%s: %s" % (name, desc)) + else: + print('') + print("%s (%s): %s" % (name, code, desc)) + self.print_event_location(event) + + # Stop on exceptions and prompt for commands. + def print_exception(self, event): + address = HexDump.address( event.get_exception_address() ) + code = HexDump.integer( event.get_exception_code() ) + desc = event.get_exception_description() + if event.is_first_chance(): + chance = 'first' + else: + chance = 'second' + if code in desc: + msg = "%s at address %s (%s chance)" % (desc, address, chance) + else: + msg = "%s (%s) at address %s (%s chance)" % (desc, code, address, chance) + print('') + print(msg) + self.print_event_location(event) + + # Show the current location in the code. + def print_event_location(self, event): + process = event.get_process() + thread = event.get_thread() + self.print_current_location(process, thread) + + # Show the current location in the code. + def print_breakpoint_location(self, event): + process = event.get_process() + thread = event.get_thread() + pc = event.get_exception_address() + self.print_current_location(process, thread, pc) + + # Show the current location in any process and thread. + def print_current_location(self, process = None, thread = None, pc = None): + if not process: + if self.lastEvent is None: + raise CmdError("no current process set") + process = self.lastEvent.get_process() + if not thread: + if self.lastEvent is None: + raise CmdError("no current process set") + thread = self.lastEvent.get_thread() + thread.suspend() + try: + if pc is None: + pc = thread.get_pc() + ctx = thread.get_context() + finally: + thread.resume() + label = process.get_label_at_address(pc) + try: + disasm = process.disassemble(pc, 15) + except WindowsError: + disasm = None + except NotImplementedError: + disasm = None + print('') + print(CrashDump.dump_registers(ctx),) + print("%s:" % label) + if disasm: + print(CrashDump.dump_code_line(disasm[0], pc, bShowDump = True)) + else: + try: + data = process.peek(pc, 15) + except Exception: + data = None + if data: + print('%s: %s' % (HexDump.address(pc), HexDump.hexblock_byte(data))) + else: + print('%s: ???' % HexDump.address(pc)) + + # Display memory contents using a given method. + def print_memory_display(self, arg, method): + if not arg: + arg = self.default_display_target + token_list = self.split_tokens(arg, 1, 2) + pid, tid, address, size = self.input_display(token_list) + label = self.get_process(pid).get_label_at_address(address) + data = self.read_memory(address, size, pid) + if data: + print("%s:" % label) + print(method(data, address),) + +#------------------------------------------------------------------------------ +# Debugging + + # Get the process ID from the prefix or the last event. + def get_process_id_from_prefix(self): + if self.cmdprefix: + pid = self.input_process(self.cmdprefix) + else: + if self.lastEvent is None: + raise CmdError("no current process set") + pid = self.lastEvent.get_pid() + return pid + + # Get the thread ID from the prefix or the last event. + def get_thread_id_from_prefix(self): + if self.cmdprefix: + tid = self.input_thread(self.cmdprefix) + else: + if self.lastEvent is None: + raise CmdError("no current process set") + tid = self.lastEvent.get_tid() + return tid + + # Get the process from the prefix or the last event. + def get_process_from_prefix(self): + pid = self.get_process_id_from_prefix() + return self.get_process(pid) + + # Get the thread from the prefix or the last event. + def get_thread_from_prefix(self): + tid = self.get_thread_id_from_prefix() + return self.get_thread(tid) + + # Get the process and thread IDs from the prefix or the last event. + def get_process_and_thread_ids_from_prefix(self): + if self.cmdprefix: + try: + pid = self.input_process(self.cmdprefix) + tid = None + except CmdError: + try: + tid = self.input_thread(self.cmdprefix) + pid = self.debug.system.get_thread(tid).get_pid() + except CmdError: + msg = "unknown process or thread (%s)" % self.cmdprefix + raise CmdError(msg) + else: + if self.lastEvent is None: + raise CmdError("no current process set") + pid = self.lastEvent.get_pid() + tid = self.lastEvent.get_tid() + return pid, tid + + # Get the process and thread from the prefix or the last event. + def get_process_and_thread_from_prefix(self): + pid, tid = self.get_process_and_thread_ids_from_prefix() + process = self.get_process(pid) + thread = self.get_thread(tid) + return process, thread + + # Get the process object. + def get_process(self, pid = None): + if pid is None: + if self.lastEvent is None: + raise CmdError("no current process set") + process = self.lastEvent.get_process() + elif self.lastEvent is not None and pid == self.lastEvent.get_pid(): + process = self.lastEvent.get_process() + else: + try: + process = self.debug.system.get_process(pid) + except KeyError: + raise CmdError("process not found (%d)" % pid) + return process + + # Get the thread object. + def get_thread(self, tid = None): + if tid is None: + if self.lastEvent is None: + raise CmdError("no current process set") + thread = self.lastEvent.get_thread() + elif self.lastEvent is not None and tid == self.lastEvent.get_tid(): + thread = self.lastEvent.get_thread() + else: + try: + thread = self.debug.system.get_thread(tid) + except KeyError: + raise CmdError("thread not found (%d)" % tid) + return thread + + # Read the process memory. + def read_memory(self, address, size, pid = None): + process = self.get_process(pid) + try: + data = process.peek(address, size) + except WindowsError: + orig_address = HexOutput.integer(address) + next_address = HexOutput.integer(address + size) + msg = "error reading process %d, from %s to %s (%d bytes)" + msg = msg % (pid, orig_address, next_address, size) + raise CmdError(msg) + return data + + # Write the process memory. + def write_memory(self, address, data, pid = None): + process = self.get_process(pid) + try: + process.write(address, data) + except WindowsError: + size = len(data) + orig_address = HexOutput.integer(address) + next_address = HexOutput.integer(address + size) + msg = "error reading process %d, from %s to %s (%d bytes)" + msg = msg % (pid, orig_address, next_address, size) + raise CmdError(msg) + + # Change a register value. + def change_register(self, register, value, tid = None): + + # Get the thread. + if tid is None: + if self.lastEvent is None: + raise CmdError("no current process set") + thread = self.lastEvent.get_thread() + else: + try: + thread = self.debug.system.get_thread(tid) + except KeyError: + raise CmdError("thread not found (%d)" % tid) + + # Convert the value to integer type. + try: + value = self.input_integer(value) + except ValueError: + pid = thread.get_pid() + value = self.input_address(value, pid, tid) + + # Suspend the thread. + # The finally clause ensures the thread is resumed before returning. + thread.suspend() + try: + + # Get the current context. + ctx = thread.get_context() + + # Register name matching is case insensitive. + register = register.lower() + + # Integer 32 bits registers. + if register in self.register_names: + register = register.title() # eax -> Eax + + # Segment (16 bit) registers. + if register in self.segment_names: + register = 'Seg%s' % register.title() # cs -> SegCs + value = value & 0x0000FFFF + + # Integer 16 bits registers. + if register in self.register_alias_16: + register = self.register_alias_16[register] + previous = ctx.get(register) & 0xFFFF0000 + value = (value & 0x0000FFFF) | previous + + # Integer 8 bits registers (low part). + if register in self.register_alias_8_low: + register = self.register_alias_8_low[register] + previous = ctx.get(register) % 0xFFFFFF00 + value = (value & 0x000000FF) | previous + + # Integer 8 bits registers (high part). + if register in self.register_alias_8_high: + register = self.register_alias_8_high[register] + previous = ctx.get(register) % 0xFFFF00FF + value = ((value & 0x000000FF) << 8) | previous + + # Set the new context. + ctx.__setitem__(register, value) + thread.set_context(ctx) + + # Resume the thread. + finally: + thread.resume() + + # Very crude way to find data within the process memory. + # TODO: Perhaps pfind.py can be integrated here instead. + def find_in_memory(self, query, process): + for mbi in process.get_memory_map(): + if mbi.State != win32.MEM_COMMIT or mbi.Protect & win32.PAGE_GUARD: + continue + address = mbi.BaseAddress + size = mbi.RegionSize + try: + data = process.read(address, size) + except WindowsError: + msg = "*** Warning: read error at address %s" + msg = msg % HexDump.address(address) + print(msg) + width = min(len(query), 16) + p = data.find(query) + while p >= 0: + q = p + len(query) + d = data[ p : min(q, p + width) ] + h = HexDump.hexline(d, width = width) + a = HexDump.address(address + p) + print("%s: %s" % (a, h)) + p = data.find(query, q) + + # Kill a process. + def kill_process(self, pid): + process = self.debug.system.get_process(pid) + try: + process.kill() + if self.debug.is_debugee(pid): + self.debug.detach(pid) + print("Killed process (%d)" % pid) + except Exception: + print("Error trying to kill process (%d)" % pid) + + # Kill a thread. + def kill_thread(self, tid): + thread = self.debug.system.get_thread(tid) + try: + thread.kill() + process = thread.get_process() + pid = process.get_pid() + if self.debug.is_debugee(pid) and not process.is_alive(): + self.debug.detach(pid) + print("Killed thread (%d)" % tid) + except Exception: + print("Error trying to kill thread (%d)" % tid) + +#------------------------------------------------------------------------------ +# Command prompt input + + # Prompt the user for commands. + def prompt_user(self): + while not self.debuggerExit: + try: + self.cmdloop() + break + except CmdError: + e = sys.exc_info()[1] + print("*** Error: %s" % str(e)) + except Exception: + traceback.print_exc() +## self.debuggerExit = True + + # Prompt the user for a YES/NO kind of question. + def ask_user(self, msg, prompt = "Are you sure? (y/N): "): + print(msg) + answer = raw_input(prompt) + answer = answer.strip()[:1].lower() + return answer == 'y' + + # Autocomplete the given command when not ambiguous. + # Convert it to lowercase (so commands are seen as case insensitive). + def autocomplete(self, cmd): + cmd = cmd.lower() + completed = self.completenames(cmd) + if len(completed) == 1: + cmd = completed[0] + return cmd + + # Get the help text for the given list of command methods. + # Note it's NOT a list of commands, but a list of actual method names. + # Each line of text is stripped and all lines are sorted. + # Repeated text lines are removed. + # Returns a single, possibly multiline, string. + def get_help(self, commands): + msg = set() + for name in commands: + if name != 'do_help': + try: + doc = getattr(self, name).__doc__.split('\n') + except Exception: + return ( "No help available when Python" + " is run with the -OO switch." ) + for x in doc: + x = x.strip() + if x: + msg.add(' %s' % x) + msg = list(msg) + msg.sort() + msg = '\n'.join(msg) + return msg + + # Parse the prefix and remove it from the command line. + def split_prefix(self, line): + prefix = None + if line.startswith('~'): + pos = line.find(' ') + if pos == 1: + pos = line.find(' ', pos + 1) + if not pos < 0: + prefix = line[ 1 : pos ].strip() + line = line[ pos : ].strip() + return prefix, line + +#------------------------------------------------------------------------------ +# Cmd() hacks + + # Header for help page. + doc_header = 'Available commands (type help * or help )' + +## # Read and write directly to stdin and stdout. +## # This prevents the use of raw_input and print. +## use_rawinput = False + + @property + def prompt(self): + if self.lastEvent: + pid = self.lastEvent.get_pid() + tid = self.lastEvent.get_tid() + if self.debug.is_debugee(pid): +## return '~%d(%d)> ' % (tid, pid) + return '%d:%d> ' % (pid, tid) + return '> ' + + # Return a sorted list of method names. + # Only returns the methods that implement commands. + def get_names(self): + names = Cmd.get_names(self) + names = [ x for x in set(names) if x.startswith('do_') ] + names.sort() + return names + + # Automatically autocomplete commands, even if Tab wasn't pressed. + # The prefix is removed from the line and stored in self.cmdprefix. + # Also implement the commands that consist of a symbol character. + def parseline(self, line): + self.cmdprefix, line = self.split_prefix(line) + line = line.strip() + if line: + if line[0] == '.': + line = 'plugin ' + line[1:] + elif line[0] == '#': + line = 'python ' + line[1:] + cmd, arg, line = Cmd.parseline(self, line) + if cmd: + cmd = self.autocomplete(cmd) + return cmd, arg, line + +## # Don't repeat the last executed command. +## def emptyline(self): +## pass + + # Reset the defaults for some commands. + def preloop(self): + self.default_disasm_target = 'eip' + self.default_display_target = 'eip' + self.last_display_command = self.do_db + + # Put the prefix back in the command line. + def get_lastcmd(self): + return self.__lastcmd + def set_lastcmd(self, lastcmd): + if self.cmdprefix: + lastcmd = '~%s %s' % (self.cmdprefix, lastcmd) + self.__lastcmd = lastcmd + lastcmd = property(get_lastcmd, set_lastcmd) + + # Quit the command prompt if the debuggerExit flag is on. + def postcmd(self, stop, line): + return stop or self.debuggerExit + +#------------------------------------------------------------------------------ +# Commands + + # Each command contains a docstring with it's help text. + # The help text consist of independent text lines, + # where each line shows a command and it's parameters. + # Each command method has the help message for itself and all it's aliases. + # Only the docstring for the "help" command is shown as-is. + + # NOTE: Command methods MUST be all lowercase! + + # Extended help command. + def do_help(self, arg): + """ + ? - show the list of available commands + ? * - show help for all commands + ? [command...] - show help for the given command(s) + help - show the list of available commands + help * - show help for all commands + help [command...] - show help for the given command(s) + """ + if not arg: + Cmd.do_help(self, arg) + elif arg in ('?', 'help'): + # An easter egg :) + print(" Help! I need somebody...") + print(" Help! Not just anybody...") + print(" Help! You know, I need someone...") + print(" Heeelp!") + else: + if arg == '*': + commands = self.get_names() + commands = [ x for x in commands if x.startswith('do_') ] + else: + commands = set() + for x in arg.split(' '): + x = x.strip() + if x: + for n in self.completenames(x): + commands.add( 'do_%s' % n ) + commands = list(commands) + commands.sort() + print(self.get_help(commands)) + + def do_shell(self, arg): + """ + ! - spawn a system shell + shell - spawn a system shell + ! [arguments...] - execute a single shell command + shell [arguments...] - execute a single shell command + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + + # Try to use the environment to locate cmd.exe. + # If not found, it's usually OK to just use the filename, + # since cmd.exe is one of those "magic" programs that + # can be automatically found by CreateProcess. + shell = os.getenv('ComSpec', 'cmd.exe') + + # When given a command, run it and return. + # When no command is given, spawn a shell. + if arg: + arg = '%s /c %s' % (shell, arg) + else: + arg = shell + process = self.debug.system.start_process(arg, bConsole = True) + process.wait() + + # This hack fixes a bug in Python, the interpreter console is closing the + # stdin pipe when calling the exit() function (Ctrl+Z seems to work fine). + class _PythonExit(object): + def __repr__(self): + return "Use exit() or Ctrl-Z plus Return to exit" + def __call__(self): + raise SystemExit() + _python_exit = _PythonExit() + + # Spawns a Python shell with some handy local variables and the winappdbg + # module already imported. Also the console banner is improved. + def _spawn_python_shell(self, arg): + import winappdbg + banner = ('Python %s on %s\nType "help", "copyright", ' + '"credits" or "license" for more information.\n') + platform = winappdbg.version.lower() + platform = 'WinAppDbg %s' % platform + banner = banner % (sys.version, platform) + local = {} + local.update(__builtins__) + local.update({ + '__name__' : '__console__', + '__doc__' : None, + 'exit' : self._python_exit, + 'self' : self, + 'arg' : arg, + 'winappdbg' : winappdbg, + }) + try: + code.interact(banner=banner, local=local) + except SystemExit: + # We need to catch it so it doesn't kill our program. + pass + + def do_python(self, arg): + """ + # - spawn a python interpreter + python - spawn a python interpreter + # - execute a single python statement + python - execute a single python statement + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + + # When given a Python statement, execute it directly. + if arg: + try: + compat.exec_(arg, globals(), locals()) + except Exception: + traceback.print_exc() + + # When no statement is given, spawn a Python interpreter. + else: + try: + self._spawn_python_shell(arg) + except Exception: + e = sys.exc_info()[1] + raise CmdError( + "unhandled exception when running Python console: %s" % e) + + # The plugins interface is quite simple. + # + # Just place a .py file with the plugin name in the "plugins" folder, + # for example "do_example.py" would implement the "example" command. + # + # The plugin must have a function named "do", which implements the + # command functionality exactly like the do_* methods of Cmd instances. + # + # The docstring for the "do" function will be parsed exactly like + # one of the debugger's commands - that is, each line is treated + # independently. + # + def do_plugin(self, arg): + """ + [~prefix] . [arguments] - run a plugin command + [~prefix] plugin [arguments] - run a plugin command + """ + pos = arg.find(' ') + if pos < 0: + name = arg + arg = '' + else: + name = arg[:pos] + arg = arg[pos:].strip() + if not name: + raise CmdError("missing plugin name") + for c in name: + if c not in self.valid_plugin_name_chars: + raise CmdError("invalid plugin name: %r" % name) + name = 'winappdbg.plugins.do_%s' % name + try: + plugin = __import__(name) + components = name.split('.') + for comp in components[1:]: + plugin = getattr(plugin, comp) + reload(plugin) + except ImportError: + raise CmdError("plugin not found: %s" % name) + try: + return plugin.do(self, arg) + except CmdError: + raise + except Exception: + e = sys.exc_info()[1] +## traceback.print_exc(e) # XXX DEBUG + raise CmdError("unhandled exception in plugin: %s" % e) + + def do_quit(self, arg): + """ + quit - close the debugging session + q - close the debugging session + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + if arg: + raise CmdError("too many arguments") + if self.confirm_quit: + count = self.debug.get_debugee_count() + if count > 0: + if count == 1: + msg = "There's a program still running." + else: + msg = "There are %s programs still running." % count + if not self.ask_user(msg): + return False + self.debuggerExit = True + return True + + do_q = do_quit + + def do_attach(self, arg): + """ + attach [target...] - attach to the given process(es) + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + targets = self.input_process_list( self.split_tokens(arg, 1) ) + if not targets: + print("Error: missing parameters") + else: + debug = self.debug + for pid in targets: + try: + debug.attach(pid) + print("Attached to process (%d)" % pid) + except Exception: + print("Error: can't attach to process (%d)" % pid) + + def do_detach(self, arg): + """ + [~process] detach - detach from the current process + detach - detach from the current process + detach [target...] - detach from the given process(es) + """ + debug = self.debug + token_list = self.split_tokens(arg) + if self.cmdprefix: + token_list.insert(0, self.cmdprefix) + targets = self.input_process_list(token_list) + if not targets: + if self.lastEvent is None: + raise CmdError("no current process set") + targets = [ self.lastEvent.get_pid() ] + for pid in targets: + try: + debug.detach(pid) + print("Detached from process (%d)" % pid) + except Exception: + print("Error: can't detach from process (%d)" % pid) + + def do_windowed(self, arg): + """ + windowed [arguments...] - run a windowed program for debugging + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + cmdline = self.input_command_line(arg) + try: + process = self.debug.execl(arg, + bConsole = False, + bFollow = self.options.follow) + print("Spawned process (%d)" % process.get_pid()) + except Exception: + raise CmdError("can't execute") + self.set_fake_last_event(process) + + def do_console(self, arg): + """ + console [arguments...] - run a console program for debugging + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + cmdline = self.input_command_line(arg) + try: + process = self.debug.execl(arg, + bConsole = True, + bFollow = self.options.follow) + print("Spawned process (%d)" % process.get_pid()) + except Exception: + raise CmdError("can't execute") + self.set_fake_last_event(process) + + def do_continue(self, arg): + """ + continue - continue execution + g - continue execution + go - continue execution + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + if arg: + raise CmdError("too many arguments") + if self.debug.get_debugee_count() > 0: + return True + + do_g = do_continue + do_go = do_continue + + def do_gh(self, arg): + """ + gh - go with exception handled + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + if arg: + raise CmdError("too many arguments") + if self.lastEvent: + self.lastEvent.continueStatus = win32.DBG_EXCEPTION_HANDLED + return self.do_go(arg) + + def do_gn(self, arg): + """ + gn - go with exception not handled + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + if arg: + raise CmdError("too many arguments") + if self.lastEvent: + self.lastEvent.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED + return self.do_go(arg) + + def do_refresh(self, arg): + """ + refresh - refresh the list of running processes and threads + [~process] refresh - refresh the list of running threads + """ + if arg: + raise CmdError("too many arguments") + if self.cmdprefix: + process = self.get_process_from_prefix() + process.scan() + else: + self.debug.system.scan() + + def do_processlist(self, arg): + """ + pl - show the processes being debugged + processlist - show the processes being debugged + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + if arg: + raise CmdError("too many arguments") + system = self.debug.system + pid_list = self.debug.get_debugee_pids() + if pid_list: + print("Process ID File name") + for pid in pid_list: + if pid == 0: + filename = "System Idle Process" + elif pid == 4: + filename = "System" + else: + filename = system.get_process(pid).get_filename() + filename = PathOperations.pathname_to_filename(filename) + print("%-12d %s" % (pid, filename)) + + do_pl = do_processlist + + def do_threadlist(self, arg): + """ + tl - show the threads being debugged + threadlist - show the threads being debugged + """ + if arg: + raise CmdError("too many arguments") + if self.cmdprefix: + process = self.get_process_from_prefix() + for thread in process.iter_threads(): + tid = thread.get_tid() + name = thread.get_name() + print("%-12d %s" % (tid, name)) + else: + system = self.debug.system + pid_list = self.debug.get_debugee_pids() + if pid_list: + print("Thread ID Thread name") + for pid in pid_list: + process = system.get_process(pid) + for thread in process.iter_threads(): + tid = thread.get_tid() + name = thread.get_name() + print("%-12d %s" % (tid, name)) + + do_tl = do_threadlist + + def do_kill(self, arg): + """ + [~process] kill - kill a process + [~thread] kill - kill a thread + kill - kill the current process + kill * - kill all debugged processes + kill - kill the given processes and threads + """ + if arg: + if arg == '*': + target_pids = self.debug.get_debugee_pids() + target_tids = list() + else: + target_pids = set() + target_tids = set() + if self.cmdprefix: + pid, tid = self.get_process_and_thread_ids_from_prefix() + if tid is None: + target_tids.add(tid) + else: + target_pids.add(pid) + for token in self.split_tokens(arg): + try: + pid = self.input_process(token) + target_pids.add(pid) + except CmdError: + try: + tid = self.input_process(token) + target_pids.add(pid) + except CmdError: + msg = "unknown process or thread (%s)" % token + raise CmdError(msg) + target_pids = list(target_pids) + target_tids = list(target_tids) + target_pids.sort() + target_tids.sort() + msg = "You are about to kill %d processes and %d threads." + msg = msg % ( len(target_pids), len(target_tids) ) + if self.ask_user(msg): + for pid in target_pids: + self.kill_process(pid) + for tid in target_tids: + self.kill_thread(tid) + else: + if self.cmdprefix: + pid, tid = self.get_process_and_thread_ids_from_prefix() + if tid is None: + if self.lastEvent is not None and pid == self.lastEvent.get_pid(): + msg = "You are about to kill the current process." + else: + msg = "You are about to kill process %d." % pid + if self.ask_user(msg): + self.kill_process(pid) + else: + if self.lastEvent is not None and tid == self.lastEvent.get_tid(): + msg = "You are about to kill the current thread." + else: + msg = "You are about to kill thread %d." % tid + if self.ask_user(msg): + self.kill_thread(tid) + else: + if self.lastEvent is None: + raise CmdError("no current process set") + pid = self.lastEvent.get_pid() + if self.ask_user("You are about to kill the current process."): + self.kill_process(pid) + + # TODO: create hidden threads using undocumented API calls. + def do_modload(self, arg): + """ + [~process] modload - load a DLL module + """ + filename = self.split_tokens(arg, 1, 1)[0] + process = self.get_process_from_prefix() + try: + process.inject_dll(filename, bWait=False) + except RuntimeError: + print("Can't inject module: %r" % filename) + + # TODO: modunload + + def do_stack(self, arg): + """ + [~thread] k - show the stack trace + [~thread] stack - show the stack trace + """ + if arg: # XXX TODO add depth parameter + raise CmdError("too many arguments") + pid, tid = self.get_process_and_thread_ids_from_prefix() + process = self.get_process(pid) + thread = process.get_thread(tid) + try: + stack_trace = thread.get_stack_trace_with_labels() + if stack_trace: + print(CrashDump.dump_stack_trace_with_labels(stack_trace),) + else: + print("No stack trace available for thread (%d)" % tid) + except WindowsError: + print("Can't get stack trace for thread (%d)" % tid) + + do_k = do_stack + + def do_break(self, arg): + """ + break - force a debug break in all debugees + break [process...] - force a debug break + """ + debug = self.debug + system = debug.system + targets = self.input_process_list( self.split_tokens(arg) ) + if not targets: + targets = debug.get_debugee_pids() + targets.sort() + if self.lastEvent: + current = self.lastEvent.get_pid() + else: + current = None + for pid in targets: + if pid != current and debug.is_debugee(pid): + process = system.get_process(pid) + try: + process.debug_break() + except WindowsError: + print("Can't force a debug break on process (%d)") + + def do_step(self, arg): + """ + p - step on the current assembly instruction + next - step on the current assembly instruction + step - step on the current assembly instruction + """ + if self.cmdprefix: + raise CmdError("prefix not allowed") + if self.lastEvent is None: + raise CmdError("no current process set") + if arg: # XXX this check is to be removed + raise CmdError("too many arguments") + pid = self.lastEvent.get_pid() + thread = self.lastEvent.get_thread() + pc = thread.get_pc() + code = thread.disassemble(pc, 16)[0] + size = code[1] + opcode = code[2].lower() + if ' ' in opcode: + opcode = opcode[ : opcode.find(' ') ] + if opcode in self.jump_instructions or opcode in ('int', 'ret', 'retn'): + return self.do_trace(arg) + address = pc + size +## print(hex(pc), hex(address), size # XXX DEBUG + self.debug.stalk_at(pid, address) + return True + + do_p = do_step + do_next = do_step + + def do_trace(self, arg): + """ + t - trace at the current assembly instruction + trace - trace at the current assembly instruction + """ + if arg: # XXX this check is to be removed + raise CmdError("too many arguments") + if self.lastEvent is None: + raise CmdError("no current thread set") + self.lastEvent.get_thread().set_tf() + return True + + do_t = do_trace + + def do_bp(self, arg): + """ + [~process] bp
- set a code breakpoint + """ + pid = self.get_process_id_from_prefix() + if not self.debug.is_debugee(pid): + raise CmdError("target process is not being debugged") + process = self.get_process(pid) + token_list = self.split_tokens(arg, 1, 1) + try: + address = self.input_address(token_list[0], pid) + deferred = False + except Exception: + address = token_list[0] + deferred = True + if not address: + address = token_list[0] + deferred = True + self.debug.break_at(pid, address) + if deferred: + print("Deferred breakpoint set at %s" % address) + else: + print("Breakpoint set at %s" % address) + + def do_ba(self, arg): + """ + [~thread] ba <1|2|4|8>
- set hardware breakpoint + """ + debug = self.debug + thread = self.get_thread_from_prefix() + pid = thread.get_pid() + tid = thread.get_tid() + if not debug.is_debugee(pid): + raise CmdError("target thread is not being debugged") + token_list = self.split_tokens(arg, 3, 3) + access = token_list[0].lower() + size = token_list[1] + address = token_list[2] + if access == 'a': + access = debug.BP_BREAK_ON_ACCESS + elif access == 'w': + access = debug.BP_BREAK_ON_WRITE + elif access == 'e': + access = debug.BP_BREAK_ON_EXECUTION + else: + raise CmdError("bad access type: %s" % token_list[0]) + if size == '1': + size = debug.BP_WATCH_BYTE + elif size == '2': + size = debug.BP_WATCH_WORD + elif size == '4': + size = debug.BP_WATCH_DWORD + elif size == '8': + size = debug.BP_WATCH_QWORD + else: + raise CmdError("bad breakpoint size: %s" % size) + thread = self.get_thread_from_prefix() + tid = thread.get_tid() + pid = thread.get_pid() + if not debug.is_debugee(pid): + raise CmdError("target process is not being debugged") + address = self.input_address(address, pid) + if debug.has_hardware_breakpoint(tid, address): + debug.erase_hardware_breakpoint(tid, address) + debug.define_hardware_breakpoint(tid, address, access, size) + debug.enable_hardware_breakpoint(tid, address) + + def do_bm(self, arg): + """ + [~process] bm - set memory breakpoint + """ + pid = self.get_process_id_from_prefix() + if not self.debug.is_debugee(pid): + raise CmdError("target process is not being debugged") + process = self.get_process(pid) + token_list = self.split_tokens(arg, 1, 2) + address, size = self.input_address_range(token_list[0], pid) + self.debug.watch_buffer(pid, address, size) + + def do_bl(self, arg): + """ + bl - list the breakpoints for the current process + bl * - list the breakpoints for all processes + [~process] bl - list the breakpoints for the given process + bl [process...] - list the breakpoints for each given process + """ + debug = self.debug + if arg == '*': + if self.cmdprefix: + raise CmdError("prefix not supported") + breakpoints = debug.get_debugee_pids() + else: + targets = self.input_process_list( self.split_tokens(arg) ) + if self.cmdprefix: + targets.insert(0, self.input_process(self.cmdprefix)) + if not targets: + if self.lastEvent is None: + raise CmdError("no current process is set") + targets = [ self.lastEvent.get_pid() ] + for pid in targets: + bplist = debug.get_process_code_breakpoints(pid) + printed_process_banner = False + if bplist: + if not printed_process_banner: + print("Process %d:" % pid) + printed_process_banner = True + for bp in bplist: + address = repr(bp)[1:-1].replace('remote address ','') + print(" %s" % address) + dbplist = debug.get_process_deferred_code_breakpoints(pid) + if dbplist: + if not printed_process_banner: + print("Process %d:" % pid) + printed_process_banner = True + for (label, action, oneshot) in dbplist: + if oneshot: + address = " Deferred unconditional one-shot" \ + " code breakpoint at %s" + else: + address = " Deferred unconditional" \ + " code breakpoint at %s" + address = address % label + print(" %s" % address) + bplist = debug.get_process_page_breakpoints(pid) + if bplist: + if not printed_process_banner: + print("Process %d:" % pid) + printed_process_banner = True + for bp in bplist: + address = repr(bp)[1:-1].replace('remote address ','') + print(" %s" % address) + for tid in debug.system.get_process(pid).iter_thread_ids(): + bplist = debug.get_thread_hardware_breakpoints(tid) + if bplist: + print("Thread %d:" % tid) + for bp in bplist: + address = repr(bp)[1:-1].replace('remote address ','') + print(" %s" % address) + + def do_bo(self, arg): + """ + [~process] bo
- make a code breakpoint one-shot + [~thread] bo
- make a hardware breakpoint one-shot + [~process] bo - make a memory breakpoint one-shot + [~process] bo
- make a memory breakpoint one-shot + """ + token_list = self.split_tokens(arg, 1, 2) + pid, tid, address, size = self.input_breakpoint(token_list) + debug = self.debug + found = False + if size is None: + if tid is not None: + if debug.has_hardware_breakpoint(tid, address): + debug.enable_one_shot_hardware_breakpoint(tid, address) + found = True + if pid is not None: + if debug.has_code_breakpoint(pid, address): + debug.enable_one_shot_code_breakpoint(pid, address) + found = True + else: + if debug.has_page_breakpoint(pid, address): + debug.enable_one_shot_page_breakpoint(pid, address) + found = True + if not found: + print("Error: breakpoint not found.") + + def do_be(self, arg): + """ + [~process] be
- enable a code breakpoint + [~thread] be
- enable a hardware breakpoint + [~process] be - enable a memory breakpoint + [~process] be
- enable a memory breakpoint + """ + token_list = self.split_tokens(arg, 1, 2) + pid, tid, address, size = self.input_breakpoint(token_list) + debug = self.debug + found = False + if size is None: + if tid is not None: + if debug.has_hardware_breakpoint(tid, address): + debug.enable_hardware_breakpoint(tid, address) + found = True + if pid is not None: + if debug.has_code_breakpoint(pid, address): + debug.enable_code_breakpoint(pid, address) + found = True + else: + if debug.has_page_breakpoint(pid, address): + debug.enable_page_breakpoint(pid, address) + found = True + if not found: + print("Error: breakpoint not found.") + + def do_bd(self, arg): + """ + [~process] bd
- disable a code breakpoint + [~thread] bd
- disable a hardware breakpoint + [~process] bd - disable a memory breakpoint + [~process] bd
- disable a memory breakpoint + """ + token_list = self.split_tokens(arg, 1, 2) + pid, tid, address, size = self.input_breakpoint(token_list) + debug = self.debug + found = False + if size is None: + if tid is not None: + if debug.has_hardware_breakpoint(tid, address): + debug.disable_hardware_breakpoint(tid, address) + found = True + if pid is not None: + if debug.has_code_breakpoint(pid, address): + debug.disable_code_breakpoint(pid, address) + found = True + else: + if debug.has_page_breakpoint(pid, address): + debug.disable_page_breakpoint(pid, address) + found = True + if not found: + print("Error: breakpoint not found.") + + def do_bc(self, arg): + """ + [~process] bc
- clear a code breakpoint + [~thread] bc
- clear a hardware breakpoint + [~process] bc - clear a memory breakpoint + [~process] bc
- clear a memory breakpoint + """ + token_list = self.split_tokens(arg, 1, 2) + pid, tid, address, size = self.input_breakpoint(token_list) + debug = self.debug + found = False + if size is None: + if tid is not None: + if debug.has_hardware_breakpoint(tid, address): + debug.dont_watch_variable(tid, address) + found = True + if pid is not None: + if debug.has_code_breakpoint(pid, address): + debug.dont_break_at(pid, address) + found = True + else: + if debug.has_page_breakpoint(pid, address): + debug.dont_watch_buffer(pid, address, size) + found = True + if not found: + print("Error: breakpoint not found.") + + def do_disassemble(self, arg): + """ + [~thread] u [register] - show code disassembly + [~process] u [address] - show code disassembly + [~thread] disassemble [register] - show code disassembly + [~process] disassemble [address] - show code disassembly + """ + if not arg: + arg = self.default_disasm_target + token_list = self.split_tokens(arg, 1, 1) + pid, tid = self.get_process_and_thread_ids_from_prefix() + process = self.get_process(pid) + address = self.input_address(token_list[0], pid, tid) + try: + code = process.disassemble(address, 15*8)[:8] + except Exception: + msg = "can't disassemble address %s" + msg = msg % HexDump.address(address) + raise CmdError(msg) + if code: + label = process.get_label_at_address(address) + last_code = code[-1] + next_address = last_code[0] + last_code[1] + next_address = HexOutput.integer(next_address) + self.default_disasm_target = next_address + print("%s:" % label) +## print(CrashDump.dump_code(code)) + for line in code: + print(CrashDump.dump_code_line(line, bShowDump = False)) + + do_u = do_disassemble + + def do_search(self, arg): + """ + [~process] s [address-address] + [~process] search [address-address] + """ + token_list = self.split_tokens(arg, 1, 3) + pid, tid = self.get_process_and_thread_ids_from_prefix() + process = self.get_process(pid) + if len(token_list) == 1: + pattern = token_list[0] + minAddr = None + maxAddr = None + else: + pattern = token_list[-1] + addr, size = self.input_address_range(token_list[:-1], pid, tid) + minAddr = addr + maxAddr = addr + size + iter = process.search_bytes(pattern) + if process.get_bits() == 32: + addr_width = 8 + else: + addr_width = 16 + # TODO: need a prettier output here! + for addr in iter: + print(HexDump.address(addr, addr_width)) + + do_s = do_search + + def do_searchhex(self, arg): + """ + [~process] sh [address-address] + [~process] searchhex [address-address] + """ + token_list = self.split_tokens(arg, 1, 3) + pid, tid = self.get_process_and_thread_ids_from_prefix() + process = self.get_process(pid) + if len(token_list) == 1: + pattern = token_list[0] + minAddr = None + maxAddr = None + else: + pattern = token_list[-1] + addr, size = self.input_address_range(token_list[:-1], pid, tid) + minAddr = addr + maxAddr = addr + size + iter = process.search_hexa(pattern) + if process.get_bits() == 32: + addr_width = 8 + else: + addr_width = 16 + for addr, bytes in iter: + print(HexDump.hexblock(bytes, addr, addr_width),) + + do_sh = do_searchhex + +## def do_strings(self, arg): +## """ +## [~process] strings - extract ASCII strings from memory +## """ +## if arg: +## raise CmdError("too many arguments") +## pid, tid = self.get_process_and_thread_ids_from_prefix() +## process = self.get_process(pid) +## for addr, size, data in process.strings(): +## print("%s: %r" % (HexDump.address(addr), data) + + def do_d(self, arg): + """ + [~thread] d - show memory contents + [~thread] d - show memory contents + [~thread] d - show memory contents + [~process] d
- show memory contents + [~process] d - show memory contents + [~process] d
- show memory contents + """ + return self.last_display_command(arg) + + def do_db(self, arg): + """ + [~thread] db - show memory contents as bytes + [~thread] db - show memory contents as bytes + [~thread] db - show memory contents as bytes + [~process] db
- show memory contents as bytes + [~process] db - show memory contents as bytes + [~process] db
- show memory contents as bytes + """ + self.print_memory_display(arg, HexDump.hexblock) + self.last_display_command = self.do_db + + def do_dw(self, arg): + """ + [~thread] dw - show memory contents as words + [~thread] dw - show memory contents as words + [~thread] dw - show memory contents as words + [~process] dw
- show memory contents as words + [~process] dw - show memory contents as words + [~process] dw
- show memory contents as words + """ + self.print_memory_display(arg, HexDump.hexblock_word) + self.last_display_command = self.do_dw + + def do_dd(self, arg): + """ + [~thread] dd - show memory contents as dwords + [~thread] dd - show memory contents as dwords + [~thread] dd - show memory contents as dwords + [~process] dd
- show memory contents as dwords + [~process] dd - show memory contents as dwords + [~process] dd
- show memory contents as dwords + """ + self.print_memory_display(arg, HexDump.hexblock_dword) + self.last_display_command = self.do_dd + + def do_dq(self, arg): + """ + [~thread] dq - show memory contents as qwords + [~thread] dq - show memory contents as qwords + [~thread] dq - show memory contents as qwords + [~process] dq
- show memory contents as qwords + [~process] dq - show memory contents as qwords + [~process] dq
- show memory contents as qwords + """ + self.print_memory_display(arg, HexDump.hexblock_qword) + self.last_display_command = self.do_dq + + # XXX TODO + # Change the way the default is used with ds and du + + def do_ds(self, arg): + """ + [~thread] ds - show memory contents as ANSI string + [~process] ds
- show memory contents as ANSI string + """ + if not arg: + arg = self.default_display_target + token_list = self.split_tokens(arg, 1, 1) + pid, tid, address, size = self.input_display(token_list, 256) + process = self.get_process(pid) + data = process.peek_string(address, False, size) + if data: + print(repr(data)) + self.last_display_command = self.do_ds + + def do_du(self, arg): + """ + [~thread] du - show memory contents as Unicode string + [~process] du
- show memory contents as Unicode string + """ + if not arg: + arg = self.default_display_target + token_list = self.split_tokens(arg, 1, 2) + pid, tid, address, size = self.input_display(token_list, 256) + process = self.get_process(pid) + data = process.peek_string(address, True, size) + if data: + print(repr(data)) + self.last_display_command = self.do_du + + def do_register(self, arg): + """ + [~thread] r - print(the value of all registers + [~thread] r - print(the value of a register + [~thread] r = - change the value of a register + [~thread] register - print(the value of all registers + [~thread] register - print(the value of a register + [~thread] register = - change the value of a register + """ + arg = arg.strip() + if not arg: + self.print_current_location() + else: + equ = arg.find('=') + if equ >= 0: + register = arg[:equ].strip() + value = arg[equ+1:].strip() + if not value: + value = '0' + self.change_register(register, value) + else: + value = self.input_register(arg) + if value is None: + raise CmdError("unknown register: %s" % arg) + try: + label = None + thread = self.get_thread_from_prefix() + process = thread.get_process() + module = process.get_module_at_address(value) + if module: + label = module.get_label_at_address(value) + except RuntimeError: + label = None + reg = arg.upper() + val = HexDump.address(value) + if label: + print("%s: %s (%s)" % (reg, val, label)) + else: + print("%s: %s" % (reg, val)) + + do_r = do_register + + def do_eb(self, arg): + """ + [~process] eb
- write the data to the specified address + """ + # TODO + # data parameter should be optional, use a child Cmd here + pid = self.get_process_id_from_prefix() + token_list = self.split_tokens(arg, 2) + address = self.input_address(token_list[0], pid) + data = HexInput.hexadecimal(' '.join(token_list[1:])) + self.write_memory(address, data, pid) + + # XXX TODO + # add ew, ed and eq here + + def do_find(self, arg): + """ + [~process] f - find the string in the process memory + [~process] find - find the string in the process memory + """ + if not arg: + raise CmdError("missing parameter: string") + process = self.get_process_from_prefix() + self.find_in_memory(arg, process) + + do_f = do_find + + def do_memory(self, arg): + """ + [~process] m - show the process memory map + [~process] memory - show the process memory map + """ + if arg: # TODO: take min and max addresses + raise CmdError("too many arguments") + process = self.get_process_from_prefix() + try: + memoryMap = process.get_memory_map() + mappedFilenames = process.get_mapped_filenames() + print('') + print(CrashDump.dump_memory_map(memoryMap, mappedFilenames)) + except WindowsError: + msg = "can't get memory information for process (%d)" + raise CmdError(msg % process.get_pid()) + + do_m = do_memory + +#------------------------------------------------------------------------------ +# Event handling + +# TODO +# * add configurable stop/don't stop behavior on events and exceptions + + # Stop for all events, unless stated otherwise. + def event(self, event): + self.print_event(event) + self.prompt_user() + + # Stop for all exceptions, unless stated otherwise. + def exception(self, event): + self.print_exception(event) + self.prompt_user() + + # Stop for breakpoint exceptions. + def breakpoint(self, event): + if hasattr(event, 'breakpoint') and event.breakpoint: + self.print_breakpoint_location(event) + else: + self.print_exception(event) + self.prompt_user() + + # Stop for WOW64 breakpoint exceptions. + def wow64_breakpoint(self, event): + self.print_exception(event) + self.prompt_user() + + # Stop for single step exceptions. + def single_step(self, event): + if event.debug.is_tracing(event.get_tid()): + self.print_breakpoint_location(event) + else: + self.print_exception(event) + self.prompt_user() + + # Don't stop for C++ exceptions. + def ms_vc_exception(self, event): + self.print_exception(event) + event.continueStatus = win32.DBG_CONTINUE + + # Don't stop for process start. + def create_process(self, event): + self.print_process_start(event) + self.print_thread_start(event) + self.print_module_load(event) + + # Don't stop for process exit. + def exit_process(self, event): + self.print_process_end(event) + + # Don't stop for thread creation. + def create_thread(self, event): + self.print_thread_start(event) + + # Don't stop for thread exit. + def exit_thread(self, event): + self.print_thread_end(event) + + # Don't stop for DLL load. + def load_dll(self, event): + self.print_module_load(event) + + # Don't stop for DLL unload. + def unload_dll(self, event): + self.print_module_unload(event) + + # Don't stop for debug strings. + def output_string(self, event): + self.print_debug_string(event) + +#------------------------------------------------------------------------------ +# History file + + def load_history(self): + global readline + if readline is None: + try: + import readline + except ImportError: + return + if self.history_file_full_path is None: + folder = os.environ.get('USERPROFILE', '') + if not folder: + folder = os.environ.get('HOME', '') + if not folder: + folder = os.path.split(sys.argv[0])[1] + if not folder: + folder = os.path.curdir + self.history_file_full_path = os.path.join(folder, + self.history_file) + try: + if os.path.exists(self.history_file_full_path): + readline.read_history_file(self.history_file_full_path) + except IOError: + e = sys.exc_info()[1] + warnings.warn("Cannot load history file, reason: %s" % str(e)) + + def save_history(self): + if self.history_file_full_path is not None: + global readline + if readline is None: + try: + import readline + except ImportError: + return + try: + readline.write_history_file(self.history_file_full_path) + except IOError: + e = sys.exc_info()[1] + warnings.warn("Cannot save history file, reason: %s" % str(e)) + +#------------------------------------------------------------------------------ +# Main loop + + # Debugging loop. + def loop(self): + self.debuggerExit = False + debug = self.debug + + # Stop on the initial event, if any. + if self.lastEvent is not None: + self.cmdqueue.append('r') + self.prompt_user() + + # Loop until the debugger is told to quit. + while not self.debuggerExit: + + try: + + # If for some reason the last event wasn't continued, + # continue it here. This won't be done more than once + # for a given Event instance, though. + try: + debug.cont() + # On error, show the command prompt. + except Exception: + traceback.print_exc() + self.prompt_user() + + # While debugees are attached, handle debug events. + # Some debug events may cause the command prompt to be shown. + if self.debug.get_debugee_count() > 0: + try: + + # Get the next debug event. + debug.wait() + + # Dispatch the debug event. + try: + debug.dispatch() + + # Continue the debug event. + finally: + debug.cont() + + # On error, show the command prompt. + except Exception: + traceback.print_exc() + self.prompt_user() + + # While no debugees are attached, show the command prompt. + else: + self.prompt_user() + + # When the user presses Ctrl-C send a debug break to all debugees. + except KeyboardInterrupt: + success = False + try: + print("*** User requested debug break") + system = debug.system + for pid in debug.get_debugee_pids(): + try: + system.get_process(pid).debug_break() + success = True + except: + traceback.print_exc() + except: + traceback.print_exc() + if not success: + raise # This should never happen! diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/module.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/module.py new file mode 100644 index 0000000..6ae0183 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/module.py @@ -0,0 +1,2016 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Module instrumentation. + +@group Instrumentation: + Module + +@group Warnings: + DebugSymbolsWarning +""" + +from __future__ import with_statement + +__revision__ = "$Id$" + +__all__ = ['Module', 'DebugSymbolsWarning'] + +import sys +from winappdbg import win32 +from winappdbg import compat +from winappdbg.textio import HexInput, HexDump +from winappdbg.util import PathOperations + +# delayed imports +Process = None + +import os +import warnings +import traceback + +#============================================================================== + +class DebugSymbolsWarning (UserWarning): + """ + This warning is issued if the support for debug symbols + isn't working properly. + """ + +#============================================================================== + +class Module (object): + """ + Interface to a DLL library loaded in the context of another process. + + @group Properties: + get_base, get_filename, get_name, get_size, get_entry_point, + get_process, set_process, get_pid, + get_handle, set_handle, open_handle, close_handle + + @group Labels: + get_label, get_label_at_address, is_address_here, + resolve, resolve_label, match_name + + @group Symbols: + load_symbols, unload_symbols, get_symbols, iter_symbols, + resolve_symbol, get_symbol_at_address + + @group Modules snapshot: + clear + + @type unknown: str + @cvar unknown: Suggested tag for unknown modules. + + @type lpBaseOfDll: int + @ivar lpBaseOfDll: Base of DLL module. + Use L{get_base} instead. + + @type hFile: L{FileHandle} + @ivar hFile: Handle to the module file. + Use L{get_handle} instead. + + @type fileName: str + @ivar fileName: Module filename. + Use L{get_filename} instead. + + @type SizeOfImage: int + @ivar SizeOfImage: Size of the module. + Use L{get_size} instead. + + @type EntryPoint: int + @ivar EntryPoint: Entry point of the module. + Use L{get_entry_point} instead. + + @type process: L{Process} + @ivar process: Process where the module is loaded. + Use the L{get_process} method instead. + """ + + unknown = '' + + class _SymbolEnumerator (object): + """ + Internally used by L{Module} to enumerate symbols in a module. + """ + + def __init__(self, undecorate = False): + self.symbols = list() + self.undecorate = undecorate + + def __call__(self, SymbolName, SymbolAddress, SymbolSize, UserContext): + """ + Callback that receives symbols and stores them in a Python list. + """ + if self.undecorate: + try: + SymbolName = win32.UnDecorateSymbolName(SymbolName) + except Exception: + pass # not all symbols are decorated! + self.symbols.append( (SymbolName, SymbolAddress, SymbolSize) ) + return win32.TRUE + + def __init__(self, lpBaseOfDll, hFile = None, fileName = None, + SizeOfImage = None, + EntryPoint = None, + process = None): + """ + @type lpBaseOfDll: str + @param lpBaseOfDll: Base address of the module. + + @type hFile: L{FileHandle} + @param hFile: (Optional) Handle to the module file. + + @type fileName: str + @param fileName: (Optional) Module filename. + + @type SizeOfImage: int + @param SizeOfImage: (Optional) Size of the module. + + @type EntryPoint: int + @param EntryPoint: (Optional) Entry point of the module. + + @type process: L{Process} + @param process: (Optional) Process where the module is loaded. + """ + self.lpBaseOfDll = lpBaseOfDll + self.fileName = fileName + self.SizeOfImage = SizeOfImage + self.EntryPoint = EntryPoint + + self.__symbols = list() + + self.set_handle(hFile) + self.set_process(process) + + # Not really sure if it's a good idea... +## def __eq__(self, aModule): +## """ +## Compare two Module objects. The comparison is made using the process +## IDs and the module bases. +## +## @type aModule: L{Module} +## @param aModule: Another Module object. +## +## @rtype: bool +## @return: C{True} if the two process IDs and module bases are equal, +## C{False} otherwise. +## """ +## return isinstance(aModule, Module) and \ +## self.get_pid() == aModule.get_pid() and \ +## self.get_base() == aModule.get_base() + + def get_handle(self): + """ + @rtype: L{Handle} + @return: File handle. + Returns C{None} if unknown. + """ + # no way to guess! + return self.__hFile + + def set_handle(self, hFile): + """ + @type hFile: L{Handle} + @param hFile: File handle. Use C{None} to clear. + """ + if hFile == win32.INVALID_HANDLE_VALUE: + hFile = None + self.__hFile = hFile + + hFile = property(get_handle, set_handle, doc="") + + def get_process(self): + """ + @rtype: L{Process} + @return: Parent Process object. + Returns C{None} if unknown. + """ + # no way to guess! + return self.__process + + def set_process(self, process = None): + """ + Manually set the parent process. Use with care! + + @type process: L{Process} + @param process: (Optional) Process object. Use C{None} for no process. + """ + if process is None: + self.__process = None + else: + global Process # delayed import + if Process is None: + from winappdbg.process import Process + if not isinstance(process, Process): + msg = "Parent process must be a Process instance, " + msg += "got %s instead" % type(process) + raise TypeError(msg) + self.__process = process + + process = property(get_process, set_process, doc="") + + def get_pid(self): + """ + @rtype: int or None + @return: Parent process global ID. + Returns C{None} on error. + """ + process = self.get_process() + if process is not None: + return process.get_pid() + + def get_base(self): + """ + @rtype: int or None + @return: Base address of the module. + Returns C{None} if unknown. + """ + return self.lpBaseOfDll + + def get_size(self): + """ + @rtype: int or None + @return: Base size of the module. + Returns C{None} if unknown. + """ + if not self.SizeOfImage: + self.__get_size_and_entry_point() + return self.SizeOfImage + + def get_entry_point(self): + """ + @rtype: int or None + @return: Entry point of the module. + Returns C{None} if unknown. + """ + if not self.EntryPoint: + self.__get_size_and_entry_point() + return self.EntryPoint + + def __get_size_and_entry_point(self): + "Get the size and entry point of the module using the Win32 API." + process = self.get_process() + if process: + try: + handle = process.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + base = self.get_base() + mi = win32.GetModuleInformation(handle, base) + self.SizeOfImage = mi.SizeOfImage + self.EntryPoint = mi.EntryPoint + except WindowsError: + e = sys.exc_info()[1] + warnings.warn( + "Cannot get size and entry point of module %s, reason: %s"\ + % (self.get_name(), e.strerror), RuntimeWarning) + + def get_filename(self): + """ + @rtype: str or None + @return: Module filename. + Returns C{None} if unknown. + """ + if self.fileName is None: + if self.hFile not in (None, win32.INVALID_HANDLE_VALUE): + fileName = self.hFile.get_filename() + if fileName: + fileName = PathOperations.native_to_win32_pathname(fileName) + self.fileName = fileName + return self.fileName + + def __filename_to_modname(self, pathname): + """ + @type pathname: str + @param pathname: Pathname to a module. + + @rtype: str + @return: Module name. + """ + filename = PathOperations.pathname_to_filename(pathname) + if filename: + filename = filename.lower() + filepart, extpart = PathOperations.split_extension(filename) + if filepart and extpart: + modName = filepart + else: + modName = filename + else: + modName = pathname + return modName + + def get_name(self): + """ + @rtype: str + @return: Module name, as used in labels. + + @warning: Names are B{NOT} guaranteed to be unique. + + If you need unique identification for a loaded module, + use the base address instead. + + @see: L{get_label} + """ + pathname = self.get_filename() + if pathname: + modName = self.__filename_to_modname(pathname) + if isinstance(modName, compat.unicode): + try: + modName = modName.encode('cp1252') + except UnicodeEncodeError: + e = sys.exc_info()[1] + warnings.warn(str(e)) + else: + modName = "0x%x" % self.get_base() + return modName + + def match_name(self, name): + """ + @rtype: bool + @return: + C{True} if the given name could refer to this module. + It may not be exactly the same returned by L{get_name}. + """ + + # If the given name is exactly our name, return True. + # Comparison is case insensitive. + my_name = self.get_name().lower() + if name.lower() == my_name: + return True + + # If the given name is a base address, compare it with ours. + try: + base = HexInput.integer(name) + except ValueError: + base = None + if base is not None and base == self.get_base(): + return True + + # If the given name is a filename, convert it to a module name. + # Then compare it with ours, case insensitive. + modName = self.__filename_to_modname(name) + if modName.lower() == my_name: + return True + + # No match. + return False + +#------------------------------------------------------------------------------ + + def open_handle(self): + """ + Opens a new handle to the module. + + The new handle is stored in the L{hFile} property. + """ + + if not self.get_filename(): + msg = "Cannot retrieve filename for module at %s" + msg = msg % HexDump.address( self.get_base() ) + raise Exception(msg) + + hFile = win32.CreateFile(self.get_filename(), + dwShareMode = win32.FILE_SHARE_READ, + dwCreationDisposition = win32.OPEN_EXISTING) + + # In case hFile was set to an actual handle value instead of a Handle + # object. This shouldn't happen unless the user tinkered with hFile. + if not hasattr(self.hFile, '__del__'): + self.close_handle() + + self.hFile = hFile + + def close_handle(self): + """ + Closes the handle to the module. + + @note: Normally you don't need to call this method. All handles + created by I{WinAppDbg} are automatically closed when the garbage + collector claims them. So unless you've been tinkering with it, + setting L{hFile} to C{None} should be enough. + """ + try: + if hasattr(self.hFile, 'close'): + self.hFile.close() + elif self.hFile not in (None, win32.INVALID_HANDLE_VALUE): + win32.CloseHandle(self.hFile) + finally: + self.hFile = None + + def get_handle(self): + """ + @rtype: L{FileHandle} + @return: Handle to the module file. + """ + if self.hFile in (None, win32.INVALID_HANDLE_VALUE): + self.open_handle() + return self.hFile + + def clear(self): + """ + Clears the resources held by this object. + """ + try: + self.set_process(None) + finally: + self.close_handle() + +#------------------------------------------------------------------------------ + + # XXX FIXME + # I've been told sometimes the debugging symbols APIs don't correctly + # handle redirected exports (for example ws2_32!recv). + # I haven't been able to reproduce the bug yet. + def load_symbols(self): + """ + Loads the debugging symbols for a module. + Automatically called by L{get_symbols}. + """ + if win32.PROCESS_ALL_ACCESS == win32.PROCESS_ALL_ACCESS_VISTA: + dwAccess = win32.PROCESS_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.PROCESS_QUERY_INFORMATION + hProcess = self.get_process().get_handle(dwAccess) + hFile = self.hFile + BaseOfDll = self.get_base() + SizeOfDll = self.get_size() + Enumerator = self._SymbolEnumerator() + try: + win32.SymInitialize(hProcess) + SymOptions = win32.SymGetOptions() + SymOptions |= ( + win32.SYMOPT_ALLOW_ZERO_ADDRESS | + win32.SYMOPT_CASE_INSENSITIVE | + win32.SYMOPT_FAVOR_COMPRESSED | + win32.SYMOPT_INCLUDE_32BIT_MODULES | + win32.SYMOPT_UNDNAME + ) + SymOptions &= ~( + win32.SYMOPT_LOAD_LINES | + win32.SYMOPT_NO_IMAGE_SEARCH | + win32.SYMOPT_NO_CPP | + win32.SYMOPT_IGNORE_NT_SYMPATH + ) + win32.SymSetOptions(SymOptions) + try: + win32.SymSetOptions( + SymOptions | win32.SYMOPT_ALLOW_ABSOLUTE_SYMBOLS) + except WindowsError: + pass + try: + try: + success = win32.SymLoadModule64( + hProcess, hFile, None, None, BaseOfDll, SizeOfDll) + except WindowsError: + success = 0 + if not success: + ImageName = self.get_filename() + success = win32.SymLoadModule64( + hProcess, None, ImageName, None, BaseOfDll, SizeOfDll) + if success: + try: + win32.SymEnumerateSymbols64( + hProcess, BaseOfDll, Enumerator) + finally: + win32.SymUnloadModule64(hProcess, BaseOfDll) + finally: + win32.SymCleanup(hProcess) + except WindowsError: + e = sys.exc_info()[1] + msg = "Cannot load debug symbols for process ID %d, reason:\n%s" + msg = msg % (self.get_pid(), traceback.format_exc(e)) + warnings.warn(msg, DebugSymbolsWarning) + self.__symbols = Enumerator.symbols + + def unload_symbols(self): + """ + Unloads the debugging symbols for a module. + """ + self.__symbols = list() + + def get_symbols(self): + """ + Returns the debugging symbols for a module. + The symbols are automatically loaded when needed. + + @rtype: list of tuple( str, int, int ) + @return: List of symbols. + Each symbol is represented by a tuple that contains: + - Symbol name + - Symbol memory address + - Symbol size in bytes + """ + if not self.__symbols: + self.load_symbols() + return list(self.__symbols) + + def iter_symbols(self): + """ + Returns an iterator for the debugging symbols in a module, + in no particular order. + The symbols are automatically loaded when needed. + + @rtype: iterator of tuple( str, int, int ) + @return: Iterator of symbols. + Each symbol is represented by a tuple that contains: + - Symbol name + - Symbol memory address + - Symbol size in bytes + """ + if not self.__symbols: + self.load_symbols() + return self.__symbols.__iter__() + + def resolve_symbol(self, symbol, bCaseSensitive = False): + """ + Resolves a debugging symbol's address. + + @type symbol: str + @param symbol: Name of the symbol to resolve. + + @type bCaseSensitive: bool + @param bCaseSensitive: C{True} for case sensitive matches, + C{False} for case insensitive. + + @rtype: int or None + @return: Memory address of symbol. C{None} if not found. + """ + if bCaseSensitive: + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + if symbol == SymbolName: + return SymbolAddress + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + try: + SymbolName = win32.UnDecorateSymbolName(SymbolName) + except Exception: + continue + if symbol == SymbolName: + return SymbolAddress + else: + symbol = symbol.lower() + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + if symbol == SymbolName.lower(): + return SymbolAddress + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + try: + SymbolName = win32.UnDecorateSymbolName(SymbolName) + except Exception: + continue + if symbol == SymbolName.lower(): + return SymbolAddress + + def get_symbol_at_address(self, address): + """ + Tries to find the closest matching symbol for the given address. + + @type address: int + @param address: Memory address to query. + + @rtype: None or tuple( str, int, int ) + @return: Returns a tuple consisting of: + - Name + - Address + - Size (in bytes) + Returns C{None} if no symbol could be matched. + """ + found = None + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + if SymbolAddress > address: + continue + if SymbolAddress + SymbolSize > address: + if not found or found[1] < SymbolAddress: + found = (SymbolName, SymbolAddress, SymbolSize) + return found + +#------------------------------------------------------------------------------ + + def get_label(self, function = None, offset = None): + """ + Retrieves the label for the given function of this module or the module + base address if no function name is given. + + @type function: str + @param function: (Optional) Exported function name. + + @type offset: int + @param offset: (Optional) Offset from the module base address. + + @rtype: str + @return: Label for the module base address, plus the offset if given. + """ + return _ModuleContainer.parse_label(self.get_name(), function, offset) + + def get_label_at_address(self, address, offset = None): + """ + Creates a label from the given memory address. + + If the address belongs to the module, the label is made relative to + it's base address. + + @type address: int + @param address: Memory address. + + @type offset: None or int + @param offset: (Optional) Offset value. + + @rtype: str + @return: Label pointing to the given address. + """ + + # Add the offset to the address. + if offset: + address = address + offset + + # Make the label relative to the base address if no match is found. + module = self.get_name() + function = None + offset = address - self.get_base() + + # Make the label relative to the entrypoint if no other match is found. + # Skip if the entry point is unknown. + start = self.get_entry_point() + if start and start <= address: + function = "start" + offset = address - start + + # Enumerate exported functions and debug symbols, + # then find the closest match, if possible. + try: + symbol = self.get_symbol_at_address(address) + if symbol: + (SymbolName, SymbolAddress, SymbolSize) = symbol + new_offset = address - SymbolAddress + if new_offset <= offset: + function = SymbolName + offset = new_offset + except WindowsError: + pass + + # Parse the label and return it. + return _ModuleContainer.parse_label(module, function, offset) + + def is_address_here(self, address): + """ + Tries to determine if the given address belongs to this module. + + @type address: int + @param address: Memory address. + + @rtype: bool or None + @return: C{True} if the address belongs to the module, + C{False} if it doesn't, + and C{None} if it can't be determined. + """ + base = self.get_base() + size = self.get_size() + if base and size: + return base <= address < (base + size) + return None + + def resolve(self, function): + """ + Resolves a function exported by this module. + + @type function: str or int + @param function: + str: Name of the function. + int: Ordinal of the function. + + @rtype: int + @return: Memory address of the exported function in the process. + Returns None on error. + """ + + # Unknown DLL filename, there's nothing we can do. + filename = self.get_filename() + if not filename: + return None + + # If the DLL is already mapped locally, resolve the function. + try: + hlib = win32.GetModuleHandle(filename) + address = win32.GetProcAddress(hlib, function) + except WindowsError: + + # Load the DLL locally, resolve the function and unload it. + try: + hlib = win32.LoadLibraryEx(filename, + win32.DONT_RESOLVE_DLL_REFERENCES) + try: + address = win32.GetProcAddress(hlib, function) + finally: + win32.FreeLibrary(hlib) + except WindowsError: + return None + + # A NULL pointer means the function was not found. + if address in (None, 0): + return None + + # Compensate for DLL base relocations locally and remotely. + return address - hlib + self.lpBaseOfDll + + def resolve_label(self, label): + """ + Resolves a label for this module only. If the label refers to another + module, an exception is raised. + + @type label: str + @param label: Label to resolve. + + @rtype: int + @return: Memory address pointed to by the label. + + @raise ValueError: The label is malformed or impossible to resolve. + @raise RuntimeError: Cannot resolve the module or function. + """ + + # Split the label into it's components. + # Use the fuzzy mode whenever possible. + aProcess = self.get_process() + if aProcess is not None: + (module, procedure, offset) = aProcess.split_label(label) + else: + (module, procedure, offset) = _ModuleContainer.split_label(label) + + # If a module name is given that doesn't match ours, + # raise an exception. + if module and not self.match_name(module): + raise RuntimeError("Label does not belong to this module") + + # Resolve the procedure if given. + if procedure: + address = self.resolve(procedure) + if address is None: + + # If it's a debug symbol, use the symbol. + address = self.resolve_symbol(procedure) + + # If it's the keyword "start" use the entry point. + if address is None and procedure == "start": + address = self.get_entry_point() + + # The procedure was not found. + if address is None: + if not module: + module = self.get_name() + msg = "Can't find procedure %s in module %s" + raise RuntimeError(msg % (procedure, module)) + + # If no procedure is given use the base address of the module. + else: + address = self.get_base() + + # Add the offset if given and return the resolved address. + if offset: + address = address + offset + return address + +#============================================================================== + +# TODO +# An alternative approach to the toolhelp32 snapshots: parsing the PEB and +# fetching the list of loaded modules from there. That would solve the problem +# of toolhelp32 not working when the process hasn't finished initializing. +# See: http://pferrie.host22.com/misc/lowlevel3.htm + +class _ModuleContainer (object): + """ + Encapsulates the capability to contain Module objects. + + @note: Labels are an approximated way of referencing memory locations + across different executions of the same process, or different processes + with common modules. They are not meant to be perfectly unique, and + some errors may occur when multiple modules with the same name are + loaded, or when module filenames can't be retrieved. + + @group Modules snapshot: + scan_modules, + get_module, get_module_bases, get_module_count, + get_module_at_address, get_module_by_name, + has_module, iter_modules, iter_module_addresses, + clear_modules + + @group Labels: + parse_label, split_label, sanitize_label, resolve_label, + resolve_label_components, get_label_at_address, split_label_strict, + split_label_fuzzy + + @group Symbols: + load_symbols, unload_symbols, get_symbols, iter_symbols, + resolve_symbol, get_symbol_at_address + + @group Debugging: + is_system_defined_breakpoint, get_system_breakpoint, + get_user_breakpoint, get_breakin_breakpoint, + get_wow64_system_breakpoint, get_wow64_user_breakpoint, + get_wow64_breakin_breakpoint, get_break_on_error_ptr + """ + + def __init__(self): + self.__moduleDict = dict() + self.__system_breakpoints = dict() + + # Replace split_label with the fuzzy version on object instances. + self.split_label = self.__use_fuzzy_mode + + def __initialize_snapshot(self): + """ + Private method to automatically initialize the snapshot + when you try to use it without calling any of the scan_* + methods first. You don't need to call this yourself. + """ + if not self.__moduleDict: + try: + self.scan_modules() + except WindowsError: + pass + + def __contains__(self, anObject): + """ + @type anObject: L{Module}, int + @param anObject: + - C{Module}: Module object to look for. + - C{int}: Base address of the DLL to look for. + + @rtype: bool + @return: C{True} if the snapshot contains + a L{Module} object with the same base address. + """ + if isinstance(anObject, Module): + anObject = anObject.lpBaseOfDll + return self.has_module(anObject) + + def __iter__(self): + """ + @see: L{iter_modules} + @rtype: dictionary-valueiterator + @return: Iterator of L{Module} objects in this snapshot. + """ + return self.iter_modules() + + def __len__(self): + """ + @see: L{get_module_count} + @rtype: int + @return: Count of L{Module} objects in this snapshot. + """ + return self.get_module_count() + + def has_module(self, lpBaseOfDll): + """ + @type lpBaseOfDll: int + @param lpBaseOfDll: Base address of the DLL to look for. + + @rtype: bool + @return: C{True} if the snapshot contains a + L{Module} object with the given base address. + """ + self.__initialize_snapshot() + return lpBaseOfDll in self.__moduleDict + + def get_module(self, lpBaseOfDll): + """ + @type lpBaseOfDll: int + @param lpBaseOfDll: Base address of the DLL to look for. + + @rtype: L{Module} + @return: Module object with the given base address. + """ + self.__initialize_snapshot() + if lpBaseOfDll not in self.__moduleDict: + msg = "Unknown DLL base address %s" + msg = msg % HexDump.address(lpBaseOfDll) + raise KeyError(msg) + return self.__moduleDict[lpBaseOfDll] + + def iter_module_addresses(self): + """ + @see: L{iter_modules} + @rtype: dictionary-keyiterator + @return: Iterator of DLL base addresses in this snapshot. + """ + self.__initialize_snapshot() + return compat.iterkeys(self.__moduleDict) + + def iter_modules(self): + """ + @see: L{iter_module_addresses} + @rtype: dictionary-valueiterator + @return: Iterator of L{Module} objects in this snapshot. + """ + self.__initialize_snapshot() + return compat.itervalues(self.__moduleDict) + + def get_module_bases(self): + """ + @see: L{iter_module_addresses} + @rtype: list( int... ) + @return: List of DLL base addresses in this snapshot. + """ + self.__initialize_snapshot() + return compat.keys(self.__moduleDict) + + def get_module_count(self): + """ + @rtype: int + @return: Count of L{Module} objects in this snapshot. + """ + self.__initialize_snapshot() + return len(self.__moduleDict) + +#------------------------------------------------------------------------------ + + def get_module_by_name(self, modName): + """ + @type modName: int + @param modName: + Name of the module to look for, as returned by L{Module.get_name}. + If two or more modules with the same name are loaded, only one + of the matching modules is returned. + + You can also pass a full pathname to the DLL file. + This works correctly even if two modules with the same name + are loaded from different paths. + + @rtype: L{Module} + @return: C{Module} object that best matches the given name. + Returns C{None} if no C{Module} can be found. + """ + + # Convert modName to lowercase. + # This helps make case insensitive string comparisons. + modName = modName.lower() + + # modName is an absolute pathname. + if PathOperations.path_is_absolute(modName): + for lib in self.iter_modules(): + if modName == lib.get_filename().lower(): + return lib + return None # Stop trying to match the name. + + # Get all the module names. + # This prevents having to iterate through the module list + # more than once. + modDict = [ ( lib.get_name(), lib ) for lib in self.iter_modules() ] + modDict = dict(modDict) + + # modName is a base filename. + if modName in modDict: + return modDict[modName] + + # modName is a base filename without extension. + filepart, extpart = PathOperations.split_extension(modName) + if filepart and extpart: + if filepart in modDict: + return modDict[filepart] + + # modName is a base address. + try: + baseAddress = HexInput.integer(modName) + except ValueError: + return None + if self.has_module(baseAddress): + return self.get_module(baseAddress) + + # Module not found. + return None + + def get_module_at_address(self, address): + """ + @type address: int + @param address: Memory address to query. + + @rtype: L{Module} + @return: C{Module} object that best matches the given address. + Returns C{None} if no C{Module} can be found. + """ + bases = self.get_module_bases() + bases.sort() + bases.append(long(0x10000000000000000)) # max. 64 bit address + 1 + if address >= bases[0]: + i = 0 + max_i = len(bases) - 1 + while i < max_i: + begin, end = bases[i:i+2] + if begin <= address < end: + module = self.get_module(begin) + here = module.is_address_here(address) + if here is False: + break + else: # True or None + return module + i = i + 1 + return None + + # XXX this method musn't end up calling __initialize_snapshot by accident! + def scan_modules(self): + """ + Populates the snapshot with loaded modules. + """ + + # The module filenames may be spoofed by malware, + # since this information resides in usermode space. + # See: http://www.ragestorm.net/blogs/?p=163 + + # Ignore special process IDs. + # PID 0: System Idle Process. Also has a special meaning to the + # toolhelp APIs (current process). + # PID 4: System Integrity Group. See this forum post for more info: + # http://tinyurl.com/ycza8jo + # (points to social.technet.microsoft.com) + # Only on XP and above + # PID 8: System (?) only in Windows 2000 and below AFAIK. + # It's probably the same as PID 4 in XP and above. + dwProcessId = self.get_pid() + if dwProcessId in (0, 4, 8): + return + + # It would seem easier to clear the snapshot first. + # But then all open handles would be closed. + found_bases = set() + with win32.CreateToolhelp32Snapshot(win32.TH32CS_SNAPMODULE, + dwProcessId) as hSnapshot: + me = win32.Module32First(hSnapshot) + while me is not None: + lpBaseAddress = me.modBaseAddr + fileName = me.szExePath # full pathname + if not fileName: + fileName = me.szModule # filename only + if not fileName: + fileName = None + else: + fileName = PathOperations.native_to_win32_pathname(fileName) + found_bases.add(lpBaseAddress) +## if not self.has_module(lpBaseAddress): # XXX triggers a scan + if lpBaseAddress not in self.__moduleDict: + aModule = Module(lpBaseAddress, fileName = fileName, + SizeOfImage = me.modBaseSize, + process = self) + self._add_module(aModule) + else: + aModule = self.get_module(lpBaseAddress) + if not aModule.fileName: + aModule.fileName = fileName + if not aModule.SizeOfImage: + aModule.SizeOfImage = me.modBaseSize + if not aModule.process: + aModule.process = self + me = win32.Module32Next(hSnapshot) +## for base in self.get_module_bases(): # XXX triggers a scan + for base in compat.keys(self.__moduleDict): + if base not in found_bases: + self._del_module(base) + + def clear_modules(self): + """ + Clears the modules snapshot. + """ + for aModule in compat.itervalues(self.__moduleDict): + aModule.clear() + self.__moduleDict = dict() + +#------------------------------------------------------------------------------ + + @staticmethod + def parse_label(module = None, function = None, offset = None): + """ + Creates a label from a module and a function name, plus an offset. + + @warning: This method only creates the label, it doesn't make sure the + label actually points to a valid memory location. + + @type module: None or str + @param module: (Optional) Module name. + + @type function: None, str or int + @param function: (Optional) Function name or ordinal. + + @type offset: None or int + @param offset: (Optional) Offset value. + + If C{function} is specified, offset from the function. + + If C{function} is C{None}, offset from the module. + + @rtype: str + @return: + Label representing the given function in the given module. + + @raise ValueError: + The module or function name contain invalid characters. + """ + + # TODO + # Invalid characters should be escaped or filtered. + + # Convert ordinals to strings. + try: + function = "#0x%x" % function + except TypeError: + pass + + # Validate the parameters. + if module is not None and ('!' in module or '+' in module): + raise ValueError("Invalid module name: %s" % module) + if function is not None and ('!' in function or '+' in function): + raise ValueError("Invalid function name: %s" % function) + + # Parse the label. + if module: + if function: + if offset: + label = "%s!%s+0x%x" % (module, function, offset) + else: + label = "%s!%s" % (module, function) + else: + if offset: +## label = "%s+0x%x!" % (module, offset) + label = "%s!0x%x" % (module, offset) + else: + label = "%s!" % module + else: + if function: + if offset: + label = "!%s+0x%x" % (function, offset) + else: + label = "!%s" % function + else: + if offset: + label = "0x%x" % offset + else: + label = "0x0" + + return label + + @staticmethod + def split_label_strict(label): + """ + Splits a label created with L{parse_label}. + + To parse labels with a less strict syntax, use the L{split_label_fuzzy} + method instead. + + @warning: This method only parses the label, it doesn't make sure the + label actually points to a valid memory location. + + @type label: str + @param label: Label to split. + + @rtype: tuple( str or None, str or int or None, int or None ) + @return: Tuple containing the C{module} name, + the C{function} name or ordinal, and the C{offset} value. + + If the label doesn't specify a module, + then C{module} is C{None}. + + If the label doesn't specify a function, + then C{function} is C{None}. + + If the label doesn't specify an offset, + then C{offset} is C{0}. + + @raise ValueError: The label is malformed. + """ + module = function = None + offset = 0 + + # Special case: None + if not label: + label = "0x0" + else: + + # Remove all blanks. + label = label.replace(' ', '') + label = label.replace('\t', '') + label = label.replace('\r', '') + label = label.replace('\n', '') + + # Special case: empty label. + if not label: + label = "0x0" + + # * ! * + if '!' in label: + try: + module, function = label.split('!') + except ValueError: + raise ValueError("Malformed label: %s" % label) + + # module ! function + if function: + if '+' in module: + raise ValueError("Malformed label: %s" % label) + + # module ! function + offset + if '+' in function: + try: + function, offset = function.split('+') + except ValueError: + raise ValueError("Malformed label: %s" % label) + try: + offset = HexInput.integer(offset) + except ValueError: + raise ValueError("Malformed label: %s" % label) + else: + + # module ! offset + try: + offset = HexInput.integer(function) + function = None + except ValueError: + pass + else: + + # module + offset ! + if '+' in module: + try: + module, offset = module.split('+') + except ValueError: + raise ValueError("Malformed label: %s" % label) + try: + offset = HexInput.integer(offset) + except ValueError: + raise ValueError("Malformed label: %s" % label) + + else: + + # module ! + try: + offset = HexInput.integer(module) + module = None + + # offset ! + except ValueError: + pass + + if not module: + module = None + if not function: + function = None + + # * + else: + + # offset + try: + offset = HexInput.integer(label) + + # # ordinal + except ValueError: + if label.startswith('#'): + function = label + try: + HexInput.integer(function[1:]) + + # module? + # function? + except ValueError: + raise ValueError("Ambiguous label: %s" % label) + + # module? + # function? + else: + raise ValueError("Ambiguous label: %s" % label) + + # Convert function ordinal strings into integers. + if function and function.startswith('#'): + try: + function = HexInput.integer(function[1:]) + except ValueError: + pass + + # Convert null offsets to None. + if not offset: + offset = None + + return (module, function, offset) + + def split_label_fuzzy(self, label): + """ + Splits a label entered as user input. + + It's more flexible in it's syntax parsing than the L{split_label_strict} + method, as it allows the exclamation mark (B{C{!}}) to be omitted. The + ambiguity is resolved by searching the modules in the snapshot to guess + if a label refers to a module or a function. It also tries to rebuild + labels when they contain hardcoded addresses. + + @warning: This method only parses the label, it doesn't make sure the + label actually points to a valid memory location. + + @type label: str + @param label: Label to split. + + @rtype: tuple( str or None, str or int or None, int or None ) + @return: Tuple containing the C{module} name, + the C{function} name or ordinal, and the C{offset} value. + + If the label doesn't specify a module, + then C{module} is C{None}. + + If the label doesn't specify a function, + then C{function} is C{None}. + + If the label doesn't specify an offset, + then C{offset} is C{0}. + + @raise ValueError: The label is malformed. + """ + module = function = None + offset = 0 + + # Special case: None + if not label: + label = compat.b("0x0") + else: + + # Remove all blanks. + label = label.replace(compat.b(' '), compat.b('')) + label = label.replace(compat.b('\t'), compat.b('')) + label = label.replace(compat.b('\r'), compat.b('')) + label = label.replace(compat.b('\n'), compat.b('')) + + # Special case: empty label. + if not label: + label = compat.b("0x0") + + # If an exclamation sign is present, we know we can parse it strictly. + if compat.b('!') in label: + return self.split_label_strict(label) + +## # Try to parse it strictly, on error do it the fuzzy way. +## try: +## return self.split_label(label) +## except ValueError: +## pass + + # * + offset + if compat.b('+') in label: + try: + prefix, offset = label.split(compat.b('+')) + except ValueError: + raise ValueError("Malformed label: %s" % label) + try: + offset = HexInput.integer(offset) + except ValueError: + raise ValueError("Malformed label: %s" % label) + label = prefix + + # This parses both filenames and base addresses. + modobj = self.get_module_by_name(label) + if modobj: + + # module + # module + offset + module = modobj.get_name() + + else: + + # TODO + # If 0xAAAAAAAA + 0xBBBBBBBB is given, + # A is interpreted as a module base address, + # and B as an offset. + # If that fails, it'd be good to add A+B and try to + # use the nearest loaded module. + + # offset + # base address + offset (when no module has that base address) + try: + address = HexInput.integer(label) + + if offset: + # If 0xAAAAAAAA + 0xBBBBBBBB is given, + # A is interpreted as a module base address, + # and B as an offset. + # If that fails, we get here, meaning no module was found + # at A. Then add up A+B and work with that as a hardcoded + # address. + offset = address + offset + else: + # If the label is a hardcoded address, we get here. + offset = address + + # If only a hardcoded address is given, + # rebuild the label using get_label_at_address. + # Then parse it again, but this time strictly, + # both because there is no need for fuzzy syntax and + # to prevent an infinite recursion if there's a bug here. + try: + new_label = self.get_label_at_address(offset) + module, function, offset = \ + self.split_label_strict(new_label) + except ValueError: + pass + + # function + # function + offset + except ValueError: + function = label + + # Convert function ordinal strings into integers. + if function and function.startswith(compat.b('#')): + try: + function = HexInput.integer(function[1:]) + except ValueError: + pass + + # Convert null offsets to None. + if not offset: + offset = None + + return (module, function, offset) + + @classmethod + def split_label(cls, label): + """ +Splits a label into it's C{module}, C{function} and C{offset} +components, as used in L{parse_label}. + +When called as a static method, the strict syntax mode is used:: + + winappdbg.Process.split_label( "kernel32!CreateFileA" ) + +When called as an instance method, the fuzzy syntax mode is used:: + + aProcessInstance.split_label( "CreateFileA" ) + +@see: L{split_label_strict}, L{split_label_fuzzy} + +@type label: str +@param label: Label to split. + +@rtype: tuple( str or None, str or int or None, int or None ) +@return: + Tuple containing the C{module} name, + the C{function} name or ordinal, and the C{offset} value. + + If the label doesn't specify a module, + then C{module} is C{None}. + + If the label doesn't specify a function, + then C{function} is C{None}. + + If the label doesn't specify an offset, + then C{offset} is C{0}. + +@raise ValueError: The label is malformed. + """ + + # XXX + # Docstring indentation was removed so epydoc doesn't complain + # when parsing the docs for __use_fuzzy_mode(). + + # This function is overwritten by __init__ + # so here is the static implementation only. + return cls.split_label_strict(label) + + # The split_label method is replaced with this function by __init__. + def __use_fuzzy_mode(self, label): + "@see: L{split_label}" + return self.split_label_fuzzy(label) +## __use_fuzzy_mode.__doc__ = split_label.__doc__ + + def sanitize_label(self, label): + """ + Converts a label taken from user input into a well-formed label. + + @type label: str + @param label: Label taken from user input. + + @rtype: str + @return: Sanitized label. + """ + (module, function, offset) = self.split_label_fuzzy(label) + label = self.parse_label(module, function, offset) + return label + + def resolve_label(self, label): + """ + Resolve the memory address of the given label. + + @note: + If multiple modules with the same name are loaded, + the label may be resolved at any of them. For a more precise + way to resolve functions use the base address to get the L{Module} + object (see L{Process.get_module}) and then call L{Module.resolve}. + + If no module name is specified in the label, the function may be + resolved in any loaded module. If you want to resolve all functions + with that name in all processes, call L{Process.iter_modules} to + iterate through all loaded modules, and then try to resolve the + function in each one of them using L{Module.resolve}. + + @type label: str + @param label: Label to resolve. + + @rtype: int + @return: Memory address pointed to by the label. + + @raise ValueError: The label is malformed or impossible to resolve. + @raise RuntimeError: Cannot resolve the module or function. + """ + + # Split the label into module, function and offset components. + module, function, offset = self.split_label_fuzzy(label) + + # Resolve the components into a memory address. + address = self.resolve_label_components(module, function, offset) + + # Return the memory address. + return address + + def resolve_label_components(self, module = None, + function = None, + offset = None): + """ + Resolve the memory address of the given module, function and/or offset. + + @note: + If multiple modules with the same name are loaded, + the label may be resolved at any of them. For a more precise + way to resolve functions use the base address to get the L{Module} + object (see L{Process.get_module}) and then call L{Module.resolve}. + + If no module name is specified in the label, the function may be + resolved in any loaded module. If you want to resolve all functions + with that name in all processes, call L{Process.iter_modules} to + iterate through all loaded modules, and then try to resolve the + function in each one of them using L{Module.resolve}. + + @type module: None or str + @param module: (Optional) Module name. + + @type function: None, str or int + @param function: (Optional) Function name or ordinal. + + @type offset: None or int + @param offset: (Optional) Offset value. + + If C{function} is specified, offset from the function. + + If C{function} is C{None}, offset from the module. + + @rtype: int + @return: Memory address pointed to by the label. + + @raise ValueError: The label is malformed or impossible to resolve. + @raise RuntimeError: Cannot resolve the module or function. + """ + # Default address if no module or function are given. + # An offset may be added later. + address = 0 + + # Resolve the module. + # If the module is not found, check for the special symbol "main". + if module: + modobj = self.get_module_by_name(module) + if not modobj: + if module == "main": + modobj = self.get_main_module() + else: + raise RuntimeError("Module %r not found" % module) + + # Resolve the exported function or debugging symbol. + # If all else fails, check for the special symbol "start". + if function: + address = modobj.resolve(function) + if address is None: + address = modobj.resolve_symbol(function) + if address is None: + if function == "start": + address = modobj.get_entry_point() + if address is None: + msg = "Symbol %r not found in module %s" + raise RuntimeError(msg % (function, module)) + + # No function, use the base address. + else: + address = modobj.get_base() + + # Resolve the function in any module. + # If all else fails, check for the special symbols "main" and "start". + elif function: + for modobj in self.iter_modules(): + address = modobj.resolve(function) + if address is not None: + break + if address is None: + if function == "start": + modobj = self.get_main_module() + address = modobj.get_entry_point() + elif function == "main": + modobj = self.get_main_module() + address = modobj.get_base() + else: + msg = "Function %r not found in any module" % function + raise RuntimeError(msg) + + # Return the address plus the offset. + if offset: + address = address + offset + return address + + def get_label_at_address(self, address, offset = None): + """ + Creates a label from the given memory address. + + @warning: This method uses the name of the nearest currently loaded + module. If that module is unloaded later, the label becomes + impossible to resolve. + + @type address: int + @param address: Memory address. + + @type offset: None or int + @param offset: (Optional) Offset value. + + @rtype: str + @return: Label pointing to the given address. + """ + if offset: + address = address + offset + modobj = self.get_module_at_address(address) + if modobj: + label = modobj.get_label_at_address(address) + else: + label = self.parse_label(None, None, address) + return label + +#------------------------------------------------------------------------------ + + # The memory addresses of system breakpoints are be cached, since they're + # all in system libraries it's not likely they'll ever change their address + # during the lifetime of the process... I don't suppose a program could + # happily unload ntdll.dll and survive. + def __get_system_breakpoint(self, label): + try: + return self.__system_breakpoints[label] + except KeyError: + try: + address = self.resolve_label(label) + except Exception: + return None + self.__system_breakpoints[label] = address + return address + + # It's in kernel32 in Windows Server 2003, in ntdll since Windows Vista. + # It can only be resolved if we have the debug symbols. + def get_break_on_error_ptr(self): + """ + @rtype: int + @return: + If present, returns the address of the C{g_dwLastErrorToBreakOn} + global variable for this process. If not, returns C{None}. + """ + address = self.__get_system_breakpoint("ntdll!g_dwLastErrorToBreakOn") + if not address: + address = self.__get_system_breakpoint( + "kernel32!g_dwLastErrorToBreakOn") + # cheat a little :) + self.__system_breakpoints["ntdll!g_dwLastErrorToBreakOn"] = address + return address + + def is_system_defined_breakpoint(self, address): + """ + @type address: int + @param address: Memory address. + + @rtype: bool + @return: C{True} if the given address points to a system defined + breakpoint. System defined breakpoints are hardcoded into + system libraries. + """ + if address: + module = self.get_module_at_address(address) + if module: + return module.match_name("ntdll") or \ + module.match_name("kernel32") + return False + + # FIXME + # In Wine, the system breakpoint seems to be somewhere in kernel32. + def get_system_breakpoint(self): + """ + @rtype: int or None + @return: Memory address of the system breakpoint + within the process address space. + Returns C{None} on error. + """ + return self.__get_system_breakpoint("ntdll!DbgBreakPoint") + + # I don't know when this breakpoint is actually used... + def get_user_breakpoint(self): + """ + @rtype: int or None + @return: Memory address of the user breakpoint + within the process address space. + Returns C{None} on error. + """ + return self.__get_system_breakpoint("ntdll!DbgUserBreakPoint") + + # On some platforms, this breakpoint can only be resolved + # when the debugging symbols for ntdll.dll are loaded. + def get_breakin_breakpoint(self): + """ + @rtype: int or None + @return: Memory address of the remote breakin breakpoint + within the process address space. + Returns C{None} on error. + """ + return self.__get_system_breakpoint("ntdll!DbgUiRemoteBreakin") + + # Equivalent of ntdll!DbgBreakPoint in Wow64. + def get_wow64_system_breakpoint(self): + """ + @rtype: int or None + @return: Memory address of the Wow64 system breakpoint + within the process address space. + Returns C{None} on error. + """ + return self.__get_system_breakpoint("ntdll32!DbgBreakPoint") + + # Equivalent of ntdll!DbgUserBreakPoint in Wow64. + def get_wow64_user_breakpoint(self): + """ + @rtype: int or None + @return: Memory address of the Wow64 user breakpoint + within the process address space. + Returns C{None} on error. + """ + return self.__get_system_breakpoint("ntdll32!DbgUserBreakPoint") + + # Equivalent of ntdll!DbgUiRemoteBreakin in Wow64. + def get_wow64_breakin_breakpoint(self): + """ + @rtype: int or None + @return: Memory address of the Wow64 remote breakin breakpoint + within the process address space. + Returns C{None} on error. + """ + return self.__get_system_breakpoint("ntdll32!DbgUiRemoteBreakin") + +#------------------------------------------------------------------------------ + + def load_symbols(self): + """ + Loads the debugging symbols for all modules in this snapshot. + Automatically called by L{get_symbols}. + """ + for aModule in self.iter_modules(): + aModule.load_symbols() + + def unload_symbols(self): + """ + Unloads the debugging symbols for all modules in this snapshot. + """ + for aModule in self.iter_modules(): + aModule.unload_symbols() + + def get_symbols(self): + """ + Returns the debugging symbols for all modules in this snapshot. + The symbols are automatically loaded when needed. + + @rtype: list of tuple( str, int, int ) + @return: List of symbols. + Each symbol is represented by a tuple that contains: + - Symbol name + - Symbol memory address + - Symbol size in bytes + """ + symbols = list() + for aModule in self.iter_modules(): + for symbol in aModule.iter_symbols(): + symbols.append(symbol) + return symbols + + def iter_symbols(self): + """ + Returns an iterator for the debugging symbols in all modules in this + snapshot, in no particular order. + The symbols are automatically loaded when needed. + + @rtype: iterator of tuple( str, int, int ) + @return: Iterator of symbols. + Each symbol is represented by a tuple that contains: + - Symbol name + - Symbol memory address + - Symbol size in bytes + """ + for aModule in self.iter_modules(): + for symbol in aModule.iter_symbols(): + yield symbol + + def resolve_symbol(self, symbol, bCaseSensitive = False): + """ + Resolves a debugging symbol's address. + + @type symbol: str + @param symbol: Name of the symbol to resolve. + + @type bCaseSensitive: bool + @param bCaseSensitive: C{True} for case sensitive matches, + C{False} for case insensitive. + + @rtype: int or None + @return: Memory address of symbol. C{None} if not found. + """ + if bCaseSensitive: + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + if symbol == SymbolName: + return SymbolAddress + else: + symbol = symbol.lower() + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + if symbol == SymbolName.lower(): + return SymbolAddress + + def get_symbol_at_address(self, address): + """ + Tries to find the closest matching symbol for the given address. + + @type address: int + @param address: Memory address to query. + + @rtype: None or tuple( str, int, int ) + @return: Returns a tuple consisting of: + - Name + - Address + - Size (in bytes) + Returns C{None} if no symbol could be matched. + """ + # Any module may have symbols pointing anywhere in memory, so there's + # no easy way to optimize this. I guess we're stuck with brute force. + found = None + for (SymbolName, SymbolAddress, SymbolSize) in self.iter_symbols(): + if SymbolAddress > address: + continue + + if SymbolAddress == address: + found = (SymbolName, SymbolAddress, SymbolSize) + break + + if SymbolAddress < address: + if found and (address - found[1]) < (address - SymbolAddress): + continue + else: + found = (SymbolName, SymbolAddress, SymbolSize) + return found +#------------------------------------------------------------------------------ + + # XXX _notify_* methods should not trigger a scan + + def _add_module(self, aModule): + """ + Private method to add a module object to the snapshot. + + @type aModule: L{Module} + @param aModule: Module object. + """ +## if not isinstance(aModule, Module): +## if hasattr(aModule, '__class__'): +## typename = aModule.__class__.__name__ +## else: +## typename = str(type(aModule)) +## msg = "Expected Module, got %s instead" % typename +## raise TypeError(msg) + lpBaseOfDll = aModule.get_base() +## if lpBaseOfDll in self.__moduleDict: +## msg = "Module already exists: %d" % lpBaseOfDll +## raise KeyError(msg) + aModule.set_process(self) + self.__moduleDict[lpBaseOfDll] = aModule + + def _del_module(self, lpBaseOfDll): + """ + Private method to remove a module object from the snapshot. + + @type lpBaseOfDll: int + @param lpBaseOfDll: Module base address. + """ + try: + aModule = self.__moduleDict[lpBaseOfDll] + del self.__moduleDict[lpBaseOfDll] + except KeyError: + aModule = None + msg = "Unknown base address %d" % HexDump.address(lpBaseOfDll) + warnings.warn(msg, RuntimeWarning) + if aModule: + aModule.clear() # remove circular references + + def __add_loaded_module(self, event): + """ + Private method to automatically add new module objects from debug events. + + @type event: L{Event} + @param event: Event object. + """ + lpBaseOfDll = event.get_module_base() + hFile = event.get_file_handle() +## if not self.has_module(lpBaseOfDll): # XXX this would trigger a scan + if lpBaseOfDll not in self.__moduleDict: + fileName = event.get_filename() + if not fileName: + fileName = None + if hasattr(event, 'get_start_address'): + EntryPoint = event.get_start_address() + else: + EntryPoint = None + aModule = Module(lpBaseOfDll, hFile, fileName = fileName, + EntryPoint = EntryPoint, + process = self) + self._add_module(aModule) + else: + aModule = self.get_module(lpBaseOfDll) + if not aModule.hFile and hFile not in (None, 0, + win32.INVALID_HANDLE_VALUE): + aModule.hFile = hFile + if not aModule.process: + aModule.process = self + if aModule.EntryPoint is None and \ + hasattr(event, 'get_start_address'): + aModule.EntryPoint = event.get_start_address() + if not aModule.fileName: + fileName = event.get_filename() + if fileName: + aModule.fileName = fileName + + def _notify_create_process(self, event): + """ + Notify the load of the main module. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{CreateProcessEvent} + @param event: Create process event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + self.__add_loaded_module(event) + return True + + def _notify_load_dll(self, event): + """ + Notify the load of a new module. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{LoadDLLEvent} + @param event: Load DLL event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + self.__add_loaded_module(event) + return True + + def _notify_unload_dll(self, event): + """ + Notify the release of a loaded module. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{UnloadDLLEvent} + @param event: Unload DLL event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + lpBaseOfDll = event.get_module_base() +## if self.has_module(lpBaseOfDll): # XXX this would trigger a scan + if lpBaseOfDll in self.__moduleDict: + self._del_module(lpBaseOfDll) + return True diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/README b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/README new file mode 100644 index 0000000..9d0fea9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/README @@ -0,0 +1 @@ +Here go the plugins for the interactive debugger. \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/__init__.py new file mode 100644 index 0000000..3836e09 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/__init__.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Plugins folder for the WinAppDbg interactive debugger. +""" + +__revision__ = "$Id: __init__.py 1125 2012-10-22 14:54:39Z qvasimodo $" diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_example.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_example.py new file mode 100644 index 0000000..591ce68 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_example.py @@ -0,0 +1,41 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Command line debugger using WinAppDbg +# Example command +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +__revision__ = "$Id$" + +def do(self, arg): + ".example - This is an example plugin for the command line debugger" + print "This is an example command." + print "%s.do(%r, %r):" % (__name__, self, arg) + print " last event", self.lastEvent + print " prefix", self.cmdprefix + print " arguments", self.split_tokens(arg) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_exchain.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_exchain.py new file mode 100644 index 0000000..aa97fec --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_exchain.py @@ -0,0 +1,51 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Command line debugger using WinAppDbg +# Show exception handlers list +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +__revision__ = "$Id$" + +from winappdbg import HexDump, Table + +def do(self, arg): + ".exchain - Show the SEH chain" + thread = self.get_thread_from_prefix() + print "Exception handlers for thread %d" % thread.get_tid() + print + table = Table() + table.addRow("Block", "Function") + bits = thread.get_bits() + for (seh, seh_func) in thread.get_seh_chain(): + if seh is not None: + seh = HexDump.address(seh, bits) + if seh_func is not None: + seh_func = HexDump.address(seh_func, bits) + table.addRow(seh, seh_func) + print table.getOutput() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_exploitable.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_exploitable.py new file mode 100644 index 0000000..64e93f6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_exploitable.py @@ -0,0 +1,50 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Command line debugger using WinAppDbg +# Determine the approximate exploitability rating +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +__revision__ = "$Id$" + +def do(self, arg): + ".exploitable - Determine the approximate exploitability rating" + + from winappdbg import Crash + + event = self.debug.lastEvent + crash = Crash(event) + crash.fetch_extra_data(event) + + status, rule, description = crash.isExploitable() + + print "-" * 79 + print "Exploitability: %s" % status + print "Matched rule: %s" % rule + print "Description: %s" % description + print "-" * 79 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_symfix.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_symfix.py new file mode 100644 index 0000000..cccfbe9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/plugins/do_symfix.py @@ -0,0 +1,37 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Command line debugger using WinAppDbg +# Fix the symbol store path +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +__revision__ = "$Id$" + +def do(self, arg): + ".symfix - Set the default Microsoft Symbol Store settings if missing" + self.debug.system.fix_symbol_store_path(remote = True, force = False) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py new file mode 100644 index 0000000..6d75f80 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py @@ -0,0 +1,5021 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Process instrumentation. + +@group Instrumentation: + Process +""" + +from __future__ import with_statement + +# FIXME +# I've been told the host process for the latest versions of VMWare +# can't be instrumented, because they try to stop code injection into the VMs. +# The solution appears to be to run the debugger from a user account that +# belongs to the VMware group. I haven't confirmed this yet. + +__revision__ = "$Id$" + +__all__ = ['Process'] + +import sys +from winappdbg import win32 +from winappdbg import compat +from winappdbg.textio import HexDump, HexInput +from winappdbg.util import Regenerator, PathOperations, MemoryAddresses +from winappdbg.module import Module, _ModuleContainer +from winappdbg.thread import Thread, _ThreadContainer +from winappdbg.window import Window +from winappdbg.search import Search, \ + Pattern, BytePattern, TextPattern, RegExpPattern, HexPattern +from winappdbg.disasm import Disassembler + +import re +import os +import os.path +import ctypes +import struct +import warnings +import traceback + +# delayed import +System = None + +#============================================================================== + +# TODO +# * Remote GetLastError() +# * The memory operation methods do not take into account that code breakpoints +# change the memory. This object should talk to BreakpointContainer to +# retrieve the original memory contents where code breakpoints are enabled. +# * A memory cache could be implemented here. + +class Process (_ThreadContainer, _ModuleContainer): + """ + Interface to a process. Contains threads and modules snapshots. + + @group Properties: + get_pid, is_alive, is_debugged, is_wow64, get_arch, get_bits, + get_filename, get_exit_code, + get_start_time, get_exit_time, get_running_time, + get_services, get_dep_policy, get_peb, get_peb_address, + get_entry_point, get_main_module, get_image_base, get_image_name, + get_command_line, get_environment, + get_command_line_block, + get_environment_block, get_environment_variables, + get_handle, open_handle, close_handle + + @group Instrumentation: + kill, wait, suspend, resume, inject_code, inject_dll, clean_exit + + @group Disassembly: + disassemble, disassemble_around, disassemble_around_pc, + disassemble_string, disassemble_instruction, disassemble_current + + @group Debugging: + flush_instruction_cache, debug_break, peek_pointers_in_data + + @group Memory mapping: + take_memory_snapshot, generate_memory_snapshot, iter_memory_snapshot, + restore_memory_snapshot, get_memory_map, get_mapped_filenames, + generate_memory_map, iter_memory_map, + is_pointer, is_address_valid, is_address_free, is_address_reserved, + is_address_commited, is_address_guard, is_address_readable, + is_address_writeable, is_address_copy_on_write, is_address_executable, + is_address_executable_and_writeable, + is_buffer, + is_buffer_readable, is_buffer_writeable, is_buffer_executable, + is_buffer_executable_and_writeable, is_buffer_copy_on_write + + @group Memory allocation: + malloc, free, mprotect, mquery + + @group Memory read: + read, read_char, read_int, read_uint, read_float, read_double, + read_dword, read_qword, read_pointer, read_string, read_structure, + peek, peek_char, peek_int, peek_uint, peek_float, peek_double, + peek_dword, peek_qword, peek_pointer, peek_string + + @group Memory write: + write, write_char, write_int, write_uint, write_float, write_double, + write_dword, write_qword, write_pointer, + poke, poke_char, poke_int, poke_uint, poke_float, poke_double, + poke_dword, poke_qword, poke_pointer + + @group Memory search: + search, search_bytes, search_hexa, search_text, search_regexp, strings + + @group Processes snapshot: + scan, clear, __contains__, __iter__, __len__ + + @group Deprecated: + get_environment_data, parse_environment_data + + @type dwProcessId: int + @ivar dwProcessId: Global process ID. Use L{get_pid} instead. + + @type hProcess: L{ProcessHandle} + @ivar hProcess: Handle to the process. Use L{get_handle} instead. + + @type fileName: str + @ivar fileName: Filename of the main module. Use L{get_filename} instead. + """ + + def __init__(self, dwProcessId, hProcess = None, fileName = None): + """ + @type dwProcessId: int + @param dwProcessId: Global process ID. + + @type hProcess: L{ProcessHandle} + @param hProcess: Handle to the process. + + @type fileName: str + @param fileName: (Optional) Filename of the main module. + """ + _ThreadContainer.__init__(self) + _ModuleContainer.__init__(self) + + self.dwProcessId = dwProcessId + self.hProcess = hProcess + self.fileName = fileName + + def get_pid(self): + """ + @rtype: int + @return: Process global ID. + """ + return self.dwProcessId + + def get_filename(self): + """ + @rtype: str + @return: Filename of the main module of the process. + """ + if not self.fileName: + self.fileName = self.get_image_name() + return self.fileName + + def open_handle(self, dwDesiredAccess = win32.PROCESS_ALL_ACCESS): + """ + Opens a new handle to the process. + + The new handle is stored in the L{hProcess} property. + + @warn: Normally you should call L{get_handle} instead, since it's much + "smarter" and tries to reuse handles and merge access rights. + + @type dwDesiredAccess: int + @param dwDesiredAccess: Desired access rights. + Defaults to L{win32.PROCESS_ALL_ACCESS}. + See: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx} + + @raise WindowsError: It's not possible to open a handle to the process + with the requested access rights. This tipically happens because + the target process is a system process and the debugger is not + runnning with administrative rights. + """ + hProcess = win32.OpenProcess(dwDesiredAccess, win32.FALSE, self.dwProcessId) + + try: + self.close_handle() + except Exception: + warnings.warn( + "Failed to close process handle: %s" % traceback.format_exc()) + + self.hProcess = hProcess + + def close_handle(self): + """ + Closes the handle to the process. + + @note: Normally you don't need to call this method. All handles + created by I{WinAppDbg} are automatically closed when the garbage + collector claims them. So unless you've been tinkering with it, + setting L{hProcess} to C{None} should be enough. + """ + try: + if hasattr(self.hProcess, 'close'): + self.hProcess.close() + elif self.hProcess not in (None, win32.INVALID_HANDLE_VALUE): + win32.CloseHandle(self.hProcess) + finally: + self.hProcess = None + + def get_handle(self, dwDesiredAccess = win32.PROCESS_ALL_ACCESS): + """ + Returns a handle to the process with I{at least} the access rights + requested. + + @note: + If a handle was previously opened and has the required access + rights, it's reused. If not, a new handle is opened with the + combination of the old and new access rights. + + @type dwDesiredAccess: int + @param dwDesiredAccess: Desired access rights. + Defaults to L{win32.PROCESS_ALL_ACCESS}. + See: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx} + + @rtype: L{ProcessHandle} + @return: Handle to the process. + + @raise WindowsError: It's not possible to open a handle to the process + with the requested access rights. This tipically happens because + the target process is a system process and the debugger is not + runnning with administrative rights. + """ + if self.hProcess in (None, win32.INVALID_HANDLE_VALUE): + self.open_handle(dwDesiredAccess) + else: + dwAccess = self.hProcess.dwAccess + if (dwAccess | dwDesiredAccess) != dwAccess: + self.open_handle(dwAccess | dwDesiredAccess) + return self.hProcess + +#------------------------------------------------------------------------------ + + # Not really sure if it's a good idea... +## def __eq__(self, aProcess): +## """ +## Compare two Process objects. The comparison is made using the IDs. +## +## @warning: +## If you have two Process instances with different handles the +## equality operator still returns C{True}, so be careful! +## +## @type aProcess: L{Process} +## @param aProcess: Another Process object. +## +## @rtype: bool +## @return: C{True} if the two process IDs are equal, +## C{False} otherwise. +## """ +## return isinstance(aProcess, Process) and \ +## self.get_pid() == aProcess.get_pid() + + def __contains__(self, anObject): + """ + The same as: C{self.has_thread(anObject) or self.has_module(anObject)} + + @type anObject: L{Thread}, L{Module} or int + @param anObject: Object to look for. + Can be a Thread, Module, thread global ID or module base address. + + @rtype: bool + @return: C{True} if the requested object was found in the snapshot. + """ + return _ThreadContainer.__contains__(self, anObject) or \ + _ModuleContainer.__contains__(self, anObject) + + def __len__(self): + """ + @see: L{get_thread_count}, L{get_module_count} + @rtype: int + @return: Count of L{Thread} and L{Module} objects in this snapshot. + """ + return _ThreadContainer.__len__(self) + \ + _ModuleContainer.__len__(self) + + class __ThreadsAndModulesIterator (object): + """ + Iterator object for L{Process} objects. + Iterates through L{Thread} objects first, L{Module} objects next. + """ + + def __init__(self, container): + """ + @type container: L{Process} + @param container: L{Thread} and L{Module} container. + """ + self.__container = container + self.__iterator = None + self.__state = 0 + + def __iter__(self): + 'x.__iter__() <==> iter(x)' + return self + + def next(self): + 'x.next() -> the next value, or raise StopIteration' + if self.__state == 0: + self.__iterator = self.__container.iter_threads() + self.__state = 1 + if self.__state == 1: + try: + return self.__iterator.next() + except StopIteration: + self.__iterator = self.__container.iter_modules() + self.__state = 2 + if self.__state == 2: + try: + return self.__iterator.next() + except StopIteration: + self.__iterator = None + self.__state = 3 + raise StopIteration + + def __iter__(self): + """ + @see: L{iter_threads}, L{iter_modules} + @rtype: iterator + @return: Iterator of L{Thread} and L{Module} objects in this snapshot. + All threads are iterated first, then all modules. + """ + return self.__ThreadsAndModulesIterator(self) + +#------------------------------------------------------------------------------ + + def wait(self, dwTimeout = None): + """ + Waits for the process to finish executing. + + @raise WindowsError: On error an exception is raised. + """ + self.get_handle(win32.SYNCHRONIZE).wait(dwTimeout) + + def kill(self, dwExitCode = 0): + """ + Terminates the execution of the process. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle(win32.PROCESS_TERMINATE) + win32.TerminateProcess(hProcess, dwExitCode) + + def suspend(self): + """ + Suspends execution on all threads of the process. + + @raise WindowsError: On error an exception is raised. + """ + self.scan_threads() # force refresh the snapshot + suspended = list() + try: + for aThread in self.iter_threads(): + aThread.suspend() + suspended.append(aThread) + except Exception: + for aThread in suspended: + try: + aThread.resume() + except Exception: + pass + raise + + def resume(self): + """ + Resumes execution on all threads of the process. + + @raise WindowsError: On error an exception is raised. + """ + if self.get_thread_count() == 0: + self.scan_threads() # only refresh the snapshot if empty + resumed = list() + try: + for aThread in self.iter_threads(): + aThread.resume() + resumed.append(aThread) + except Exception: + for aThread in resumed: + try: + aThread.suspend() + except Exception: + pass + raise + + def is_debugged(self): + """ + Tries to determine if the process is being debugged by another process. + It may detect other debuggers besides WinAppDbg. + + @rtype: bool + @return: C{True} if the process has a debugger attached. + + @warning: + May return inaccurate results when some anti-debug techniques are + used by the target process. + + @note: To know if a process currently being debugged by a L{Debug} + object, call L{Debug.is_debugee} instead. + """ + # FIXME the MSDN docs don't say what access rights are needed here! + hProcess = self.get_handle(win32.PROCESS_QUERY_INFORMATION) + return win32.CheckRemoteDebuggerPresent(hProcess) + + def is_alive(self): + """ + @rtype: bool + @return: C{True} if the process is currently running. + """ + try: + self.wait(0) + except WindowsError: + e = sys.exc_info()[1] + return e.winerror == win32.WAIT_TIMEOUT + return False + + def get_exit_code(self): + """ + @rtype: int + @return: Process exit code, or C{STILL_ACTIVE} if it's still alive. + + @warning: If a process returns C{STILL_ACTIVE} as it's exit code, + you may not be able to determine if it's active or not with this + method. Use L{is_alive} to check if the process is still active. + Alternatively you can call L{get_handle} to get the handle object + and then L{ProcessHandle.wait} on it to wait until the process + finishes running. + """ + if win32.PROCESS_ALL_ACCESS == win32.PROCESS_ALL_ACCESS_VISTA: + dwAccess = win32.PROCESS_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.PROCESS_QUERY_INFORMATION + return win32.GetExitCodeProcess( self.get_handle(dwAccess) ) + +#------------------------------------------------------------------------------ + + def scan(self): + """ + Populates the snapshot of threads and modules. + """ + self.scan_threads() + self.scan_modules() + + def clear(self): + """ + Clears the snapshot of threads and modules. + """ + try: + try: + self.clear_threads() + finally: + self.clear_modules() + finally: + self.close_handle() + +#------------------------------------------------------------------------------ + + # Regular expression to find hexadecimal values of any size. + __hexa_parameter = re.compile('0x[0-9A-Fa-f]+') + + def __fixup_labels(self, disasm): + """ + Private method used when disassembling from process memory. + + It has no return value because the list is modified in place. On return + all raw memory addresses are replaced by labels when possible. + + @type disasm: list of tuple(int, int, str, str) + @param disasm: Output of one of the dissassembly functions. + """ + for index in compat.xrange(len(disasm)): + (address, size, text, dump) = disasm[index] + m = self.__hexa_parameter.search(text) + while m: + s, e = m.span() + value = text[s:e] + try: + label = self.get_label_at_address( int(value, 0x10) ) + except Exception: + label = None + if label: + text = text[:s] + label + text[e:] + e = s + len(value) + m = self.__hexa_parameter.search(text, e) + disasm[index] = (address, size, text, dump) + + def disassemble_string(self, lpAddress, code): + """ + Disassemble instructions from a block of binary code. + + @type lpAddress: int + @param lpAddress: Memory address where the code was read from. + + @type code: str + @param code: Binary code to disassemble. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + + @raise NotImplementedError: + No compatible disassembler was found for the current platform. + """ + try: + disasm = self.__disasm + except AttributeError: + disasm = self.__disasm = Disassembler( self.get_arch() ) + return disasm.decode(lpAddress, code) + + def disassemble(self, lpAddress, dwSize): + """ + Disassemble instructions from the address space of the process. + + @type lpAddress: int + @param lpAddress: Memory address where to read the code from. + + @type dwSize: int + @param dwSize: Size of binary code to disassemble. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + data = self.read(lpAddress, dwSize) + disasm = self.disassemble_string(lpAddress, data) + self.__fixup_labels(disasm) + return disasm + + # FIXME + # This algorithm really sucks, I've got to write a better one :P + def disassemble_around(self, lpAddress, dwSize = 64): + """ + Disassemble around the given address. + + @type lpAddress: int + @param lpAddress: Memory address where to read the code from. + + @type dwSize: int + @param dwSize: Delta offset. + Code will be read from lpAddress - dwSize to lpAddress + dwSize. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + dwDelta = int(float(dwSize) / 2.0) + addr_1 = lpAddress - dwDelta + addr_2 = lpAddress + size_1 = dwDelta + size_2 = dwSize - dwDelta + data = self.read(addr_1, dwSize) + data_1 = data[:size_1] + data_2 = data[size_1:] + disasm_1 = self.disassemble_string(addr_1, data_1) + disasm_2 = self.disassemble_string(addr_2, data_2) + disasm = disasm_1 + disasm_2 + self.__fixup_labels(disasm) + return disasm + + def disassemble_around_pc(self, dwThreadId, dwSize = 64): + """ + Disassemble around the program counter of the given thread. + + @type dwThreadId: int + @param dwThreadId: Global thread ID. + The program counter for this thread will be used as the disassembly + address. + + @type dwSize: int + @param dwSize: Delta offset. + Code will be read from pc - dwSize to pc + dwSize. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aThread = self.get_thread(dwThreadId) + return self.disassemble_around(aThread.get_pc(), dwSize) + + def disassemble_instruction(self, lpAddress): + """ + Disassemble the instruction at the given memory address. + + @type lpAddress: int + @param lpAddress: Memory address where to read the code from. + + @rtype: tuple( long, int, str, str ) + @return: The tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + return self.disassemble(lpAddress, 15)[0] + + def disassemble_current(self, dwThreadId): + """ + Disassemble the instruction at the program counter of the given thread. + + @type dwThreadId: int + @param dwThreadId: Global thread ID. + The program counter for this thread will be used as the disassembly + address. + + @rtype: tuple( long, int, str, str ) + @return: The tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aThread = self.get_thread(dwThreadId) + return self.disassemble_instruction(aThread.get_pc()) + +#------------------------------------------------------------------------------ + + def flush_instruction_cache(self): + """ + Flush the instruction cache. This is required if the process memory is + modified and one or more threads are executing nearby the modified + memory region. + + @see: U{http://blogs.msdn.com/oldnewthing/archive/2003/12/08/55954.aspx#55958} + + @raise WindowsError: Raises exception on error. + """ + # FIXME + # No idea what access rights are required here! + # Maybe PROCESS_VM_OPERATION ??? + # In any case we're only calling this from the debugger, + # so it should be fine (we already have PROCESS_ALL_ACCESS). + win32.FlushInstructionCache( self.get_handle() ) + + def debug_break(self): + """ + Triggers the system breakpoint in the process. + + @raise WindowsError: On error an exception is raised. + """ + # The exception is raised by a new thread. + # When continuing the exception, the thread dies by itself. + # This thread is hidden from the debugger. + win32.DebugBreakProcess( self.get_handle() ) + + def is_wow64(self): + """ + Determines if the process is running under WOW64. + + @rtype: bool + @return: + C{True} if the process is running under WOW64. That is, a 32-bit + application running in a 64-bit Windows. + + C{False} if the process is either a 32-bit application running in + a 32-bit Windows, or a 64-bit application running in a 64-bit + Windows. + + @raise WindowsError: On error an exception is raised. + + @see: U{http://msdn.microsoft.com/en-us/library/aa384249(VS.85).aspx} + """ + try: + wow64 = self.__wow64 + except AttributeError: + if (win32.bits == 32 and not win32.wow64): + wow64 = False + else: + if win32.PROCESS_ALL_ACCESS == win32.PROCESS_ALL_ACCESS_VISTA: + dwAccess = win32.PROCESS_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.PROCESS_QUERY_INFORMATION + hProcess = self.get_handle(dwAccess) + try: + wow64 = win32.IsWow64Process(hProcess) + except AttributeError: + wow64 = False + self.__wow64 = wow64 + return wow64 + + def get_arch(self): + """ + @rtype: str + @return: The architecture in which this process believes to be running. + For example, if running a 32 bit binary in a 64 bit machine, the + architecture returned by this method will be L{win32.ARCH_I386}, + but the value of L{System.arch} will be L{win32.ARCH_AMD64}. + """ + + # Are we in a 32 bit machine? + if win32.bits == 32 and not win32.wow64: + return win32.arch + + # Is the process outside of WOW64? + if not self.is_wow64(): + return win32.arch + + # In WOW64, "amd64" becomes "i386". + if win32.arch == win32.ARCH_AMD64: + return win32.ARCH_I386 + + # We don't know the translation for other architectures. + raise NotImplementedError() + + def get_bits(self): + """ + @rtype: str + @return: The number of bits in which this process believes to be + running. For example, if running a 32 bit binary in a 64 bit + machine, the number of bits returned by this method will be C{32}, + but the value of L{System.arch} will be C{64}. + """ + + # Are we in a 32 bit machine? + if win32.bits == 32 and not win32.wow64: + + # All processes are 32 bits. + return 32 + + # Is the process inside WOW64? + if self.is_wow64(): + + # The process is 32 bits. + return 32 + + # The process is 64 bits. + return 64 + + # TODO: get_os, to test compatibility run + # See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683224(v=vs.85).aspx + +#------------------------------------------------------------------------------ + + def get_start_time(self): + """ + Determines when has this process started running. + + @rtype: win32.SYSTEMTIME + @return: Process start time. + """ + if win32.PROCESS_ALL_ACCESS == win32.PROCESS_ALL_ACCESS_VISTA: + dwAccess = win32.PROCESS_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.PROCESS_QUERY_INFORMATION + hProcess = self.get_handle(dwAccess) + CreationTime = win32.GetProcessTimes(hProcess)[0] + return win32.FileTimeToSystemTime(CreationTime) + + def get_exit_time(self): + """ + Determines when has this process finished running. + If the process is still alive, the current time is returned instead. + + @rtype: win32.SYSTEMTIME + @return: Process exit time. + """ + if self.is_alive(): + ExitTime = win32.GetSystemTimeAsFileTime() + else: + if win32.PROCESS_ALL_ACCESS == win32.PROCESS_ALL_ACCESS_VISTA: + dwAccess = win32.PROCESS_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.PROCESS_QUERY_INFORMATION + hProcess = self.get_handle(dwAccess) + ExitTime = win32.GetProcessTimes(hProcess)[1] + return win32.FileTimeToSystemTime(ExitTime) + + def get_running_time(self): + """ + Determines how long has this process been running. + + @rtype: long + @return: Process running time in milliseconds. + """ + if win32.PROCESS_ALL_ACCESS == win32.PROCESS_ALL_ACCESS_VISTA: + dwAccess = win32.PROCESS_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.PROCESS_QUERY_INFORMATION + hProcess = self.get_handle(dwAccess) + (CreationTime, ExitTime, _, _) = win32.GetProcessTimes(hProcess) + if self.is_alive(): + ExitTime = win32.GetSystemTimeAsFileTime() + CreationTime = CreationTime.dwLowDateTime + (CreationTime.dwHighDateTime << 32) + ExitTime = ExitTime.dwLowDateTime + ( ExitTime.dwHighDateTime << 32) + RunningTime = ExitTime - CreationTime + return RunningTime / 10000 # 100 nanoseconds steps => milliseconds + +#------------------------------------------------------------------------------ + + def __load_System_class(self): + global System # delayed import + if System is None: + from system import System + + def get_services(self): + """ + Retrieves the list of system services that are currently running in + this process. + + @see: L{System.get_services} + + @rtype: list( L{win32.ServiceStatusProcessEntry} ) + @return: List of service status descriptors. + """ + self.__load_System_class() + pid = self.get_pid() + return [d for d in System.get_active_services() if d.ProcessId == pid] + +#------------------------------------------------------------------------------ + + def get_dep_policy(self): + """ + Retrieves the DEP (Data Execution Prevention) policy for this process. + + @note: This method is only available in Windows XP SP3 and above, and + only for 32 bit processes. It will fail in any other circumstance. + + @see: U{http://msdn.microsoft.com/en-us/library/bb736297(v=vs.85).aspx} + + @rtype: tuple(int, int) + @return: + The first member of the tuple is the DEP flags. It can be a + combination of the following values: + - 0: DEP is disabled for this process. + - 1: DEP is enabled for this process. (C{PROCESS_DEP_ENABLE}) + - 2: DEP-ATL thunk emulation is disabled for this process. + (C{PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION}) + + The second member of the tuple is the permanent flag. If C{TRUE} + the DEP settings cannot be changed in runtime for this process. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle(win32.PROCESS_QUERY_INFORMATION) + try: + return win32.kernel32.GetProcessDEPPolicy(hProcess) + except AttributeError: + msg = "This method is only available in Windows XP SP3 and above." + raise NotImplementedError(msg) + +#------------------------------------------------------------------------------ + + def get_peb(self): + """ + Returns a copy of the PEB. + To dereference pointers in it call L{Process.read_structure}. + + @rtype: L{win32.PEB} + @return: PEB structure. + @raise WindowsError: An exception is raised on error. + """ + self.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + return self.read_structure(self.get_peb_address(), win32.PEB) + + def get_peb_address(self): + """ + Returns a remote pointer to the PEB. + + @rtype: int + @return: Remote pointer to the L{win32.PEB} structure. + Returns C{None} on error. + """ + try: + return self._peb_ptr + except AttributeError: + hProcess = self.get_handle(win32.PROCESS_QUERY_INFORMATION) + pbi = win32.NtQueryInformationProcess(hProcess, + win32.ProcessBasicInformation) + address = pbi.PebBaseAddress + self._peb_ptr = address + return address + + def get_entry_point(self): + """ + Alias to C{process.get_main_module().get_entry_point()}. + + @rtype: int + @return: Address of the entry point of the main module. + """ + return self.get_main_module().get_entry_point() + + def get_main_module(self): + """ + @rtype: L{Module} + @return: Module object for the process main module. + """ + return self.get_module(self.get_image_base()) + + def get_image_base(self): + """ + @rtype: int + @return: Image base address for the process main module. + """ + return self.get_peb().ImageBaseAddress + + def get_image_name(self): + """ + @rtype: int + @return: Filename of the process main module. + + This method does it's best to retrieve the filename. + However sometimes this is not possible, so C{None} may + be returned instead. + """ + + # Method 1: Module.fileName + # It's cached if the filename was already found by the other methods, + # if it came with the corresponding debug event, or it was found by the + # toolhelp API. + mainModule = None + try: + mainModule = self.get_main_module() + name = mainModule.fileName + if not name: + name = None + except (KeyError, AttributeError, WindowsError): +## traceback.print_exc() # XXX DEBUG + name = None + + # Method 2: QueryFullProcessImageName() + # Not implemented until Windows Vista. + if not name: + try: + hProcess = self.get_handle( + win32.PROCESS_QUERY_LIMITED_INFORMATION) + name = win32.QueryFullProcessImageName(hProcess) + except (AttributeError, WindowsError): +## traceback.print_exc() # XXX DEBUG + name = None + + # Method 3: GetProcessImageFileName() + # + # Not implemented until Windows XP. + # For more info see: + # https://voidnish.wordpress.com/2005/06/20/getprocessimagefilenamequerydosdevice-trivia/ + if not name: + try: + hProcess = self.get_handle(win32.PROCESS_QUERY_INFORMATION) + name = win32.GetProcessImageFileName(hProcess) + if name: + name = PathOperations.native_to_win32_pathname(name) + else: + name = None + except (AttributeError, WindowsError): +## traceback.print_exc() # XXX DEBUG + if not name: + name = None + + # Method 4: GetModuleFileNameEx() + # Not implemented until Windows 2000. + # + # May be spoofed by malware, since this information resides + # in usermode space (see http://www.ragestorm.net/blogs/?p=163). + if not name: + try: + hProcess = self.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + try: + name = win32.GetModuleFileNameEx(hProcess) + except WindowsError: +## traceback.print_exc() # XXX DEBUG + name = win32.GetModuleFileNameEx( + hProcess, self.get_image_base()) + if name: + name = PathOperations.native_to_win32_pathname(name) + else: + name = None + except (AttributeError, WindowsError): +## traceback.print_exc() # XXX DEBUG + if not name: + name = None + + # Method 5: PEB.ProcessParameters->ImagePathName + # + # May fail since it's using an undocumented internal structure. + # + # May be spoofed by malware, since this information resides + # in usermode space (see http://www.ragestorm.net/blogs/?p=163). + if not name: + try: + peb = self.get_peb() + pp = self.read_structure(peb.ProcessParameters, + win32.RTL_USER_PROCESS_PARAMETERS) + s = pp.ImagePathName + name = self.peek_string(s.Buffer, + dwMaxSize=s.MaximumLength, fUnicode=True) + if name: + name = PathOperations.native_to_win32_pathname(name) + else: + name = None + except (AttributeError, WindowsError): +## traceback.print_exc() # XXX DEBUG + name = None + + # Method 6: Module.get_filename() + # It tries to get the filename from the file handle. + # + # There are currently some problems due to the strange way the API + # works - it returns the pathname without the drive letter, and I + # couldn't figure out a way to fix it. + if not name and mainModule is not None: + try: + name = mainModule.get_filename() + if not name: + name = None + except (AttributeError, WindowsError): +## traceback.print_exc() # XXX DEBUG + name = None + + # Remember the filename. + if name and mainModule is not None: + mainModule.fileName = name + + # Return the image filename, or None on error. + return name + + def get_command_line_block(self): + """ + Retrieves the command line block memory address and size. + + @rtype: tuple(int, int) + @return: Tuple with the memory address of the command line block + and it's maximum size in Unicode characters. + + @raise WindowsError: On error an exception is raised. + """ + peb = self.get_peb() + pp = self.read_structure(peb.ProcessParameters, + win32.RTL_USER_PROCESS_PARAMETERS) + s = pp.CommandLine + return (s.Buffer, s.MaximumLength) + + def get_environment_block(self): + """ + Retrieves the environment block memory address for the process. + + @note: The size is always enough to contain the environment data, but + it may not be an exact size. It's best to read the memory and + scan for two null wide chars to find the actual size. + + @rtype: tuple(int, int) + @return: Tuple with the memory address of the environment block + and it's size. + + @raise WindowsError: On error an exception is raised. + """ + peb = self.get_peb() + pp = self.read_structure(peb.ProcessParameters, + win32.RTL_USER_PROCESS_PARAMETERS) + Environment = pp.Environment + try: + EnvironmentSize = pp.EnvironmentSize + except AttributeError: + mbi = self.mquery(Environment) + EnvironmentSize = mbi.RegionSize + mbi.BaseAddress - Environment + return (Environment, EnvironmentSize) + + def get_command_line(self): + """ + Retrieves the command line with wich the program was started. + + @rtype: str + @return: Command line string. + + @raise WindowsError: On error an exception is raised. + """ + (Buffer, MaximumLength) = self.get_command_line_block() + CommandLine = self.peek_string(Buffer, dwMaxSize=MaximumLength, + fUnicode=True) + gst = win32.GuessStringType + if gst.t_default == gst.t_ansi: + CommandLine = CommandLine.encode('cp1252') + return CommandLine + + def get_environment_variables(self): + """ + Retrieves the environment variables with wich the program is running. + + @rtype: list of tuple(compat.unicode, compat.unicode) + @return: Environment keys and values as found in the process memory. + + @raise WindowsError: On error an exception is raised. + """ + + # Note: the first bytes are garbage and must be skipped. Then the first + # two environment entries are the current drive and directory as key + # and value pairs, followed by the ExitCode variable (it's what batch + # files know as "errorlevel"). After that, the real environment vars + # are there in alphabetical order. In theory that's where it stops, + # but I've always seen one more "variable" tucked at the end which + # may be another environment block but in ANSI. I haven't examined it + # yet, I'm just skipping it because if it's parsed as Unicode it just + # renders garbage. + + # Read the environment block contents. + data = self.peek( *self.get_environment_block() ) + + # Put them into a Unicode buffer. + tmp = ctypes.create_string_buffer(data) + buffer = ctypes.create_unicode_buffer(len(data)) + ctypes.memmove(buffer, tmp, len(data)) + del tmp + + # Skip until the first Unicode null char is found. + pos = 0 + while buffer[pos] != u'\0': + pos += 1 + pos += 1 + + # Loop for each environment variable... + environment = [] + while buffer[pos] != u'\0': + + # Until we find a null char... + env_name_pos = pos + env_name = u'' + found_name = False + while buffer[pos] != u'\0': + + # Get the current char. + char = buffer[pos] + + # Is it an equal sign? + if char == u'=': + + # Skip leading equal signs. + if env_name_pos == pos: + env_name_pos += 1 + pos += 1 + continue + + # Otherwise we found the separator equal sign. + pos += 1 + found_name = True + break + + # Add the char to the variable name. + env_name += char + + # Next char. + pos += 1 + + # If the name was not parsed properly, stop. + if not found_name: + break + + # Read the variable value until we find a null char. + env_value = u'' + while buffer[pos] != u'\0': + env_value += buffer[pos] + pos += 1 + + # Skip the null char. + pos += 1 + + # Add to the list of environment variables found. + environment.append( (env_name, env_value) ) + + # Remove the last entry, it's garbage. + if environment: + environment.pop() + + # Return the environment variables. + return environment + + def get_environment_data(self, fUnicode = None): + """ + Retrieves the environment block data with wich the program is running. + + @warn: Deprecated since WinAppDbg 1.5. + + @see: L{win32.GuessStringType} + + @type fUnicode: bool or None + @param fUnicode: C{True} to return a list of Unicode strings, C{False} + to return a list of ANSI strings, or C{None} to return whatever + the default is for string types. + + @rtype: list of str + @return: Environment keys and values separated by a (C{=}) character, + as found in the process memory. + + @raise WindowsError: On error an exception is raised. + """ + + # Issue a deprecation warning. + warnings.warn( + "Process.get_environment_data() is deprecated" \ + " since WinAppDbg 1.5.", + DeprecationWarning) + + # Get the environment variables. + block = [ key + u'=' + value for (key, value) \ + in self.get_environment_variables() ] + + # Convert the data to ANSI if requested. + if fUnicode is None: + gst = win32.GuessStringType + fUnicode = gst.t_default == gst.t_unicode + if not fUnicode: + block = [x.encode('cp1252') for x in block] + + # Return the environment data. + return block + + @staticmethod + def parse_environment_data(block): + """ + Parse the environment block into a Python dictionary. + + @warn: Deprecated since WinAppDbg 1.5. + + @note: Values of duplicated keys are joined using null characters. + + @type block: list of str + @param block: List of strings as returned by L{get_environment_data}. + + @rtype: dict(str S{->} str) + @return: Dictionary of environment keys and values. + """ + + # Issue a deprecation warning. + warnings.warn( + "Process.parse_environment_data() is deprecated" \ + " since WinAppDbg 1.5.", + DeprecationWarning) + + # Create an empty environment dictionary. + environment = dict() + + # End here if the environment block is empty. + if not block: + return environment + + # Prepare the tokens (ANSI or Unicode). + gst = win32.GuessStringType + if type(block[0]) == gst.t_ansi: + equals = '=' + terminator = '\0' + else: + equals = u'=' + terminator = u'\0' + + # Split the blocks into key/value pairs. + for chunk in block: + sep = chunk.find(equals, 1) + if sep < 0: +## raise Exception() + continue # corrupted environment block? + key, value = chunk[:sep], chunk[sep+1:] + + # For duplicated keys, append the value. + # Values are separated using null terminators. + if key not in environment: + environment[key] = value + else: + environment[key] += terminator + value + + # Return the environment dictionary. + return environment + + def get_environment(self, fUnicode = None): + """ + Retrieves the environment with wich the program is running. + + @note: Duplicated keys are joined using null characters. + To avoid this behavior, call L{get_environment_variables} instead + and convert the results to a dictionary directly, like this: + C{dict(process.get_environment_variables())} + + @see: L{win32.GuessStringType} + + @type fUnicode: bool or None + @param fUnicode: C{True} to return a list of Unicode strings, C{False} + to return a list of ANSI strings, or C{None} to return whatever + the default is for string types. + + @rtype: dict(str S{->} str) + @return: Dictionary of environment keys and values. + + @raise WindowsError: On error an exception is raised. + """ + + # Get the environment variables. + variables = self.get_environment_variables() + + # Convert the strings to ANSI if requested. + if fUnicode is None: + gst = win32.GuessStringType + fUnicode = gst.t_default == gst.t_unicode + if not fUnicode: + variables = [ ( key.encode('cp1252'), value.encode('cp1252') ) \ + for (key, value) in variables ] + + # Add the variables to a dictionary, concatenating duplicates. + environment = dict() + for key, value in variables: + if key in environment: + environment[key] = environment[key] + u'\0' + value + else: + environment[key] = value + + # Return the dictionary. + return environment + +#------------------------------------------------------------------------------ + + def search(self, pattern, minAddr = None, maxAddr = None): + """ + Search for the given pattern within the process memory. + + @type pattern: str, compat.unicode or L{Pattern} + @param pattern: Pattern to search for. + It may be a byte string, a Unicode string, or an instance of + L{Pattern}. + + The following L{Pattern} subclasses are provided by WinAppDbg: + - L{BytePattern} + - L{TextPattern} + - L{RegExpPattern} + - L{HexPattern} + + You can also write your own subclass of L{Pattern} for customized + searches. + + @type minAddr: int + @param minAddr: (Optional) Start the search at this memory address. + + @type maxAddr: int + @param maxAddr: (Optional) Stop the search at this memory address. + + @rtype: iterator of tuple( int, int, str ) + @return: An iterator of tuples. Each tuple contains the following: + - The memory address where the pattern was found. + - The size of the data that matches the pattern. + - The data that matches the pattern. + + @raise WindowsError: An error occurred when querying or reading the + process memory. + """ + if isinstance(pattern, str): + return self.search_bytes(pattern, minAddr, maxAddr) + if isinstance(pattern, compat.unicode): + return self.search_bytes(pattern.encode("utf-16le"), + minAddr, maxAddr) + if isinstance(pattern, Pattern): + return Search.search_process(self, pattern, minAddr, maxAddr) + raise TypeError("Unknown pattern type: %r" % type(pattern)) + + def search_bytes(self, bytes, minAddr = None, maxAddr = None): + """ + Search for the given byte pattern within the process memory. + + @type bytes: str + @param bytes: Bytes to search for. + + @type minAddr: int + @param minAddr: (Optional) Start the search at this memory address. + + @type maxAddr: int + @param maxAddr: (Optional) Stop the search at this memory address. + + @rtype: iterator of int + @return: An iterator of memory addresses where the pattern was found. + + @raise WindowsError: An error occurred when querying or reading the + process memory. + """ + pattern = BytePattern(bytes) + matches = Search.search_process(self, pattern, minAddr, maxAddr) + for addr, size, data in matches: + yield addr + + def search_text(self, text, encoding = "utf-16le", + caseSensitive = False, + minAddr = None, + maxAddr = None): + """ + Search for the given text within the process memory. + + @type text: str or compat.unicode + @param text: Text to search for. + + @type encoding: str + @param encoding: (Optional) Encoding for the text parameter. + Only used when the text to search for is a Unicode string. + Don't change unless you know what you're doing! + + @type caseSensitive: bool + @param caseSensitive: C{True} of the search is case sensitive, + C{False} otherwise. + + @type minAddr: int + @param minAddr: (Optional) Start the search at this memory address. + + @type maxAddr: int + @param maxAddr: (Optional) Stop the search at this memory address. + + @rtype: iterator of tuple( int, str ) + @return: An iterator of tuples. Each tuple contains the following: + - The memory address where the pattern was found. + - The text that matches the pattern. + + @raise WindowsError: An error occurred when querying or reading the + process memory. + """ + pattern = TextPattern(text, encoding, caseSensitive) + matches = Search.search_process(self, pattern, minAddr, maxAddr) + for addr, size, data in matches: + yield addr, data + + def search_regexp(self, regexp, flags = 0, + minAddr = None, + maxAddr = None, + bufferPages = -1): + """ + Search for the given regular expression within the process memory. + + @type regexp: str + @param regexp: Regular expression string. + + @type flags: int + @param flags: Regular expression flags. + + @type minAddr: int + @param minAddr: (Optional) Start the search at this memory address. + + @type maxAddr: int + @param maxAddr: (Optional) Stop the search at this memory address. + + @type bufferPages: int + @param bufferPages: (Optional) Number of memory pages to buffer when + performing the search. Valid values are: + - C{0} or C{None}: + Automatically determine the required buffer size. May not give + complete results for regular expressions that match variable + sized strings. + - C{> 0}: Set the buffer size, in memory pages. + - C{< 0}: Disable buffering entirely. This may give you a little + speed gain at the cost of an increased memory usage. If the + target process has very large contiguous memory regions it may + actually be slower or even fail. It's also the only way to + guarantee complete results for regular expressions that match + variable sized strings. + + @rtype: iterator of tuple( int, int, str ) + @return: An iterator of tuples. Each tuple contains the following: + - The memory address where the pattern was found. + - The size of the data that matches the pattern. + - The data that matches the pattern. + + @raise WindowsError: An error occurred when querying or reading the + process memory. + """ + pattern = RegExpPattern(regexp, flags) + return Search.search_process(self, pattern, + minAddr, maxAddr, + bufferPages) + + def search_hexa(self, hexa, minAddr = None, maxAddr = None): + """ + Search for the given hexadecimal pattern within the process memory. + + Hex patterns must be in this form:: + "68 65 6c 6c 6f 20 77 6f 72 6c 64" # "hello world" + + Spaces are optional. Capitalization of hex digits doesn't matter. + This is exactly equivalent to the previous example:: + "68656C6C6F20776F726C64" # "hello world" + + Wildcards are allowed, in the form of a C{?} sign in any hex digit:: + "5? 5? c3" # pop register / pop register / ret + "b8 ?? ?? ?? ??" # mov eax, immediate value + + @type hexa: str + @param hexa: Pattern to search for. + + @type minAddr: int + @param minAddr: (Optional) Start the search at this memory address. + + @type maxAddr: int + @param maxAddr: (Optional) Stop the search at this memory address. + + @rtype: iterator of tuple( int, str ) + @return: An iterator of tuples. Each tuple contains the following: + - The memory address where the pattern was found. + - The bytes that match the pattern. + + @raise WindowsError: An error occurred when querying or reading the + process memory. + """ + pattern = HexPattern(hexa) + matches = Search.search_process(self, pattern, minAddr, maxAddr) + for addr, size, data in matches: + yield addr, data + + def strings(self, minSize = 4, maxSize = 1024): + """ + Extract ASCII strings from the process memory. + + @type minSize: int + @param minSize: (Optional) Minimum size of the strings to search for. + + @type maxSize: int + @param maxSize: (Optional) Maximum size of the strings to search for. + + @rtype: iterator of tuple(int, int, str) + @return: Iterator of strings extracted from the process memory. + Each tuple contains the following: + - The memory address where the string was found. + - The size of the string. + - The string. + """ + return Search.extract_ascii_strings(self, minSize = minSize, + maxSize = maxSize) + +#------------------------------------------------------------------------------ + + def __read_c_type(self, address, format, c_type): + size = ctypes.sizeof(c_type) + packed = self.read(address, size) + if len(packed) != size: + raise ctypes.WinError() + return struct.unpack(format, packed)[0] + + def __write_c_type(self, address, format, unpacked): + packed = struct.pack('@L', unpacked) + self.write(address, packed) + + # XXX TODO + # + Maybe change page permissions before trying to read? + def read(self, lpBaseAddress, nSize): + """ + Reads from the memory of the process. + + @see: L{peek} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @type nSize: int + @param nSize: Number of bytes to read. + + @rtype: str + @return: Bytes read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + if not self.is_buffer(lpBaseAddress, nSize): + raise ctypes.WinError(win32.ERROR_INVALID_ADDRESS) + data = win32.ReadProcessMemory(hProcess, lpBaseAddress, nSize) + if len(data) != nSize: + raise ctypes.WinError() + return data + + def write(self, lpBaseAddress, lpBuffer): + """ + Writes to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type lpBuffer: str + @param lpBuffer: Bytes to write. + + @raise WindowsError: On error an exception is raised. + """ + r = self.poke(lpBaseAddress, lpBuffer) + if r != len(lpBuffer): + raise ctypes.WinError() + + def read_char(self, lpBaseAddress): + """ + Reads a single character to the memory of the process. + + @see: L{peek_char} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @rtype: int + @return: Character value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return ord( self.read(lpBaseAddress, 1) ) + + def write_char(self, lpBaseAddress, char): + """ + Writes a single character to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_char} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type char: int + @param char: Character to write. + + @raise WindowsError: On error an exception is raised. + """ + self.write(lpBaseAddress, chr(char)) + + def read_int(self, lpBaseAddress): + """ + Reads a signed integer from the memory of the process. + + @see: L{peek_int} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, compat.b('@l'), ctypes.c_int) + + def write_int(self, lpBaseAddress, unpackedValue): + """ + Writes a signed integer to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_int} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '@l', unpackedValue) + + def read_uint(self, lpBaseAddress): + """ + Reads an unsigned integer from the memory of the process. + + @see: L{peek_uint} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, '@L', ctypes.c_uint) + + def write_uint(self, lpBaseAddress, unpackedValue): + """ + Writes an unsigned integer to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_uint} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '@L', unpackedValue) + + def read_float(self, lpBaseAddress): + """ + Reads a float from the memory of the process. + + @see: L{peek_float} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Floating point value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, '@f', ctypes.c_float) + + def write_float(self, lpBaseAddress, unpackedValue): + """ + Writes a float to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_float} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Floating point value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '@f', unpackedValue) + + def read_double(self, lpBaseAddress): + """ + Reads a double from the memory of the process. + + @see: L{peek_double} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Floating point value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, '@d', ctypes.c_double) + + def write_double(self, lpBaseAddress, unpackedValue): + """ + Writes a double to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_double} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Floating point value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '@d', unpackedValue) + + def read_pointer(self, lpBaseAddress): + """ + Reads a pointer value from the memory of the process. + + @see: L{peek_pointer} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Pointer value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, '@P', ctypes.c_void_p) + + def write_pointer(self, lpBaseAddress, unpackedValue): + """ + Writes a pointer value to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_pointer} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '@P', unpackedValue) + + def read_dword(self, lpBaseAddress): + """ + Reads a DWORD from the memory of the process. + + @see: L{peek_dword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, '=L', win32.DWORD) + + def write_dword(self, lpBaseAddress, unpackedValue): + """ + Writes a DWORD to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_dword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '=L', unpackedValue) + + def read_qword(self, lpBaseAddress): + """ + Reads a QWORD from the memory of the process. + + @see: L{peek_qword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + return self.__read_c_type(lpBaseAddress, '=Q', win32.QWORD) + + def write_qword(self, lpBaseAddress, unpackedValue): + """ + Writes a QWORD to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{poke_qword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @raise WindowsError: On error an exception is raised. + """ + self.__write_c_type(lpBaseAddress, '=Q', unpackedValue) + + def read_structure(self, lpBaseAddress, stype): + """ + Reads a ctypes structure from the memory of the process. + + @see: L{read} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @type stype: class ctypes.Structure or a subclass. + @param stype: Structure definition. + + @rtype: int + @return: Structure instance filled in with data + read from the process memory. + + @raise WindowsError: On error an exception is raised. + """ + if type(lpBaseAddress) not in (type(0), type(long(0))): + lpBaseAddress = ctypes.cast(lpBaseAddress, ctypes.c_void_p) + data = self.read(lpBaseAddress, ctypes.sizeof(stype)) + buff = ctypes.create_string_buffer(data) + ptr = ctypes.cast(ctypes.pointer(buff), ctypes.POINTER(stype)) + return ptr.contents + +# XXX TODO +## def write_structure(self, lpBaseAddress, sStructure): +## """ +## Writes a ctypes structure into the memory of the process. +## +## @note: Page permissions may be changed temporarily while writing. +## +## @see: L{write} +## +## @type lpBaseAddress: int +## @param lpBaseAddress: Memory address to begin writing. +## +## @type sStructure: ctypes.Structure or a subclass' instance. +## @param sStructure: Structure definition. +## +## @rtype: int +## @return: Structure instance filled in with data +## read from the process memory. +## +## @raise WindowsError: On error an exception is raised. +## """ +## size = ctypes.sizeof(sStructure) +## data = ctypes.create_string_buffer("", size = size) +## win32.CopyMemory(ctypes.byref(data), ctypes.byref(sStructure), size) +## self.write(lpBaseAddress, data.raw) + + def read_string(self, lpBaseAddress, nChars, fUnicode = False): + """ + Reads an ASCII or Unicode string + from the address space of the process. + + @see: L{peek_string} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @type nChars: int + @param nChars: String length to read, in characters. + Remember that Unicode strings have two byte characters. + + @type fUnicode: bool + @param fUnicode: C{True} is the string is expected to be Unicode, + C{False} if it's expected to be ANSI. + + @rtype: str, compat.unicode + @return: String read from the process memory space. + + @raise WindowsError: On error an exception is raised. + """ + if fUnicode: + nChars = nChars * 2 + szString = self.read(lpBaseAddress, nChars) + if fUnicode: + szString = compat.unicode(szString, 'U16', 'ignore') + return szString + +#------------------------------------------------------------------------------ + + # FIXME this won't work properly with a different endianness! + def __peek_c_type(self, address, format, c_type): + size = ctypes.sizeof(c_type) + packed = self.peek(address, size) + if len(packed) < size: + packed = '\0' * (size - len(packed)) + packed + elif len(packed) > size: + packed = packed[:size] + return struct.unpack(format, packed)[0] + + def __poke_c_type(self, address, format, unpacked): + packed = struct.pack('@L', unpacked) + return self.poke(address, packed) + + def peek(self, lpBaseAddress, nSize): + """ + Reads the memory of the process. + + @see: L{read} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @type nSize: int + @param nSize: Number of bytes to read. + + @rtype: str + @return: Bytes read from the process memory. + Returns an empty string on error. + """ + # XXX TODO + # + Maybe change page permissions before trying to read? + # + Maybe use mquery instead of get_memory_map? + # (less syscalls if we break out of the loop earlier) + data = '' + if nSize > 0: + try: + hProcess = self.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + for mbi in self.get_memory_map(lpBaseAddress, + lpBaseAddress + nSize): + if not mbi.is_readable(): + nSize = mbi.BaseAddress - lpBaseAddress + break + if nSize > 0: + data = win32.ReadProcessMemory( + hProcess, lpBaseAddress, nSize) + except WindowsError: + e = sys.exc_info()[1] + msg = "Error reading process %d address %s: %s" + msg %= (self.get_pid(), + HexDump.address(lpBaseAddress), + e.strerror) + warnings.warn(msg) + return data + + def poke(self, lpBaseAddress, lpBuffer): + """ + Writes to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type lpBuffer: str + @param lpBuffer: Bytes to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + assert isinstance(lpBuffer, compat.bytes) + hProcess = self.get_handle( win32.PROCESS_VM_WRITE | + win32.PROCESS_VM_OPERATION | + win32.PROCESS_QUERY_INFORMATION ) + mbi = self.mquery(lpBaseAddress) + if not mbi.has_content(): + raise ctypes.WinError(win32.ERROR_INVALID_ADDRESS) + if mbi.is_image() or mbi.is_mapped(): + prot = win32.PAGE_WRITECOPY + elif mbi.is_writeable(): + prot = None + elif mbi.is_executable(): + prot = win32.PAGE_EXECUTE_READWRITE + else: + prot = win32.PAGE_READWRITE + if prot is not None: + try: + self.mprotect(lpBaseAddress, len(lpBuffer), prot) + except Exception: + prot = None + msg = ("Failed to adjust page permissions" + " for process %s at address %s: %s") + msg = msg % (self.get_pid(), + HexDump.address(lpBaseAddress, self.get_bits()), + traceback.format_exc()) + warnings.warn(msg, RuntimeWarning) + try: + r = win32.WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer) + finally: + if prot is not None: + self.mprotect(lpBaseAddress, len(lpBuffer), mbi.Protect) + return r + + def peek_char(self, lpBaseAddress): + """ + Reads a single character from the memory of the process. + + @see: L{read_char} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Character read from the process memory. + Returns zero on error. + """ + char = self.peek(lpBaseAddress, 1) + if char: + return ord(char) + return 0 + + def poke_char(self, lpBaseAddress, char): + """ + Writes a single character to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_char} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type char: str + @param char: Character to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.poke(lpBaseAddress, chr(char)) + + def peek_int(self, lpBaseAddress): + """ + Reads a signed integer from the memory of the process. + + @see: L{read_int} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '@l', ctypes.c_int) + + def poke_int(self, lpBaseAddress, unpackedValue): + """ + Writes a signed integer to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_int} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '@l', unpackedValue) + + def peek_uint(self, lpBaseAddress): + """ + Reads an unsigned integer from the memory of the process. + + @see: L{read_uint} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '@L', ctypes.c_uint) + + def poke_uint(self, lpBaseAddress, unpackedValue): + """ + Writes an unsigned integer to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_uint} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '@L', unpackedValue) + + def peek_float(self, lpBaseAddress): + """ + Reads a float from the memory of the process. + + @see: L{read_float} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '@f', ctypes.c_float) + + def poke_float(self, lpBaseAddress, unpackedValue): + """ + Writes a float to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_float} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '@f', unpackedValue) + + def peek_double(self, lpBaseAddress): + """ + Reads a double from the memory of the process. + + @see: L{read_double} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '@d', ctypes.c_double) + + def poke_double(self, lpBaseAddress, unpackedValue): + """ + Writes a double to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_double} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '@d', unpackedValue) + + def peek_dword(self, lpBaseAddress): + """ + Reads a DWORD from the memory of the process. + + @see: L{read_dword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '=L', win32.DWORD) + + def poke_dword(self, lpBaseAddress, unpackedValue): + """ + Writes a DWORD to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_dword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '=L', unpackedValue) + + def peek_qword(self, lpBaseAddress): + """ + Reads a QWORD from the memory of the process. + + @see: L{read_qword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Integer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '=Q', win32.QWORD) + + def poke_qword(self, lpBaseAddress, unpackedValue): + """ + Writes a QWORD to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_qword} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '=Q', unpackedValue) + + def peek_pointer(self, lpBaseAddress): + """ + Reads a pointer value from the memory of the process. + + @see: L{read_pointer} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @rtype: int + @return: Pointer value read from the process memory. + Returns zero on error. + """ + return self.__peek_c_type(lpBaseAddress, '@P', ctypes.c_void_p) + + def poke_pointer(self, lpBaseAddress, unpackedValue): + """ + Writes a pointer value to the memory of the process. + + @note: Page permissions may be changed temporarily while writing. + + @see: L{write_pointer} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin writing. + + @type unpackedValue: int, long + @param unpackedValue: Value to write. + + @rtype: int + @return: Number of bytes written. + May be less than the number of bytes to write. + """ + return self.__poke_c_type(lpBaseAddress, '@P', unpackedValue) + + def peek_string(self, lpBaseAddress, fUnicode = False, dwMaxSize = 0x1000): + """ + Tries to read an ASCII or Unicode string + from the address space of the process. + + @see: L{read_string} + + @type lpBaseAddress: int + @param lpBaseAddress: Memory address to begin reading. + + @type fUnicode: bool + @param fUnicode: C{True} is the string is expected to be Unicode, + C{False} if it's expected to be ANSI. + + @type dwMaxSize: int + @param dwMaxSize: Maximum allowed string length to read, in bytes. + + @rtype: str, compat.unicode + @return: String read from the process memory space. + It B{doesn't} include the terminating null character. + Returns an empty string on failure. + """ + + # Validate the parameters. + if not lpBaseAddress or dwMaxSize == 0: + if fUnicode: + return u'' + return '' + if not dwMaxSize: + dwMaxSize = 0x1000 + + # Read the string. + szString = self.peek(lpBaseAddress, dwMaxSize) + + # If the string is Unicode... + if fUnicode: + + # Decode the string. + szString = compat.unicode(szString, 'U16', 'replace') +## try: +## szString = compat.unicode(szString, 'U16') +## except UnicodeDecodeError: +## szString = struct.unpack('H' * (len(szString) / 2), szString) +## szString = [ unichr(c) for c in szString ] +## szString = u''.join(szString) + + # Truncate the string when the first null char is found. + szString = szString[ : szString.find(u'\0') ] + + # If the string is ANSI... + else: + + # Truncate the string when the first null char is found. + szString = szString[ : szString.find('\0') ] + + # Return the decoded string. + return szString + + # TODO + # try to avoid reading the same page twice by caching it + def peek_pointers_in_data(self, data, peekSize = 16, peekStep = 1): + """ + Tries to guess which values in the given data are valid pointers, + and reads some data from them. + + @see: L{peek} + + @type data: str + @param data: Binary data to find pointers in. + + @type peekSize: int + @param peekSize: Number of bytes to read from each pointer found. + + @type peekStep: int + @param peekStep: Expected data alignment. + Tipically you specify 1 when data alignment is unknown, + or 4 when you expect data to be DWORD aligned. + Any other value may be specified. + + @rtype: dict( str S{->} str ) + @return: Dictionary mapping stack offsets to the data they point to. + """ + result = dict() + ptrSize = win32.sizeof(win32.LPVOID) + if ptrSize == 4: + ptrFmt = ' 0: + for i in compat.xrange(0, len(data), peekStep): + packed = data[i:i+ptrSize] + if len(packed) == ptrSize: + address = struct.unpack(ptrFmt, packed)[0] +## if not address & (~0xFFFF): continue + peek_data = self.peek(address, peekSize) + if peek_data: + result[i] = peek_data + return result + +#------------------------------------------------------------------------------ + + def malloc(self, dwSize, lpAddress = None): + """ + Allocates memory into the address space of the process. + + @see: L{free} + + @type dwSize: int + @param dwSize: Number of bytes to allocate. + + @type lpAddress: int + @param lpAddress: (Optional) + Desired address for the newly allocated memory. + This is only a hint, the memory could still be allocated somewhere + else. + + @rtype: int + @return: Address of the newly allocated memory. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle(win32.PROCESS_VM_OPERATION) + return win32.VirtualAllocEx(hProcess, lpAddress, dwSize) + + def mprotect(self, lpAddress, dwSize, flNewProtect): + """ + Set memory protection in the address space of the process. + + @see: U{http://msdn.microsoft.com/en-us/library/aa366899.aspx} + + @type lpAddress: int + @param lpAddress: Address of memory to protect. + + @type dwSize: int + @param dwSize: Number of bytes to protect. + + @type flNewProtect: int + @param flNewProtect: New protect flags. + + @rtype: int + @return: Old protect flags. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle(win32.PROCESS_VM_OPERATION) + return win32.VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect) + + def mquery(self, lpAddress): + """ + Query memory information from the address space of the process. + Returns a L{win32.MemoryBasicInformation} object. + + @see: U{http://msdn.microsoft.com/en-us/library/aa366907(VS.85).aspx} + + @type lpAddress: int + @param lpAddress: Address of memory to query. + + @rtype: L{win32.MemoryBasicInformation} + @return: Memory region information. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle(win32.PROCESS_QUERY_INFORMATION) + return win32.VirtualQueryEx(hProcess, lpAddress) + + def free(self, lpAddress): + """ + Frees memory from the address space of the process. + + @see: U{http://msdn.microsoft.com/en-us/library/aa366894(v=vs.85).aspx} + + @type lpAddress: int + @param lpAddress: Address of memory to free. + Must be the base address returned by L{malloc}. + + @raise WindowsError: On error an exception is raised. + """ + hProcess = self.get_handle(win32.PROCESS_VM_OPERATION) + win32.VirtualFreeEx(hProcess, lpAddress) + +#------------------------------------------------------------------------------ + + def is_pointer(self, address): + """ + Determines if an address is a valid code or data pointer. + + That is, the address must be valid and must point to code or data in + the target process. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: C{True} if the address is a valid code or data pointer. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.has_content() + + def is_address_valid(self, address): + """ + Determines if an address is a valid user mode address. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: C{True} if the address is a valid user mode address. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return True + + def is_address_free(self, address): + """ + Determines if an address belongs to a free page. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: C{True} if the address belongs to a free page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_free() + + def is_address_reserved(self, address): + """ + Determines if an address belongs to a reserved page. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: C{True} if the address belongs to a reserved page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_reserved() + + def is_address_commited(self, address): + """ + Determines if an address belongs to a commited page. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: C{True} if the address belongs to a commited page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_commited() + + def is_address_guard(self, address): + """ + Determines if an address belongs to a guard page. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: C{True} if the address belongs to a guard page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_guard() + + def is_address_readable(self, address): + """ + Determines if an address belongs to a commited and readable page. + The page may or may not have additional permissions. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: + C{True} if the address belongs to a commited and readable page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_readable() + + def is_address_writeable(self, address): + """ + Determines if an address belongs to a commited and writeable page. + The page may or may not have additional permissions. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: + C{True} if the address belongs to a commited and writeable page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_writeable() + + def is_address_copy_on_write(self, address): + """ + Determines if an address belongs to a commited, copy-on-write page. + The page may or may not have additional permissions. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: + C{True} if the address belongs to a commited, copy-on-write page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_copy_on_write() + + def is_address_executable(self, address): + """ + Determines if an address belongs to a commited and executable page. + The page may or may not have additional permissions. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: + C{True} if the address belongs to a commited and executable page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_executable() + + def is_address_executable_and_writeable(self, address): + """ + Determines if an address belongs to a commited, writeable and + executable page. The page may or may not have additional permissions. + + Looking for writeable and executable pages is important when + exploiting a software vulnerability. + + @note: Returns always C{False} for kernel mode addresses. + + @type address: int + @param address: Memory address to query. + + @rtype: bool + @return: + C{True} if the address belongs to a commited, writeable and + executable page. + + @raise WindowsError: An exception is raised on error. + """ + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + return mbi.is_executable_and_writeable() + + def is_buffer(self, address, size): + """ + Determines if the given memory area is a valid code or data buffer. + + @note: Returns always C{False} for kernel mode addresses. + + @see: L{mquery} + + @type address: int + @param address: Memory address. + + @type size: int + @param size: Number of bytes. Must be greater than zero. + + @rtype: bool + @return: C{True} if the memory area is a valid code or data buffer, + C{False} otherwise. + + @raise ValueError: The size argument must be greater than zero. + @raise WindowsError: On error an exception is raised. + """ + if size <= 0: + raise ValueError("The size argument must be greater than zero") + while size > 0: + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + if not mbi.has_content(): + return False + size = size - mbi.RegionSize + return True + + def is_buffer_readable(self, address, size): + """ + Determines if the given memory area is readable. + + @note: Returns always C{False} for kernel mode addresses. + + @see: L{mquery} + + @type address: int + @param address: Memory address. + + @type size: int + @param size: Number of bytes. Must be greater than zero. + + @rtype: bool + @return: C{True} if the memory area is readable, C{False} otherwise. + + @raise ValueError: The size argument must be greater than zero. + @raise WindowsError: On error an exception is raised. + """ + if size <= 0: + raise ValueError("The size argument must be greater than zero") + while size > 0: + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + if not mbi.is_readable(): + return False + size = size - mbi.RegionSize + return True + + def is_buffer_writeable(self, address, size): + """ + Determines if the given memory area is writeable. + + @note: Returns always C{False} for kernel mode addresses. + + @see: L{mquery} + + @type address: int + @param address: Memory address. + + @type size: int + @param size: Number of bytes. Must be greater than zero. + + @rtype: bool + @return: C{True} if the memory area is writeable, C{False} otherwise. + + @raise ValueError: The size argument must be greater than zero. + @raise WindowsError: On error an exception is raised. + """ + if size <= 0: + raise ValueError("The size argument must be greater than zero") + while size > 0: + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + if not mbi.is_writeable(): + return False + size = size - mbi.RegionSize + return True + + def is_buffer_copy_on_write(self, address, size): + """ + Determines if the given memory area is marked as copy-on-write. + + @note: Returns always C{False} for kernel mode addresses. + + @see: L{mquery} + + @type address: int + @param address: Memory address. + + @type size: int + @param size: Number of bytes. Must be greater than zero. + + @rtype: bool + @return: C{True} if the memory area is marked as copy-on-write, + C{False} otherwise. + + @raise ValueError: The size argument must be greater than zero. + @raise WindowsError: On error an exception is raised. + """ + if size <= 0: + raise ValueError("The size argument must be greater than zero") + while size > 0: + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + if not mbi.is_copy_on_write(): + return False + size = size - mbi.RegionSize + return True + + def is_buffer_executable(self, address, size): + """ + Determines if the given memory area is executable. + + @note: Returns always C{False} for kernel mode addresses. + + @see: L{mquery} + + @type address: int + @param address: Memory address. + + @type size: int + @param size: Number of bytes. Must be greater than zero. + + @rtype: bool + @return: C{True} if the memory area is executable, C{False} otherwise. + + @raise ValueError: The size argument must be greater than zero. + @raise WindowsError: On error an exception is raised. + """ + if size <= 0: + raise ValueError("The size argument must be greater than zero") + while size > 0: + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + if not mbi.is_executable(): + return False + size = size - mbi.RegionSize + return True + + def is_buffer_executable_and_writeable(self, address, size): + """ + Determines if the given memory area is writeable and executable. + + Looking for writeable and executable pages is important when + exploiting a software vulnerability. + + @note: Returns always C{False} for kernel mode addresses. + + @see: L{mquery} + + @type address: int + @param address: Memory address. + + @type size: int + @param size: Number of bytes. Must be greater than zero. + + @rtype: bool + @return: C{True} if the memory area is writeable and executable, + C{False} otherwise. + + @raise ValueError: The size argument must be greater than zero. + @raise WindowsError: On error an exception is raised. + """ + if size <= 0: + raise ValueError("The size argument must be greater than zero") + while size > 0: + try: + mbi = self.mquery(address) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + return False + raise + if not mbi.is_executable(): + return False + size = size - mbi.RegionSize + return True + + def get_memory_map(self, minAddr = None, maxAddr = None): + """ + Produces a memory map to the process address space. + + Optionally restrict the map to the given address range. + + @see: L{mquery} + + @type minAddr: int + @param minAddr: (Optional) Starting address in address range to query. + + @type maxAddr: int + @param maxAddr: (Optional) Ending address in address range to query. + + @rtype: list( L{win32.MemoryBasicInformation} ) + @return: List of memory region information objects. + """ + return list(self.iter_memory_map(minAddr, maxAddr)) + + def generate_memory_map(self, minAddr = None, maxAddr = None): + """ + Returns a L{Regenerator} that can iterate indefinitely over the memory + map to the process address space. + + Optionally restrict the map to the given address range. + + @see: L{mquery} + + @type minAddr: int + @param minAddr: (Optional) Starting address in address range to query. + + @type maxAddr: int + @param maxAddr: (Optional) Ending address in address range to query. + + @rtype: L{Regenerator} of L{win32.MemoryBasicInformation} + @return: List of memory region information objects. + """ + return Regenerator(self.iter_memory_map, minAddr, maxAddr) + + def iter_memory_map(self, minAddr = None, maxAddr = None): + """ + Produces an iterator over the memory map to the process address space. + + Optionally restrict the map to the given address range. + + @see: L{mquery} + + @type minAddr: int + @param minAddr: (Optional) Starting address in address range to query. + + @type maxAddr: int + @param maxAddr: (Optional) Ending address in address range to query. + + @rtype: iterator of L{win32.MemoryBasicInformation} + @return: List of memory region information objects. + """ + minAddr, maxAddr = MemoryAddresses.align_address_range(minAddr,maxAddr) + prevAddr = minAddr - 1 + currentAddr = minAddr + while prevAddr < currentAddr < maxAddr: + try: + mbi = self.mquery(currentAddr) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_INVALID_PARAMETER: + break + raise + yield mbi + prevAddr = currentAddr + currentAddr = mbi.BaseAddress + mbi.RegionSize + + def get_mapped_filenames(self, memoryMap = None): + """ + Retrieves the filenames for memory mapped files in the debugee. + + @type memoryMap: list( L{win32.MemoryBasicInformation} ) + @param memoryMap: (Optional) Memory map returned by L{get_memory_map}. + If not given, the current memory map is used. + + @rtype: dict( int S{->} str ) + @return: Dictionary mapping memory addresses to file names. + Native filenames are converted to Win32 filenames when possible. + """ + hProcess = self.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + if not memoryMap: + memoryMap = self.get_memory_map() + mappedFilenames = dict() + for mbi in memoryMap: + if mbi.Type not in (win32.MEM_IMAGE, win32.MEM_MAPPED): + continue + baseAddress = mbi.BaseAddress + fileName = "" + try: + fileName = win32.GetMappedFileName(hProcess, baseAddress) + fileName = PathOperations.native_to_win32_pathname(fileName) + except WindowsError: + #e = sys.exc_info()[1] + #try: + # msg = "Can't get mapped file name at address %s in process " \ + # "%d, reason: %s" % (HexDump.address(baseAddress), + # self.get_pid(), + # e.strerror) + # warnings.warn(msg, Warning) + #except Exception: + pass + mappedFilenames[baseAddress] = fileName + return mappedFilenames + + def generate_memory_snapshot(self, minAddr = None, maxAddr = None): + """ + Returns a L{Regenerator} that allows you to iterate through the memory + contents of a process indefinitely. + + It's basically the same as the L{take_memory_snapshot} method, but it + takes the snapshot of each memory region as it goes, as opposed to + taking the whole snapshot at once. This allows you to work with very + large snapshots without a significant performance penalty. + + Example:: + # Print the memory contents of a process. + process.suspend() + try: + snapshot = process.generate_memory_snapshot() + for mbi in snapshot: + print HexDump.hexblock(mbi.content, mbi.BaseAddress) + finally: + process.resume() + + The downside of this is the process must remain suspended while + iterating the snapshot, otherwise strange things may happen. + + The snapshot can be iterated more than once. Each time it's iterated + the memory contents of the process will be fetched again. + + You can also iterate the memory of a dead process, just as long as the + last open handle to it hasn't been closed. + + @see: L{take_memory_snapshot} + + @type minAddr: int + @param minAddr: (Optional) Starting address in address range to query. + + @type maxAddr: int + @param maxAddr: (Optional) Ending address in address range to query. + + @rtype: L{Regenerator} of L{win32.MemoryBasicInformation} + @return: Generator that when iterated returns memory region information + objects. Two extra properties are added to these objects: + - C{filename}: Mapped filename, or C{None}. + - C{content}: Memory contents, or C{None}. + """ + return Regenerator(self.iter_memory_snapshot, minAddr, maxAddr) + + def iter_memory_snapshot(self, minAddr = None, maxAddr = None): + """ + Returns an iterator that allows you to go through the memory contents + of a process. + + It's basically the same as the L{take_memory_snapshot} method, but it + takes the snapshot of each memory region as it goes, as opposed to + taking the whole snapshot at once. This allows you to work with very + large snapshots without a significant performance penalty. + + Example:: + # Print the memory contents of a process. + process.suspend() + try: + snapshot = process.generate_memory_snapshot() + for mbi in snapshot: + print HexDump.hexblock(mbi.content, mbi.BaseAddress) + finally: + process.resume() + + The downside of this is the process must remain suspended while + iterating the snapshot, otherwise strange things may happen. + + The snapshot can only iterated once. To be able to iterate indefinitely + call the L{generate_memory_snapshot} method instead. + + You can also iterate the memory of a dead process, just as long as the + last open handle to it hasn't been closed. + + @see: L{take_memory_snapshot} + + @type minAddr: int + @param minAddr: (Optional) Starting address in address range to query. + + @type maxAddr: int + @param maxAddr: (Optional) Ending address in address range to query. + + @rtype: iterator of L{win32.MemoryBasicInformation} + @return: Iterator of memory region information objects. + Two extra properties are added to these objects: + - C{filename}: Mapped filename, or C{None}. + - C{content}: Memory contents, or C{None}. + """ + + # One may feel tempted to include calls to self.suspend() and + # self.resume() here, but that wouldn't work on a dead process. + # It also wouldn't be needed when debugging since the process is + # already suspended when the debug event arrives. So it's up to + # the user to suspend the process if needed. + + # Get the memory map. + memory = self.get_memory_map(minAddr, maxAddr) + + # Abort if the map couldn't be retrieved. + if not memory: + return + + # Get the mapped filenames. + # Don't fail on access denied errors. + try: + filenames = self.get_mapped_filenames(memory) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror != win32.ERROR_ACCESS_DENIED: + raise + filenames = dict() + + # Trim the first memory information block if needed. + if minAddr is not None: + minAddr = MemoryAddresses.align_address_to_page_start(minAddr) + mbi = memory[0] + if mbi.BaseAddress < minAddr: + mbi.RegionSize = mbi.BaseAddress + mbi.RegionSize - minAddr + mbi.BaseAddress = minAddr + + # Trim the last memory information block if needed. + if maxAddr is not None: + if maxAddr != MemoryAddresses.align_address_to_page_start(maxAddr): + maxAddr = MemoryAddresses.align_address_to_page_end(maxAddr) + mbi = memory[-1] + if mbi.BaseAddress + mbi.RegionSize > maxAddr: + mbi.RegionSize = maxAddr - mbi.BaseAddress + + # Read the contents of each block and yield it. + while memory: + mbi = memory.pop(0) # so the garbage collector can take it + mbi.filename = filenames.get(mbi.BaseAddress, None) + if mbi.has_content(): + mbi.content = self.read(mbi.BaseAddress, mbi.RegionSize) + else: + mbi.content = None + yield mbi + + def take_memory_snapshot(self, minAddr = None, maxAddr = None): + """ + Takes a snapshot of the memory contents of the process. + + It's best if the process is suspended (if alive) when taking the + snapshot. Execution can be resumed afterwards. + + Example:: + # Print the memory contents of a process. + process.suspend() + try: + snapshot = process.take_memory_snapshot() + for mbi in snapshot: + print HexDump.hexblock(mbi.content, mbi.BaseAddress) + finally: + process.resume() + + You can also iterate the memory of a dead process, just as long as the + last open handle to it hasn't been closed. + + @warning: If the target process has a very big memory footprint, the + resulting snapshot will be equally big. This may result in a severe + performance penalty. + + @see: L{generate_memory_snapshot} + + @type minAddr: int + @param minAddr: (Optional) Starting address in address range to query. + + @type maxAddr: int + @param maxAddr: (Optional) Ending address in address range to query. + + @rtype: list( L{win32.MemoryBasicInformation} ) + @return: List of memory region information objects. + Two extra properties are added to these objects: + - C{filename}: Mapped filename, or C{None}. + - C{content}: Memory contents, or C{None}. + """ + return list( self.iter_memory_snapshot(minAddr, maxAddr) ) + + def restore_memory_snapshot(self, snapshot, + bSkipMappedFiles = True, + bSkipOnError = False): + """ + Attempts to restore the memory state as it was when the given snapshot + was taken. + + @warning: Currently only the memory contents, state and protect bits + are restored. Under some circumstances this method may fail (for + example if memory was freed and then reused by a mapped file). + + @type snapshot: list( L{win32.MemoryBasicInformation} ) + @param snapshot: Memory snapshot returned by L{take_memory_snapshot}. + Snapshots returned by L{generate_memory_snapshot} don't work here. + + @type bSkipMappedFiles: bool + @param bSkipMappedFiles: C{True} to avoid restoring the contents of + memory mapped files, C{False} otherwise. Use with care! Setting + this to C{False} can cause undesired side effects - changes to + memory mapped files may be written to disk by the OS. Also note + that most mapped files are typically executables and don't change, + so trying to restore their contents is usually a waste of time. + + @type bSkipOnError: bool + @param bSkipOnError: C{True} to issue a warning when an error occurs + during the restoration of the snapshot, C{False} to stop and raise + an exception instead. Use with care! Setting this to C{True} will + cause the debugger to falsely believe the memory snapshot has been + correctly restored. + + @raise WindowsError: An error occured while restoring the snapshot. + @raise RuntimeError: An error occured while restoring the snapshot. + @raise TypeError: A snapshot of the wrong type was passed. + """ + if not snapshot or not isinstance(snapshot, list) \ + or not isinstance(snapshot[0], win32.MemoryBasicInformation): + raise TypeError( "Only snapshots returned by " \ + "take_memory_snapshot() can be used here." ) + + # Get the process handle. + hProcess = self.get_handle( win32.PROCESS_VM_WRITE | + win32.PROCESS_VM_OPERATION | + win32.PROCESS_SUSPEND_RESUME | + win32.PROCESS_QUERY_INFORMATION ) + + # Freeze the process. + self.suspend() + try: + + # For each memory region in the snapshot... + for old_mbi in snapshot: + + # If the region matches, restore it directly. + new_mbi = self.mquery(old_mbi.BaseAddress) + if new_mbi.BaseAddress == old_mbi.BaseAddress and \ + new_mbi.RegionSize == old_mbi.RegionSize: + self.__restore_mbi(hProcess, new_mbi, old_mbi, + bSkipMappedFiles) + + # If the region doesn't match, restore it page by page. + else: + + # We need a copy so we don't corrupt the snapshot. + old_mbi = win32.MemoryBasicInformation(old_mbi) + + # Get the overlapping range of pages. + old_start = old_mbi.BaseAddress + old_end = old_start + old_mbi.RegionSize + new_start = new_mbi.BaseAddress + new_end = new_start + new_mbi.RegionSize + if old_start > new_start: + start = old_start + else: + start = new_start + if old_end < new_end: + end = old_end + else: + end = new_end + + # Restore each page in the overlapping range. + step = MemoryAddresses.pageSize + old_mbi.RegionSize = step + new_mbi.RegionSize = step + address = start + while address < end: + old_mbi.BaseAddress = address + new_mbi.BaseAddress = address + self.__restore_mbi(hProcess, new_mbi, old_mbi, + bSkipMappedFiles, bSkipOnError) + address = address + step + + # Resume execution. + finally: + self.resume() + + def __restore_mbi(self, hProcess, new_mbi, old_mbi, bSkipMappedFiles, + bSkipOnError): + """ + Used internally by L{restore_memory_snapshot}. + """ + +## print "Restoring %s-%s" % ( +## HexDump.address(old_mbi.BaseAddress, self.get_bits()), +## HexDump.address(old_mbi.BaseAddress + old_mbi.RegionSize, +## self.get_bits())) + + try: + + # Restore the region state. + if new_mbi.State != old_mbi.State: + if new_mbi.is_free(): + if old_mbi.is_reserved(): + + # Free -> Reserved + address = win32.VirtualAllocEx(hProcess, + old_mbi.BaseAddress, + old_mbi.RegionSize, + win32.MEM_RESERVE, + old_mbi.Protect) + if address != old_mbi.BaseAddress: + self.free(address) + msg = "Error restoring region at address %s" + msg = msg % HexDump(old_mbi.BaseAddress, + self.get_bits()) + raise RuntimeError(msg) + # permissions already restored + new_mbi.Protect = old_mbi.Protect + + else: # elif old_mbi.is_commited(): + + # Free -> Commited + address = win32.VirtualAllocEx(hProcess, + old_mbi.BaseAddress, + old_mbi.RegionSize, + win32.MEM_RESERVE | \ + win32.MEM_COMMIT, + old_mbi.Protect) + if address != old_mbi.BaseAddress: + self.free(address) + msg = "Error restoring region at address %s" + msg = msg % HexDump(old_mbi.BaseAddress, + self.get_bits()) + raise RuntimeError(msg) + # permissions already restored + new_mbi.Protect = old_mbi.Protect + + elif new_mbi.is_reserved(): + if old_mbi.is_commited(): + + # Reserved -> Commited + address = win32.VirtualAllocEx(hProcess, + old_mbi.BaseAddress, + old_mbi.RegionSize, + win32.MEM_COMMIT, + old_mbi.Protect) + if address != old_mbi.BaseAddress: + self.free(address) + msg = "Error restoring region at address %s" + msg = msg % HexDump(old_mbi.BaseAddress, + self.get_bits()) + raise RuntimeError(msg) + # permissions already restored + new_mbi.Protect = old_mbi.Protect + + else: # elif old_mbi.is_free(): + + # Reserved -> Free + win32.VirtualFreeEx(hProcess, + old_mbi.BaseAddress, + old_mbi.RegionSize, + win32.MEM_RELEASE) + + else: # elif new_mbi.is_commited(): + if old_mbi.is_reserved(): + + # Commited -> Reserved + win32.VirtualFreeEx(hProcess, + old_mbi.BaseAddress, + old_mbi.RegionSize, + win32.MEM_DECOMMIT) + + else: # elif old_mbi.is_free(): + + # Commited -> Free + win32.VirtualFreeEx(hProcess, + old_mbi.BaseAddress, + old_mbi.RegionSize, + win32.MEM_DECOMMIT | win32.MEM_RELEASE) + + new_mbi.State = old_mbi.State + + # Restore the region permissions. + if old_mbi.is_commited() and old_mbi.Protect != new_mbi.Protect: + win32.VirtualProtectEx(hProcess, old_mbi.BaseAddress, + old_mbi.RegionSize, old_mbi.Protect) + new_mbi.Protect = old_mbi.Protect + + # Restore the region data. + # Ignore write errors when the region belongs to a mapped file. + if old_mbi.has_content(): + if old_mbi.Type != 0: + if not bSkipMappedFiles: + self.poke(old_mbi.BaseAddress, old_mbi.content) + else: + self.write(old_mbi.BaseAddress, old_mbi.content) + new_mbi.content = old_mbi.content + + # On error, skip this region or raise an exception. + except Exception: + if not bSkipOnError: + raise + msg = "Error restoring region at address %s: %s" + msg = msg % ( + HexDump(old_mbi.BaseAddress, self.get_bits()), + traceback.format_exc()) + warnings.warn(msg, RuntimeWarning) + +#------------------------------------------------------------------------------ + + def inject_code(self, payload, lpParameter = 0): + """ + Injects relocatable code into the process memory and executes it. + + @warning: Don't forget to free the memory when you're done with it! + Otherwise you'll be leaking memory in the target process. + + @see: L{inject_dll} + + @type payload: str + @param payload: Relocatable code to run in a new thread. + + @type lpParameter: int + @param lpParameter: (Optional) Parameter to be pushed in the stack. + + @rtype: tuple( L{Thread}, int ) + @return: The injected Thread object + and the memory address where the code was written. + + @raise WindowsError: An exception is raised on error. + """ + + # Uncomment for debugging... +## payload = '\xCC' + payload + + # Allocate the memory for the shellcode. + lpStartAddress = self.malloc(len(payload)) + + # Catch exceptions so we can free the memory on error. + try: + + # Write the shellcode to our memory location. + self.write(lpStartAddress, payload) + + # Start a new thread for the shellcode to run. + aThread = self.start_thread(lpStartAddress, lpParameter, + bSuspended = False) + + # Remember the shellcode address. + # It will be freed ONLY by the Thread.kill() method + # and the EventHandler class, otherwise you'll have to + # free it in your code, or have your shellcode clean up + # after itself (recommended). + aThread.pInjectedMemory = lpStartAddress + + # Free the memory on error. + except Exception: + self.free(lpStartAddress) + raise + + # Return the Thread object and the shellcode address. + return aThread, lpStartAddress + + # TODO + # The shellcode should check for errors, otherwise it just crashes + # when the DLL can't be loaded or the procedure can't be found. + # On error the shellcode should execute an int3 instruction. + def inject_dll(self, dllname, procname = None, lpParameter = 0, + bWait = True, dwTimeout = None): + """ + Injects a DLL into the process memory. + + @warning: Setting C{bWait} to C{True} when the process is frozen by a + debug event will cause a deadlock in your debugger. + + @warning: This involves allocating memory in the target process. + This is how the freeing of this memory is handled: + + - If the C{bWait} flag is set to C{True} the memory will be freed + automatically before returning from this method. + - If the C{bWait} flag is set to C{False}, the memory address is + set as the L{Thread.pInjectedMemory} property of the returned + thread object. + - L{Debug} objects free L{Thread.pInjectedMemory} automatically + both when it detaches from a process and when the injected + thread finishes its execution. + - The {Thread.kill} method also frees L{Thread.pInjectedMemory} + automatically, even if you're not attached to the process. + + You could still be leaking memory if not careful. For example, if + you inject a dll into a process you're not attached to, you don't + wait for the thread's completion and you don't kill it either, the + memory would be leaked. + + @see: L{inject_code} + + @type dllname: str + @param dllname: Name of the DLL module to load. + + @type procname: str + @param procname: (Optional) Procedure to call when the DLL is loaded. + + @type lpParameter: int + @param lpParameter: (Optional) Parameter to the C{procname} procedure. + + @type bWait: bool + @param bWait: C{True} to wait for the process to finish. + C{False} to return immediately. + + @type dwTimeout: int + @param dwTimeout: (Optional) Timeout value in milliseconds. + Ignored if C{bWait} is C{False}. + + @rtype: L{Thread} + @return: Newly created thread object. If C{bWait} is set to C{True} the + thread will be dead, otherwise it will be alive. + + @raise NotImplementedError: The target platform is not supported. + Currently calling a procedure in the library is only supported in + the I{i386} architecture. + + @raise WindowsError: An exception is raised on error. + """ + + # Resolve kernel32.dll + aModule = self.get_module_by_name(compat.b('kernel32.dll')) + if aModule is None: + self.scan_modules() + aModule = self.get_module_by_name(compat.b('kernel32.dll')) + if aModule is None: + raise RuntimeError( + "Cannot resolve kernel32.dll in the remote process") + + # Old method, using shellcode. + if procname: + if self.get_arch() != win32.ARCH_I386: + raise NotImplementedError() + dllname = compat.b(dllname) + + # Resolve kernel32.dll!LoadLibraryA + pllib = aModule.resolve(compat.b('LoadLibraryA')) + if not pllib: + raise RuntimeError( + "Cannot resolve kernel32.dll!LoadLibraryA" + " in the remote process") + + # Resolve kernel32.dll!GetProcAddress + pgpad = aModule.resolve(compat.b('GetProcAddress')) + if not pgpad: + raise RuntimeError( + "Cannot resolve kernel32.dll!GetProcAddress" + " in the remote process") + + # Resolve kernel32.dll!VirtualFree + pvf = aModule.resolve(compat.b('VirtualFree')) + if not pvf: + raise RuntimeError( + "Cannot resolve kernel32.dll!VirtualFree" + " in the remote process") + + # Shellcode follows... + code = compat.b('') + + # push dllname + code += compat.b('\xe8') + struct.pack('= 2 and bAllowElevation: + pi = win32.CreateProcess(None, lpCmdLine, + bInheritHandles = bInheritHandles, + dwCreationFlags = dwCreationFlags, + lpStartupInfo = lpStartupInfo) + + # Create the process the hard way... + else: + + # If we allow elevation, use the current process token. + # If not, get the token from the current shell process. + hToken = None + try: + if not bAllowElevation: + if bFollow: + msg = ( + "Child processes can't be autofollowed" + " when dropping UAC elevation.") + raise NotImplementedError(msg) + if bConsole: + msg = ( + "Child processes can't inherit the debugger's" + " console when dropping UAC elevation.") + raise NotImplementedError(msg) + if bInheritHandles: + msg = ( + "Child processes can't inherit the debugger's" + " handles when dropping UAC elevation.") + raise NotImplementedError(msg) + try: + hWnd = self.get_shell_window() + except WindowsError: + hWnd = self.get_desktop_window() + shell = hWnd.get_process() + try: + hShell = shell.get_handle( + win32.PROCESS_QUERY_INFORMATION) + with win32.OpenProcessToken(hShell) as hShellToken: + hToken = win32.DuplicateTokenEx(hShellToken) + finally: + shell.close_handle() + + # Lower trust level if requested. + if iTrustLevel < 2: + if iTrustLevel > 0: + dwLevelId = win32.SAFER_LEVELID_NORMALUSER + else: + dwLevelId = win32.SAFER_LEVELID_UNTRUSTED + with win32.SaferCreateLevel(dwLevelId = dwLevelId) as hSafer: + hSaferToken = win32.SaferComputeTokenFromLevel( + hSafer, hToken)[0] + try: + if hToken is not None: + hToken.close() + except: + hSaferToken.close() + raise + hToken = hSaferToken + + # If we have a computed token, call CreateProcessAsUser(). + if bAllowElevation: + pi = win32.CreateProcessAsUser( + hToken = hToken, + lpCommandLine = lpCmdLine, + bInheritHandles = bInheritHandles, + dwCreationFlags = dwCreationFlags, + lpStartupInfo = lpStartupInfo) + + # If we have a primary token call CreateProcessWithToken(). + # The problem is, there are many flags CreateProcess() and + # CreateProcessAsUser() accept but CreateProcessWithToken() + # and CreateProcessWithLogonW() don't, so we need to work + # around them. + else: + + # Remove the debug flags. + dwCreationFlags &= ~win32.DEBUG_PROCESS + dwCreationFlags &= ~win32.DEBUG_ONLY_THIS_PROCESS + + # Remove the console flags. + dwCreationFlags &= ~win32.DETACHED_PROCESS + + # The process will be created suspended. + dwCreationFlags |= win32.CREATE_SUSPENDED + + # Create the process using the new primary token. + pi = win32.CreateProcessWithToken( + hToken = hToken, + dwLogonFlags = win32.LOGON_WITH_PROFILE, + lpCommandLine = lpCmdLine, + dwCreationFlags = dwCreationFlags, + lpStartupInfo = lpStartupInfo) + + # Attach as a debugger, if requested. + if bDebug: + win32.DebugActiveProcess(pi.dwProcessId) + + # Resume execution, if requested. + if not bSuspended: + win32.ResumeThread(pi.hThread) + + # Close the token when we're done with it. + finally: + if hToken is not None: + hToken.close() + + # Wrap the new process and thread in Process and Thread objects, + # and add them to the corresponding snapshots. + aProcess = Process(pi.dwProcessId, pi.hProcess) + aThread = Thread (pi.dwThreadId, pi.hThread) + aProcess._add_thread(aThread) + self._add_process(aProcess) + + # Clean up on error. + except: + if pi is not None: + try: + win32.TerminateProcess(pi.hProcess) + except WindowsError: + pass + pi.hThread.close() + pi.hProcess.close() + raise + + # Return the new Process object. + return aProcess + + def get_explorer_pid(self): + """ + Tries to find the process ID for "explorer.exe". + + @rtype: int or None + @return: Returns the process ID, or C{None} on error. + """ + try: + exp = win32.SHGetFolderPath(win32.CSIDL_WINDOWS) + except Exception: + exp = None + if not exp: + exp = os.getenv('SystemRoot') + if exp: + exp = os.path.join(exp, 'explorer.exe') + exp_list = self.find_processes_by_filename(exp) + if exp_list: + return exp_list[0][0].get_pid() + return None + +#------------------------------------------------------------------------------ + + # XXX this methods musn't end up calling __initialize_snapshot by accident! + + def scan(self): + """ + Populates the snapshot with running processes and threads, + and loaded modules. + + Tipically this is the first method called after instantiating a + L{System} object, as it makes a best effort approach to gathering + information on running processes. + + @rtype: bool + @return: C{True} if the snapshot is complete, C{False} if the debugger + doesn't have permission to scan some processes. In either case, the + snapshot is complete for all processes the debugger has access to. + """ + has_threads = True + try: + try: + + # Try using the Toolhelp API + # to scan for processes and threads. + self.scan_processes_and_threads() + + except Exception: + + # On error, try using the PSAPI to scan for process IDs only. + self.scan_processes_fast() + + # Now try using the Toolhelp again to get the threads. + for aProcess in self.__processDict.values(): + if aProcess._get_thread_ids(): + try: + aProcess.scan_threads() + except WindowsError: + has_threads = False + + finally: + + # Try using the Remote Desktop API to scan for processes only. + # This will update the filenames when it's not possible + # to obtain them from the Toolhelp API. + self.scan_processes() + + # When finished scanning for processes, try modules too. + has_modules = self.scan_modules() + + # Try updating the process filenames when possible. + has_full_names = self.scan_process_filenames() + + # Return the completion status. + return has_threads and has_modules and has_full_names + + def scan_processes_and_threads(self): + """ + Populates the snapshot with running processes and threads. + + Tipically you don't need to call this method directly, if unsure use + L{scan} instead. + + @note: This method uses the Toolhelp API. + + @see: L{scan_modules} + + @raise WindowsError: An error occured while updating the snapshot. + The snapshot was not modified. + """ + + # The main module filename may be spoofed by malware, + # since this information resides in usermode space. + # See: http://www.ragestorm.net/blogs/?p=163 + + our_pid = win32.GetCurrentProcessId() + dead_pids = set( compat.iterkeys(self.__processDict) ) + found_tids = set() + + # Ignore our own process if it's in the snapshot for some reason + if our_pid in dead_pids: + dead_pids.remove(our_pid) + + # Take a snapshot of all processes and threads + dwFlags = win32.TH32CS_SNAPPROCESS | win32.TH32CS_SNAPTHREAD + with win32.CreateToolhelp32Snapshot(dwFlags) as hSnapshot: + + # Add all the processes (excluding our own) + pe = win32.Process32First(hSnapshot) + while pe is not None: + dwProcessId = pe.th32ProcessID + if dwProcessId != our_pid: + if dwProcessId in dead_pids: + dead_pids.remove(dwProcessId) + if dwProcessId not in self.__processDict: + aProcess = Process(dwProcessId, fileName=pe.szExeFile) + self._add_process(aProcess) + elif pe.szExeFile: + aProcess = self.get_process(dwProcessId) + if not aProcess.fileName: + aProcess.fileName = pe.szExeFile + pe = win32.Process32Next(hSnapshot) + + # Add all the threads + te = win32.Thread32First(hSnapshot) + while te is not None: + dwProcessId = te.th32OwnerProcessID + if dwProcessId != our_pid: + if dwProcessId in dead_pids: + dead_pids.remove(dwProcessId) + if dwProcessId in self.__processDict: + aProcess = self.get_process(dwProcessId) + else: + aProcess = Process(dwProcessId) + self._add_process(aProcess) + dwThreadId = te.th32ThreadID + found_tids.add(dwThreadId) + if not aProcess._has_thread_id(dwThreadId): + aThread = Thread(dwThreadId, process = aProcess) + aProcess._add_thread(aThread) + te = win32.Thread32Next(hSnapshot) + + # Remove dead processes + for pid in dead_pids: + self._del_process(pid) + + # Remove dead threads + for aProcess in compat.itervalues(self.__processDict): + dead_tids = set( aProcess._get_thread_ids() ) + dead_tids.difference_update(found_tids) + for tid in dead_tids: + aProcess._del_thread(tid) + + def scan_modules(self): + """ + Populates the snapshot with loaded modules. + + Tipically you don't need to call this method directly, if unsure use + L{scan} instead. + + @note: This method uses the Toolhelp API. + + @see: L{scan_processes_and_threads} + + @rtype: bool + @return: C{True} if the snapshot is complete, C{False} if the debugger + doesn't have permission to scan some processes. In either case, the + snapshot is complete for all processes the debugger has access to. + """ + complete = True + for aProcess in compat.itervalues(self.__processDict): + try: + aProcess.scan_modules() + except WindowsError: + complete = False + return complete + + def scan_processes(self): + """ + Populates the snapshot with running processes. + + Tipically you don't need to call this method directly, if unsure use + L{scan} instead. + + @note: This method uses the Remote Desktop API instead of the Toolhelp + API. It might give slightly different results, especially if the + current process does not have full privileges. + + @note: This method will only retrieve process filenames. To get the + process pathnames instead, B{after} this method call + L{scan_process_filenames}. + + @raise WindowsError: An error occured while updating the snapshot. + The snapshot was not modified. + """ + + # Get the previous list of PIDs. + # We'll be removing live PIDs from it as we find them. + our_pid = win32.GetCurrentProcessId() + dead_pids = set( compat.iterkeys(self.__processDict) ) + + # Ignore our own PID. + if our_pid in dead_pids: + dead_pids.remove(our_pid) + + # Get the list of processes from the Remote Desktop API. + pProcessInfo = None + try: + pProcessInfo, dwCount = win32.WTSEnumerateProcesses( + win32.WTS_CURRENT_SERVER_HANDLE) + + # For each process found... + for index in compat.xrange(dwCount): + sProcessInfo = pProcessInfo[index] + +## # Ignore processes belonging to other sessions. +## if sProcessInfo.SessionId != win32.WTS_CURRENT_SESSION: +## continue + + # Ignore our own PID. + pid = sProcessInfo.ProcessId + if pid == our_pid: + continue + + # Remove the PID from the dead PIDs list. + if pid in dead_pids: + dead_pids.remove(pid) + + # Get the "process name". + # Empirically, this seems to be the filename without the path. + # (The MSDN docs aren't very clear about this API call). + fileName = sProcessInfo.pProcessName + + # If the process is new, add a new Process object. + if pid not in self.__processDict: + aProcess = Process(pid, fileName = fileName) + self._add_process(aProcess) + + # If the process was already in the snapshot, and the + # filename is missing, update the Process object. + elif fileName: + aProcess = self.__processDict.get(pid) + if not aProcess.fileName: + aProcess.fileName = fileName + + # Free the memory allocated by the Remote Desktop API. + finally: + if pProcessInfo is not None: + try: + win32.WTSFreeMemory(pProcessInfo) + except WindowsError: + pass + + # At this point the only remaining PIDs from the old list are dead. + # Remove them from the snapshot. + for pid in dead_pids: + self._del_process(pid) + + def scan_processes_fast(self): + """ + Populates the snapshot with running processes. + Only the PID is retrieved for each process. + + Dead processes are removed. + Threads and modules of living processes are ignored. + + Tipically you don't need to call this method directly, if unsure use + L{scan} instead. + + @note: This method uses the PSAPI. It may be faster for scanning, + but some information may be missing, outdated or slower to obtain. + This could be a good tradeoff under some circumstances. + """ + + # Get the new and old list of pids + new_pids = set( win32.EnumProcesses() ) + old_pids = set( compat.iterkeys(self.__processDict) ) + + # Ignore our own pid + our_pid = win32.GetCurrentProcessId() + if our_pid in new_pids: + new_pids.remove(our_pid) + if our_pid in old_pids: + old_pids.remove(our_pid) + + # Add newly found pids + for pid in new_pids.difference(old_pids): + self._add_process( Process(pid) ) + + # Remove missing pids + for pid in old_pids.difference(new_pids): + self._del_process(pid) + + def scan_process_filenames(self): + """ + Update the filename for each process in the snapshot when possible. + + @note: Tipically you don't need to call this method. It's called + automatically by L{scan} to get the full pathname for each process + when possible, since some scan methods only get filenames without + the path component. + + If unsure, use L{scan} instead. + + @see: L{scan}, L{Process.get_filename} + + @rtype: bool + @return: C{True} if all the pathnames were retrieved, C{False} if the + debugger doesn't have permission to scan some processes. In either + case, all processes the debugger has access to have a full pathname + instead of just a filename. + """ + complete = True + for aProcess in self.__processDict.values(): + try: + new_name = None + old_name = aProcess.fileName + try: + aProcess.fileName = None + new_name = aProcess.get_filename() + finally: + if not new_name: + aProcess.fileName = old_name + complete = False + except Exception: + complete = False + return complete + +#------------------------------------------------------------------------------ + + def clear_dead_processes(self): + """ + Removes Process objects from the snapshot + referring to processes no longer running. + """ + for pid in self.get_process_ids(): + aProcess = self.get_process(pid) + if not aProcess.is_alive(): + self._del_process(aProcess) + + def clear_unattached_processes(self): + """ + Removes Process objects from the snapshot + referring to processes not being debugged. + """ + for pid in self.get_process_ids(): + aProcess = self.get_process(pid) + if not aProcess.is_being_debugged(): + self._del_process(aProcess) + + def close_process_handles(self): + """ + Closes all open handles to processes in this snapshot. + """ + for pid in self.get_process_ids(): + aProcess = self.get_process(pid) + try: + aProcess.close_handle() + except Exception: + e = sys.exc_info()[1] + try: + msg = "Cannot close process handle %s, reason: %s" + msg %= (aProcess.hProcess.value, str(e)) + warnings.warn(msg) + except Exception: + pass + + def close_process_and_thread_handles(self): + """ + Closes all open handles to processes and threads in this snapshot. + """ + for aProcess in self.iter_processes(): + aProcess.close_thread_handles() + try: + aProcess.close_handle() + except Exception: + e = sys.exc_info()[1] + try: + msg = "Cannot close process handle %s, reason: %s" + msg %= (aProcess.hProcess.value, str(e)) + warnings.warn(msg) + except Exception: + pass + + def clear_processes(self): + """ + Removes all L{Process}, L{Thread} and L{Module} objects in this snapshot. + """ + #self.close_process_and_thread_handles() + for aProcess in self.iter_processes(): + aProcess.clear() + self.__processDict = dict() + + def clear(self): + """ + Clears this snapshot. + + @see: L{clear_processes} + """ + self.clear_processes() + +#------------------------------------------------------------------------------ + + # Docs for these methods are taken from the _ThreadContainer class. + + def has_thread(self, dwThreadId): + dwProcessId = self.get_pid_from_tid(dwThreadId) + if dwProcessId is None: + return False + return self.has_process(dwProcessId) + + def get_thread(self, dwThreadId): + dwProcessId = self.get_pid_from_tid(dwThreadId) + if dwProcessId is None: + msg = "Unknown thread ID %d" % dwThreadId + raise KeyError(msg) + return self.get_process(dwProcessId).get_thread(dwThreadId) + + def get_thread_ids(self): + ids = list() + for aProcess in self.iter_processes(): + ids += aProcess.get_thread_ids() + return ids + + def get_thread_count(self): + count = 0 + for aProcess in self.iter_processes(): + count += aProcess.get_thread_count() + return count + + has_thread.__doc__ = _ThreadContainer.has_thread.__doc__ + get_thread.__doc__ = _ThreadContainer.get_thread.__doc__ + get_thread_ids.__doc__ = _ThreadContainer.get_thread_ids.__doc__ + get_thread_count.__doc__ = _ThreadContainer.get_thread_count.__doc__ + +#------------------------------------------------------------------------------ + + # Docs for these methods are taken from the _ModuleContainer class. + + def get_module_count(self): + count = 0 + for aProcess in self.iter_processes(): + count += aProcess.get_module_count() + return count + + get_module_count.__doc__ = _ModuleContainer.get_module_count.__doc__ + +#------------------------------------------------------------------------------ + + def find_modules_by_base(self, lpBaseOfDll): + """ + @rtype: list( L{Module}... ) + @return: List of Module objects with the given base address. + """ + found = list() + for aProcess in self.iter_processes(): + if aProcess.has_module(lpBaseOfDll): + aModule = aProcess.get_module(lpBaseOfDll) + found.append( (aProcess, aModule) ) + return found + + def find_modules_by_name(self, fileName): + """ + @rtype: list( L{Module}... ) + @return: List of Module objects found. + """ + found = list() + for aProcess in self.iter_processes(): + aModule = aProcess.get_module_by_name(fileName) + if aModule is not None: + found.append( (aProcess, aModule) ) + return found + + def find_modules_by_address(self, address): + """ + @rtype: list( L{Module}... ) + @return: List of Module objects that best match the given address. + """ + found = list() + for aProcess in self.iter_processes(): + aModule = aProcess.get_module_at_address(address) + if aModule is not None: + found.append( (aProcess, aModule) ) + return found + + def __find_processes_by_filename(self, filename): + """ + Internally used by L{find_processes_by_filename}. + """ + found = list() + filename = filename.lower() + if PathOperations.path_is_absolute(filename): + for aProcess in self.iter_processes(): + imagename = aProcess.get_filename() + if imagename and imagename.lower() == filename: + found.append( (aProcess, imagename) ) + else: + for aProcess in self.iter_processes(): + imagename = aProcess.get_filename() + if imagename: + imagename = PathOperations.pathname_to_filename(imagename) + if imagename.lower() == filename: + found.append( (aProcess, imagename) ) + return found + + def find_processes_by_filename(self, fileName): + """ + @type fileName: str + @param fileName: Filename to search for. + If it's a full pathname, the match must be exact. + If it's a base filename only, the file part is matched, + regardless of the directory where it's located. + + @note: If the process is not found and the file extension is not + given, this method will search again assuming a default + extension (.exe). + + @rtype: list of tuple( L{Process}, str ) + @return: List of processes matching the given main module filename. + Each tuple contains a Process object and it's filename. + """ + found = self.__find_processes_by_filename(fileName) + if not found: + fn, ext = PathOperations.split_extension(fileName) + if not ext: + fileName = '%s.exe' % fn + found = self.__find_processes_by_filename(fileName) + return found + +#------------------------------------------------------------------------------ + + # XXX _notify_* methods should not trigger a scan + + def _add_process(self, aProcess): + """ + Private method to add a process object to the snapshot. + + @type aProcess: L{Process} + @param aProcess: Process object. + """ +## if not isinstance(aProcess, Process): +## if hasattr(aProcess, '__class__'): +## typename = aProcess.__class__.__name__ +## else: +## typename = str(type(aProcess)) +## msg = "Expected Process, got %s instead" % typename +## raise TypeError(msg) + dwProcessId = aProcess.dwProcessId +## if dwProcessId in self.__processDict: +## msg = "Process already exists: %d" % dwProcessId +## raise KeyError(msg) + self.__processDict[dwProcessId] = aProcess + + def _del_process(self, dwProcessId): + """ + Private method to remove a process object from the snapshot. + + @type dwProcessId: int + @param dwProcessId: Global process ID. + """ + try: + aProcess = self.__processDict[dwProcessId] + del self.__processDict[dwProcessId] + except KeyError: + aProcess = None + msg = "Unknown process ID %d" % dwProcessId + warnings.warn(msg, RuntimeWarning) + if aProcess: + aProcess.clear() # remove circular references + + # Notify the creation of a new process. + def _notify_create_process(self, event): + """ + Notify the creation of a new process. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{CreateProcessEvent} + @param event: Create process event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + dwProcessId = event.get_pid() + dwThreadId = event.get_tid() + hProcess = event.get_process_handle() +## if not self.has_process(dwProcessId): # XXX this would trigger a scan + if dwProcessId not in self.__processDict: + aProcess = Process(dwProcessId, hProcess) + self._add_process(aProcess) + aProcess.fileName = event.get_filename() + else: + aProcess = self.get_process(dwProcessId) + #if hProcess != win32.INVALID_HANDLE_VALUE: + # aProcess.hProcess = hProcess # may have more privileges + if not aProcess.fileName: + fileName = event.get_filename() + if fileName: + aProcess.fileName = fileName + return aProcess._notify_create_process(event) # pass it to the process + + def _notify_exit_process(self, event): + """ + Notify the termination of a process. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{ExitProcessEvent} + @param event: Exit process event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + dwProcessId = event.get_pid() +## if self.has_process(dwProcessId): # XXX this would trigger a scan + if dwProcessId in self.__processDict: + self._del_process(dwProcessId) + return True diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/registry.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/registry.py new file mode 100644 index 0000000..5623b80 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/registry.py @@ -0,0 +1,695 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Registry access. + +@group Instrumentation: + Registry, RegistryKey +""" + +from __future__ import with_statement + +__revision__ = "$Id$" + +__all__ = ['Registry'] + +import sys +from winappdbg import win32 +from winappdbg import compat +import collections +import warnings + +#============================================================================== + +class _RegistryContainer (object): + """ + Base class for L{Registry} and L{RegistryKey}. + """ + + # Dummy object to detect empty arguments. + class __EmptyArgument: + pass + __emptyArgument = __EmptyArgument() + + def __init__(self): + self.__default = None + + def has_key(self, name): + return name in self + + def get(self, name, default=__emptyArgument): + try: + return self[name] + except KeyError: + if default is RegistryKey.__emptyArgument: + return self.__default + return default + + def setdefault(self, default): + self.__default = default + + def __iter__(self): + return compat.iterkeys(self) + +#============================================================================== + +class RegistryKey (_RegistryContainer): + """ + Exposes a single Windows Registry key as a dictionary-like object. + + @see: L{Registry} + + @type path: str + @ivar path: Registry key path. + + @type handle: L{win32.RegistryKeyHandle} + @ivar handle: Registry key handle. + """ + + def __init__(self, path, handle): + """ + @type path: str + @param path: Registry key path. + + @type handle: L{win32.RegistryKeyHandle} + @param handle: Registry key handle. + """ + super(RegistryKey, self).__init__() + if path.endswith('\\'): + path = path[:-1] + self._path = path + self._handle = handle + + @property + def path(self): + return self._path + + @property + def handle(self): + #if not self._handle: + # msg = "This Registry key handle has already been closed." + # raise RuntimeError(msg) + return self._handle + + #def close(self): + # """ + # Close the Registry key handle, freeing its resources. It cannot be + # used again after calling this method. + # + # @note: This method will be called automatically by the garbage + # collector, and upon exiting a "with" block. + # + # @raise RuntimeError: This Registry key handle has already been closed. + # """ + # self.handle.close() + # + #def __enter__(self): + # """ + # Compatibility with the "C{with}" Python statement. + # """ + # return self + # + #def __exit__(self, type, value, traceback): + # """ + # Compatibility with the "C{with}" Python statement. + # """ + # try: + # self.close() + # except Exception: + # pass + + def __contains__(self, name): + try: + win32.RegQueryValueEx(self.handle, name, False) + return True + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_FILE_NOT_FOUND: + return False + raise + + def __getitem__(self, name): + try: + return win32.RegQueryValueEx(self.handle, name)[0] + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_FILE_NOT_FOUND: + raise KeyError(name) + raise + + def __setitem__(self, name, value): + win32.RegSetValueEx(self.handle, name, value) + + def __delitem__(self, name): + win32.RegDeleteValue(self.handle, name) + + def iterkeys(self): + handle = self.handle + index = 0 + while 1: + resp = win32.RegEnumValue(handle, index, False) + if resp is None: + break + yield resp[0] + index += 1 + + def itervalues(self): + handle = self.handle + index = 0 + while 1: + resp = win32.RegEnumValue(handle, index) + if resp is None: + break + yield resp[2] + index += 1 + + def iteritems(self): + handle = self.handle + index = 0 + while 1: + resp = win32.RegEnumValue(handle, index) + if resp is None: + break + yield resp[0], resp[2] + index += 1 + + def keys(self): + # return list(self.iterkeys()) # that can't be optimized by psyco + handle = self.handle + keys = list() + index = 0 + while 1: + resp = win32.RegEnumValue(handle, index, False) + if resp is None: + break + keys.append(resp[0]) + index += 1 + return keys + + def values(self): + # return list(self.itervalues()) # that can't be optimized by psyco + handle = self.handle + values = list() + index = 0 + while 1: + resp = win32.RegEnumValue(handle, index) + if resp is None: + break + values.append(resp[2]) + index += 1 + return values + + def items(self): + # return list(self.iteritems()) # that can't be optimized by psyco + handle = self.handle + items = list() + index = 0 + while 1: + resp = win32.RegEnumValue(handle, index) + if resp is None: + break + items.append( (resp[0], resp[2]) ) + index += 1 + return items + + def get_value_type(self, name): + """ + Retrieves the low-level data type for the given value. + + @type name: str + @param name: Registry value name. + + @rtype: int + @return: One of the following constants: + - L{win32.REG_NONE} (0) + - L{win32.REG_SZ} (1) + - L{win32.REG_EXPAND_SZ} (2) + - L{win32.REG_BINARY} (3) + - L{win32.REG_DWORD} (4) + - L{win32.REG_DWORD_BIG_ENDIAN} (5) + - L{win32.REG_LINK} (6) + - L{win32.REG_MULTI_SZ} (7) + - L{win32.REG_RESOURCE_LIST} (8) + - L{win32.REG_FULL_RESOURCE_DESCRIPTOR} (9) + - L{win32.REG_RESOURCE_REQUIREMENTS_LIST} (10) + - L{win32.REG_QWORD} (11) + + @raise KeyError: The specified value could not be found. + """ + try: + return win32.RegQueryValueEx(self.handle, name)[1] + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_FILE_NOT_FOUND: + raise KeyError(name) + raise + + def clear(self): + handle = self.handle + while 1: + resp = win32.RegEnumValue(handle, 0, False) + if resp is None: + break + win32.RegDeleteValue(handle, resp[0]) + + def __str__(self): + default = self[''] + return str(default) + + def __unicode__(self): + default = self[u''] + return compat.unicode(default) + + def __repr__(self): + return '' % self._path + + def iterchildren(self): + """ + Iterates the subkeys for this Registry key. + + @rtype: iter of L{RegistryKey} + @return: Iterator of subkeys. + """ + handle = self.handle + index = 0 + while 1: + subkey = win32.RegEnumKey(handle, index) + if subkey is None: + break + yield self.child(subkey) + index += 1 + + def children(self): + """ + Returns a list of subkeys for this Registry key. + + @rtype: list(L{RegistryKey}) + @return: List of subkeys. + """ + # return list(self.iterchildren()) # that can't be optimized by psyco + handle = self.handle + result = [] + index = 0 + while 1: + subkey = win32.RegEnumKey(handle, index) + if subkey is None: + break + result.append( self.child(subkey) ) + index += 1 + return result + + def child(self, subkey): + """ + Retrieves a subkey for this Registry key, given its name. + + @type subkey: str + @param subkey: Name of the subkey. + + @rtype: L{RegistryKey} + @return: Subkey. + """ + path = self._path + '\\' + subkey + handle = win32.RegOpenKey(self.handle, subkey) + return RegistryKey(path, handle) + + def flush(self): + """ + Flushes changes immediately to disk. + + This method is normally not needed, as the Registry writes changes + to disk by itself. This mechanism is provided to ensure the write + happens immediately, as opposed to whenever the OS wants to. + + @warn: Calling this method too often may degrade performance. + """ + win32.RegFlushKey(self.handle) + +#============================================================================== + +# TODO: possibly cache the RegistryKey objects +# to avoid opening and closing handles many times on code sequences like this: +# +# r = Registry() +# r['HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Run']['Example 1'] = 'example1.exe' +# r['HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Run']['Example 2'] = 'example2.exe' +# r['HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Run']['Example 3'] = 'example3.exe' + +# TODO: support for access flags? +# TODO: should be possible to disable the safety checks (see __delitem__) + +# TODO: workaround for an API bug described by a user in MSDN +# +# http://msdn.microsoft.com/en-us/library/windows/desktop/aa379776(v=vs.85).aspx +# +# Apparently RegDeleteTree won't work remotely from Win7 to WinXP, and the only +# solution is to recursively call RegDeleteKey. + +class Registry (_RegistryContainer): + """ + Exposes the Windows Registry as a Python container. + + @type machine: str or None + @ivar machine: For a remote Registry, the machine name. + For a local Registry, the value is C{None}. + """ + + _hives_by_name = { + + # Short names + 'HKCR' : win32.HKEY_CLASSES_ROOT, + 'HKCU' : win32.HKEY_CURRENT_USER, + 'HKLM' : win32.HKEY_LOCAL_MACHINE, + 'HKU' : win32.HKEY_USERS, + 'HKPD' : win32.HKEY_PERFORMANCE_DATA, + 'HKCC' : win32.HKEY_CURRENT_CONFIG, + + # Long names + 'HKEY_CLASSES_ROOT' : win32.HKEY_CLASSES_ROOT, + 'HKEY_CURRENT_USER' : win32.HKEY_CURRENT_USER, + 'HKEY_LOCAL_MACHINE' : win32.HKEY_LOCAL_MACHINE, + 'HKEY_USERS' : win32.HKEY_USERS, + 'HKEY_PERFORMANCE_DATA' : win32.HKEY_PERFORMANCE_DATA, + 'HKEY_CURRENT_CONFIG' : win32.HKEY_CURRENT_CONFIG, + } + + _hives_by_value = { + win32.HKEY_CLASSES_ROOT : 'HKEY_CLASSES_ROOT', + win32.HKEY_CURRENT_USER : 'HKEY_CURRENT_USER', + win32.HKEY_LOCAL_MACHINE : 'HKEY_LOCAL_MACHINE', + win32.HKEY_USERS : 'HKEY_USERS', + win32.HKEY_PERFORMANCE_DATA : 'HKEY_PERFORMANCE_DATA', + win32.HKEY_CURRENT_CONFIG : 'HKEY_CURRENT_CONFIG', + } + + _hives = sorted(compat.itervalues(_hives_by_value)) + + def __init__(self, machine = None): + """ + Opens a local or remote registry. + + @type machine: str + @param machine: Optional machine name. If C{None} it opens the local + registry. + """ + self._machine = machine + self._remote_hives = {} + + @property + def machine(self): + return self._machine + + def _split_path(self, path): + """ + Splits a Registry path and returns the hive and key. + + @type path: str + @param path: Registry path. + + @rtype: tuple( int, str ) + @return: Tuple containing the hive handle and the subkey path. + The hive handle is always one of the following integer constants: + - L{win32.HKEY_CLASSES_ROOT} + - L{win32.HKEY_CURRENT_USER} + - L{win32.HKEY_LOCAL_MACHINE} + - L{win32.HKEY_USERS} + - L{win32.HKEY_PERFORMANCE_DATA} + - L{win32.HKEY_CURRENT_CONFIG} + """ + if '\\' in path: + p = path.find('\\') + hive = path[:p] + path = path[p+1:] + else: + hive = path + path = None + handle = self._hives_by_name[ hive.upper() ] + return handle, path + + def _parse_path(self, path): + """ + Parses a Registry path and returns the hive and key. + + @type path: str + @param path: Registry path. + + @rtype: tuple( int, str ) + @return: Tuple containing the hive handle and the subkey path. + For a local Registry, the hive handle is an integer. + For a remote Registry, the hive handle is a L{RegistryKeyHandle}. + """ + handle, path = self._split_path(path) + if self._machine is not None: + handle = self._connect_hive(handle) + return handle, path + + def _join_path(self, hive, subkey): + """ + Joins the hive and key to make a Registry path. + + @type hive: int + @param hive: Registry hive handle. + The hive handle must be one of the following integer constants: + - L{win32.HKEY_CLASSES_ROOT} + - L{win32.HKEY_CURRENT_USER} + - L{win32.HKEY_LOCAL_MACHINE} + - L{win32.HKEY_USERS} + - L{win32.HKEY_PERFORMANCE_DATA} + - L{win32.HKEY_CURRENT_CONFIG} + + @type subkey: str + @param subkey: Subkey path. + + @rtype: str + @return: Registry path. + """ + path = self._hives_by_value[hive] + if subkey: + path = path + '\\' + subkey + return path + + def _sanitize_path(self, path): + """ + Sanitizes the given Registry path. + + @type path: str + @param path: Registry path. + + @rtype: str + @return: Registry path. + """ + return self._join_path( *self._split_path(path) ) + + def _connect_hive(self, hive): + """ + Connect to the specified hive of a remote Registry. + + @note: The connection will be cached, to close all connections and + erase this cache call the L{close} method. + + @type hive: int + @param hive: Hive to connect to. + + @rtype: L{win32.RegistryKeyHandle} + @return: Open handle to the remote Registry hive. + """ + try: + handle = self._remote_hives[hive] + except KeyError: + handle = win32.RegConnectRegistry(self._machine, hive) + self._remote_hives[hive] = handle + return handle + + def close(self): + """ + Closes all open connections to the remote Registry. + + No exceptions are raised, even if an error occurs. + + This method has no effect when opening the local Registry. + + The remote Registry will still be accessible after calling this method + (new connections will be opened automatically on access). + """ + while self._remote_hives: + hive = self._remote_hives.popitem()[1] + try: + hive.close() + except Exception: + try: + e = sys.exc_info()[1] + msg = "Cannot close registry hive handle %s, reason: %s" + msg %= (hive.value, str(e)) + warnings.warn(msg) + except Exception: + pass + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.close() + + def __repr__(self): + if self._machine: + return '' % self._machine + return '' + + def __contains__(self, path): + hive, subpath = self._parse_path(path) + try: + with win32.RegOpenKey(hive, subpath): + return True + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_FILE_NOT_FOUND: + return False + raise + + def __getitem__(self, path): + path = self._sanitize_path(path) + hive, subpath = self._parse_path(path) + try: + handle = win32.RegOpenKey(hive, subpath) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_FILE_NOT_FOUND: + raise KeyError(path) + raise + return RegistryKey(path, handle) + + def __setitem__(self, path, value): + do_copy = isinstance(value, RegistryKey) + if not do_copy and not isinstance(value, str) \ + and not isinstance(value, compat.unicode): + if isinstance(value, object): + t = value.__class__.__name__ + else: + t = type(value) + raise TypeError("Expected string or RegistryKey, got %s" % t) + hive, subpath = self._parse_path(path) + with win32.RegCreateKey(hive, subpath) as handle: + if do_copy: + win32.RegCopyTree(value.handle, None, handle) + else: + win32.RegSetValueEx(handle, None, value) + + # XXX FIXME currently not working! + # It's probably best to call RegDeleteKey recursively, even if slower. + def __delitem__(self, path): + hive, subpath = self._parse_path(path) + if not subpath: + raise TypeError( + "Are you SURE you want to wipe out an entire hive?!" + " Call win32.RegDeleteTree() directly if you must...") + try: + win32.RegDeleteTree(hive, subpath) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror == win32.ERROR_FILE_NOT_FOUND: + raise KeyError(path) + raise + + def create(self, path): + """ + Creates a new Registry key. + + @type path: str + @param path: Registry key path. + + @rtype: L{RegistryKey} + @return: The newly created Registry key. + """ + path = self._sanitize_path(path) + hive, subpath = self._parse_path(path) + handle = win32.RegCreateKey(hive, subpath) + return RegistryKey(path, handle) + + def subkeys(self, path): + """ + Returns a list of subkeys for the given Registry key. + + @type path: str + @param path: Registry key path. + + @rtype: list(str) + @return: List of subkey names. + """ + result = list() + hive, subpath = self._parse_path(path) + with win32.RegOpenKey(hive, subpath) as handle: + index = 0 + while 1: + name = win32.RegEnumKey(handle, index) + if name is None: + break + result.append(name) + index += 1 + return result + + def iterate(self, path): + """ + Returns a recursive iterator on the specified key and its subkeys. + + @type path: str + @param path: Registry key path. + + @rtype: iterator + @return: Recursive iterator that returns Registry key paths. + + @raise KeyError: The specified path does not exist. + """ + if path.endswith('\\'): + path = path[:-1] + if not self.has_key(path): + raise KeyError(path) + stack = collections.deque() + stack.appendleft(path) + return self.__iterate(stack) + + def iterkeys(self): + """ + Returns an iterator that crawls the entire Windows Registry. + """ + stack = collections.deque(self._hives) + stack.reverse() + return self.__iterate(stack) + + def __iterate(self, stack): + while stack: + path = stack.popleft() + yield path + try: + subkeys = self.subkeys(path) + except WindowsError: + continue + prefix = path + '\\' + subkeys = [prefix + name for name in subkeys] + stack.extendleft(subkeys) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/search.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/search.py new file mode 100644 index 0000000..6efaea6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/search.py @@ -0,0 +1,665 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Process memory finder +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Process memory search. + +@group Memory search: + Search, + Pattern, + BytePattern, + TextPattern, + RegExpPattern, + HexPattern +""" + +__revision__ = "$Id$" + +__all__ = [ + 'Search', + 'Pattern', + 'BytePattern', + 'TextPattern', + 'RegExpPattern', + 'HexPattern', + ] + +from winappdbg.textio import HexInput +from winappdbg.util import StaticClass, MemoryAddresses +from winappdbg import win32 + +import warnings + +try: + # http://pypi.python.org/pypi/regex + import regex as re +except ImportError: + import re + +#============================================================================== + +class Pattern (object): + """ + Base class for search patterns. + + The following L{Pattern} subclasses are provided by WinAppDbg: + - L{BytePattern} + - L{TextPattern} + - L{RegExpPattern} + - L{HexPattern} + + @see: L{Search.search_process} + """ + + def __init__(self, pattern): + """ + Class constructor. + + The only mandatory argument should be the pattern string. + + This method B{MUST} be reimplemented by subclasses of L{Pattern}. + """ + raise NotImplementedError() + + def __len__(self): + """ + Returns the maximum expected length of the strings matched by this + pattern. Exact behavior is implementation dependent. + + Ideally it should be an exact value, but in some cases it's not + possible to calculate so an upper limit should be returned instead. + + If that's not possible either an exception must be raised. + + This value will be used to calculate the required buffer size when + doing buffered searches. + + This method B{MUST} be reimplemented by subclasses of L{Pattern}. + """ + raise NotImplementedError() + + def read(self, process, address, size): + """ + Reads the requested number of bytes from the process memory at the + given address. + + Subclasses of L{Pattern} tipically don't need to reimplement this + method. + """ + return process.read(address, size) + + def find(self, buffer, pos = None): + """ + Searches for the pattern in the given buffer, optionally starting at + the given position within the buffer. + + This method B{MUST} be reimplemented by subclasses of L{Pattern}. + + @type buffer: str + @param buffer: Buffer to search on. + + @type pos: int + @param pos: + (Optional) Position within the buffer to start searching from. + + @rtype: tuple( int, int ) + @return: Tuple containing the following: + - Position within the buffer where a match is found, or C{-1} if + no match was found. + - Length of the matched data if a match is found, or undefined if + no match was found. + """ + raise NotImplementedError() + + def found(self, address, size, data): + """ + This method gets called when a match is found. + + This allows subclasses of L{Pattern} to filter out unwanted results, + or modify the results before giving them to the caller of + L{Search.search_process}. + + If the return value is C{None} the result is skipped. + + Subclasses of L{Pattern} don't need to reimplement this method unless + filtering is needed. + + @type address: int + @param address: The memory address where the pattern was found. + + @type size: int + @param size: The size of the data that matches the pattern. + + @type data: str + @param data: The data that matches the pattern. + + @rtype: tuple( int, int, str ) + @return: Tuple containing the following: + * The memory address where the pattern was found. + * The size of the data that matches the pattern. + * The data that matches the pattern. + """ + return (address, size, data) + +#------------------------------------------------------------------------------ + +class BytePattern (Pattern): + """ + Fixed byte pattern. + + @type pattern: str + @ivar pattern: Byte string to search for. + + @type length: int + @ivar length: Length of the byte pattern. + """ + + def __init__(self, pattern): + """ + @type pattern: str + @param pattern: Byte string to search for. + """ + self.pattern = str(pattern) + self.length = len(pattern) + + def __len__(self): + """ + Returns the exact length of the pattern. + + @see: L{Pattern.__len__} + """ + return self.length + + def find(self, buffer, pos = None): + return buffer.find(self.pattern, pos), self.length + +#------------------------------------------------------------------------------ + +# FIXME: case insensitive compat.unicode searches are probably buggy! + +class TextPattern (BytePattern): + """ + Text pattern. + + @type isUnicode: bool + @ivar isUnicode: C{True} if the text to search for is a compat.unicode string, + C{False} otherwise. + + @type encoding: str + @ivar encoding: Encoding for the text parameter. + Only used when the text to search for is a Unicode string. + Don't change unless you know what you're doing! + + @type caseSensitive: bool + @ivar caseSensitive: C{True} of the search is case sensitive, + C{False} otherwise. + """ + + def __init__(self, text, encoding = "utf-16le", caseSensitive = False): + """ + @type text: str or compat.unicode + @param text: Text to search for. + + @type encoding: str + @param encoding: (Optional) Encoding for the text parameter. + Only used when the text to search for is a Unicode string. + Don't change unless you know what you're doing! + + @type caseSensitive: bool + @param caseSensitive: C{True} of the search is case sensitive, + C{False} otherwise. + """ + self.isUnicode = isinstance(text, compat.unicode) + self.encoding = encoding + self.caseSensitive = caseSensitive + if not self.caseSensitive: + pattern = text.lower() + if self.isUnicode: + pattern = text.encode(encoding) + super(TextPattern, self).__init__(pattern) + + def read(self, process, address, size): + data = super(TextPattern, self).read(address, size) + if not self.caseSensitive: + if self.isUnicode: + try: + encoding = self.encoding + text = data.decode(encoding, "replace") + text = text.lower() + new_data = text.encode(encoding, "replace") + if len(data) == len(new_data): + data = new_data + else: + data = data.lower() + except Exception: + data = data.lower() + else: + data = data.lower() + return data + + def found(self, address, size, data): + if self.isUnicode: + try: + data = compat.unicode(data, self.encoding) + except Exception: +## traceback.print_exc() # XXX DEBUG + return None + return (address, size, data) + +#------------------------------------------------------------------------------ + +class RegExpPattern (Pattern): + """ + Regular expression pattern. + + @type pattern: str + @ivar pattern: Regular expression in text form. + + @type flags: int + @ivar flags: Regular expression flags. + + @type regexp: re.compile + @ivar regexp: Regular expression in compiled form. + + @type maxLength: int + @ivar maxLength: + Maximum expected length of the strings matched by this regular + expression. + + This value will be used to calculate the required buffer size when + doing buffered searches. + + Ideally it should be an exact value, but in some cases it's not + possible to calculate so an upper limit should be given instead. + + If that's not possible either, C{None} should be used. That will + cause an exception to be raised if this pattern is used in a + buffered search. + """ + + def __init__(self, regexp, flags = 0, maxLength = None): + """ + @type regexp: str + @param regexp: Regular expression string. + + @type flags: int + @param flags: Regular expression flags. + + @type maxLength: int + @param maxLength: Maximum expected length of the strings matched by + this regular expression. + + This value will be used to calculate the required buffer size when + doing buffered searches. + + Ideally it should be an exact value, but in some cases it's not + possible to calculate so an upper limit should be given instead. + + If that's not possible either, C{None} should be used. That will + cause an exception to be raised if this pattern is used in a + buffered search. + """ + self.pattern = regexp + self.flags = flags + self.regexp = re.compile(regexp, flags) + self.maxLength = maxLength + + def __len__(self): + """ + Returns the maximum expected length of the strings matched by this + pattern. This value is taken from the C{maxLength} argument of the + constructor if this class. + + Ideally it should be an exact value, but in some cases it's not + possible to calculate so an upper limit should be returned instead. + + If that's not possible either an exception must be raised. + + This value will be used to calculate the required buffer size when + doing buffered searches. + """ + if self.maxLength is None: + raise NotImplementedError() + return self.maxLength + + def find(self, buffer, pos = None): + if not pos: # make sure pos is an int + pos = 0 + match = self.regexp.search(buffer, pos) + if match: + start, end = match.span() + return start, end - start + return -1, 0 + +#------------------------------------------------------------------------------ + +class HexPattern (RegExpPattern): + """ + Hexadecimal pattern. + + Hex patterns must be in this form:: + "68 65 6c 6c 6f 20 77 6f 72 6c 64" # "hello world" + + Spaces are optional. Capitalization of hex digits doesn't matter. + This is exactly equivalent to the previous example:: + "68656C6C6F20776F726C64" # "hello world" + + Wildcards are allowed, in the form of a C{?} sign in any hex digit:: + "5? 5? c3" # pop register / pop register / ret + "b8 ?? ?? ?? ??" # mov eax, immediate value + + @type pattern: str + @ivar pattern: Hexadecimal pattern. + """ + + def __new__(cls, pattern): + """ + If the pattern is completely static (no wildcards are present) a + L{BytePattern} is created instead. That's because searching for a + fixed byte pattern is faster than searching for a regular expression. + """ + if '?' not in pattern: + return BytePattern( HexInput.hexadecimal(pattern) ) + return object.__new__(cls, pattern) + + def __init__(self, hexa): + """ + Hex patterns must be in this form:: + "68 65 6c 6c 6f 20 77 6f 72 6c 64" # "hello world" + + Spaces are optional. Capitalization of hex digits doesn't matter. + This is exactly equivalent to the previous example:: + "68656C6C6F20776F726C64" # "hello world" + + Wildcards are allowed, in the form of a C{?} sign in any hex digit:: + "5? 5? c3" # pop register / pop register / ret + "b8 ?? ?? ?? ??" # mov eax, immediate value + + @type hexa: str + @param hexa: Pattern to search for. + """ + maxLength = len([x for x in hexa + if x in "?0123456789ABCDEFabcdef"]) / 2 + super(HexPattern, self).__init__(HexInput.pattern(hexa), + maxLength = maxLength) + +#============================================================================== + +class Search (StaticClass): + """ + Static class to group the search functionality. + + Do not instance this class! Use its static methods instead. + """ + + # TODO: aligned searches + # TODO: method to coalesce search results + # TODO: search memory dumps + # TODO: search non-ascii C strings + + @staticmethod + def search_process(process, pattern, minAddr = None, + maxAddr = None, + bufferPages = None, + overlapping = False): + """ + Search for the given pattern within the process memory. + + @type process: L{Process} + @param process: Process to search. + + @type pattern: L{Pattern} + @param pattern: Pattern to search for. + It must be an instance of a subclass of L{Pattern}. + + The following L{Pattern} subclasses are provided by WinAppDbg: + - L{BytePattern} + - L{TextPattern} + - L{RegExpPattern} + - L{HexPattern} + + You can also write your own subclass of L{Pattern} for customized + searches. + + @type minAddr: int + @param minAddr: (Optional) Start the search at this memory address. + + @type maxAddr: int + @param maxAddr: (Optional) Stop the search at this memory address. + + @type bufferPages: int + @param bufferPages: (Optional) Number of memory pages to buffer when + performing the search. Valid values are: + - C{0} or C{None}: + Automatically determine the required buffer size. May not give + complete results for regular expressions that match variable + sized strings. + - C{> 0}: Set the buffer size, in memory pages. + - C{< 0}: Disable buffering entirely. This may give you a little + speed gain at the cost of an increased memory usage. If the + target process has very large contiguous memory regions it may + actually be slower or even fail. It's also the only way to + guarantee complete results for regular expressions that match + variable sized strings. + + @type overlapping: bool + @param overlapping: C{True} to allow overlapping results, C{False} + otherwise. + + Overlapping results yield the maximum possible number of results. + + For example, if searching for "AAAA" within "AAAAAAAA" at address + C{0x10000}, when overlapping is turned off the following matches + are yielded:: + (0x10000, 4, "AAAA") + (0x10004, 4, "AAAA") + + If overlapping is turned on, the following matches are yielded:: + (0x10000, 4, "AAAA") + (0x10001, 4, "AAAA") + (0x10002, 4, "AAAA") + (0x10003, 4, "AAAA") + (0x10004, 4, "AAAA") + + As you can see, the middle results are overlapping the last two. + + @rtype: iterator of tuple( int, int, str ) + @return: An iterator of tuples. Each tuple contains the following: + - The memory address where the pattern was found. + - The size of the data that matches the pattern. + - The data that matches the pattern. + + @raise WindowsError: An error occurred when querying or reading the + process memory. + """ + + # Do some namespace lookups of symbols we'll be using frequently. + MEM_COMMIT = win32.MEM_COMMIT + PAGE_GUARD = win32.PAGE_GUARD + page = MemoryAddresses.pageSize + read = pattern.read + find = pattern.find + + # Calculate the address range. + if minAddr is None: + minAddr = 0 + if maxAddr is None: + maxAddr = win32.LPVOID(-1).value # XXX HACK + + # Calculate the buffer size from the number of pages. + if bufferPages is None: + try: + size = MemoryAddresses.\ + align_address_to_page_end(len(pattern)) + page + except NotImplementedError: + size = None + elif bufferPages > 0: + size = page * (bufferPages + 1) + else: + size = None + + # Get the memory map of the process. + memory_map = process.iter_memory_map(minAddr, maxAddr) + + # Perform search with buffering enabled. + if size: + + # Loop through all memory blocks containing data. + buffer = "" # buffer to hold the memory data + prev_addr = 0 # previous memory block address + last = 0 # position of the last match + delta = 0 # delta of last read address and start of buffer + for mbi in memory_map: + + # Skip blocks with no data to search on. + if not mbi.has_content(): + continue + + # Get the address and size of this block. + address = mbi.BaseAddress # current address to search on + block_size = mbi.RegionSize # total size of the block + if address >= maxAddr: + break + end = address + block_size # end address of the block + + # If the block is contiguous to the previous block, + # coalesce the new data in the buffer. + if delta and address == prev_addr: + buffer += read(process, address, page) + + # If not, clear the buffer and read new data. + else: + buffer = read(process, address, min(size, block_size)) + last = 0 + delta = 0 + + # Search for the pattern in this block. + while 1: + + # Yield each match of the pattern in the buffer. + pos, length = find(buffer, last) + while pos >= last: + match_addr = address + pos - delta + if minAddr <= match_addr < maxAddr: + result = pattern.found( + match_addr, length, + buffer [ pos : pos + length ] ) + if result is not None: + yield result + if overlapping: + last = pos + 1 + else: + last = pos + length + pos, length = find(buffer, last) + + # Advance to the next page. + address = address + page + block_size = block_size - page + prev_addr = address + + # Fix the position of the last match. + last = last - page + if last < 0: + last = 0 + + # Remove the first page in the buffer. + buffer = buffer[ page : ] + delta = page + + # If we haven't reached the end of the block yet, + # read the next page in the block and keep seaching. + if address < end: + buffer = buffer + read(process, address, page) + + # Otherwise, we're done searching this block. + else: + break + + # Perform search with buffering disabled. + else: + + # Loop through all memory blocks containing data. + for mbi in memory_map: + + # Skip blocks with no data to search on. + if not mbi.has_content(): + continue + + # Get the address and size of this block. + address = mbi.BaseAddress + block_size = mbi.RegionSize + if address >= maxAddr: + break; + + # Read the whole memory region. + buffer = process.read(address, block_size) + + # Search for the pattern in this region. + pos, length = find(buffer) + last = 0 + while pos >= last: + match_addr = address + pos + if minAddr <= match_addr < maxAddr: + result = pattern.found( + match_addr, length, + buffer [ pos : pos + length ] ) + if result is not None: + yield result + if overlapping: + last = pos + 1 + else: + last = pos + length + pos, length = find(buffer, last) + + @classmethod + def extract_ascii_strings(cls, process, minSize = 4, maxSize = 1024): + """ + Extract ASCII strings from the process memory. + + @type process: L{Process} + @param process: Process to search. + + @type minSize: int + @param minSize: (Optional) Minimum size of the strings to search for. + + @type maxSize: int + @param maxSize: (Optional) Maximum size of the strings to search for. + + @rtype: iterator of tuple(int, int, str) + @return: Iterator of strings extracted from the process memory. + Each tuple contains the following: + - The memory address where the string was found. + - The size of the string. + - The string. + """ + regexp = r"[\s\w\!\@\#\$\%%\^\&\*\(\)\{\}\[\]\~\`\'\"\:\;\.\,\\\/\-\+\=\_\<\>]{%d,%d}\0" % (minSize, maxSize) + pattern = RegExpPattern(regexp, 0, maxSize) + return cls.search_process(process, pattern, overlapping = False) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/sql.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/sql.py new file mode 100644 index 0000000..d974110 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/sql.py @@ -0,0 +1,993 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +SQL database storage support. + +@group Crash reporting: + CrashDAO +""" + +__revision__ = "$Id$" + +__all__ = ['CrashDAO'] + +import sqlite3 +import datetime +import warnings + +from sqlalchemy import create_engine, Column, ForeignKey, Sequence +from sqlalchemy.engine.url import URL +from sqlalchemy.ext.compiler import compiles +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.interfaces import PoolListener +from sqlalchemy.orm import sessionmaker, deferred +from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound +from sqlalchemy.types import Integer, BigInteger, Boolean, DateTime, String, \ + LargeBinary, Enum, VARCHAR +from sqlalchemy.sql.expression import asc, desc + +from crash import Crash, Marshaller, pickle, HIGHEST_PROTOCOL +from textio import CrashDump +import win32 + +#------------------------------------------------------------------------------ + +try: + from decorator import decorator +except ImportError: + import functools + def decorator(w): + """ + The C{decorator} module was not found. You can install it from: + U{http://pypi.python.org/pypi/decorator/} + """ + def d(fn): + @functools.wraps(fn) + def x(*argv, **argd): + return w(fn, *argv, **argd) + return x + return d + +#------------------------------------------------------------------------------ + +@compiles(String, 'mysql') +@compiles(VARCHAR, 'mysql') +def _compile_varchar_mysql(element, compiler, **kw): + """MySQL hack to avoid the "VARCHAR requires a length" error.""" + if not element.length or element.length == 'max': + return "TEXT" + else: + return compiler.visit_VARCHAR(element, **kw) + +#------------------------------------------------------------------------------ + +class _SQLitePatch (PoolListener): + """ + Used internally by L{BaseDAO}. + + After connecting to an SQLite database, ensure that the foreign keys + support is enabled. If not, abort the connection. + + @see: U{http://sqlite.org/foreignkeys.html} + """ + def connect(dbapi_connection, connection_record): + """ + Called once by SQLAlchemy for each new SQLite DB-API connection. + + Here is where we issue some PRAGMA statements to configure how we're + going to access the SQLite database. + + @param dbapi_connection: + A newly connected raw SQLite DB-API connection. + + @param connection_record: + Unused by this method. + """ + try: + cursor = dbapi_connection.cursor() + try: + cursor.execute("PRAGMA foreign_keys = ON;") + cursor.execute("PRAGMA foreign_keys;") + if cursor.fetchone()[0] != 1: + raise Exception() + finally: + cursor.close() + except Exception: + dbapi_connection.close() + raise sqlite3.Error() + +#------------------------------------------------------------------------------ + +class BaseDTO (object): + """ + Customized declarative base for SQLAlchemy. + """ + + __table_args__ = { + + # Don't use MyISAM in MySQL. It doesn't support ON DELETE CASCADE. + 'mysql_engine': 'InnoDB', + + # Don't use BlitzDB in Drizzle. It doesn't support foreign keys. + 'drizzle_engine': 'InnoDB', + + # Collate to UTF-8. + 'mysql_charset': 'utf8', + + } + +BaseDTO = declarative_base(cls = BaseDTO) + +#------------------------------------------------------------------------------ + +# TODO: if using mssql, check it's at least SQL Server 2005 +# (LIMIT and OFFSET support is required). +# TODO: if using mysql, check it's at least MySQL 5.0.3 +# (nested transactions are required). +# TODO: maybe in mysql check the tables are not myisam? +# TODO: maybe create the database if it doesn't exist? +# TODO: maybe add a method to compact the database? +# http://stackoverflow.com/questions/1875885 +# http://www.sqlite.org/lang_vacuum.html +# http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html +# http://msdn.microsoft.com/en-us/library/ms174459(v=sql.90).aspx + +class BaseDAO (object): + """ + Data Access Object base class. + + @type _url: sqlalchemy.url.URL + @ivar _url: Database connection URL. + + @type _dialect: str + @ivar _dialect: SQL dialect currently being used. + + @type _driver: str + @ivar _driver: Name of the database driver currently being used. + To get the actual Python module use L{_url}.get_driver() instead. + + @type _session: sqlalchemy.orm.Session + @ivar _session: Database session object. + + @type _new_session: class + @cvar _new_session: Custom configured Session class used to create the + L{_session} instance variable. + + @type _echo: bool + @cvar _echo: Set to C{True} to print all SQL queries to standard output. + """ + + _echo = False + + _new_session = sessionmaker(autoflush = True, + autocommit = True, + expire_on_commit = True, + weak_identity_map = True) + + def __init__(self, url, creator = None): + """ + Connect to the database using the given connection URL. + + The current implementation uses SQLAlchemy and so it will support + whatever database said module supports. + + @type url: str + @param url: + URL that specifies the database to connect to. + + Some examples: + - Opening an SQLite file: + C{dao = CrashDAO("sqlite:///C:\\some\\path\\database.sqlite")} + - Connecting to a locally installed SQL Express database: + C{dao = CrashDAO("mssql://.\\SQLEXPRESS/Crashes?trusted_connection=yes")} + - Connecting to a MySQL database running locally, using the + C{oursql} library, authenticating as the "winappdbg" user with + no password: + C{dao = CrashDAO("mysql+oursql://winappdbg@localhost/Crashes")} + - Connecting to a Postgres database running locally, + authenticating with user and password: + C{dao = CrashDAO("postgresql://winappdbg:winappdbg@localhost/Crashes")} + + For more information see the C{SQLAlchemy} documentation online: + U{http://docs.sqlalchemy.org/en/latest/core/engines.html} + + Note that in all dialects except for SQLite the database + must already exist. The tables schema, however, is created + automatically when connecting for the first time. + + To create the database in MSSQL, you can use the + U{SQLCMD} + command:: + sqlcmd -Q "CREATE DATABASE Crashes" + + In MySQL you can use something like the following:: + mysql -u root -e "CREATE DATABASE Crashes;" + + And in Postgres:: + createdb Crashes -h localhost -U winappdbg -p winappdbg -O winappdbg + + Some small changes to the schema may be tolerated (for example, + increasing the maximum length of string columns, or adding new + columns with default values). Of course, it's best to test it + first before making changes in a live database. This all depends + very much on the SQLAlchemy version you're using, but it's best + to use the latest version always. + + @type creator: callable + @param creator: (Optional) Callback function that creates the SQL + database connection. + + Normally it's not necessary to use this argument. However in some + odd cases you may need to customize the database connection. + """ + + # Parse the connection URL. + parsed_url = URL(url) + schema = parsed_url.drivername + if '+' in schema: + dialect, driver = schema.split('+') + else: + dialect, driver = schema, 'base' + dialect = dialect.strip().lower() + driver = driver.strip() + + # Prepare the database engine arguments. + arguments = {'echo' : self._echo} + if dialect == 'sqlite': + arguments['module'] = sqlite3.dbapi2 + arguments['listeners'] = [_SQLitePatch()] + if creator is not None: + arguments['creator'] = creator + + # Load the database engine. + engine = create_engine(url, **arguments) + + # Create a new session. + session = self._new_session(bind = engine) + + # Create the required tables if they don't exist. + BaseDTO.metadata.create_all(engine) + # TODO: create a dialect specific index on the "signature" column. + + # Set the instance properties. + self._url = parsed_url + self._driver = driver + self._dialect = dialect + self._session = session + + def _transactional(self, method, *argv, **argd): + """ + Begins a transaction and calls the given DAO method. + + If the method executes successfully the transaction is commited. + + If the method fails, the transaction is rolled back. + + @type method: callable + @param method: Bound method of this class or one of its subclasses. + The first argument will always be C{self}. + + @return: The return value of the method call. + + @raise Exception: Any exception raised by the method. + """ + self._session.begin(subtransactions = True) + try: + result = method(self, *argv, **argd) + self._session.commit() + return result + except: + self._session.rollback() + raise + +#------------------------------------------------------------------------------ + +@decorator +def Transactional(fn, self, *argv, **argd): + """ + Decorator that wraps DAO methods to handle transactions automatically. + + It may only work with subclasses of L{BaseDAO}. + """ + return self._transactional(fn, *argv, **argd) + +#============================================================================== + +# Generates all possible memory access flags. +def _gen_valid_access_flags(): + f = [] + for a1 in ("---", "R--", "RW-", "RC-", "--X", "R-X", "RWX", "RCX", "???"): + for a2 in ("G", "-"): + for a3 in ("N", "-"): + for a4 in ("W", "-"): + f.append("%s %s%s%s" % (a1, a2, a3, a4)) + return tuple(f) +_valid_access_flags = _gen_valid_access_flags() + +# Enumerated types for the memory table. +n_MEM_ACCESS_ENUM = {"name" : "MEM_ACCESS_ENUM"} +n_MEM_ALLOC_ACCESS_ENUM = {"name" : "MEM_ALLOC_ACCESS_ENUM"} +MEM_ACCESS_ENUM = Enum(*_valid_access_flags, + **n_MEM_ACCESS_ENUM) +MEM_ALLOC_ACCESS_ENUM = Enum(*_valid_access_flags, + **n_MEM_ALLOC_ACCESS_ENUM) +MEM_STATE_ENUM = Enum("Reserved", "Commited", "Free", "Unknown", + name = "MEM_STATE_ENUM") +MEM_TYPE_ENUM = Enum("Image", "Mapped", "Private", "Unknown", + name = "MEM_TYPE_ENUM") + +# Cleanup the namespace. +del _gen_valid_access_flags +del _valid_access_flags +del n_MEM_ACCESS_ENUM +del n_MEM_ALLOC_ACCESS_ENUM + +#------------------------------------------------------------------------------ + +class MemoryDTO (BaseDTO): + """ + Database mapping for memory dumps. + """ + + # Declare the table mapping. + __tablename__ = 'memory' + id = Column(Integer, Sequence(__tablename__ + '_seq'), + primary_key = True, autoincrement = True) + crash_id = Column(Integer, ForeignKey('crashes.id', + ondelete = 'CASCADE', + onupdate = 'CASCADE'), + nullable = False) + address = Column(BigInteger, nullable = False, index = True) + size = Column(BigInteger, nullable = False) + state = Column(MEM_STATE_ENUM, nullable = False) + access = Column(MEM_ACCESS_ENUM) + type = Column(MEM_TYPE_ENUM) + alloc_base = Column(BigInteger) + alloc_access = Column(MEM_ALLOC_ACCESS_ENUM) + filename = Column(String) + content = deferred(Column(LargeBinary)) + + def __init__(self, crash_id, mbi): + """ + Process a L{win32.MemoryBasicInformation} object for database storage. + """ + + # Crash ID. + self.crash_id = crash_id + + # Address. + self.address = mbi.BaseAddress + + # Size. + self.size = mbi.RegionSize + + # State (free or allocated). + if mbi.State == win32.MEM_RESERVE: + self.state = "Reserved" + elif mbi.State == win32.MEM_COMMIT: + self.state = "Commited" + elif mbi.State == win32.MEM_FREE: + self.state = "Free" + else: + self.state = "Unknown" + + # Page protection bits (R/W/X/G). + if mbi.State != win32.MEM_COMMIT: + self.access = None + else: + self.access = self._to_access(mbi.Protect) + + # Type (file mapping, executable image, or private memory). + if mbi.Type == win32.MEM_IMAGE: + self.type = "Image" + elif mbi.Type == win32.MEM_MAPPED: + self.type = "Mapped" + elif mbi.Type == win32.MEM_PRIVATE: + self.type = "Private" + elif mbi.Type == 0: + self.type = None + else: + self.type = "Unknown" + + # Allocation info. + self.alloc_base = mbi.AllocationBase + if not mbi.AllocationProtect: + self.alloc_access = None + else: + self.alloc_access = self._to_access(mbi.AllocationProtect) + + # Filename (for memory mappings). + try: + self.filename = mbi.filename + except AttributeError: + self.filename = None + + # Memory contents. + try: + self.content = mbi.content + except AttributeError: + self.content = None + + def _to_access(self, protect): + if protect & win32.PAGE_NOACCESS: + access = "--- " + elif protect & win32.PAGE_READONLY: + access = "R-- " + elif protect & win32.PAGE_READWRITE: + access = "RW- " + elif protect & win32.PAGE_WRITECOPY: + access = "RC- " + elif protect & win32.PAGE_EXECUTE: + access = "--X " + elif protect & win32.PAGE_EXECUTE_READ: + access = "R-X " + elif protect & win32.PAGE_EXECUTE_READWRITE: + access = "RWX " + elif protect & win32.PAGE_EXECUTE_WRITECOPY: + access = "RCX " + else: + access = "??? " + if protect & win32.PAGE_GUARD: + access += "G" + else: + access += "-" + if protect & win32.PAGE_NOCACHE: + access += "N" + else: + access += "-" + if protect & win32.PAGE_WRITECOMBINE: + access += "W" + else: + access += "-" + return access + + def toMBI(self, getMemoryDump = False): + """ + Returns a L{win32.MemoryBasicInformation} object using the data + retrieved from the database. + + @type getMemoryDump: bool + @param getMemoryDump: (Optional) If C{True} retrieve the memory dump. + Defaults to C{False} since this may be a costly operation. + + @rtype: L{win32.MemoryBasicInformation} + @return: Memory block information. + """ + mbi = win32.MemoryBasicInformation() + mbi.BaseAddress = self.address + mbi.RegionSize = self.size + mbi.State = self._parse_state(self.state) + mbi.Protect = self._parse_access(self.access) + mbi.Type = self._parse_type(self.type) + if self.alloc_base is not None: + mbi.AllocationBase = self.alloc_base + else: + mbi.AllocationBase = mbi.BaseAddress + if self.alloc_access is not None: + mbi.AllocationProtect = self._parse_access(self.alloc_access) + else: + mbi.AllocationProtect = mbi.Protect + if self.filename is not None: + mbi.filename = self.filename + if getMemoryDump and self.content is not None: + mbi.content = self.content + return mbi + + @staticmethod + def _parse_state(state): + if state: + if state == "Reserved": + return win32.MEM_RESERVE + if state == "Commited": + return win32.MEM_COMMIT + if state == "Free": + return win32.MEM_FREE + return 0 + + @staticmethod + def _parse_type(type): + if type: + if type == "Image": + return win32.MEM_IMAGE + if type == "Mapped": + return win32.MEM_MAPPED + if type == "Private": + return win32.MEM_PRIVATE + return -1 + return 0 + + @staticmethod + def _parse_access(access): + if not access: + return 0 + perm = access[:3] + if perm == "R--": + protect = win32.PAGE_READONLY + elif perm == "RW-": + protect = win32.PAGE_READWRITE + elif perm == "RC-": + protect = win32.PAGE_WRITECOPY + elif perm == "--X": + protect = win32.PAGE_EXECUTE + elif perm == "R-X": + protect = win32.PAGE_EXECUTE_READ + elif perm == "RWX": + protect = win32.PAGE_EXECUTE_READWRITE + elif perm == "RCX": + protect = win32.PAGE_EXECUTE_WRITECOPY + else: + protect = win32.PAGE_NOACCESS + if access[5] == "G": + protect = protect | win32.PAGE_GUARD + if access[6] == "N": + protect = protect | win32.PAGE_NOCACHE + if access[7] == "W": + protect = protect | win32.PAGE_WRITECOMBINE + return protect + +#------------------------------------------------------------------------------ + +class CrashDTO (BaseDTO): + """ + Database mapping for crash dumps. + """ + + # Table name. + __tablename__ = "crashes" + + # Primary key. + id = Column(Integer, Sequence(__tablename__ + '_seq'), + primary_key = True, autoincrement = True) + + # Timestamp. + timestamp = Column(DateTime, nullable = False, index = True) + + # Exploitability test. + exploitable = Column(Integer, nullable = False) + exploitability_rule = Column(String(32), nullable = False) + exploitability_rating = Column(String(32), nullable = False) + exploitability_desc = Column(String, nullable = False) + + # Platform description. + os = Column(String(32), nullable = False) + arch = Column(String(16), nullable = False) + bits = Column(Integer, nullable = False) # Integer(4) is deprecated :( + + # Event description. + event = Column(String, nullable = False) + pid = Column(Integer, nullable = False) + tid = Column(Integer, nullable = False) + pc = Column(BigInteger, nullable = False) + sp = Column(BigInteger, nullable = False) + fp = Column(BigInteger, nullable = False) + pc_label = Column(String, nullable = False) + + # Exception description. + exception = Column(String(64)) + exception_text = Column(String(64)) + exception_address = Column(BigInteger) + exception_label = Column(String) + first_chance = Column(Boolean) + fault_type = Column(Integer) + fault_address = Column(BigInteger) + fault_label = Column(String) + fault_disasm = Column(String) + stack_trace = Column(String) + + # Environment description. + command_line = Column(String) + environment = Column(String) + + # Debug strings. + debug_string = Column(String) + + # Notes. + notes = Column(String) + + # Heuristic signature. + signature = Column(String, nullable = False) + + # Pickled Crash object, minus the memory dump. + data = deferred(Column(LargeBinary, nullable = False)) + + def __init__(self, crash): + """ + @type crash: Crash + @param crash: L{Crash} object to store into the database. + """ + + # Timestamp and signature. + self.timestamp = datetime.datetime.fromtimestamp( crash.timeStamp ) + self.signature = pickle.dumps(crash.signature, protocol = 0) + + # Marshalled Crash object, minus the memory dump. + # This code is *not* thread safe! + memoryMap = crash.memoryMap + try: + crash.memoryMap = None + self.data = buffer( Marshaller.dumps(crash) ) + finally: + crash.memoryMap = memoryMap + + # Exploitability test. + self.exploitability_rating, \ + self.exploitability_rule, \ + self.exploitability_desc = crash.isExploitable() + + # Exploitability test as an integer result (for sorting). + self.exploitable = [ + "Not an exception", + "Not exploitable", + "Not likely exploitable", + "Unknown", + "Probably exploitable", + "Exploitable", + ].index(self.exploitability_rating) + + # Platform description. + self.os = crash.os + self.arch = crash.arch + self.bits = crash.bits + + # Event description. + self.event = crash.eventName + self.pid = crash.pid + self.tid = crash.tid + self.pc = crash.pc + self.sp = crash.sp + self.fp = crash.fp + self.pc_label = crash.labelPC + + # Exception description. + self.exception = crash.exceptionName + self.exception_text = crash.exceptionDescription + self.exception_address = crash.exceptionAddress + self.exception_label = crash.exceptionLabel + self.first_chance = crash.firstChance + self.fault_type = crash.faultType + self.fault_address = crash.faultAddress + self.fault_label = crash.faultLabel + self.fault_disasm = CrashDump.dump_code( crash.faultDisasm, + crash.pc ) + self.stack_trace = CrashDump.dump_stack_trace_with_labels( + crash.stackTracePretty ) + + # Command line. + self.command_line = crash.commandLine + + # Environment. + if crash.environment: + envList = crash.environment.items() + envList.sort() + environment = '' + for envKey, envVal in envList: + # Must concatenate here instead of using a substitution, + # so strings can be automatically promoted to Unicode. + environment += envKey + '=' + envVal + '\n' + if environment: + self.environment = environment + + # Debug string. + self.debug_string = crash.debugString + + # Notes. + self.notes = crash.notesReport() + + def toCrash(self, getMemoryDump = False): + """ + Returns a L{Crash} object using the data retrieved from the database. + + @type getMemoryDump: bool + @param getMemoryDump: If C{True} retrieve the memory dump. + Defaults to C{False} since this may be a costly operation. + + @rtype: L{Crash} + @return: Crash object. + """ + crash = Marshaller.loads(str(self.data)) + if not isinstance(crash, Crash): + raise TypeError( + "Expected Crash instance, got %s instead" % type(crash)) + crash._rowid = self.id + if not crash.memoryMap: + memory = getattr(self, "memory", []) + if memory: + crash.memoryMap = [dto.toMBI(getMemoryDump) for dto in memory] + return crash + +#============================================================================== + +# TODO: add a method to modify already stored crash dumps. + +class CrashDAO (BaseDAO): + """ + Data Access Object to read, write and search for L{Crash} objects in a + database. + """ + + @Transactional + def add(self, crash, allow_duplicates = True): + """ + Add a new crash dump to the database, optionally filtering them by + signature to avoid duplicates. + + @type crash: L{Crash} + @param crash: Crash object. + + @type allow_duplicates: bool + @param allow_duplicates: (Optional) + C{True} to always add the new crash dump. + C{False} to only add the crash dump if no other crash with the + same signature is found in the database. + + Sometimes, your fuzzer turns out to be I{too} good. Then you find + youself browsing through gigabytes of crash dumps, only to find + a handful of actual bugs in them. This simple heuristic filter + saves you the trouble by discarding crashes that seem to be similar + to another one you've already found. + """ + + # Filter out duplicated crashes, if requested. + if not allow_duplicates: + signature = pickle.dumps(crash.signature, protocol = 0) + if self._session.query(CrashDTO.id) \ + .filter_by(signature = signature) \ + .count() > 0: + return + + # Fill out a new row for the crashes table. + crash_id = self.__add_crash(crash) + + # Fill out new rows for the memory dump. + self.__add_memory(crash_id, crash.memoryMap) + + # On success set the row ID for the Crash object. + # WARNING: In nested calls, make sure to delete + # this property before a session rollback! + crash._rowid = crash_id + + # Store the Crash object into the crashes table. + def __add_crash(self, crash): + session = self._session + r_crash = None + try: + + # Fill out a new row for the crashes table. + r_crash = CrashDTO(crash) + session.add(r_crash) + + # Flush and get the new row ID. + session.flush() + crash_id = r_crash.id + + finally: + try: + + # Make the ORM forget the CrashDTO object. + if r_crash is not None: + session.expire(r_crash) + + finally: + + # Delete the last reference to the CrashDTO + # object, so the Python garbage collector claims it. + del r_crash + + # Return the row ID. + return crash_id + + # Store the memory dump into the memory table. + def __add_memory(self, crash_id, memoryMap): + session = self._session + if memoryMap: + for mbi in memoryMap: + r_mem = MemoryDTO(crash_id, mbi) + session.add(r_mem) + session.flush() + + @Transactional + def find(self, + signature = None, order = 0, + since = None, until = None, + offset = None, limit = None): + """ + Retrieve all crash dumps in the database, optionally filtering them by + signature and timestamp, and/or sorting them by timestamp. + + Results can be paged to avoid consuming too much memory if the database + is large. + + @see: L{find_by_example} + + @type signature: object + @param signature: (Optional) Return only through crashes matching + this signature. See L{Crash.signature} for more details. + + @type order: int + @param order: (Optional) Sort by timestamp. + If C{== 0}, results are not sorted. + If C{> 0}, results are sorted from older to newer. + If C{< 0}, results are sorted from newer to older. + + @type since: datetime + @param since: (Optional) Return only the crashes after and + including this date and time. + + @type until: datetime + @param until: (Optional) Return only the crashes before this date + and time, not including it. + + @type offset: int + @param offset: (Optional) Skip the first I{offset} results. + + @type limit: int + @param limit: (Optional) Return at most I{limit} results. + + @rtype: list(L{Crash}) + @return: List of Crash objects. + """ + + # Validate the parameters. + if since and until and since > until: + warnings.warn("CrashDAO.find() got the 'since' and 'until'" + " arguments reversed, corrected automatically.") + since, until = until, since + if limit is not None and not limit: + warnings.warn("CrashDAO.find() was set a limit of 0 results," + " returning without executing a query.") + return [] + + # Build the SQL query. + query = self._session.query(CrashDTO) + if signature is not None: + sig_pickled = pickle.dumps(signature, protocol = 0) + query = query.filter(CrashDTO.signature == sig_pickled) + if since: + query = query.filter(CrashDTO.timestamp >= since) + if until: + query = query.filter(CrashDTO.timestamp < until) + if order: + if order > 0: + query = query.order_by(asc(CrashDTO.timestamp)) + else: + query = query.order_by(desc(CrashDTO.timestamp)) + else: + # Default ordering is by row ID, to get consistent results. + # Also some database engines require ordering when using offsets. + query = query.order_by(asc(CrashDTO.id)) + if offset: + query = query.offset(offset) + if limit: + query = query.limit(limit) + + # Execute the SQL query and convert the results. + try: + return [dto.toCrash() for dto in query.all()] + except NoResultFound: + return [] + + @Transactional + def find_by_example(self, crash, offset = None, limit = None): + """ + Find all crash dumps that have common properties with the crash dump + provided. + + Results can be paged to avoid consuming too much memory if the database + is large. + + @see: L{find} + + @type crash: L{Crash} + @param crash: Crash object to compare with. Fields set to C{None} are + ignored, all other fields but the signature are used in the + comparison. + + To search for signature instead use the L{find} method. + + @type offset: int + @param offset: (Optional) Skip the first I{offset} results. + + @type limit: int + @param limit: (Optional) Return at most I{limit} results. + + @rtype: list(L{Crash}) + @return: List of similar crash dumps found. + """ + + # Validate the parameters. + if limit is not None and not limit: + warnings.warn("CrashDAO.find_by_example() was set a limit of 0" + " results, returning without executing a query.") + return [] + + # Build the query. + query = self._session.query(CrashDTO) + + # Order by row ID to get consistent results. + # Also some database engines require ordering when using offsets. + query = query.asc(CrashDTO.id) + + # Build a CrashDTO from the Crash object. + dto = CrashDTO(crash) + + # Filter all the fields in the crashes table that are present in the + # CrashDTO object and not set to None, except for the row ID. + for name, column in compat.iteritems(CrashDTO.__dict__): + if not name.startswith('__') and name not in ('id', + 'signature', + 'data'): + if isinstance(column, Column): + value = getattr(dto, name, None) + if value is not None: + query = query.filter(column == value) + + # Page the query. + if offset: + query = query.offset(offset) + if limit: + query = query.limit(limit) + + # Execute the SQL query and convert the results. + try: + return [dto.toCrash() for dto in query.all()] + except NoResultFound: + return [] + + @Transactional + def count(self, signature = None): + """ + Counts how many crash dumps have been stored in this database. + Optionally filters the count by heuristic signature. + + @type signature: object + @param signature: (Optional) Count only the crashes that match + this signature. See L{Crash.signature} for more details. + + @rtype: int + @return: Count of crash dumps stored in this database. + """ + query = self._session.query(CrashDTO.id) + if signature: + sig_pickled = pickle.dumps(signature, protocol = 0) + query = query.filter_by(signature = sig_pickled) + return query.count() + + @Transactional + def delete(self, crash): + """ + Remove the given crash dump from the database. + + @type crash: L{Crash} + @param crash: Crash dump to remove. + """ + query = self._session.query(CrashDTO).filter_by(id = crash._rowid) + query.delete(synchronize_session = False) + del crash._rowid diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/system.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/system.py new file mode 100644 index 0000000..9ee3200 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/system.py @@ -0,0 +1,1297 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +System settings. + +@group Instrumentation: + System +""" + +from __future__ import with_statement + +__revision__ = "$Id$" + +__all__ = ['System'] + +from winappdbg import win32 +from winappdbg.registry import Registry +from winappdbg.textio import HexInput, HexDump +from winappdbg.util import Regenerator, PathOperations, MemoryAddresses, DebugRegister, \ + classproperty +from winappdbg.process import _ProcessContainer +from winappdbg.window import Window + +import sys +import os +import ctypes +import warnings + +from os import path, getenv + +#============================================================================== + +class System (_ProcessContainer): + """ + Interface to a batch of processes, plus some system wide settings. + Contains a snapshot of processes. + + @group Platform settings: + arch, bits, os, wow64, pageSize + + @group Instrumentation: + find_window, get_window_at, get_foreground_window, + get_desktop_window, get_shell_window + + @group Debugging: + load_dbghelp, fix_symbol_store_path, + request_debug_privileges, drop_debug_privileges + + @group Postmortem debugging: + get_postmortem_debugger, set_postmortem_debugger, + get_postmortem_exclusion_list, add_to_postmortem_exclusion_list, + remove_from_postmortem_exclusion_list + + @group System services: + get_services, get_active_services, + start_service, stop_service, + pause_service, resume_service, + get_service_display_name, get_service_from_display_name + + @group Permissions and privileges: + request_privileges, drop_privileges, adjust_privileges, is_admin + + @group Miscellaneous global settings: + set_kill_on_exit_mode, read_msr, write_msr, enable_step_on_branch_mode, + get_last_branch_location + + @type arch: str + @cvar arch: Name of the processor architecture we're running on. + For more details see L{win32.version._get_arch}. + + @type bits: int + @cvar bits: Size of the machine word in bits for the current architecture. + For more details see L{win32.version._get_bits}. + + @type os: str + @cvar os: Name of the Windows version we're runing on. + For more details see L{win32.version._get_os}. + + @type wow64: bool + @cvar wow64: C{True} if the debugger is a 32 bits process running in a 64 + bits version of Windows, C{False} otherwise. + + @type pageSize: int + @cvar pageSize: Page size in bytes. Defaults to 0x1000 but it's + automatically updated on runtime when importing the module. + + @type registry: L{Registry} + @cvar registry: Windows Registry for this machine. + """ + + arch = win32.arch + bits = win32.bits + os = win32.os + wow64 = win32.wow64 + + @classproperty + def pageSize(cls): + pageSize = MemoryAddresses.pageSize + cls.pageSize = pageSize + return pageSize + + registry = Registry() + +#------------------------------------------------------------------------------ + + @staticmethod + def find_window(className = None, windowName = None): + """ + Find the first top-level window in the current desktop to match the + given class name and/or window name. If neither are provided any + top-level window will match. + + @see: L{get_window_at} + + @type className: str + @param className: (Optional) Class name of the window to find. + If C{None} or not used any class name will match the search. + + @type windowName: str + @param windowName: (Optional) Caption text of the window to find. + If C{None} or not used any caption text will match the search. + + @rtype: L{Window} or None + @return: A window that matches the request. There may be more matching + windows, but this method only returns one. If no matching window + is found, the return value is C{None}. + + @raise WindowsError: An error occured while processing this request. + """ + # I'd love to reverse the order of the parameters + # but that might create some confusion. :( + hWnd = win32.FindWindow(className, windowName) + if hWnd: + return Window(hWnd) + + @staticmethod + def get_window_at(x, y): + """ + Get the window located at the given coordinates in the desktop. + If no such window exists an exception is raised. + + @see: L{find_window} + + @type x: int + @param x: Horizontal coordinate. + @type y: int + @param y: Vertical coordinate. + + @rtype: L{Window} + @return: Window at the requested position. If no such window + exists a C{WindowsError} exception is raised. + + @raise WindowsError: An error occured while processing this request. + """ + return Window( win32.WindowFromPoint( (x, y) ) ) + + @staticmethod + def get_foreground_window(): + """ + @rtype: L{Window} + @return: Returns the foreground window. + @raise WindowsError: An error occured while processing this request. + """ + return Window( win32.GetForegroundWindow() ) + + @staticmethod + def get_desktop_window(): + """ + @rtype: L{Window} + @return: Returns the desktop window. + @raise WindowsError: An error occured while processing this request. + """ + return Window( win32.GetDesktopWindow() ) + + @staticmethod + def get_shell_window(): + """ + @rtype: L{Window} + @return: Returns the shell window. + @raise WindowsError: An error occured while processing this request. + """ + return Window( win32.GetShellWindow() ) + +#------------------------------------------------------------------------------ + + @classmethod + def request_debug_privileges(cls, bIgnoreExceptions = False): + """ + Requests debug privileges. + + This may be needed to debug processes running as SYSTEM + (such as services) since Windows XP. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when requesting debug privileges. + + @rtype: bool + @return: C{True} on success, C{False} on failure. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + try: + cls.request_privileges(win32.SE_DEBUG_NAME) + return True + except Exception: + if not bIgnoreExceptions: + raise + return False + + @classmethod + def drop_debug_privileges(cls, bIgnoreExceptions = False): + """ + Drops debug privileges. + + This may be needed to avoid being detected + by certain anti-debug tricks. + + @type bIgnoreExceptions: bool + @param bIgnoreExceptions: C{True} to ignore any exceptions that may be + raised when dropping debug privileges. + + @rtype: bool + @return: C{True} on success, C{False} on failure. + + @raise WindowsError: Raises an exception on error, unless + C{bIgnoreExceptions} is C{True}. + """ + try: + cls.drop_privileges(win32.SE_DEBUG_NAME) + return True + except Exception: + if not bIgnoreExceptions: + raise + return False + + @classmethod + def request_privileges(cls, *privileges): + """ + Requests privileges. + + @type privileges: int... + @param privileges: Privileges to request. + + @raise WindowsError: Raises an exception on error. + """ + cls.adjust_privileges(True, privileges) + + @classmethod + def drop_privileges(cls, *privileges): + """ + Drops privileges. + + @type privileges: int... + @param privileges: Privileges to drop. + + @raise WindowsError: Raises an exception on error. + """ + cls.adjust_privileges(False, privileges) + + @staticmethod + def adjust_privileges(state, privileges): + """ + Requests or drops privileges. + + @type state: bool + @param state: C{True} to request, C{False} to drop. + + @type privileges: list(int) + @param privileges: Privileges to request or drop. + + @raise WindowsError: Raises an exception on error. + """ + with win32.OpenProcessToken(win32.GetCurrentProcess(), + win32.TOKEN_ADJUST_PRIVILEGES) as hToken: + NewState = ( (priv, state) for priv in privileges ) + win32.AdjustTokenPrivileges(hToken, NewState) + + @staticmethod + def is_admin(): + """ + @rtype: bool + @return: C{True} if the current user as Administrator privileges, + C{False} otherwise. Since Windows Vista and above this means if + the current process is running with UAC elevation or not. + """ + return win32.IsUserAnAdmin() + +#------------------------------------------------------------------------------ + + __binary_types = { + win32.VFT_APP: "application", + win32.VFT_DLL: "dynamic link library", + win32.VFT_STATIC_LIB: "static link library", + win32.VFT_FONT: "font", + win32.VFT_DRV: "driver", + win32.VFT_VXD: "legacy driver", + } + + __driver_types = { + win32.VFT2_DRV_COMM: "communications driver", + win32.VFT2_DRV_DISPLAY: "display driver", + win32.VFT2_DRV_INSTALLABLE: "installable driver", + win32.VFT2_DRV_KEYBOARD: "keyboard driver", + win32.VFT2_DRV_LANGUAGE: "language driver", + win32.VFT2_DRV_MOUSE: "mouse driver", + win32.VFT2_DRV_NETWORK: "network driver", + win32.VFT2_DRV_PRINTER: "printer driver", + win32.VFT2_DRV_SOUND: "sound driver", + win32.VFT2_DRV_SYSTEM: "system driver", + win32.VFT2_DRV_VERSIONED_PRINTER: "versioned printer driver", + } + + __font_types = { + win32.VFT2_FONT_RASTER: "raster font", + win32.VFT2_FONT_TRUETYPE: "TrueType font", + win32.VFT2_FONT_VECTOR: "vector font", + } + + __months = ( + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ) + + __days_of_the_week = ( + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + ) + + @classmethod + def get_file_version_info(cls, filename): + """ + Get the program version from an executable file, if available. + + @type filename: str + @param filename: Pathname to the executable file to query. + + @rtype: tuple(str, str, bool, bool, str, str) + @return: Tuple with version information extracted from the executable + file metadata, containing the following: + - File version number (C{"major.minor"}). + - Product version number (C{"major.minor"}). + - C{True} for debug builds, C{False} for production builds. + - C{True} for legacy OS builds (DOS, OS/2, Win16), + C{False} for modern OS builds. + - Binary file type. + May be one of the following values: + - "application" + - "dynamic link library" + - "static link library" + - "font" + - "raster font" + - "TrueType font" + - "vector font" + - "driver" + - "communications driver" + - "display driver" + - "installable driver" + - "keyboard driver" + - "language driver" + - "legacy driver" + - "mouse driver" + - "network driver" + - "printer driver" + - "sound driver" + - "system driver" + - "versioned printer driver" + - Binary creation timestamp. + Any of the fields may be C{None} if not available. + + @raise WindowsError: Raises an exception on error. + """ + + # Get the file version info structure. + pBlock = win32.GetFileVersionInfo(filename) + pBuffer, dwLen = win32.VerQueryValue(pBlock, "\\") + if dwLen != ctypes.sizeof(win32.VS_FIXEDFILEINFO): + raise ctypes.WinError(win32.ERROR_BAD_LENGTH) + pVersionInfo = ctypes.cast(pBuffer, + ctypes.POINTER(win32.VS_FIXEDFILEINFO)) + VersionInfo = pVersionInfo.contents + if VersionInfo.dwSignature != 0xFEEF04BD: + raise ctypes.WinError(win32.ERROR_BAD_ARGUMENTS) + + # File and product versions. + FileVersion = "%d.%d" % (VersionInfo.dwFileVersionMS, + VersionInfo.dwFileVersionLS) + ProductVersion = "%d.%d" % (VersionInfo.dwProductVersionMS, + VersionInfo.dwProductVersionLS) + + # Debug build? + if VersionInfo.dwFileFlagsMask & win32.VS_FF_DEBUG: + DebugBuild = (VersionInfo.dwFileFlags & win32.VS_FF_DEBUG) != 0 + else: + DebugBuild = None + + # Legacy OS build? + LegacyBuild = (VersionInfo.dwFileOS != win32.VOS_NT_WINDOWS32) + + # File type. + FileType = cls.__binary_types.get(VersionInfo.dwFileType) + if VersionInfo.dwFileType == win32.VFT_DRV: + FileType = cls.__driver_types.get(VersionInfo.dwFileSubtype) + elif VersionInfo.dwFileType == win32.VFT_FONT: + FileType = cls.__font_types.get(VersionInfo.dwFileSubtype) + + # Timestamp, ex: "Monday, July 7, 2013 (12:20:50.126)". + # FIXME: how do we know the time zone? + FileDate = (VersionInfo.dwFileDateMS << 32) + VersionInfo.dwFileDateLS + if FileDate: + CreationTime = win32.FileTimeToSystemTime(FileDate) + CreationTimestamp = "%s, %s %d, %d (%d:%d:%d.%d)" % ( + cls.__days_of_the_week[CreationTime.wDayOfWeek], + cls.__months[CreationTime.wMonth], + CreationTime.wDay, + CreationTime.wYear, + CreationTime.wHour, + CreationTime.wMinute, + CreationTime.wSecond, + CreationTime.wMilliseconds, + ) + else: + CreationTimestamp = None + + # Return the file version info. + return ( + FileVersion, + ProductVersion, + DebugBuild, + LegacyBuild, + FileType, + CreationTimestamp, + ) + +#------------------------------------------------------------------------------ + + # Locations for dbghelp.dll. + # Unfortunately, Microsoft started bundling WinDbg with the + # platform SDK, so the install directories may vary across + # versions and platforms. + __dbghelp_locations = { + + # Intel 64 bits. + win32.ARCH_AMD64: set([ + + # WinDbg bundled with the SDK, version 8.0. + path.join( + getenv("ProgramFiles", "C:\\Program Files"), + "Windows Kits", + "8.0", + "Debuggers", + "x64", + "dbghelp.dll"), + path.join( + getenv("ProgramW6432", getenv("ProgramFiles", + "C:\\Program Files")), + "Windows Kits", + "8.0", + "Debuggers", + "x64", + "dbghelp.dll"), + + # Old standalone versions of WinDbg. + path.join( + getenv("ProgramFiles", "C:\\Program Files"), + "Debugging Tools for Windows (x64)", + "dbghelp.dll"), + ]), + + # Intel 32 bits. + win32.ARCH_I386 : set([ + + # WinDbg bundled with the SDK, version 8.0. + path.join( + getenv("ProgramFiles", "C:\\Program Files"), + "Windows Kits", + "8.0", + "Debuggers", + "x86", + "dbghelp.dll"), + path.join( + getenv("ProgramW6432", getenv("ProgramFiles", + "C:\\Program Files")), + "Windows Kits", + "8.0", + "Debuggers", + "x86", + "dbghelp.dll"), + + # Old standalone versions of WinDbg. + path.join( + getenv("ProgramFiles", "C:\\Program Files"), + "Debugging Tools for Windows (x86)", + "dbghelp.dll"), + + # Version shipped with Windows. + path.join( + getenv("ProgramFiles", "C:\\Program Files"), + "Debugging Tools for Windows (x86)", + "dbghelp.dll"), + ]), + } + + @classmethod + def load_dbghelp(cls, pathname = None): + """ + Load the specified version of the C{dbghelp.dll} library. + + This library is shipped with the Debugging Tools for Windows, and it's + required to load debug symbols. + + Normally you don't need to call this method, as WinAppDbg already tries + to load the latest version automatically - but it may come in handy if + the Debugging Tools are installed in a non standard folder. + + Example:: + from winappdbg import Debug + + def simple_debugger( argv ): + + # Instance a Debug object, passing it the event handler callback + debug = Debug( my_event_handler ) + try: + + # Load a specific dbghelp.dll file + debug.system.load_dbghelp("C:\\Some folder\\dbghelp.dll") + + # Start a new process for debugging + debug.execv( argv ) + + # Wait for the debugee to finish + debug.loop() + + # Stop the debugger + finally: + debug.stop() + + @see: U{http://msdn.microsoft.com/en-us/library/ms679294(VS.85).aspx} + + @type pathname: str + @param pathname: + (Optional) Full pathname to the C{dbghelp.dll} library. + If not provided this method will try to autodetect it. + + @rtype: ctypes.WinDLL + @return: Loaded instance of C{dbghelp.dll}. + + @raise NotImplementedError: This feature was not implemented for the + current architecture. + + @raise WindowsError: An error occured while processing this request. + """ + + # If an explicit pathname was not given, search for the library. + if not pathname: + + # Under WOW64 we'll treat AMD64 as I386. + arch = win32.arch + if arch == win32.ARCH_AMD64 and win32.bits == 32: + arch = win32.ARCH_I386 + + # Check if the architecture is supported. + if not arch in cls.__dbghelp_locations: + msg = "Architecture %s is not currently supported." + raise NotImplementedError(msg % arch) + + # Grab all versions of the library we can find. + found = [] + for pathname in cls.__dbghelp_locations[arch]: + if path.isfile(pathname): + try: + f_ver, p_ver = cls.get_file_version_info(pathname)[:2] + except WindowsError: + msg = "Failed to parse file version metadata for: %s" + warnings.warn(msg % pathname) + if not f_ver: + f_ver = p_ver + elif p_ver and p_ver > f_ver: + f_ver = p_ver + found.append( (f_ver, pathname) ) + + # If we found any, use the newest version. + if found: + found.sort() + pathname = found.pop()[1] + + # If we didn't find any, trust the default DLL search algorithm. + else: + pathname = "dbghelp.dll" + + # Load the library. + dbghelp = ctypes.windll.LoadLibrary(pathname) + + # Set it globally as the library to be used. + ctypes.windll.dbghelp = dbghelp + + # Return the library. + return dbghelp + + @staticmethod + def fix_symbol_store_path(symbol_store_path = None, + remote = True, + force = False): + """ + Fix the symbol store path. Equivalent to the C{.symfix} command in + Microsoft WinDbg. + + If the symbol store path environment variable hasn't been set, this + method will provide a default one. + + @type symbol_store_path: str or None + @param symbol_store_path: (Optional) Symbol store path to set. + + @type remote: bool + @param remote: (Optional) Defines the symbol store path to set when the + C{symbol_store_path} is C{None}. + + If C{True} the default symbol store path is set to the Microsoft + symbol server. Debug symbols will be downloaded through HTTP. + This gives the best results but is also quite slow. + + If C{False} the default symbol store path is set to the local + cache only. This prevents debug symbols from being downloaded and + is faster, but unless you've installed the debug symbols on this + machine or downloaded them in a previous debugging session, some + symbols may be missing. + + If the C{symbol_store_path} argument is not C{None}, this argument + is ignored entirely. + + @type force: bool + @param force: (Optional) If C{True} the new symbol store path is set + always. If C{False} the new symbol store path is only set if + missing. + + This allows you to call this method preventively to ensure the + symbol server is always set up correctly when running your script, + but without messing up whatever configuration the user has. + + Example:: + from winappdbg import Debug, System + + def simple_debugger( argv ): + + # Instance a Debug object + debug = Debug( MyEventHandler() ) + try: + + # Make sure the remote symbol store is set + System.fix_symbol_store_path(remote = True, + force = False) + + # Start a new process for debugging + debug.execv( argv ) + + # Wait for the debugee to finish + debug.loop() + + # Stop the debugger + finally: + debug.stop() + + @rtype: str or None + @return: The previously set symbol store path if any, + otherwise returns C{None}. + """ + try: + if symbol_store_path is None: + local_path = "C:\\SYMBOLS" + if not path.isdir(local_path): + local_path = "C:\\Windows\\Symbols" + if not path.isdir(local_path): + local_path = path.abspath(".") + if remote: + symbol_store_path = ( + "cache*;SRV*" + + local_path + + "*" + "http://msdl.microsoft.com/download/symbols" + ) + else: + symbol_store_path = "cache*;SRV*" + local_path + previous = os.environ.get("_NT_SYMBOL_PATH", None) + if not previous or force: + os.environ["_NT_SYMBOL_PATH"] = symbol_store_path + return previous + except Exception: + e = sys.exc_info()[1] + warnings.warn("Cannot fix symbol path, reason: %s" % str(e), + RuntimeWarning) + +#------------------------------------------------------------------------------ + + @staticmethod + def set_kill_on_exit_mode(bKillOnExit = False): + """ + Defines the behavior of the debugged processes when the debugging + thread dies. This method only affects the calling thread. + + Works on the following platforms: + + - Microsoft Windows XP and above. + - Wine (Windows Emulator). + + Fails on the following platforms: + + - Microsoft Windows 2000 and below. + - ReactOS. + + @type bKillOnExit: bool + @param bKillOnExit: C{True} to automatically kill processes when the + debugger thread dies. C{False} to automatically detach from + processes when the debugger thread dies. + + @rtype: bool + @return: C{True} on success, C{False} on error. + + @note: + This call will fail if a debug port was not created. That is, if + the debugger isn't attached to at least one process. For more info + see: U{http://msdn.microsoft.com/en-us/library/ms679307.aspx} + """ + try: + # won't work before calling CreateProcess or DebugActiveProcess + win32.DebugSetProcessKillOnExit(bKillOnExit) + except (AttributeError, WindowsError): + return False + return True + + @staticmethod + def read_msr(address): + """ + Read the contents of the specified MSR (Machine Specific Register). + + @type address: int + @param address: MSR to read. + + @rtype: int + @return: Value of the specified MSR. + + @raise WindowsError: + Raises an exception on error. + + @raise NotImplementedError: + Current architecture is not C{i386} or C{amd64}. + + @warning: + It could potentially brick your machine. + It works on my machine, but your mileage may vary. + """ + if win32.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + raise NotImplementedError( + "MSR reading is only supported on i386 or amd64 processors.") + msr = win32.SYSDBG_MSR() + msr.Address = address + msr.Data = 0 + win32.NtSystemDebugControl(win32.SysDbgReadMsr, + InputBuffer = msr, + OutputBuffer = msr) + return msr.Data + + @staticmethod + def write_msr(address, value): + """ + Set the contents of the specified MSR (Machine Specific Register). + + @type address: int + @param address: MSR to write. + + @type value: int + @param value: Contents to write on the MSR. + + @raise WindowsError: + Raises an exception on error. + + @raise NotImplementedError: + Current architecture is not C{i386} or C{amd64}. + + @warning: + It could potentially brick your machine. + It works on my machine, but your mileage may vary. + """ + if win32.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + raise NotImplementedError( + "MSR writing is only supported on i386 or amd64 processors.") + msr = win32.SYSDBG_MSR() + msr.Address = address + msr.Data = value + win32.NtSystemDebugControl(win32.SysDbgWriteMsr, InputBuffer = msr) + + @classmethod + def enable_step_on_branch_mode(cls): + """ + When tracing, call this on every single step event + for step on branch mode. + + @raise WindowsError: + Raises C{ERROR_DEBUGGER_INACTIVE} if the debugger is not attached + to least one process. + + @raise NotImplementedError: + Current architecture is not C{i386} or C{amd64}. + + @warning: + This method uses the processor's machine specific registers (MSR). + It could potentially brick your machine. + It works on my machine, but your mileage may vary. + + @note: + It doesn't seem to work in VMWare or VirtualBox machines. + Maybe it fails in other virtualization/emulation environments, + no extensive testing was made so far. + """ + cls.write_msr(DebugRegister.DebugCtlMSR, + DebugRegister.BranchTrapFlag | DebugRegister.LastBranchRecord) + + @classmethod + def get_last_branch_location(cls): + """ + Returns the source and destination addresses of the last taken branch. + + @rtype: tuple( int, int ) + @return: Source and destination addresses of the last taken branch. + + @raise WindowsError: + Raises an exception on error. + + @raise NotImplementedError: + Current architecture is not C{i386} or C{amd64}. + + @warning: + This method uses the processor's machine specific registers (MSR). + It could potentially brick your machine. + It works on my machine, but your mileage may vary. + + @note: + It doesn't seem to work in VMWare or VirtualBox machines. + Maybe it fails in other virtualization/emulation environments, + no extensive testing was made so far. + """ + LastBranchFromIP = cls.read_msr(DebugRegister.LastBranchFromIP) + LastBranchToIP = cls.read_msr(DebugRegister.LastBranchToIP) + return ( LastBranchFromIP, LastBranchToIP ) + +#------------------------------------------------------------------------------ + + @classmethod + def get_postmortem_debugger(cls, bits = None): + """ + Returns the postmortem debugging settings from the Registry. + + @see: L{set_postmortem_debugger} + + @type bits: int + @param bits: Set to C{32} for the 32 bits debugger, or C{64} for the + 64 bits debugger. Set to {None} for the default (L{System.bits}. + + @rtype: tuple( str, bool, int ) + @return: A tuple containing the command line string to the postmortem + debugger, a boolean specifying if user interaction is allowed + before attaching, and an integer specifying a user defined hotkey. + Any member of the tuple may be C{None}. + See L{set_postmortem_debugger} for more details. + + @raise WindowsError: + Raises an exception on error. + """ + if bits is None: + bits = cls.bits + elif bits not in (32, 64): + raise NotImplementedError("Unknown architecture (%r bits)" % bits) + + if bits == 32 and cls.bits == 64: + keyname = 'HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug' + else: + keyname = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug' + + key = cls.registry[keyname] + + debugger = key.get('Debugger') + auto = key.get('Auto') + hotkey = key.get('UserDebuggerHotkey') + + if auto is not None: + auto = bool(auto) + + return (debugger, auto, hotkey) + + @classmethod + def get_postmortem_exclusion_list(cls, bits = None): + """ + Returns the exclusion list for the postmortem debugger. + + @see: L{get_postmortem_debugger} + + @type bits: int + @param bits: Set to C{32} for the 32 bits debugger, or C{64} for the + 64 bits debugger. Set to {None} for the default (L{System.bits}). + + @rtype: list( str ) + @return: List of excluded application filenames. + + @raise WindowsError: + Raises an exception on error. + """ + if bits is None: + bits = cls.bits + elif bits not in (32, 64): + raise NotImplementedError("Unknown architecture (%r bits)" % bits) + + if bits == 32 and cls.bits == 64: + keyname = 'HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\AutoExclusionList' + else: + keyname = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\AutoExclusionList' + + try: + key = cls.registry[keyname] + except KeyError: + return [] + + return [name for (name, enabled) in key.items() if enabled] + + @classmethod + def set_postmortem_debugger(cls, cmdline, + auto = None, hotkey = None, bits = None): + """ + Sets the postmortem debugging settings in the Registry. + + @warning: This method requires administrative rights. + + @see: L{get_postmortem_debugger} + + @type cmdline: str + @param cmdline: Command line to the new postmortem debugger. + When the debugger is invoked, the first "%ld" is replaced with the + process ID and the second "%ld" is replaced with the event handle. + Don't forget to enclose the program filename in double quotes if + the path contains spaces. + + @type auto: bool + @param auto: Set to C{True} if no user interaction is allowed, C{False} + to prompt a confirmation dialog before attaching. + Use C{None} to leave this value unchanged. + + @type hotkey: int + @param hotkey: Virtual key scan code for the user defined hotkey. + Use C{0} to disable the hotkey. + Use C{None} to leave this value unchanged. + + @type bits: int + @param bits: Set to C{32} for the 32 bits debugger, or C{64} for the + 64 bits debugger. Set to {None} for the default (L{System.bits}). + + @rtype: tuple( str, bool, int ) + @return: Previously defined command line and auto flag. + + @raise WindowsError: + Raises an exception on error. + """ + if bits is None: + bits = cls.bits + elif bits not in (32, 64): + raise NotImplementedError("Unknown architecture (%r bits)" % bits) + + if bits == 32 and cls.bits == 64: + keyname = 'HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug' + else: + keyname = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug' + + key = cls.registry[keyname] + + if cmdline is not None: + key['Debugger'] = cmdline + if auto is not None: + key['Auto'] = int(bool(auto)) + if hotkey is not None: + key['UserDebuggerHotkey'] = int(hotkey) + + @classmethod + def add_to_postmortem_exclusion_list(cls, pathname, bits = None): + """ + Adds the given filename to the exclusion list for postmortem debugging. + + @warning: This method requires administrative rights. + + @see: L{get_postmortem_exclusion_list} + + @type pathname: str + @param pathname: + Application pathname to exclude from postmortem debugging. + + @type bits: int + @param bits: Set to C{32} for the 32 bits debugger, or C{64} for the + 64 bits debugger. Set to {None} for the default (L{System.bits}). + + @raise WindowsError: + Raises an exception on error. + """ + if bits is None: + bits = cls.bits + elif bits not in (32, 64): + raise NotImplementedError("Unknown architecture (%r bits)" % bits) + + if bits == 32 and cls.bits == 64: + keyname = 'HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\AutoExclusionList' + else: + keyname = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\AutoExclusionList' + + try: + key = cls.registry[keyname] + except KeyError: + key = cls.registry.create(keyname) + + key[pathname] = 1 + + @classmethod + def remove_from_postmortem_exclusion_list(cls, pathname, bits = None): + """ + Removes the given filename to the exclusion list for postmortem + debugging from the Registry. + + @warning: This method requires administrative rights. + + @warning: Don't ever delete entries you haven't created yourself! + Some entries are set by default for your version of Windows. + Deleting them might deadlock your system under some circumstances. + + For more details see: + U{http://msdn.microsoft.com/en-us/library/bb204634(v=vs.85).aspx} + + @see: L{get_postmortem_exclusion_list} + + @type pathname: str + @param pathname: Application pathname to remove from the postmortem + debugging exclusion list. + + @type bits: int + @param bits: Set to C{32} for the 32 bits debugger, or C{64} for the + 64 bits debugger. Set to {None} for the default (L{System.bits}). + + @raise WindowsError: + Raises an exception on error. + """ + if bits is None: + bits = cls.bits + elif bits not in (32, 64): + raise NotImplementedError("Unknown architecture (%r bits)" % bits) + + if bits == 32 and cls.bits == 64: + keyname = 'HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\AutoExclusionList' + else: + keyname = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\\AutoExclusionList' + + try: + key = cls.registry[keyname] + except KeyError: + return + + try: + del key[pathname] + except KeyError: + return + +#------------------------------------------------------------------------------ + + @staticmethod + def get_services(): + """ + Retrieve a list of all system services. + + @see: L{get_active_services}, + L{start_service}, L{stop_service}, + L{pause_service}, L{resume_service} + + @rtype: list( L{win32.ServiceStatusProcessEntry} ) + @return: List of service status descriptors. + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_ENUMERATE_SERVICE + ) as hSCManager: + try: + return win32.EnumServicesStatusEx(hSCManager) + except AttributeError: + return win32.EnumServicesStatus(hSCManager) + + @staticmethod + def get_active_services(): + """ + Retrieve a list of all active system services. + + @see: L{get_services}, + L{start_service}, L{stop_service}, + L{pause_service}, L{resume_service} + + @rtype: list( L{win32.ServiceStatusProcessEntry} ) + @return: List of service status descriptors. + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_ENUMERATE_SERVICE + ) as hSCManager: + return [ entry for entry in win32.EnumServicesStatusEx(hSCManager, + dwServiceType = win32.SERVICE_WIN32, + dwServiceState = win32.SERVICE_ACTIVE) \ + if entry.ProcessId ] + + @staticmethod + def get_service(name): + """ + Get the service descriptor for the given service name. + + @see: L{start_service}, L{stop_service}, + L{pause_service}, L{resume_service} + + @type name: str + @param name: Service unique name. You can get this value from the + C{ServiceName} member of the service descriptors returned by + L{get_services} or L{get_active_services}. + + @rtype: L{win32.ServiceStatusProcess} + @return: Service status descriptor. + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_ENUMERATE_SERVICE + ) as hSCManager: + with win32.OpenService(hSCManager, name, + dwDesiredAccess = win32.SERVICE_QUERY_STATUS + ) as hService: + try: + return win32.QueryServiceStatusEx(hService) + except AttributeError: + return win32.QueryServiceStatus(hService) + + @staticmethod + def get_service_display_name(name): + """ + Get the service display name for the given service name. + + @see: L{get_service} + + @type name: str + @param name: Service unique name. You can get this value from the + C{ServiceName} member of the service descriptors returned by + L{get_services} or L{get_active_services}. + + @rtype: str + @return: Service display name. + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_ENUMERATE_SERVICE + ) as hSCManager: + return win32.GetServiceDisplayName(hSCManager, name) + + @staticmethod + def get_service_from_display_name(displayName): + """ + Get the service unique name given its display name. + + @see: L{get_service} + + @type displayName: str + @param displayName: Service display name. You can get this value from + the C{DisplayName} member of the service descriptors returned by + L{get_services} or L{get_active_services}. + + @rtype: str + @return: Service unique name. + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_ENUMERATE_SERVICE + ) as hSCManager: + return win32.GetServiceKeyName(hSCManager, displayName) + + @staticmethod + def start_service(name, argv = None): + """ + Start the service given by name. + + @warn: This method requires UAC elevation in Windows Vista and above. + + @see: L{stop_service}, L{pause_service}, L{resume_service} + + @type name: str + @param name: Service unique name. You can get this value from the + C{ServiceName} member of the service descriptors returned by + L{get_services} or L{get_active_services}. + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_CONNECT + ) as hSCManager: + with win32.OpenService(hSCManager, name, + dwDesiredAccess = win32.SERVICE_START + ) as hService: + win32.StartService(hService) + + @staticmethod + def stop_service(name): + """ + Stop the service given by name. + + @warn: This method requires UAC elevation in Windows Vista and above. + + @see: L{get_services}, L{get_active_services}, + L{start_service}, L{pause_service}, L{resume_service} + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_CONNECT + ) as hSCManager: + with win32.OpenService(hSCManager, name, + dwDesiredAccess = win32.SERVICE_STOP + ) as hService: + win32.ControlService(hService, win32.SERVICE_CONTROL_STOP) + + @staticmethod + def pause_service(name): + """ + Pause the service given by name. + + @warn: This method requires UAC elevation in Windows Vista and above. + + @note: Not all services support this. + + @see: L{get_services}, L{get_active_services}, + L{start_service}, L{stop_service}, L{resume_service} + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_CONNECT + ) as hSCManager: + with win32.OpenService(hSCManager, name, + dwDesiredAccess = win32.SERVICE_PAUSE_CONTINUE + ) as hService: + win32.ControlService(hService, win32.SERVICE_CONTROL_PAUSE) + + @staticmethod + def resume_service(name): + """ + Resume the service given by name. + + @warn: This method requires UAC elevation in Windows Vista and above. + + @note: Not all services support this. + + @see: L{get_services}, L{get_active_services}, + L{start_service}, L{stop_service}, L{pause_service} + """ + with win32.OpenSCManager( + dwDesiredAccess = win32.SC_MANAGER_CONNECT + ) as hSCManager: + with win32.OpenService(hSCManager, name, + dwDesiredAccess = win32.SERVICE_PAUSE_CONTINUE + ) as hService: + win32.ControlService(hService, win32.SERVICE_CONTROL_CONTINUE) + + # TODO: create_service, delete_service diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/textio.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/textio.py new file mode 100644 index 0000000..402f631 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/textio.py @@ -0,0 +1,1879 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Functions for text input, logging or text output. + +@group Helpers: + HexDump, + HexInput, + HexOutput, + Color, + Table, + Logger + DebugLog + CrashDump +""" + +__revision__ = "$Id$" + +__all__ = [ + 'HexDump', + 'HexInput', + 'HexOutput', + 'Color', + 'Table', + 'CrashDump', + 'DebugLog', + 'Logger', + ] + +import sys +from winappdbg import win32 +from winappdbg import compat +from winappdbg.util import StaticClass + +import re +import time +import struct +import traceback + +#------------------------------------------------------------------------------ + +class HexInput (StaticClass): + """ + Static functions for user input parsing. + The counterparts for each method are in the L{HexOutput} class. + """ + + @staticmethod + def integer(token): + """ + Convert numeric strings into integers. + + @type token: str + @param token: String to parse. + + @rtype: int + @return: Parsed integer value. + """ + token = token.strip() + neg = False + if token.startswith(compat.b('-')): + token = token[1:] + neg = True + if token.startswith(compat.b('0x')): + result = int(token, 16) # hexadecimal + elif token.startswith(compat.b('0b')): + result = int(token[2:], 2) # binary + elif token.startswith(compat.b('0o')): + result = int(token, 8) # octal + else: + try: + result = int(token) # decimal + except ValueError: + result = int(token, 16) # hexadecimal (no "0x" prefix) + if neg: + result = -result + return result + + @staticmethod + def address(token): + """ + Convert numeric strings into memory addresses. + + @type token: str + @param token: String to parse. + + @rtype: int + @return: Parsed integer value. + """ + return int(token, 16) + + @staticmethod + def hexadecimal(token): + """ + Convert a strip of hexadecimal numbers into binary data. + + @type token: str + @param token: String to parse. + + @rtype: str + @return: Parsed string value. + """ + token = ''.join([ c for c in token if c.isalnum() ]) + if len(token) % 2 != 0: + raise ValueError("Missing characters in hex data") + data = '' + for i in compat.xrange(0, len(token), 2): + x = token[i:i+2] + d = int(x, 16) + s = struct.pack('= 0: + return ('0x%%.%dx' % (integer_size - 2)) % integer + return ('-0x%%.%dx' % (integer_size - 2)) % -integer + + @classmethod + def address(cls, address, bits = None): + """ + @type address: int + @param address: Memory address. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexOutput.address_size} + + @rtype: str + @return: Text output. + """ + if bits is None: + address_size = cls.address_size + bits = win32.bits + else: + address_size = (bits / 4) + 2 + if address < 0: + address = ((2 ** bits) - 1) ^ ~address + return ('0x%%.%dx' % (address_size - 2)) % address + + @staticmethod + def hexadecimal(data): + """ + Convert binary data to a string of hexadecimal numbers. + + @type data: str + @param data: Binary data. + + @rtype: str + @return: Hexadecimal representation. + """ + return HexDump.hexadecimal(data, separator = '') + + @classmethod + def integer_list_file(cls, filename, values, bits = None): + """ + Write a list of integers to a file. + If a file of the same name exists, it's contents are replaced. + + See L{HexInput.integer_list_file} for a description of the file format. + + @type filename: str + @param filename: Name of the file to write. + + @type values: list( int ) + @param values: List of integers to write to the file. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexOutput.integer_size} + """ + fd = open(filename, 'w') + for integer in values: + print >> fd, cls.integer(integer, bits) + fd.close() + + @classmethod + def string_list_file(cls, filename, values): + """ + Write a list of strings to a file. + If a file of the same name exists, it's contents are replaced. + + See L{HexInput.string_list_file} for a description of the file format. + + @type filename: str + @param filename: Name of the file to write. + + @type values: list( int ) + @param values: List of strings to write to the file. + """ + fd = open(filename, 'w') + for string in values: + print >> fd, string + fd.close() + + @classmethod + def mixed_list_file(cls, filename, values, bits): + """ + Write a list of mixed values to a file. + If a file of the same name exists, it's contents are replaced. + + See L{HexInput.mixed_list_file} for a description of the file format. + + @type filename: str + @param filename: Name of the file to write. + + @type values: list( int ) + @param values: List of mixed values to write to the file. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexOutput.integer_size} + """ + fd = open(filename, 'w') + for original in values: + try: + parsed = cls.integer(original, bits) + except TypeError: + parsed = repr(original) + print >> fd, parsed + fd.close() + +#------------------------------------------------------------------------------ + +class HexDump (StaticClass): + """ + Static functions for hexadecimal dumps. + + @type integer_size: int + @cvar integer_size: Size in characters of an outputted integer. + This value is platform dependent. + + @type address_size: int + @cvar address_size: Size in characters of an outputted address. + This value is platform dependent. + """ + + integer_size = (win32.SIZEOF(win32.DWORD) * 2) + address_size = (win32.SIZEOF(win32.SIZE_T) * 2) + + @classmethod + def integer(cls, integer, bits = None): + """ + @type integer: int + @param integer: Integer. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.integer_size} + + @rtype: str + @return: Text output. + """ + if bits is None: + integer_size = cls.integer_size + else: + integer_size = bits / 4 + return ('%%.%dX' % integer_size) % integer + + @classmethod + def address(cls, address, bits = None): + """ + @type address: int + @param address: Memory address. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text output. + """ + if bits is None: + address_size = cls.address_size + bits = win32.bits + else: + address_size = bits / 4 + if address < 0: + address = ((2 ** bits) - 1) ^ ~address + return ('%%.%dX' % address_size) % address + + @staticmethod + def printable(data): + """ + Replace unprintable characters with dots. + + @type data: str + @param data: Binary data. + + @rtype: str + @return: Printable text. + """ + result = '' + for c in data: + if 32 < ord(c) < 128: + result += c + else: + result += '.' + return result + + @staticmethod + def hexadecimal(data, separator = ''): + """ + Convert binary data to a string of hexadecimal numbers. + + @type data: str + @param data: Binary data. + + @type separator: str + @param separator: + Separator between the hexadecimal representation of each character. + + @rtype: str + @return: Hexadecimal representation. + """ + return separator.join( [ '%.2x' % ord(c) for c in data ] ) + + @staticmethod + def hexa_word(data, separator = ' '): + """ + Convert binary data to a string of hexadecimal WORDs. + + @type data: str + @param data: Binary data. + + @type separator: str + @param separator: + Separator between the hexadecimal representation of each WORD. + + @rtype: str + @return: Hexadecimal representation. + """ + if len(data) & 1 != 0: + data += '\0' + return separator.join( [ '%.4x' % struct.unpack(' 0: + width.extend( len_row[ -missing : ] ) + elif missing < 0: + len_row.extend( [0] * (-missing) ) + self.__width = [ max( width[i], len_row[i] ) for i in compat.xrange(len(len_row)) ] + self.__cols.append(row) + + def justify(self, column, direction): + """ + Make the text in a column left or right justified. + + @type column: int + @param column: Index of the column. + + @type direction: int + @param direction: + C{-1} to justify left, + C{1} to justify right. + + @raise IndexError: Bad column index. + @raise ValueError: Bad direction value. + """ + if direction == -1: + self.__width[column] = abs(self.__width[column]) + elif direction == 1: + self.__width[column] = - abs(self.__width[column]) + else: + raise ValueError("Bad direction value.") + + def getWidth(self): + """ + Get the width of the text output for the table. + + @rtype: int + @return: Width in characters for the text output, + including the newline character. + """ + width = 0 + if self.__width: + width = sum( abs(x) for x in self.__width ) + width = width + len(self.__width) * len(self.__sep) + 1 + return width + + def getOutput(self): + """ + Get the text output for the table. + + @rtype: str + @return: Text output. + """ + return '%s\n' % '\n'.join( self.yieldOutput() ) + + def yieldOutput(self): + """ + Generate the text output for the table. + + @rtype: generator of str + @return: Text output. + """ + width = self.__width + if width: + num_cols = len(width) + fmt = ['%%%ds' % -w for w in width] + if width[-1] > 0: + fmt[-1] = '%s' + fmt = self.__sep.join(fmt) + for row in self.__cols: + row.extend( [''] * (num_cols - len(row)) ) + yield fmt % tuple(row) + + def show(self): + """ + Print the text output for the table. + """ + print(self.getOutput()) + +#------------------------------------------------------------------------------ + +class CrashDump (StaticClass): + """ + Static functions for crash dumps. + + @type reg_template: str + @cvar reg_template: Template for the L{dump_registers} method. + """ + + # Templates for the dump_registers method. + reg_template = { + win32.ARCH_I386 : ( + 'eax=%(Eax).8x ebx=%(Ebx).8x ecx=%(Ecx).8x edx=%(Edx).8x esi=%(Esi).8x edi=%(Edi).8x\n' + 'eip=%(Eip).8x esp=%(Esp).8x ebp=%(Ebp).8x %(efl_dump)s\n' + 'cs=%(SegCs).4x ss=%(SegSs).4x ds=%(SegDs).4x es=%(SegEs).4x fs=%(SegFs).4x gs=%(SegGs).4x efl=%(EFlags).8x\n' + ), + win32.ARCH_AMD64 : ( + 'rax=%(Rax).16x rbx=%(Rbx).16x rcx=%(Rcx).16x\n' + 'rdx=%(Rdx).16x rsi=%(Rsi).16x rdi=%(Rdi).16x\n' + 'rip=%(Rip).16x rsp=%(Rsp).16x rbp=%(Rbp).16x\n' + ' r8=%(R8).16x r9=%(R9).16x r10=%(R10).16x\n' + 'r11=%(R11).16x r12=%(R12).16x r13=%(R13).16x\n' + 'r14=%(R14).16x r15=%(R15).16x\n' + '%(efl_dump)s\n' + 'cs=%(SegCs).4x ss=%(SegSs).4x ds=%(SegDs).4x es=%(SegEs).4x fs=%(SegFs).4x gs=%(SegGs).4x efl=%(EFlags).8x\n' + ), + } + + @staticmethod + def dump_flags(efl): + """ + Dump the x86 processor flags. + The output mimics that of the WinDBG debugger. + Used by L{dump_registers}. + + @type efl: int + @param efl: Value of the eFlags register. + + @rtype: str + @return: Text suitable for logging. + """ + if efl is None: + return '' + efl_dump = 'iopl=%1d' % ((efl & 0x3000) >> 12) + if efl & 0x100000: + efl_dump += ' vip' + else: + efl_dump += ' ' + if efl & 0x80000: + efl_dump += ' vif' + else: + efl_dump += ' ' + # 0x20000 ??? + if efl & 0x800: + efl_dump += ' ov' # Overflow + else: + efl_dump += ' no' # No overflow + if efl & 0x400: + efl_dump += ' dn' # Downwards + else: + efl_dump += ' up' # Upwards + if efl & 0x200: + efl_dump += ' ei' # Enable interrupts + else: + efl_dump += ' di' # Disable interrupts + # 0x100 trap flag + if efl & 0x80: + efl_dump += ' ng' # Negative + else: + efl_dump += ' pl' # Positive + if efl & 0x40: + efl_dump += ' zr' # Zero + else: + efl_dump += ' nz' # Nonzero + if efl & 0x10: + efl_dump += ' ac' # Auxiliary carry + else: + efl_dump += ' na' # No auxiliary carry + # 0x8 ??? + if efl & 0x4: + efl_dump += ' pe' # Parity odd + else: + efl_dump += ' po' # Parity even + # 0x2 ??? + if efl & 0x1: + efl_dump += ' cy' # Carry + else: + efl_dump += ' nc' # No carry + return efl_dump + + @classmethod + def dump_registers(cls, registers, arch = None): + """ + Dump the x86/x64 processor register values. + The output mimics that of the WinDBG debugger. + + @type registers: dict( str S{->} int ) + @param registers: Dictionary mapping register names to their values. + + @type arch: str + @param arch: Architecture of the machine whose registers were dumped. + Defaults to the current architecture. + Currently only the following architectures are supported: + - L{win32.ARCH_I386} + - L{win32.ARCH_AMD64} + + @rtype: str + @return: Text suitable for logging. + """ + if registers is None: + return '' + if arch is None: + if 'Eax' in registers: + arch = win32.ARCH_I386 + elif 'Rax' in registers: + arch = win32.ARCH_AMD64 + else: + arch = 'Unknown' + if arch not in cls.reg_template: + msg = "Don't know how to dump the registers for architecture: %s" + raise NotImplementedError(msg % arch) + registers = registers.copy() + registers['efl_dump'] = cls.dump_flags( registers['EFlags'] ) + return cls.reg_template[arch] % registers + + @staticmethod + def dump_registers_peek(registers, data, separator = ' ', width = 16): + """ + Dump data pointed to by the given registers, if any. + + @type registers: dict( str S{->} int ) + @param registers: Dictionary mapping register names to their values. + This value is returned by L{Thread.get_context}. + + @type data: dict( str S{->} str ) + @param data: Dictionary mapping register names to the data they point to. + This value is returned by L{Thread.peek_pointers_in_registers}. + + @rtype: str + @return: Text suitable for logging. + """ + if None in (registers, data): + return '' + names = compat.keys(data) + names.sort() + result = '' + for reg_name in names: + tag = reg_name.lower() + dumped = HexDump.hexline(data[reg_name], separator, width) + result += '%s -> %s\n' % (tag, dumped) + return result + + @staticmethod + def dump_data_peek(data, base = 0, + separator = ' ', + width = 16, + bits = None): + """ + Dump data from pointers guessed within the given binary data. + + @type data: str + @param data: Dictionary mapping offsets to the data they point to. + + @type base: int + @param base: Base offset. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text suitable for logging. + """ + if data is None: + return '' + pointers = compat.keys(data) + pointers.sort() + result = '' + for offset in pointers: + dumped = HexDump.hexline(data[offset], separator, width) + address = HexDump.address(base + offset, bits) + result += '%s -> %s\n' % (address, dumped) + return result + + @staticmethod + def dump_stack_peek(data, separator = ' ', width = 16, arch = None): + """ + Dump data from pointers guessed within the given stack dump. + + @type data: str + @param data: Dictionary mapping stack offsets to the data they point to. + + @type separator: str + @param separator: + Separator between the hexadecimal representation of each character. + + @type width: int + @param width: + (Optional) Maximum number of characters to convert per text line. + This value is also used for padding. + + @type arch: str + @param arch: Architecture of the machine whose registers were dumped. + Defaults to the current architecture. + + @rtype: str + @return: Text suitable for logging. + """ + if data is None: + return '' + if arch is None: + arch = win32.arch + pointers = compat.keys(data) + pointers.sort() + result = '' + if pointers: + if arch == win32.ARCH_I386: + spreg = 'esp' + elif arch == win32.ARCH_AMD64: + spreg = 'rsp' + else: + spreg = 'STACK' # just a generic tag + tag_fmt = '[%s+0x%%.%dx]' % (spreg, len( '%x' % pointers[-1] ) ) + for offset in pointers: + dumped = HexDump.hexline(data[offset], separator, width) + tag = tag_fmt % offset + result += '%s -> %s\n' % (tag, dumped) + return result + + @staticmethod + def dump_stack_trace(stack_trace, bits = None): + """ + Dump a stack trace, as returned by L{Thread.get_stack_trace} with the + C{bUseLabels} parameter set to C{False}. + + @type stack_trace: list( int, int, str ) + @param stack_trace: Stack trace as a list of tuples of + ( return address, frame pointer, module filename ) + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text suitable for logging. + """ + if not stack_trace: + return '' + table = Table() + table.addRow('Frame', 'Origin', 'Module') + for (fp, ra, mod) in stack_trace: + fp_d = HexDump.address(fp, bits) + ra_d = HexDump.address(ra, bits) + table.addRow(fp_d, ra_d, mod) + return table.getOutput() + + @staticmethod + def dump_stack_trace_with_labels(stack_trace, bits = None): + """ + Dump a stack trace, + as returned by L{Thread.get_stack_trace_with_labels}. + + @type stack_trace: list( int, int, str ) + @param stack_trace: Stack trace as a list of tuples of + ( return address, frame pointer, module filename ) + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text suitable for logging. + """ + if not stack_trace: + return '' + table = Table() + table.addRow('Frame', 'Origin') + for (fp, label) in stack_trace: + table.addRow( HexDump.address(fp, bits), label ) + return table.getOutput() + + # TODO + # + Instead of a star when EIP points to, it would be better to show + # any register value (or other values like the exception address) that + # points to a location in the dissassembled code. + # + It'd be very useful to show some labels here. + # + It'd be very useful to show register contents for code at EIP + @staticmethod + def dump_code(disassembly, pc = None, + bLowercase = True, + bits = None): + """ + Dump a disassembly. Optionally mark where the program counter is. + + @type disassembly: list of tuple( int, int, str, str ) + @param disassembly: Disassembly dump as returned by + L{Process.disassemble} or L{Thread.disassemble_around_pc}. + + @type pc: int + @param pc: (Optional) Program counter. + + @type bLowercase: bool + @param bLowercase: (Optional) If C{True} convert the code to lowercase. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text suitable for logging. + """ + if not disassembly: + return '' + table = Table(sep = ' | ') + for (addr, size, code, dump) in disassembly: + if bLowercase: + code = code.lower() + if addr == pc: + addr = ' * %s' % HexDump.address(addr, bits) + else: + addr = ' %s' % HexDump.address(addr, bits) + table.addRow(addr, dump, code) + table.justify(1, 1) + return table.getOutput() + + @staticmethod + def dump_code_line(disassembly_line, bShowAddress = True, + bShowDump = True, + bLowercase = True, + dwDumpWidth = None, + dwCodeWidth = None, + bits = None): + """ + Dump a single line of code. To dump a block of code use L{dump_code}. + + @type disassembly_line: tuple( int, int, str, str ) + @param disassembly_line: Single item of the list returned by + L{Process.disassemble} or L{Thread.disassemble_around_pc}. + + @type bShowAddress: bool + @param bShowAddress: (Optional) If C{True} show the memory address. + + @type bShowDump: bool + @param bShowDump: (Optional) If C{True} show the hexadecimal dump. + + @type bLowercase: bool + @param bLowercase: (Optional) If C{True} convert the code to lowercase. + + @type dwDumpWidth: int or None + @param dwDumpWidth: (Optional) Width in characters of the hex dump. + + @type dwCodeWidth: int or None + @param dwCodeWidth: (Optional) Width in characters of the code. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text suitable for logging. + """ + if bits is None: + address_size = HexDump.address_size + else: + address_size = bits / 4 + (addr, size, code, dump) = disassembly_line + dump = dump.replace(' ', '') + result = list() + fmt = '' + if bShowAddress: + result.append( HexDump.address(addr, bits) ) + fmt += '%%%ds:' % address_size + if bShowDump: + result.append(dump) + if dwDumpWidth: + fmt += ' %%-%ds' % dwDumpWidth + else: + fmt += ' %s' + if bLowercase: + code = code.lower() + result.append(code) + if dwCodeWidth: + fmt += ' %%-%ds' % dwCodeWidth + else: + fmt += ' %s' + return fmt % tuple(result) + + @staticmethod + def dump_memory_map(memoryMap, mappedFilenames = None, bits = None): + """ + Dump the memory map of a process. Optionally show the filenames for + memory mapped files as well. + + @type memoryMap: list( L{win32.MemoryBasicInformation} ) + @param memoryMap: Memory map returned by L{Process.get_memory_map}. + + @type mappedFilenames: dict( int S{->} str ) + @param mappedFilenames: (Optional) Memory mapped filenames + returned by L{Process.get_mapped_filenames}. + + @type bits: int + @param bits: + (Optional) Number of bits of the target architecture. + The default is platform dependent. See: L{HexDump.address_size} + + @rtype: str + @return: Text suitable for logging. + """ + if not memoryMap: + return '' + + table = Table() + if mappedFilenames: + table.addRow("Address", "Size", "State", "Access", "Type", "File") + else: + table.addRow("Address", "Size", "State", "Access", "Type") + + # For each memory block in the map... + for mbi in memoryMap: + + # Address and size of memory block. + BaseAddress = HexDump.address(mbi.BaseAddress, bits) + RegionSize = HexDump.address(mbi.RegionSize, bits) + + # State (free or allocated). + mbiState = mbi.State + if mbiState == win32.MEM_RESERVE: + State = "Reserved" + elif mbiState == win32.MEM_COMMIT: + State = "Commited" + elif mbiState == win32.MEM_FREE: + State = "Free" + else: + State = "Unknown" + + # Page protection bits (R/W/X/G). + if mbiState != win32.MEM_COMMIT: + Protect = "" + else: + mbiProtect = mbi.Protect + if mbiProtect & win32.PAGE_NOACCESS: + Protect = "--- " + elif mbiProtect & win32.PAGE_READONLY: + Protect = "R-- " + elif mbiProtect & win32.PAGE_READWRITE: + Protect = "RW- " + elif mbiProtect & win32.PAGE_WRITECOPY: + Protect = "RC- " + elif mbiProtect & win32.PAGE_EXECUTE: + Protect = "--X " + elif mbiProtect & win32.PAGE_EXECUTE_READ: + Protect = "R-X " + elif mbiProtect & win32.PAGE_EXECUTE_READWRITE: + Protect = "RWX " + elif mbiProtect & win32.PAGE_EXECUTE_WRITECOPY: + Protect = "RCX " + else: + Protect = "??? " + if mbiProtect & win32.PAGE_GUARD: + Protect += "G" + else: + Protect += "-" + if mbiProtect & win32.PAGE_NOCACHE: + Protect += "N" + else: + Protect += "-" + if mbiProtect & win32.PAGE_WRITECOMBINE: + Protect += "W" + else: + Protect += "-" + + # Type (file mapping, executable image, or private memory). + mbiType = mbi.Type + if mbiType == win32.MEM_IMAGE: + Type = "Image" + elif mbiType == win32.MEM_MAPPED: + Type = "Mapped" + elif mbiType == win32.MEM_PRIVATE: + Type = "Private" + elif mbiType == 0: + Type = "" + else: + Type = "Unknown" + + # Output a row in the table. + if mappedFilenames: + FileName = mappedFilenames.get(mbi.BaseAddress, '') + table.addRow( BaseAddress, RegionSize, State, Protect, Type, FileName ) + else: + table.addRow( BaseAddress, RegionSize, State, Protect, Type ) + + # Return the table output. + return table.getOutput() + +#------------------------------------------------------------------------------ + +class DebugLog (StaticClass): + 'Static functions for debug logging.' + + @staticmethod + def log_text(text): + """ + Log lines of text, inserting a timestamp. + + @type text: str + @param text: Text to log. + + @rtype: str + @return: Log line. + """ + if text.endswith('\n'): + text = text[:-len('\n')] + #text = text.replace('\n', '\n\t\t') # text CSV + ltime = time.strftime("%X") + msecs = (time.time() % 1) * 1000 + return '[%s.%04d] %s' % (ltime, msecs, text) + #return '[%s.%04d]\t%s' % (ltime, msecs, text) # text CSV + + @classmethod + def log_event(cls, event, text = None): + """ + Log lines of text associated with a debug event. + + @type event: L{Event} + @param event: Event object. + + @type text: str + @param text: (Optional) Text to log. If no text is provided the default + is to show a description of the event itself. + + @rtype: str + @return: Log line. + """ + if not text: + if event.get_event_code() == win32.EXCEPTION_DEBUG_EVENT: + what = event.get_exception_description() + if event.is_first_chance(): + what = '%s (first chance)' % what + else: + what = '%s (second chance)' % what + try: + address = event.get_fault_address() + except NotImplementedError: + address = event.get_exception_address() + else: + what = event.get_event_name() + address = event.get_thread().get_pc() + process = event.get_process() + label = process.get_label_at_address(address) + address = HexDump.address(address, process.get_bits()) + if label: + where = '%s (%s)' % (address, label) + else: + where = address + text = '%s at %s' % (what, where) + text = 'pid %d tid %d: %s' % (event.get_pid(), event.get_tid(), text) + #text = 'pid %d tid %d:\t%s' % (event.get_pid(), event.get_tid(), text) # text CSV + return cls.log_text(text) + +#------------------------------------------------------------------------------ + +class Logger(object): + """ + Logs text to standard output and/or a text file. + + @type logfile: str or None + @ivar logfile: Append messages to this text file. + + @type verbose: bool + @ivar verbose: C{True} to print messages to standard output. + + @type fd: file + @ivar fd: File object where log messages are printed to. + C{None} if no log file is used. + """ + + def __init__(self, logfile = None, verbose = True): + """ + @type logfile: str or None + @param logfile: Append messages to this text file. + + @type verbose: bool + @param verbose: C{True} to print messages to standard output. + """ + self.verbose = verbose + self.logfile = logfile + if self.logfile: + self.fd = open(self.logfile, 'a+') + + def __logfile_error(self, e): + """ + Shows an error message to standard error + if the log file can't be written to. + + Used internally. + + @type e: Exception + @param e: Exception raised when trying to write to the log file. + """ + from sys import stderr + msg = "Warning, error writing log file %s: %s\n" + msg = msg % (self.logfile, str(e)) + stderr.write(DebugLog.log_text(msg)) + self.logfile = None + self.fd = None + + def __do_log(self, text): + """ + Writes the given text verbatim into the log file (if any) + and/or standard input (if the verbose flag is turned on). + + Used internally. + + @type text: str + @param text: Text to print. + """ + if isinstance(text, compat.unicode): + text = text.encode('cp1252') + if self.verbose: + print(text) + if self.logfile: + try: + self.fd.writelines('%s\n' % text) + except IOError: + e = sys.exc_info()[1] + self.__logfile_error(e) + + def log_text(self, text): + """ + Log lines of text, inserting a timestamp. + + @type text: str + @param text: Text to log. + """ + self.__do_log( DebugLog.log_text(text) ) + + def log_event(self, event, text = None): + """ + Log lines of text associated with a debug event. + + @type event: L{Event} + @param event: Event object. + + @type text: str + @param text: (Optional) Text to log. If no text is provided the default + is to show a description of the event itself. + """ + self.__do_log( DebugLog.log_event(event, text) ) + + def log_exc(self): + """ + Log lines of text associated with the last Python exception. + """ + self.__do_log( 'Exception raised: %s' % traceback.format_exc() ) + + def is_enabled(self): + """ + Determines if the logger will actually print anything when the log_* + methods are called. + + This may save some processing if the log text requires a lengthy + calculation to prepare. If no log file is set and stdout logging + is disabled, there's no point in preparing a log text that won't + be shown to anyone. + + @rtype: bool + @return: C{True} if a log file was set and/or standard output logging + is enabled, or C{False} otherwise. + """ + return self.verbose or self.logfile diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/thread.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/thread.py new file mode 100644 index 0000000..9307c42 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/thread.py @@ -0,0 +1,2127 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Thread instrumentation. + +@group Instrumentation: + Thread +""" + +from __future__ import with_statement + +__revision__ = "$Id$" + +__all__ = ['Thread'] + +from winappdbg import win32 +from winappdbg import compat +from winappdbg.textio import HexDump +from winappdbg.util import DebugRegister +from winappdbg.window import Window + +import sys +import struct +import warnings + +# delayed imports +Process = None + +#============================================================================== + +# TODO +# + fetch special registers (MMX, XMM, 3DNow!, etc) + +class Thread (object): + """ + Interface to a thread in another process. + + @group Properties: + get_tid, get_pid, get_process, set_process, get_exit_code, is_alive, + get_name, set_name, get_windows, get_teb, get_teb_address, is_wow64, + get_arch, get_bits, get_handle, open_handle, close_handle + + @group Instrumentation: + suspend, resume, kill, wait + + @group Debugging: + get_seh_chain_pointer, set_seh_chain_pointer, + get_seh_chain, get_wait_chain, is_hidden + + @group Disassembly: + disassemble, disassemble_around, disassemble_around_pc, + disassemble_string, disassemble_instruction, disassemble_current + + @group Stack: + get_stack_frame, get_stack_frame_range, get_stack_range, + get_stack_trace, get_stack_trace_with_labels, + read_stack_data, read_stack_dwords, read_stack_qwords, + peek_stack_data, peek_stack_dwords, peek_stack_qwords, + read_stack_structure, read_stack_frame + + @group Registers: + get_context, + get_register, + get_flags, get_flag_value, + get_pc, get_sp, get_fp, + get_cf, get_df, get_sf, get_tf, get_zf, + set_context, + set_register, + set_flags, set_flag_value, + set_pc, set_sp, set_fp, + set_cf, set_df, set_sf, set_tf, set_zf, + clear_cf, clear_df, clear_sf, clear_tf, clear_zf, + Flags + + @group Threads snapshot: + clear + + @group Miscellaneous: + read_code_bytes, peek_code_bytes, + peek_pointers_in_data, peek_pointers_in_registers, + get_linear_address, get_label_at_pc + + @type dwThreadId: int + @ivar dwThreadId: Global thread ID. Use L{get_tid} instead. + + @type hThread: L{ThreadHandle} + @ivar hThread: Handle to the thread. Use L{get_handle} instead. + + @type process: L{Process} + @ivar process: Parent process object. Use L{get_process} instead. + + @type pInjectedMemory: int + @ivar pInjectedMemory: If the thread was created by L{Process.inject_code}, + this member contains a pointer to the memory buffer for the injected + code. Otherwise it's C{None}. + + The L{kill} method uses this member to free the buffer + when the injected thread is killed. + """ + + def __init__(self, dwThreadId, hThread = None, process = None): + """ + @type dwThreadId: int + @param dwThreadId: Global thread ID. + + @type hThread: L{ThreadHandle} + @param hThread: (Optional) Handle to the thread. + + @type process: L{Process} + @param process: (Optional) Parent Process object. + """ + self.dwProcessId = None + self.dwThreadId = dwThreadId + self.hThread = hThread + self.pInjectedMemory = None + self.set_name(None) + self.set_process(process) + + # Not really sure if it's a good idea... +## def __eq__(self, aThread): +## """ +## Compare two Thread objects. The comparison is made using the IDs. +## +## @warning: +## If you have two Thread instances with different handles the +## equality operator still returns C{True}, so be careful! +## +## @type aThread: L{Thread} +## @param aThread: Another Thread object. +## +## @rtype: bool +## @return: C{True} if the two thread IDs are equal, +## C{False} otherwise. +## """ +## return isinstance(aThread, Thread) and \ +## self.get_tid() == aThread.get_tid() + + def __load_Process_class(self): + global Process # delayed import + if Process is None: + from winappdbg.process import Process + + def get_process(self): + """ + @rtype: L{Process} + @return: Parent Process object. + Returns C{None} if unknown. + """ + if self.__process is not None: + return self.__process + self.__load_Process_class() + self.__process = Process(self.get_pid()) + return self.__process + + def set_process(self, process = None): + """ + Manually set the parent Process object. Use with care! + + @type process: L{Process} + @param process: (Optional) Process object. Use C{None} for no process. + """ + if process is None: + self.dwProcessId = None + self.__process = None + else: + self.__load_Process_class() + if not isinstance(process, Process): + msg = "Parent process must be a Process instance, " + msg += "got %s instead" % type(process) + raise TypeError(msg) + self.dwProcessId = process.get_pid() + self.__process = process + + process = property(get_process, set_process, doc="") + + def get_pid(self): + """ + @rtype: int + @return: Parent process global ID. + + @raise WindowsError: An error occured when calling a Win32 API function. + @raise RuntimeError: The parent process ID can't be found. + """ + if self.dwProcessId is None: + if self.__process is not None: + # Infinite loop if self.__process is None + self.dwProcessId = self.get_process().get_pid() + else: + try: + # I wish this had been implemented before Vista... + # XXX TODO find the real ntdll call under this api + hThread = self.get_handle( + win32.THREAD_QUERY_LIMITED_INFORMATION) + self.dwProcessId = win32.GetProcessIdOfThread(hThread) + except AttributeError: + # This method really sucks :P + self.dwProcessId = self.__get_pid_by_scanning() + return self.dwProcessId + + def __get_pid_by_scanning(self): + 'Internally used by get_pid().' + dwProcessId = None + dwThreadId = self.get_tid() + with win32.CreateToolhelp32Snapshot(win32.TH32CS_SNAPTHREAD) as hSnapshot: + te = win32.Thread32First(hSnapshot) + while te is not None: + if te.th32ThreadID == dwThreadId: + dwProcessId = te.th32OwnerProcessID + break + te = win32.Thread32Next(hSnapshot) + if dwProcessId is None: + msg = "Cannot find thread ID %d in any process" % dwThreadId + raise RuntimeError(msg) + return dwProcessId + + def get_tid(self): + """ + @rtype: int + @return: Thread global ID. + """ + return self.dwThreadId + + def get_name(self): + """ + @rtype: str + @return: Thread name, or C{None} if the thread is nameless. + """ + return self.name + + def set_name(self, name = None): + """ + Sets the thread's name. + + @type name: str + @param name: Thread name, or C{None} if the thread is nameless. + """ + self.name = name + +#------------------------------------------------------------------------------ + + def open_handle(self, dwDesiredAccess = win32.THREAD_ALL_ACCESS): + """ + Opens a new handle to the thread, closing the previous one. + + The new handle is stored in the L{hThread} property. + + @warn: Normally you should call L{get_handle} instead, since it's much + "smarter" and tries to reuse handles and merge access rights. + + @type dwDesiredAccess: int + @param dwDesiredAccess: Desired access rights. + Defaults to L{win32.THREAD_ALL_ACCESS}. + See: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms686769(v=vs.85).aspx} + + @raise WindowsError: It's not possible to open a handle to the thread + with the requested access rights. This tipically happens because + the target thread belongs to system process and the debugger is not + runnning with administrative rights. + """ + hThread = win32.OpenThread(dwDesiredAccess, win32.FALSE, self.dwThreadId) + + # In case hThread was set to an actual handle value instead of a Handle + # object. This shouldn't happen unless the user tinkered with it. + if not hasattr(self.hThread, '__del__'): + self.close_handle() + + self.hThread = hThread + + def close_handle(self): + """ + Closes the handle to the thread. + + @note: Normally you don't need to call this method. All handles + created by I{WinAppDbg} are automatically closed when the garbage + collector claims them. + """ + try: + if hasattr(self.hThread, 'close'): + self.hThread.close() + elif self.hThread not in (None, win32.INVALID_HANDLE_VALUE): + win32.CloseHandle(self.hThread) + finally: + self.hThread = None + + def get_handle(self, dwDesiredAccess = win32.THREAD_ALL_ACCESS): + """ + Returns a handle to the thread with I{at least} the access rights + requested. + + @note: + If a handle was previously opened and has the required access + rights, it's reused. If not, a new handle is opened with the + combination of the old and new access rights. + + @type dwDesiredAccess: int + @param dwDesiredAccess: Desired access rights. + See: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms686769(v=vs.85).aspx} + + @rtype: ThreadHandle + @return: Handle to the thread. + + @raise WindowsError: It's not possible to open a handle to the thread + with the requested access rights. This tipically happens because + the target thread belongs to system process and the debugger is not + runnning with administrative rights. + """ + if self.hThread in (None, win32.INVALID_HANDLE_VALUE): + self.open_handle(dwDesiredAccess) + else: + dwAccess = self.hThread.dwAccess + if (dwAccess | dwDesiredAccess) != dwAccess: + self.open_handle(dwAccess | dwDesiredAccess) + return self.hThread + + def clear(self): + """ + Clears the resources held by this object. + """ + try: + self.set_process(None) + finally: + self.close_handle() + +#------------------------------------------------------------------------------ + + def wait(self, dwTimeout = None): + """ + Waits for the thread to finish executing. + + @type dwTimeout: int + @param dwTimeout: (Optional) Timeout value in milliseconds. + Use C{INFINITE} or C{None} for no timeout. + """ + self.get_handle(win32.SYNCHRONIZE).wait(dwTimeout) + + def kill(self, dwExitCode = 0): + """ + Terminates the thread execution. + + @note: If the C{lpInjectedMemory} member contains a valid pointer, + the memory is freed. + + @type dwExitCode: int + @param dwExitCode: (Optional) Thread exit code. + """ + hThread = self.get_handle(win32.THREAD_TERMINATE) + win32.TerminateThread(hThread, dwExitCode) + + # Ugliest hack ever, won't work if many pieces of code are injected. + # Seriously, what was I thinking? Lame! :( + if self.pInjectedMemory is not None: + try: + self.get_process().free(self.pInjectedMemory) + self.pInjectedMemory = None + except Exception: +## raise # XXX DEBUG + pass + + # XXX TODO + # suspend() and resume() should have a counter of how many times a thread + # was suspended, so on debugger exit they could (optionally!) be restored + + def suspend(self): + """ + Suspends the thread execution. + + @rtype: int + @return: Suspend count. If zero, the thread is running. + """ + hThread = self.get_handle(win32.THREAD_SUSPEND_RESUME) + if self.is_wow64(): + # FIXME this will be horribly slow on XP 64 + # since it'll try to resolve a missing API every time + try: + return win32.Wow64SuspendThread(hThread) + except AttributeError: + pass + return win32.SuspendThread(hThread) + + def resume(self): + """ + Resumes the thread execution. + + @rtype: int + @return: Suspend count. If zero, the thread is running. + """ + hThread = self.get_handle(win32.THREAD_SUSPEND_RESUME) + return win32.ResumeThread(hThread) + + def is_alive(self): + """ + @rtype: bool + @return: C{True} if the thread if currently running. + @raise WindowsError: + The debugger doesn't have enough privileges to perform this action. + """ + try: + self.wait(0) + except WindowsError: + e = sys.exc_info()[1] + error = e.winerror + if error == win32.ERROR_ACCESS_DENIED: + raise + return error == win32.WAIT_TIMEOUT + return True + + def get_exit_code(self): + """ + @rtype: int + @return: Thread exit code, or C{STILL_ACTIVE} if it's still alive. + """ + if win32.THREAD_ALL_ACCESS == win32.THREAD_ALL_ACCESS_VISTA: + dwAccess = win32.THREAD_QUERY_LIMITED_INFORMATION + else: + dwAccess = win32.THREAD_QUERY_INFORMATION + return win32.GetExitCodeThread( self.get_handle(dwAccess) ) + +#------------------------------------------------------------------------------ + + # XXX TODO + # Support for string searches on the window captions. + + def get_windows(self): + """ + @rtype: list of L{Window} + @return: Returns a list of windows handled by this thread. + """ + try: + process = self.get_process() + except Exception: + process = None + return [ + Window( hWnd, process, self ) \ + for hWnd in win32.EnumThreadWindows( self.get_tid() ) + ] + +#------------------------------------------------------------------------------ + + # TODO + # A registers cache could be implemented here. + def get_context(self, ContextFlags = None, bSuspend = False): + """ + Retrieves the execution context (i.e. the registers values) for this + thread. + + @type ContextFlags: int + @param ContextFlags: Optional, specify which registers to retrieve. + Defaults to C{win32.CONTEXT_ALL} which retrieves all registes + for the current platform. + + @type bSuspend: bool + @param bSuspend: C{True} to automatically suspend the thread before + getting its context, C{False} otherwise. + + Defaults to C{False} because suspending the thread during some + debug events (like thread creation or destruction) may lead to + strange errors. + + Note that WinAppDbg 1.4 used to suspend the thread automatically + always. This behavior was changed in version 1.5. + + @rtype: dict( str S{->} int ) + @return: Dictionary mapping register names to their values. + + @see: L{set_context} + """ + + # Some words on the "strange errors" that lead to the bSuspend + # parameter. Peter Van Eeckhoutte and I were working on a fix + # for some bugs he found in the 1.5 betas when we stumbled upon + # what seemed to be a deadlock in the debug API that caused the + # GetThreadContext() call never to return. Since removing the + # call to SuspendThread() solved the problem, and a few Google + # searches showed a handful of problems related to these two + # APIs and Wow64 environments, I decided to break compatibility. + # + # Here are some pages about the weird behavior of SuspendThread: + # http://zachsaw.blogspot.com.es/2010/11/wow64-bug-getthreadcontext-may-return.html + # http://stackoverflow.com/questions/3444190/windows-suspendthread-doesnt-getthreadcontext-fails + + # Get the thread handle. + dwAccess = win32.THREAD_GET_CONTEXT + if bSuspend: + dwAccess = dwAccess | win32.THREAD_SUSPEND_RESUME + hThread = self.get_handle(dwAccess) + + # Suspend the thread if requested. + if bSuspend: + try: + self.suspend() + except WindowsError: + # Threads can't be suspended when the exit process event + # arrives, but you can still get the context. + bSuspend = False + + # If an exception is raised, make sure the thread execution is resumed. + try: + + if win32.bits == self.get_bits(): + + # 64 bit debugger attached to 64 bit process, or + # 32 bit debugger attached to 32 bit process. + ctx = win32.GetThreadContext(hThread, + ContextFlags = ContextFlags) + + else: + if self.is_wow64(): + + # 64 bit debugger attached to 32 bit process. + if ContextFlags is not None: + ContextFlags &= ~win32.ContextArchMask + ContextFlags |= win32.WOW64_CONTEXT_i386 + ctx = win32.Wow64GetThreadContext(hThread, ContextFlags) + + else: + + # 32 bit debugger attached to 64 bit process. + # XXX only i386/AMD64 is supported in this particular case + if win32.arch not in (win32.ARCH_I386, win32.ARCH_AMD64): + raise NotImplementedError() + if ContextFlags is not None: + ContextFlags &= ~win32.ContextArchMask + ContextFlags |= win32.context_amd64.CONTEXT_AMD64 + ctx = win32.context_amd64.GetThreadContext(hThread, + ContextFlags = ContextFlags) + + finally: + + # Resume the thread if we suspended it. + if bSuspend: + self.resume() + + # Return the context. + return ctx + + def set_context(self, context, bSuspend = False): + """ + Sets the values of the registers. + + @see: L{get_context} + + @type context: dict( str S{->} int ) + @param context: Dictionary mapping register names to their values. + + @type bSuspend: bool + @param bSuspend: C{True} to automatically suspend the thread before + setting its context, C{False} otherwise. + + Defaults to C{False} because suspending the thread during some + debug events (like thread creation or destruction) may lead to + strange errors. + + Note that WinAppDbg 1.4 used to suspend the thread automatically + always. This behavior was changed in version 1.5. + """ + + # Get the thread handle. + dwAccess = win32.THREAD_SET_CONTEXT + if bSuspend: + dwAccess = dwAccess | win32.THREAD_SUSPEND_RESUME + hThread = self.get_handle(dwAccess) + + # Suspend the thread if requested. + if bSuspend: + self.suspend() + # No fix for the exit process event bug. + # Setting the context of a dead thread is pointless anyway. + + # Set the thread context. + try: + if win32.bits == 64 and self.is_wow64(): + win32.Wow64SetThreadContext(hThread, context) + else: + win32.SetThreadContext(hThread, context) + + # Resume the thread if we suspended it. + finally: + if bSuspend: + self.resume() + + def get_register(self, register): + """ + @type register: str + @param register: Register name. + + @rtype: int + @return: Value of the requested register. + """ + 'Returns the value of a specific register.' + context = self.get_context() + return context[register] + + def set_register(self, register, value): + """ + Sets the value of a specific register. + + @type register: str + @param register: Register name. + + @rtype: int + @return: Register value. + """ + context = self.get_context() + context[register] = value + self.set_context(context) + +#------------------------------------------------------------------------------ + + # TODO: a metaclass would do a better job instead of checking the platform + # during module import, also would support mixing 32 and 64 bits + + if win32.arch in (win32.ARCH_I386, win32.ARCH_AMD64): + + def get_pc(self): + """ + @rtype: int + @return: Value of the program counter register. + """ + context = self.get_context(win32.CONTEXT_CONTROL) + return context.pc + + def set_pc(self, pc): + """ + Sets the value of the program counter register. + + @type pc: int + @param pc: Value of the program counter register. + """ + context = self.get_context(win32.CONTEXT_CONTROL) + context.pc = pc + self.set_context(context) + + def get_sp(self): + """ + @rtype: int + @return: Value of the stack pointer register. + """ + context = self.get_context(win32.CONTEXT_CONTROL) + return context.sp + + def set_sp(self, sp): + """ + Sets the value of the stack pointer register. + + @type sp: int + @param sp: Value of the stack pointer register. + """ + context = self.get_context(win32.CONTEXT_CONTROL) + context.sp = sp + self.set_context(context) + + def get_fp(self): + """ + @rtype: int + @return: Value of the frame pointer register. + """ + flags = win32.CONTEXT_CONTROL | win32.CONTEXT_INTEGER + context = self.get_context(flags) + return context.fp + + def set_fp(self, fp): + """ + Sets the value of the frame pointer register. + + @type fp: int + @param fp: Value of the frame pointer register. + """ + flags = win32.CONTEXT_CONTROL | win32.CONTEXT_INTEGER + context = self.get_context(flags) + context.fp = fp + self.set_context(context) + +#------------------------------------------------------------------------------ + + if win32.arch in (win32.ARCH_I386, win32.ARCH_AMD64): + + class Flags (object): + 'Commonly used processor flags' + Overflow = 0x800 + Direction = 0x400 + Interrupts = 0x200 + Trap = 0x100 + Sign = 0x80 + Zero = 0x40 + # 0x20 ??? + Auxiliary = 0x10 + # 0x8 ??? + Parity = 0x4 + # 0x2 ??? + Carry = 0x1 + + def get_flags(self, FlagMask = 0xFFFFFFFF): + """ + @type FlagMask: int + @param FlagMask: (Optional) Bitwise-AND mask. + + @rtype: int + @return: Flags register contents, optionally masking out some bits. + """ + context = self.get_context(win32.CONTEXT_CONTROL) + return context['EFlags'] & FlagMask + + def set_flags(self, eflags, FlagMask = 0xFFFFFFFF): + """ + Sets the flags register, optionally masking some bits. + + @type eflags: int + @param eflags: Flags register contents. + + @type FlagMask: int + @param FlagMask: (Optional) Bitwise-AND mask. + """ + context = self.get_context(win32.CONTEXT_CONTROL) + context['EFlags'] = (context['EFlags'] & FlagMask) | eflags + self.set_context(context) + + def get_flag_value(self, FlagBit): + """ + @type FlagBit: int + @param FlagBit: One of the L{Flags}. + + @rtype: bool + @return: Boolean value of the requested flag. + """ + return bool( self.get_flags(FlagBit) ) + + def set_flag_value(self, FlagBit, FlagValue): + """ + Sets a single flag, leaving the others intact. + + @type FlagBit: int + @param FlagBit: One of the L{Flags}. + + @type FlagValue: bool + @param FlagValue: Boolean value of the flag. + """ + if FlagValue: + eflags = FlagBit + else: + eflags = 0 + FlagMask = 0xFFFFFFFF ^ FlagBit + self.set_flags(eflags, FlagMask) + + def get_zf(self): + """ + @rtype: bool + @return: Boolean value of the Zero flag. + """ + return self.get_flag_value(self.Flags.Zero) + + def get_cf(self): + """ + @rtype: bool + @return: Boolean value of the Carry flag. + """ + return self.get_flag_value(self.Flags.Carry) + + def get_sf(self): + """ + @rtype: bool + @return: Boolean value of the Sign flag. + """ + return self.get_flag_value(self.Flags.Sign) + + def get_df(self): + """ + @rtype: bool + @return: Boolean value of the Direction flag. + """ + return self.get_flag_value(self.Flags.Direction) + + def get_tf(self): + """ + @rtype: bool + @return: Boolean value of the Trap flag. + """ + return self.get_flag_value(self.Flags.Trap) + + def clear_zf(self): + 'Clears the Zero flag.' + self.set_flag_value(self.Flags.Zero, False) + + def clear_cf(self): + 'Clears the Carry flag.' + self.set_flag_value(self.Flags.Carry, False) + + def clear_sf(self): + 'Clears the Sign flag.' + self.set_flag_value(self.Flags.Sign, False) + + def clear_df(self): + 'Clears the Direction flag.' + self.set_flag_value(self.Flags.Direction, False) + + def clear_tf(self): + 'Clears the Trap flag.' + self.set_flag_value(self.Flags.Trap, False) + + def set_zf(self): + 'Sets the Zero flag.' + self.set_flag_value(self.Flags.Zero, True) + + def set_cf(self): + 'Sets the Carry flag.' + self.set_flag_value(self.Flags.Carry, True) + + def set_sf(self): + 'Sets the Sign flag.' + self.set_flag_value(self.Flags.Sign, True) + + def set_df(self): + 'Sets the Direction flag.' + self.set_flag_value(self.Flags.Direction, True) + + def set_tf(self): + 'Sets the Trap flag.' + self.set_flag_value(self.Flags.Trap, True) + +#------------------------------------------------------------------------------ + + def is_wow64(self): + """ + Determines if the thread is running under WOW64. + + @rtype: bool + @return: + C{True} if the thread is running under WOW64. That is, it belongs + to a 32-bit application running in a 64-bit Windows. + + C{False} if the thread belongs to either a 32-bit application + running in a 32-bit Windows, or a 64-bit application running in a + 64-bit Windows. + + @raise WindowsError: On error an exception is raised. + + @see: U{http://msdn.microsoft.com/en-us/library/aa384249(VS.85).aspx} + """ + try: + wow64 = self.__wow64 + except AttributeError: + if (win32.bits == 32 and not win32.wow64): + wow64 = False + else: + wow64 = self.get_process().is_wow64() + self.__wow64 = wow64 + return wow64 + + def get_arch(self): + """ + @rtype: str + @return: The architecture in which this thread believes to be running. + For example, if running a 32 bit binary in a 64 bit machine, the + architecture returned by this method will be L{win32.ARCH_I386}, + but the value of L{System.arch} will be L{win32.ARCH_AMD64}. + """ + if win32.bits == 32 and not win32.wow64: + return win32.arch + return self.get_process().get_arch() + + def get_bits(self): + """ + @rtype: str + @return: The number of bits in which this thread believes to be + running. For example, if running a 32 bit binary in a 64 bit + machine, the number of bits returned by this method will be C{32}, + but the value of L{System.arch} will be C{64}. + """ + if win32.bits == 32 and not win32.wow64: + return 32 + return self.get_process().get_bits() + + def is_hidden(self): + """ + Determines if the thread has been hidden from debuggers. + + Some binary packers hide their own threads to thwart debugging. + + @rtype: bool + @return: C{True} if the thread is hidden from debuggers. + This means the thread's execution won't be stopped for debug + events, and thus said events won't be sent to the debugger. + """ + return win32.NtQueryInformationThread( + self.get_handle(), # XXX what permissions do I need? + win32.ThreadHideFromDebugger) + + def get_teb(self): + """ + Returns a copy of the TEB. + To dereference pointers in it call L{Process.read_structure}. + + @rtype: L{TEB} + @return: TEB structure. + @raise WindowsError: An exception is raised on error. + """ + return self.get_process().read_structure( self.get_teb_address(), + win32.TEB ) + + def get_teb_address(self): + """ + Returns a remote pointer to the TEB. + + @rtype: int + @return: Remote pointer to the L{TEB} structure. + @raise WindowsError: An exception is raised on error. + """ + try: + return self._teb_ptr + except AttributeError: + try: + hThread = self.get_handle(win32.THREAD_QUERY_INFORMATION) + tbi = win32.NtQueryInformationThread( hThread, + win32.ThreadBasicInformation) + address = tbi.TebBaseAddress + except WindowsError: + address = self.get_linear_address('SegFs', 0) # fs:[0] + if not address: + raise + self._teb_ptr = address + return address + + def get_linear_address(self, segment, address): + """ + Translates segment-relative addresses to linear addresses. + + Linear addresses can be used to access a process memory, + calling L{Process.read} and L{Process.write}. + + @type segment: str + @param segment: Segment register name. + + @type address: int + @param address: Segment relative memory address. + + @rtype: int + @return: Linear memory address. + + @raise ValueError: Address is too large for selector. + + @raise WindowsError: + The current architecture does not support selectors. + Selectors only exist in x86-based systems. + """ + hThread = self.get_handle(win32.THREAD_QUERY_INFORMATION) + selector = self.get_register(segment) + ldt = win32.GetThreadSelectorEntry(hThread, selector) + BaseLow = ldt.BaseLow + BaseMid = ldt.HighWord.Bytes.BaseMid << 16 + BaseHi = ldt.HighWord.Bytes.BaseHi << 24 + Base = BaseLow | BaseMid | BaseHi + LimitLow = ldt.LimitLow + LimitHi = ldt.HighWord.Bits.LimitHi << 16 + Limit = LimitLow | LimitHi + if address > Limit: + msg = "Address %s too large for segment %s (selector %d)" + msg = msg % (HexDump.address(address, self.get_bits()), + segment, selector) + raise ValueError(msg) + return Base + address + + def get_label_at_pc(self): + """ + @rtype: str + @return: Label that points to the instruction currently being executed. + """ + return self.get_process().get_label_at_address( self.get_pc() ) + + def get_seh_chain_pointer(self): + """ + Get the pointer to the first structured exception handler block. + + @rtype: int + @return: Remote pointer to the first block of the structured exception + handlers linked list. If the list is empty, the returned value is + C{0xFFFFFFFF}. + + @raise NotImplementedError: + This method is only supported in 32 bits versions of Windows. + """ + if win32.arch != win32.ARCH_I386: + raise NotImplementedError( + "SEH chain parsing is only supported in 32-bit Windows.") + + process = self.get_process() + address = self.get_linear_address( 'SegFs', 0 ) + return process.read_pointer( address ) + + def set_seh_chain_pointer(self, value): + """ + Change the pointer to the first structured exception handler block. + + @type value: int + @param value: Value of the remote pointer to the first block of the + structured exception handlers linked list. To disable SEH set the + value C{0xFFFFFFFF}. + + @raise NotImplementedError: + This method is only supported in 32 bits versions of Windows. + """ + if win32.arch != win32.ARCH_I386: + raise NotImplementedError( + "SEH chain parsing is only supported in 32-bit Windows.") + + process = self.get_process() + address = self.get_linear_address( 'SegFs', 0 ) + process.write_pointer( address, value ) + + def get_seh_chain(self): + """ + @rtype: list of tuple( int, int ) + @return: List of structured exception handlers. + Each SEH is represented as a tuple of two addresses: + - Address of this SEH block + - Address of the SEH callback function + Do not confuse this with the contents of the SEH block itself, + where the first member is a pointer to the B{next} block instead. + + @raise NotImplementedError: + This method is only supported in 32 bits versions of Windows. + """ + seh_chain = list() + try: + process = self.get_process() + seh = self.get_seh_chain_pointer() + while seh != 0xFFFFFFFF: + seh_func = process.read_pointer( seh + 4 ) + seh_chain.append( (seh, seh_func) ) + seh = process.read_pointer( seh ) + except WindowsError: + seh_chain.append( (seh, None) ) + return seh_chain + + def get_wait_chain(self): + """ + @rtype: + tuple of ( + list of L{win32.WaitChainNodeInfo} structures, + bool) + @return: + Wait chain for the thread. + The boolean indicates if there's a cycle in the chain (a deadlock). + @raise AttributeError: + This method is only suppported in Windows Vista and above. + @see: + U{http://msdn.microsoft.com/en-us/library/ms681622%28VS.85%29.aspx} + """ + with win32.OpenThreadWaitChainSession() as hWct: + return win32.GetThreadWaitChain(hWct, ThreadId = self.get_tid()) + + def get_stack_range(self): + """ + @rtype: tuple( int, int ) + @return: Stack beginning and end pointers, in memory addresses order. + That is, the first pointer is the stack top, and the second pointer + is the stack bottom, since the stack grows towards lower memory + addresses. + @raise WindowsError: Raises an exception on error. + """ + # TODO use teb.DeallocationStack too (max. possible stack size) + teb = self.get_teb() + tib = teb.NtTib + return ( tib.StackLimit, tib.StackBase ) # top, bottom + + def __get_stack_trace(self, depth = 16, bUseLabels = True, + bMakePretty = True): + """ + Tries to get a stack trace for the current function using the debug + helper API (dbghelp.dll). + + @type depth: int + @param depth: Maximum depth of stack trace. + + @type bUseLabels: bool + @param bUseLabels: C{True} to use labels, C{False} to use addresses. + + @type bMakePretty: bool + @param bMakePretty: + C{True} for user readable labels, + C{False} for labels that can be passed to L{Process.resolve_label}. + + "Pretty" labels look better when producing output for the user to + read, while pure labels are more useful programatically. + + @rtype: tuple of tuple( int, int, str ) + @return: Stack trace of the thread as a tuple of + ( return address, frame pointer address, module filename ) + when C{bUseLabels} is C{True}, or a tuple of + ( return address, frame pointer label ) + when C{bUseLabels} is C{False}. + + @raise WindowsError: Raises an exception on error. + """ + + aProcess = self.get_process() + arch = aProcess.get_arch() + bits = aProcess.get_bits() + + if arch == win32.ARCH_I386: + MachineType = win32.IMAGE_FILE_MACHINE_I386 + elif arch == win32.ARCH_AMD64: + MachineType = win32.IMAGE_FILE_MACHINE_AMD64 + elif arch == win32.ARCH_IA64: + MachineType = win32.IMAGE_FILE_MACHINE_IA64 + else: + msg = "Stack walking is not available for this architecture: %s" + raise NotImplementedError(msg % arch) + + hProcess = aProcess.get_handle( win32.PROCESS_VM_READ | + win32.PROCESS_QUERY_INFORMATION ) + hThread = self.get_handle( win32.THREAD_GET_CONTEXT | + win32.THREAD_QUERY_INFORMATION ) + + StackFrame = win32.STACKFRAME64() + StackFrame.AddrPC = win32.ADDRESS64( self.get_pc() ) + StackFrame.AddrFrame = win32.ADDRESS64( self.get_fp() ) + StackFrame.AddrStack = win32.ADDRESS64( self.get_sp() ) + + trace = list() + while win32.StackWalk64(MachineType, hProcess, hThread, StackFrame): + if depth <= 0: + break + fp = StackFrame.AddrFrame.Offset + ra = aProcess.peek_pointer(fp + 4) + if ra == 0: + break + lib = aProcess.get_module_at_address(ra) + if lib is None: + lib = "" + else: + if lib.fileName: + lib = lib.fileName + else: + lib = "%s" % HexDump.address(lib.lpBaseOfDll, bits) + if bUseLabels: + label = aProcess.get_label_at_address(ra) + if bMakePretty: + label = '%s (%s)' % (HexDump.address(ra, bits), label) + trace.append( (fp, label) ) + else: + trace.append( (fp, ra, lib) ) + fp = aProcess.peek_pointer(fp) + return tuple(trace) + + def __get_stack_trace_manually(self, depth = 16, bUseLabels = True, + bMakePretty = True): + """ + Tries to get a stack trace for the current function. + Only works for functions with standard prologue and epilogue. + + @type depth: int + @param depth: Maximum depth of stack trace. + + @type bUseLabels: bool + @param bUseLabels: C{True} to use labels, C{False} to use addresses. + + @type bMakePretty: bool + @param bMakePretty: + C{True} for user readable labels, + C{False} for labels that can be passed to L{Process.resolve_label}. + + "Pretty" labels look better when producing output for the user to + read, while pure labels are more useful programatically. + + @rtype: tuple of tuple( int, int, str ) + @return: Stack trace of the thread as a tuple of + ( return address, frame pointer address, module filename ) + when C{bUseLabels} is C{True}, or a tuple of + ( return address, frame pointer label ) + when C{bUseLabels} is C{False}. + + @raise WindowsError: Raises an exception on error. + """ + aProcess = self.get_process() + st, sb = self.get_stack_range() # top, bottom + fp = self.get_fp() + trace = list() + if aProcess.get_module_count() == 0: + aProcess.scan_modules() + bits = aProcess.get_bits() + while depth > 0: + if fp == 0: + break + if not st <= fp < sb: + break + ra = aProcess.peek_pointer(fp + 4) + if ra == 0: + break + lib = aProcess.get_module_at_address(ra) + if lib is None: + lib = "" + else: + if lib.fileName: + lib = lib.fileName + else: + lib = "%s" % HexDump.address(lib.lpBaseOfDll, bits) + if bUseLabels: + label = aProcess.get_label_at_address(ra) + if bMakePretty: + label = '%s (%s)' % (HexDump.address(ra, bits), label) + trace.append( (fp, label) ) + else: + trace.append( (fp, ra, lib) ) + fp = aProcess.peek_pointer(fp) + return tuple(trace) + + def get_stack_trace(self, depth = 16): + """ + Tries to get a stack trace for the current function. + Only works for functions with standard prologue and epilogue. + + @type depth: int + @param depth: Maximum depth of stack trace. + + @rtype: tuple of tuple( int, int, str ) + @return: Stack trace of the thread as a tuple of + ( return address, frame pointer address, module filename ). + + @raise WindowsError: Raises an exception on error. + """ + try: + trace = self.__get_stack_trace(depth, False) + except Exception: + import traceback + traceback.print_exc() + trace = () + if not trace: + trace = self.__get_stack_trace_manually(depth, False) + return trace + + def get_stack_trace_with_labels(self, depth = 16, bMakePretty = True): + """ + Tries to get a stack trace for the current function. + Only works for functions with standard prologue and epilogue. + + @type depth: int + @param depth: Maximum depth of stack trace. + + @type bMakePretty: bool + @param bMakePretty: + C{True} for user readable labels, + C{False} for labels that can be passed to L{Process.resolve_label}. + + "Pretty" labels look better when producing output for the user to + read, while pure labels are more useful programatically. + + @rtype: tuple of tuple( int, int, str ) + @return: Stack trace of the thread as a tuple of + ( return address, frame pointer label ). + + @raise WindowsError: Raises an exception on error. + """ + try: + trace = self.__get_stack_trace(depth, True, bMakePretty) + except Exception: + trace = () + if not trace: + trace = self.__get_stack_trace_manually(depth, True, bMakePretty) + return trace + + def get_stack_frame_range(self): + """ + Returns the starting and ending addresses of the stack frame. + Only works for functions with standard prologue and epilogue. + + @rtype: tuple( int, int ) + @return: Stack frame range. + May not be accurate, depending on the compiler used. + + @raise RuntimeError: The stack frame is invalid, + or the function doesn't have a standard prologue + and epilogue. + + @raise WindowsError: An error occured when getting the thread context. + """ + st, sb = self.get_stack_range() # top, bottom + sp = self.get_sp() + fp = self.get_fp() + size = fp - sp + if not st <= sp < sb: + raise RuntimeError('Stack pointer lies outside the stack') + if not st <= fp < sb: + raise RuntimeError('Frame pointer lies outside the stack') + if sp > fp: + raise RuntimeError('No valid stack frame found') + return (sp, fp) + + def get_stack_frame(self, max_size = None): + """ + Reads the contents of the current stack frame. + Only works for functions with standard prologue and epilogue. + + @type max_size: int + @param max_size: (Optional) Maximum amount of bytes to read. + + @rtype: str + @return: Stack frame data. + May not be accurate, depending on the compiler used. + May return an empty string. + + @raise RuntimeError: The stack frame is invalid, + or the function doesn't have a standard prologue + and epilogue. + + @raise WindowsError: An error occured when getting the thread context + or reading data from the process memory. + """ + sp, fp = self.get_stack_frame_range() + size = fp - sp + if max_size and size > max_size: + size = max_size + return self.get_process().peek(sp, size) + + def read_stack_data(self, size = 128, offset = 0): + """ + Reads the contents of the top of the stack. + + @type size: int + @param size: Number of bytes to read. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + + @rtype: str + @return: Stack data. + + @raise WindowsError: Could not read the requested data. + """ + aProcess = self.get_process() + return aProcess.read(self.get_sp() + offset, size) + + def peek_stack_data(self, size = 128, offset = 0): + """ + Tries to read the contents of the top of the stack. + + @type size: int + @param size: Number of bytes to read. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + + @rtype: str + @return: Stack data. + Returned data may be less than the requested size. + """ + aProcess = self.get_process() + return aProcess.peek(self.get_sp() + offset, size) + + def read_stack_dwords(self, count, offset = 0): + """ + Reads DWORDs from the top of the stack. + + @type count: int + @param count: Number of DWORDs to read. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + + @rtype: tuple( int... ) + @return: Tuple of integers read from the stack. + + @raise WindowsError: Could not read the requested data. + """ + if count > 0: + stackData = self.read_stack_data(count * 4, offset) + return struct.unpack('<'+('L'*count), stackData) + return () + + def peek_stack_dwords(self, count, offset = 0): + """ + Tries to read DWORDs from the top of the stack. + + @type count: int + @param count: Number of DWORDs to read. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + + @rtype: tuple( int... ) + @return: Tuple of integers read from the stack. + May be less than the requested number of DWORDs. + """ + stackData = self.peek_stack_data(count * 4, offset) + if len(stackData) & 3: + stackData = stackData[:-len(stackData) & 3] + if not stackData: + return () + return struct.unpack('<'+('L'*count), stackData) + + def read_stack_qwords(self, count, offset = 0): + """ + Reads QWORDs from the top of the stack. + + @type count: int + @param count: Number of QWORDs to read. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + + @rtype: tuple( int... ) + @return: Tuple of integers read from the stack. + + @raise WindowsError: Could not read the requested data. + """ + stackData = self.read_stack_data(count * 8, offset) + return struct.unpack('<'+('Q'*count), stackData) + + def peek_stack_qwords(self, count, offset = 0): + """ + Tries to read QWORDs from the top of the stack. + + @type count: int + @param count: Number of QWORDs to read. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + + @rtype: tuple( int... ) + @return: Tuple of integers read from the stack. + May be less than the requested number of QWORDs. + """ + stackData = self.peek_stack_data(count * 8, offset) + if len(stackData) & 7: + stackData = stackData[:-len(stackData) & 7] + if not stackData: + return () + return struct.unpack('<'+('Q'*count), stackData) + + def read_stack_structure(self, structure, offset = 0): + """ + Reads the given structure at the top of the stack. + + @type structure: ctypes.Structure + @param structure: Structure of the data to read from the stack. + + @type offset: int + @param offset: Offset from the stack pointer to begin reading. + The stack pointer is the same returned by the L{get_sp} method. + + @rtype: tuple + @return: Tuple of elements read from the stack. The type of each + element matches the types in the stack frame structure. + """ + aProcess = self.get_process() + stackData = aProcess.read_structure(self.get_sp() + offset, structure) + return tuple([ stackData.__getattribute__(name) + for (name, type) in stackData._fields_ ]) + + def read_stack_frame(self, structure, offset = 0): + """ + Reads the stack frame of the thread. + + @type structure: ctypes.Structure + @param structure: Structure of the stack frame. + + @type offset: int + @param offset: Offset from the frame pointer to begin reading. + The frame pointer is the same returned by the L{get_fp} method. + + @rtype: tuple + @return: Tuple of elements read from the stack frame. The type of each + element matches the types in the stack frame structure. + """ + aProcess = self.get_process() + stackData = aProcess.read_structure(self.get_fp() + offset, structure) + return tuple([ stackData.__getattribute__(name) + for (name, type) in stackData._fields_ ]) + + def read_code_bytes(self, size = 128, offset = 0): + """ + Tries to read some bytes of the code currently being executed. + + @type size: int + @param size: Number of bytes to read. + + @type offset: int + @param offset: Offset from the program counter to begin reading. + + @rtype: str + @return: Bytes read from the process memory. + + @raise WindowsError: Could not read the requested data. + """ + return self.get_process().read(self.get_pc() + offset, size) + + def peek_code_bytes(self, size = 128, offset = 0): + """ + Tries to read some bytes of the code currently being executed. + + @type size: int + @param size: Number of bytes to read. + + @type offset: int + @param offset: Offset from the program counter to begin reading. + + @rtype: str + @return: Bytes read from the process memory. + May be less than the requested number of bytes. + """ + return self.get_process().peek(self.get_pc() + offset, size) + + def peek_pointers_in_registers(self, peekSize = 16, context = None): + """ + Tries to guess which values in the registers are valid pointers, + and reads some data from them. + + @type peekSize: int + @param peekSize: Number of bytes to read from each pointer found. + + @type context: dict( str S{->} int ) + @param context: (Optional) + Dictionary mapping register names to their values. + If not given, the current thread context will be used. + + @rtype: dict( str S{->} str ) + @return: Dictionary mapping register names to the data they point to. + """ + peekable_registers = ( + 'Eax', 'Ebx', 'Ecx', 'Edx', 'Esi', 'Edi', 'Ebp' + ) + if not context: + context = self.get_context(win32.CONTEXT_CONTROL | \ + win32.CONTEXT_INTEGER) + aProcess = self.get_process() + data = dict() + for (reg_name, reg_value) in compat.iteritems(context): + if reg_name not in peekable_registers: + continue +## if reg_name == 'Ebp': +## stack_begin, stack_end = self.get_stack_range() +## print hex(stack_end), hex(reg_value), hex(stack_begin) +## if stack_begin and stack_end and stack_end < stack_begin and \ +## stack_begin <= reg_value <= stack_end: +## continue + reg_data = aProcess.peek(reg_value, peekSize) + if reg_data: + data[reg_name] = reg_data + return data + + # TODO + # try to avoid reading the same page twice by caching it + def peek_pointers_in_data(self, data, peekSize = 16, peekStep = 1): + """ + Tries to guess which values in the given data are valid pointers, + and reads some data from them. + + @type data: str + @param data: Binary data to find pointers in. + + @type peekSize: int + @param peekSize: Number of bytes to read from each pointer found. + + @type peekStep: int + @param peekStep: Expected data alignment. + Tipically you specify 1 when data alignment is unknown, + or 4 when you expect data to be DWORD aligned. + Any other value may be specified. + + @rtype: dict( str S{->} str ) + @return: Dictionary mapping stack offsets to the data they point to. + """ + aProcess = self.get_process() + return aProcess.peek_pointers_in_data(data, peekSize, peekStep) + +#------------------------------------------------------------------------------ + + # TODO + # The disassemble_around and disassemble_around_pc methods + # should take as parameter instruction counts rather than sizes + + def disassemble_string(self, lpAddress, code): + """ + Disassemble instructions from a block of binary code. + + @type lpAddress: int + @param lpAddress: Memory address where the code was read from. + + @type code: str + @param code: Binary code to disassemble. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aProcess = self.get_process() + return aProcess.disassemble_string(lpAddress, code) + + def disassemble(self, lpAddress, dwSize): + """ + Disassemble instructions from the address space of the process. + + @type lpAddress: int + @param lpAddress: Memory address where to read the code from. + + @type dwSize: int + @param dwSize: Size of binary code to disassemble. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aProcess = self.get_process() + return aProcess.disassemble(lpAddress, dwSize) + + def disassemble_around(self, lpAddress, dwSize = 64): + """ + Disassemble around the given address. + + @type lpAddress: int + @param lpAddress: Memory address where to read the code from. + + @type dwSize: int + @param dwSize: Delta offset. + Code will be read from lpAddress - dwSize to lpAddress + dwSize. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aProcess = self.get_process() + return aProcess.disassemble_around(lpAddress, dwSize) + + def disassemble_around_pc(self, dwSize = 64): + """ + Disassemble around the program counter of the given thread. + + @type dwSize: int + @param dwSize: Delta offset. + Code will be read from pc - dwSize to pc + dwSize. + + @rtype: list of tuple( long, int, str, str ) + @return: List of tuples. Each tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aProcess = self.get_process() + return aProcess.disassemble_around(self.get_pc(), dwSize) + + def disassemble_instruction(self, lpAddress): + """ + Disassemble the instruction at the given memory address. + + @type lpAddress: int + @param lpAddress: Memory address where to read the code from. + + @rtype: tuple( long, int, str, str ) + @return: The tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + aProcess = self.get_process() + return aProcess.disassemble(lpAddress, 15)[0] + + def disassemble_current(self): + """ + Disassemble the instruction at the program counter of the given thread. + + @rtype: tuple( long, int, str, str ) + @return: The tuple represents an assembly instruction + and contains: + - Memory address of instruction. + - Size of instruction in bytes. + - Disassembly line of instruction. + - Hexadecimal dump of instruction. + """ + return self.disassemble_instruction( self.get_pc() ) + +#============================================================================== + +class _ThreadContainer (object): + """ + Encapsulates the capability to contain Thread objects. + + @group Instrumentation: + start_thread + + @group Threads snapshot: + scan_threads, + get_thread, get_thread_count, get_thread_ids, + has_thread, iter_threads, iter_thread_ids, + find_threads_by_name, get_windows, + clear_threads, clear_dead_threads, close_thread_handles + """ + + def __init__(self): + self.__threadDict = dict() + + def __initialize_snapshot(self): + """ + Private method to automatically initialize the snapshot + when you try to use it without calling any of the scan_* + methods first. You don't need to call this yourself. + """ + if not self.__threadDict: + self.scan_threads() + + def __contains__(self, anObject): + """ + @type anObject: L{Thread}, int + @param anObject: + - C{int}: Global ID of the thread to look for. + - C{Thread}: Thread object to look for. + + @rtype: bool + @return: C{True} if the snapshot contains + a L{Thread} object with the same ID. + """ + if isinstance(anObject, Thread): + anObject = anObject.dwThreadId + return self.has_thread(anObject) + + def __iter__(self): + """ + @see: L{iter_threads} + @rtype: dictionary-valueiterator + @return: Iterator of L{Thread} objects in this snapshot. + """ + return self.iter_threads() + + def __len__(self): + """ + @see: L{get_thread_count} + @rtype: int + @return: Count of L{Thread} objects in this snapshot. + """ + return self.get_thread_count() + + def has_thread(self, dwThreadId): + """ + @type dwThreadId: int + @param dwThreadId: Global ID of the thread to look for. + + @rtype: bool + @return: C{True} if the snapshot contains a + L{Thread} object with the given global ID. + """ + self.__initialize_snapshot() + return dwThreadId in self.__threadDict + + def get_thread(self, dwThreadId): + """ + @type dwThreadId: int + @param dwThreadId: Global ID of the thread to look for. + + @rtype: L{Thread} + @return: Thread object with the given global ID. + """ + self.__initialize_snapshot() + if dwThreadId not in self.__threadDict: + msg = "Unknown thread ID: %d" % dwThreadId + raise KeyError(msg) + return self.__threadDict[dwThreadId] + + def iter_thread_ids(self): + """ + @see: L{iter_threads} + @rtype: dictionary-keyiterator + @return: Iterator of global thread IDs in this snapshot. + """ + self.__initialize_snapshot() + return compat.iterkeys(self.__threadDict) + + def iter_threads(self): + """ + @see: L{iter_thread_ids} + @rtype: dictionary-valueiterator + @return: Iterator of L{Thread} objects in this snapshot. + """ + self.__initialize_snapshot() + return compat.itervalues(self.__threadDict) + + def get_thread_ids(self): + """ + @rtype: list( int ) + @return: List of global thread IDs in this snapshot. + """ + self.__initialize_snapshot() + return compat.keys(self.__threadDict) + + def get_thread_count(self): + """ + @rtype: int + @return: Count of L{Thread} objects in this snapshot. + """ + self.__initialize_snapshot() + return len(self.__threadDict) + +#------------------------------------------------------------------------------ + + def find_threads_by_name(self, name, bExactMatch = True): + """ + Find threads by name, using different search methods. + + @type name: str, None + @param name: Name to look for. Use C{None} to find nameless threads. + + @type bExactMatch: bool + @param bExactMatch: C{True} if the name must be + B{exactly} as given, C{False} if the name can be + loosely matched. + + This parameter is ignored when C{name} is C{None}. + + @rtype: list( L{Thread} ) + @return: All threads matching the given name. + """ + found_threads = list() + + # Find threads with no name. + if name is None: + for aThread in self.iter_threads(): + if aThread.get_name() is None: + found_threads.append(aThread) + + # Find threads matching the given name exactly. + elif bExactMatch: + for aThread in self.iter_threads(): + if aThread.get_name() == name: + found_threads.append(aThread) + + # Find threads whose names match the given substring. + else: + for aThread in self.iter_threads(): + t_name = aThread.get_name() + if t_name is not None and name in t_name: + found_threads.append(aThread) + + return found_threads + +#------------------------------------------------------------------------------ + + # XXX TODO + # Support for string searches on the window captions. + + def get_windows(self): + """ + @rtype: list of L{Window} + @return: Returns a list of windows handled by this process. + """ + window_list = list() + for thread in self.iter_threads(): + window_list.extend( thread.get_windows() ) + return window_list + +#------------------------------------------------------------------------------ + + def start_thread(self, lpStartAddress, lpParameter=0, bSuspended = False): + """ + Remotely creates a new thread in the process. + + @type lpStartAddress: int + @param lpStartAddress: Start address for the new thread. + + @type lpParameter: int + @param lpParameter: Optional argument for the new thread. + + @type bSuspended: bool + @param bSuspended: C{True} if the new thread should be suspended. + In that case use L{Thread.resume} to start execution. + """ + if bSuspended: + dwCreationFlags = win32.CREATE_SUSPENDED + else: + dwCreationFlags = 0 + hProcess = self.get_handle( win32.PROCESS_CREATE_THREAD | + win32.PROCESS_QUERY_INFORMATION | + win32.PROCESS_VM_OPERATION | + win32.PROCESS_VM_WRITE | + win32.PROCESS_VM_READ ) + hThread, dwThreadId = win32.CreateRemoteThread( + hProcess, 0, 0, lpStartAddress, lpParameter, dwCreationFlags) + aThread = Thread(dwThreadId, hThread, self) + self._add_thread(aThread) + return aThread + +#------------------------------------------------------------------------------ + + # TODO + # maybe put all the toolhelp code into their own set of classes? + # + # XXX this method musn't end up calling __initialize_snapshot by accident! + def scan_threads(self): + """ + Populates the snapshot with running threads. + """ + + # Ignore special process IDs. + # PID 0: System Idle Process. Also has a special meaning to the + # toolhelp APIs (current process). + # PID 4: System Integrity Group. See this forum post for more info: + # http://tinyurl.com/ycza8jo + # (points to social.technet.microsoft.com) + # Only on XP and above + # PID 8: System (?) only in Windows 2000 and below AFAIK. + # It's probably the same as PID 4 in XP and above. + dwProcessId = self.get_pid() + if dwProcessId in (0, 4, 8): + return + +## dead_tids = set( self.get_thread_ids() ) # XXX triggers a scan + dead_tids = self._get_thread_ids() + dwProcessId = self.get_pid() + hSnapshot = win32.CreateToolhelp32Snapshot(win32.TH32CS_SNAPTHREAD, + dwProcessId) + try: + te = win32.Thread32First(hSnapshot) + while te is not None: + if te.th32OwnerProcessID == dwProcessId: + dwThreadId = te.th32ThreadID + if dwThreadId in dead_tids: + dead_tids.remove(dwThreadId) +## if not self.has_thread(dwThreadId): # XXX triggers a scan + if not self._has_thread_id(dwThreadId): + aThread = Thread(dwThreadId, process = self) + self._add_thread(aThread) + te = win32.Thread32Next(hSnapshot) + finally: + win32.CloseHandle(hSnapshot) + for tid in dead_tids: + self._del_thread(tid) + + def clear_dead_threads(self): + """ + Remove Thread objects from the snapshot + referring to threads no longer running. + """ + for tid in self.get_thread_ids(): + aThread = self.get_thread(tid) + if not aThread.is_alive(): + self._del_thread(aThread) + + def clear_threads(self): + """ + Clears the threads snapshot. + """ + for aThread in compat.itervalues(self.__threadDict): + aThread.clear() + self.__threadDict = dict() + + def close_thread_handles(self): + """ + Closes all open handles to threads in the snapshot. + """ + for aThread in self.iter_threads(): + try: + aThread.close_handle() + except Exception: + try: + e = sys.exc_info()[1] + msg = "Cannot close thread handle %s, reason: %s" + msg %= (aThread.hThread.value, str(e)) + warnings.warn(msg) + except Exception: + pass + +#------------------------------------------------------------------------------ + + # XXX _notify_* methods should not trigger a scan + + def _add_thread(self, aThread): + """ + Private method to add a thread object to the snapshot. + + @type aThread: L{Thread} + @param aThread: Thread object. + """ +## if not isinstance(aThread, Thread): +## if hasattr(aThread, '__class__'): +## typename = aThread.__class__.__name__ +## else: +## typename = str(type(aThread)) +## msg = "Expected Thread, got %s instead" % typename +## raise TypeError(msg) + dwThreadId = aThread.dwThreadId +## if dwThreadId in self.__threadDict: +## msg = "Already have a Thread object with ID %d" % dwThreadId +## raise KeyError(msg) + aThread.set_process(self) + self.__threadDict[dwThreadId] = aThread + + def _del_thread(self, dwThreadId): + """ + Private method to remove a thread object from the snapshot. + + @type dwThreadId: int + @param dwThreadId: Global thread ID. + """ + try: + aThread = self.__threadDict[dwThreadId] + del self.__threadDict[dwThreadId] + except KeyError: + aThread = None + msg = "Unknown thread ID %d" % dwThreadId + warnings.warn(msg, RuntimeWarning) + if aThread: + aThread.clear() # remove circular references + + def _has_thread_id(self, dwThreadId): + """ + Private method to test for a thread in the snapshot without triggering + an automatic scan. + """ + return dwThreadId in self.__threadDict + + def _get_thread_ids(self): + """ + Private method to get the list of thread IDs currently in the snapshot + without triggering an automatic scan. + """ + return compat.keys(self.__threadDict) + + def __add_created_thread(self, event): + """ + Private method to automatically add new thread objects from debug events. + + @type event: L{Event} + @param event: Event object. + """ + dwThreadId = event.get_tid() + hThread = event.get_thread_handle() +## if not self.has_thread(dwThreadId): # XXX this would trigger a scan + if not self._has_thread_id(dwThreadId): + aThread = Thread(dwThreadId, hThread, self) + teb_ptr = event.get_teb() # remember the TEB pointer + if teb_ptr: + aThread._teb_ptr = teb_ptr + self._add_thread(aThread) + #else: + # aThread = self.get_thread(dwThreadId) + # if hThread != win32.INVALID_HANDLE_VALUE: + # aThread.hThread = hThread # may have more privileges + + def _notify_create_process(self, event): + """ + Notify the creation of the main thread of this process. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{CreateProcessEvent} + @param event: Create process event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + self.__add_created_thread(event) + return True + + def _notify_create_thread(self, event): + """ + Notify the creation of a new thread in this process. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{CreateThreadEvent} + @param event: Create thread event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + self.__add_created_thread(event) + return True + + def _notify_exit_thread(self, event): + """ + Notify the termination of a thread. + + This is done automatically by the L{Debug} class, you shouldn't need + to call it yourself. + + @type event: L{ExitThreadEvent} + @param event: Exit thread event. + + @rtype: bool + @return: C{True} to call the user-defined handle, C{False} otherwise. + """ + dwThreadId = event.get_tid() +## if self.has_thread(dwThreadId): # XXX this would trigger a scan + if self._has_thread_id(dwThreadId): + self._del_thread(dwThreadId) + return True diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/util.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/util.py new file mode 100644 index 0000000..4a9a984 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/util.py @@ -0,0 +1,1038 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Miscellaneous utility classes and functions. + +@group Helpers: + PathOperations, + MemoryAddresses, + CustomAddressIterator, + DataAddressIterator, + ImageAddressIterator, + MappedAddressIterator, + ExecutableAddressIterator, + ReadableAddressIterator, + WriteableAddressIterator, + ExecutableAndWriteableAddressIterator, + DebugRegister, + Regenerator, + BannerHelpFormatter, + StaticClass, + classproperty +""" + +__revision__ = "$Id$" + +__all__ = [ + + # Filename and pathname manipulation + 'PathOperations', + + # Memory address operations + 'MemoryAddresses', + 'CustomAddressIterator', + 'DataAddressIterator', + 'ImageAddressIterator', + 'MappedAddressIterator', + 'ExecutableAddressIterator', + 'ReadableAddressIterator', + 'WriteableAddressIterator', + 'ExecutableAndWriteableAddressIterator', + + # Debug registers manipulation + 'DebugRegister', + + # Miscellaneous + 'Regenerator', + ] + +import sys +import os +import ctypes +import optparse + +from winappdbg import win32 +from winappdbg import compat + +#============================================================================== + +class classproperty(property): + """ + Class property method. + + Only works for getting properties, if you set them + the symbol gets overwritten in the class namespace. + + Inspired on: U{http://stackoverflow.com/a/7864317/426293} + """ + def __init__(self, fget=None, fset=None, fdel=None, doc=""): + if fset is not None or fdel is not None: + raise NotImplementedError() + super(classproperty, self).__init__(fget=classmethod(fget), doc=doc) + def __get__(self, cls, owner): + return self.fget.__get__(None, owner)() + +class BannerHelpFormatter(optparse.IndentedHelpFormatter): + "Just a small tweak to optparse to be able to print a banner." + def __init__(self, banner, *argv, **argd): + self.banner = banner + optparse.IndentedHelpFormatter.__init__(self, *argv, **argd) + def format_usage(self, usage): + msg = optparse.IndentedHelpFormatter.format_usage(self, usage) + return '%s\n%s' % (self.banner, msg) + +# See Process.generate_memory_snapshot() +class Regenerator(object): + """ + Calls a generator and iterates it. When it's finished iterating, the + generator is called again. This allows you to iterate a generator more + than once (well, sort of). + """ + + def __init__(self, g_function, *v_args, **d_args): + """ + @type g_function: function + @param g_function: Function that when called returns a generator. + + @type v_args: tuple + @param v_args: Variable arguments to pass to the generator function. + + @type d_args: dict + @param d_args: Variable arguments to pass to the generator function. + """ + self.__g_function = g_function + self.__v_args = v_args + self.__d_args = d_args + self.__g_object = None + + def __iter__(self): + 'x.__iter__() <==> iter(x)' + return self + + def next(self): + 'x.next() -> the next value, or raise StopIteration' + if self.__g_object is None: + self.__g_object = self.__g_function( *self.__v_args, **self.__d_args ) + try: + return self.__g_object.next() + except StopIteration: + self.__g_object = None + raise + +class StaticClass (object): + def __new__(cls, *argv, **argd): + "Don't try to instance this class, just use the static methods." + raise NotImplementedError( + "Cannot instance static class %s" % cls.__name__) + +#============================================================================== + +class PathOperations (StaticClass): + """ + Static methods for filename and pathname manipulation. + """ + + @staticmethod + def path_is_relative(path): + """ + @see: L{path_is_absolute} + + @type path: str + @param path: Absolute or relative path. + + @rtype: bool + @return: C{True} if the path is relative, C{False} if it's absolute. + """ + return win32.PathIsRelative(path) + + @staticmethod + def path_is_absolute(path): + """ + @see: L{path_is_relative} + + @type path: str + @param path: Absolute or relative path. + + @rtype: bool + @return: C{True} if the path is absolute, C{False} if it's relative. + """ + return not win32.PathIsRelative(path) + + @staticmethod + def make_relative(path, current = None): + """ + @type path: str + @param path: Absolute path. + + @type current: str + @param current: (Optional) Path to the current directory. + + @rtype: str + @return: Relative path. + + @raise WindowsError: It's impossible to make the path relative. + This happens when the path and the current path are not on the + same disk drive or network share. + """ + return win32.PathRelativePathTo(pszFrom = current, pszTo = path) + + @staticmethod + def make_absolute(path): + """ + @type path: str + @param path: Relative path. + + @rtype: str + @return: Absolute path. + """ + return win32.GetFullPathName(path)[0] + + @staticmethod + def split_extension(pathname): + """ + @type pathname: str + @param pathname: Absolute path. + + @rtype: tuple( str, str ) + @return: + Tuple containing the file and extension components of the filename. + """ + filepart = win32.PathRemoveExtension(pathname) + extpart = win32.PathFindExtension(pathname) + return (filepart, extpart) + + @staticmethod + def split_filename(pathname): + """ + @type pathname: str + @param pathname: Absolute path. + + @rtype: tuple( str, str ) + @return: Tuple containing the path to the file and the base filename. + """ + filepart = win32.PathFindFileName(pathname) + pathpart = win32.PathRemoveFileSpec(pathname) + return (pathpart, filepart) + + @staticmethod + def split_path(path): + """ + @see: L{join_path} + + @type path: str + @param path: Absolute or relative path. + + @rtype: list( str... ) + @return: List of path components. + """ + components = list() + while path: + next = win32.PathFindNextComponent(path) + if next: + prev = path[ : -len(next) ] + components.append(prev) + path = next + return components + + @staticmethod + def join_path(*components): + """ + @see: L{split_path} + + @type components: tuple( str... ) + @param components: Path components. + + @rtype: str + @return: Absolute or relative path. + """ + if components: + path = components[0] + for next in components[1:]: + path = win32.PathAppend(path, next) + else: + path = "" + return path + + @staticmethod + def native_to_win32_pathname(name): + """ + @type name: str + @param name: Native (NT) absolute pathname. + + @rtype: str + @return: Win32 absolute pathname. + """ + # XXX TODO + # There are probably some native paths that + # won't be converted by this naive approach. + if name.startswith(compat.b("\\")): + if name.startswith(compat.b("\\??\\")): + name = name[4:] + elif name.startswith(compat.b("\\SystemRoot\\")): + system_root_path = os.environ['SYSTEMROOT'] + if system_root_path.endswith('\\'): + system_root_path = system_root_path[:-1] + name = system_root_path + name[11:] + else: + for drive_number in compat.xrange(ord('A'), ord('Z') + 1): + drive_letter = '%c:' % drive_number + try: + device_native_path = win32.QueryDosDevice(drive_letter) + except WindowsError: + e = sys.exc_info()[1] + if e.winerror in (win32.ERROR_FILE_NOT_FOUND, \ + win32.ERROR_PATH_NOT_FOUND): + continue + raise + if not device_native_path.endswith(compat.b('\\')): + device_native_path += compat.b('\\') + if name.startswith(device_native_path): + name = drive_letter + compat.b('\\') + \ + name[ len(device_native_path) : ] + break + return name + + @staticmethod + def pathname_to_filename(pathname): + """ + Equivalent to: C{PathOperations.split_filename(pathname)[0]} + + @note: This function is preserved for backwards compatibility with + WinAppDbg 1.4 and earlier. It may be removed in future versions. + + @type pathname: str + @param pathname: Absolute path to a file. + + @rtype: str + @return: Filename component of the path. + """ + return win32.PathFindFileName(pathname) + +#============================================================================== + +class MemoryAddresses (StaticClass): + """ + Class to manipulate memory addresses. + + @type pageSize: int + @cvar pageSize: Page size in bytes. Defaults to 0x1000 but it's + automatically updated on runtime when importing the module. + """ + + @classproperty + def pageSize(cls): + """ + Try to get the pageSize value on runtime. + """ + try: + try: + pageSize = win32.GetSystemInfo().dwPageSize + except WindowsError: + pageSize = 0x1000 + except NameError: + pageSize = 0x1000 + cls.pageSize = pageSize # now this function won't be called again + return pageSize + + @classmethod + def align_address_to_page_start(cls, address): + """ + Align the given address to the start of the page it occupies. + + @type address: int + @param address: Memory address. + + @rtype: int + @return: Aligned memory address. + """ + return address - ( address % cls.pageSize ) + + @classmethod + def align_address_to_page_end(cls, address): + """ + Align the given address to the end of the page it occupies. + That is, to point to the start of the next page. + + @type address: int + @param address: Memory address. + + @rtype: int + @return: Aligned memory address. + """ + return address + cls.pageSize - ( address % cls.pageSize ) + + @classmethod + def align_address_range(cls, begin, end): + """ + Align the given address range to the start and end of the page(s) it occupies. + + @type begin: int + @param begin: Memory address of the beginning of the buffer. + Use C{None} for the first legal address in the address space. + + @type end: int + @param end: Memory address of the end of the buffer. + Use C{None} for the last legal address in the address space. + + @rtype: tuple( int, int ) + @return: Aligned memory addresses. + """ + if begin is None: + begin = 0 + if end is None: + end = win32.LPVOID(-1).value # XXX HACK + if end < begin: + begin, end = end, begin + begin = cls.align_address_to_page_start(begin) + if end != cls.align_address_to_page_start(end): + end = cls.align_address_to_page_end(end) + return (begin, end) + + @classmethod + def get_buffer_size_in_pages(cls, address, size): + """ + Get the number of pages in use by the given buffer. + + @type address: int + @param address: Aligned memory address. + + @type size: int + @param size: Buffer size. + + @rtype: int + @return: Buffer size in number of pages. + """ + if size < 0: + size = -size + address = address - size + begin, end = cls.align_address_range(address, address + size) + # XXX FIXME + # I think this rounding fails at least for address 0xFFFFFFFF size 1 + return int(float(end - begin) / float(cls.pageSize)) + + @staticmethod + def do_ranges_intersect(begin, end, old_begin, old_end): + """ + Determine if the two given memory address ranges intersect. + + @type begin: int + @param begin: Start address of the first range. + + @type end: int + @param end: End address of the first range. + + @type old_begin: int + @param old_begin: Start address of the second range. + + @type old_end: int + @param old_end: End address of the second range. + + @rtype: bool + @return: C{True} if the two ranges intersect, C{False} otherwise. + """ + return (old_begin <= begin < old_end) or \ + (old_begin < end <= old_end) or \ + (begin <= old_begin < end) or \ + (begin < old_end <= end) + +#============================================================================== + +def CustomAddressIterator(memory_map, condition): + """ + Generator function that iterates through a memory map, filtering memory + region blocks by any given condition. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @type condition: function + @param condition: Callback function that returns C{True} if the memory + block should be returned, or C{False} if it should be filtered. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + for mbi in memory_map: + if condition(mbi): + address = mbi.BaseAddress + max_addr = address + mbi.RegionSize + while address < max_addr: + yield address + address = address + 1 + +def DataAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that contain data. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.has_content) + +def ImageAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that belong to executable images. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.is_image) + +def MappedAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that belong to memory mapped files. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.is_mapped) + +def ReadableAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that are readable. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.is_readable) + +def WriteableAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that are writeable. + + @note: Writeable memory is always readable too. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.is_writeable) + +def ExecutableAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that are executable. + + @note: Executable memory is always readable too. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.is_executable) + +def ExecutableAndWriteableAddressIterator(memory_map): + """ + Generator function that iterates through a memory map, returning only those + memory blocks that are executable and writeable. + + @note: The presence of such pages make memory corruption vulnerabilities + much easier to exploit. + + @type memory_map: list( L{win32.MemoryBasicInformation} ) + @param memory_map: List of memory region information objects. + Returned by L{Process.get_memory_map}. + + @rtype: generator of L{win32.MemoryBasicInformation} + @return: Generator object to iterate memory blocks. + """ + return CustomAddressIterator(memory_map, + win32.MemoryBasicInformation.is_executable_and_writeable) + +#============================================================================== +try: + _registerMask = win32.SIZE_T(-1).value +except TypeError: + if win32.SIZEOF(win32.SIZE_T) == 4: + _registerMask = 0xFFFFFFFF + elif win32.SIZEOF(win32.SIZE_T) == 8: + _registerMask = 0xFFFFFFFFFFFFFFFF + else: + raise + +class DebugRegister (StaticClass): + """ + Class to manipulate debug registers. + Used by L{HardwareBreakpoint}. + + @group Trigger flags used by HardwareBreakpoint: + BREAK_ON_EXECUTION, BREAK_ON_WRITE, BREAK_ON_ACCESS, BREAK_ON_IO_ACCESS + @group Size flags used by HardwareBreakpoint: + WATCH_BYTE, WATCH_WORD, WATCH_DWORD, WATCH_QWORD + @group Bitwise masks for Dr7: + enableMask, disableMask, triggerMask, watchMask, clearMask, + generalDetectMask + @group Bitwise masks for Dr6: + hitMask, hitMaskAll, debugAccessMask, singleStepMask, taskSwitchMask, + clearDr6Mask, clearHitMask + @group Debug control MSR definitions: + DebugCtlMSR, LastBranchRecord, BranchTrapFlag, PinControl, + LastBranchToIP, LastBranchFromIP, + LastExceptionToIP, LastExceptionFromIP + + @type BREAK_ON_EXECUTION: int + @cvar BREAK_ON_EXECUTION: Break on execution. + + @type BREAK_ON_WRITE: int + @cvar BREAK_ON_WRITE: Break on write. + + @type BREAK_ON_ACCESS: int + @cvar BREAK_ON_ACCESS: Break on read or write. + + @type BREAK_ON_IO_ACCESS: int + @cvar BREAK_ON_IO_ACCESS: Break on I/O port access. + Not supported by any hardware. + + @type WATCH_BYTE: int + @cvar WATCH_BYTE: Watch a byte. + + @type WATCH_WORD: int + @cvar WATCH_WORD: Watch a word. + + @type WATCH_DWORD: int + @cvar WATCH_DWORD: Watch a double word. + + @type WATCH_QWORD: int + @cvar WATCH_QWORD: Watch one quad word. + + @type enableMask: 4-tuple of integers + @cvar enableMask: + Enable bit on C{Dr7} for each slot. + Works as a bitwise-OR mask. + + @type disableMask: 4-tuple of integers + @cvar disableMask: + Mask of the enable bit on C{Dr7} for each slot. + Works as a bitwise-AND mask. + + @type triggerMask: 4-tuple of 2-tuples of integers + @cvar triggerMask: + Trigger bits on C{Dr7} for each trigger flag value. + Each 2-tuple has the bitwise-OR mask and the bitwise-AND mask. + + @type watchMask: 4-tuple of 2-tuples of integers + @cvar watchMask: + Watch bits on C{Dr7} for each watch flag value. + Each 2-tuple has the bitwise-OR mask and the bitwise-AND mask. + + @type clearMask: 4-tuple of integers + @cvar clearMask: + Mask of all important bits on C{Dr7} for each slot. + Works as a bitwise-AND mask. + + @type generalDetectMask: integer + @cvar generalDetectMask: + General detect mode bit. It enables the processor to notify the + debugger when the debugee is trying to access one of the debug + registers. + + @type hitMask: 4-tuple of integers + @cvar hitMask: + Hit bit on C{Dr6} for each slot. + Works as a bitwise-AND mask. + + @type hitMaskAll: integer + @cvar hitMaskAll: + Bitmask for all hit bits in C{Dr6}. Useful to know if at least one + hardware breakpoint was hit, or to clear the hit bits only. + + @type clearHitMask: integer + @cvar clearHitMask: + Bitmask to clear all the hit bits in C{Dr6}. + + @type debugAccessMask: integer + @cvar debugAccessMask: + The debugee tried to access a debug register. Needs bit + L{generalDetectMask} enabled in C{Dr7}. + + @type singleStepMask: integer + @cvar singleStepMask: + A single step exception was raised. Needs the trap flag enabled. + + @type taskSwitchMask: integer + @cvar taskSwitchMask: + A task switch has occurred. Needs the TSS T-bit set to 1. + + @type clearDr6Mask: integer + @cvar clearDr6Mask: + Bitmask to clear all meaningful bits in C{Dr6}. + """ + + BREAK_ON_EXECUTION = 0 + BREAK_ON_WRITE = 1 + BREAK_ON_ACCESS = 3 + BREAK_ON_IO_ACCESS = 2 + + WATCH_BYTE = 0 + WATCH_WORD = 1 + WATCH_DWORD = 3 + WATCH_QWORD = 2 + + registerMask = _registerMask + +#------------------------------------------------------------------------------ + + ########################################################################### + # http://en.wikipedia.org/wiki/Debug_register + # + # DR7 - Debug control + # + # The low-order eight bits of DR7 (0,2,4,6 and 1,3,5,7) selectively enable + # the four address breakpoint conditions. There are two levels of enabling: + # the local (0,2,4,6) and global (1,3,5,7) levels. The local enable bits + # are automatically reset by the processor at every task switch to avoid + # unwanted breakpoint conditions in the new task. The global enable bits + # are not reset by a task switch; therefore, they can be used for + # conditions that are global to all tasks. + # + # Bits 16-17 (DR0), 20-21 (DR1), 24-25 (DR2), 28-29 (DR3), define when + # breakpoints trigger. Each breakpoint has a two-bit entry that specifies + # whether they break on execution (00b), data write (01b), data read or + # write (11b). 10b is defined to mean break on IO read or write but no + # hardware supports it. Bits 18-19 (DR0), 22-23 (DR1), 26-27 (DR2), 30-31 + # (DR3), define how large area of memory is watched by breakpoints. Again + # each breakpoint has a two-bit entry that specifies whether they watch + # one (00b), two (01b), eight (10b) or four (11b) bytes. + ########################################################################### + + # Dr7 |= enableMask[register] + enableMask = ( + 1 << 0, # Dr0 (bit 0) + 1 << 2, # Dr1 (bit 2) + 1 << 4, # Dr2 (bit 4) + 1 << 6, # Dr3 (bit 6) + ) + + # Dr7 &= disableMask[register] + disableMask = tuple( [_registerMask ^ x for x in enableMask] ) # The registerMask from the class is not there in py3 + try: + del x # It's not there in py3 + except: + pass + + # orMask, andMask = triggerMask[register][trigger] + # Dr7 = (Dr7 & andMask) | orMask # to set + # Dr7 = Dr7 & andMask # to remove + triggerMask = ( + # Dr0 (bits 16-17) + ( + ((0 << 16), (3 << 16) ^ registerMask), # execute + ((1 << 16), (3 << 16) ^ registerMask), # write + ((2 << 16), (3 << 16) ^ registerMask), # io read + ((3 << 16), (3 << 16) ^ registerMask), # access + ), + # Dr1 (bits 20-21) + ( + ((0 << 20), (3 << 20) ^ registerMask), # execute + ((1 << 20), (3 << 20) ^ registerMask), # write + ((2 << 20), (3 << 20) ^ registerMask), # io read + ((3 << 20), (3 << 20) ^ registerMask), # access + ), + # Dr2 (bits 24-25) + ( + ((0 << 24), (3 << 24) ^ registerMask), # execute + ((1 << 24), (3 << 24) ^ registerMask), # write + ((2 << 24), (3 << 24) ^ registerMask), # io read + ((3 << 24), (3 << 24) ^ registerMask), # access + ), + # Dr3 (bits 28-29) + ( + ((0 << 28), (3 << 28) ^ registerMask), # execute + ((1 << 28), (3 << 28) ^ registerMask), # write + ((2 << 28), (3 << 28) ^ registerMask), # io read + ((3 << 28), (3 << 28) ^ registerMask), # access + ), + ) + + # orMask, andMask = watchMask[register][watch] + # Dr7 = (Dr7 & andMask) | orMask # to set + # Dr7 = Dr7 & andMask # to remove + watchMask = ( + # Dr0 (bits 18-19) + ( + ((0 << 18), (3 << 18) ^ registerMask), # byte + ((1 << 18), (3 << 18) ^ registerMask), # word + ((2 << 18), (3 << 18) ^ registerMask), # qword + ((3 << 18), (3 << 18) ^ registerMask), # dword + ), + # Dr1 (bits 22-23) + ( + ((0 << 23), (3 << 23) ^ registerMask), # byte + ((1 << 23), (3 << 23) ^ registerMask), # word + ((2 << 23), (3 << 23) ^ registerMask), # qword + ((3 << 23), (3 << 23) ^ registerMask), # dword + ), + # Dr2 (bits 26-27) + ( + ((0 << 26), (3 << 26) ^ registerMask), # byte + ((1 << 26), (3 << 26) ^ registerMask), # word + ((2 << 26), (3 << 26) ^ registerMask), # qword + ((3 << 26), (3 << 26) ^ registerMask), # dword + ), + # Dr3 (bits 30-31) + ( + ((0 << 30), (3 << 31) ^ registerMask), # byte + ((1 << 30), (3 << 31) ^ registerMask), # word + ((2 << 30), (3 << 31) ^ registerMask), # qword + ((3 << 30), (3 << 31) ^ registerMask), # dword + ), + ) + + # Dr7 = Dr7 & clearMask[register] + clearMask = ( + registerMask ^ ( (1 << 0) + (3 << 16) + (3 << 18) ), # Dr0 + registerMask ^ ( (1 << 2) + (3 << 20) + (3 << 22) ), # Dr1 + registerMask ^ ( (1 << 4) + (3 << 24) + (3 << 26) ), # Dr2 + registerMask ^ ( (1 << 6) + (3 << 28) + (3 << 30) ), # Dr3 + ) + + # Dr7 = Dr7 | generalDetectMask + generalDetectMask = (1 << 13) + + ########################################################################### + # http://en.wikipedia.org/wiki/Debug_register + # + # DR6 - Debug status + # + # The debug status register permits the debugger to determine which debug + # conditions have occurred. When the processor detects an enabled debug + # exception, it sets the low-order bits of this register (0,1,2,3) before + # entering the debug exception handler. + # + # Note that the bits of DR6 are never cleared by the processor. To avoid + # any confusion in identifying the next debug exception, the debug handler + # should move zeros to DR6 immediately before returning. + ########################################################################### + + # bool(Dr6 & hitMask[register]) + hitMask = ( + (1 << 0), # Dr0 + (1 << 1), # Dr1 + (1 << 2), # Dr2 + (1 << 3), # Dr3 + ) + + # bool(Dr6 & anyHitMask) + hitMaskAll = hitMask[0] | hitMask[1] | hitMask[2] | hitMask[3] + + # Dr6 = Dr6 & clearHitMask + clearHitMask = registerMask ^ hitMaskAll + + # bool(Dr6 & debugAccessMask) + debugAccessMask = (1 << 13) + + # bool(Dr6 & singleStepMask) + singleStepMask = (1 << 14) + + # bool(Dr6 & taskSwitchMask) + taskSwitchMask = (1 << 15) + + # Dr6 = Dr6 & clearDr6Mask + clearDr6Mask = registerMask ^ (hitMaskAll | \ + debugAccessMask | singleStepMask | taskSwitchMask) + +#------------------------------------------------------------------------------ + +############################################################################### +# +# (from the AMD64 manuals) +# +# The fields within the DebugCtlMSR register are: +# +# Last-Branch Record (LBR) - Bit 0, read/write. Software sets this bit to 1 +# to cause the processor to record the source and target addresses of the +# last control transfer taken before a debug exception occurs. The recorded +# control transfers include branch instructions, interrupts, and exceptions. +# +# Branch Single Step (BTF) - Bit 1, read/write. Software uses this bit to +# change the behavior of the rFLAGS.TF bit. When this bit is cleared to 0, +# the rFLAGS.TF bit controls instruction single stepping, (normal behavior). +# When this bit is set to 1, the rFLAGS.TF bit controls single stepping on +# control transfers. The single-stepped control transfers include branch +# instructions, interrupts, and exceptions. Control-transfer single stepping +# requires both BTF=1 and rFLAGS.TF=1. +# +# Performance-Monitoring/Breakpoint Pin-Control (PBi) - Bits 5-2, read/write. +# Software uses these bits to control the type of information reported by +# the four external performance-monitoring/breakpoint pins on the processor. +# When a PBi bit is cleared to 0, the corresponding external pin (BPi) +# reports performance-monitor information. When a PBi bit is set to 1, the +# corresponding external pin (BPi) reports breakpoint information. +# +# All remaining bits in the DebugCtlMSR register are reserved. +# +# Software can enable control-transfer single stepping by setting +# DebugCtlMSR.BTF to 1 and rFLAGS.TF to 1. The processor automatically +# disables control-transfer single stepping when a debug exception (#DB) +# occurs by clearing DebugCtlMSR.BTF to 0. rFLAGS.TF is also cleared when a +# #DB exception occurs. Before exiting the debug-exception handler, software +# must set both DebugCtlMSR.BTF and rFLAGS.TF to 1 to restart single +# stepping. +# +############################################################################### + + DebugCtlMSR = 0x1D9 + LastBranchRecord = (1 << 0) + BranchTrapFlag = (1 << 1) + PinControl = ( + (1 << 2), # PB1 + (1 << 3), # PB2 + (1 << 4), # PB3 + (1 << 5), # PB4 + ) + +############################################################################### +# +# (from the AMD64 manuals) +# +# Control-transfer recording MSRs: LastBranchToIP, LastBranchFromIP, +# LastExceptionToIP, and LastExceptionFromIP. These registers are loaded +# automatically by the processor when the DebugCtlMSR.LBR bit is set to 1. +# These MSRs are read-only. +# +# The processor automatically disables control-transfer recording when a +# debug exception (#DB) occurs by clearing DebugCtlMSR.LBR to 0. The +# contents of the control-transfer recording MSRs are not altered by the +# processor when the #DB occurs. Before exiting the debug-exception handler, +# software can set DebugCtlMSR.LBR to 1 to re-enable the recording mechanism. +# +############################################################################### + + LastBranchToIP = 0x1DC + LastBranchFromIP = 0x1DB + LastExceptionToIP = 0x1DE + LastExceptionFromIP = 0x1DD + +#------------------------------------------------------------------------------ + + @classmethod + def clear_bp(cls, ctx, register): + """ + Clears a hardware breakpoint. + + @see: find_slot, set_bp + + @type ctx: dict( str S{->} int ) + @param ctx: Thread context dictionary. + + @type register: int + @param register: Slot (debug register) for hardware breakpoint. + """ + ctx['Dr7'] &= cls.clearMask[register] + ctx['Dr%d' % register] = 0 + + @classmethod + def set_bp(cls, ctx, register, address, trigger, watch): + """ + Sets a hardware breakpoint. + + @see: clear_bp, find_slot + + @type ctx: dict( str S{->} int ) + @param ctx: Thread context dictionary. + + @type register: int + @param register: Slot (debug register). + + @type address: int + @param address: Memory address. + + @type trigger: int + @param trigger: Trigger flag. See L{HardwareBreakpoint.validTriggers}. + + @type watch: int + @param watch: Watch flag. See L{HardwareBreakpoint.validWatchSizes}. + """ + Dr7 = ctx['Dr7'] + Dr7 |= cls.enableMask[register] + orMask, andMask = cls.triggerMask[register][trigger] + Dr7 &= andMask + Dr7 |= orMask + orMask, andMask = cls.watchMask[register][watch] + Dr7 &= andMask + Dr7 |= orMask + ctx['Dr7'] = Dr7 + ctx['Dr%d' % register] = address + + @classmethod + def find_slot(cls, ctx): + """ + Finds an empty slot to set a hardware breakpoint. + + @see: clear_bp, set_bp + + @type ctx: dict( str S{->} int ) + @param ctx: Thread context dictionary. + + @rtype: int + @return: Slot (debug register) for hardware breakpoint. + """ + Dr7 = ctx['Dr7'] + slot = 0 + for m in cls.enableMask: + if (Dr7 & m) == 0: + return slot + slot += 1 + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__init__.py new file mode 100644 index 0000000..b5536c1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/__init__.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Debugging API wrappers in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32 import defines +from winappdbg.win32 import kernel32 +from winappdbg.win32 import user32 +from winappdbg.win32 import advapi32 +from winappdbg.win32 import wtsapi32 +from winappdbg.win32 import shell32 +from winappdbg.win32 import shlwapi +from winappdbg.win32 import psapi +from winappdbg.win32 import dbghelp +from winappdbg.win32 import ntdll + +from winappdbg.win32.defines import * +from winappdbg.win32.kernel32 import * +from winappdbg.win32.user32 import * +from winappdbg.win32.advapi32 import * +from winappdbg.win32.wtsapi32 import * +from winappdbg.win32.shell32 import * +from winappdbg.win32.shlwapi import * +from winappdbg.win32.psapi import * +from winappdbg.win32.dbghelp import * +from winappdbg.win32.ntdll import * + +# This calculates the list of exported symbols. +_all = set() +_all.update(defines._all) +_all.update(kernel32._all) +_all.update(user32._all) +_all.update(advapi32._all) +_all.update(wtsapi32._all) +_all.update(shell32._all) +_all.update(shlwapi._all) +_all.update(psapi._all) +_all.update(dbghelp._all) +_all.update(ntdll._all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/advapi32.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/advapi32.py new file mode 100644 index 0000000..4e49889 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/advapi32.py @@ -0,0 +1,3209 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for advapi32.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.kernel32 import * + +# XXX TODO +# + add transacted registry operations + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- Constants ---------------------------------------------------------------- + +# Privilege constants +SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege" +SE_AUDIT_NAME = "SeAuditPrivilege" +SE_BACKUP_NAME = "SeBackupPrivilege" +SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege" +SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege" +SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege" +SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege" +SE_CREATE_SYMBOLIC_LINK_NAME = "SeCreateSymbolicLinkPrivilege" +SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege" +SE_DEBUG_NAME = "SeDebugPrivilege" +SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege" +SE_IMPERSONATE_NAME = "SeImpersonatePrivilege" +SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege" +SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege" +SE_INC_WORKING_SET_NAME = "SeIncreaseWorkingSetPrivilege" +SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege" +SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege" +SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege" +SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege" +SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege" +SE_RELABEL_NAME = "SeRelabelPrivilege" +SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege" +SE_RESTORE_NAME = "SeRestorePrivilege" +SE_SECURITY_NAME = "SeSecurityPrivilege" +SE_SHUTDOWN_NAME = "SeShutdownPrivilege" +SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege" +SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege" +SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege" +SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege" +SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege" +SE_TCB_NAME = "SeTcbPrivilege" +SE_TIME_ZONE_NAME = "SeTimeZonePrivilege" +SE_TRUSTED_CREDMAN_ACCESS_NAME = "SeTrustedCredManAccessPrivilege" +SE_UNDOCK_NAME = "SeUndockPrivilege" +SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege" + +SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001 +SE_PRIVILEGE_ENABLED = 0x00000002 +SE_PRIVILEGE_REMOVED = 0x00000004 +SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000 + +TOKEN_ADJUST_PRIVILEGES = 0x00000020 + +LOGON_WITH_PROFILE = 0x00000001 +LOGON_NETCREDENTIALS_ONLY = 0x00000002 + +# Token access rights +TOKEN_ASSIGN_PRIMARY = 0x0001 +TOKEN_DUPLICATE = 0x0002 +TOKEN_IMPERSONATE = 0x0004 +TOKEN_QUERY = 0x0008 +TOKEN_QUERY_SOURCE = 0x0010 +TOKEN_ADJUST_PRIVILEGES = 0x0020 +TOKEN_ADJUST_GROUPS = 0x0040 +TOKEN_ADJUST_DEFAULT = 0x0080 +TOKEN_ADJUST_SESSIONID = 0x0100 +TOKEN_READ = (STANDARD_RIGHTS_READ | TOKEN_QUERY) +TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | + TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE | + TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT | + TOKEN_ADJUST_SESSIONID) + +# Predefined HKEY values +HKEY_CLASSES_ROOT = 0x80000000 +HKEY_CURRENT_USER = 0x80000001 +HKEY_LOCAL_MACHINE = 0x80000002 +HKEY_USERS = 0x80000003 +HKEY_PERFORMANCE_DATA = 0x80000004 +HKEY_CURRENT_CONFIG = 0x80000005 + +# Registry access rights +KEY_ALL_ACCESS = 0xF003F +KEY_CREATE_LINK = 0x0020 +KEY_CREATE_SUB_KEY = 0x0004 +KEY_ENUMERATE_SUB_KEYS = 0x0008 +KEY_EXECUTE = 0x20019 +KEY_NOTIFY = 0x0010 +KEY_QUERY_VALUE = 0x0001 +KEY_READ = 0x20019 +KEY_SET_VALUE = 0x0002 +KEY_WOW64_32KEY = 0x0200 +KEY_WOW64_64KEY = 0x0100 +KEY_WRITE = 0x20006 + +# Registry value types +REG_NONE = 0 +REG_SZ = 1 +REG_EXPAND_SZ = 2 +REG_BINARY = 3 +REG_DWORD = 4 +REG_DWORD_LITTLE_ENDIAN = REG_DWORD +REG_DWORD_BIG_ENDIAN = 5 +REG_LINK = 6 +REG_MULTI_SZ = 7 +REG_RESOURCE_LIST = 8 +REG_FULL_RESOURCE_DESCRIPTOR = 9 +REG_RESOURCE_REQUIREMENTS_LIST = 10 +REG_QWORD = 11 +REG_QWORD_LITTLE_ENDIAN = REG_QWORD + +#--- TOKEN_PRIVILEGE structure ------------------------------------------------ + +# typedef struct _LUID { +# DWORD LowPart; +# LONG HighPart; +# } LUID, +# *PLUID; +class LUID(Structure): + _fields_ = [ + ("LowPart", DWORD), + ("HighPart", LONG), + ] + +PLUID = POINTER(LUID) + +# typedef struct _LUID_AND_ATTRIBUTES { +# LUID Luid; +# DWORD Attributes; +# } LUID_AND_ATTRIBUTES, +# *PLUID_AND_ATTRIBUTES; +class LUID_AND_ATTRIBUTES(Structure): + _fields_ = [ + ("Luid", LUID), + ("Attributes", DWORD), + ] + +# typedef struct _TOKEN_PRIVILEGES { +# DWORD PrivilegeCount; +# LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; +# } TOKEN_PRIVILEGES, +# *PTOKEN_PRIVILEGES; +class TOKEN_PRIVILEGES(Structure): + _fields_ = [ + ("PrivilegeCount", DWORD), +## ("Privileges", LUID_AND_ATTRIBUTES * ANYSIZE_ARRAY), + ("Privileges", LUID_AND_ATTRIBUTES), + ] + # See comments on AdjustTokenPrivileges about this structure + +PTOKEN_PRIVILEGES = POINTER(TOKEN_PRIVILEGES) + +#--- GetTokenInformation enums and structures --------------------------------- + +# typedef enum _TOKEN_INFORMATION_CLASS { +# TokenUser = 1, +# TokenGroups, +# TokenPrivileges, +# TokenOwner, +# TokenPrimaryGroup, +# TokenDefaultDacl, +# TokenSource, +# TokenType, +# TokenImpersonationLevel, +# TokenStatistics, +# TokenRestrictedSids, +# TokenSessionId, +# TokenGroupsAndPrivileges, +# TokenSessionReference, +# TokenSandBoxInert, +# TokenAuditPolicy, +# TokenOrigin, +# TokenElevationType, +# TokenLinkedToken, +# TokenElevation, +# TokenHasRestrictions, +# TokenAccessInformation, +# TokenVirtualizationAllowed, +# TokenVirtualizationEnabled, +# TokenIntegrityLevel, +# TokenUIAccess, +# TokenMandatoryPolicy, +# TokenLogonSid, +# TokenIsAppContainer, +# TokenCapabilities, +# TokenAppContainerSid, +# TokenAppContainerNumber, +# TokenUserClaimAttributes, +# TokenDeviceClaimAttributes, +# TokenRestrictedUserClaimAttributes, +# TokenRestrictedDeviceClaimAttributes, +# TokenDeviceGroups, +# TokenRestrictedDeviceGroups, +# TokenSecurityAttributes, +# TokenIsRestricted, +# MaxTokenInfoClass +# } TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS; + +TOKEN_INFORMATION_CLASS = ctypes.c_int + +TokenUser = 1 +TokenGroups = 2 +TokenPrivileges = 3 +TokenOwner = 4 +TokenPrimaryGroup = 5 +TokenDefaultDacl = 6 +TokenSource = 7 +TokenType = 8 +TokenImpersonationLevel = 9 +TokenStatistics = 10 +TokenRestrictedSids = 11 +TokenSessionId = 12 +TokenGroupsAndPrivileges = 13 +TokenSessionReference = 14 +TokenSandBoxInert = 15 +TokenAuditPolicy = 16 +TokenOrigin = 17 +TokenElevationType = 18 +TokenLinkedToken = 19 +TokenElevation = 20 +TokenHasRestrictions = 21 +TokenAccessInformation = 22 +TokenVirtualizationAllowed = 23 +TokenVirtualizationEnabled = 24 +TokenIntegrityLevel = 25 +TokenUIAccess = 26 +TokenMandatoryPolicy = 27 +TokenLogonSid = 28 +TokenIsAppContainer = 29 +TokenCapabilities = 30 +TokenAppContainerSid = 31 +TokenAppContainerNumber = 32 +TokenUserClaimAttributes = 33 +TokenDeviceClaimAttributes = 34 +TokenRestrictedUserClaimAttributes = 35 +TokenRestrictedDeviceClaimAttributes = 36 +TokenDeviceGroups = 37 +TokenRestrictedDeviceGroups = 38 +TokenSecurityAttributes = 39 +TokenIsRestricted = 40 +MaxTokenInfoClass = 41 + +# typedef enum tagTOKEN_TYPE { +# TokenPrimary = 1, +# TokenImpersonation +# } TOKEN_TYPE, *PTOKEN_TYPE; + +TOKEN_TYPE = ctypes.c_int +PTOKEN_TYPE = POINTER(TOKEN_TYPE) + +TokenPrimary = 1 +TokenImpersonation = 2 + +# typedef enum { +# TokenElevationTypeDefault = 1, +# TokenElevationTypeFull, +# TokenElevationTypeLimited +# } TOKEN_ELEVATION_TYPE , *PTOKEN_ELEVATION_TYPE; + +TokenElevationTypeDefault = 1 +TokenElevationTypeFull = 2 +TokenElevationTypeLimited = 3 + +TOKEN_ELEVATION_TYPE = ctypes.c_int +PTOKEN_ELEVATION_TYPE = POINTER(TOKEN_ELEVATION_TYPE) + +# typedef enum _SECURITY_IMPERSONATION_LEVEL { +# SecurityAnonymous, +# SecurityIdentification, +# SecurityImpersonation, +# SecurityDelegation +# } SECURITY_IMPERSONATION_LEVEL, *PSECURITY_IMPERSONATION_LEVEL; + +SecurityAnonymous = 0 +SecurityIdentification = 1 +SecurityImpersonation = 2 +SecurityDelegation = 3 + +SECURITY_IMPERSONATION_LEVEL = ctypes.c_int +PSECURITY_IMPERSONATION_LEVEL = POINTER(SECURITY_IMPERSONATION_LEVEL) + +# typedef struct _SID_AND_ATTRIBUTES { +# PSID Sid; +# DWORD Attributes; +# } SID_AND_ATTRIBUTES, *PSID_AND_ATTRIBUTES; +class SID_AND_ATTRIBUTES(Structure): + _fields_ = [ + ("Sid", PSID), + ("Attributes", DWORD), + ] +PSID_AND_ATTRIBUTES = POINTER(SID_AND_ATTRIBUTES) + +# typedef struct _TOKEN_USER { +# SID_AND_ATTRIBUTES User; +# } TOKEN_USER, *PTOKEN_USER; +class TOKEN_USER(Structure): + _fields_ = [ + ("User", SID_AND_ATTRIBUTES), + ] +PTOKEN_USER = POINTER(TOKEN_USER) + +# typedef struct _TOKEN_MANDATORY_LABEL { +# SID_AND_ATTRIBUTES Label; +# } TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL; +class TOKEN_MANDATORY_LABEL(Structure): + _fields_ = [ + ("Label", SID_AND_ATTRIBUTES), + ] +PTOKEN_MANDATORY_LABEL = POINTER(TOKEN_MANDATORY_LABEL) + +# typedef struct _TOKEN_OWNER { +# PSID Owner; +# } TOKEN_OWNER, *PTOKEN_OWNER; +class TOKEN_OWNER(Structure): + _fields_ = [ + ("Owner", PSID), + ] +PTOKEN_OWNER = POINTER(TOKEN_OWNER) + +# typedef struct _TOKEN_PRIMARY_GROUP { +# PSID PrimaryGroup; +# } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP; +class TOKEN_PRIMARY_GROUP(Structure): + _fields_ = [ + ("PrimaryGroup", PSID), + ] +PTOKEN_PRIMARY_GROUP = POINTER(TOKEN_PRIMARY_GROUP) + +# typedef struct _TOKEN_APPCONTAINER_INFORMATION { +# PSID TokenAppContainer; +# } TOKEN_APPCONTAINER_INFORMATION, *PTOKEN_APPCONTAINER_INFORMATION; +class TOKEN_APPCONTAINER_INFORMATION(Structure): + _fields_ = [ + ("TokenAppContainer", PSID), + ] +PTOKEN_APPCONTAINER_INFORMATION = POINTER(TOKEN_APPCONTAINER_INFORMATION) + +# typedef struct _TOKEN_ORIGIN { +# LUID OriginatingLogonSession; +# } TOKEN_ORIGIN, *PTOKEN_ORIGIN; +class TOKEN_ORIGIN(Structure): + _fields_ = [ + ("OriginatingLogonSession", LUID), + ] +PTOKEN_ORIGIN = POINTER(TOKEN_ORIGIN) + +# typedef struct _TOKEN_LINKED_TOKEN { +# HANDLE LinkedToken; +# } TOKEN_LINKED_TOKEN, *PTOKEN_LINKED_TOKEN; +class TOKEN_LINKED_TOKEN(Structure): + _fields_ = [ + ("LinkedToken", HANDLE), + ] +PTOKEN_LINKED_TOKEN = POINTER(TOKEN_LINKED_TOKEN) + +# typedef struct _TOKEN_STATISTICS { +# LUID TokenId; +# LUID AuthenticationId; +# LARGE_INTEGER ExpirationTime; +# TOKEN_TYPE TokenType; +# SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; +# DWORD DynamicCharged; +# DWORD DynamicAvailable; +# DWORD GroupCount; +# DWORD PrivilegeCount; +# LUID ModifiedId; +# } TOKEN_STATISTICS, *PTOKEN_STATISTICS; +class TOKEN_STATISTICS(Structure): + _fields_ = [ + ("TokenId", LUID), + ("AuthenticationId", LUID), + ("ExpirationTime", LONGLONG), # LARGE_INTEGER + ("TokenType", TOKEN_TYPE), + ("ImpersonationLevel", SECURITY_IMPERSONATION_LEVEL), + ("DynamicCharged", DWORD), + ("DynamicAvailable", DWORD), + ("GroupCount", DWORD), + ("PrivilegeCount", DWORD), + ("ModifiedId", LUID), + ] +PTOKEN_STATISTICS = POINTER(TOKEN_STATISTICS) + +#--- SID_NAME_USE enum -------------------------------------------------------- + +# typedef enum _SID_NAME_USE { +# SidTypeUser = 1, +# SidTypeGroup, +# SidTypeDomain, +# SidTypeAlias, +# SidTypeWellKnownGroup, +# SidTypeDeletedAccount, +# SidTypeInvalid, +# SidTypeUnknown, +# SidTypeComputer, +# SidTypeLabel +# } SID_NAME_USE, *PSID_NAME_USE; + +SidTypeUser = 1 +SidTypeGroup = 2 +SidTypeDomain = 3 +SidTypeAlias = 4 +SidTypeWellKnownGroup = 5 +SidTypeDeletedAccount = 6 +SidTypeInvalid = 7 +SidTypeUnknown = 8 +SidTypeComputer = 9 +SidTypeLabel = 10 + +#--- WAITCHAIN_NODE_INFO structure and types ---------------------------------- + +WCT_MAX_NODE_COUNT = 16 +WCT_OBJNAME_LENGTH = 128 +WCT_ASYNC_OPEN_FLAG = 1 +WCTP_OPEN_ALL_FLAGS = WCT_ASYNC_OPEN_FLAG +WCT_OUT_OF_PROC_FLAG = 1 +WCT_OUT_OF_PROC_COM_FLAG = 2 +WCT_OUT_OF_PROC_CS_FLAG = 4 +WCTP_GETINFO_ALL_FLAGS = WCT_OUT_OF_PROC_FLAG | WCT_OUT_OF_PROC_COM_FLAG | WCT_OUT_OF_PROC_CS_FLAG + +HWCT = LPVOID + +# typedef enum _WCT_OBJECT_TYPE +# { +# WctCriticalSectionType = 1, +# WctSendMessageType, +# WctMutexType, +# WctAlpcType, +# WctComType, +# WctThreadWaitType, +# WctProcessWaitType, +# WctThreadType, +# WctComActivationType, +# WctUnknownType, +# WctMaxType +# } WCT_OBJECT_TYPE; + +WCT_OBJECT_TYPE = DWORD + +WctCriticalSectionType = 1 +WctSendMessageType = 2 +WctMutexType = 3 +WctAlpcType = 4 +WctComType = 5 +WctThreadWaitType = 6 +WctProcessWaitType = 7 +WctThreadType = 8 +WctComActivationType = 9 +WctUnknownType = 10 +WctMaxType = 11 + +# typedef enum _WCT_OBJECT_STATUS +# { +# WctStatusNoAccess = 1, // ACCESS_DENIED for this object +# WctStatusRunning, // Thread status +# WctStatusBlocked, // Thread status +# WctStatusPidOnly, // Thread status +# WctStatusPidOnlyRpcss, // Thread status +# WctStatusOwned, // Dispatcher object status +# WctStatusNotOwned, // Dispatcher object status +# WctStatusAbandoned, // Dispatcher object status +# WctStatusUnknown, // All objects +# WctStatusError, // All objects +# WctStatusMax +# } WCT_OBJECT_STATUS; + +WCT_OBJECT_STATUS = DWORD + +WctStatusNoAccess = 1 # ACCESS_DENIED for this object +WctStatusRunning = 2 # Thread status +WctStatusBlocked = 3 # Thread status +WctStatusPidOnly = 4 # Thread status +WctStatusPidOnlyRpcss = 5 # Thread status +WctStatusOwned = 6 # Dispatcher object status +WctStatusNotOwned = 7 # Dispatcher object status +WctStatusAbandoned = 8 # Dispatcher object status +WctStatusUnknown = 9 # All objects +WctStatusError = 10 # All objects +WctStatusMax = 11 + +# typedef struct _WAITCHAIN_NODE_INFO { +# WCT_OBJECT_TYPE ObjectType; +# WCT_OBJECT_STATUS ObjectStatus; +# union { +# struct { +# WCHAR ObjectName[WCT_OBJNAME_LENGTH]; +# LARGE_INTEGER Timeout; +# BOOL Alertable; +# } LockObject; +# struct { +# DWORD ProcessId; +# DWORD ThreadId; +# DWORD WaitTime; +# DWORD ContextSwitches; +# } ThreadObject; +# } ; +# }WAITCHAIN_NODE_INFO, *PWAITCHAIN_NODE_INFO; + +class _WAITCHAIN_NODE_INFO_STRUCT_1(Structure): + _fields_ = [ + ("ObjectName", WCHAR * WCT_OBJNAME_LENGTH), + ("Timeout", LONGLONG), # LARGE_INTEGER + ("Alertable", BOOL), + ] + +class _WAITCHAIN_NODE_INFO_STRUCT_2(Structure): + _fields_ = [ + ("ProcessId", DWORD), + ("ThreadId", DWORD), + ("WaitTime", DWORD), + ("ContextSwitches", DWORD), + ] + +class _WAITCHAIN_NODE_INFO_UNION(Union): + _fields_ = [ + ("LockObject", _WAITCHAIN_NODE_INFO_STRUCT_1), + ("ThreadObject", _WAITCHAIN_NODE_INFO_STRUCT_2), + ] + +class WAITCHAIN_NODE_INFO(Structure): + _fields_ = [ + ("ObjectType", WCT_OBJECT_TYPE), + ("ObjectStatus", WCT_OBJECT_STATUS), + ("u", _WAITCHAIN_NODE_INFO_UNION), + ] + +PWAITCHAIN_NODE_INFO = POINTER(WAITCHAIN_NODE_INFO) + +class WaitChainNodeInfo (object): + """ + Represents a node in the wait chain. + + It's a wrapper on the L{WAITCHAIN_NODE_INFO} structure. + + The following members are defined only + if the node is of L{WctThreadType} type: + - C{ProcessId} + - C{ThreadId} + - C{WaitTime} + - C{ContextSwitches} + + @see: L{GetThreadWaitChain} + + @type ObjectName: unicode + @ivar ObjectName: Object name. May be an empty string. + + @type ObjectType: int + @ivar ObjectType: Object type. + Should be one of the following values: + - L{WctCriticalSectionType} + - L{WctSendMessageType} + - L{WctMutexType} + - L{WctAlpcType} + - L{WctComType} + - L{WctThreadWaitType} + - L{WctProcessWaitType} + - L{WctThreadType} + - L{WctComActivationType} + - L{WctUnknownType} + + @type ObjectStatus: int + @ivar ObjectStatus: Wait status. + Should be one of the following values: + - L{WctStatusNoAccess} I{(ACCESS_DENIED for this object)} + - L{WctStatusRunning} I{(Thread status)} + - L{WctStatusBlocked} I{(Thread status)} + - L{WctStatusPidOnly} I{(Thread status)} + - L{WctStatusPidOnlyRpcss} I{(Thread status)} + - L{WctStatusOwned} I{(Dispatcher object status)} + - L{WctStatusNotOwned} I{(Dispatcher object status)} + - L{WctStatusAbandoned} I{(Dispatcher object status)} + - L{WctStatusUnknown} I{(All objects)} + - L{WctStatusError} I{(All objects)} + + @type ProcessId: int + @ivar ProcessId: Process global ID. + + @type ThreadId: int + @ivar ThreadId: Thread global ID. + + @type WaitTime: int + @ivar WaitTime: Wait time. + + @type ContextSwitches: int + @ivar ContextSwitches: Number of context switches. + """ + + #@type Timeout: int + #@ivar Timeout: Currently not documented in MSDN. + # + #@type Alertable: bool + #@ivar Alertable: Currently not documented in MSDN. + + # TODO: __repr__ + + def __init__(self, aStructure): + self.ObjectType = aStructure.ObjectType + self.ObjectStatus = aStructure.ObjectStatus + if self.ObjectType == WctThreadType: + self.ProcessId = aStructure.u.ThreadObject.ProcessId + self.ThreadId = aStructure.u.ThreadObject.ThreadId + self.WaitTime = aStructure.u.ThreadObject.WaitTime + self.ContextSwitches = aStructure.u.ThreadObject.ContextSwitches + self.ObjectName = u'' + else: + self.ObjectName = aStructure.u.LockObject.ObjectName.value + #self.Timeout = aStructure.u.LockObject.Timeout + #self.Alertable = bool(aStructure.u.LockObject.Alertable) + +class ThreadWaitChainSessionHandle (Handle): + """ + Thread wait chain session handle. + + Returned by L{OpenThreadWaitChainSession}. + + @see: L{Handle} + """ + + def __init__(self, aHandle = None): + """ + @type aHandle: int + @param aHandle: Win32 handle value. + """ + super(ThreadWaitChainSessionHandle, self).__init__(aHandle, + bOwnership = True) + + def _close(self): + if self.value is None: + raise ValueError("Handle was already closed!") + CloseThreadWaitChainSession(self.value) + + def dup(self): + raise NotImplementedError() + + def wait(self, dwMilliseconds = None): + raise NotImplementedError() + + @property + def inherit(self): + return False + + @property + def protectFromClose(self): + return False + +#--- Privilege dropping ------------------------------------------------------- + +SAFER_LEVEL_HANDLE = HANDLE + +SAFER_SCOPEID_MACHINE = 1 +SAFER_SCOPEID_USER = 2 + +SAFER_LEVEL_OPEN = 1 + +SAFER_LEVELID_DISALLOWED = 0x00000 +SAFER_LEVELID_UNTRUSTED = 0x01000 +SAFER_LEVELID_CONSTRAINED = 0x10000 +SAFER_LEVELID_NORMALUSER = 0x20000 +SAFER_LEVELID_FULLYTRUSTED = 0x40000 + +SAFER_POLICY_INFO_CLASS = DWORD +SaferPolicyLevelList = 1 +SaferPolicyEnableTransparentEnforcement = 2 +SaferPolicyDefaultLevel = 3 +SaferPolicyEvaluateUserScope = 4 +SaferPolicyScopeFlags = 5 + +SAFER_TOKEN_NULL_IF_EQUAL = 1 +SAFER_TOKEN_COMPARE_ONLY = 2 +SAFER_TOKEN_MAKE_INERT = 4 +SAFER_TOKEN_WANT_FLAGS = 8 +SAFER_TOKEN_MASK = 15 + +#--- Service Control Manager types, constants and structures ------------------ + +SC_HANDLE = HANDLE + +SERVICES_ACTIVE_DATABASEW = u"ServicesActive" +SERVICES_FAILED_DATABASEW = u"ServicesFailed" + +SERVICES_ACTIVE_DATABASEA = "ServicesActive" +SERVICES_FAILED_DATABASEA = "ServicesFailed" + +SC_GROUP_IDENTIFIERW = u'+' +SC_GROUP_IDENTIFIERA = '+' + +SERVICE_NO_CHANGE = 0xffffffff + +# enum SC_STATUS_TYPE +SC_STATUS_TYPE = ctypes.c_int +SC_STATUS_PROCESS_INFO = 0 + +# enum SC_ENUM_TYPE +SC_ENUM_TYPE = ctypes.c_int +SC_ENUM_PROCESS_INFO = 0 + +# Access rights +# http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx + +SERVICE_ALL_ACCESS = 0xF01FF +SERVICE_QUERY_CONFIG = 0x0001 +SERVICE_CHANGE_CONFIG = 0x0002 +SERVICE_QUERY_STATUS = 0x0004 +SERVICE_ENUMERATE_DEPENDENTS = 0x0008 +SERVICE_START = 0x0010 +SERVICE_STOP = 0x0020 +SERVICE_PAUSE_CONTINUE = 0x0040 +SERVICE_INTERROGATE = 0x0080 +SERVICE_USER_DEFINED_CONTROL = 0x0100 + +SC_MANAGER_ALL_ACCESS = 0xF003F +SC_MANAGER_CONNECT = 0x0001 +SC_MANAGER_CREATE_SERVICE = 0x0002 +SC_MANAGER_ENUMERATE_SERVICE = 0x0004 +SC_MANAGER_LOCK = 0x0008 +SC_MANAGER_QUERY_LOCK_STATUS = 0x0010 +SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020 + +# CreateService() service start type +SERVICE_BOOT_START = 0x00000000 +SERVICE_SYSTEM_START = 0x00000001 +SERVICE_AUTO_START = 0x00000002 +SERVICE_DEMAND_START = 0x00000003 +SERVICE_DISABLED = 0x00000004 + +# CreateService() error control flags +SERVICE_ERROR_IGNORE = 0x00000000 +SERVICE_ERROR_NORMAL = 0x00000001 +SERVICE_ERROR_SEVERE = 0x00000002 +SERVICE_ERROR_CRITICAL = 0x00000003 + +# EnumServicesStatusEx() service state filters +SERVICE_ACTIVE = 1 +SERVICE_INACTIVE = 2 +SERVICE_STATE_ALL = 3 + +# SERVICE_STATUS_PROCESS.dwServiceType +SERVICE_KERNEL_DRIVER = 0x00000001 +SERVICE_FILE_SYSTEM_DRIVER = 0x00000002 +SERVICE_ADAPTER = 0x00000004 +SERVICE_RECOGNIZER_DRIVER = 0x00000008 +SERVICE_WIN32_OWN_PROCESS = 0x00000010 +SERVICE_WIN32_SHARE_PROCESS = 0x00000020 +SERVICE_INTERACTIVE_PROCESS = 0x00000100 + +# EnumServicesStatusEx() service type filters (in addition to actual types) +SERVICE_DRIVER = 0x0000000B # SERVICE_KERNEL_DRIVER and SERVICE_FILE_SYSTEM_DRIVER +SERVICE_WIN32 = 0x00000030 # SERVICE_WIN32_OWN_PROCESS and SERVICE_WIN32_SHARE_PROCESS + +# SERVICE_STATUS_PROCESS.dwCurrentState +SERVICE_STOPPED = 0x00000001 +SERVICE_START_PENDING = 0x00000002 +SERVICE_STOP_PENDING = 0x00000003 +SERVICE_RUNNING = 0x00000004 +SERVICE_CONTINUE_PENDING = 0x00000005 +SERVICE_PAUSE_PENDING = 0x00000006 +SERVICE_PAUSED = 0x00000007 + +# SERVICE_STATUS_PROCESS.dwControlsAccepted +SERVICE_ACCEPT_STOP = 0x00000001 +SERVICE_ACCEPT_PAUSE_CONTINUE = 0x00000002 +SERVICE_ACCEPT_SHUTDOWN = 0x00000004 +SERVICE_ACCEPT_PARAMCHANGE = 0x00000008 +SERVICE_ACCEPT_NETBINDCHANGE = 0x00000010 +SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 0x00000020 +SERVICE_ACCEPT_POWEREVENT = 0x00000040 +SERVICE_ACCEPT_SESSIONCHANGE = 0x00000080 +SERVICE_ACCEPT_PRESHUTDOWN = 0x00000100 + +# SERVICE_STATUS_PROCESS.dwServiceFlags +SERVICE_RUNS_IN_SYSTEM_PROCESS = 0x00000001 + +# Service control flags +SERVICE_CONTROL_STOP = 0x00000001 +SERVICE_CONTROL_PAUSE = 0x00000002 +SERVICE_CONTROL_CONTINUE = 0x00000003 +SERVICE_CONTROL_INTERROGATE = 0x00000004 +SERVICE_CONTROL_SHUTDOWN = 0x00000005 +SERVICE_CONTROL_PARAMCHANGE = 0x00000006 +SERVICE_CONTROL_NETBINDADD = 0x00000007 +SERVICE_CONTROL_NETBINDREMOVE = 0x00000008 +SERVICE_CONTROL_NETBINDENABLE = 0x00000009 +SERVICE_CONTROL_NETBINDDISABLE = 0x0000000A +SERVICE_CONTROL_DEVICEEVENT = 0x0000000B +SERVICE_CONTROL_HARDWAREPROFILECHANGE = 0x0000000C +SERVICE_CONTROL_POWEREVENT = 0x0000000D +SERVICE_CONTROL_SESSIONCHANGE = 0x0000000E + +# Service control accepted bitmasks +SERVICE_ACCEPT_STOP = 0x00000001 +SERVICE_ACCEPT_PAUSE_CONTINUE = 0x00000002 +SERVICE_ACCEPT_SHUTDOWN = 0x00000004 +SERVICE_ACCEPT_PARAMCHANGE = 0x00000008 +SERVICE_ACCEPT_NETBINDCHANGE = 0x00000010 +SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 0x00000020 +SERVICE_ACCEPT_POWEREVENT = 0x00000040 +SERVICE_ACCEPT_SESSIONCHANGE = 0x00000080 +SERVICE_ACCEPT_PRESHUTDOWN = 0x00000100 +SERVICE_ACCEPT_TIMECHANGE = 0x00000200 +SERVICE_ACCEPT_TRIGGEREVENT = 0x00000400 +SERVICE_ACCEPT_USERMODEREBOOT = 0x00000800 + +# enum SC_ACTION_TYPE +SC_ACTION_NONE = 0 +SC_ACTION_RESTART = 1 +SC_ACTION_REBOOT = 2 +SC_ACTION_RUN_COMMAND = 3 + +# QueryServiceConfig2 +SERVICE_CONFIG_DESCRIPTION = 1 +SERVICE_CONFIG_FAILURE_ACTIONS = 2 + +# typedef struct _SERVICE_STATUS { +# DWORD dwServiceType; +# DWORD dwCurrentState; +# DWORD dwControlsAccepted; +# DWORD dwWin32ExitCode; +# DWORD dwServiceSpecificExitCode; +# DWORD dwCheckPoint; +# DWORD dwWaitHint; +# } SERVICE_STATUS, *LPSERVICE_STATUS; +class SERVICE_STATUS(Structure): + _fields_ = [ + ("dwServiceType", DWORD), + ("dwCurrentState", DWORD), + ("dwControlsAccepted", DWORD), + ("dwWin32ExitCode", DWORD), + ("dwServiceSpecificExitCode", DWORD), + ("dwCheckPoint", DWORD), + ("dwWaitHint", DWORD), + ] +LPSERVICE_STATUS = POINTER(SERVICE_STATUS) + +# typedef struct _SERVICE_STATUS_PROCESS { +# DWORD dwServiceType; +# DWORD dwCurrentState; +# DWORD dwControlsAccepted; +# DWORD dwWin32ExitCode; +# DWORD dwServiceSpecificExitCode; +# DWORD dwCheckPoint; +# DWORD dwWaitHint; +# DWORD dwProcessId; +# DWORD dwServiceFlags; +# } SERVICE_STATUS_PROCESS, *LPSERVICE_STATUS_PROCESS; +class SERVICE_STATUS_PROCESS(Structure): + _fields_ = SERVICE_STATUS._fields_ + [ + ("dwProcessId", DWORD), + ("dwServiceFlags", DWORD), + ] +LPSERVICE_STATUS_PROCESS = POINTER(SERVICE_STATUS_PROCESS) + +# typedef struct _ENUM_SERVICE_STATUS { +# LPTSTR lpServiceName; +# LPTSTR lpDisplayName; +# SERVICE_STATUS ServiceStatus; +# } ENUM_SERVICE_STATUS, *LPENUM_SERVICE_STATUS; +class ENUM_SERVICE_STATUSA(Structure): + _fields_ = [ + ("lpServiceName", LPSTR), + ("lpDisplayName", LPSTR), + ("ServiceStatus", SERVICE_STATUS), + ] +class ENUM_SERVICE_STATUSW(Structure): + _fields_ = [ + ("lpServiceName", LPWSTR), + ("lpDisplayName", LPWSTR), + ("ServiceStatus", SERVICE_STATUS), + ] +LPENUM_SERVICE_STATUSA = POINTER(ENUM_SERVICE_STATUSA) +LPENUM_SERVICE_STATUSW = POINTER(ENUM_SERVICE_STATUSW) + +# typedef struct _ENUM_SERVICE_STATUS_PROCESS { +# LPTSTR lpServiceName; +# LPTSTR lpDisplayName; +# SERVICE_STATUS_PROCESS ServiceStatusProcess; +# } ENUM_SERVICE_STATUS_PROCESS, *LPENUM_SERVICE_STATUS_PROCESS; +class ENUM_SERVICE_STATUS_PROCESSA(Structure): + _fields_ = [ + ("lpServiceName", LPSTR), + ("lpDisplayName", LPSTR), + ("ServiceStatusProcess", SERVICE_STATUS_PROCESS), + ] +class ENUM_SERVICE_STATUS_PROCESSW(Structure): + _fields_ = [ + ("lpServiceName", LPWSTR), + ("lpDisplayName", LPWSTR), + ("ServiceStatusProcess", SERVICE_STATUS_PROCESS), + ] +LPENUM_SERVICE_STATUS_PROCESSA = POINTER(ENUM_SERVICE_STATUS_PROCESSA) +LPENUM_SERVICE_STATUS_PROCESSW = POINTER(ENUM_SERVICE_STATUS_PROCESSW) + +class ServiceStatus(object): + """ + Wrapper for the L{SERVICE_STATUS} structure. + """ + + def __init__(self, raw): + """ + @type raw: L{SERVICE_STATUS} + @param raw: Raw structure for this service status data. + """ + self.ServiceType = raw.dwServiceType + self.CurrentState = raw.dwCurrentState + self.ControlsAccepted = raw.dwControlsAccepted + self.Win32ExitCode = raw.dwWin32ExitCode + self.ServiceSpecificExitCode = raw.dwServiceSpecificExitCode + self.CheckPoint = raw.dwCheckPoint + self.WaitHint = raw.dwWaitHint + +class ServiceStatusProcess(object): + """ + Wrapper for the L{SERVICE_STATUS_PROCESS} structure. + """ + + def __init__(self, raw): + """ + @type raw: L{SERVICE_STATUS_PROCESS} + @param raw: Raw structure for this service status data. + """ + self.ServiceType = raw.dwServiceType + self.CurrentState = raw.dwCurrentState + self.ControlsAccepted = raw.dwControlsAccepted + self.Win32ExitCode = raw.dwWin32ExitCode + self.ServiceSpecificExitCode = raw.dwServiceSpecificExitCode + self.CheckPoint = raw.dwCheckPoint + self.WaitHint = raw.dwWaitHint + self.ProcessId = raw.dwProcessId + self.ServiceFlags = raw.dwServiceFlags + +class ServiceStatusEntry(object): + """ + Service status entry returned by L{EnumServicesStatus}. + """ + + def __init__(self, raw): + """ + @type raw: L{ENUM_SERVICE_STATUSA} or L{ENUM_SERVICE_STATUSW} + @param raw: Raw structure for this service status entry. + """ + self.ServiceName = raw.lpServiceName + self.DisplayName = raw.lpDisplayName + self.ServiceType = raw.ServiceStatus.dwServiceType + self.CurrentState = raw.ServiceStatus.dwCurrentState + self.ControlsAccepted = raw.ServiceStatus.dwControlsAccepted + self.Win32ExitCode = raw.ServiceStatus.dwWin32ExitCode + self.ServiceSpecificExitCode = raw.ServiceStatus.dwServiceSpecificExitCode + self.CheckPoint = raw.ServiceStatus.dwCheckPoint + self.WaitHint = raw.ServiceStatus.dwWaitHint + + def __str__(self): + output = [] + if self.ServiceType & SERVICE_INTERACTIVE_PROCESS: + output.append("Interactive service") + else: + output.append("Service") + if self.DisplayName: + output.append("\"%s\" (%s)" % (self.DisplayName, self.ServiceName)) + else: + output.append("\"%s\"" % self.ServiceName) + if self.CurrentState == SERVICE_CONTINUE_PENDING: + output.append("is about to continue.") + elif self.CurrentState == SERVICE_PAUSE_PENDING: + output.append("is pausing.") + elif self.CurrentState == SERVICE_PAUSED: + output.append("is paused.") + elif self.CurrentState == SERVICE_RUNNING: + output.append("is running.") + elif self.CurrentState == SERVICE_START_PENDING: + output.append("is starting.") + elif self.CurrentState == SERVICE_STOP_PENDING: + output.append("is stopping.") + elif self.CurrentState == SERVICE_STOPPED: + output.append("is stopped.") + return " ".join(output) + +class ServiceStatusProcessEntry(object): + """ + Service status entry returned by L{EnumServicesStatusEx}. + """ + + def __init__(self, raw): + """ + @type raw: L{ENUM_SERVICE_STATUS_PROCESSA} or L{ENUM_SERVICE_STATUS_PROCESSW} + @param raw: Raw structure for this service status entry. + """ + self.ServiceName = raw.lpServiceName + self.DisplayName = raw.lpDisplayName + self.ServiceType = raw.ServiceStatusProcess.dwServiceType + self.CurrentState = raw.ServiceStatusProcess.dwCurrentState + self.ControlsAccepted = raw.ServiceStatusProcess.dwControlsAccepted + self.Win32ExitCode = raw.ServiceStatusProcess.dwWin32ExitCode + self.ServiceSpecificExitCode = raw.ServiceStatusProcess.dwServiceSpecificExitCode + self.CheckPoint = raw.ServiceStatusProcess.dwCheckPoint + self.WaitHint = raw.ServiceStatusProcess.dwWaitHint + self.ProcessId = raw.ServiceStatusProcess.dwProcessId + self.ServiceFlags = raw.ServiceStatusProcess.dwServiceFlags + + def __str__(self): + output = [] + if self.ServiceType & SERVICE_INTERACTIVE_PROCESS: + output.append("Interactive service ") + else: + output.append("Service ") + if self.DisplayName: + output.append("\"%s\" (%s)" % (self.DisplayName, self.ServiceName)) + else: + output.append("\"%s\"" % self.ServiceName) + if self.CurrentState == SERVICE_CONTINUE_PENDING: + output.append(" is about to continue") + elif self.CurrentState == SERVICE_PAUSE_PENDING: + output.append(" is pausing") + elif self.CurrentState == SERVICE_PAUSED: + output.append(" is paused") + elif self.CurrentState == SERVICE_RUNNING: + output.append(" is running") + elif self.CurrentState == SERVICE_START_PENDING: + output.append(" is starting") + elif self.CurrentState == SERVICE_STOP_PENDING: + output.append(" is stopping") + elif self.CurrentState == SERVICE_STOPPED: + output.append(" is stopped") + if self.ProcessId: + output.append(" at process %d" % self.ProcessId) + output.append(".") + return "".join(output) + +#--- Handle wrappers ---------------------------------------------------------- + +# XXX maybe add functions related to the tokens here? +class TokenHandle (Handle): + """ + Access token handle. + + @see: L{Handle} + """ + pass + +class RegistryKeyHandle (UserModeHandle): + """ + Registry key handle. + """ + + _TYPE = HKEY + + def _close(self): + RegCloseKey(self.value) + +class SaferLevelHandle (UserModeHandle): + """ + Safer level handle. + + @see: U{http://msdn.microsoft.com/en-us/library/ms722425(VS.85).aspx} + """ + + _TYPE = SAFER_LEVEL_HANDLE + + def _close(self): + SaferCloseLevel(self.value) + +class ServiceHandle (UserModeHandle): + """ + Service handle. + + @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms684330(v=vs.85).aspx} + """ + + _TYPE = SC_HANDLE + + def _close(self): + CloseServiceHandle(self.value) + +class ServiceControlManagerHandle (UserModeHandle): + """ + Service Control Manager (SCM) handle. + + @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms684323(v=vs.85).aspx} + """ + + _TYPE = SC_HANDLE + + def _close(self): + CloseServiceHandle(self.value) + +#--- advapi32.dll ------------------------------------------------------------- + +# BOOL WINAPI GetUserName( +# __out LPTSTR lpBuffer, +# __inout LPDWORD lpnSize +# ); +def GetUserNameA(): + _GetUserNameA = windll.advapi32.GetUserNameA + _GetUserNameA.argtypes = [LPSTR, LPDWORD] + _GetUserNameA.restype = bool + + nSize = DWORD(0) + _GetUserNameA(None, byref(nSize)) + error = GetLastError() + if error != ERROR_INSUFFICIENT_BUFFER: + raise ctypes.WinError(error) + lpBuffer = ctypes.create_string_buffer('', nSize.value + 1) + success = _GetUserNameA(lpBuffer, byref(nSize)) + if not success: + raise ctypes.WinError() + return lpBuffer.value + +def GetUserNameW(): + _GetUserNameW = windll.advapi32.GetUserNameW + _GetUserNameW.argtypes = [LPWSTR, LPDWORD] + _GetUserNameW.restype = bool + + nSize = DWORD(0) + _GetUserNameW(None, byref(nSize)) + error = GetLastError() + if error != ERROR_INSUFFICIENT_BUFFER: + raise ctypes.WinError(error) + lpBuffer = ctypes.create_unicode_buffer(u'', nSize.value + 1) + success = _GetUserNameW(lpBuffer, byref(nSize)) + if not success: + raise ctypes.WinError() + return lpBuffer.value + +GetUserName = DefaultStringType(GetUserNameA, GetUserNameW) + +# BOOL WINAPI LookupAccountName( +# __in_opt LPCTSTR lpSystemName, +# __in LPCTSTR lpAccountName, +# __out_opt PSID Sid, +# __inout LPDWORD cbSid, +# __out_opt LPTSTR ReferencedDomainName, +# __inout LPDWORD cchReferencedDomainName, +# __out PSID_NAME_USE peUse +# ); + +# XXX TO DO + +# BOOL WINAPI LookupAccountSid( +# __in_opt LPCTSTR lpSystemName, +# __in PSID lpSid, +# __out_opt LPTSTR lpName, +# __inout LPDWORD cchName, +# __out_opt LPTSTR lpReferencedDomainName, +# __inout LPDWORD cchReferencedDomainName, +# __out PSID_NAME_USE peUse +# ); +def LookupAccountSidA(lpSystemName, lpSid): + _LookupAccountSidA = windll.advapi32.LookupAccountSidA + _LookupAccountSidA.argtypes = [LPSTR, PSID, LPSTR, LPDWORD, LPSTR, LPDWORD, LPDWORD] + _LookupAccountSidA.restype = bool + + cchName = DWORD(0) + cchReferencedDomainName = DWORD(0) + peUse = DWORD(0) + _LookupAccountSidA(lpSystemName, lpSid, None, byref(cchName), None, byref(cchReferencedDomainName), byref(peUse)) + error = GetLastError() + if error != ERROR_INSUFFICIENT_BUFFER: + raise ctypes.WinError(error) + lpName = ctypes.create_string_buffer('', cchName + 1) + lpReferencedDomainName = ctypes.create_string_buffer('', cchReferencedDomainName + 1) + success = _LookupAccountSidA(lpSystemName, lpSid, lpName, byref(cchName), lpReferencedDomainName, byref(cchReferencedDomainName), byref(peUse)) + if not success: + raise ctypes.WinError() + return lpName.value, lpReferencedDomainName.value, peUse.value + +def LookupAccountSidW(lpSystemName, lpSid): + _LookupAccountSidW = windll.advapi32.LookupAccountSidA + _LookupAccountSidW.argtypes = [LPSTR, PSID, LPWSTR, LPDWORD, LPWSTR, LPDWORD, LPDWORD] + _LookupAccountSidW.restype = bool + + cchName = DWORD(0) + cchReferencedDomainName = DWORD(0) + peUse = DWORD(0) + _LookupAccountSidW(lpSystemName, lpSid, None, byref(cchName), None, byref(cchReferencedDomainName), byref(peUse)) + error = GetLastError() + if error != ERROR_INSUFFICIENT_BUFFER: + raise ctypes.WinError(error) + lpName = ctypes.create_unicode_buffer(u'', cchName + 1) + lpReferencedDomainName = ctypes.create_unicode_buffer(u'', cchReferencedDomainName + 1) + success = _LookupAccountSidW(lpSystemName, lpSid, lpName, byref(cchName), lpReferencedDomainName, byref(cchReferencedDomainName), byref(peUse)) + if not success: + raise ctypes.WinError() + return lpName.value, lpReferencedDomainName.value, peUse.value + +LookupAccountSid = GuessStringType(LookupAccountSidA, LookupAccountSidW) + +# BOOL ConvertSidToStringSid( +# __in PSID Sid, +# __out LPTSTR *StringSid +# ); +def ConvertSidToStringSidA(Sid): + _ConvertSidToStringSidA = windll.advapi32.ConvertSidToStringSidA + _ConvertSidToStringSidA.argtypes = [PSID, LPSTR] + _ConvertSidToStringSidA.restype = bool + _ConvertSidToStringSidA.errcheck = RaiseIfZero + + pStringSid = LPSTR() + _ConvertSidToStringSidA(Sid, byref(pStringSid)) + try: + StringSid = pStringSid.value + finally: + LocalFree(pStringSid) + return StringSid + +def ConvertSidToStringSidW(Sid): + _ConvertSidToStringSidW = windll.advapi32.ConvertSidToStringSidW + _ConvertSidToStringSidW.argtypes = [PSID, LPWSTR] + _ConvertSidToStringSidW.restype = bool + _ConvertSidToStringSidW.errcheck = RaiseIfZero + + pStringSid = LPWSTR() + _ConvertSidToStringSidW(Sid, byref(pStringSid)) + try: + StringSid = pStringSid.value + finally: + LocalFree(pStringSid) + return StringSid + +ConvertSidToStringSid = DefaultStringType(ConvertSidToStringSidA, ConvertSidToStringSidW) + +# BOOL WINAPI ConvertStringSidToSid( +# __in LPCTSTR StringSid, +# __out PSID *Sid +# ); +def ConvertStringSidToSidA(StringSid): + _ConvertStringSidToSidA = windll.advapi32.ConvertStringSidToSidA + _ConvertStringSidToSidA.argtypes = [LPSTR, PVOID] + _ConvertStringSidToSidA.restype = bool + _ConvertStringSidToSidA.errcheck = RaiseIfZero + + Sid = PVOID() + _ConvertStringSidToSidA(StringSid, ctypes.pointer(Sid)) + return Sid.value + +def ConvertStringSidToSidW(StringSid): + _ConvertStringSidToSidW = windll.advapi32.ConvertStringSidToSidW + _ConvertStringSidToSidW.argtypes = [LPWSTR, PVOID] + _ConvertStringSidToSidW.restype = bool + _ConvertStringSidToSidW.errcheck = RaiseIfZero + + Sid = PVOID() + _ConvertStringSidToSidW(StringSid, ctypes.pointer(Sid)) + return Sid.value + +ConvertStringSidToSid = GuessStringType(ConvertStringSidToSidA, ConvertStringSidToSidW) + +# BOOL WINAPI IsValidSid( +# __in PSID pSid +# ); +def IsValidSid(pSid): + _IsValidSid = windll.advapi32.IsValidSid + _IsValidSid.argtypes = [PSID] + _IsValidSid.restype = bool + return _IsValidSid(pSid) + +# BOOL WINAPI EqualSid( +# __in PSID pSid1, +# __in PSID pSid2 +# ); +def EqualSid(pSid1, pSid2): + _EqualSid = windll.advapi32.EqualSid + _EqualSid.argtypes = [PSID, PSID] + _EqualSid.restype = bool + return _EqualSid(pSid1, pSid2) + +# DWORD WINAPI GetLengthSid( +# __in PSID pSid +# ); +def GetLengthSid(pSid): + _GetLengthSid = windll.advapi32.GetLengthSid + _GetLengthSid.argtypes = [PSID] + _GetLengthSid.restype = DWORD + return _GetLengthSid(pSid) + +# BOOL WINAPI CopySid( +# __in DWORD nDestinationSidLength, +# __out PSID pDestinationSid, +# __in PSID pSourceSid +# ); +def CopySid(pSourceSid): + _CopySid = windll.advapi32.CopySid + _CopySid.argtypes = [DWORD, PVOID, PSID] + _CopySid.restype = bool + _CopySid.errcheck = RaiseIfZero + + nDestinationSidLength = GetLengthSid(pSourceSid) + DestinationSid = ctypes.create_string_buffer('', nDestinationSidLength) + pDestinationSid = ctypes.cast(ctypes.pointer(DestinationSid), PVOID) + _CopySid(nDestinationSidLength, pDestinationSid, pSourceSid) + return ctypes.cast(pDestinationSid, PSID) + +# PVOID WINAPI FreeSid( +# __in PSID pSid +# ); +def FreeSid(pSid): + _FreeSid = windll.advapi32.FreeSid + _FreeSid.argtypes = [PSID] + _FreeSid.restype = PSID + _FreeSid.errcheck = RaiseIfNotZero + _FreeSid(pSid) + +# BOOL WINAPI OpenProcessToken( +# __in HANDLE ProcessHandle, +# __in DWORD DesiredAccess, +# __out PHANDLE TokenHandle +# ); +def OpenProcessToken(ProcessHandle, DesiredAccess = TOKEN_ALL_ACCESS): + _OpenProcessToken = windll.advapi32.OpenProcessToken + _OpenProcessToken.argtypes = [HANDLE, DWORD, PHANDLE] + _OpenProcessToken.restype = bool + _OpenProcessToken.errcheck = RaiseIfZero + + NewTokenHandle = HANDLE(INVALID_HANDLE_VALUE) + _OpenProcessToken(ProcessHandle, DesiredAccess, byref(NewTokenHandle)) + return TokenHandle(NewTokenHandle.value) + +# BOOL WINAPI OpenThreadToken( +# __in HANDLE ThreadHandle, +# __in DWORD DesiredAccess, +# __in BOOL OpenAsSelf, +# __out PHANDLE TokenHandle +# ); +def OpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf = True): + _OpenThreadToken = windll.advapi32.OpenThreadToken + _OpenThreadToken.argtypes = [HANDLE, DWORD, BOOL, PHANDLE] + _OpenThreadToken.restype = bool + _OpenThreadToken.errcheck = RaiseIfZero + + NewTokenHandle = HANDLE(INVALID_HANDLE_VALUE) + _OpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, byref(NewTokenHandle)) + return TokenHandle(NewTokenHandle.value) + +# BOOL WINAPI DuplicateToken( +# _In_ HANDLE ExistingTokenHandle, +# _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, +# _Out_ PHANDLE DuplicateTokenHandle +# ); +def DuplicateToken(ExistingTokenHandle, ImpersonationLevel = SecurityImpersonation): + _DuplicateToken = windll.advapi32.DuplicateToken + _DuplicateToken.argtypes = [HANDLE, SECURITY_IMPERSONATION_LEVEL, PHANDLE] + _DuplicateToken.restype = bool + _DuplicateToken.errcheck = RaiseIfZero + + DuplicateTokenHandle = HANDLE(INVALID_HANDLE_VALUE) + _DuplicateToken(ExistingTokenHandle, ImpersonationLevel, byref(DuplicateTokenHandle)) + return TokenHandle(DuplicateTokenHandle.value) + +# BOOL WINAPI DuplicateTokenEx( +# _In_ HANDLE hExistingToken, +# _In_ DWORD dwDesiredAccess, +# _In_opt_ LPSECURITY_ATTRIBUTES lpTokenAttributes, +# _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, +# _In_ TOKEN_TYPE TokenType, +# _Out_ PHANDLE phNewToken +# ); +def DuplicateTokenEx(hExistingToken, dwDesiredAccess = TOKEN_ALL_ACCESS, lpTokenAttributes = None, ImpersonationLevel = SecurityImpersonation, TokenType = TokenPrimary): + _DuplicateTokenEx = windll.advapi32.DuplicateTokenEx + _DuplicateTokenEx.argtypes = [HANDLE, DWORD, LPSECURITY_ATTRIBUTES, SECURITY_IMPERSONATION_LEVEL, TOKEN_TYPE, PHANDLE] + _DuplicateTokenEx.restype = bool + _DuplicateTokenEx.errcheck = RaiseIfZero + + DuplicateTokenHandle = HANDLE(INVALID_HANDLE_VALUE) + _DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, byref(DuplicateTokenHandle)) + return TokenHandle(DuplicateTokenHandle.value) + +# BOOL WINAPI IsTokenRestricted( +# __in HANDLE TokenHandle +# ); +def IsTokenRestricted(hTokenHandle): + _IsTokenRestricted = windll.advapi32.IsTokenRestricted + _IsTokenRestricted.argtypes = [HANDLE] + _IsTokenRestricted.restype = bool + _IsTokenRestricted.errcheck = RaiseIfNotErrorSuccess + + SetLastError(ERROR_SUCCESS) + return _IsTokenRestricted(hTokenHandle) + +# BOOL WINAPI LookupPrivilegeValue( +# __in_opt LPCTSTR lpSystemName, +# __in LPCTSTR lpName, +# __out PLUID lpLuid +# ); +def LookupPrivilegeValueA(lpSystemName, lpName): + _LookupPrivilegeValueA = windll.advapi32.LookupPrivilegeValueA + _LookupPrivilegeValueA.argtypes = [LPSTR, LPSTR, PLUID] + _LookupPrivilegeValueA.restype = bool + _LookupPrivilegeValueA.errcheck = RaiseIfZero + + lpLuid = LUID() + if not lpSystemName: + lpSystemName = None + _LookupPrivilegeValueA(lpSystemName, lpName, byref(lpLuid)) + return lpLuid + +def LookupPrivilegeValueW(lpSystemName, lpName): + _LookupPrivilegeValueW = windll.advapi32.LookupPrivilegeValueW + _LookupPrivilegeValueW.argtypes = [LPWSTR, LPWSTR, PLUID] + _LookupPrivilegeValueW.restype = bool + _LookupPrivilegeValueW.errcheck = RaiseIfZero + + lpLuid = LUID() + if not lpSystemName: + lpSystemName = None + _LookupPrivilegeValueW(lpSystemName, lpName, byref(lpLuid)) + return lpLuid + +LookupPrivilegeValue = GuessStringType(LookupPrivilegeValueA, LookupPrivilegeValueW) + +# BOOL WINAPI LookupPrivilegeName( +# __in_opt LPCTSTR lpSystemName, +# __in PLUID lpLuid, +# __out_opt LPTSTR lpName, +# __inout LPDWORD cchName +# ); + +def LookupPrivilegeNameA(lpSystemName, lpLuid): + _LookupPrivilegeNameA = windll.advapi32.LookupPrivilegeNameA + _LookupPrivilegeNameA.argtypes = [LPSTR, PLUID, LPSTR, LPDWORD] + _LookupPrivilegeNameA.restype = bool + _LookupPrivilegeNameA.errcheck = RaiseIfZero + + cchName = DWORD(0) + _LookupPrivilegeNameA(lpSystemName, byref(lpLuid), NULL, byref(cchName)) + lpName = ctypes.create_string_buffer("", cchName.value) + _LookupPrivilegeNameA(lpSystemName, byref(lpLuid), byref(lpName), byref(cchName)) + return lpName.value + +def LookupPrivilegeNameW(lpSystemName, lpLuid): + _LookupPrivilegeNameW = windll.advapi32.LookupPrivilegeNameW + _LookupPrivilegeNameW.argtypes = [LPWSTR, PLUID, LPWSTR, LPDWORD] + _LookupPrivilegeNameW.restype = bool + _LookupPrivilegeNameW.errcheck = RaiseIfZero + + cchName = DWORD(0) + _LookupPrivilegeNameW(lpSystemName, byref(lpLuid), NULL, byref(cchName)) + lpName = ctypes.create_unicode_buffer(u"", cchName.value) + _LookupPrivilegeNameW(lpSystemName, byref(lpLuid), byref(lpName), byref(cchName)) + return lpName.value + +LookupPrivilegeName = GuessStringType(LookupPrivilegeNameA, LookupPrivilegeNameW) + +# BOOL WINAPI AdjustTokenPrivileges( +# __in HANDLE TokenHandle, +# __in BOOL DisableAllPrivileges, +# __in_opt PTOKEN_PRIVILEGES NewState, +# __in DWORD BufferLength, +# __out_opt PTOKEN_PRIVILEGES PreviousState, +# __out_opt PDWORD ReturnLength +# ); +def AdjustTokenPrivileges(TokenHandle, NewState = ()): + _AdjustTokenPrivileges = windll.advapi32.AdjustTokenPrivileges + _AdjustTokenPrivileges.argtypes = [HANDLE, BOOL, LPVOID, DWORD, LPVOID, LPVOID] + _AdjustTokenPrivileges.restype = bool + _AdjustTokenPrivileges.errcheck = RaiseIfZero + # + # I don't know how to allocate variable sized structures in ctypes :( + # so this hack will work by using always TOKEN_PRIVILEGES of one element + # and calling the API many times. This also means the PreviousState + # parameter won't be supported yet as it's too much hassle. In a future + # version I look forward to implementing this function correctly. + # + if not NewState: + _AdjustTokenPrivileges(TokenHandle, TRUE, NULL, 0, NULL, NULL) + else: + success = True + for (privilege, enabled) in NewState: + if not isinstance(privilege, LUID): + privilege = LookupPrivilegeValue(NULL, privilege) + if enabled == True: + flags = SE_PRIVILEGE_ENABLED + elif enabled == False: + flags = SE_PRIVILEGE_REMOVED + elif enabled == None: + flags = 0 + else: + flags = enabled + laa = LUID_AND_ATTRIBUTES(privilege, flags) + tp = TOKEN_PRIVILEGES(1, laa) + _AdjustTokenPrivileges(TokenHandle, FALSE, byref(tp), sizeof(tp), NULL, NULL) + +# BOOL WINAPI GetTokenInformation( +# __in HANDLE TokenHandle, +# __in TOKEN_INFORMATION_CLASS TokenInformationClass, +# __out_opt LPVOID TokenInformation, +# __in DWORD TokenInformationLength, +# __out PDWORD ReturnLength +# ); +def GetTokenInformation(hTokenHandle, TokenInformationClass): + if TokenInformationClass <= 0 or TokenInformationClass > MaxTokenInfoClass: + raise ValueError("Invalid value for TokenInformationClass (%i)" % TokenInformationClass) + + # User SID. + if TokenInformationClass == TokenUser: + TokenInformation = TOKEN_USER() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.User.Sid.value + + # Owner SID. + if TokenInformationClass == TokenOwner: + TokenInformation = TOKEN_OWNER() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.Owner.value + + # Primary group SID. + if TokenInformationClass == TokenOwner: + TokenInformation = TOKEN_PRIMARY_GROUP() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.PrimaryGroup.value + + # App container SID. + if TokenInformationClass == TokenAppContainerSid: + TokenInformation = TOKEN_APPCONTAINER_INFORMATION() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.TokenAppContainer.value + + # Integrity level SID. + if TokenInformationClass == TokenIntegrityLevel: + TokenInformation = TOKEN_MANDATORY_LABEL() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.Label.Sid.value, TokenInformation.Label.Attributes + + # Logon session LUID. + if TokenInformationClass == TokenOrigin: + TokenInformation = TOKEN_ORIGIN() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.OriginatingLogonSession + + # Primary or impersonation token. + if TokenInformationClass == TokenType: + TokenInformation = TOKEN_TYPE(0) + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.value + + # Elevated token. + if TokenInformationClass == TokenElevation: + TokenInformation = TOKEN_ELEVATION(0) + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.value + + # Security impersonation level. + if TokenInformationClass == TokenElevation: + TokenInformation = SECURITY_IMPERSONATION_LEVEL(0) + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.value + + # Session ID and other DWORD values. + if TokenInformationClass in (TokenSessionId, TokenAppContainerNumber): + TokenInformation = DWORD(0) + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation.value + + # Various boolean flags. + if TokenInformationClass in (TokenSandBoxInert, TokenHasRestrictions, TokenUIAccess, + TokenVirtualizationAllowed, TokenVirtualizationEnabled): + TokenInformation = DWORD(0) + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return bool(TokenInformation.value) + + # Linked token. + if TokenInformationClass == TokenLinkedToken: + TokenInformation = TOKEN_LINKED_TOKEN(0) + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenHandle(TokenInformation.LinkedToken.value, bOwnership = True) + + # Token statistics. + if TokenInformationClass == TokenStatistics: + TokenInformation = TOKEN_STATISTICS() + _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation) + return TokenInformation # TODO add a class wrapper? + + # Currently unsupported flags. + raise NotImplementedError("TokenInformationClass(%i) not yet supported!" % TokenInformationClass) + +def _internal_GetTokenInformation(hTokenHandle, TokenInformationClass, TokenInformation): + _GetTokenInformation = windll.advapi32.GetTokenInformation + _GetTokenInformation.argtypes = [HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD] + _GetTokenInformation.restype = bool + _GetTokenInformation.errcheck = RaiseIfZero + + ReturnLength = DWORD(0) + TokenInformationLength = SIZEOF(TokenInformation) + _GetTokenInformation(hTokenHandle, TokenInformationClass, byref(TokenInformation), TokenInformationLength, byref(ReturnLength)) + if ReturnLength.value != TokenInformationLength: + raise ctypes.WinError(ERROR_INSUFFICIENT_BUFFER) + return TokenInformation + +# BOOL WINAPI SetTokenInformation( +# __in HANDLE TokenHandle, +# __in TOKEN_INFORMATION_CLASS TokenInformationClass, +# __in LPVOID TokenInformation, +# __in DWORD TokenInformationLength +# ); + +# XXX TODO + +# BOOL WINAPI CreateProcessWithLogonW( +# __in LPCWSTR lpUsername, +# __in_opt LPCWSTR lpDomain, +# __in LPCWSTR lpPassword, +# __in DWORD dwLogonFlags, +# __in_opt LPCWSTR lpApplicationName, +# __inout_opt LPWSTR lpCommandLine, +# __in DWORD dwCreationFlags, +# __in_opt LPVOID lpEnvironment, +# __in_opt LPCWSTR lpCurrentDirectory, +# __in LPSTARTUPINFOW lpStartupInfo, +# __out LPPROCESS_INFORMATION lpProcessInfo +# ); +def CreateProcessWithLogonW(lpUsername = None, lpDomain = None, lpPassword = None, dwLogonFlags = 0, lpApplicationName = None, lpCommandLine = None, dwCreationFlags = 0, lpEnvironment = None, lpCurrentDirectory = None, lpStartupInfo = None): + _CreateProcessWithLogonW = windll.advapi32.CreateProcessWithLogonW + _CreateProcessWithLogonW.argtypes = [LPWSTR, LPWSTR, LPWSTR, DWORD, LPWSTR, LPWSTR, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] + _CreateProcessWithLogonW.restype = bool + _CreateProcessWithLogonW.errcheck = RaiseIfZero + + if not lpUsername: + lpUsername = None + if not lpDomain: + lpDomain = None + if not lpPassword: + lpPassword = None + if not lpApplicationName: + lpApplicationName = None + if not lpCommandLine: + lpCommandLine = None + else: + lpCommandLine = ctypes.create_unicode_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine))) + if not lpEnvironment: + lpEnvironment = None + else: + lpEnvironment = ctypes.create_unicode_buffer(lpEnvironment) + if not lpCurrentDirectory: + lpCurrentDirectory = None + if not lpStartupInfo: + lpStartupInfo = STARTUPINFOW() + lpStartupInfo.cb = sizeof(STARTUPINFOW) + lpStartupInfo.lpReserved = 0 + lpStartupInfo.lpDesktop = 0 + lpStartupInfo.lpTitle = 0 + lpStartupInfo.dwFlags = 0 + lpStartupInfo.cbReserved2 = 0 + lpStartupInfo.lpReserved2 = 0 + lpProcessInformation = PROCESS_INFORMATION() + lpProcessInformation.hProcess = INVALID_HANDLE_VALUE + lpProcessInformation.hThread = INVALID_HANDLE_VALUE + lpProcessInformation.dwProcessId = 0 + lpProcessInformation.dwThreadId = 0 + _CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) + return ProcessInformation(lpProcessInformation) + +CreateProcessWithLogonA = MakeANSIVersion(CreateProcessWithLogonW) +CreateProcessWithLogon = DefaultStringType(CreateProcessWithLogonA, CreateProcessWithLogonW) + +# BOOL WINAPI CreateProcessWithTokenW( +# __in HANDLE hToken, +# __in DWORD dwLogonFlags, +# __in_opt LPCWSTR lpApplicationName, +# __inout_opt LPWSTR lpCommandLine, +# __in DWORD dwCreationFlags, +# __in_opt LPVOID lpEnvironment, +# __in_opt LPCWSTR lpCurrentDirectory, +# __in LPSTARTUPINFOW lpStartupInfo, +# __out LPPROCESS_INFORMATION lpProcessInfo +# ); +def CreateProcessWithTokenW(hToken = None, dwLogonFlags = 0, lpApplicationName = None, lpCommandLine = None, dwCreationFlags = 0, lpEnvironment = None, lpCurrentDirectory = None, lpStartupInfo = None): + _CreateProcessWithTokenW = windll.advapi32.CreateProcessWithTokenW + _CreateProcessWithTokenW.argtypes = [HANDLE, DWORD, LPWSTR, LPWSTR, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] + _CreateProcessWithTokenW.restype = bool + _CreateProcessWithTokenW.errcheck = RaiseIfZero + + if not hToken: + hToken = None + if not lpApplicationName: + lpApplicationName = None + if not lpCommandLine: + lpCommandLine = None + else: + lpCommandLine = ctypes.create_unicode_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine))) + if not lpEnvironment: + lpEnvironment = None + else: + lpEnvironment = ctypes.create_unicode_buffer(lpEnvironment) + if not lpCurrentDirectory: + lpCurrentDirectory = None + if not lpStartupInfo: + lpStartupInfo = STARTUPINFOW() + lpStartupInfo.cb = sizeof(STARTUPINFOW) + lpStartupInfo.lpReserved = 0 + lpStartupInfo.lpDesktop = 0 + lpStartupInfo.lpTitle = 0 + lpStartupInfo.dwFlags = 0 + lpStartupInfo.cbReserved2 = 0 + lpStartupInfo.lpReserved2 = 0 + lpProcessInformation = PROCESS_INFORMATION() + lpProcessInformation.hProcess = INVALID_HANDLE_VALUE + lpProcessInformation.hThread = INVALID_HANDLE_VALUE + lpProcessInformation.dwProcessId = 0 + lpProcessInformation.dwThreadId = 0 + _CreateProcessWithTokenW(hToken, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) + return ProcessInformation(lpProcessInformation) + +CreateProcessWithTokenA = MakeANSIVersion(CreateProcessWithTokenW) +CreateProcessWithToken = DefaultStringType(CreateProcessWithTokenA, CreateProcessWithTokenW) + +# BOOL WINAPI CreateProcessAsUser( +# __in_opt HANDLE hToken, +# __in_opt LPCTSTR lpApplicationName, +# __inout_opt LPTSTR lpCommandLine, +# __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, +# __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, +# __in BOOL bInheritHandles, +# __in DWORD dwCreationFlags, +# __in_opt LPVOID lpEnvironment, +# __in_opt LPCTSTR lpCurrentDirectory, +# __in LPSTARTUPINFO lpStartupInfo, +# __out LPPROCESS_INFORMATION lpProcessInformation +# ); +def CreateProcessAsUserA(hToken = None, lpApplicationName = None, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None): + _CreateProcessAsUserA = windll.advapi32.CreateProcessAsUserA + _CreateProcessAsUserA.argtypes = [HANDLE, LPSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPSTR, LPVOID, LPPROCESS_INFORMATION] + _CreateProcessAsUserA.restype = bool + _CreateProcessAsUserA.errcheck = RaiseIfZero + + if not lpApplicationName: + lpApplicationName = None + if not lpCommandLine: + lpCommandLine = None + else: + lpCommandLine = ctypes.create_string_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine))) + if not lpEnvironment: + lpEnvironment = None + else: + lpEnvironment = ctypes.create_string_buffer(lpEnvironment) + if not lpCurrentDirectory: + lpCurrentDirectory = None + if not lpProcessAttributes: + lpProcessAttributes = None + else: + lpProcessAttributes = byref(lpProcessAttributes) + if not lpThreadAttributes: + lpThreadAttributes = None + else: + lpThreadAttributes = byref(lpThreadAttributes) + if not lpStartupInfo: + lpStartupInfo = STARTUPINFO() + lpStartupInfo.cb = sizeof(STARTUPINFO) + lpStartupInfo.lpReserved = 0 + lpStartupInfo.lpDesktop = 0 + lpStartupInfo.lpTitle = 0 + lpStartupInfo.dwFlags = 0 + lpStartupInfo.cbReserved2 = 0 + lpStartupInfo.lpReserved2 = 0 + lpProcessInformation = PROCESS_INFORMATION() + lpProcessInformation.hProcess = INVALID_HANDLE_VALUE + lpProcessInformation.hThread = INVALID_HANDLE_VALUE + lpProcessInformation.dwProcessId = 0 + lpProcessInformation.dwThreadId = 0 + _CreateProcessAsUserA(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) + return ProcessInformation(lpProcessInformation) + +def CreateProcessAsUserW(hToken = None, lpApplicationName = None, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None): + _CreateProcessAsUserW = windll.advapi32.CreateProcessAsUserW + _CreateProcessAsUserW.argtypes = [HANDLE, LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] + _CreateProcessAsUserW.restype = bool + _CreateProcessAsUserW.errcheck = RaiseIfZero + + if not lpApplicationName: + lpApplicationName = None + if not lpCommandLine: + lpCommandLine = None + else: + lpCommandLine = ctypes.create_unicode_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine))) + if not lpEnvironment: + lpEnvironment = None + else: + lpEnvironment = ctypes.create_unicode_buffer(lpEnvironment) + if not lpCurrentDirectory: + lpCurrentDirectory = None + if not lpProcessAttributes: + lpProcessAttributes = None + else: + lpProcessAttributes = byref(lpProcessAttributes) + if not lpThreadAttributes: + lpThreadAttributes = None + else: + lpThreadAttributes = byref(lpThreadAttributes) + if not lpStartupInfo: + lpStartupInfo = STARTUPINFO() + lpStartupInfo.cb = sizeof(STARTUPINFO) + lpStartupInfo.lpReserved = 0 + lpStartupInfo.lpDesktop = 0 + lpStartupInfo.lpTitle = 0 + lpStartupInfo.dwFlags = 0 + lpStartupInfo.cbReserved2 = 0 + lpStartupInfo.lpReserved2 = 0 + lpProcessInformation = PROCESS_INFORMATION() + lpProcessInformation.hProcess = INVALID_HANDLE_VALUE + lpProcessInformation.hThread = INVALID_HANDLE_VALUE + lpProcessInformation.dwProcessId = 0 + lpProcessInformation.dwThreadId = 0 + _CreateProcessAsUserW(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) + return ProcessInformation(lpProcessInformation) + +CreateProcessAsUser = GuessStringType(CreateProcessAsUserA, CreateProcessAsUserW) + +# VOID CALLBACK WaitChainCallback( +# HWCT WctHandle, +# DWORD_PTR Context, +# DWORD CallbackStatus, +# LPDWORD NodeCount, +# PWAITCHAIN_NODE_INFO NodeInfoArray, +# LPBOOL IsCycle +# ); +PWAITCHAINCALLBACK = WINFUNCTYPE(HWCT, DWORD_PTR, DWORD, LPDWORD, PWAITCHAIN_NODE_INFO, LPBOOL) + +# HWCT WINAPI OpenThreadWaitChainSession( +# __in DWORD Flags, +# __in_opt PWAITCHAINCALLBACK callback +# ); +def OpenThreadWaitChainSession(Flags = 0, callback = None): + _OpenThreadWaitChainSession = windll.advapi32.OpenThreadWaitChainSession + _OpenThreadWaitChainSession.argtypes = [DWORD, PVOID] + _OpenThreadWaitChainSession.restype = HWCT + _OpenThreadWaitChainSession.errcheck = RaiseIfZero + + if callback is not None: + callback = PWAITCHAINCALLBACK(callback) + aHandle = _OpenThreadWaitChainSession(Flags, callback) + return ThreadWaitChainSessionHandle(aHandle) + +# BOOL WINAPI GetThreadWaitChain( +# _In_ HWCT WctHandle, +# _In_opt_ DWORD_PTR Context, +# _In_ DWORD Flags, +# _In_ DWORD ThreadId, +# _Inout_ LPDWORD NodeCount, +# _Out_ PWAITCHAIN_NODE_INFO NodeInfoArray, +# _Out_ LPBOOL IsCycle +# ); +def GetThreadWaitChain(WctHandle, Context = None, Flags = WCTP_GETINFO_ALL_FLAGS, ThreadId = -1, NodeCount = WCT_MAX_NODE_COUNT): + _GetThreadWaitChain = windll.advapi32.GetThreadWaitChain + _GetThreadWaitChain.argtypes = [HWCT, LPDWORD, DWORD, DWORD, LPDWORD, PWAITCHAIN_NODE_INFO, LPBOOL] + _GetThreadWaitChain.restype = bool + _GetThreadWaitChain.errcheck = RaiseIfZero + + dwNodeCount = DWORD(NodeCount) + NodeInfoArray = (WAITCHAIN_NODE_INFO * NodeCount)() + IsCycle = BOOL(0) + _GetThreadWaitChain(WctHandle, Context, Flags, ThreadId, byref(dwNodeCount), ctypes.cast(ctypes.pointer(NodeInfoArray), PWAITCHAIN_NODE_INFO), byref(IsCycle)) + while dwNodeCount.value > NodeCount: + NodeCount = dwNodeCount.value + NodeInfoArray = (WAITCHAIN_NODE_INFO * NodeCount)() + _GetThreadWaitChain(WctHandle, Context, Flags, ThreadId, byref(dwNodeCount), ctypes.cast(ctypes.pointer(NodeInfoArray), PWAITCHAIN_NODE_INFO), byref(IsCycle)) + return ( + [ WaitChainNodeInfo(NodeInfoArray[index]) for index in compat.xrange(dwNodeCount.value) ], + bool(IsCycle.value) + ) + +# VOID WINAPI CloseThreadWaitChainSession( +# __in HWCT WctHandle +# ); +def CloseThreadWaitChainSession(WctHandle): + _CloseThreadWaitChainSession = windll.advapi32.CloseThreadWaitChainSession + _CloseThreadWaitChainSession.argtypes = [HWCT] + _CloseThreadWaitChainSession(WctHandle) + +# BOOL WINAPI SaferCreateLevel( +# __in DWORD dwScopeId, +# __in DWORD dwLevelId, +# __in DWORD OpenFlags, +# __out SAFER_LEVEL_HANDLE *pLevelHandle, +# __reserved LPVOID lpReserved +# ); +def SaferCreateLevel(dwScopeId=SAFER_SCOPEID_USER, dwLevelId=SAFER_LEVELID_NORMALUSER, OpenFlags=0): + _SaferCreateLevel = windll.advapi32.SaferCreateLevel + _SaferCreateLevel.argtypes = [DWORD, DWORD, DWORD, POINTER(SAFER_LEVEL_HANDLE), LPVOID] + _SaferCreateLevel.restype = BOOL + _SaferCreateLevel.errcheck = RaiseIfZero + + hLevelHandle = SAFER_LEVEL_HANDLE(INVALID_HANDLE_VALUE) + _SaferCreateLevel(dwScopeId, dwLevelId, OpenFlags, byref(hLevelHandle), None) + return SaferLevelHandle(hLevelHandle.value) + +# BOOL WINAPI SaferIdentifyLevel( +# __in DWORD dwNumProperties, +# __in_opt PSAFER_CODE_PROPERTIES pCodeProperties, +# __out SAFER_LEVEL_HANDLE *pLevelHandle, +# __reserved LPVOID lpReserved +# ); + +# XXX TODO + +# BOOL WINAPI SaferComputeTokenFromLevel( +# __in SAFER_LEVEL_HANDLE LevelHandle, +# __in_opt HANDLE InAccessToken, +# __out PHANDLE OutAccessToken, +# __in DWORD dwFlags, +# __inout_opt LPVOID lpReserved +# ); +def SaferComputeTokenFromLevel(LevelHandle, InAccessToken=None, dwFlags=0): + _SaferComputeTokenFromLevel = windll.advapi32.SaferComputeTokenFromLevel + _SaferComputeTokenFromLevel.argtypes = [SAFER_LEVEL_HANDLE, HANDLE, PHANDLE, DWORD, LPDWORD] + _SaferComputeTokenFromLevel.restype = BOOL + _SaferComputeTokenFromLevel.errcheck = RaiseIfZero + + OutAccessToken = HANDLE(INVALID_HANDLE_VALUE) + lpReserved = DWORD(0) + _SaferComputeTokenFromLevel(LevelHandle, InAccessToken, byref(OutAccessToken), dwFlags, byref(lpReserved)) + return TokenHandle(OutAccessToken.value), lpReserved.value + +# BOOL WINAPI SaferCloseLevel( +# __in SAFER_LEVEL_HANDLE hLevelHandle +# ); +def SaferCloseLevel(hLevelHandle): + _SaferCloseLevel = windll.advapi32.SaferCloseLevel + _SaferCloseLevel.argtypes = [SAFER_LEVEL_HANDLE] + _SaferCloseLevel.restype = BOOL + _SaferCloseLevel.errcheck = RaiseIfZero + + if hasattr(hLevelHandle, 'value'): + _SaferCloseLevel(hLevelHandle.value) + else: + _SaferCloseLevel(hLevelHandle) + +# BOOL SaferiIsExecutableFileType( +# __in LPCWSTR szFullPath, +# __in BOOLEAN bFromShellExecute +# ); +def SaferiIsExecutableFileType(szFullPath, bFromShellExecute = False): + _SaferiIsExecutableFileType = windll.advapi32.SaferiIsExecutableFileType + _SaferiIsExecutableFileType.argtypes = [LPWSTR, BOOLEAN] + _SaferiIsExecutableFileType.restype = BOOL + _SaferiIsExecutableFileType.errcheck = RaiseIfLastError + + SetLastError(ERROR_SUCCESS) + return bool(_SaferiIsExecutableFileType(compat.unicode(szFullPath), bFromShellExecute)) + +# useful alias since I'm likely to misspell it :P +SaferIsExecutableFileType = SaferiIsExecutableFileType + +#------------------------------------------------------------------------------ + +# LONG WINAPI RegCloseKey( +# __in HKEY hKey +# ); +def RegCloseKey(hKey): + if hasattr(hKey, 'value'): + value = hKey.value + else: + value = hKey + + if value in ( + HKEY_CLASSES_ROOT, + HKEY_CURRENT_USER, + HKEY_LOCAL_MACHINE, + HKEY_USERS, + HKEY_PERFORMANCE_DATA, + HKEY_CURRENT_CONFIG + ): + return + + _RegCloseKey = windll.advapi32.RegCloseKey + _RegCloseKey.argtypes = [HKEY] + _RegCloseKey.restype = LONG + _RegCloseKey.errcheck = RaiseIfNotErrorSuccess + _RegCloseKey(hKey) + +# LONG WINAPI RegConnectRegistry( +# __in_opt LPCTSTR lpMachineName, +# __in HKEY hKey, +# __out PHKEY phkResult +# ); +def RegConnectRegistryA(lpMachineName = None, hKey = HKEY_LOCAL_MACHINE): + _RegConnectRegistryA = windll.advapi32.RegConnectRegistryA + _RegConnectRegistryA.argtypes = [LPSTR, HKEY, PHKEY] + _RegConnectRegistryA.restype = LONG + _RegConnectRegistryA.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegConnectRegistryA(lpMachineName, hKey, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +def RegConnectRegistryW(lpMachineName = None, hKey = HKEY_LOCAL_MACHINE): + _RegConnectRegistryW = windll.advapi32.RegConnectRegistryW + _RegConnectRegistryW.argtypes = [LPWSTR, HKEY, PHKEY] + _RegConnectRegistryW.restype = LONG + _RegConnectRegistryW.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegConnectRegistryW(lpMachineName, hKey, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +RegConnectRegistry = GuessStringType(RegConnectRegistryA, RegConnectRegistryW) + +# LONG WINAPI RegCreateKey( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey, +# __out PHKEY phkResult +# ); +def RegCreateKeyA(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): + _RegCreateKeyA = windll.advapi32.RegCreateKeyA + _RegCreateKeyA.argtypes = [HKEY, LPSTR, PHKEY] + _RegCreateKeyA.restype = LONG + _RegCreateKeyA.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegCreateKeyA(hKey, lpSubKey, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +def RegCreateKeyW(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): + _RegCreateKeyW = windll.advapi32.RegCreateKeyW + _RegCreateKeyW.argtypes = [HKEY, LPWSTR, PHKEY] + _RegCreateKeyW.restype = LONG + _RegCreateKeyW.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegCreateKeyW(hKey, lpSubKey, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +RegCreateKey = GuessStringType(RegCreateKeyA, RegCreateKeyW) + +# LONG WINAPI RegCreateKeyEx( +# __in HKEY hKey, +# __in LPCTSTR lpSubKey, +# __reserved DWORD Reserved, +# __in_opt LPTSTR lpClass, +# __in DWORD dwOptions, +# __in REGSAM samDesired, +# __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, +# __out PHKEY phkResult, +# __out_opt LPDWORD lpdwDisposition +# ); + +# XXX TODO + +# LONG WINAPI RegOpenKey( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey, +# __out PHKEY phkResult +# ); +def RegOpenKeyA(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): + _RegOpenKeyA = windll.advapi32.RegOpenKeyA + _RegOpenKeyA.argtypes = [HKEY, LPSTR, PHKEY] + _RegOpenKeyA.restype = LONG + _RegOpenKeyA.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegOpenKeyA(hKey, lpSubKey, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +def RegOpenKeyW(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): + _RegOpenKeyW = windll.advapi32.RegOpenKeyW + _RegOpenKeyW.argtypes = [HKEY, LPWSTR, PHKEY] + _RegOpenKeyW.restype = LONG + _RegOpenKeyW.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegOpenKeyW(hKey, lpSubKey, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +RegOpenKey = GuessStringType(RegOpenKeyA, RegOpenKeyW) + +# LONG WINAPI RegOpenKeyEx( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey, +# __reserved DWORD ulOptions, +# __in REGSAM samDesired, +# __out PHKEY phkResult +# ); +def RegOpenKeyExA(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None, samDesired = KEY_ALL_ACCESS): + _RegOpenKeyExA = windll.advapi32.RegOpenKeyExA + _RegOpenKeyExA.argtypes = [HKEY, LPSTR, DWORD, REGSAM, PHKEY] + _RegOpenKeyExA.restype = LONG + _RegOpenKeyExA.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegOpenKeyExA(hKey, lpSubKey, 0, samDesired, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +def RegOpenKeyExW(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None, samDesired = KEY_ALL_ACCESS): + _RegOpenKeyExW = windll.advapi32.RegOpenKeyExW + _RegOpenKeyExW.argtypes = [HKEY, LPWSTR, DWORD, REGSAM, PHKEY] + _RegOpenKeyExW.restype = LONG + _RegOpenKeyExW.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegOpenKeyExW(hKey, lpSubKey, 0, samDesired, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +RegOpenKeyEx = GuessStringType(RegOpenKeyExA, RegOpenKeyExW) + +# LONG WINAPI RegOpenCurrentUser( +# __in REGSAM samDesired, +# __out PHKEY phkResult +# ); +def RegOpenCurrentUser(samDesired = KEY_ALL_ACCESS): + _RegOpenCurrentUser = windll.advapi32.RegOpenCurrentUser + _RegOpenCurrentUser.argtypes = [REGSAM, PHKEY] + _RegOpenCurrentUser.restype = LONG + _RegOpenCurrentUser.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegOpenCurrentUser(samDesired, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +# LONG WINAPI RegOpenUserClassesRoot( +# __in HANDLE hToken, +# __reserved DWORD dwOptions, +# __in REGSAM samDesired, +# __out PHKEY phkResult +# ); +def RegOpenUserClassesRoot(hToken, samDesired = KEY_ALL_ACCESS): + _RegOpenUserClassesRoot = windll.advapi32.RegOpenUserClassesRoot + _RegOpenUserClassesRoot.argtypes = [HANDLE, DWORD, REGSAM, PHKEY] + _RegOpenUserClassesRoot.restype = LONG + _RegOpenUserClassesRoot.errcheck = RaiseIfNotErrorSuccess + + hkResult = HKEY(INVALID_HANDLE_VALUE) + _RegOpenUserClassesRoot(hToken, 0, samDesired, byref(hkResult)) + return RegistryKeyHandle(hkResult.value) + +# LONG WINAPI RegQueryValue( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey, +# __out_opt LPTSTR lpValue, +# __inout_opt PLONG lpcbValue +# ); +def RegQueryValueA(hKey, lpSubKey = None): + _RegQueryValueA = windll.advapi32.RegQueryValueA + _RegQueryValueA.argtypes = [HKEY, LPSTR, LPVOID, PLONG] + _RegQueryValueA.restype = LONG + _RegQueryValueA.errcheck = RaiseIfNotErrorSuccess + + cbValue = LONG(0) + _RegQueryValueA(hKey, lpSubKey, None, byref(cbValue)) + lpValue = ctypes.create_string_buffer(cbValue.value) + _RegQueryValueA(hKey, lpSubKey, lpValue, byref(cbValue)) + return lpValue.value + +def RegQueryValueW(hKey, lpSubKey = None): + _RegQueryValueW = windll.advapi32.RegQueryValueW + _RegQueryValueW.argtypes = [HKEY, LPWSTR, LPVOID, PLONG] + _RegQueryValueW.restype = LONG + _RegQueryValueW.errcheck = RaiseIfNotErrorSuccess + + cbValue = LONG(0) + _RegQueryValueW(hKey, lpSubKey, None, byref(cbValue)) + lpValue = ctypes.create_unicode_buffer(cbValue.value * sizeof(WCHAR)) + _RegQueryValueW(hKey, lpSubKey, lpValue, byref(cbValue)) + return lpValue.value + +RegQueryValue = GuessStringType(RegQueryValueA, RegQueryValueW) + +# LONG WINAPI RegQueryValueEx( +# __in HKEY hKey, +# __in_opt LPCTSTR lpValueName, +# __reserved LPDWORD lpReserved, +# __out_opt LPDWORD lpType, +# __out_opt LPBYTE lpData, +# __inout_opt LPDWORD lpcbData +# ); +def _internal_RegQueryValueEx(ansi, hKey, lpValueName = None, bGetData = True): + _RegQueryValueEx = _caller_RegQueryValueEx(ansi) + + cbData = DWORD(0) + dwType = DWORD(-1) + _RegQueryValueEx(hKey, lpValueName, None, byref(dwType), None, byref(cbData)) + Type = dwType.value + + if not bGetData: + return cbData.value, Type + + if Type in (REG_DWORD, REG_DWORD_BIG_ENDIAN): # REG_DWORD_LITTLE_ENDIAN + if cbData.value != 4: + raise ValueError("REG_DWORD value of size %d" % cbData.value) + dwData = DWORD(0) + _RegQueryValueEx(hKey, lpValueName, None, None, byref(dwData), byref(cbData)) + return dwData.value, Type + + if Type == REG_QWORD: # REG_QWORD_LITTLE_ENDIAN + if cbData.value != 8: + raise ValueError("REG_QWORD value of size %d" % cbData.value) + qwData = QWORD(long(0)) + _RegQueryValueEx(hKey, lpValueName, None, None, byref(qwData), byref(cbData)) + return qwData.value, Type + + if Type in (REG_SZ, REG_EXPAND_SZ): + if ansi: + szData = ctypes.create_string_buffer(cbData.value) + else: + szData = ctypes.create_unicode_buffer(cbData.value) + _RegQueryValueEx(hKey, lpValueName, None, None, byref(szData), byref(cbData)) + return szData.value, Type + + if Type == REG_MULTI_SZ: + if ansi: + szData = ctypes.create_string_buffer(cbData.value) + else: + szData = ctypes.create_unicode_buffer(cbData.value) + _RegQueryValueEx(hKey, lpValueName, None, None, byref(szData), byref(cbData)) + Data = szData[:] + if ansi: + aData = Data.split('\0') + else: + aData = Data.split(u'\0') + aData = [token for token in aData if token] + return aData, Type + + if Type == REG_LINK: + szData = ctypes.create_unicode_buffer(cbData.value) + _RegQueryValueEx(hKey, lpValueName, None, None, byref(szData), byref(cbData)) + return szData.value, Type + + # REG_BINARY, REG_NONE, and any future types + szData = ctypes.create_string_buffer(cbData.value) + _RegQueryValueEx(hKey, lpValueName, None, None, byref(szData), byref(cbData)) + return szData.raw, Type + +def _caller_RegQueryValueEx(ansi): + if ansi: + _RegQueryValueEx = windll.advapi32.RegQueryValueExA + _RegQueryValueEx.argtypes = [HKEY, LPSTR, LPVOID, PDWORD, LPVOID, PDWORD] + else: + _RegQueryValueEx = windll.advapi32.RegQueryValueExW + _RegQueryValueEx.argtypes = [HKEY, LPWSTR, LPVOID, PDWORD, LPVOID, PDWORD] + _RegQueryValueEx.restype = LONG + _RegQueryValueEx.errcheck = RaiseIfNotErrorSuccess + return _RegQueryValueEx + +# see _internal_RegQueryValueEx +def RegQueryValueExA(hKey, lpValueName = None, bGetData = True): + return _internal_RegQueryValueEx(True, hKey, lpValueName, bGetData) + +# see _internal_RegQueryValueEx +def RegQueryValueExW(hKey, lpValueName = None, bGetData = True): + return _internal_RegQueryValueEx(False, hKey, lpValueName, bGetData) + +RegQueryValueEx = GuessStringType(RegQueryValueExA, RegQueryValueExW) + +# LONG WINAPI RegSetValueEx( +# __in HKEY hKey, +# __in_opt LPCTSTR lpValueName, +# __reserved DWORD Reserved, +# __in DWORD dwType, +# __in_opt const BYTE *lpData, +# __in DWORD cbData +# ); +def RegSetValueEx(hKey, lpValueName = None, lpData = None, dwType = None): + + # Determine which version of the API to use, ANSI or Widechar. + if lpValueName is None: + if isinstance(lpData, GuessStringType.t_ansi): + ansi = True + elif isinstance(lpData, GuessStringType.t_unicode): + ansi = False + else: + ansi = (GuessStringType.t_ansi == GuessStringType.t_default) + elif isinstance(lpValueName, GuessStringType.t_ansi): + ansi = True + elif isinstance(lpValueName, GuessStringType.t_unicode): + ansi = False + else: + raise TypeError("String expected, got %s instead" % type(lpValueName)) + + # Autodetect the type when not given. + # TODO: improve detection of DWORD and QWORD by seeing if the value "fits". + if dwType is None: + if lpValueName is None: + dwType = REG_SZ + elif lpData is None: + dwType = REG_NONE + elif isinstance(lpData, GuessStringType.t_ansi): + dwType = REG_SZ + elif isinstance(lpData, GuessStringType.t_unicode): + dwType = REG_SZ + elif isinstance(lpData, int): + dwType = REG_DWORD + elif isinstance(lpData, long): + dwType = REG_QWORD + else: + dwType = REG_BINARY + + # Load the ctypes caller. + if ansi: + _RegSetValueEx = windll.advapi32.RegSetValueExA + _RegSetValueEx.argtypes = [HKEY, LPSTR, DWORD, DWORD, LPVOID, DWORD] + else: + _RegSetValueEx = windll.advapi32.RegSetValueExW + _RegSetValueEx.argtypes = [HKEY, LPWSTR, DWORD, DWORD, LPVOID, DWORD] + _RegSetValueEx.restype = LONG + _RegSetValueEx.errcheck = RaiseIfNotErrorSuccess + + # Convert the arguments so ctypes can understand them. + if lpData is None: + DataRef = None + DataSize = 0 + else: + if dwType in (REG_DWORD, REG_DWORD_BIG_ENDIAN): # REG_DWORD_LITTLE_ENDIAN + Data = DWORD(lpData) + elif dwType == REG_QWORD: # REG_QWORD_LITTLE_ENDIAN + Data = QWORD(lpData) + elif dwType in (REG_SZ, REG_EXPAND_SZ): + if ansi: + Data = ctypes.create_string_buffer(lpData) + else: + Data = ctypes.create_unicode_buffer(lpData) + elif dwType == REG_MULTI_SZ: + if ansi: + Data = ctypes.create_string_buffer('\0'.join(lpData) + '\0\0') + else: + Data = ctypes.create_unicode_buffer(u'\0'.join(lpData) + u'\0\0') + elif dwType == REG_LINK: + Data = ctypes.create_unicode_buffer(lpData) + else: + Data = ctypes.create_string_buffer(lpData) + DataRef = byref(Data) + DataSize = sizeof(Data) + + # Call the API with the converted arguments. + _RegSetValueEx(hKey, lpValueName, 0, dwType, DataRef, DataSize) + +# No "GuessStringType" here since detection is done inside. +RegSetValueExA = RegSetValueExW = RegSetValueEx + +# LONG WINAPI RegEnumKey( +# __in HKEY hKey, +# __in DWORD dwIndex, +# __out LPTSTR lpName, +# __in DWORD cchName +# ); +def RegEnumKeyA(hKey, dwIndex): + _RegEnumKeyA = windll.advapi32.RegEnumKeyA + _RegEnumKeyA.argtypes = [HKEY, DWORD, LPSTR, DWORD] + _RegEnumKeyA.restype = LONG + + cchName = 1024 + while True: + lpName = ctypes.create_string_buffer(cchName) + errcode = _RegEnumKeyA(hKey, dwIndex, lpName, cchName) + if errcode != ERROR_MORE_DATA: + break + cchName = cchName + 1024 + if cchName > 65536: + raise ctypes.WinError(errcode) + if errcode == ERROR_NO_MORE_ITEMS: + return None + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return lpName.value + +def RegEnumKeyW(hKey, dwIndex): + _RegEnumKeyW = windll.advapi32.RegEnumKeyW + _RegEnumKeyW.argtypes = [HKEY, DWORD, LPWSTR, DWORD] + _RegEnumKeyW.restype = LONG + + cchName = 512 + while True: + lpName = ctypes.create_unicode_buffer(cchName) + errcode = _RegEnumKeyW(hKey, dwIndex, lpName, cchName * 2) + if errcode != ERROR_MORE_DATA: + break + cchName = cchName + 512 + if cchName > 32768: + raise ctypes.WinError(errcode) + if errcode == ERROR_NO_MORE_ITEMS: + return None + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return lpName.value + +RegEnumKey = DefaultStringType(RegEnumKeyA, RegEnumKeyW) + +# LONG WINAPI RegEnumKeyEx( +# __in HKEY hKey, +# __in DWORD dwIndex, +# __out LPTSTR lpName, +# __inout LPDWORD lpcName, +# __reserved LPDWORD lpReserved, +# __inout LPTSTR lpClass, +# __inout_opt LPDWORD lpcClass, +# __out_opt PFILETIME lpftLastWriteTime +# ); + +# XXX TODO + +# LONG WINAPI RegEnumValue( +# __in HKEY hKey, +# __in DWORD dwIndex, +# __out LPTSTR lpValueName, +# __inout LPDWORD lpcchValueName, +# __reserved LPDWORD lpReserved, +# __out_opt LPDWORD lpType, +# __out_opt LPBYTE lpData, +# __inout_opt LPDWORD lpcbData +# ); +def _internal_RegEnumValue(ansi, hKey, dwIndex, bGetData = True): + if ansi: + _RegEnumValue = windll.advapi32.RegEnumValueA + _RegEnumValue.argtypes = [HKEY, DWORD, LPSTR, LPDWORD, LPVOID, LPDWORD, LPVOID, LPDWORD] + else: + _RegEnumValue = windll.advapi32.RegEnumValueW + _RegEnumValue.argtypes = [HKEY, DWORD, LPWSTR, LPDWORD, LPVOID, LPDWORD, LPVOID, LPDWORD] + _RegEnumValue.restype = LONG + + cchValueName = DWORD(1024) + dwType = DWORD(-1) + lpcchValueName = byref(cchValueName) + lpType = byref(dwType) + if ansi: + lpValueName = ctypes.create_string_buffer(cchValueName.value) + else: + lpValueName = ctypes.create_unicode_buffer(cchValueName.value) + if bGetData: + cbData = DWORD(0) + lpcbData = byref(cbData) + else: + lpcbData = None + lpData = None + errcode = _RegEnumValue(hKey, dwIndex, lpValueName, lpcchValueName, None, lpType, lpData, lpcbData) + + if errcode == ERROR_MORE_DATA or (bGetData and errcode == ERROR_SUCCESS): + if ansi: + cchValueName.value = cchValueName.value + sizeof(CHAR) + lpValueName = ctypes.create_string_buffer(cchValueName.value) + else: + cchValueName.value = cchValueName.value + sizeof(WCHAR) + lpValueName = ctypes.create_unicode_buffer(cchValueName.value) + + if bGetData: + Type = dwType.value + + if Type in (REG_DWORD, REG_DWORD_BIG_ENDIAN): # REG_DWORD_LITTLE_ENDIAN + if cbData.value != sizeof(DWORD): + raise ValueError("REG_DWORD value of size %d" % cbData.value) + Data = DWORD(0) + + elif Type == REG_QWORD: # REG_QWORD_LITTLE_ENDIAN + if cbData.value != sizeof(QWORD): + raise ValueError("REG_QWORD value of size %d" % cbData.value) + Data = QWORD(long(0)) + + elif Type in (REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ): + if ansi: + Data = ctypes.create_string_buffer(cbData.value) + else: + Data = ctypes.create_unicode_buffer(cbData.value) + + elif Type == REG_LINK: + Data = ctypes.create_unicode_buffer(cbData.value) + + else: # REG_BINARY, REG_NONE, and any future types + Data = ctypes.create_string_buffer(cbData.value) + + lpData = byref(Data) + + errcode = _RegEnumValue(hKey, dwIndex, lpValueName, lpcchValueName, None, lpType, lpData, lpcbData) + + if errcode == ERROR_NO_MORE_ITEMS: + return None + #if errcode != ERROR_SUCCESS: + # raise ctypes.WinError(errcode) + + if not bGetData: + return lpValueName.value, dwType.value + + if Type in (REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_QWORD, REG_SZ, REG_EXPAND_SZ, REG_LINK): # REG_DWORD_LITTLE_ENDIAN, REG_QWORD_LITTLE_ENDIAN + return lpValueName.value, dwType.value, Data.value + + if Type == REG_MULTI_SZ: + sData = Data[:] + del Data + if ansi: + aData = sData.split('\0') + else: + aData = sData.split(u'\0') + aData = [token for token in aData if token] + return lpValueName.value, dwType.value, aData + + # REG_BINARY, REG_NONE, and any future types + return lpValueName.value, dwType.value, Data.raw + +def RegEnumValueA(hKey, dwIndex, bGetData = True): + return _internal_RegEnumValue(True, hKey, dwIndex, bGetData) + +def RegEnumValueW(hKey, dwIndex, bGetData = True): + return _internal_RegEnumValue(False, hKey, dwIndex, bGetData) + +RegEnumValue = DefaultStringType(RegEnumValueA, RegEnumValueW) + +# XXX TODO + +# LONG WINAPI RegSetKeyValue( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey, +# __in_opt LPCTSTR lpValueName, +# __in DWORD dwType, +# __in_opt LPCVOID lpData, +# __in DWORD cbData +# ); + +# XXX TODO + +# LONG WINAPI RegQueryMultipleValues( +# __in HKEY hKey, +# __out PVALENT val_list, +# __in DWORD num_vals, +# __out_opt LPTSTR lpValueBuf, +# __inout_opt LPDWORD ldwTotsize +# ); + +# XXX TODO + +# LONG WINAPI RegDeleteValue( +# __in HKEY hKey, +# __in_opt LPCTSTR lpValueName +# ); +def RegDeleteValueA(hKeySrc, lpValueName = None): + _RegDeleteValueA = windll.advapi32.RegDeleteValueA + _RegDeleteValueA.argtypes = [HKEY, LPSTR] + _RegDeleteValueA.restype = LONG + _RegDeleteValueA.errcheck = RaiseIfNotErrorSuccess + _RegDeleteValueA(hKeySrc, lpValueName) +def RegDeleteValueW(hKeySrc, lpValueName = None): + _RegDeleteValueW = windll.advapi32.RegDeleteValueW + _RegDeleteValueW.argtypes = [HKEY, LPWSTR] + _RegDeleteValueW.restype = LONG + _RegDeleteValueW.errcheck = RaiseIfNotErrorSuccess + _RegDeleteValueW(hKeySrc, lpValueName) +RegDeleteValue = GuessStringType(RegDeleteValueA, RegDeleteValueW) + +# LONG WINAPI RegDeleteKeyValue( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey, +# __in_opt LPCTSTR lpValueName +# ); +def RegDeleteKeyValueA(hKeySrc, lpSubKey = None, lpValueName = None): + _RegDeleteKeyValueA = windll.advapi32.RegDeleteKeyValueA + _RegDeleteKeyValueA.argtypes = [HKEY, LPSTR, LPSTR] + _RegDeleteKeyValueA.restype = LONG + _RegDeleteKeyValueA.errcheck = RaiseIfNotErrorSuccess + _RegDeleteKeyValueA(hKeySrc, lpSubKey, lpValueName) +def RegDeleteKeyValueW(hKeySrc, lpSubKey = None, lpValueName = None): + _RegDeleteKeyValueW = windll.advapi32.RegDeleteKeyValueW + _RegDeleteKeyValueW.argtypes = [HKEY, LPWSTR, LPWSTR] + _RegDeleteKeyValueW.restype = LONG + _RegDeleteKeyValueW.errcheck = RaiseIfNotErrorSuccess + _RegDeleteKeyValueW(hKeySrc, lpSubKey, lpValueName) +RegDeleteKeyValue = GuessStringType(RegDeleteKeyValueA, RegDeleteKeyValueW) + +# LONG WINAPI RegDeleteKey( +# __in HKEY hKey, +# __in LPCTSTR lpSubKey +# ); +def RegDeleteKeyA(hKeySrc, lpSubKey = None): + _RegDeleteKeyA = windll.advapi32.RegDeleteKeyA + _RegDeleteKeyA.argtypes = [HKEY, LPSTR] + _RegDeleteKeyA.restype = LONG + _RegDeleteKeyA.errcheck = RaiseIfNotErrorSuccess + _RegDeleteKeyA(hKeySrc, lpSubKey) +def RegDeleteKeyW(hKeySrc, lpSubKey = None): + _RegDeleteKeyW = windll.advapi32.RegDeleteKeyW + _RegDeleteKeyW.argtypes = [HKEY, LPWSTR] + _RegDeleteKeyW.restype = LONG + _RegDeleteKeyW.errcheck = RaiseIfNotErrorSuccess + _RegDeleteKeyW(hKeySrc, lpSubKey) +RegDeleteKey = GuessStringType(RegDeleteKeyA, RegDeleteKeyW) + +# LONG WINAPI RegDeleteKeyEx( +# __in HKEY hKey, +# __in LPCTSTR lpSubKey, +# __in REGSAM samDesired, +# __reserved DWORD Reserved +# ); + +def RegDeleteKeyExA(hKeySrc, lpSubKey = None, samDesired = KEY_WOW64_32KEY): + _RegDeleteKeyExA = windll.advapi32.RegDeleteKeyExA + _RegDeleteKeyExA.argtypes = [HKEY, LPSTR, REGSAM, DWORD] + _RegDeleteKeyExA.restype = LONG + _RegDeleteKeyExA.errcheck = RaiseIfNotErrorSuccess + _RegDeleteKeyExA(hKeySrc, lpSubKey, samDesired, 0) +def RegDeleteKeyExW(hKeySrc, lpSubKey = None, samDesired = KEY_WOW64_32KEY): + _RegDeleteKeyExW = windll.advapi32.RegDeleteKeyExW + _RegDeleteKeyExW.argtypes = [HKEY, LPWSTR, REGSAM, DWORD] + _RegDeleteKeyExW.restype = LONG + _RegDeleteKeyExW.errcheck = RaiseIfNotErrorSuccess + _RegDeleteKeyExW(hKeySrc, lpSubKey, samDesired, 0) +RegDeleteKeyEx = GuessStringType(RegDeleteKeyExA, RegDeleteKeyExW) + +# LONG WINAPI RegCopyTree( +# __in HKEY hKeySrc, +# __in_opt LPCTSTR lpSubKey, +# __in HKEY hKeyDest +# ); +def RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest): + _RegCopyTreeA = windll.advapi32.RegCopyTreeA + _RegCopyTreeA.argtypes = [HKEY, LPSTR, HKEY] + _RegCopyTreeA.restype = LONG + _RegCopyTreeA.errcheck = RaiseIfNotErrorSuccess + _RegCopyTreeA(hKeySrc, lpSubKey, hKeyDest) +def RegCopyTreeW(hKeySrc, lpSubKey, hKeyDest): + _RegCopyTreeW = windll.advapi32.RegCopyTreeW + _RegCopyTreeW.argtypes = [HKEY, LPWSTR, HKEY] + _RegCopyTreeW.restype = LONG + _RegCopyTreeW.errcheck = RaiseIfNotErrorSuccess + _RegCopyTreeW(hKeySrc, lpSubKey, hKeyDest) +RegCopyTree = GuessStringType(RegCopyTreeA, RegCopyTreeW) + +# LONG WINAPI RegDeleteTree( +# __in HKEY hKey, +# __in_opt LPCTSTR lpSubKey +# ); +def RegDeleteTreeA(hKey, lpSubKey = None): + _RegDeleteTreeA = windll.advapi32.RegDeleteTreeA + _RegDeleteTreeA.argtypes = [HKEY, LPWSTR] + _RegDeleteTreeA.restype = LONG + _RegDeleteTreeA.errcheck = RaiseIfNotErrorSuccess + _RegDeleteTreeA(hKey, lpSubKey) +def RegDeleteTreeW(hKey, lpSubKey = None): + _RegDeleteTreeW = windll.advapi32.RegDeleteTreeW + _RegDeleteTreeW.argtypes = [HKEY, LPWSTR] + _RegDeleteTreeW.restype = LONG + _RegDeleteTreeW.errcheck = RaiseIfNotErrorSuccess + _RegDeleteTreeW(hKey, lpSubKey) +RegDeleteTree = GuessStringType(RegDeleteTreeA, RegDeleteTreeW) + +# LONG WINAPI RegFlushKey( +# __in HKEY hKey +# ); +def RegFlushKey(hKey): + _RegFlushKey = windll.advapi32.RegFlushKey + _RegFlushKey.argtypes = [HKEY] + _RegFlushKey.restype = LONG + _RegFlushKey.errcheck = RaiseIfNotErrorSuccess + _RegFlushKey(hKey) + +# LONG WINAPI RegLoadMUIString( +# _In_ HKEY hKey, +# _In_opt_ LPCTSTR pszValue, +# _Out_opt_ LPTSTR pszOutBuf, +# _In_ DWORD cbOutBuf, +# _Out_opt_ LPDWORD pcbData, +# _In_ DWORD Flags, +# _In_opt_ LPCTSTR pszDirectory +# ); + +# TO DO + +#------------------------------------------------------------------------------ + +# BOOL WINAPI CloseServiceHandle( +# _In_ SC_HANDLE hSCObject +# ); +def CloseServiceHandle(hSCObject): + _CloseServiceHandle = windll.advapi32.CloseServiceHandle + _CloseServiceHandle.argtypes = [SC_HANDLE] + _CloseServiceHandle.restype = bool + _CloseServiceHandle.errcheck = RaiseIfZero + + if isinstance(hSCObject, Handle): + # Prevents the handle from being closed without notifying the Handle object. + hSCObject.close() + else: + _CloseServiceHandle(hSCObject) + +# SC_HANDLE WINAPI OpenSCManager( +# _In_opt_ LPCTSTR lpMachineName, +# _In_opt_ LPCTSTR lpDatabaseName, +# _In_ DWORD dwDesiredAccess +# ); +def OpenSCManagerA(lpMachineName = None, lpDatabaseName = None, dwDesiredAccess = SC_MANAGER_ALL_ACCESS): + _OpenSCManagerA = windll.advapi32.OpenSCManagerA + _OpenSCManagerA.argtypes = [LPSTR, LPSTR, DWORD] + _OpenSCManagerA.restype = SC_HANDLE + _OpenSCManagerA.errcheck = RaiseIfZero + + hSCObject = _OpenSCManagerA(lpMachineName, lpDatabaseName, dwDesiredAccess) + return ServiceControlManagerHandle(hSCObject) + +def OpenSCManagerW(lpMachineName = None, lpDatabaseName = None, dwDesiredAccess = SC_MANAGER_ALL_ACCESS): + _OpenSCManagerW = windll.advapi32.OpenSCManagerW + _OpenSCManagerW.argtypes = [LPWSTR, LPWSTR, DWORD] + _OpenSCManagerW.restype = SC_HANDLE + _OpenSCManagerW.errcheck = RaiseIfZero + + hSCObject = _OpenSCManagerA(lpMachineName, lpDatabaseName, dwDesiredAccess) + return ServiceControlManagerHandle(hSCObject) + +OpenSCManager = GuessStringType(OpenSCManagerA, OpenSCManagerW) + +# SC_HANDLE WINAPI OpenService( +# _In_ SC_HANDLE hSCManager, +# _In_ LPCTSTR lpServiceName, +# _In_ DWORD dwDesiredAccess +# ); +def OpenServiceA(hSCManager, lpServiceName, dwDesiredAccess = SERVICE_ALL_ACCESS): + _OpenServiceA = windll.advapi32.OpenServiceA + _OpenServiceA.argtypes = [SC_HANDLE, LPSTR, DWORD] + _OpenServiceA.restype = SC_HANDLE + _OpenServiceA.errcheck = RaiseIfZero + return ServiceHandle( _OpenServiceA(hSCManager, lpServiceName, dwDesiredAccess) ) + +def OpenServiceW(hSCManager, lpServiceName, dwDesiredAccess = SERVICE_ALL_ACCESS): + _OpenServiceW = windll.advapi32.OpenServiceW + _OpenServiceW.argtypes = [SC_HANDLE, LPWSTR, DWORD] + _OpenServiceW.restype = SC_HANDLE + _OpenServiceW.errcheck = RaiseIfZero + return ServiceHandle( _OpenServiceW(hSCManager, lpServiceName, dwDesiredAccess) ) + +OpenService = GuessStringType(OpenServiceA, OpenServiceW) + +# SC_HANDLE WINAPI CreateService( +# _In_ SC_HANDLE hSCManager, +# _In_ LPCTSTR lpServiceName, +# _In_opt_ LPCTSTR lpDisplayName, +# _In_ DWORD dwDesiredAccess, +# _In_ DWORD dwServiceType, +# _In_ DWORD dwStartType, +# _In_ DWORD dwErrorControl, +# _In_opt_ LPCTSTR lpBinaryPathName, +# _In_opt_ LPCTSTR lpLoadOrderGroup, +# _Out_opt_ LPDWORD lpdwTagId, +# _In_opt_ LPCTSTR lpDependencies, +# _In_opt_ LPCTSTR lpServiceStartName, +# _In_opt_ LPCTSTR lpPassword +# ); +def CreateServiceA(hSCManager, lpServiceName, + lpDisplayName = None, + dwDesiredAccess = SERVICE_ALL_ACCESS, + dwServiceType = SERVICE_WIN32_OWN_PROCESS, + dwStartType = SERVICE_DEMAND_START, + dwErrorControl = SERVICE_ERROR_NORMAL, + lpBinaryPathName = None, + lpLoadOrderGroup = None, + lpDependencies = None, + lpServiceStartName = None, + lpPassword = None): + + _CreateServiceA = windll.advapi32.CreateServiceA + _CreateServiceA.argtypes = [SC_HANDLE, LPSTR, LPSTR, DWORD, DWORD, DWORD, DWORD, LPSTR, LPSTR, LPDWORD, LPSTR, LPSTR, LPSTR] + _CreateServiceA.restype = SC_HANDLE + _CreateServiceA.errcheck = RaiseIfZero + + dwTagId = DWORD(0) + hService = _CreateServiceA(hSCManager, lpServiceName, dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, byref(dwTagId), lpDependencies, lpServiceStartName, lpPassword) + return ServiceHandle(hService), dwTagId.value + +def CreateServiceW(hSCManager, lpServiceName, + lpDisplayName = None, + dwDesiredAccess = SERVICE_ALL_ACCESS, + dwServiceType = SERVICE_WIN32_OWN_PROCESS, + dwStartType = SERVICE_DEMAND_START, + dwErrorControl = SERVICE_ERROR_NORMAL, + lpBinaryPathName = None, + lpLoadOrderGroup = None, + lpDependencies = None, + lpServiceStartName = None, + lpPassword = None): + + _CreateServiceW = windll.advapi32.CreateServiceW + _CreateServiceW.argtypes = [SC_HANDLE, LPWSTR, LPWSTR, DWORD, DWORD, DWORD, DWORD, LPWSTR, LPWSTR, LPDWORD, LPWSTR, LPWSTR, LPWSTR] + _CreateServiceW.restype = SC_HANDLE + _CreateServiceW.errcheck = RaiseIfZero + + dwTagId = DWORD(0) + hService = _CreateServiceW(hSCManager, lpServiceName, dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, byref(dwTagId), lpDependencies, lpServiceStartName, lpPassword) + return ServiceHandle(hService), dwTagId.value + +CreateService = GuessStringType(CreateServiceA, CreateServiceW) + +# BOOL WINAPI DeleteService( +# _In_ SC_HANDLE hService +# ); +def DeleteService(hService): + _DeleteService = windll.advapi32.DeleteService + _DeleteService.argtypes = [SC_HANDLE] + _DeleteService.restype = bool + _DeleteService.errcheck = RaiseIfZero + _DeleteService(hService) + +# BOOL WINAPI GetServiceKeyName( +# _In_ SC_HANDLE hSCManager, +# _In_ LPCTSTR lpDisplayName, +# _Out_opt_ LPTSTR lpServiceName, +# _Inout_ LPDWORD lpcchBuffer +# ); +def GetServiceKeyNameA(hSCManager, lpDisplayName): + _GetServiceKeyNameA = windll.advapi32.GetServiceKeyNameA + _GetServiceKeyNameA.argtypes = [SC_HANDLE, LPSTR, LPSTR, LPDWORD] + _GetServiceKeyNameA.restype = bool + + cchBuffer = DWORD(0) + _GetServiceKeyNameA(hSCManager, lpDisplayName, None, byref(cchBuffer)) + if cchBuffer.value == 0: + raise ctypes.WinError() + lpServiceName = ctypes.create_string_buffer(cchBuffer.value + 1) + cchBuffer.value = sizeof(lpServiceName) + success = _GetServiceKeyNameA(hSCManager, lpDisplayName, lpServiceName, byref(cchBuffer)) + if not success: + raise ctypes.WinError() + return lpServiceName.value + +def GetServiceKeyNameW(hSCManager, lpDisplayName): + _GetServiceKeyNameW = windll.advapi32.GetServiceKeyNameW + _GetServiceKeyNameW.argtypes = [SC_HANDLE, LPWSTR, LPWSTR, LPDWORD] + _GetServiceKeyNameW.restype = bool + + cchBuffer = DWORD(0) + _GetServiceKeyNameW(hSCManager, lpDisplayName, None, byref(cchBuffer)) + if cchBuffer.value == 0: + raise ctypes.WinError() + lpServiceName = ctypes.create_unicode_buffer(cchBuffer.value + 2) + cchBuffer.value = sizeof(lpServiceName) + success = _GetServiceKeyNameW(hSCManager, lpDisplayName, lpServiceName, byref(cchBuffer)) + if not success: + raise ctypes.WinError() + return lpServiceName.value + +GetServiceKeyName = GuessStringType(GetServiceKeyNameA, GetServiceKeyNameW) + +# BOOL WINAPI GetServiceDisplayName( +# _In_ SC_HANDLE hSCManager, +# _In_ LPCTSTR lpServiceName, +# _Out_opt_ LPTSTR lpDisplayName, +# _Inout_ LPDWORD lpcchBuffer +# ); +def GetServiceDisplayNameA(hSCManager, lpServiceName): + _GetServiceDisplayNameA = windll.advapi32.GetServiceDisplayNameA + _GetServiceDisplayNameA.argtypes = [SC_HANDLE, LPSTR, LPSTR, LPDWORD] + _GetServiceDisplayNameA.restype = bool + + cchBuffer = DWORD(0) + _GetServiceDisplayNameA(hSCManager, lpServiceName, None, byref(cchBuffer)) + if cchBuffer.value == 0: + raise ctypes.WinError() + lpDisplayName = ctypes.create_string_buffer(cchBuffer.value + 1) + cchBuffer.value = sizeof(lpDisplayName) + success = _GetServiceDisplayNameA(hSCManager, lpServiceName, lpDisplayName, byref(cchBuffer)) + if not success: + raise ctypes.WinError() + return lpDisplayName.value + +def GetServiceDisplayNameW(hSCManager, lpServiceName): + _GetServiceDisplayNameW = windll.advapi32.GetServiceDisplayNameW + _GetServiceDisplayNameW.argtypes = [SC_HANDLE, LPWSTR, LPWSTR, LPDWORD] + _GetServiceDisplayNameW.restype = bool + + cchBuffer = DWORD(0) + _GetServiceDisplayNameW(hSCManager, lpServiceName, None, byref(cchBuffer)) + if cchBuffer.value == 0: + raise ctypes.WinError() + lpDisplayName = ctypes.create_unicode_buffer(cchBuffer.value + 2) + cchBuffer.value = sizeof(lpDisplayName) + success = _GetServiceDisplayNameW(hSCManager, lpServiceName, lpDisplayName, byref(cchBuffer)) + if not success: + raise ctypes.WinError() + return lpDisplayName.value + +GetServiceDisplayName = GuessStringType(GetServiceDisplayNameA, GetServiceDisplayNameW) + +# BOOL WINAPI QueryServiceConfig( +# _In_ SC_HANDLE hService, +# _Out_opt_ LPQUERY_SERVICE_CONFIG lpServiceConfig, +# _In_ DWORD cbBufSize, +# _Out_ LPDWORD pcbBytesNeeded +# ); + +# TO DO + +# BOOL WINAPI QueryServiceConfig2( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwInfoLevel, +# _Out_opt_ LPBYTE lpBuffer, +# _In_ DWORD cbBufSize, +# _Out_ LPDWORD pcbBytesNeeded +# ); + +# TO DO + +# BOOL WINAPI ChangeServiceConfig( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwServiceType, +# _In_ DWORD dwStartType, +# _In_ DWORD dwErrorControl, +# _In_opt_ LPCTSTR lpBinaryPathName, +# _In_opt_ LPCTSTR lpLoadOrderGroup, +# _Out_opt_ LPDWORD lpdwTagId, +# _In_opt_ LPCTSTR lpDependencies, +# _In_opt_ LPCTSTR lpServiceStartName, +# _In_opt_ LPCTSTR lpPassword, +# _In_opt_ LPCTSTR lpDisplayName +# ); + +# TO DO + +# BOOL WINAPI ChangeServiceConfig2( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwInfoLevel, +# _In_opt_ LPVOID lpInfo +# ); + +# TO DO + +# BOOL WINAPI StartService( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwNumServiceArgs, +# _In_opt_ LPCTSTR *lpServiceArgVectors +# ); +def StartServiceA(hService, ServiceArgVectors = None): + _StartServiceA = windll.advapi32.StartServiceA + _StartServiceA.argtypes = [SC_HANDLE, DWORD, LPVOID] + _StartServiceA.restype = bool + _StartServiceA.errcheck = RaiseIfZero + + if ServiceArgVectors: + dwNumServiceArgs = len(ServiceArgVectors) + CServiceArgVectors = (LPSTR * dwNumServiceArgs)(*ServiceArgVectors) + lpServiceArgVectors = ctypes.pointer(CServiceArgVectors) + else: + dwNumServiceArgs = 0 + lpServiceArgVectors = None + _StartServiceA(hService, dwNumServiceArgs, lpServiceArgVectors) + +def StartServiceW(hService, ServiceArgVectors = None): + _StartServiceW = windll.advapi32.StartServiceW + _StartServiceW.argtypes = [SC_HANDLE, DWORD, LPVOID] + _StartServiceW.restype = bool + _StartServiceW.errcheck = RaiseIfZero + + if ServiceArgVectors: + dwNumServiceArgs = len(ServiceArgVectors) + CServiceArgVectors = (LPWSTR * dwNumServiceArgs)(*ServiceArgVectors) + lpServiceArgVectors = ctypes.pointer(CServiceArgVectors) + else: + dwNumServiceArgs = 0 + lpServiceArgVectors = None + _StartServiceW(hService, dwNumServiceArgs, lpServiceArgVectors) + +StartService = GuessStringType(StartServiceA, StartServiceW) + +# BOOL WINAPI ControlService( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwControl, +# _Out_ LPSERVICE_STATUS lpServiceStatus +# ); +def ControlService(hService, dwControl): + _ControlService = windll.advapi32.ControlService + _ControlService.argtypes = [SC_HANDLE, DWORD, LPSERVICE_STATUS] + _ControlService.restype = bool + _ControlService.errcheck = RaiseIfZero + + rawServiceStatus = SERVICE_STATUS() + _ControlService(hService, dwControl, byref(rawServiceStatus)) + return ServiceStatus(rawServiceStatus) + +# BOOL WINAPI ControlServiceEx( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwControl, +# _In_ DWORD dwInfoLevel, +# _Inout_ PVOID pControlParams +# ); + +# TO DO + +# DWORD WINAPI NotifyServiceStatusChange( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwNotifyMask, +# _In_ PSERVICE_NOTIFY pNotifyBuffer +# ); + +# TO DO + +# BOOL WINAPI QueryServiceStatus( +# _In_ SC_HANDLE hService, +# _Out_ LPSERVICE_STATUS lpServiceStatus +# ); +def QueryServiceStatus(hService): + _QueryServiceStatus = windll.advapi32.QueryServiceStatus + _QueryServiceStatus.argtypes = [SC_HANDLE, LPSERVICE_STATUS] + _QueryServiceStatus.restype = bool + _QueryServiceStatus.errcheck = RaiseIfZero + + rawServiceStatus = SERVICE_STATUS() + _QueryServiceStatus(hService, byref(rawServiceStatus)) + return ServiceStatus(rawServiceStatus) + +# BOOL WINAPI QueryServiceStatusEx( +# _In_ SC_HANDLE hService, +# _In_ SC_STATUS_TYPE InfoLevel, +# _Out_opt_ LPBYTE lpBuffer, +# _In_ DWORD cbBufSize, +# _Out_ LPDWORD pcbBytesNeeded +# ); +def QueryServiceStatusEx(hService, InfoLevel = SC_STATUS_PROCESS_INFO): + + if InfoLevel != SC_STATUS_PROCESS_INFO: + raise NotImplementedError() + + _QueryServiceStatusEx = windll.advapi32.QueryServiceStatusEx + _QueryServiceStatusEx.argtypes = [SC_HANDLE, SC_STATUS_TYPE, LPVOID, DWORD, LPDWORD] + _QueryServiceStatusEx.restype = bool + _QueryServiceStatusEx.errcheck = RaiseIfZero + + lpBuffer = SERVICE_STATUS_PROCESS() + cbBytesNeeded = DWORD(sizeof(lpBuffer)) + _QueryServiceStatusEx(hService, InfoLevel, byref(lpBuffer), sizeof(lpBuffer), byref(cbBytesNeeded)) + return ServiceStatusProcess(lpBuffer) + +# BOOL WINAPI EnumServicesStatus( +# _In_ SC_HANDLE hSCManager, +# _In_ DWORD dwServiceType, +# _In_ DWORD dwServiceState, +# _Out_opt_ LPENUM_SERVICE_STATUS lpServices, +# _In_ DWORD cbBufSize, +# _Out_ LPDWORD pcbBytesNeeded, +# _Out_ LPDWORD lpServicesReturned, +# _Inout_opt_ LPDWORD lpResumeHandle +# ); +def EnumServicesStatusA(hSCManager, dwServiceType = SERVICE_DRIVER | SERVICE_WIN32, dwServiceState = SERVICE_STATE_ALL): + _EnumServicesStatusA = windll.advapi32.EnumServicesStatusA + _EnumServicesStatusA.argtypes = [SC_HANDLE, DWORD, DWORD, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD] + _EnumServicesStatusA.restype = bool + + cbBytesNeeded = DWORD(0) + ServicesReturned = DWORD(0) + ResumeHandle = DWORD(0) + + _EnumServicesStatusA(hSCManager, dwServiceType, dwServiceState, None, 0, byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle)) + + Services = [] + success = False + while GetLastError() == ERROR_MORE_DATA: + if cbBytesNeeded.value < sizeof(ENUM_SERVICE_STATUSA): + break + ServicesBuffer = ctypes.create_string_buffer("", cbBytesNeeded.value) + success = _EnumServicesStatusA(hSCManager, dwServiceType, dwServiceState, byref(ServicesBuffer), sizeof(ServicesBuffer), byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle)) + if sizeof(ServicesBuffer) < (sizeof(ENUM_SERVICE_STATUSA) * ServicesReturned.value): + raise ctypes.WinError() + lpServicesArray = ctypes.cast(ctypes.cast(ctypes.pointer(ServicesBuffer), ctypes.c_void_p), LPENUM_SERVICE_STATUSA) + for index in compat.xrange(0, ServicesReturned.value): + Services.append( ServiceStatusEntry(lpServicesArray[index]) ) + if success: break + if not success: + raise ctypes.WinError() + + return Services + +def EnumServicesStatusW(hSCManager, dwServiceType = SERVICE_DRIVER | SERVICE_WIN32, dwServiceState = SERVICE_STATE_ALL): + _EnumServicesStatusW = windll.advapi32.EnumServicesStatusW + _EnumServicesStatusW.argtypes = [SC_HANDLE, DWORD, DWORD, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD] + _EnumServicesStatusW.restype = bool + + cbBytesNeeded = DWORD(0) + ServicesReturned = DWORD(0) + ResumeHandle = DWORD(0) + + _EnumServicesStatusW(hSCManager, dwServiceType, dwServiceState, None, 0, byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle)) + + Services = [] + success = False + while GetLastError() == ERROR_MORE_DATA: + if cbBytesNeeded.value < sizeof(ENUM_SERVICE_STATUSW): + break + ServicesBuffer = ctypes.create_string_buffer("", cbBytesNeeded.value) + success = _EnumServicesStatusW(hSCManager, dwServiceType, dwServiceState, byref(ServicesBuffer), sizeof(ServicesBuffer), byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle)) + if sizeof(ServicesBuffer) < (sizeof(ENUM_SERVICE_STATUSW) * ServicesReturned.value): + raise ctypes.WinError() + lpServicesArray = ctypes.cast(ctypes.cast(ctypes.pointer(ServicesBuffer), ctypes.c_void_p), LPENUM_SERVICE_STATUSW) + for index in compat.xrange(0, ServicesReturned.value): + Services.append( ServiceStatusEntry(lpServicesArray[index]) ) + if success: break + if not success: + raise ctypes.WinError() + + return Services + +EnumServicesStatus = DefaultStringType(EnumServicesStatusA, EnumServicesStatusW) + +# BOOL WINAPI EnumServicesStatusEx( +# _In_ SC_HANDLE hSCManager, +# _In_ SC_ENUM_TYPE InfoLevel, +# _In_ DWORD dwServiceType, +# _In_ DWORD dwServiceState, +# _Out_opt_ LPBYTE lpServices, +# _In_ DWORD cbBufSize, +# _Out_ LPDWORD pcbBytesNeeded, +# _Out_ LPDWORD lpServicesReturned, +# _Inout_opt_ LPDWORD lpResumeHandle, +# _In_opt_ LPCTSTR pszGroupName +# ); +def EnumServicesStatusExA(hSCManager, InfoLevel = SC_ENUM_PROCESS_INFO, dwServiceType = SERVICE_DRIVER | SERVICE_WIN32, dwServiceState = SERVICE_STATE_ALL, pszGroupName = None): + + if InfoLevel != SC_ENUM_PROCESS_INFO: + raise NotImplementedError() + + _EnumServicesStatusExA = windll.advapi32.EnumServicesStatusExA + _EnumServicesStatusExA.argtypes = [SC_HANDLE, SC_ENUM_TYPE, DWORD, DWORD, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR] + _EnumServicesStatusExA.restype = bool + + cbBytesNeeded = DWORD(0) + ServicesReturned = DWORD(0) + ResumeHandle = DWORD(0) + + _EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, None, 0, byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle), pszGroupName) + + Services = [] + success = False + while GetLastError() == ERROR_MORE_DATA: + if cbBytesNeeded.value < sizeof(ENUM_SERVICE_STATUS_PROCESSA): + break + ServicesBuffer = ctypes.create_string_buffer("", cbBytesNeeded.value) + success = _EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, byref(ServicesBuffer), sizeof(ServicesBuffer), byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle), pszGroupName) + if sizeof(ServicesBuffer) < (sizeof(ENUM_SERVICE_STATUS_PROCESSA) * ServicesReturned.value): + raise ctypes.WinError() + lpServicesArray = ctypes.cast(ctypes.cast(ctypes.pointer(ServicesBuffer), ctypes.c_void_p), LPENUM_SERVICE_STATUS_PROCESSA) + for index in compat.xrange(0, ServicesReturned.value): + Services.append( ServiceStatusProcessEntry(lpServicesArray[index]) ) + if success: break + if not success: + raise ctypes.WinError() + + return Services + +def EnumServicesStatusExW(hSCManager, InfoLevel = SC_ENUM_PROCESS_INFO, dwServiceType = SERVICE_DRIVER | SERVICE_WIN32, dwServiceState = SERVICE_STATE_ALL, pszGroupName = None): + _EnumServicesStatusExW = windll.advapi32.EnumServicesStatusExW + _EnumServicesStatusExW.argtypes = [SC_HANDLE, SC_ENUM_TYPE, DWORD, DWORD, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD, LPWSTR] + _EnumServicesStatusExW.restype = bool + + if InfoLevel != SC_ENUM_PROCESS_INFO: + raise NotImplementedError() + + cbBytesNeeded = DWORD(0) + ServicesReturned = DWORD(0) + ResumeHandle = DWORD(0) + + _EnumServicesStatusExW(hSCManager, InfoLevel, dwServiceType, dwServiceState, None, 0, byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle), pszGroupName) + + Services = [] + success = False + while GetLastError() == ERROR_MORE_DATA: + if cbBytesNeeded.value < sizeof(ENUM_SERVICE_STATUS_PROCESSW): + break + ServicesBuffer = ctypes.create_string_buffer("", cbBytesNeeded.value) + success = _EnumServicesStatusExW(hSCManager, InfoLevel, dwServiceType, dwServiceState, byref(ServicesBuffer), sizeof(ServicesBuffer), byref(cbBytesNeeded), byref(ServicesReturned), byref(ResumeHandle), pszGroupName) + if sizeof(ServicesBuffer) < (sizeof(ENUM_SERVICE_STATUS_PROCESSW) * ServicesReturned.value): + raise ctypes.WinError() + lpServicesArray = ctypes.cast(ctypes.cast(ctypes.pointer(ServicesBuffer), ctypes.c_void_p), LPENUM_SERVICE_STATUS_PROCESSW) + for index in compat.xrange(0, ServicesReturned.value): + Services.append( ServiceStatusProcessEntry(lpServicesArray[index]) ) + if success: break + if not success: + raise ctypes.WinError() + + return Services + +EnumServicesStatusEx = DefaultStringType(EnumServicesStatusExA, EnumServicesStatusExW) + +# BOOL WINAPI EnumDependentServices( +# _In_ SC_HANDLE hService, +# _In_ DWORD dwServiceState, +# _Out_opt_ LPENUM_SERVICE_STATUS lpServices, +# _In_ DWORD cbBufSize, +# _Out_ LPDWORD pcbBytesNeeded, +# _Out_ LPDWORD lpServicesReturned +# ); + +# TO DO + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_amd64.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_amd64.py new file mode 100644 index 0000000..eb786b6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_amd64.py @@ -0,0 +1,762 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +CONTEXT structure for amd64. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.version import ARCH_AMD64 +from winappdbg.win32 import context_i386 + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- CONTEXT structures and constants ----------------------------------------- + +# The following values specify the type of access in the first parameter +# of the exception record when the exception code specifies an access +# violation. +EXCEPTION_READ_FAULT = 0 # exception caused by a read +EXCEPTION_WRITE_FAULT = 1 # exception caused by a write +EXCEPTION_EXECUTE_FAULT = 8 # exception caused by an instruction fetch + +CONTEXT_AMD64 = 0x00100000 + +CONTEXT_CONTROL = (CONTEXT_AMD64 | long(0x1)) +CONTEXT_INTEGER = (CONTEXT_AMD64 | long(0x2)) +CONTEXT_SEGMENTS = (CONTEXT_AMD64 | long(0x4)) +CONTEXT_FLOATING_POINT = (CONTEXT_AMD64 | long(0x8)) +CONTEXT_DEBUG_REGISTERS = (CONTEXT_AMD64 | long(0x10)) + +CONTEXT_MMX_REGISTERS = CONTEXT_FLOATING_POINT + +CONTEXT_FULL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT) + +CONTEXT_ALL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \ + CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS) + +CONTEXT_EXCEPTION_ACTIVE = 0x8000000 +CONTEXT_SERVICE_ACTIVE = 0x10000000 +CONTEXT_EXCEPTION_REQUEST = 0x40000000 +CONTEXT_EXCEPTION_REPORTING = 0x80000000 + +INITIAL_MXCSR = 0x1f80 # initial MXCSR value +INITIAL_FPCSR = 0x027f # initial FPCSR value + +# typedef struct _XMM_SAVE_AREA32 { +# WORD ControlWord; +# WORD StatusWord; +# BYTE TagWord; +# BYTE Reserved1; +# WORD ErrorOpcode; +# DWORD ErrorOffset; +# WORD ErrorSelector; +# WORD Reserved2; +# DWORD DataOffset; +# WORD DataSelector; +# WORD Reserved3; +# DWORD MxCsr; +# DWORD MxCsr_Mask; +# M128A FloatRegisters[8]; +# M128A XmmRegisters[16]; +# BYTE Reserved4[96]; +# } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32; +class XMM_SAVE_AREA32(Structure): + _pack_ = 1 + _fields_ = [ + ('ControlWord', WORD), + ('StatusWord', WORD), + ('TagWord', BYTE), + ('Reserved1', BYTE), + ('ErrorOpcode', WORD), + ('ErrorOffset', DWORD), + ('ErrorSelector', WORD), + ('Reserved2', WORD), + ('DataOffset', DWORD), + ('DataSelector', WORD), + ('Reserved3', WORD), + ('MxCsr', DWORD), + ('MxCsr_Mask', DWORD), + ('FloatRegisters', M128A * 8), + ('XmmRegisters', M128A * 16), + ('Reserved4', BYTE * 96), + ] + + def from_dict(self): + raise NotImplementedError() + + def to_dict(self): + d = dict() + for name, type in self._fields_: + if name in ('FloatRegisters', 'XmmRegisters'): + d[name] = tuple([ (x.LowPart + (x.HighPart << 64)) for x in getattr(self, name) ]) + elif name == 'Reserved4': + d[name] = tuple([ chr(x) for x in getattr(self, name) ]) + else: + d[name] = getattr(self, name) + return d + +LEGACY_SAVE_AREA_LENGTH = sizeof(XMM_SAVE_AREA32) + +PXMM_SAVE_AREA32 = ctypes.POINTER(XMM_SAVE_AREA32) +LPXMM_SAVE_AREA32 = PXMM_SAVE_AREA32 + +# // +# // Context Frame +# // +# // This frame has a several purposes: 1) it is used as an argument to +# // NtContinue, 2) is is used to constuct a call frame for APC delivery, +# // and 3) it is used in the user level thread creation routines. +# // +# // +# // The flags field within this record controls the contents of a CONTEXT +# // record. +# // +# // If the context record is used as an input parameter, then for each +# // portion of the context record controlled by a flag whose value is +# // set, it is assumed that that portion of the context record contains +# // valid context. If the context record is being used to modify a threads +# // context, then only that portion of the threads context is modified. +# // +# // If the context record is used as an output parameter to capture the +# // context of a thread, then only those portions of the thread's context +# // corresponding to set flags will be returned. +# // +# // CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags. +# // +# // CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15. +# // +# // CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs. +# // +# // CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7. +# // +# // CONTEXT_MMX_REGISTERS specifies the floating point and extended registers +# // Mm0/St0-Mm7/St7 and Xmm0-Xmm15). +# // +# +# typedef struct DECLSPEC_ALIGN(16) _CONTEXT { +# +# // +# // Register parameter home addresses. +# // +# // N.B. These fields are for convience - they could be used to extend the +# // context record in the future. +# // +# +# DWORD64 P1Home; +# DWORD64 P2Home; +# DWORD64 P3Home; +# DWORD64 P4Home; +# DWORD64 P5Home; +# DWORD64 P6Home; +# +# // +# // Control flags. +# // +# +# DWORD ContextFlags; +# DWORD MxCsr; +# +# // +# // Segment Registers and processor flags. +# // +# +# WORD SegCs; +# WORD SegDs; +# WORD SegEs; +# WORD SegFs; +# WORD SegGs; +# WORD SegSs; +# DWORD EFlags; +# +# // +# // Debug registers +# // +# +# DWORD64 Dr0; +# DWORD64 Dr1; +# DWORD64 Dr2; +# DWORD64 Dr3; +# DWORD64 Dr6; +# DWORD64 Dr7; +# +# // +# // Integer registers. +# // +# +# DWORD64 Rax; +# DWORD64 Rcx; +# DWORD64 Rdx; +# DWORD64 Rbx; +# DWORD64 Rsp; +# DWORD64 Rbp; +# DWORD64 Rsi; +# DWORD64 Rdi; +# DWORD64 R8; +# DWORD64 R9; +# DWORD64 R10; +# DWORD64 R11; +# DWORD64 R12; +# DWORD64 R13; +# DWORD64 R14; +# DWORD64 R15; +# +# // +# // Program counter. +# // +# +# DWORD64 Rip; +# +# // +# // Floating point state. +# // +# +# union { +# XMM_SAVE_AREA32 FltSave; +# struct { +# M128A Header[2]; +# M128A Legacy[8]; +# M128A Xmm0; +# M128A Xmm1; +# M128A Xmm2; +# M128A Xmm3; +# M128A Xmm4; +# M128A Xmm5; +# M128A Xmm6; +# M128A Xmm7; +# M128A Xmm8; +# M128A Xmm9; +# M128A Xmm10; +# M128A Xmm11; +# M128A Xmm12; +# M128A Xmm13; +# M128A Xmm14; +# M128A Xmm15; +# }; +# }; +# +# // +# // Vector registers. +# // +# +# M128A VectorRegister[26]; +# DWORD64 VectorControl; +# +# // +# // Special debug control registers. +# // +# +# DWORD64 DebugControl; +# DWORD64 LastBranchToRip; +# DWORD64 LastBranchFromRip; +# DWORD64 LastExceptionToRip; +# DWORD64 LastExceptionFromRip; +# } CONTEXT, *PCONTEXT; + +class _CONTEXT_FLTSAVE_STRUCT(Structure): + _fields_ = [ + ('Header', M128A * 2), + ('Legacy', M128A * 8), + ('Xmm0', M128A), + ('Xmm1', M128A), + ('Xmm2', M128A), + ('Xmm3', M128A), + ('Xmm4', M128A), + ('Xmm5', M128A), + ('Xmm6', M128A), + ('Xmm7', M128A), + ('Xmm8', M128A), + ('Xmm9', M128A), + ('Xmm10', M128A), + ('Xmm11', M128A), + ('Xmm12', M128A), + ('Xmm13', M128A), + ('Xmm14', M128A), + ('Xmm15', M128A), + ] + + def from_dict(self): + raise NotImplementedError() + + def to_dict(self): + d = dict() + for name, type in self._fields_: + if name in ('Header', 'Legacy'): + d[name] = tuple([ (x.Low + (x.High << 64)) for x in getattr(self, name) ]) + else: + x = getattr(self, name) + d[name] = x.Low + (x.High << 64) + return d + +class _CONTEXT_FLTSAVE_UNION(Union): + _fields_ = [ + ('flt', XMM_SAVE_AREA32), + ('xmm', _CONTEXT_FLTSAVE_STRUCT), + ] + + def from_dict(self): + raise NotImplementedError() + + def to_dict(self): + d = dict() + d['flt'] = self.flt.to_dict() + d['xmm'] = self.xmm.to_dict() + return d + +class CONTEXT(Structure): + arch = ARCH_AMD64 + + _pack_ = 16 + _fields_ = [ + + # Register parameter home addresses. + ('P1Home', DWORD64), + ('P2Home', DWORD64), + ('P3Home', DWORD64), + ('P4Home', DWORD64), + ('P5Home', DWORD64), + ('P6Home', DWORD64), + + # Control flags. + ('ContextFlags', DWORD), + ('MxCsr', DWORD), + + # Segment Registers and processor flags. + ('SegCs', WORD), + ('SegDs', WORD), + ('SegEs', WORD), + ('SegFs', WORD), + ('SegGs', WORD), + ('SegSs', WORD), + ('EFlags', DWORD), + + # Debug registers. + ('Dr0', DWORD64), + ('Dr1', DWORD64), + ('Dr2', DWORD64), + ('Dr3', DWORD64), + ('Dr6', DWORD64), + ('Dr7', DWORD64), + + # Integer registers. + ('Rax', DWORD64), + ('Rcx', DWORD64), + ('Rdx', DWORD64), + ('Rbx', DWORD64), + ('Rsp', DWORD64), + ('Rbp', DWORD64), + ('Rsi', DWORD64), + ('Rdi', DWORD64), + ('R8', DWORD64), + ('R9', DWORD64), + ('R10', DWORD64), + ('R11', DWORD64), + ('R12', DWORD64), + ('R13', DWORD64), + ('R14', DWORD64), + ('R15', DWORD64), + + # Program counter. + ('Rip', DWORD64), + + # Floating point state. + ('FltSave', _CONTEXT_FLTSAVE_UNION), + + # Vector registers. + ('VectorRegister', M128A * 26), + ('VectorControl', DWORD64), + + # Special debug control registers. + ('DebugControl', DWORD64), + ('LastBranchToRip', DWORD64), + ('LastBranchFromRip', DWORD64), + ('LastExceptionToRip', DWORD64), + ('LastExceptionFromRip', DWORD64), + ] + + _others = ('P1Home', 'P2Home', 'P3Home', 'P4Home', 'P5Home', 'P6Home', \ + 'MxCsr', 'VectorRegister', 'VectorControl') + _control = ('SegSs', 'Rsp', 'SegCs', 'Rip', 'EFlags') + _integer = ('Rax', 'Rcx', 'Rdx', 'Rbx', 'Rsp', 'Rbp', 'Rsi', 'Rdi', \ + 'R8', 'R9', 'R10', 'R11', 'R12', 'R13', 'R14', 'R15') + _segments = ('SegDs', 'SegEs', 'SegFs', 'SegGs') + _debug = ('Dr0', 'Dr1', 'Dr2', 'Dr3', 'Dr6', 'Dr7', \ + 'DebugControl', 'LastBranchToRip', 'LastBranchFromRip', \ + 'LastExceptionToRip', 'LastExceptionFromRip') + _mmx = ('Xmm0', 'Xmm1', 'Xmm2', 'Xmm3', 'Xmm4', 'Xmm5', 'Xmm6', 'Xmm7', \ + 'Xmm8', 'Xmm9', 'Xmm10', 'Xmm11', 'Xmm12', 'Xmm13', 'Xmm14', 'Xmm15') + + # XXX TODO + # Convert VectorRegister and Xmm0-Xmm15 to pure Python types! + + @classmethod + def from_dict(cls, ctx): + 'Instance a new structure from a Python native type.' + ctx = Context(ctx) + s = cls() + ContextFlags = ctx['ContextFlags'] + s.ContextFlags = ContextFlags + for key in cls._others: + if key != 'VectorRegister': + setattr(s, key, ctx[key]) + else: + w = ctx[key] + v = (M128A * len(w))() + i = 0 + for x in w: + y = M128A() + y.High = x >> 64 + y.Low = x - (x >> 64) + v[i] = y + i += 1 + setattr(s, key, v) + if (ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL: + for key in cls._control: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER: + for key in cls._integer: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS: + for key in cls._segments: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_DEBUG_REGISTERS) == CONTEXT_DEBUG_REGISTERS: + for key in cls._debug: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_MMX_REGISTERS) == CONTEXT_MMX_REGISTERS: + xmm = s.FltSave.xmm + for key in cls._mmx: + y = M128A() + y.High = x >> 64 + y.Low = x - (x >> 64) + setattr(xmm, key, y) + return s + + def to_dict(self): + 'Convert a structure into a Python dictionary.' + ctx = Context() + ContextFlags = self.ContextFlags + ctx['ContextFlags'] = ContextFlags + for key in self._others: + if key != 'VectorRegister': + ctx[key] = getattr(self, key) + else: + ctx[key] = tuple([ (x.Low + (x.High << 64)) for x in getattr(self, key) ]) + if (ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL: + for key in self._control: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER: + for key in self._integer: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS: + for key in self._segments: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_DEBUG_REGISTERS) == CONTEXT_DEBUG_REGISTERS: + for key in self._debug: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_MMX_REGISTERS) == CONTEXT_MMX_REGISTERS: + xmm = self.FltSave.xmm.to_dict() + for key in self._mmx: + ctx[key] = xmm.get(key) + return ctx + +PCONTEXT = ctypes.POINTER(CONTEXT) +LPCONTEXT = PCONTEXT + +class Context(dict): + """ + Register context dictionary for the amd64 architecture. + """ + + arch = CONTEXT.arch + + def __get_pc(self): + return self['Rip'] + def __set_pc(self, value): + self['Rip'] = value + pc = property(__get_pc, __set_pc) + + def __get_sp(self): + return self['Rsp'] + def __set_sp(self, value): + self['Rsp'] = value + sp = property(__get_sp, __set_sp) + + def __get_fp(self): + return self['Rbp'] + def __set_fp(self, value): + self['Rbp'] = value + fp = property(__get_fp, __set_fp) + +#--- LDT_ENTRY structure ------------------------------------------------------ + +# typedef struct _LDT_ENTRY { +# WORD LimitLow; +# WORD BaseLow; +# union { +# struct { +# BYTE BaseMid; +# BYTE Flags1; +# BYTE Flags2; +# BYTE BaseHi; +# } Bytes; +# struct { +# DWORD BaseMid :8; +# DWORD Type :5; +# DWORD Dpl :2; +# DWORD Pres :1; +# DWORD LimitHi :4; +# DWORD Sys :1; +# DWORD Reserved_0 :1; +# DWORD Default_Big :1; +# DWORD Granularity :1; +# DWORD BaseHi :8; +# } Bits; +# } HighWord; +# } LDT_ENTRY, +# *PLDT_ENTRY; + +class _LDT_ENTRY_BYTES_(Structure): + _pack_ = 1 + _fields_ = [ + ('BaseMid', BYTE), + ('Flags1', BYTE), + ('Flags2', BYTE), + ('BaseHi', BYTE), + ] + +class _LDT_ENTRY_BITS_(Structure): + _pack_ = 1 + _fields_ = [ + ('BaseMid', DWORD, 8), + ('Type', DWORD, 5), + ('Dpl', DWORD, 2), + ('Pres', DWORD, 1), + ('LimitHi', DWORD, 4), + ('Sys', DWORD, 1), + ('Reserved_0', DWORD, 1), + ('Default_Big', DWORD, 1), + ('Granularity', DWORD, 1), + ('BaseHi', DWORD, 8), + ] + +class _LDT_ENTRY_HIGHWORD_(Union): + _pack_ = 1 + _fields_ = [ + ('Bytes', _LDT_ENTRY_BYTES_), + ('Bits', _LDT_ENTRY_BITS_), + ] + +class LDT_ENTRY(Structure): + _pack_ = 1 + _fields_ = [ + ('LimitLow', WORD), + ('BaseLow', WORD), + ('HighWord', _LDT_ENTRY_HIGHWORD_), + ] + +PLDT_ENTRY = POINTER(LDT_ENTRY) +LPLDT_ENTRY = PLDT_ENTRY + +#--- WOW64 CONTEXT structure and constants ------------------------------------ + +# Value of SegCs in a Wow64 thread when running in 32 bits mode +WOW64_CS32 = 0x23 + +WOW64_CONTEXT_i386 = long(0x00010000) +WOW64_CONTEXT_i486 = long(0x00010000) + +WOW64_CONTEXT_CONTROL = (WOW64_CONTEXT_i386 | long(0x00000001)) +WOW64_CONTEXT_INTEGER = (WOW64_CONTEXT_i386 | long(0x00000002)) +WOW64_CONTEXT_SEGMENTS = (WOW64_CONTEXT_i386 | long(0x00000004)) +WOW64_CONTEXT_FLOATING_POINT = (WOW64_CONTEXT_i386 | long(0x00000008)) +WOW64_CONTEXT_DEBUG_REGISTERS = (WOW64_CONTEXT_i386 | long(0x00000010)) +WOW64_CONTEXT_EXTENDED_REGISTERS = (WOW64_CONTEXT_i386 | long(0x00000020)) + +WOW64_CONTEXT_FULL = (WOW64_CONTEXT_CONTROL | WOW64_CONTEXT_INTEGER | WOW64_CONTEXT_SEGMENTS) +WOW64_CONTEXT_ALL = (WOW64_CONTEXT_CONTROL | WOW64_CONTEXT_INTEGER | WOW64_CONTEXT_SEGMENTS | WOW64_CONTEXT_FLOATING_POINT | WOW64_CONTEXT_DEBUG_REGISTERS | WOW64_CONTEXT_EXTENDED_REGISTERS) + +WOW64_SIZE_OF_80387_REGISTERS = 80 +WOW64_MAXIMUM_SUPPORTED_EXTENSION = 512 + +class WOW64_FLOATING_SAVE_AREA (context_i386.FLOATING_SAVE_AREA): + pass + +class WOW64_CONTEXT (context_i386.CONTEXT): + pass + +class WOW64_LDT_ENTRY (context_i386.LDT_ENTRY): + pass + +PWOW64_FLOATING_SAVE_AREA = POINTER(WOW64_FLOATING_SAVE_AREA) +PWOW64_CONTEXT = POINTER(WOW64_CONTEXT) +PWOW64_LDT_ENTRY = POINTER(WOW64_LDT_ENTRY) + +############################################################################### + +# BOOL WINAPI GetThreadSelectorEntry( +# __in HANDLE hThread, +# __in DWORD dwSelector, +# __out LPLDT_ENTRY lpSelectorEntry +# ); +def GetThreadSelectorEntry(hThread, dwSelector): + _GetThreadSelectorEntry = windll.kernel32.GetThreadSelectorEntry + _GetThreadSelectorEntry.argtypes = [HANDLE, DWORD, LPLDT_ENTRY] + _GetThreadSelectorEntry.restype = bool + _GetThreadSelectorEntry.errcheck = RaiseIfZero + + ldt = LDT_ENTRY() + _GetThreadSelectorEntry(hThread, dwSelector, byref(ldt)) + return ldt + +# BOOL WINAPI GetThreadContext( +# __in HANDLE hThread, +# __inout LPCONTEXT lpContext +# ); +def GetThreadContext(hThread, ContextFlags = None, raw = False): + _GetThreadContext = windll.kernel32.GetThreadContext + _GetThreadContext.argtypes = [HANDLE, LPCONTEXT] + _GetThreadContext.restype = bool + _GetThreadContext.errcheck = RaiseIfZero + + if ContextFlags is None: + ContextFlags = CONTEXT_ALL | CONTEXT_AMD64 + Context = CONTEXT() + Context.ContextFlags = ContextFlags + _GetThreadContext(hThread, byref(Context)) + if raw: + return Context + return Context.to_dict() + +# BOOL WINAPI SetThreadContext( +# __in HANDLE hThread, +# __in const CONTEXT* lpContext +# ); +def SetThreadContext(hThread, lpContext): + _SetThreadContext = windll.kernel32.SetThreadContext + _SetThreadContext.argtypes = [HANDLE, LPCONTEXT] + _SetThreadContext.restype = bool + _SetThreadContext.errcheck = RaiseIfZero + + if isinstance(lpContext, dict): + lpContext = CONTEXT.from_dict(lpContext) + _SetThreadContext(hThread, byref(lpContext)) + +# BOOL Wow64GetThreadSelectorEntry( +# __in HANDLE hThread, +# __in DWORD dwSelector, +# __out PWOW64_LDT_ENTRY lpSelectorEntry +# ); +def Wow64GetThreadSelectorEntry(hThread, dwSelector): + _Wow64GetThreadSelectorEntry = windll.kernel32.Wow64GetThreadSelectorEntry + _Wow64GetThreadSelectorEntry.argtypes = [HANDLE, DWORD, PWOW64_LDT_ENTRY] + _Wow64GetThreadSelectorEntry.restype = bool + _Wow64GetThreadSelectorEntry.errcheck = RaiseIfZero + + lpSelectorEntry = WOW64_LDT_ENTRY() + _Wow64GetThreadSelectorEntry(hThread, dwSelector, byref(lpSelectorEntry)) + return lpSelectorEntry + +# DWORD WINAPI Wow64ResumeThread( +# __in HANDLE hThread +# ); +def Wow64ResumeThread(hThread): + _Wow64ResumeThread = windll.kernel32.Wow64ResumeThread + _Wow64ResumeThread.argtypes = [HANDLE] + _Wow64ResumeThread.restype = DWORD + + previousCount = _Wow64ResumeThread(hThread) + if previousCount == DWORD(-1).value: + raise ctypes.WinError() + return previousCount + +# DWORD WINAPI Wow64SuspendThread( +# __in HANDLE hThread +# ); +def Wow64SuspendThread(hThread): + _Wow64SuspendThread = windll.kernel32.Wow64SuspendThread + _Wow64SuspendThread.argtypes = [HANDLE] + _Wow64SuspendThread.restype = DWORD + + previousCount = _Wow64SuspendThread(hThread) + if previousCount == DWORD(-1).value: + raise ctypes.WinError() + return previousCount + +# XXX TODO Use this http://www.nynaeve.net/Code/GetThreadWow64Context.cpp +# Also see http://www.woodmann.com/forum/archive/index.php/t-11162.html + +# BOOL WINAPI Wow64GetThreadContext( +# __in HANDLE hThread, +# __inout PWOW64_CONTEXT lpContext +# ); +def Wow64GetThreadContext(hThread, ContextFlags = None): + _Wow64GetThreadContext = windll.kernel32.Wow64GetThreadContext + _Wow64GetThreadContext.argtypes = [HANDLE, PWOW64_CONTEXT] + _Wow64GetThreadContext.restype = bool + _Wow64GetThreadContext.errcheck = RaiseIfZero + + # XXX doesn't exist in XP 64 bits + + Context = WOW64_CONTEXT() + if ContextFlags is None: + Context.ContextFlags = WOW64_CONTEXT_ALL | WOW64_CONTEXT_i386 + else: + Context.ContextFlags = ContextFlags + _Wow64GetThreadContext(hThread, byref(Context)) + return Context.to_dict() + +# BOOL WINAPI Wow64SetThreadContext( +# __in HANDLE hThread, +# __in const WOW64_CONTEXT *lpContext +# ); +def Wow64SetThreadContext(hThread, lpContext): + _Wow64SetThreadContext = windll.kernel32.Wow64SetThreadContext + _Wow64SetThreadContext.argtypes = [HANDLE, PWOW64_CONTEXT] + _Wow64SetThreadContext.restype = bool + _Wow64SetThreadContext.errcheck = RaiseIfZero + + # XXX doesn't exist in XP 64 bits + + if isinstance(lpContext, dict): + lpContext = WOW64_CONTEXT.from_dict(lpContext) + _Wow64SetThreadContext(hThread, byref(lpContext)) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_i386.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_i386.py new file mode 100644 index 0000000..91ff2d9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/context_i386.py @@ -0,0 +1,449 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +CONTEXT structure for i386. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.version import ARCH_I386 + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- CONTEXT structures and constants ----------------------------------------- + +# The following values specify the type of access in the first parameter +# of the exception record when the exception code specifies an access +# violation. +EXCEPTION_READ_FAULT = 0 # exception caused by a read +EXCEPTION_WRITE_FAULT = 1 # exception caused by a write +EXCEPTION_EXECUTE_FAULT = 8 # exception caused by an instruction fetch + +CONTEXT_i386 = 0x00010000 # this assumes that i386 and +CONTEXT_i486 = 0x00010000 # i486 have identical context records + +CONTEXT_CONTROL = (CONTEXT_i386 | long(0x00000001)) # SS:SP, CS:IP, FLAGS, BP +CONTEXT_INTEGER = (CONTEXT_i386 | long(0x00000002)) # AX, BX, CX, DX, SI, DI +CONTEXT_SEGMENTS = (CONTEXT_i386 | long(0x00000004)) # DS, ES, FS, GS +CONTEXT_FLOATING_POINT = (CONTEXT_i386 | long(0x00000008)) # 387 state +CONTEXT_DEBUG_REGISTERS = (CONTEXT_i386 | long(0x00000010)) # DB 0-3,6,7 +CONTEXT_EXTENDED_REGISTERS = (CONTEXT_i386 | long(0x00000020)) # cpu specific extensions + +CONTEXT_FULL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS) + +CONTEXT_ALL = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \ + CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | \ + CONTEXT_EXTENDED_REGISTERS) + +SIZE_OF_80387_REGISTERS = 80 +MAXIMUM_SUPPORTED_EXTENSION = 512 + +# typedef struct _FLOATING_SAVE_AREA { +# DWORD ControlWord; +# DWORD StatusWord; +# DWORD TagWord; +# DWORD ErrorOffset; +# DWORD ErrorSelector; +# DWORD DataOffset; +# DWORD DataSelector; +# BYTE RegisterArea[SIZE_OF_80387_REGISTERS]; +# DWORD Cr0NpxState; +# } FLOATING_SAVE_AREA; +class FLOATING_SAVE_AREA(Structure): + _pack_ = 1 + _fields_ = [ + ('ControlWord', DWORD), + ('StatusWord', DWORD), + ('TagWord', DWORD), + ('ErrorOffset', DWORD), + ('ErrorSelector', DWORD), + ('DataOffset', DWORD), + ('DataSelector', DWORD), + ('RegisterArea', BYTE * SIZE_OF_80387_REGISTERS), + ('Cr0NpxState', DWORD), + ] + + _integer_members = ('ControlWord', 'StatusWord', 'TagWord', 'ErrorOffset', 'ErrorSelector', 'DataOffset', 'DataSelector', 'Cr0NpxState') + + @classmethod + def from_dict(cls, fsa): + 'Instance a new structure from a Python dictionary.' + fsa = dict(fsa) + s = cls() + for key in cls._integer_members: + setattr(s, key, fsa.get(key)) + ra = fsa.get('RegisterArea', None) + if ra is not None: + for index in compat.xrange(0, SIZE_OF_80387_REGISTERS): + s.RegisterArea[index] = ra[index] + return s + + def to_dict(self): + 'Convert a structure into a Python dictionary.' + fsa = dict() + for key in self._integer_members: + fsa[key] = getattr(self, key) + ra = [ self.RegisterArea[index] for index in compat.xrange(0, SIZE_OF_80387_REGISTERS) ] + ra = tuple(ra) + fsa['RegisterArea'] = ra + return fsa + +PFLOATING_SAVE_AREA = POINTER(FLOATING_SAVE_AREA) +LPFLOATING_SAVE_AREA = PFLOATING_SAVE_AREA + +# typedef struct _CONTEXT { +# DWORD ContextFlags; +# DWORD Dr0; +# DWORD Dr1; +# DWORD Dr2; +# DWORD Dr3; +# DWORD Dr6; +# DWORD Dr7; +# FLOATING_SAVE_AREA FloatSave; +# DWORD SegGs; +# DWORD SegFs; +# DWORD SegEs; +# DWORD SegDs; +# DWORD Edi; +# DWORD Esi; +# DWORD Ebx; +# DWORD Edx; +# DWORD Ecx; +# DWORD Eax; +# DWORD Ebp; +# DWORD Eip; +# DWORD SegCs; +# DWORD EFlags; +# DWORD Esp; +# DWORD SegSs; +# BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]; +# } CONTEXT; +class CONTEXT(Structure): + arch = ARCH_I386 + + _pack_ = 1 + + # Context Frame + # + # This frame has a several purposes: 1) it is used as an argument to + # NtContinue, 2) is is used to constuct a call frame for APC delivery, + # and 3) it is used in the user level thread creation routines. + # + # The layout of the record conforms to a standard call frame. + + _fields_ = [ + + # The flags values within this flag control the contents of + # a CONTEXT record. + # + # If the context record is used as an input parameter, then + # for each portion of the context record controlled by a flag + # whose value is set, it is assumed that that portion of the + # context record contains valid context. If the context record + # is being used to modify a threads context, then only that + # portion of the threads context will be modified. + # + # If the context record is used as an IN OUT parameter to capture + # the context of a thread, then only those portions of the thread's + # context corresponding to set flags will be returned. + # + # The context record is never used as an OUT only parameter. + + ('ContextFlags', DWORD), + + # This section is specified/returned if CONTEXT_DEBUG_REGISTERS is + # set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT + # included in CONTEXT_FULL. + + ('Dr0', DWORD), + ('Dr1', DWORD), + ('Dr2', DWORD), + ('Dr3', DWORD), + ('Dr6', DWORD), + ('Dr7', DWORD), + + # This section is specified/returned if the + # ContextFlags word contains the flag CONTEXT_FLOATING_POINT. + + ('FloatSave', FLOATING_SAVE_AREA), + + # This section is specified/returned if the + # ContextFlags word contains the flag CONTEXT_SEGMENTS. + + ('SegGs', DWORD), + ('SegFs', DWORD), + ('SegEs', DWORD), + ('SegDs', DWORD), + + # This section is specified/returned if the + # ContextFlags word contains the flag CONTEXT_INTEGER. + + ('Edi', DWORD), + ('Esi', DWORD), + ('Ebx', DWORD), + ('Edx', DWORD), + ('Ecx', DWORD), + ('Eax', DWORD), + + # This section is specified/returned if the + # ContextFlags word contains the flag CONTEXT_CONTROL. + + ('Ebp', DWORD), + ('Eip', DWORD), + ('SegCs', DWORD), # MUST BE SANITIZED + ('EFlags', DWORD), # MUST BE SANITIZED + ('Esp', DWORD), + ('SegSs', DWORD), + + # This section is specified/returned if the ContextFlags word + # contains the flag CONTEXT_EXTENDED_REGISTERS. + # The format and contexts are processor specific. + + ('ExtendedRegisters', BYTE * MAXIMUM_SUPPORTED_EXTENSION), + ] + + _ctx_debug = ('Dr0', 'Dr1', 'Dr2', 'Dr3', 'Dr6', 'Dr7') + _ctx_segs = ('SegGs', 'SegFs', 'SegEs', 'SegDs', ) + _ctx_int = ('Edi', 'Esi', 'Ebx', 'Edx', 'Ecx', 'Eax') + _ctx_ctrl = ('Ebp', 'Eip', 'SegCs', 'EFlags', 'Esp', 'SegSs') + + @classmethod + def from_dict(cls, ctx): + 'Instance a new structure from a Python dictionary.' + ctx = Context(ctx) + s = cls() + ContextFlags = ctx['ContextFlags'] + setattr(s, 'ContextFlags', ContextFlags) + if (ContextFlags & CONTEXT_DEBUG_REGISTERS) == CONTEXT_DEBUG_REGISTERS: + for key in s._ctx_debug: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT: + fsa = ctx['FloatSave'] + s.FloatSave = FLOATING_SAVE_AREA.from_dict(fsa) + if (ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS: + for key in s._ctx_segs: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER: + for key in s._ctx_int: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL: + for key in s._ctx_ctrl: + setattr(s, key, ctx[key]) + if (ContextFlags & CONTEXT_EXTENDED_REGISTERS) == CONTEXT_EXTENDED_REGISTERS: + er = ctx['ExtendedRegisters'] + for index in compat.xrange(0, MAXIMUM_SUPPORTED_EXTENSION): + s.ExtendedRegisters[index] = er[index] + return s + + def to_dict(self): + 'Convert a structure into a Python native type.' + ctx = Context() + ContextFlags = self.ContextFlags + ctx['ContextFlags'] = ContextFlags + if (ContextFlags & CONTEXT_DEBUG_REGISTERS) == CONTEXT_DEBUG_REGISTERS: + for key in self._ctx_debug: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT: + ctx['FloatSave'] = self.FloatSave.to_dict() + if (ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS: + for key in self._ctx_segs: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER: + for key in self._ctx_int: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL: + for key in self._ctx_ctrl: + ctx[key] = getattr(self, key) + if (ContextFlags & CONTEXT_EXTENDED_REGISTERS) == CONTEXT_EXTENDED_REGISTERS: + er = [ self.ExtendedRegisters[index] for index in compat.xrange(0, MAXIMUM_SUPPORTED_EXTENSION) ] + er = tuple(er) + ctx['ExtendedRegisters'] = er + return ctx + +PCONTEXT = POINTER(CONTEXT) +LPCONTEXT = PCONTEXT + +class Context(dict): + """ + Register context dictionary for the i386 architecture. + """ + + arch = CONTEXT.arch + + def __get_pc(self): + return self['Eip'] + def __set_pc(self, value): + self['Eip'] = value + pc = property(__get_pc, __set_pc) + + def __get_sp(self): + return self['Esp'] + def __set_sp(self, value): + self['Esp'] = value + sp = property(__get_sp, __set_sp) + + def __get_fp(self): + return self['Ebp'] + def __set_fp(self, value): + self['Ebp'] = value + fp = property(__get_fp, __set_fp) + +#--- LDT_ENTRY structure ------------------------------------------------------ + +# typedef struct _LDT_ENTRY { +# WORD LimitLow; +# WORD BaseLow; +# union { +# struct { +# BYTE BaseMid; +# BYTE Flags1; +# BYTE Flags2; +# BYTE BaseHi; +# } Bytes; +# struct { +# DWORD BaseMid :8; +# DWORD Type :5; +# DWORD Dpl :2; +# DWORD Pres :1; +# DWORD LimitHi :4; +# DWORD Sys :1; +# DWORD Reserved_0 :1; +# DWORD Default_Big :1; +# DWORD Granularity :1; +# DWORD BaseHi :8; +# } Bits; +# } HighWord; +# } LDT_ENTRY, +# *PLDT_ENTRY; + +class _LDT_ENTRY_BYTES_(Structure): + _pack_ = 1 + _fields_ = [ + ('BaseMid', BYTE), + ('Flags1', BYTE), + ('Flags2', BYTE), + ('BaseHi', BYTE), + ] + +class _LDT_ENTRY_BITS_(Structure): + _pack_ = 1 + _fields_ = [ + ('BaseMid', DWORD, 8), + ('Type', DWORD, 5), + ('Dpl', DWORD, 2), + ('Pres', DWORD, 1), + ('LimitHi', DWORD, 4), + ('Sys', DWORD, 1), + ('Reserved_0', DWORD, 1), + ('Default_Big', DWORD, 1), + ('Granularity', DWORD, 1), + ('BaseHi', DWORD, 8), + ] + +class _LDT_ENTRY_HIGHWORD_(Union): + _pack_ = 1 + _fields_ = [ + ('Bytes', _LDT_ENTRY_BYTES_), + ('Bits', _LDT_ENTRY_BITS_), + ] + +class LDT_ENTRY(Structure): + _pack_ = 1 + _fields_ = [ + ('LimitLow', WORD), + ('BaseLow', WORD), + ('HighWord', _LDT_ENTRY_HIGHWORD_), + ] + +PLDT_ENTRY = POINTER(LDT_ENTRY) +LPLDT_ENTRY = PLDT_ENTRY + +############################################################################### + +# BOOL WINAPI GetThreadSelectorEntry( +# __in HANDLE hThread, +# __in DWORD dwSelector, +# __out LPLDT_ENTRY lpSelectorEntry +# ); +def GetThreadSelectorEntry(hThread, dwSelector): + _GetThreadSelectorEntry = windll.kernel32.GetThreadSelectorEntry + _GetThreadSelectorEntry.argtypes = [HANDLE, DWORD, LPLDT_ENTRY] + _GetThreadSelectorEntry.restype = bool + _GetThreadSelectorEntry.errcheck = RaiseIfZero + + ldt = LDT_ENTRY() + _GetThreadSelectorEntry(hThread, dwSelector, byref(ldt)) + return ldt + +# BOOL WINAPI GetThreadContext( +# __in HANDLE hThread, +# __inout LPCONTEXT lpContext +# ); +def GetThreadContext(hThread, ContextFlags = None, raw = False): + _GetThreadContext = windll.kernel32.GetThreadContext + _GetThreadContext.argtypes = [HANDLE, LPCONTEXT] + _GetThreadContext.restype = bool + _GetThreadContext.errcheck = RaiseIfZero + + if ContextFlags is None: + ContextFlags = CONTEXT_ALL | CONTEXT_i386 + Context = CONTEXT() + Context.ContextFlags = ContextFlags + _GetThreadContext(hThread, byref(Context)) + if raw: + return Context + return Context.to_dict() + +# BOOL WINAPI SetThreadContext( +# __in HANDLE hThread, +# __in const CONTEXT* lpContext +# ); +def SetThreadContext(hThread, lpContext): + _SetThreadContext = windll.kernel32.SetThreadContext + _SetThreadContext.argtypes = [HANDLE, LPCONTEXT] + _SetThreadContext.restype = bool + _SetThreadContext.errcheck = RaiseIfZero + + if isinstance(lpContext, dict): + lpContext = CONTEXT.from_dict(lpContext) + _SetThreadContext(hThread, byref(lpContext)) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py new file mode 100644 index 0000000..ce14ff9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py @@ -0,0 +1,1277 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for dbghelp.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.version import * +from winappdbg.win32.kernel32 import * + +# DbgHelp versions and features list: +# http://msdn.microsoft.com/en-us/library/windows/desktop/ms679294(v=vs.85).aspx + +#------------------------------------------------------------------------------ +# Tries to load the newest version of dbghelp.dll if available. + +def _load_latest_dbghelp_dll(): + + from os import getenv + from os.path import join, exists + + program_files_location = getenv("ProgramFiles") + if not program_files_location: + program_files_location = "C:\Program Files" + + program_files_x86_location = getenv("ProgramFiles(x86)") + + if arch == ARCH_AMD64: + if wow64: + pathname = join( + program_files_x86_location or program_files_location, + "Debugging Tools for Windows (x86)", + "dbghelp.dll") + else: + pathname = join( + program_files_location, + "Debugging Tools for Windows (x64)", + "dbghelp.dll") + elif arch == ARCH_I386: + pathname = join( + program_files_location, + "Debugging Tools for Windows (x86)", + "dbghelp.dll") + else: + pathname = None + + if pathname and exists(pathname): + try: + _dbghelp = ctypes.windll.LoadLibrary(pathname) + ctypes.windll.dbghelp = _dbghelp + except Exception: + pass + +_load_latest_dbghelp_dll() + +# Recover the old binding of the "os" symbol. +# XXX FIXME not sure if I really need to do this! +##from version import os + +#------------------------------------------------------------------------------ + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +# SymGetHomeDirectory "type" values +hdBase = 0 +hdSym = 1 +hdSrc = 2 + +UNDNAME_32_BIT_DECODE = 0x0800 +UNDNAME_COMPLETE = 0x0000 +UNDNAME_NAME_ONLY = 0x1000 +UNDNAME_NO_ACCESS_SPECIFIERS = 0x0080 +UNDNAME_NO_ALLOCATION_LANGUAGE = 0x0010 +UNDNAME_NO_ALLOCATION_MODEL = 0x0008 +UNDNAME_NO_ARGUMENTS = 0x2000 +UNDNAME_NO_CV_THISTYPE = 0x0040 +UNDNAME_NO_FUNCTION_RETURNS = 0x0004 +UNDNAME_NO_LEADING_UNDERSCORES = 0x0001 +UNDNAME_NO_MEMBER_TYPE = 0x0200 +UNDNAME_NO_MS_KEYWORDS = 0x0002 +UNDNAME_NO_MS_THISTYPE = 0x0020 +UNDNAME_NO_RETURN_UDT_MODEL = 0x0400 +UNDNAME_NO_SPECIAL_SYMS = 0x4000 +UNDNAME_NO_THISTYPE = 0x0060 +UNDNAME_NO_THROW_SIGNATURES = 0x0100 + +#--- IMAGEHLP_MODULE structure and related ------------------------------------ + +SYMOPT_ALLOW_ABSOLUTE_SYMBOLS = 0x00000800 +SYMOPT_ALLOW_ZERO_ADDRESS = 0x01000000 +SYMOPT_AUTO_PUBLICS = 0x00010000 +SYMOPT_CASE_INSENSITIVE = 0x00000001 +SYMOPT_DEBUG = 0x80000000 +SYMOPT_DEFERRED_LOADS = 0x00000004 +SYMOPT_DISABLE_SYMSRV_AUTODETECT = 0x02000000 +SYMOPT_EXACT_SYMBOLS = 0x00000400 +SYMOPT_FAIL_CRITICAL_ERRORS = 0x00000200 +SYMOPT_FAVOR_COMPRESSED = 0x00800000 +SYMOPT_FLAT_DIRECTORY = 0x00400000 +SYMOPT_IGNORE_CVREC = 0x00000080 +SYMOPT_IGNORE_IMAGEDIR = 0x00200000 +SYMOPT_IGNORE_NT_SYMPATH = 0x00001000 +SYMOPT_INCLUDE_32BIT_MODULES = 0x00002000 +SYMOPT_LOAD_ANYTHING = 0x00000040 +SYMOPT_LOAD_LINES = 0x00000010 +SYMOPT_NO_CPP = 0x00000008 +SYMOPT_NO_IMAGE_SEARCH = 0x00020000 +SYMOPT_NO_PROMPTS = 0x00080000 +SYMOPT_NO_PUBLICS = 0x00008000 +SYMOPT_NO_UNQUALIFIED_LOADS = 0x00000100 +SYMOPT_OVERWRITE = 0x00100000 +SYMOPT_PUBLICS_ONLY = 0x00004000 +SYMOPT_SECURE = 0x00040000 +SYMOPT_UNDNAME = 0x00000002 + +##SSRVOPT_DWORD +##SSRVOPT_DWORDPTR +##SSRVOPT_GUIDPTR +## +##SSRVOPT_CALLBACK +##SSRVOPT_DOWNSTREAM_STORE +##SSRVOPT_FLAT_DEFAULT_STORE +##SSRVOPT_FAVOR_COMPRESSED +##SSRVOPT_NOCOPY +##SSRVOPT_OVERWRITE +##SSRVOPT_PARAMTYPE +##SSRVOPT_PARENTWIN +##SSRVOPT_PROXY +##SSRVOPT_RESET +##SSRVOPT_SECURE +##SSRVOPT_SETCONTEXT +##SSRVOPT_TRACE +##SSRVOPT_UNATTENDED + +# typedef enum +# { +# SymNone = 0, +# SymCoff, +# SymCv, +# SymPdb, +# SymExport, +# SymDeferred, +# SymSym, +# SymDia, +# SymVirtual, +# NumSymTypes +# } SYM_TYPE; +SymNone = 0 +SymCoff = 1 +SymCv = 2 +SymPdb = 3 +SymExport = 4 +SymDeferred = 5 +SymSym = 6 +SymDia = 7 +SymVirtual = 8 +NumSymTypes = 9 + +# typedef struct _IMAGEHLP_MODULE64 { +# DWORD SizeOfStruct; +# DWORD64 BaseOfImage; +# DWORD ImageSize; +# DWORD TimeDateStamp; +# DWORD CheckSum; +# DWORD NumSyms; +# SYM_TYPE SymType; +# TCHAR ModuleName[32]; +# TCHAR ImageName[256]; +# TCHAR LoadedImageName[256]; +# TCHAR LoadedPdbName[256]; +# DWORD CVSig; +# TCHAR CVData[MAX_PATH*3]; +# DWORD PdbSig; +# GUID PdbSig70; +# DWORD PdbAge; +# BOOL PdbUnmatched; +# BOOL DbgUnmatched; +# BOOL LineNumbers; +# BOOL GlobalSymbols; +# BOOL TypeInfo; +# BOOL SourceIndexed; +# BOOL Publics; +# } IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64; + +class IMAGEHLP_MODULE (Structure): + _fields_ = [ + ("SizeOfStruct", DWORD), + ("BaseOfImage", DWORD), + ("ImageSize", DWORD), + ("TimeDateStamp", DWORD), + ("CheckSum", DWORD), + ("NumSyms", DWORD), + ("SymType", DWORD), # SYM_TYPE + ("ModuleName", CHAR * 32), + ("ImageName", CHAR * 256), + ("LoadedImageName", CHAR * 256), + ] +PIMAGEHLP_MODULE = POINTER(IMAGEHLP_MODULE) + +class IMAGEHLP_MODULE64 (Structure): + _fields_ = [ + ("SizeOfStruct", DWORD), + ("BaseOfImage", DWORD64), + ("ImageSize", DWORD), + ("TimeDateStamp", DWORD), + ("CheckSum", DWORD), + ("NumSyms", DWORD), + ("SymType", DWORD), # SYM_TYPE + ("ModuleName", CHAR * 32), + ("ImageName", CHAR * 256), + ("LoadedImageName", CHAR * 256), + ("LoadedPdbName", CHAR * 256), + ("CVSig", DWORD), + ("CVData", CHAR * (MAX_PATH * 3)), + ("PdbSig", DWORD), + ("PdbSig70", GUID), + ("PdbAge", DWORD), + ("PdbUnmatched", BOOL), + ("DbgUnmatched", BOOL), + ("LineNumbers", BOOL), + ("GlobalSymbols", BOOL), + ("TypeInfo", BOOL), + ("SourceIndexed", BOOL), + ("Publics", BOOL), + ] +PIMAGEHLP_MODULE64 = POINTER(IMAGEHLP_MODULE64) + +class IMAGEHLP_MODULEW (Structure): + _fields_ = [ + ("SizeOfStruct", DWORD), + ("BaseOfImage", DWORD), + ("ImageSize", DWORD), + ("TimeDateStamp", DWORD), + ("CheckSum", DWORD), + ("NumSyms", DWORD), + ("SymType", DWORD), # SYM_TYPE + ("ModuleName", WCHAR * 32), + ("ImageName", WCHAR * 256), + ("LoadedImageName", WCHAR * 256), + ] +PIMAGEHLP_MODULEW = POINTER(IMAGEHLP_MODULEW) + +class IMAGEHLP_MODULEW64 (Structure): + _fields_ = [ + ("SizeOfStruct", DWORD), + ("BaseOfImage", DWORD64), + ("ImageSize", DWORD), + ("TimeDateStamp", DWORD), + ("CheckSum", DWORD), + ("NumSyms", DWORD), + ("SymType", DWORD), # SYM_TYPE + ("ModuleName", WCHAR * 32), + ("ImageName", WCHAR * 256), + ("LoadedImageName", WCHAR * 256), + ("LoadedPdbName", WCHAR * 256), + ("CVSig", DWORD), + ("CVData", WCHAR * (MAX_PATH * 3)), + ("PdbSig", DWORD), + ("PdbSig70", GUID), + ("PdbAge", DWORD), + ("PdbUnmatched", BOOL), + ("DbgUnmatched", BOOL), + ("LineNumbers", BOOL), + ("GlobalSymbols", BOOL), + ("TypeInfo", BOOL), + ("SourceIndexed", BOOL), + ("Publics", BOOL), + ] +PIMAGEHLP_MODULEW64 = POINTER(IMAGEHLP_MODULEW64) + +#--- dbghelp.dll -------------------------------------------------------------- + +# XXX the ANSI versions of these functions don't end in "A" as expected! + +# BOOL WINAPI MakeSureDirectoryPathExists( +# _In_ PCSTR DirPath +# ); +def MakeSureDirectoryPathExistsA(DirPath): + _MakeSureDirectoryPathExists = windll.dbghelp.MakeSureDirectoryPathExists + _MakeSureDirectoryPathExists.argtypes = [LPSTR] + _MakeSureDirectoryPathExists.restype = bool + _MakeSureDirectoryPathExists.errcheck = RaiseIfZero + return _MakeSureDirectoryPathExists(DirPath) + +MakeSureDirectoryPathExistsW = MakeWideVersion(MakeSureDirectoryPathExistsA) +MakeSureDirectoryPathExists = GuessStringType(MakeSureDirectoryPathExistsA, MakeSureDirectoryPathExistsW) + +# BOOL WINAPI SymInitialize( +# __in HANDLE hProcess, +# __in_opt PCTSTR UserSearchPath, +# __in BOOL fInvadeProcess +# ); +def SymInitializeA(hProcess, UserSearchPath = None, fInvadeProcess = False): + _SymInitialize = windll.dbghelp.SymInitialize + _SymInitialize.argtypes = [HANDLE, LPSTR, BOOL] + _SymInitialize.restype = bool + _SymInitialize.errcheck = RaiseIfZero + if not UserSearchPath: + UserSearchPath = None + _SymInitialize(hProcess, UserSearchPath, fInvadeProcess) + +SymInitializeW = MakeWideVersion(SymInitializeA) +SymInitialize = GuessStringType(SymInitializeA, SymInitializeW) + +# BOOL WINAPI SymCleanup( +# __in HANDLE hProcess +# ); +def SymCleanup(hProcess): + _SymCleanup = windll.dbghelp.SymCleanup + _SymCleanup.argtypes = [HANDLE] + _SymCleanup.restype = bool + _SymCleanup.errcheck = RaiseIfZero + _SymCleanup(hProcess) + +# BOOL WINAPI SymRefreshModuleList( +# __in HANDLE hProcess +# ); +def SymRefreshModuleList(hProcess): + _SymRefreshModuleList = windll.dbghelp.SymRefreshModuleList + _SymRefreshModuleList.argtypes = [HANDLE] + _SymRefreshModuleList.restype = bool + _SymRefreshModuleList.errcheck = RaiseIfZero + _SymRefreshModuleList(hProcess) + +# BOOL WINAPI SymSetParentWindow( +# __in HWND hwnd +# ); +def SymSetParentWindow(hwnd): + _SymSetParentWindow = windll.dbghelp.SymSetParentWindow + _SymSetParentWindow.argtypes = [HWND] + _SymSetParentWindow.restype = bool + _SymSetParentWindow.errcheck = RaiseIfZero + _SymSetParentWindow(hwnd) + +# DWORD WINAPI SymSetOptions( +# __in DWORD SymOptions +# ); +def SymSetOptions(SymOptions): + _SymSetOptions = windll.dbghelp.SymSetOptions + _SymSetOptions.argtypes = [DWORD] + _SymSetOptions.restype = DWORD + _SymSetOptions.errcheck = RaiseIfZero + _SymSetOptions(SymOptions) + +# DWORD WINAPI SymGetOptions(void); +def SymGetOptions(): + _SymGetOptions = windll.dbghelp.SymGetOptions + _SymGetOptions.argtypes = [] + _SymGetOptions.restype = DWORD + return _SymGetOptions() + +# DWORD WINAPI SymLoadModule( +# __in HANDLE hProcess, +# __in_opt HANDLE hFile, +# __in_opt PCSTR ImageName, +# __in_opt PCSTR ModuleName, +# __in DWORD BaseOfDll, +# __in DWORD SizeOfDll +# ); +def SymLoadModuleA(hProcess, hFile = None, ImageName = None, ModuleName = None, BaseOfDll = None, SizeOfDll = None): + _SymLoadModule = windll.dbghelp.SymLoadModule + _SymLoadModule.argtypes = [HANDLE, HANDLE, LPSTR, LPSTR, DWORD, DWORD] + _SymLoadModule.restype = DWORD + + if not ImageName: + ImageName = None + if not ModuleName: + ModuleName = None + if not BaseOfDll: + BaseOfDll = 0 + if not SizeOfDll: + SizeOfDll = 0 + SetLastError(ERROR_SUCCESS) + lpBaseAddress = _SymLoadModule(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll) + if lpBaseAddress == NULL: + dwErrorCode = GetLastError() + if dwErrorCode != ERROR_SUCCESS: + raise ctypes.WinError(dwErrorCode) + return lpBaseAddress + +SymLoadModuleW = MakeWideVersion(SymLoadModuleA) +SymLoadModule = GuessStringType(SymLoadModuleA, SymLoadModuleW) + +# DWORD64 WINAPI SymLoadModule64( +# __in HANDLE hProcess, +# __in_opt HANDLE hFile, +# __in_opt PCSTR ImageName, +# __in_opt PCSTR ModuleName, +# __in DWORD64 BaseOfDll, +# __in DWORD SizeOfDll +# ); +def SymLoadModule64A(hProcess, hFile = None, ImageName = None, ModuleName = None, BaseOfDll = None, SizeOfDll = None): + _SymLoadModule64 = windll.dbghelp.SymLoadModule64 + _SymLoadModule64.argtypes = [HANDLE, HANDLE, LPSTR, LPSTR, DWORD64, DWORD] + _SymLoadModule64.restype = DWORD64 + + if not ImageName: + ImageName = None + if not ModuleName: + ModuleName = None + if not BaseOfDll: + BaseOfDll = 0 + if not SizeOfDll: + SizeOfDll = 0 + SetLastError(ERROR_SUCCESS) + lpBaseAddress = _SymLoadModule64(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll) + if lpBaseAddress == NULL: + dwErrorCode = GetLastError() + if dwErrorCode != ERROR_SUCCESS: + raise ctypes.WinError(dwErrorCode) + return lpBaseAddress + +SymLoadModule64W = MakeWideVersion(SymLoadModule64A) +SymLoadModule64 = GuessStringType(SymLoadModule64A, SymLoadModule64W) + +# BOOL WINAPI SymUnloadModule( +# __in HANDLE hProcess, +# __in DWORD BaseOfDll +# ); +def SymUnloadModule(hProcess, BaseOfDll): + _SymUnloadModule = windll.dbghelp.SymUnloadModule + _SymUnloadModule.argtypes = [HANDLE, DWORD] + _SymUnloadModule.restype = bool + _SymUnloadModule.errcheck = RaiseIfZero + _SymUnloadModule(hProcess, BaseOfDll) + +# BOOL WINAPI SymUnloadModule64( +# __in HANDLE hProcess, +# __in DWORD64 BaseOfDll +# ); +def SymUnloadModule64(hProcess, BaseOfDll): + _SymUnloadModule64 = windll.dbghelp.SymUnloadModule64 + _SymUnloadModule64.argtypes = [HANDLE, DWORD64] + _SymUnloadModule64.restype = bool + _SymUnloadModule64.errcheck = RaiseIfZero + _SymUnloadModule64(hProcess, BaseOfDll) + +# BOOL WINAPI SymGetModuleInfo( +# __in HANDLE hProcess, +# __in DWORD dwAddr, +# __out PIMAGEHLP_MODULE ModuleInfo +# ); +def SymGetModuleInfoA(hProcess, dwAddr): + _SymGetModuleInfo = windll.dbghelp.SymGetModuleInfo + _SymGetModuleInfo.argtypes = [HANDLE, DWORD, PIMAGEHLP_MODULE] + _SymGetModuleInfo.restype = bool + _SymGetModuleInfo.errcheck = RaiseIfZero + + ModuleInfo = IMAGEHLP_MODULE() + ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) + _SymGetModuleInfo(hProcess, dwAddr, byref(ModuleInfo)) + return ModuleInfo + +def SymGetModuleInfoW(hProcess, dwAddr): + _SymGetModuleInfoW = windll.dbghelp.SymGetModuleInfoW + _SymGetModuleInfoW.argtypes = [HANDLE, DWORD, PIMAGEHLP_MODULEW] + _SymGetModuleInfoW.restype = bool + _SymGetModuleInfoW.errcheck = RaiseIfZero + + ModuleInfo = IMAGEHLP_MODULEW() + ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) + _SymGetModuleInfoW(hProcess, dwAddr, byref(ModuleInfo)) + return ModuleInfo + +SymGetModuleInfo = GuessStringType(SymGetModuleInfoA, SymGetModuleInfoW) + +# BOOL WINAPI SymGetModuleInfo64( +# __in HANDLE hProcess, +# __in DWORD64 dwAddr, +# __out PIMAGEHLP_MODULE64 ModuleInfo +# ); +def SymGetModuleInfo64A(hProcess, dwAddr): + _SymGetModuleInfo64 = windll.dbghelp.SymGetModuleInfo64 + _SymGetModuleInfo64.argtypes = [HANDLE, DWORD64, PIMAGEHLP_MODULE64] + _SymGetModuleInfo64.restype = bool + _SymGetModuleInfo64.errcheck = RaiseIfZero + + ModuleInfo = IMAGEHLP_MODULE64() + ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) + _SymGetModuleInfo64(hProcess, dwAddr, byref(ModuleInfo)) + return ModuleInfo + +def SymGetModuleInfo64W(hProcess, dwAddr): + _SymGetModuleInfo64W = windll.dbghelp.SymGetModuleInfo64W + _SymGetModuleInfo64W.argtypes = [HANDLE, DWORD64, PIMAGEHLP_MODULE64W] + _SymGetModuleInfo64W.restype = bool + _SymGetModuleInfo64W.errcheck = RaiseIfZero + + ModuleInfo = IMAGEHLP_MODULE64W() + ModuleInfo.SizeOfStruct = sizeof(ModuleInfo) + _SymGetModuleInfo64W(hProcess, dwAddr, byref(ModuleInfo)) + return ModuleInfo + +SymGetModuleInfo64 = GuessStringType(SymGetModuleInfo64A, SymGetModuleInfo64W) + +# BOOL CALLBACK SymEnumerateModulesProc( +# __in PCTSTR ModuleName, +# __in DWORD BaseOfDll, +# __in_opt PVOID UserContext +# ); +PSYM_ENUMMODULES_CALLBACK = WINFUNCTYPE(BOOL, LPSTR, DWORD, PVOID) +PSYM_ENUMMODULES_CALLBACKW = WINFUNCTYPE(BOOL, LPWSTR, DWORD, PVOID) + +# BOOL CALLBACK SymEnumerateModulesProc64( +# __in PCTSTR ModuleName, +# __in DWORD64 BaseOfDll, +# __in_opt PVOID UserContext +# ); +PSYM_ENUMMODULES_CALLBACK64 = WINFUNCTYPE(BOOL, LPSTR, DWORD64, PVOID) +PSYM_ENUMMODULES_CALLBACKW64 = WINFUNCTYPE(BOOL, LPWSTR, DWORD64, PVOID) + +# BOOL WINAPI SymEnumerateModules( +# __in HANDLE hProcess, +# __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, +# __in_opt PVOID UserContext +# ); +def SymEnumerateModulesA(hProcess, EnumModulesCallback, UserContext = None): + _SymEnumerateModules = windll.dbghelp.SymEnumerateModules + _SymEnumerateModules.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACK, PVOID] + _SymEnumerateModules.restype = bool + _SymEnumerateModules.errcheck = RaiseIfZero + + EnumModulesCallback = PSYM_ENUMMODULES_CALLBACK(EnumModulesCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateModules(hProcess, EnumModulesCallback, UserContext) + +def SymEnumerateModulesW(hProcess, EnumModulesCallback, UserContext = None): + _SymEnumerateModulesW = windll.dbghelp.SymEnumerateModulesW + _SymEnumerateModulesW.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACKW, PVOID] + _SymEnumerateModulesW.restype = bool + _SymEnumerateModulesW.errcheck = RaiseIfZero + + EnumModulesCallback = PSYM_ENUMMODULES_CALLBACKW(EnumModulesCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateModulesW(hProcess, EnumModulesCallback, UserContext) + +SymEnumerateModules = GuessStringType(SymEnumerateModulesA, SymEnumerateModulesW) + +# BOOL WINAPI SymEnumerateModules64( +# __in HANDLE hProcess, +# __in PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, +# __in_opt PVOID UserContext +# ); +def SymEnumerateModules64A(hProcess, EnumModulesCallback, UserContext = None): + _SymEnumerateModules64 = windll.dbghelp.SymEnumerateModules64 + _SymEnumerateModules64.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACK64, PVOID] + _SymEnumerateModules64.restype = bool + _SymEnumerateModules64.errcheck = RaiseIfZero + + EnumModulesCallback = PSYM_ENUMMODULES_CALLBACK64(EnumModulesCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateModules64(hProcess, EnumModulesCallback, UserContext) + +def SymEnumerateModules64W(hProcess, EnumModulesCallback, UserContext = None): + _SymEnumerateModules64W = windll.dbghelp.SymEnumerateModules64W + _SymEnumerateModules64W.argtypes = [HANDLE, PSYM_ENUMMODULES_CALLBACK64W, PVOID] + _SymEnumerateModules64W.restype = bool + _SymEnumerateModules64W.errcheck = RaiseIfZero + + EnumModulesCallback = PSYM_ENUMMODULES_CALLBACK64W(EnumModulesCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateModules64W(hProcess, EnumModulesCallback, UserContext) + +SymEnumerateModules64 = GuessStringType(SymEnumerateModules64A, SymEnumerateModules64W) + +# BOOL CALLBACK SymEnumerateSymbolsProc( +# __in PCTSTR SymbolName, +# __in DWORD SymbolAddress, +# __in ULONG SymbolSize, +# __in_opt PVOID UserContext +# ); +PSYM_ENUMSYMBOLS_CALLBACK = WINFUNCTYPE(BOOL, LPSTR, DWORD, ULONG, PVOID) +PSYM_ENUMSYMBOLS_CALLBACKW = WINFUNCTYPE(BOOL, LPWSTR, DWORD, ULONG, PVOID) + +# BOOL CALLBACK SymEnumerateSymbolsProc64( +# __in PCTSTR SymbolName, +# __in DWORD64 SymbolAddress, +# __in ULONG SymbolSize, +# __in_opt PVOID UserContext +# ); +PSYM_ENUMSYMBOLS_CALLBACK64 = WINFUNCTYPE(BOOL, LPSTR, DWORD64, ULONG, PVOID) +PSYM_ENUMSYMBOLS_CALLBACKW64 = WINFUNCTYPE(BOOL, LPWSTR, DWORD64, ULONG, PVOID) + +# BOOL WINAPI SymEnumerateSymbols( +# __in HANDLE hProcess, +# __in ULONG BaseOfDll, +# __in PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback, +# __in_opt PVOID UserContext +# ); +def SymEnumerateSymbolsA(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None): + _SymEnumerateSymbols = windll.dbghelp.SymEnumerateSymbols + _SymEnumerateSymbols.argtypes = [HANDLE, ULONG, PSYM_ENUMSYMBOLS_CALLBACK, PVOID] + _SymEnumerateSymbols.restype = bool + _SymEnumerateSymbols.errcheck = RaiseIfZero + + EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK(EnumSymbolsCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateSymbols(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext) + +def SymEnumerateSymbolsW(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None): + _SymEnumerateSymbolsW = windll.dbghelp.SymEnumerateSymbolsW + _SymEnumerateSymbolsW.argtypes = [HANDLE, ULONG, PSYM_ENUMSYMBOLS_CALLBACKW, PVOID] + _SymEnumerateSymbolsW.restype = bool + _SymEnumerateSymbolsW.errcheck = RaiseIfZero + + EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACKW(EnumSymbolsCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateSymbolsW(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext) + +SymEnumerateSymbols = GuessStringType(SymEnumerateSymbolsA, SymEnumerateSymbolsW) + +# BOOL WINAPI SymEnumerateSymbols64( +# __in HANDLE hProcess, +# __in ULONG64 BaseOfDll, +# __in PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback, +# __in_opt PVOID UserContext +# ); +def SymEnumerateSymbols64A(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None): + _SymEnumerateSymbols64 = windll.dbghelp.SymEnumerateSymbols64 + _SymEnumerateSymbols64.argtypes = [HANDLE, ULONG64, PSYM_ENUMSYMBOLS_CALLBACK64, PVOID] + _SymEnumerateSymbols64.restype = bool + _SymEnumerateSymbols64.errcheck = RaiseIfZero + + EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK64(EnumSymbolsCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateSymbols64(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext) + +def SymEnumerateSymbols64W(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext = None): + _SymEnumerateSymbols64W = windll.dbghelp.SymEnumerateSymbols64W + _SymEnumerateSymbols64W.argtypes = [HANDLE, ULONG64, PSYM_ENUMSYMBOLS_CALLBACK64W, PVOID] + _SymEnumerateSymbols64W.restype = bool + _SymEnumerateSymbols64W.errcheck = RaiseIfZero + + EnumSymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK64W(EnumSymbolsCallback) + if UserContext: + UserContext = ctypes.pointer(UserContext) + else: + UserContext = LPVOID(NULL) + _SymEnumerateSymbols64W(hProcess, BaseOfDll, EnumSymbolsCallback, UserContext) + +SymEnumerateSymbols64 = GuessStringType(SymEnumerateSymbols64A, SymEnumerateSymbols64W) + +# DWORD WINAPI UnDecorateSymbolName( +# __in PCTSTR DecoratedName, +# __out PTSTR UnDecoratedName, +# __in DWORD UndecoratedLength, +# __in DWORD Flags +# ); +def UnDecorateSymbolNameA(DecoratedName, Flags = UNDNAME_COMPLETE): + _UnDecorateSymbolNameA = windll.dbghelp.UnDecorateSymbolName + _UnDecorateSymbolNameA.argtypes = [LPSTR, LPSTR, DWORD, DWORD] + _UnDecorateSymbolNameA.restype = DWORD + _UnDecorateSymbolNameA.errcheck = RaiseIfZero + + UndecoratedLength = _UnDecorateSymbolNameA(DecoratedName, None, 0, Flags) + UnDecoratedName = ctypes.create_string_buffer('', UndecoratedLength + 1) + _UnDecorateSymbolNameA(DecoratedName, UnDecoratedName, UndecoratedLength, Flags) + return UnDecoratedName.value + +def UnDecorateSymbolNameW(DecoratedName, Flags = UNDNAME_COMPLETE): + _UnDecorateSymbolNameW = windll.dbghelp.UnDecorateSymbolNameW + _UnDecorateSymbolNameW.argtypes = [LPWSTR, LPWSTR, DWORD, DWORD] + _UnDecorateSymbolNameW.restype = DWORD + _UnDecorateSymbolNameW.errcheck = RaiseIfZero + + UndecoratedLength = _UnDecorateSymbolNameW(DecoratedName, None, 0, Flags) + UnDecoratedName = ctypes.create_unicode_buffer(u'', UndecoratedLength + 1) + _UnDecorateSymbolNameW(DecoratedName, UnDecoratedName, UndecoratedLength, Flags) + return UnDecoratedName.value + +UnDecorateSymbolName = GuessStringType(UnDecorateSymbolNameA, UnDecorateSymbolNameW) + +# BOOL WINAPI SymGetSearchPath( +# __in HANDLE hProcess, +# __out PTSTR SearchPath, +# __in DWORD SearchPathLength +# ); +def SymGetSearchPathA(hProcess): + _SymGetSearchPath = windll.dbghelp.SymGetSearchPath + _SymGetSearchPath.argtypes = [HANDLE, LPSTR, DWORD] + _SymGetSearchPath.restype = bool + _SymGetSearchPath.errcheck = RaiseIfZero + + SearchPathLength = MAX_PATH + SearchPath = ctypes.create_string_buffer("", SearchPathLength) + _SymGetSearchPath(hProcess, SearchPath, SearchPathLength) + return SearchPath.value + +def SymGetSearchPathW(hProcess): + _SymGetSearchPathW = windll.dbghelp.SymGetSearchPathW + _SymGetSearchPathW.argtypes = [HANDLE, LPWSTR, DWORD] + _SymGetSearchPathW.restype = bool + _SymGetSearchPathW.errcheck = RaiseIfZero + + SearchPathLength = MAX_PATH + SearchPath = ctypes.create_unicode_buffer(u"", SearchPathLength) + _SymGetSearchPathW(hProcess, SearchPath, SearchPathLength) + return SearchPath.value + +SymGetSearchPath = GuessStringType(SymGetSearchPathA, SymGetSearchPathW) + +# BOOL WINAPI SymSetSearchPath( +# __in HANDLE hProcess, +# __in_opt PCTSTR SearchPath +# ); +def SymSetSearchPathA(hProcess, SearchPath = None): + _SymSetSearchPath = windll.dbghelp.SymSetSearchPath + _SymSetSearchPath.argtypes = [HANDLE, LPSTR] + _SymSetSearchPath.restype = bool + _SymSetSearchPath.errcheck = RaiseIfZero + if not SearchPath: + SearchPath = None + _SymSetSearchPath(hProcess, SearchPath) + +def SymSetSearchPathW(hProcess, SearchPath = None): + _SymSetSearchPathW = windll.dbghelp.SymSetSearchPathW + _SymSetSearchPathW.argtypes = [HANDLE, LPWSTR] + _SymSetSearchPathW.restype = bool + _SymSetSearchPathW.errcheck = RaiseIfZero + if not SearchPath: + SearchPath = None + _SymSetSearchPathW(hProcess, SearchPath) + +SymSetSearchPath = GuessStringType(SymSetSearchPathA, SymSetSearchPathW) + +# PTCHAR WINAPI SymGetHomeDirectory( +# __in DWORD type, +# __out PTSTR dir, +# __in size_t size +# ); +def SymGetHomeDirectoryA(type): + _SymGetHomeDirectoryA = windll.dbghelp.SymGetHomeDirectoryA + _SymGetHomeDirectoryA.argtypes = [DWORD, LPSTR, SIZE_T] + _SymGetHomeDirectoryA.restype = LPSTR + _SymGetHomeDirectoryA.errcheck = RaiseIfZero + + size = MAX_PATH + dir = ctypes.create_string_buffer("", size) + _SymGetHomeDirectoryA(type, dir, size) + return dir.value + +def SymGetHomeDirectoryW(type): + _SymGetHomeDirectoryW = windll.dbghelp.SymGetHomeDirectoryW + _SymGetHomeDirectoryW.argtypes = [DWORD, LPWSTR, SIZE_T] + _SymGetHomeDirectoryW.restype = LPWSTR + _SymGetHomeDirectoryW.errcheck = RaiseIfZero + + size = MAX_PATH + dir = ctypes.create_unicode_buffer(u"", size) + _SymGetHomeDirectoryW(type, dir, size) + return dir.value + +SymGetHomeDirectory = GuessStringType(SymGetHomeDirectoryA, SymGetHomeDirectoryW) + +# PTCHAR WINAPI SymSetHomeDirectory( +# __in HANDLE hProcess, +# __in_opt PCTSTR dir +# ); +def SymSetHomeDirectoryA(hProcess, dir = None): + _SymSetHomeDirectoryA = windll.dbghelp.SymSetHomeDirectoryA + _SymSetHomeDirectoryA.argtypes = [HANDLE, LPSTR] + _SymSetHomeDirectoryA.restype = LPSTR + _SymSetHomeDirectoryA.errcheck = RaiseIfZero + if not dir: + dir = None + _SymSetHomeDirectoryA(hProcess, dir) + return dir + +def SymSetHomeDirectoryW(hProcess, dir = None): + _SymSetHomeDirectoryW = windll.dbghelp.SymSetHomeDirectoryW + _SymSetHomeDirectoryW.argtypes = [HANDLE, LPWSTR] + _SymSetHomeDirectoryW.restype = LPWSTR + _SymSetHomeDirectoryW.errcheck = RaiseIfZero + if not dir: + dir = None + _SymSetHomeDirectoryW(hProcess, dir) + return dir + +SymSetHomeDirectory = GuessStringType(SymSetHomeDirectoryA, SymSetHomeDirectoryW) + +#--- DbgHelp 5+ support, patch by Neitsa -------------------------------------- + +# XXX TODO +# + use the GuessStringType decorator for ANSI/Wide versions +# + replace hardcoded struct sizes with sizeof() calls +# + StackWalk64 should raise on error, but something has to be done about it +# not setting the last error code (maybe we should call SetLastError +# ourselves with a default error code?) +# /Mario + +#maximum length of a symbol name +MAX_SYM_NAME = 2000 + +class SYM_INFO(Structure): + _fields_ = [ + ("SizeOfStruct", ULONG), + ("TypeIndex", ULONG), + ("Reserved", ULONG64 * 2), + ("Index", ULONG), + ("Size", ULONG), + ("ModBase", ULONG64), + ("Flags", ULONG), + ("Value", ULONG64), + ("Address", ULONG64), + ("Register", ULONG), + ("Scope", ULONG), + ("Tag", ULONG), + ("NameLen", ULONG), + ("MaxNameLen", ULONG), + ("Name", CHAR * (MAX_SYM_NAME + 1)), + ] +PSYM_INFO = POINTER(SYM_INFO) + +class SYM_INFOW(Structure): + _fields_ = [ + ("SizeOfStruct", ULONG), + ("TypeIndex", ULONG), + ("Reserved", ULONG64 * 2), + ("Index", ULONG), + ("Size", ULONG), + ("ModBase", ULONG64), + ("Flags", ULONG), + ("Value", ULONG64), + ("Address", ULONG64), + ("Register", ULONG), + ("Scope", ULONG), + ("Tag", ULONG), + ("NameLen", ULONG), + ("MaxNameLen", ULONG), + ("Name", WCHAR * (MAX_SYM_NAME + 1)), + ] +PSYM_INFOW = POINTER(SYM_INFOW) + +#=============================================================================== +# BOOL WINAPI SymFromName( +# __in HANDLE hProcess, +# __in PCTSTR Name, +# __inout PSYMBOL_INFO Symbol +# ); +#=============================================================================== +def SymFromName(hProcess, Name): + _SymFromNameA = windll.dbghelp.SymFromName + _SymFromNameA.argtypes = [HANDLE, LPSTR, PSYM_INFO] + _SymFromNameA.restype = bool + _SymFromNameA.errcheck = RaiseIfZero + + SymInfo = SYM_INFO() + SymInfo.SizeOfStruct = 88 # *don't modify*: sizeof(SYMBOL_INFO) in C. + SymInfo.MaxNameLen = MAX_SYM_NAME + + _SymFromNameA(hProcess, Name, byref(SymInfo)) + + return SymInfo + +def SymFromNameW(hProcess, Name): + _SymFromNameW = windll.dbghelp.SymFromNameW + _SymFromNameW.argtypes = [HANDLE, LPWSTR, PSYM_INFOW] + _SymFromNameW.restype = bool + _SymFromNameW.errcheck = RaiseIfZero + + SymInfo = SYM_INFOW() + SymInfo.SizeOfStruct = 88 # *don't modify*: sizeof(SYMBOL_INFOW) in C. + SymInfo.MaxNameLen = MAX_SYM_NAME + + _SymFromNameW(hProcess, Name, byref(SymInfo)) + + return SymInfo + +#=============================================================================== +# BOOL WINAPI SymFromAddr( +# __in HANDLE hProcess, +# __in DWORD64 Address, +# __out_opt PDWORD64 Displacement, +# __inout PSYMBOL_INFO Symbol +# ); +#=============================================================================== +def SymFromAddr(hProcess, Address): + _SymFromAddr = windll.dbghelp.SymFromAddr + _SymFromAddr.argtypes = [HANDLE, DWORD64, PDWORD64, PSYM_INFO] + _SymFromAddr.restype = bool + _SymFromAddr.errcheck = RaiseIfZero + + SymInfo = SYM_INFO() + SymInfo.SizeOfStruct = 88 # *don't modify*: sizeof(SYMBOL_INFO) in C. + SymInfo.MaxNameLen = MAX_SYM_NAME + + Displacement = DWORD64(0) + _SymFromAddr(hProcess, Address, byref(Displacement), byref(SymInfo)) + + return (Displacement.value, SymInfo) + +def SymFromAddrW(hProcess, Address): + _SymFromAddr = windll.dbghelp.SymFromAddrW + _SymFromAddr.argtypes = [HANDLE, DWORD64, PDWORD64, PSYM_INFOW] + _SymFromAddr.restype = bool + _SymFromAddr.errcheck = RaiseIfZero + + SymInfo = SYM_INFOW() + SymInfo.SizeOfStruct = 88 # *don't modify*: sizeof(SYMBOL_INFOW) in C. + SymInfo.MaxNameLen = MAX_SYM_NAME + + Displacement = DWORD64(0) + _SymFromAddr(hProcess, Address, byref(Displacement), byref(SymInfo)) + + return (Displacement.value, SymInfo) + +#=============================================================================== +# typedef struct _IMAGEHLP_SYMBOL64 { +# DWORD SizeOfStruct; +# DWORD64 Address; +# DWORD Size; +# DWORD Flags; +# DWORD MaxNameLength; +# CHAR Name[1]; +# } IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; +#=============================================================================== +class IMAGEHLP_SYMBOL64 (Structure): + _fields_ = [ + ("SizeOfStruct", DWORD), + ("Address", DWORD64), + ("Size", DWORD), + ("Flags", DWORD), + ("MaxNameLength", DWORD), + ("Name", CHAR * (MAX_SYM_NAME + 1)), + ] +PIMAGEHLP_SYMBOL64 = POINTER(IMAGEHLP_SYMBOL64) + +#=============================================================================== +# typedef struct _IMAGEHLP_SYMBOLW64 { +# DWORD SizeOfStruct; +# DWORD64 Address; +# DWORD Size; +# DWORD Flags; +# DWORD MaxNameLength; +# WCHAR Name[1]; +# } IMAGEHLP_SYMBOLW64, *PIMAGEHLP_SYMBOLW64; +#=============================================================================== +class IMAGEHLP_SYMBOLW64 (Structure): + _fields_ = [ + ("SizeOfStruct", DWORD), + ("Address", DWORD64), + ("Size", DWORD), + ("Flags", DWORD), + ("MaxNameLength", DWORD), + ("Name", WCHAR * (MAX_SYM_NAME + 1)), + ] +PIMAGEHLP_SYMBOLW64 = POINTER(IMAGEHLP_SYMBOLW64) + +#=============================================================================== +# BOOL WINAPI SymGetSymFromAddr64( +# __in HANDLE hProcess, +# __in DWORD64 Address, +# __out_opt PDWORD64 Displacement, +# __inout PIMAGEHLP_SYMBOL64 Symbol +# ); +#=============================================================================== +def SymGetSymFromAddr64(hProcess, Address): + _SymGetSymFromAddr64 = windll.dbghelp.SymGetSymFromAddr64 + _SymGetSymFromAddr64.argtypes = [HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64] + _SymGetSymFromAddr64.restype = bool + _SymGetSymFromAddr64.errcheck = RaiseIfZero + + imagehlp_symbol64 = IMAGEHLP_SYMBOL64() + imagehlp_symbol64.SizeOfStruct = 32 # *don't modify*: sizeof(IMAGEHLP_SYMBOL64) in C. + imagehlp_symbol64.MaxNameLen = MAX_SYM_NAME + + Displacement = DWORD64(0) + _SymGetSymFromAddr64(hProcess, Address, byref(Displacement), byref(imagehlp_symbol64)) + + return (Displacement.value, imagehlp_symbol64) + +#TODO: check for the 'W' version of SymGetSymFromAddr64() + + +#=============================================================================== +# typedef struct API_VERSION { +# USHORT MajorVersion; +# USHORT MinorVersion; +# USHORT Revision; +# USHORT Reserved; +# } API_VERSION, *LPAPI_VERSION; +#=============================================================================== +class API_VERSION (Structure): + _fields_ = [ + ("MajorVersion", USHORT), + ("MinorVersion", USHORT), + ("Revision", USHORT), + ("Reserved", USHORT), + ] +PAPI_VERSION = POINTER(API_VERSION) +LPAPI_VERSION = PAPI_VERSION + +#=============================================================================== +# LPAPI_VERSION WINAPI ImagehlpApiVersion(void); +#=============================================================================== +def ImagehlpApiVersion(): + _ImagehlpApiVersion = windll.dbghelp.ImagehlpApiVersion + _ImagehlpApiVersion.restype = LPAPI_VERSION + + api_version = _ImagehlpApiVersion() + return api_version.contents + + +#=============================================================================== +# LPAPI_VERSION WINAPI ImagehlpApiVersionEx( +# __in LPAPI_VERSION AppVersion +# ); +#=============================================================================== +def ImagehlpApiVersionEx(MajorVersion, MinorVersion, Revision): + _ImagehlpApiVersionEx = windll.dbghelp.ImagehlpApiVersionEx + _ImagehlpApiVersionEx.argtypes = [LPAPI_VERSION] + _ImagehlpApiVersionEx.restype = LPAPI_VERSION + + api_version = API_VERSION(MajorVersion, MinorVersion, Revision, 0) + + ret_api_version = _ImagehlpApiVersionEx(byref(api_version)) + + return ret_api_version.contents + +#=============================================================================== +# typedef enum { +# AddrMode1616, +# AddrMode1632, +# AddrModeReal, +# AddrModeFlat +# } ADDRESS_MODE; +#=============================================================================== +AddrMode1616 = 0 +AddrMode1632 = 1 +AddrModeReal = 2 +AddrModeFlat = 3 + +ADDRESS_MODE = DWORD #needed for the size of an ADDRESS_MODE (see ADDRESS64) + +#=============================================================================== +# typedef struct _tagADDRESS64 { +# DWORD64 Offset; +# WORD Segment; +# ADDRESS_MODE Mode; +# } ADDRESS64, *LPADDRESS64; +#=============================================================================== +class ADDRESS64 (Structure): + _fields_ = [ + ("Offset", DWORD64), + ("Segment", WORD), + ("Mode", ADDRESS_MODE), #it's a member of the ADDRESS_MODE enum. + ] +LPADDRESS64 = POINTER(ADDRESS64) + +#=============================================================================== +# typedef struct _KDHELP64 { +# DWORD64 Thread; +# DWORD ThCallbackStack; +# DWORD ThCallbackBStore; +# DWORD NextCallback; +# DWORD FramePointer; +# DWORD64 KiCallUserMode; +# DWORD64 KeUserCallbackDispatcher; +# DWORD64 SystemRangeStart; +# DWORD64 KiUserExceptionDispatcher; +# DWORD64 StackBase; +# DWORD64 StackLimit; +# DWORD64 Reserved[5]; +# } KDHELP64, *PKDHELP64; +#=============================================================================== +class KDHELP64 (Structure): + _fields_ = [ + ("Thread", DWORD64), + ("ThCallbackStack", DWORD), + ("ThCallbackBStore", DWORD), + ("NextCallback", DWORD), + ("FramePointer", DWORD), + ("KiCallUserMode", DWORD64), + ("KeUserCallbackDispatcher", DWORD64), + ("SystemRangeStart", DWORD64), + ("KiUserExceptionDispatcher", DWORD64), + ("StackBase", DWORD64), + ("StackLimit", DWORD64), + ("Reserved", DWORD64 * 5), + ] +PKDHELP64 = POINTER(KDHELP64) + +#=============================================================================== +# typedef struct _tagSTACKFRAME64 { +# ADDRESS64 AddrPC; +# ADDRESS64 AddrReturn; +# ADDRESS64 AddrFrame; +# ADDRESS64 AddrStack; +# ADDRESS64 AddrBStore; +# PVOID FuncTableEntry; +# DWORD64 Params[4]; +# BOOL Far; +# BOOL Virtual; +# DWORD64 Reserved[3]; +# KDHELP64 KdHelp; +# } STACKFRAME64, *LPSTACKFRAME64; +#=============================================================================== +class STACKFRAME64(Structure): + _fields_ = [ + ("AddrPC", ADDRESS64), + ("AddrReturn", ADDRESS64), + ("AddrFrame", ADDRESS64), + ("AddrStack", ADDRESS64), + ("AddrBStore", ADDRESS64), + ("FuncTableEntry", PVOID), + ("Params", DWORD64 * 4), + ("Far", BOOL), + ("Virtual", BOOL), + ("Reserved", DWORD64 * 3), + ("KdHelp", KDHELP64), + ] +LPSTACKFRAME64 = POINTER(STACKFRAME64) + +#=============================================================================== +# BOOL CALLBACK ReadProcessMemoryProc64( +# __in HANDLE hProcess, +# __in DWORD64 lpBaseAddress, +# __out PVOID lpBuffer, +# __in DWORD nSize, +# __out LPDWORD lpNumberOfBytesRead +# ); +#=============================================================================== +PREAD_PROCESS_MEMORY_ROUTINE64 = WINFUNCTYPE(BOOL, HANDLE, DWORD64, PVOID, DWORD, LPDWORD) + +#=============================================================================== +# PVOID CALLBACK FunctionTableAccessProc64( +# __in HANDLE hProcess, +# __in DWORD64 AddrBase +# ); +#=============================================================================== +PFUNCTION_TABLE_ACCESS_ROUTINE64 = WINFUNCTYPE(PVOID, HANDLE, DWORD64) + +#=============================================================================== +# DWORD64 CALLBACK GetModuleBaseProc64( +# __in HANDLE hProcess, +# __in DWORD64 Address +# ); +#=============================================================================== +PGET_MODULE_BASE_ROUTINE64 = WINFUNCTYPE(DWORD64, HANDLE, DWORD64) + +#=============================================================================== +# DWORD64 CALLBACK GetModuleBaseProc64( +# __in HANDLE hProcess, +# __in DWORD64 Address +# ); +#=============================================================================== +PTRANSLATE_ADDRESS_ROUTINE64 = WINFUNCTYPE(DWORD64, HANDLE, DWORD64) + +# Valid machine types for StackWalk64 function +IMAGE_FILE_MACHINE_I386 = 0x014c #Intel x86 +IMAGE_FILE_MACHINE_IA64 = 0x0200 #Intel Itanium Processor Family (IPF) +IMAGE_FILE_MACHINE_AMD64 = 0x8664 #x64 (AMD64 or EM64T) + +#=============================================================================== +# BOOL WINAPI StackWalk64( +# __in DWORD MachineType, +# __in HANDLE hProcess, +# __in HANDLE hThread, +# __inout LPSTACKFRAME64 StackFrame, +# __inout PVOID ContextRecord, +# __in_opt PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, +# __in_opt PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, +# __in_opt PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, +# __in_opt PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress +# ); +#=============================================================================== +def StackWalk64(MachineType, hProcess, hThread, StackFrame, + ContextRecord = None, ReadMemoryRoutine = None, + FunctionTableAccessRoutine = None, GetModuleBaseRoutine = None, + TranslateAddress = None): + + _StackWalk64 = windll.dbghelp.StackWalk64 + _StackWalk64.argtypes = [DWORD, HANDLE, HANDLE, LPSTACKFRAME64, PVOID, + PREAD_PROCESS_MEMORY_ROUTINE64, + PFUNCTION_TABLE_ACCESS_ROUTINE64, + PGET_MODULE_BASE_ROUTINE64, + PTRANSLATE_ADDRESS_ROUTINE64] + _StackWalk64.restype = bool + + pReadMemoryRoutine = None + if ReadMemoryRoutine: + pReadMemoryRoutine = PREAD_PROCESS_MEMORY_ROUTINE64(ReadMemoryRoutine) + else: + pReadMemoryRoutine = ctypes.cast(None, PREAD_PROCESS_MEMORY_ROUTINE64) + + pFunctionTableAccessRoutine = None + if FunctionTableAccessRoutine: + pFunctionTableAccessRoutine = PFUNCTION_TABLE_ACCESS_ROUTINE64(FunctionTableAccessRoutine) + else: + pFunctionTableAccessRoutine = ctypes.cast(None, PFUNCTION_TABLE_ACCESS_ROUTINE64) + + pGetModuleBaseRoutine = None + if GetModuleBaseRoutine: + pGetModuleBaseRoutine = PGET_MODULE_BASE_ROUTINE64(GetModuleBaseRoutine) + else: + pGetModuleBaseRoutine = ctypes.cast(None, PGET_MODULE_BASE_ROUTINE64) + + pTranslateAddress = None + if TranslateAddress: + pTranslateAddress = PTRANSLATE_ADDRESS_ROUTINE64(TranslateAddress) + else: + pTranslateAddress = ctypes.cast(None, PTRANSLATE_ADDRESS_ROUTINE64) + + pContextRecord = None + if ContextRecord is None: + ContextRecord = GetThreadContext(hThread, raw=True) + pContextRecord = PCONTEXT(ContextRecord) + + #this function *DOESN'T* set last error [GetLastError()] properly most of the time. + ret = _StackWalk64(MachineType, hProcess, hThread, byref(StackFrame), + pContextRecord, pReadMemoryRoutine, + pFunctionTableAccessRoutine, pGetModuleBaseRoutine, + pTranslateAddress) + + return ret + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/defines.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/defines.py new file mode 100644 index 0000000..187e429 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/defines.py @@ -0,0 +1,718 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Common definitions. +""" + +# TODO +# + add TCHAR and related types? + +__revision__ = "$Id$" + +import ctypes +import functools +from winappdbg import compat + +#------------------------------------------------------------------------------ + +# Some stuff from ctypes we'll be using very frequently. +addressof = ctypes.addressof +sizeof = ctypes.sizeof +SIZEOF = ctypes.sizeof +POINTER = ctypes.POINTER +Structure = ctypes.Structure +Union = ctypes.Union +WINFUNCTYPE = ctypes.WINFUNCTYPE +windll = ctypes.windll + +# The IronPython implementation of byref() was giving me problems, +# so I'm replacing it with the slower pointer() function. +try: + ctypes.c_void_p(ctypes.byref(ctypes.c_char())) # this fails in IronPython + byref = ctypes.byref +except TypeError: + byref = ctypes.pointer + +# XXX DEBUG +# The following code can be enabled to make the Win32 API wrappers log to +# standard output the dll and function names, the parameter values and the +# return value for each call. + +##WIN32_VERBOSE_MODE = True +WIN32_VERBOSE_MODE = False + +if WIN32_VERBOSE_MODE: + + class WinDllHook(object): + def __getattr__(self, name): + if name.startswith('_'): + return object.__getattr__(self, name) + return WinFuncHook(name) + + class WinFuncHook(object): + def __init__(self, name): + self.__name = name + + def __getattr__(self, name): + if name.startswith('_'): + return object.__getattr__(self, name) + return WinCallHook(self.__name, name) + + class WinCallHook(object): + def __init__(self, dllname, funcname): + self.__dllname = dllname + self.__funcname = funcname + self.__func = getattr(getattr(ctypes.windll, dllname), funcname) + + def __copy_attribute(self, attribute): + try: + value = getattr(self, attribute) + setattr(self.__func, attribute, value) + except AttributeError: + try: + delattr(self.__func, attribute) + except AttributeError: + pass + + def __call__(self, *argv): + self.__copy_attribute('argtypes') + self.__copy_attribute('restype') + self.__copy_attribute('errcheck') + print("-"*10) + print("%s ! %s %r" % (self.__dllname, self.__funcname, argv)) + retval = self.__func(*argv) + print("== %r" % (retval,)) + return retval + + windll = WinDllHook() + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +def RaiseIfZero(result, func = None, arguments = ()): + """ + Error checking for most Win32 API calls. + + The function is assumed to return an integer, which is C{0} on error. + In that case the C{WindowsError} exception is raised. + """ + if not result: + raise ctypes.WinError() + return result + +def RaiseIfNotZero(result, func = None, arguments = ()): + """ + Error checking for some odd Win32 API calls. + + The function is assumed to return an integer, which is zero on success. + If the return value is nonzero the C{WindowsError} exception is raised. + + This is mostly useful for free() like functions, where the return value is + the pointer to the memory block on failure or a C{NULL} pointer on success. + """ + if result: + raise ctypes.WinError() + return result + +def RaiseIfNotErrorSuccess(result, func = None, arguments = ()): + """ + Error checking for Win32 Registry API calls. + + The function is assumed to return a Win32 error code. If the code is not + C{ERROR_SUCCESS} then a C{WindowsError} exception is raised. + """ + if result != ERROR_SUCCESS: + raise ctypes.WinError(result) + return result + +class GuessStringType(object): + """ + Decorator that guesses the correct version (A or W) to call + based on the types of the strings passed as parameters. + + Calls the B{ANSI} version if the only string types are ANSI. + + Calls the B{Unicode} version if Unicode or mixed string types are passed. + + The default if no string arguments are passed depends on the value of the + L{t_default} class variable. + + @type fn_ansi: function + @ivar fn_ansi: ANSI version of the API function to call. + @type fn_unicode: function + @ivar fn_unicode: Unicode (wide) version of the API function to call. + + @type t_default: type + @cvar t_default: Default string type to use. + Possible values are: + - type('') for ANSI + - type(u'') for Unicode + """ + + # ANSI and Unicode types + t_ansi = type('') + t_unicode = type(u'') + + # Default is ANSI for Python 2.x + t_default = t_ansi + + def __init__(self, fn_ansi, fn_unicode): + """ + @type fn_ansi: function + @param fn_ansi: ANSI version of the API function to call. + @type fn_unicode: function + @param fn_unicode: Unicode (wide) version of the API function to call. + """ + self.fn_ansi = fn_ansi + self.fn_unicode = fn_unicode + + # Copy the wrapped function attributes. + try: + self.__name__ = self.fn_ansi.__name__[:-1] # remove the A or W + except AttributeError: + pass + try: + self.__module__ = self.fn_ansi.__module__ + except AttributeError: + pass + try: + self.__doc__ = self.fn_ansi.__doc__ + except AttributeError: + pass + + def __call__(self, *argv, **argd): + + # Shortcut to self.t_ansi + t_ansi = self.t_ansi + + # Get the types of all arguments for the function + v_types = [ type(item) for item in argv ] + v_types.extend( [ type(value) for (key, value) in compat.iteritems(argd) ] ) + + # Get the appropriate function for the default type + if self.t_default == t_ansi: + fn = self.fn_ansi + else: + fn = self.fn_unicode + + # If at least one argument is a Unicode string... + if self.t_unicode in v_types: + + # If al least one argument is an ANSI string, + # convert all ANSI strings to Unicode + if t_ansi in v_types: + argv = list(argv) + for index in compat.xrange(len(argv)): + if v_types[index] == t_ansi: + argv[index] = compat.unicode(argv[index]) + for (key, value) in argd.items(): + if type(value) == t_ansi: + argd[key] = compat.unicode(value) + + # Use the W version + fn = self.fn_unicode + + # If at least one argument is an ANSI string, + # but there are no Unicode strings... + elif t_ansi in v_types: + + # Use the A version + fn = self.fn_ansi + + # Call the function and return the result + return fn(*argv, **argd) + +class DefaultStringType(object): + """ + Decorator that uses the default version (A or W) to call + based on the configuration of the L{GuessStringType} decorator. + + @see: L{GuessStringType.t_default} + + @type fn_ansi: function + @ivar fn_ansi: ANSI version of the API function to call. + @type fn_unicode: function + @ivar fn_unicode: Unicode (wide) version of the API function to call. + """ + + def __init__(self, fn_ansi, fn_unicode): + """ + @type fn_ansi: function + @param fn_ansi: ANSI version of the API function to call. + @type fn_unicode: function + @param fn_unicode: Unicode (wide) version of the API function to call. + """ + self.fn_ansi = fn_ansi + self.fn_unicode = fn_unicode + + # Copy the wrapped function attributes. + try: + self.__name__ = self.fn_ansi.__name__[:-1] # remove the A or W + except AttributeError: + pass + try: + self.__module__ = self.fn_ansi.__module__ + except AttributeError: + pass + try: + self.__doc__ = self.fn_ansi.__doc__ + except AttributeError: + pass + + def __call__(self, *argv, **argd): + + # Get the appropriate function based on the default. + if GuessStringType.t_default == GuessStringType.t_ansi: + fn = self.fn_ansi + else: + fn = self.fn_unicode + + # Call the function and return the result + return fn(*argv, **argd) + +def MakeANSIVersion(fn): + """ + Decorator that generates an ANSI version of a Unicode (wide) only API call. + + @type fn: callable + @param fn: Unicode (wide) version of the API function to call. + """ + @functools.wraps(fn) + def wrapper(*argv, **argd): + t_ansi = GuessStringType.t_ansi + t_unicode = GuessStringType.t_unicode + v_types = [ type(item) for item in argv ] + v_types.extend( [ type(value) for (key, value) in compat.iteritems(argd) ] ) + if t_ansi in v_types: + argv = list(argv) + for index in compat.xrange(len(argv)): + if v_types[index] == t_ansi: + argv[index] = t_unicode(argv[index]) + for key, value in argd.items(): + if type(value) == t_ansi: + argd[key] = t_unicode(value) + return fn(*argv, **argd) + return wrapper + +def MakeWideVersion(fn): + """ + Decorator that generates a Unicode (wide) version of an ANSI only API call. + + @type fn: callable + @param fn: ANSI version of the API function to call. + """ + @functools.wraps(fn) + def wrapper(*argv, **argd): + t_ansi = GuessStringType.t_ansi + t_unicode = GuessStringType.t_unicode + v_types = [ type(item) for item in argv ] + v_types.extend( [ type(value) for (key, value) in compat.iteritems(argd) ] ) + if t_unicode in v_types: + argv = list(argv) + for index in compat.xrange(len(argv)): + if v_types[index] == t_unicode: + argv[index] = t_ansi(argv[index]) + for key, value in argd.items(): + if type(value) == t_unicode: + argd[key] = t_ansi(value) + return fn(*argv, **argd) + return wrapper + +#--- Types -------------------------------------------------------------------- +# http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx + +# Map of basic C types to Win32 types +LPVOID = ctypes.c_void_p +CHAR = ctypes.c_char +WCHAR = ctypes.c_wchar +BYTE = ctypes.c_ubyte +SBYTE = ctypes.c_byte +WORD = ctypes.c_uint16 +SWORD = ctypes.c_int16 +DWORD = ctypes.c_uint32 +SDWORD = ctypes.c_int32 +QWORD = ctypes.c_uint64 +SQWORD = ctypes.c_int64 +SHORT = ctypes.c_short +USHORT = ctypes.c_ushort +INT = ctypes.c_int +UINT = ctypes.c_uint +LONG = ctypes.c_long +ULONG = ctypes.c_ulong +LONGLONG = ctypes.c_int64 # c_longlong +ULONGLONG = ctypes.c_uint64 # c_ulonglong +LPSTR = ctypes.c_char_p +LPWSTR = ctypes.c_wchar_p +INT8 = ctypes.c_int8 +INT16 = ctypes.c_int16 +INT32 = ctypes.c_int32 +INT64 = ctypes.c_int64 +UINT8 = ctypes.c_uint8 +UINT16 = ctypes.c_uint16 +UINT32 = ctypes.c_uint32 +UINT64 = ctypes.c_uint64 +LONG32 = ctypes.c_int32 +LONG64 = ctypes.c_int64 +ULONG32 = ctypes.c_uint32 +ULONG64 = ctypes.c_uint64 +DWORD32 = ctypes.c_uint32 +DWORD64 = ctypes.c_uint64 +BOOL = ctypes.c_int +FLOAT = ctypes.c_float + +# Map size_t to SIZE_T +try: + SIZE_T = ctypes.c_size_t + SSIZE_T = ctypes.c_ssize_t +except AttributeError: + # Size of a pointer + SIZE_T = {1:BYTE, 2:WORD, 4:DWORD, 8:QWORD}[sizeof(LPVOID)] + SSIZE_T = {1:SBYTE, 2:SWORD, 4:SDWORD, 8:SQWORD}[sizeof(LPVOID)] +PSIZE_T = POINTER(SIZE_T) + +# Not really pointers but pointer-sized integers +DWORD_PTR = SIZE_T +ULONG_PTR = SIZE_T +LONG_PTR = SIZE_T + +# Other Win32 types, more may be added as needed +PVOID = LPVOID +PPVOID = POINTER(PVOID) +PSTR = LPSTR +PWSTR = LPWSTR +PCHAR = LPSTR +PWCHAR = LPWSTR +LPBYTE = POINTER(BYTE) +LPSBYTE = POINTER(SBYTE) +LPWORD = POINTER(WORD) +LPSWORD = POINTER(SWORD) +LPDWORD = POINTER(DWORD) +LPSDWORD = POINTER(SDWORD) +LPULONG = POINTER(ULONG) +LPLONG = POINTER(LONG) +PDWORD = LPDWORD +PDWORD_PTR = POINTER(DWORD_PTR) +PULONG = LPULONG +PLONG = LPLONG +CCHAR = CHAR +BOOLEAN = BYTE +PBOOL = POINTER(BOOL) +LPBOOL = PBOOL +TCHAR = CHAR # XXX ANSI by default? +UCHAR = BYTE +DWORDLONG = ULONGLONG +LPDWORD32 = POINTER(DWORD32) +LPULONG32 = POINTER(ULONG32) +LPDWORD64 = POINTER(DWORD64) +LPULONG64 = POINTER(ULONG64) +PDWORD32 = LPDWORD32 +PULONG32 = LPULONG32 +PDWORD64 = LPDWORD64 +PULONG64 = LPULONG64 +ATOM = WORD +HANDLE = LPVOID +PHANDLE = POINTER(HANDLE) +LPHANDLE = PHANDLE +HMODULE = HANDLE +HINSTANCE = HANDLE +HTASK = HANDLE +HKEY = HANDLE +PHKEY = POINTER(HKEY) +HDESK = HANDLE +HRSRC = HANDLE +HSTR = HANDLE +HWINSTA = HANDLE +HKL = HANDLE +HDWP = HANDLE +HFILE = HANDLE +HRESULT = LONG +HGLOBAL = HANDLE +HLOCAL = HANDLE +HGDIOBJ = HANDLE +HDC = HGDIOBJ +HRGN = HGDIOBJ +HBITMAP = HGDIOBJ +HPALETTE = HGDIOBJ +HPEN = HGDIOBJ +HBRUSH = HGDIOBJ +HMF = HGDIOBJ +HEMF = HGDIOBJ +HENHMETAFILE = HGDIOBJ +HMETAFILE = HGDIOBJ +HMETAFILEPICT = HGDIOBJ +HWND = HANDLE +NTSTATUS = LONG +PNTSTATUS = POINTER(NTSTATUS) +KAFFINITY = ULONG_PTR +RVA = DWORD +RVA64 = QWORD +WPARAM = DWORD +LPARAM = LPVOID +LRESULT = LPVOID +ACCESS_MASK = DWORD +REGSAM = ACCESS_MASK +PACCESS_MASK = POINTER(ACCESS_MASK) +PREGSAM = POINTER(REGSAM) + +# Since the SID is an opaque structure, let's treat its pointers as void* +PSID = PVOID + +# typedef union _LARGE_INTEGER { +# struct { +# DWORD LowPart; +# LONG HighPart; +# } ; +# struct { +# DWORD LowPart; +# LONG HighPart; +# } u; +# LONGLONG QuadPart; +# } LARGE_INTEGER, +# *PLARGE_INTEGER; + +# XXX TODO + +# typedef struct _FLOAT128 { +# __int64 LowPart; +# __int64 HighPart; +# } FLOAT128; +class FLOAT128 (Structure): + _fields_ = [ + ("LowPart", QWORD), + ("HighPart", QWORD), + ] +PFLOAT128 = POINTER(FLOAT128) + +# typedef struct DECLSPEC_ALIGN(16) _M128A { +# ULONGLONG Low; +# LONGLONG High; +# } M128A, *PM128A; +class M128A(Structure): + _fields_ = [ + ("Low", ULONGLONG), + ("High", LONGLONG), + ] +PM128A = POINTER(M128A) + +#--- Constants ---------------------------------------------------------------- + +NULL = None +INFINITE = -1 +TRUE = 1 +FALSE = 0 + +# http://blogs.msdn.com/oldnewthing/archive/2004/08/26/220873.aspx +ANYSIZE_ARRAY = 1 + +# Invalid handle value is -1 casted to void pointer. +try: + INVALID_HANDLE_VALUE = ctypes.c_void_p(-1).value #-1 #0xFFFFFFFF +except TypeError: + if sizeof(ctypes.c_void_p) == 4: + INVALID_HANDLE_VALUE = 0xFFFFFFFF + elif sizeof(ctypes.c_void_p) == 8: + INVALID_HANDLE_VALUE = 0xFFFFFFFFFFFFFFFF + else: + raise + +MAX_MODULE_NAME32 = 255 +MAX_PATH = 260 + +# Error codes +# TODO maybe add more error codes? +# if they're too many they could be pickled instead, +# or at the very least put in a new file +ERROR_SUCCESS = 0 +ERROR_INVALID_FUNCTION = 1 +ERROR_FILE_NOT_FOUND = 2 +ERROR_PATH_NOT_FOUND = 3 +ERROR_ACCESS_DENIED = 5 +ERROR_INVALID_HANDLE = 6 +ERROR_NOT_ENOUGH_MEMORY = 8 +ERROR_INVALID_DRIVE = 15 +ERROR_NO_MORE_FILES = 18 +ERROR_BAD_LENGTH = 24 +ERROR_HANDLE_EOF = 38 +ERROR_HANDLE_DISK_FULL = 39 +ERROR_NOT_SUPPORTED = 50 +ERROR_FILE_EXISTS = 80 +ERROR_INVALID_PARAMETER = 87 +ERROR_BUFFER_OVERFLOW = 111 +ERROR_DISK_FULL = 112 +ERROR_CALL_NOT_IMPLEMENTED = 120 +ERROR_SEM_TIMEOUT = 121 +ERROR_INSUFFICIENT_BUFFER = 122 +ERROR_INVALID_NAME = 123 +ERROR_MOD_NOT_FOUND = 126 +ERROR_PROC_NOT_FOUND = 127 +ERROR_DIR_NOT_EMPTY = 145 +ERROR_BAD_THREADID_ADDR = 159 +ERROR_BAD_ARGUMENTS = 160 +ERROR_BAD_PATHNAME = 161 +ERROR_ALREADY_EXISTS = 183 +ERROR_INVALID_FLAG_NUMBER = 186 +ERROR_ENVVAR_NOT_FOUND = 203 +ERROR_FILENAME_EXCED_RANGE = 206 +ERROR_MORE_DATA = 234 + +WAIT_TIMEOUT = 258 + +ERROR_NO_MORE_ITEMS = 259 +ERROR_PARTIAL_COPY = 299 +ERROR_INVALID_ADDRESS = 487 +ERROR_THREAD_NOT_IN_PROCESS = 566 +ERROR_CONTROL_C_EXIT = 572 +ERROR_UNHANDLED_EXCEPTION = 574 +ERROR_ASSERTION_FAILURE = 668 +ERROR_WOW_ASSERTION = 670 + +ERROR_DBG_EXCEPTION_NOT_HANDLED = 688 +ERROR_DBG_REPLY_LATER = 689 +ERROR_DBG_UNABLE_TO_PROVIDE_HANDLE = 690 +ERROR_DBG_TERMINATE_THREAD = 691 +ERROR_DBG_TERMINATE_PROCESS = 692 +ERROR_DBG_CONTROL_C = 693 +ERROR_DBG_PRINTEXCEPTION_C = 694 +ERROR_DBG_RIPEXCEPTION = 695 +ERROR_DBG_CONTROL_BREAK = 696 +ERROR_DBG_COMMAND_EXCEPTION = 697 +ERROR_DBG_EXCEPTION_HANDLED = 766 +ERROR_DBG_CONTINUE = 767 + +ERROR_ELEVATION_REQUIRED = 740 +ERROR_NOACCESS = 998 + +ERROR_CIRCULAR_DEPENDENCY = 1059 +ERROR_SERVICE_DOES_NOT_EXIST = 1060 +ERROR_SERVICE_CANNOT_ACCEPT_CTRL = 1061 +ERROR_SERVICE_NOT_ACTIVE = 1062 +ERROR_FAILED_SERVICE_CONTROLLER_CONNECT = 1063 +ERROR_EXCEPTION_IN_SERVICE = 1064 +ERROR_DATABASE_DOES_NOT_EXIST = 1065 +ERROR_SERVICE_SPECIFIC_ERROR = 1066 +ERROR_PROCESS_ABORTED = 1067 +ERROR_SERVICE_DEPENDENCY_FAIL = 1068 +ERROR_SERVICE_LOGON_FAILED = 1069 +ERROR_SERVICE_START_HANG = 1070 +ERROR_INVALID_SERVICE_LOCK = 1071 +ERROR_SERVICE_MARKED_FOR_DELETE = 1072 +ERROR_SERVICE_EXISTS = 1073 +ERROR_ALREADY_RUNNING_LKG = 1074 +ERROR_SERVICE_DEPENDENCY_DELETED = 1075 +ERROR_BOOT_ALREADY_ACCEPTED = 1076 +ERROR_SERVICE_NEVER_STARTED = 1077 +ERROR_DUPLICATE_SERVICE_NAME = 1078 +ERROR_DIFFERENT_SERVICE_ACCOUNT = 1079 +ERROR_CANNOT_DETECT_DRIVER_FAILURE = 1080 +ERROR_CANNOT_DETECT_PROCESS_ABORT = 1081 +ERROR_NO_RECOVERY_PROGRAM = 1082 +ERROR_SERVICE_NOT_IN_EXE = 1083 +ERROR_NOT_SAFEBOOT_SERVICE = 1084 + +ERROR_DEBUGGER_INACTIVE = 1284 + +ERROR_PRIVILEGE_NOT_HELD = 1314 + +ERROR_NONE_MAPPED = 1332 + +RPC_S_SERVER_UNAVAILABLE = 1722 + +# Standard access rights +import sys +if sys.version_info[0] >= 3: + long = int + +DELETE = long(0x00010000) +READ_CONTROL = long(0x00020000) +WRITE_DAC = long(0x00040000) +WRITE_OWNER = long(0x00080000) +SYNCHRONIZE = long(0x00100000) +STANDARD_RIGHTS_REQUIRED = long(0x000F0000) +STANDARD_RIGHTS_READ = READ_CONTROL +STANDARD_RIGHTS_WRITE = READ_CONTROL +STANDARD_RIGHTS_EXECUTE = READ_CONTROL +STANDARD_RIGHTS_ALL = long(0x001F0000) +SPECIFIC_RIGHTS_ALL = long(0x0000FFFF) + +#--- Structures --------------------------------------------------------------- + +# typedef struct _LSA_UNICODE_STRING { +# USHORT Length; +# USHORT MaximumLength; +# PWSTR Buffer; +# } LSA_UNICODE_STRING, +# *PLSA_UNICODE_STRING, +# UNICODE_STRING, +# *PUNICODE_STRING; +class UNICODE_STRING(Structure): + _fields_ = [ + ("Length", USHORT), + ("MaximumLength", USHORT), + ("Buffer", PVOID), + ] + +# From MSDN: +# +# typedef struct _GUID { +# DWORD Data1; +# WORD Data2; +# WORD Data3; +# BYTE Data4[8]; +# } GUID; +class GUID(Structure): + _fields_ = [ + ("Data1", DWORD), + ("Data2", WORD), + ("Data3", WORD), + ("Data4", BYTE * 8), +] + +# From MSDN: +# +# typedef struct _LIST_ENTRY { +# struct _LIST_ENTRY *Flink; +# struct _LIST_ENTRY *Blink; +# } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY; +class LIST_ENTRY(Structure): + _fields_ = [ + ("Flink", PVOID), # POINTER(LIST_ENTRY) + ("Blink", PVOID), # POINTER(LIST_ENTRY) +] + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +##__all__ = [_x for _x in _all if not _x.startswith('_')] +##__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/gdi32.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/gdi32.py new file mode 100644 index 0000000..c3b5e6e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/gdi32.py @@ -0,0 +1,507 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for gdi32.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.kernel32 import GetLastError, SetLastError + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- Helpers ------------------------------------------------------------------ + +#--- Types -------------------------------------------------------------------- + +#--- Constants ---------------------------------------------------------------- + +# GDI object types +OBJ_PEN = 1 +OBJ_BRUSH = 2 +OBJ_DC = 3 +OBJ_METADC = 4 +OBJ_PAL = 5 +OBJ_FONT = 6 +OBJ_BITMAP = 7 +OBJ_REGION = 8 +OBJ_METAFILE = 9 +OBJ_MEMDC = 10 +OBJ_EXTPEN = 11 +OBJ_ENHMETADC = 12 +OBJ_ENHMETAFILE = 13 +OBJ_COLORSPACE = 14 +GDI_OBJ_LAST = OBJ_COLORSPACE + +# Ternary raster operations +SRCCOPY = 0x00CC0020 # dest = source +SRCPAINT = 0x00EE0086 # dest = source OR dest +SRCAND = 0x008800C6 # dest = source AND dest +SRCINVERT = 0x00660046 # dest = source XOR dest +SRCERASE = 0x00440328 # dest = source AND (NOT dest) +NOTSRCCOPY = 0x00330008 # dest = (NOT source) +NOTSRCERASE = 0x001100A6 # dest = (NOT src) AND (NOT dest) +MERGECOPY = 0x00C000CA # dest = (source AND pattern) +MERGEPAINT = 0x00BB0226 # dest = (NOT source) OR dest +PATCOPY = 0x00F00021 # dest = pattern +PATPAINT = 0x00FB0A09 # dest = DPSnoo +PATINVERT = 0x005A0049 # dest = pattern XOR dest +DSTINVERT = 0x00550009 # dest = (NOT dest) +BLACKNESS = 0x00000042 # dest = BLACK +WHITENESS = 0x00FF0062 # dest = WHITE +NOMIRRORBITMAP = 0x80000000 # Do not Mirror the bitmap in this call +CAPTUREBLT = 0x40000000 # Include layered windows + +# Region flags +ERROR = 0 +NULLREGION = 1 +SIMPLEREGION = 2 +COMPLEXREGION = 3 +RGN_ERROR = ERROR + +# CombineRgn() styles +RGN_AND = 1 +RGN_OR = 2 +RGN_XOR = 3 +RGN_DIFF = 4 +RGN_COPY = 5 +RGN_MIN = RGN_AND +RGN_MAX = RGN_COPY + +# StretchBlt() modes +BLACKONWHITE = 1 +WHITEONBLACK = 2 +COLORONCOLOR = 3 +HALFTONE = 4 +MAXSTRETCHBLTMODE = 4 +STRETCH_ANDSCANS = BLACKONWHITE +STRETCH_ORSCANS = WHITEONBLACK +STRETCH_DELETESCANS = COLORONCOLOR +STRETCH_HALFTONE = HALFTONE + +# PolyFill() modes +ALTERNATE = 1 +WINDING = 2 +POLYFILL_LAST = 2 + +# Layout orientation options +LAYOUT_RTL = 0x00000001 # Right to left +LAYOUT_BTT = 0x00000002 # Bottom to top +LAYOUT_VBH = 0x00000004 # Vertical before horizontal +LAYOUT_ORIENTATIONMASK = LAYOUT_RTL + LAYOUT_BTT + LAYOUT_VBH +LAYOUT_BITMAPORIENTATIONPRESERVED = 0x00000008 + +# Stock objects +WHITE_BRUSH = 0 +LTGRAY_BRUSH = 1 +GRAY_BRUSH = 2 +DKGRAY_BRUSH = 3 +BLACK_BRUSH = 4 +NULL_BRUSH = 5 +HOLLOW_BRUSH = NULL_BRUSH +WHITE_PEN = 6 +BLACK_PEN = 7 +NULL_PEN = 8 +OEM_FIXED_FONT = 10 +ANSI_FIXED_FONT = 11 +ANSI_VAR_FONT = 12 +SYSTEM_FONT = 13 +DEVICE_DEFAULT_FONT = 14 +DEFAULT_PALETTE = 15 +SYSTEM_FIXED_FONT = 16 + +# Metafile functions +META_SETBKCOLOR = 0x0201 +META_SETBKMODE = 0x0102 +META_SETMAPMODE = 0x0103 +META_SETROP2 = 0x0104 +META_SETRELABS = 0x0105 +META_SETPOLYFILLMODE = 0x0106 +META_SETSTRETCHBLTMODE = 0x0107 +META_SETTEXTCHAREXTRA = 0x0108 +META_SETTEXTCOLOR = 0x0209 +META_SETTEXTJUSTIFICATION = 0x020A +META_SETWINDOWORG = 0x020B +META_SETWINDOWEXT = 0x020C +META_SETVIEWPORTORG = 0x020D +META_SETVIEWPORTEXT = 0x020E +META_OFFSETWINDOWORG = 0x020F +META_SCALEWINDOWEXT = 0x0410 +META_OFFSETVIEWPORTORG = 0x0211 +META_SCALEVIEWPORTEXT = 0x0412 +META_LINETO = 0x0213 +META_MOVETO = 0x0214 +META_EXCLUDECLIPRECT = 0x0415 +META_INTERSECTCLIPRECT = 0x0416 +META_ARC = 0x0817 +META_ELLIPSE = 0x0418 +META_FLOODFILL = 0x0419 +META_PIE = 0x081A +META_RECTANGLE = 0x041B +META_ROUNDRECT = 0x061C +META_PATBLT = 0x061D +META_SAVEDC = 0x001E +META_SETPIXEL = 0x041F +META_OFFSETCLIPRGN = 0x0220 +META_TEXTOUT = 0x0521 +META_BITBLT = 0x0922 +META_STRETCHBLT = 0x0B23 +META_POLYGON = 0x0324 +META_POLYLINE = 0x0325 +META_ESCAPE = 0x0626 +META_RESTOREDC = 0x0127 +META_FILLREGION = 0x0228 +META_FRAMEREGION = 0x0429 +META_INVERTREGION = 0x012A +META_PAINTREGION = 0x012B +META_SELECTCLIPREGION = 0x012C +META_SELECTOBJECT = 0x012D +META_SETTEXTALIGN = 0x012E +META_CHORD = 0x0830 +META_SETMAPPERFLAGS = 0x0231 +META_EXTTEXTOUT = 0x0a32 +META_SETDIBTODEV = 0x0d33 +META_SELECTPALETTE = 0x0234 +META_REALIZEPALETTE = 0x0035 +META_ANIMATEPALETTE = 0x0436 +META_SETPALENTRIES = 0x0037 +META_POLYPOLYGON = 0x0538 +META_RESIZEPALETTE = 0x0139 +META_DIBBITBLT = 0x0940 +META_DIBSTRETCHBLT = 0x0b41 +META_DIBCREATEPATTERNBRUSH = 0x0142 +META_STRETCHDIB = 0x0f43 +META_EXTFLOODFILL = 0x0548 +META_SETLAYOUT = 0x0149 +META_DELETEOBJECT = 0x01f0 +META_CREATEPALETTE = 0x00f7 +META_CREATEPATTERNBRUSH = 0x01F9 +META_CREATEPENINDIRECT = 0x02FA +META_CREATEFONTINDIRECT = 0x02FB +META_CREATEBRUSHINDIRECT = 0x02FC +META_CREATEREGION = 0x06FF + +# Metafile escape codes +NEWFRAME = 1 +ABORTDOC = 2 +NEXTBAND = 3 +SETCOLORTABLE = 4 +GETCOLORTABLE = 5 +FLUSHOUTPUT = 6 +DRAFTMODE = 7 +QUERYESCSUPPORT = 8 +SETABORTPROC = 9 +STARTDOC = 10 +ENDDOC = 11 +GETPHYSPAGESIZE = 12 +GETPRINTINGOFFSET = 13 +GETSCALINGFACTOR = 14 +MFCOMMENT = 15 +GETPENWIDTH = 16 +SETCOPYCOUNT = 17 +SELECTPAPERSOURCE = 18 +DEVICEDATA = 19 +PASSTHROUGH = 19 +GETTECHNOLGY = 20 +GETTECHNOLOGY = 20 +SETLINECAP = 21 +SETLINEJOIN = 22 +SETMITERLIMIT = 23 +BANDINFO = 24 +DRAWPATTERNRECT = 25 +GETVECTORPENSIZE = 26 +GETVECTORBRUSHSIZE = 27 +ENABLEDUPLEX = 28 +GETSETPAPERBINS = 29 +GETSETPRINTORIENT = 30 +ENUMPAPERBINS = 31 +SETDIBSCALING = 32 +EPSPRINTING = 33 +ENUMPAPERMETRICS = 34 +GETSETPAPERMETRICS = 35 +POSTSCRIPT_DATA = 37 +POSTSCRIPT_IGNORE = 38 +MOUSETRAILS = 39 +GETDEVICEUNITS = 42 +GETEXTENDEDTEXTMETRICS = 256 +GETEXTENTTABLE = 257 +GETPAIRKERNTABLE = 258 +GETTRACKKERNTABLE = 259 +EXTTEXTOUT = 512 +GETFACENAME = 513 +DOWNLOADFACE = 514 +ENABLERELATIVEWIDTHS = 768 +ENABLEPAIRKERNING = 769 +SETKERNTRACK = 770 +SETALLJUSTVALUES = 771 +SETCHARSET = 772 +STRETCHBLT = 2048 +METAFILE_DRIVER = 2049 +GETSETSCREENPARAMS = 3072 +QUERYDIBSUPPORT = 3073 +BEGIN_PATH = 4096 +CLIP_TO_PATH = 4097 +END_PATH = 4098 +EXT_DEVICE_CAPS = 4099 +RESTORE_CTM = 4100 +SAVE_CTM = 4101 +SET_ARC_DIRECTION = 4102 +SET_BACKGROUND_COLOR = 4103 +SET_POLY_MODE = 4104 +SET_SCREEN_ANGLE = 4105 +SET_SPREAD = 4106 +TRANSFORM_CTM = 4107 +SET_CLIP_BOX = 4108 +SET_BOUNDS = 4109 +SET_MIRROR_MODE = 4110 +OPENCHANNEL = 4110 +DOWNLOADHEADER = 4111 +CLOSECHANNEL = 4112 +POSTSCRIPT_PASSTHROUGH = 4115 +ENCAPSULATED_POSTSCRIPT = 4116 +POSTSCRIPT_IDENTIFY = 4117 +POSTSCRIPT_INJECTION = 4118 +CHECKJPEGFORMAT = 4119 +CHECKPNGFORMAT = 4120 +GET_PS_FEATURESETTING = 4121 +GDIPLUS_TS_QUERYVER = 4122 +GDIPLUS_TS_RECORD = 4123 +SPCLPASSTHROUGH2 = 4568 + +#--- Structures --------------------------------------------------------------- + +# typedef struct _RECT { +# LONG left; +# LONG top; +# LONG right; +# LONG bottom; +# }RECT, *PRECT; +class RECT(Structure): + _fields_ = [ + ('left', LONG), + ('top', LONG), + ('right', LONG), + ('bottom', LONG), + ] +PRECT = POINTER(RECT) +LPRECT = PRECT + +# typedef struct tagPOINT { +# LONG x; +# LONG y; +# } POINT; +class POINT(Structure): + _fields_ = [ + ('x', LONG), + ('y', LONG), + ] +PPOINT = POINTER(POINT) +LPPOINT = PPOINT + +# typedef struct tagBITMAP { +# LONG bmType; +# LONG bmWidth; +# LONG bmHeight; +# LONG bmWidthBytes; +# WORD bmPlanes; +# WORD bmBitsPixel; +# LPVOID bmBits; +# } BITMAP, *PBITMAP; +class BITMAP(Structure): + _fields_ = [ + ("bmType", LONG), + ("bmWidth", LONG), + ("bmHeight", LONG), + ("bmWidthBytes", LONG), + ("bmPlanes", WORD), + ("bmBitsPixel", WORD), + ("bmBits", LPVOID), + ] +PBITMAP = POINTER(BITMAP) +LPBITMAP = PBITMAP + +#--- High level classes ------------------------------------------------------- + +#--- gdi32.dll ---------------------------------------------------------------- + +# HDC GetDC( +# __in HWND hWnd +# ); +def GetDC(hWnd): + _GetDC = windll.gdi32.GetDC + _GetDC.argtypes = [HWND] + _GetDC.restype = HDC + _GetDC.errcheck = RaiseIfZero + return _GetDC(hWnd) + +# HDC GetWindowDC( +# __in HWND hWnd +# ); +def GetWindowDC(hWnd): + _GetWindowDC = windll.gdi32.GetWindowDC + _GetWindowDC.argtypes = [HWND] + _GetWindowDC.restype = HDC + _GetWindowDC.errcheck = RaiseIfZero + return _GetWindowDC(hWnd) + +# int ReleaseDC( +# __in HWND hWnd, +# __in HDC hDC +# ); +def ReleaseDC(hWnd, hDC): + _ReleaseDC = windll.gdi32.ReleaseDC + _ReleaseDC.argtypes = [HWND, HDC] + _ReleaseDC.restype = ctypes.c_int + _ReleaseDC.errcheck = RaiseIfZero + _ReleaseDC(hWnd, hDC) + +# HGDIOBJ SelectObject( +# __in HDC hdc, +# __in HGDIOBJ hgdiobj +# ); +def SelectObject(hdc, hgdiobj): + _SelectObject = windll.gdi32.SelectObject + _SelectObject.argtypes = [HDC, HGDIOBJ] + _SelectObject.restype = HGDIOBJ + _SelectObject.errcheck = RaiseIfZero + return _SelectObject(hdc, hgdiobj) + +# HGDIOBJ GetStockObject( +# __in int fnObject +# ); +def GetStockObject(fnObject): + _GetStockObject = windll.gdi32.GetStockObject + _GetStockObject.argtypes = [ctypes.c_int] + _GetStockObject.restype = HGDIOBJ + _GetStockObject.errcheck = RaiseIfZero + return _GetStockObject(fnObject) + +# DWORD GetObjectType( +# __in HGDIOBJ h +# ); +def GetObjectType(h): + _GetObjectType = windll.gdi32.GetObjectType + _GetObjectType.argtypes = [HGDIOBJ] + _GetObjectType.restype = DWORD + _GetObjectType.errcheck = RaiseIfZero + return _GetObjectType(h) + +# int GetObject( +# __in HGDIOBJ hgdiobj, +# __in int cbBuffer, +# __out LPVOID lpvObject +# ); +def GetObject(hgdiobj, cbBuffer = None, lpvObject = None): + _GetObject = windll.gdi32.GetObject + _GetObject.argtypes = [HGDIOBJ, ctypes.c_int, LPVOID] + _GetObject.restype = ctypes.c_int + _GetObject.errcheck = RaiseIfZero + + # Both cbBuffer and lpvObject can be omitted, the correct + # size and structure to return are automatically deduced. + # If lpvObject is given it must be a ctypes object, not a pointer. + # Always returns a ctypes object. + + if cbBuffer is not None: + if lpvObject is None: + lpvObject = ctypes.create_string_buffer("", cbBuffer) + elif lpvObject is not None: + cbBuffer = sizeof(lpvObject) + else: # most likely case, both are None + t = GetObjectType(hgdiobj) + if t == OBJ_PEN: + cbBuffer = sizeof(LOGPEN) + lpvObject = LOGPEN() + elif t == OBJ_BRUSH: + cbBuffer = sizeof(LOGBRUSH) + lpvObject = LOGBRUSH() + elif t == OBJ_PAL: + cbBuffer = _GetObject(hgdiobj, 0, None) + lpvObject = (WORD * (cbBuffer // sizeof(WORD)))() + elif t == OBJ_FONT: + cbBuffer = sizeof(LOGFONT) + lpvObject = LOGFONT() + elif t == OBJ_BITMAP: # try the two possible types of bitmap + cbBuffer = sizeof(DIBSECTION) + lpvObject = DIBSECTION() + try: + _GetObject(hgdiobj, cbBuffer, byref(lpvObject)) + return lpvObject + except WindowsError: + cbBuffer = sizeof(BITMAP) + lpvObject = BITMAP() + elif t == OBJ_EXTPEN: + cbBuffer = sizeof(LOGEXTPEN) + lpvObject = LOGEXTPEN() + else: + cbBuffer = _GetObject(hgdiobj, 0, None) + lpvObject = ctypes.create_string_buffer("", cbBuffer) + _GetObject(hgdiobj, cbBuffer, byref(lpvObject)) + return lpvObject + +# LONG GetBitmapBits( +# __in HBITMAP hbmp, +# __in LONG cbBuffer, +# __out LPVOID lpvBits +# ); +def GetBitmapBits(hbmp): + _GetBitmapBits = windll.gdi32.GetBitmapBits + _GetBitmapBits.argtypes = [HBITMAP, LONG, LPVOID] + _GetBitmapBits.restype = LONG + _GetBitmapBits.errcheck = RaiseIfZero + + bitmap = GetObject(hbmp, lpvObject = BITMAP()) + cbBuffer = bitmap.bmWidthBytes * bitmap.bmHeight + lpvBits = ctypes.create_string_buffer("", cbBuffer) + _GetBitmapBits(hbmp, cbBuffer, byref(lpvBits)) + return lpvBits.raw + +# HBITMAP CreateBitmapIndirect( +# __in const BITMAP *lpbm +# ); +def CreateBitmapIndirect(lpbm): + _CreateBitmapIndirect = windll.gdi32.CreateBitmapIndirect + _CreateBitmapIndirect.argtypes = [PBITMAP] + _CreateBitmapIndirect.restype = HBITMAP + _CreateBitmapIndirect.errcheck = RaiseIfZero + return _CreateBitmapIndirect(lpbm) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/kernel32.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/kernel32.py new file mode 100644 index 0000000..d0c0468 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/kernel32.py @@ -0,0 +1,4716 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for kernel32.dll in ctypes. +""" + +__revision__ = "$Id$" + +import warnings + +from winappdbg.win32.defines import * + +from winappdbg.win32 import context_i386 +from winappdbg.win32 import context_amd64 + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +_all.add('version') +#============================================================================== + +from winappdbg.win32.version import * + +#------------------------------------------------------------------------------ + +# This can't be defined in defines.py because it calls GetLastError(). +def RaiseIfLastError(result, func = None, arguments = ()): + """ + Error checking for Win32 API calls with no error-specific return value. + + Regardless of the return value, the function calls GetLastError(). If the + code is not C{ERROR_SUCCESS} then a C{WindowsError} exception is raised. + + For this to work, the user MUST call SetLastError(ERROR_SUCCESS) prior to + calling the API. Otherwise an exception may be raised even on success, + since most API calls don't clear the error status code. + """ + code = GetLastError() + if code != ERROR_SUCCESS: + raise ctypes.WinError(code) + return result + +#--- CONTEXT structure and constants ------------------------------------------ + +ContextArchMask = 0x0FFF0000 # just guessing here! seems to work, though + +if arch == ARCH_I386: + from winappdbg.win32.context_i386 import * +elif arch == ARCH_AMD64: + if bits == 64: + from winappdbg.win32.context_amd64 import * + else: + from winappdbg.win32.context_i386 import * +else: + warnings.warn("Unknown or unsupported architecture: %s" % arch) + +#--- Constants ---------------------------------------------------------------- + +STILL_ACTIVE = 259 + +WAIT_TIMEOUT = 0x102 +WAIT_FAILED = -1 +WAIT_OBJECT_0 = 0 + +EXCEPTION_NONCONTINUABLE = 0x1 # Noncontinuable exception +EXCEPTION_MAXIMUM_PARAMETERS = 15 # maximum number of exception parameters +MAXIMUM_WAIT_OBJECTS = 64 # Maximum number of wait objects +MAXIMUM_SUSPEND_COUNT = 0x7f # Maximum times thread can be suspended + +FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100 +FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 + +GR_GDIOBJECTS = 0 +GR_USEROBJECTS = 1 + +PROCESS_NAME_NATIVE = 1 + +MAXINTATOM = 0xC000 + +STD_INPUT_HANDLE = 0xFFFFFFF6 # (DWORD)-10 +STD_OUTPUT_HANDLE = 0xFFFFFFF5 # (DWORD)-11 +STD_ERROR_HANDLE = 0xFFFFFFF4 # (DWORD)-12 + +ATTACH_PARENT_PROCESS = 0xFFFFFFFF # (DWORD)-1 + +# LoadLibraryEx constants +DONT_RESOLVE_DLL_REFERENCES = 0x00000001 +LOAD_LIBRARY_AS_DATAFILE = 0x00000002 +LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008 +LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010 +LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020 +LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040 + +# SetSearchPathMode flags +# TODO I couldn't find these constants :( +##BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE = ??? +##BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE = ??? +##BASE_SEARCH_PATH_PERMANENT = ??? + +# Console control events +CTRL_C_EVENT = 0 +CTRL_BREAK_EVENT = 1 +CTRL_CLOSE_EVENT = 2 +CTRL_LOGOFF_EVENT = 5 +CTRL_SHUTDOWN_EVENT = 6 + +# Heap flags +HEAP_NO_SERIALIZE = 0x00000001 +HEAP_GENERATE_EXCEPTIONS = 0x00000004 +HEAP_ZERO_MEMORY = 0x00000008 +HEAP_CREATE_ENABLE_EXECUTE = 0x00040000 + +# Standard access rights +DELETE = long(0x00010000) +READ_CONTROL = long(0x00020000) +WRITE_DAC = long(0x00040000) +WRITE_OWNER = long(0x00080000) +SYNCHRONIZE = long(0x00100000) +STANDARD_RIGHTS_REQUIRED = long(0x000F0000) +STANDARD_RIGHTS_READ = (READ_CONTROL) +STANDARD_RIGHTS_WRITE = (READ_CONTROL) +STANDARD_RIGHTS_EXECUTE = (READ_CONTROL) +STANDARD_RIGHTS_ALL = long(0x001F0000) +SPECIFIC_RIGHTS_ALL = long(0x0000FFFF) + +# Mutex access rights +MUTEX_ALL_ACCESS = 0x1F0001 +MUTEX_MODIFY_STATE = 1 + +# Event access rights +EVENT_ALL_ACCESS = 0x1F0003 +EVENT_MODIFY_STATE = 2 + +# Semaphore access rights +SEMAPHORE_ALL_ACCESS = 0x1F0003 +SEMAPHORE_MODIFY_STATE = 2 + +# Timer access rights +TIMER_ALL_ACCESS = 0x1F0003 +TIMER_MODIFY_STATE = 2 +TIMER_QUERY_STATE = 1 + +# Process access rights for OpenProcess +PROCESS_TERMINATE = 0x0001 +PROCESS_CREATE_THREAD = 0x0002 +PROCESS_SET_SESSIONID = 0x0004 +PROCESS_VM_OPERATION = 0x0008 +PROCESS_VM_READ = 0x0010 +PROCESS_VM_WRITE = 0x0020 +PROCESS_DUP_HANDLE = 0x0040 +PROCESS_CREATE_PROCESS = 0x0080 +PROCESS_SET_QUOTA = 0x0100 +PROCESS_SET_INFORMATION = 0x0200 +PROCESS_QUERY_INFORMATION = 0x0400 +PROCESS_SUSPEND_RESUME = 0x0800 +PROCESS_QUERY_LIMITED_INFORMATION = 0x1000 + +# Thread access rights for OpenThread +THREAD_TERMINATE = 0x0001 +THREAD_SUSPEND_RESUME = 0x0002 +THREAD_ALERT = 0x0004 +THREAD_GET_CONTEXT = 0x0008 +THREAD_SET_CONTEXT = 0x0010 +THREAD_SET_INFORMATION = 0x0020 +THREAD_QUERY_INFORMATION = 0x0040 +THREAD_SET_THREAD_TOKEN = 0x0080 +THREAD_IMPERSONATE = 0x0100 +THREAD_DIRECT_IMPERSONATION = 0x0200 +THREAD_SET_LIMITED_INFORMATION = 0x0400 +THREAD_QUERY_LIMITED_INFORMATION = 0x0800 + +# The values of PROCESS_ALL_ACCESS and THREAD_ALL_ACCESS were changed in Vista/2008 +PROCESS_ALL_ACCESS_NT = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF) +PROCESS_ALL_ACCESS_VISTA = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFFF) +THREAD_ALL_ACCESS_NT = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3FF) +THREAD_ALL_ACCESS_VISTA = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFFF) +if NTDDI_VERSION < NTDDI_VISTA: + PROCESS_ALL_ACCESS = PROCESS_ALL_ACCESS_NT + THREAD_ALL_ACCESS = THREAD_ALL_ACCESS_NT +else: + PROCESS_ALL_ACCESS = PROCESS_ALL_ACCESS_VISTA + THREAD_ALL_ACCESS = THREAD_ALL_ACCESS_VISTA + +# Process priority classes + +IDLE_PRIORITY_CLASS = 0x00000040 +BELOW_NORMAL_PRIORITY_CLASS = 0x00004000 +NORMAL_PRIORITY_CLASS = 0x00000020 +ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000 +HIGH_PRIORITY_CLASS = 0x00000080 +REALTIME_PRIORITY_CLASS = 0x00000100 + +PROCESS_MODE_BACKGROUND_BEGIN = 0x00100000 +PROCESS_MODE_BACKGROUND_END = 0x00200000 + +# dwCreationFlag values + +DEBUG_PROCESS = 0x00000001 +DEBUG_ONLY_THIS_PROCESS = 0x00000002 +CREATE_SUSPENDED = 0x00000004 # Threads and processes +DETACHED_PROCESS = 0x00000008 +CREATE_NEW_CONSOLE = 0x00000010 +NORMAL_PRIORITY_CLASS = 0x00000020 +IDLE_PRIORITY_CLASS = 0x00000040 +HIGH_PRIORITY_CLASS = 0x00000080 +REALTIME_PRIORITY_CLASS = 0x00000100 +CREATE_NEW_PROCESS_GROUP = 0x00000200 +CREATE_UNICODE_ENVIRONMENT = 0x00000400 +CREATE_SEPARATE_WOW_VDM = 0x00000800 +CREATE_SHARED_WOW_VDM = 0x00001000 +CREATE_FORCEDOS = 0x00002000 +BELOW_NORMAL_PRIORITY_CLASS = 0x00004000 +ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000 +INHERIT_PARENT_AFFINITY = 0x00010000 +STACK_SIZE_PARAM_IS_A_RESERVATION = 0x00010000 # Threads only +INHERIT_CALLER_PRIORITY = 0x00020000 # Deprecated +CREATE_PROTECTED_PROCESS = 0x00040000 +EXTENDED_STARTUPINFO_PRESENT = 0x00080000 +PROCESS_MODE_BACKGROUND_BEGIN = 0x00100000 +PROCESS_MODE_BACKGROUND_END = 0x00200000 +CREATE_BREAKAWAY_FROM_JOB = 0x01000000 +CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000 +CREATE_DEFAULT_ERROR_MODE = 0x04000000 +CREATE_NO_WINDOW = 0x08000000 +PROFILE_USER = 0x10000000 +PROFILE_KERNEL = 0x20000000 +PROFILE_SERVER = 0x40000000 +CREATE_IGNORE_SYSTEM_DEFAULT = 0x80000000 + +# Thread priority values + +THREAD_BASE_PRIORITY_LOWRT = 15 # value that gets a thread to LowRealtime-1 +THREAD_BASE_PRIORITY_MAX = 2 # maximum thread base priority boost +THREAD_BASE_PRIORITY_MIN = (-2) # minimum thread base priority boost +THREAD_BASE_PRIORITY_IDLE = (-15) # value that gets a thread to idle + +THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN +THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST+1) +THREAD_PRIORITY_NORMAL = 0 +THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX +THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST-1) +THREAD_PRIORITY_ERROR_RETURN = long(0xFFFFFFFF) + +THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT +THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE + +# Memory access +SECTION_QUERY = 0x0001 +SECTION_MAP_WRITE = 0x0002 +SECTION_MAP_READ = 0x0004 +SECTION_MAP_EXECUTE = 0x0008 +SECTION_EXTEND_SIZE = 0x0010 +SECTION_MAP_EXECUTE_EXPLICIT = 0x0020 # not included in SECTION_ALL_ACCESS + +SECTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\ + SECTION_MAP_WRITE | \ + SECTION_MAP_READ | \ + SECTION_MAP_EXECUTE | \ + SECTION_EXTEND_SIZE) +PAGE_NOACCESS = 0x01 +PAGE_READONLY = 0x02 +PAGE_READWRITE = 0x04 +PAGE_WRITECOPY = 0x08 +PAGE_EXECUTE = 0x10 +PAGE_EXECUTE_READ = 0x20 +PAGE_EXECUTE_READWRITE = 0x40 +PAGE_EXECUTE_WRITECOPY = 0x80 +PAGE_GUARD = 0x100 +PAGE_NOCACHE = 0x200 +PAGE_WRITECOMBINE = 0x400 +MEM_COMMIT = 0x1000 +MEM_RESERVE = 0x2000 +MEM_DECOMMIT = 0x4000 +MEM_RELEASE = 0x8000 +MEM_FREE = 0x10000 +MEM_PRIVATE = 0x20000 +MEM_MAPPED = 0x40000 +MEM_RESET = 0x80000 +MEM_TOP_DOWN = 0x100000 +MEM_WRITE_WATCH = 0x200000 +MEM_PHYSICAL = 0x400000 +MEM_LARGE_PAGES = 0x20000000 +MEM_4MB_PAGES = 0x80000000 +SEC_FILE = 0x800000 +SEC_IMAGE = 0x1000000 +SEC_RESERVE = 0x4000000 +SEC_COMMIT = 0x8000000 +SEC_NOCACHE = 0x10000000 +SEC_LARGE_PAGES = 0x80000000 +MEM_IMAGE = SEC_IMAGE +WRITE_WATCH_FLAG_RESET = 0x01 +FILE_MAP_ALL_ACCESS = 0xF001F + +SECTION_QUERY = 0x0001 +SECTION_MAP_WRITE = 0x0002 +SECTION_MAP_READ = 0x0004 +SECTION_MAP_EXECUTE = 0x0008 +SECTION_EXTEND_SIZE = 0x0010 +SECTION_MAP_EXECUTE_EXPLICIT = 0x0020 # not included in SECTION_ALL_ACCESS + +SECTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\ + SECTION_MAP_WRITE | \ + SECTION_MAP_READ | \ + SECTION_MAP_EXECUTE | \ + SECTION_EXTEND_SIZE) + +FILE_MAP_COPY = SECTION_QUERY +FILE_MAP_WRITE = SECTION_MAP_WRITE +FILE_MAP_READ = SECTION_MAP_READ +FILE_MAP_ALL_ACCESS = SECTION_ALL_ACCESS +FILE_MAP_EXECUTE = SECTION_MAP_EXECUTE_EXPLICIT # not included in FILE_MAP_ALL_ACCESS + +GENERIC_READ = 0x80000000 +GENERIC_WRITE = 0x40000000 +GENERIC_EXECUTE = 0x20000000 +GENERIC_ALL = 0x10000000 + +FILE_SHARE_READ = 0x00000001 +FILE_SHARE_WRITE = 0x00000002 +FILE_SHARE_DELETE = 0x00000004 + +CREATE_NEW = 1 +CREATE_ALWAYS = 2 +OPEN_EXISTING = 3 +OPEN_ALWAYS = 4 +TRUNCATE_EXISTING = 5 + +FILE_ATTRIBUTE_READONLY = 0x00000001 +FILE_ATTRIBUTE_NORMAL = 0x00000080 +FILE_ATTRIBUTE_TEMPORARY = 0x00000100 + +FILE_FLAG_WRITE_THROUGH = 0x80000000 +FILE_FLAG_NO_BUFFERING = 0x20000000 +FILE_FLAG_RANDOM_ACCESS = 0x10000000 +FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000 +FILE_FLAG_DELETE_ON_CLOSE = 0x04000000 +FILE_FLAG_OVERLAPPED = 0x40000000 + +FILE_ATTRIBUTE_READONLY = 0x00000001 +FILE_ATTRIBUTE_HIDDEN = 0x00000002 +FILE_ATTRIBUTE_SYSTEM = 0x00000004 +FILE_ATTRIBUTE_DIRECTORY = 0x00000010 +FILE_ATTRIBUTE_ARCHIVE = 0x00000020 +FILE_ATTRIBUTE_DEVICE = 0x00000040 +FILE_ATTRIBUTE_NORMAL = 0x00000080 +FILE_ATTRIBUTE_TEMPORARY = 0x00000100 + +# Debug events +EXCEPTION_DEBUG_EVENT = 1 +CREATE_THREAD_DEBUG_EVENT = 2 +CREATE_PROCESS_DEBUG_EVENT = 3 +EXIT_THREAD_DEBUG_EVENT = 4 +EXIT_PROCESS_DEBUG_EVENT = 5 +LOAD_DLL_DEBUG_EVENT = 6 +UNLOAD_DLL_DEBUG_EVENT = 7 +OUTPUT_DEBUG_STRING_EVENT = 8 +RIP_EVENT = 9 + +# Debug status codes (ContinueDebugEvent) +DBG_EXCEPTION_HANDLED = long(0x00010001) +DBG_CONTINUE = long(0x00010002) +DBG_REPLY_LATER = long(0x40010001) +DBG_UNABLE_TO_PROVIDE_HANDLE = long(0x40010002) +DBG_TERMINATE_THREAD = long(0x40010003) +DBG_TERMINATE_PROCESS = long(0x40010004) +DBG_CONTROL_C = long(0x40010005) +DBG_PRINTEXCEPTION_C = long(0x40010006) +DBG_RIPEXCEPTION = long(0x40010007) +DBG_CONTROL_BREAK = long(0x40010008) +DBG_COMMAND_EXCEPTION = long(0x40010009) +DBG_EXCEPTION_NOT_HANDLED = long(0x80010001) +DBG_NO_STATE_CHANGE = long(0xC0010001) +DBG_APP_NOT_IDLE = long(0xC0010002) + +# Status codes +STATUS_WAIT_0 = long(0x00000000) +STATUS_ABANDONED_WAIT_0 = long(0x00000080) +STATUS_USER_APC = long(0x000000C0) +STATUS_TIMEOUT = long(0x00000102) +STATUS_PENDING = long(0x00000103) +STATUS_SEGMENT_NOTIFICATION = long(0x40000005) +STATUS_GUARD_PAGE_VIOLATION = long(0x80000001) +STATUS_DATATYPE_MISALIGNMENT = long(0x80000002) +STATUS_BREAKPOINT = long(0x80000003) +STATUS_SINGLE_STEP = long(0x80000004) +STATUS_INVALID_INFO_CLASS = long(0xC0000003) +STATUS_ACCESS_VIOLATION = long(0xC0000005) +STATUS_IN_PAGE_ERROR = long(0xC0000006) +STATUS_INVALID_HANDLE = long(0xC0000008) +STATUS_NO_MEMORY = long(0xC0000017) +STATUS_ILLEGAL_INSTRUCTION = long(0xC000001D) +STATUS_NONCONTINUABLE_EXCEPTION = long(0xC0000025) +STATUS_INVALID_DISPOSITION = long(0xC0000026) +STATUS_ARRAY_BOUNDS_EXCEEDED = long(0xC000008C) +STATUS_FLOAT_DENORMAL_OPERAND = long(0xC000008D) +STATUS_FLOAT_DIVIDE_BY_ZERO = long(0xC000008E) +STATUS_FLOAT_INEXACT_RESULT = long(0xC000008F) +STATUS_FLOAT_INVALID_OPERATION = long(0xC0000090) +STATUS_FLOAT_OVERFLOW = long(0xC0000091) +STATUS_FLOAT_STACK_CHECK = long(0xC0000092) +STATUS_FLOAT_UNDERFLOW = long(0xC0000093) +STATUS_INTEGER_DIVIDE_BY_ZERO = long(0xC0000094) +STATUS_INTEGER_OVERFLOW = long(0xC0000095) +STATUS_PRIVILEGED_INSTRUCTION = long(0xC0000096) +STATUS_STACK_OVERFLOW = long(0xC00000FD) +STATUS_CONTROL_C_EXIT = long(0xC000013A) +STATUS_FLOAT_MULTIPLE_FAULTS = long(0xC00002B4) +STATUS_FLOAT_MULTIPLE_TRAPS = long(0xC00002B5) +STATUS_REG_NAT_CONSUMPTION = long(0xC00002C9) +STATUS_SXS_EARLY_DEACTIVATION = long(0xC015000F) +STATUS_SXS_INVALID_DEACTIVATION = long(0xC0150010) + +STATUS_STACK_BUFFER_OVERRUN = long(0xC0000409) +STATUS_WX86_BREAKPOINT = long(0x4000001F) +STATUS_HEAP_CORRUPTION = long(0xC0000374) + +STATUS_POSSIBLE_DEADLOCK = long(0xC0000194) + +STATUS_UNWIND_CONSOLIDATE = long(0x80000029) + +# Exception codes + +EXCEPTION_ACCESS_VIOLATION = STATUS_ACCESS_VIOLATION +EXCEPTION_ARRAY_BOUNDS_EXCEEDED = STATUS_ARRAY_BOUNDS_EXCEEDED +EXCEPTION_BREAKPOINT = STATUS_BREAKPOINT +EXCEPTION_DATATYPE_MISALIGNMENT = STATUS_DATATYPE_MISALIGNMENT +EXCEPTION_FLT_DENORMAL_OPERAND = STATUS_FLOAT_DENORMAL_OPERAND +EXCEPTION_FLT_DIVIDE_BY_ZERO = STATUS_FLOAT_DIVIDE_BY_ZERO +EXCEPTION_FLT_INEXACT_RESULT = STATUS_FLOAT_INEXACT_RESULT +EXCEPTION_FLT_INVALID_OPERATION = STATUS_FLOAT_INVALID_OPERATION +EXCEPTION_FLT_OVERFLOW = STATUS_FLOAT_OVERFLOW +EXCEPTION_FLT_STACK_CHECK = STATUS_FLOAT_STACK_CHECK +EXCEPTION_FLT_UNDERFLOW = STATUS_FLOAT_UNDERFLOW +EXCEPTION_ILLEGAL_INSTRUCTION = STATUS_ILLEGAL_INSTRUCTION +EXCEPTION_IN_PAGE_ERROR = STATUS_IN_PAGE_ERROR +EXCEPTION_INT_DIVIDE_BY_ZERO = STATUS_INTEGER_DIVIDE_BY_ZERO +EXCEPTION_INT_OVERFLOW = STATUS_INTEGER_OVERFLOW +EXCEPTION_INVALID_DISPOSITION = STATUS_INVALID_DISPOSITION +EXCEPTION_NONCONTINUABLE_EXCEPTION = STATUS_NONCONTINUABLE_EXCEPTION +EXCEPTION_PRIV_INSTRUCTION = STATUS_PRIVILEGED_INSTRUCTION +EXCEPTION_SINGLE_STEP = STATUS_SINGLE_STEP +EXCEPTION_STACK_OVERFLOW = STATUS_STACK_OVERFLOW + +EXCEPTION_GUARD_PAGE = STATUS_GUARD_PAGE_VIOLATION +EXCEPTION_INVALID_HANDLE = STATUS_INVALID_HANDLE +EXCEPTION_POSSIBLE_DEADLOCK = STATUS_POSSIBLE_DEADLOCK +EXCEPTION_WX86_BREAKPOINT = STATUS_WX86_BREAKPOINT + +CONTROL_C_EXIT = STATUS_CONTROL_C_EXIT + +DBG_CONTROL_C = long(0x40010005) +MS_VC_EXCEPTION = long(0x406D1388) + +# Access violation types +ACCESS_VIOLATION_TYPE_READ = EXCEPTION_READ_FAULT +ACCESS_VIOLATION_TYPE_WRITE = EXCEPTION_WRITE_FAULT +ACCESS_VIOLATION_TYPE_DEP = EXCEPTION_EXECUTE_FAULT + +# RIP event types +SLE_ERROR = 1 +SLE_MINORERROR = 2 +SLE_WARNING = 3 + +# DuplicateHandle constants +DUPLICATE_CLOSE_SOURCE = 0x00000001 +DUPLICATE_SAME_ACCESS = 0x00000002 + +# GetFinalPathNameByHandle constants +FILE_NAME_NORMALIZED = 0x0 +FILE_NAME_OPENED = 0x8 +VOLUME_NAME_DOS = 0x0 +VOLUME_NAME_GUID = 0x1 +VOLUME_NAME_NONE = 0x4 +VOLUME_NAME_NT = 0x2 + +# GetProductInfo constants +PRODUCT_BUSINESS = 0x00000006 +PRODUCT_BUSINESS_N = 0x00000010 +PRODUCT_CLUSTER_SERVER = 0x00000012 +PRODUCT_DATACENTER_SERVER = 0x00000008 +PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C +PRODUCT_DATACENTER_SERVER_CORE_V = 0x00000027 +PRODUCT_DATACENTER_SERVER_V = 0x00000025 +PRODUCT_ENTERPRISE = 0x00000004 +PRODUCT_ENTERPRISE_E = 0x00000046 +PRODUCT_ENTERPRISE_N = 0x0000001B +PRODUCT_ENTERPRISE_SERVER = 0x0000000A +PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E +PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029 +PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F +PRODUCT_ENTERPRISE_SERVER_V = 0x00000026 +PRODUCT_HOME_BASIC = 0x00000002 +PRODUCT_HOME_BASIC_E = 0x00000043 +PRODUCT_HOME_BASIC_N = 0x00000005 +PRODUCT_HOME_PREMIUM = 0x00000003 +PRODUCT_HOME_PREMIUM_E = 0x00000044 +PRODUCT_HOME_PREMIUM_N = 0x0000001A +PRODUCT_HYPERV = 0x0000002A +PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E +PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020 +PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F +PRODUCT_PROFESSIONAL = 0x00000030 +PRODUCT_PROFESSIONAL_E = 0x00000045 +PRODUCT_PROFESSIONAL_N = 0x00000031 +PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018 +PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023 +PRODUCT_SERVER_FOUNDATION = 0x00000021 +PRODUCT_SMALLBUSINESS_SERVER = 0x00000009 +PRODUCT_STANDARD_SERVER = 0x00000007 +PRODUCT_STANDARD_SERVER_CORE = 0x0000000D +PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028 +PRODUCT_STANDARD_SERVER_V = 0x00000024 +PRODUCT_STARTER = 0x0000000B +PRODUCT_STARTER_E = 0x00000042 +PRODUCT_STARTER_N = 0x0000002F +PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017 +PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014 +PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015 +PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016 +PRODUCT_UNDEFINED = 0x00000000 +PRODUCT_UNLICENSED = 0xABCDABCD +PRODUCT_ULTIMATE = 0x00000001 +PRODUCT_ULTIMATE_E = 0x00000047 +PRODUCT_ULTIMATE_N = 0x0000001C +PRODUCT_WEB_SERVER = 0x00000011 +PRODUCT_WEB_SERVER_CORE = 0x0000001D + +# DEP policy flags +PROCESS_DEP_ENABLE = 1 +PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION = 2 + +# Error modes +SEM_FAILCRITICALERRORS = 0x001 +SEM_NOGPFAULTERRORBOX = 0x002 +SEM_NOALIGNMENTFAULTEXCEPT = 0x004 +SEM_NOOPENFILEERRORBOX = 0x800 + +# GetHandleInformation / SetHandleInformation +HANDLE_FLAG_INHERIT = 0x00000001 +HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002 + +#--- Handle wrappers ---------------------------------------------------------- + +class Handle (object): + """ + Encapsulates Win32 handles to avoid leaking them. + + @type inherit: bool + @ivar inherit: C{True} if the handle is to be inherited by child processes, + C{False} otherwise. + + @type protectFromClose: bool + @ivar protectFromClose: Set to C{True} to prevent the handle from being + closed. Must be set to C{False} before you're done using the handle, + or it will be left open until the debugger exits. Use with care! + + @see: + L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle} + """ + + # XXX DEBUG + # When this private flag is True each Handle will print a message to + # standard output when it's created and destroyed. This is useful for + # detecting handle leaks within WinAppDbg itself. + __bLeakDetection = False + + def __init__(self, aHandle = None, bOwnership = True): + """ + @type aHandle: int + @param aHandle: Win32 handle value. + + @type bOwnership: bool + @param bOwnership: + C{True} if we own the handle and we need to close it. + C{False} if someone else will be calling L{CloseHandle}. + """ + super(Handle, self).__init__() + self._value = self._normalize(aHandle) + self.bOwnership = bOwnership + if Handle.__bLeakDetection: # XXX DEBUG + print("INIT HANDLE (%r) %r" % (self.value, self)) + + @property + def value(self): + return self._value + + def __del__(self): + """ + Closes the Win32 handle when the Python object is destroyed. + """ + try: + if Handle.__bLeakDetection: # XXX DEBUG + print("DEL HANDLE %r" % self) + self.close() + except Exception: + pass + + def __enter__(self): + """ + Compatibility with the "C{with}" Python statement. + """ + if Handle.__bLeakDetection: # XXX DEBUG + print("ENTER HANDLE %r" % self) + return self + + def __exit__(self, type, value, traceback): + """ + Compatibility with the "C{with}" Python statement. + """ + if Handle.__bLeakDetection: # XXX DEBUG + print("EXIT HANDLE %r" % self) + try: + self.close() + except Exception: + pass + + def __copy__(self): + """ + Duplicates the Win32 handle when copying the Python object. + + @rtype: L{Handle} + @return: A new handle to the same Win32 object. + """ + return self.dup() + + def __deepcopy__(self): + """ + Duplicates the Win32 handle when copying the Python object. + + @rtype: L{Handle} + @return: A new handle to the same win32 object. + """ + return self.dup() + + @property + def _as_parameter_(self): + """ + Compatibility with ctypes. + Allows passing transparently a Handle object to an API call. + """ + return HANDLE(self.value) + + @staticmethod + def from_param(value): + """ + Compatibility with ctypes. + Allows passing transparently a Handle object to an API call. + + @type value: int + @param value: Numeric handle value. + """ + return HANDLE(value) + + def close(self): + """ + Closes the Win32 handle. + """ + if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE): + if Handle.__bLeakDetection: # XXX DEBUG + print("CLOSE HANDLE (%d) %r" % (self.value, self)) + try: + self._close() + finally: + self._value = None + + def _close(self): + """ + Low-level close method. + This is a private method, do not call it. + """ + CloseHandle(self.value) + + def dup(self): + """ + @rtype: L{Handle} + @return: A new handle to the same Win32 object. + """ + if self.value is None: + raise ValueError("Closed handles can't be duplicated!") + new_handle = DuplicateHandle(self.value) + if Handle.__bLeakDetection: # XXX DEBUG + print("DUP HANDLE (%d -> %d) %r %r" % \ + (self.value, new_handle.value, self, new_handle)) + return new_handle + + @staticmethod + def _normalize(value): + """ + Normalize handle values. + """ + if hasattr(value, 'value'): + value = value.value + if value is not None: + value = long(value) + return value + + def wait(self, dwMilliseconds = None): + """ + Wait for the Win32 object to be signaled. + + @type dwMilliseconds: int + @param dwMilliseconds: (Optional) Timeout value in milliseconds. + Use C{INFINITE} or C{None} for no timeout. + """ + if self.value is None: + raise ValueError("Handle is already closed!") + if dwMilliseconds is None: + dwMilliseconds = INFINITE + r = WaitForSingleObject(self.value, dwMilliseconds) + if r != WAIT_OBJECT_0: + raise ctypes.WinError(r) + + def __repr__(self): + return '<%s: %s>' % (self.__class__.__name__, self.value) + + def __get_inherit(self): + if self.value is None: + raise ValueError("Handle is already closed!") + return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT ) + + def __set_inherit(self, value): + if self.value is None: + raise ValueError("Handle is already closed!") + flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ] + SetHandleInformation(self.value, flag, flag) + + inherit = property(__get_inherit, __set_inherit) + + def __get_protectFromClose(self): + if self.value is None: + raise ValueError("Handle is already closed!") + return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE ) + + def __set_protectFromClose(self, value): + if self.value is None: + raise ValueError("Handle is already closed!") + flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ] + SetHandleInformation(self.value, flag, flag) + + protectFromClose = property(__get_protectFromClose, __set_protectFromClose) + +class UserModeHandle (Handle): + """ + Base class for non-kernel handles. Generally this means they are closed + by special Win32 API functions instead of CloseHandle() and some standard + operations (synchronizing, duplicating, inheritance) are not supported. + + @type _TYPE: C type + @cvar _TYPE: C type to translate this handle to. + Subclasses should override this. + Defaults to L{HANDLE}. + """ + + # Subclasses should override this. + _TYPE = HANDLE + + # This method must be implemented by subclasses. + def _close(self): + raise NotImplementedError() + + # Translation to C type. + @property + def _as_parameter_(self): + return self._TYPE(self.value) + + # Translation to C type. + @staticmethod + def from_param(value): + return self._TYPE(self.value) + + # Operation not supported. + @property + def inherit(self): + return False + + # Operation not supported. + @property + def protectFromClose(self): + return False + + # Operation not supported. + def dup(self): + raise NotImplementedError() + + # Operation not supported. + def wait(self, dwMilliseconds = None): + raise NotImplementedError() + +class ProcessHandle (Handle): + """ + Win32 process handle. + + @type dwAccess: int + @ivar dwAccess: Current access flags to this handle. + This is the same value passed to L{OpenProcess}. + Can only be C{None} if C{aHandle} is also C{None}. + Defaults to L{PROCESS_ALL_ACCESS}. + + @see: L{Handle} + """ + + def __init__(self, aHandle = None, bOwnership = True, + dwAccess = PROCESS_ALL_ACCESS): + """ + @type aHandle: int + @param aHandle: Win32 handle value. + + @type bOwnership: bool + @param bOwnership: + C{True} if we own the handle and we need to close it. + C{False} if someone else will be calling L{CloseHandle}. + + @type dwAccess: int + @param dwAccess: Current access flags to this handle. + This is the same value passed to L{OpenProcess}. + Can only be C{None} if C{aHandle} is also C{None}. + Defaults to L{PROCESS_ALL_ACCESS}. + """ + super(ProcessHandle, self).__init__(aHandle, bOwnership) + self.dwAccess = dwAccess + if aHandle is not None and dwAccess is None: + msg = "Missing access flags for process handle: %x" % aHandle + raise TypeError(msg) + + def get_pid(self): + """ + @rtype: int + @return: Process global ID. + """ + return GetProcessId(self.value) + +class ThreadHandle (Handle): + """ + Win32 thread handle. + + @type dwAccess: int + @ivar dwAccess: Current access flags to this handle. + This is the same value passed to L{OpenThread}. + Can only be C{None} if C{aHandle} is also C{None}. + Defaults to L{THREAD_ALL_ACCESS}. + + @see: L{Handle} + """ + + def __init__(self, aHandle = None, bOwnership = True, + dwAccess = THREAD_ALL_ACCESS): + """ + @type aHandle: int + @param aHandle: Win32 handle value. + + @type bOwnership: bool + @param bOwnership: + C{True} if we own the handle and we need to close it. + C{False} if someone else will be calling L{CloseHandle}. + + @type dwAccess: int + @param dwAccess: Current access flags to this handle. + This is the same value passed to L{OpenThread}. + Can only be C{None} if C{aHandle} is also C{None}. + Defaults to L{THREAD_ALL_ACCESS}. + """ + super(ThreadHandle, self).__init__(aHandle, bOwnership) + self.dwAccess = dwAccess + if aHandle is not None and dwAccess is None: + msg = "Missing access flags for thread handle: %x" % aHandle + raise TypeError(msg) + + def get_tid(self): + """ + @rtype: int + @return: Thread global ID. + """ + return GetThreadId(self.value) + +class FileHandle (Handle): + """ + Win32 file handle. + + @see: L{Handle} + """ + + def get_filename(self): + """ + @rtype: None or str + @return: Name of the open file, or C{None} if unavailable. + """ + # + # XXX BUG + # + # This code truncates the first two bytes of the path. + # It seems to be the expected behavior of NtQueryInformationFile. + # + # My guess is it only returns the NT pathname, without the device name. + # It's like dropping the drive letter in a Win32 pathname. + # + # Note that using the "official" GetFileInformationByHandleEx + # API introduced in Vista doesn't change the results! + # + dwBufferSize = 0x1004 + lpFileInformation = ctypes.create_string_buffer(dwBufferSize) + try: + GetFileInformationByHandleEx(self.value, + FILE_INFO_BY_HANDLE_CLASS.FileNameInfo, + lpFileInformation, dwBufferSize) + except AttributeError: + from winappdbg.win32.ntdll import NtQueryInformationFile, \ + FileNameInformation, \ + FILE_NAME_INFORMATION + NtQueryInformationFile(self.value, + FileNameInformation, + lpFileInformation, + dwBufferSize) + FileName = compat.unicode(lpFileInformation.raw[sizeof(DWORD):], 'U16') + FileName = ctypes.create_unicode_buffer(FileName).value + if not FileName: + FileName = None + elif FileName[1:2] != ':': + # When the drive letter is missing, we'll assume SYSTEMROOT. + # Not a good solution but it could be worse. + import os + FileName = os.environ['SYSTEMROOT'][:2] + FileName + return FileName + +class FileMappingHandle (Handle): + """ + File mapping handle. + + @see: L{Handle} + """ + pass + +# XXX maybe add functions related to the toolhelp snapshots here? +class SnapshotHandle (Handle): + """ + Toolhelp32 snapshot handle. + + @see: L{Handle} + """ + pass + +#--- Structure wrappers ------------------------------------------------------- + +class ProcessInformation (object): + """ + Process information object returned by L{CreateProcess}. + """ + + def __init__(self, pi): + self.hProcess = ProcessHandle(pi.hProcess) + self.hThread = ThreadHandle(pi.hThread) + self.dwProcessId = pi.dwProcessId + self.dwThreadId = pi.dwThreadId + +# Don't psyco-optimize this class because it needs to be serialized. +class MemoryBasicInformation (object): + """ + Memory information object returned by L{VirtualQueryEx}. + """ + + READABLE = ( + PAGE_EXECUTE_READ | + PAGE_EXECUTE_READWRITE | + PAGE_EXECUTE_WRITECOPY | + PAGE_READONLY | + PAGE_READWRITE | + PAGE_WRITECOPY + ) + + WRITEABLE = ( + PAGE_EXECUTE_READWRITE | + PAGE_EXECUTE_WRITECOPY | + PAGE_READWRITE | + PAGE_WRITECOPY + ) + + COPY_ON_WRITE = ( + PAGE_EXECUTE_WRITECOPY | + PAGE_WRITECOPY + ) + + EXECUTABLE = ( + PAGE_EXECUTE | + PAGE_EXECUTE_READ | + PAGE_EXECUTE_READWRITE | + PAGE_EXECUTE_WRITECOPY + ) + + EXECUTABLE_AND_WRITEABLE = ( + PAGE_EXECUTE_READWRITE | + PAGE_EXECUTE_WRITECOPY + ) + + def __init__(self, mbi=None): + """ + @type mbi: L{MEMORY_BASIC_INFORMATION} or L{MemoryBasicInformation} + @param mbi: Either a L{MEMORY_BASIC_INFORMATION} structure or another + L{MemoryBasicInformation} instance. + """ + if mbi is None: + self.BaseAddress = None + self.AllocationBase = None + self.AllocationProtect = None + self.RegionSize = None + self.State = None + self.Protect = None + self.Type = None + else: + self.BaseAddress = mbi.BaseAddress + self.AllocationBase = mbi.AllocationBase + self.AllocationProtect = mbi.AllocationProtect + self.RegionSize = mbi.RegionSize + self.State = mbi.State + self.Protect = mbi.Protect + self.Type = mbi.Type + + # Only used when copying MemoryBasicInformation objects, instead of + # instancing them from a MEMORY_BASIC_INFORMATION structure. + if hasattr(mbi, 'content'): + self.content = mbi.content + if hasattr(mbi, 'filename'): + self.content = mbi.filename + + def __contains__(self, address): + """ + Test if the given memory address falls within this memory region. + + @type address: int + @param address: Memory address to test. + + @rtype: bool + @return: C{True} if the given memory address falls within this memory + region, C{False} otherwise. + """ + return self.BaseAddress <= address < (self.BaseAddress + self.RegionSize) + + def is_free(self): + """ + @rtype: bool + @return: C{True} if the memory in this region is free. + """ + return self.State == MEM_FREE + + def is_reserved(self): + """ + @rtype: bool + @return: C{True} if the memory in this region is reserved. + """ + return self.State == MEM_RESERVE + + def is_commited(self): + """ + @rtype: bool + @return: C{True} if the memory in this region is commited. + """ + return self.State == MEM_COMMIT + + def is_image(self): + """ + @rtype: bool + @return: C{True} if the memory in this region belongs to an executable + image. + """ + return self.Type == MEM_IMAGE + + def is_mapped(self): + """ + @rtype: bool + @return: C{True} if the memory in this region belongs to a mapped file. + """ + return self.Type == MEM_MAPPED + + def is_private(self): + """ + @rtype: bool + @return: C{True} if the memory in this region is private. + """ + return self.Type == MEM_PRIVATE + + def is_guard(self): + """ + @rtype: bool + @return: C{True} if all pages in this region are guard pages. + """ + return self.is_commited() and bool(self.Protect & PAGE_GUARD) + + def has_content(self): + """ + @rtype: bool + @return: C{True} if the memory in this region has any data in it. + """ + return self.is_commited() and not bool(self.Protect & (PAGE_GUARD | PAGE_NOACCESS)) + + def is_readable(self): + """ + @rtype: bool + @return: C{True} if all pages in this region are readable. + """ + return self.has_content() and bool(self.Protect & self.READABLE) + + def is_writeable(self): + """ + @rtype: bool + @return: C{True} if all pages in this region are writeable. + """ + return self.has_content() and bool(self.Protect & self.WRITEABLE) + + def is_copy_on_write(self): + """ + @rtype: bool + @return: C{True} if all pages in this region are marked as + copy-on-write. This means the pages are writeable, but changes + are not propagated to disk. + @note: + Tipically data sections in executable images are marked like this. + """ + return self.has_content() and bool(self.Protect & self.COPY_ON_WRITE) + + def is_executable(self): + """ + @rtype: bool + @return: C{True} if all pages in this region are executable. + @note: Executable pages are always readable. + """ + return self.has_content() and bool(self.Protect & self.EXECUTABLE) + + def is_executable_and_writeable(self): + """ + @rtype: bool + @return: C{True} if all pages in this region are executable and + writeable. + @note: The presence of such pages make memory corruption + vulnerabilities much easier to exploit. + """ + return self.has_content() and bool(self.Protect & self.EXECUTABLE_AND_WRITEABLE) + +class ProcThreadAttributeList (object): + """ + Extended process and thread attribute support. + + To be used with L{STARTUPINFOEX}. + Only available for Windows Vista and above. + + @type AttributeList: list of tuple( int, ctypes-compatible object ) + @ivar AttributeList: List of (Attribute, Value) pairs. + + @type AttributeListBuffer: L{LPPROC_THREAD_ATTRIBUTE_LIST} + @ivar AttributeListBuffer: Memory buffer used to store the attribute list. + L{InitializeProcThreadAttributeList}, + L{UpdateProcThreadAttribute}, + L{DeleteProcThreadAttributeList} and + L{STARTUPINFOEX}. + """ + + def __init__(self, AttributeList): + """ + @type AttributeList: list of tuple( int, ctypes-compatible object ) + @param AttributeList: List of (Attribute, Value) pairs. + """ + self.AttributeList = AttributeList + self.AttributeListBuffer = InitializeProcThreadAttributeList( + len(AttributeList)) + try: + for Attribute, Value in AttributeList: + UpdateProcThreadAttribute(self.AttributeListBuffer, + Attribute, Value) + except: + ProcThreadAttributeList.__del__(self) + raise + + def __del__(self): + try: + DeleteProcThreadAttributeList(self.AttributeListBuffer) + del self.AttributeListBuffer + except Exception: + pass + + def __copy__(self): + return self.__deepcopy__() + + def __deepcopy__(self): + return self.__class__(self.AttributeList) + + @property + def value(self): + return ctypes.cast(ctypes.pointer(self.AttributeListBuffer), LPVOID) + + @property + def _as_parameter_(self): + return self.value + + # XXX TODO + @staticmethod + def from_param(value): + raise NotImplementedError() + +#--- OVERLAPPED structure ----------------------------------------------------- + +# typedef struct _OVERLAPPED { +# ULONG_PTR Internal; +# ULONG_PTR InternalHigh; +# union { +# struct { +# DWORD Offset; +# DWORD OffsetHigh; +# } ; +# PVOID Pointer; +# } ; +# HANDLE hEvent; +# }OVERLAPPED, *LPOVERLAPPED; +class _OVERLAPPED_STRUCT(Structure): + _fields_ = [ + ('Offset', DWORD), + ('OffsetHigh', DWORD), + ] +class _OVERLAPPED_UNION(Union): + _fields_ = [ + ('s', _OVERLAPPED_STRUCT), + ('Pointer', PVOID), + ] +class OVERLAPPED(Structure): + _fields_ = [ + ('Internal', ULONG_PTR), + ('InternalHigh', ULONG_PTR), + ('u', _OVERLAPPED_UNION), + ('hEvent', HANDLE), + ] +LPOVERLAPPED = POINTER(OVERLAPPED) + +#--- SECURITY_ATTRIBUTES structure -------------------------------------------- + +# typedef struct _SECURITY_ATTRIBUTES { +# DWORD nLength; +# LPVOID lpSecurityDescriptor; +# BOOL bInheritHandle; +# } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; +class SECURITY_ATTRIBUTES(Structure): + _fields_ = [ + ('nLength', DWORD), + ('lpSecurityDescriptor', LPVOID), + ('bInheritHandle', BOOL), + ] +LPSECURITY_ATTRIBUTES = POINTER(SECURITY_ATTRIBUTES) + +# --- Extended process and thread attribute support --------------------------- + +PPROC_THREAD_ATTRIBUTE_LIST = LPVOID +LPPROC_THREAD_ATTRIBUTE_LIST = PPROC_THREAD_ATTRIBUTE_LIST + +PROC_THREAD_ATTRIBUTE_NUMBER = 0x0000FFFF +PROC_THREAD_ATTRIBUTE_THREAD = 0x00010000 # Attribute may be used with thread creation +PROC_THREAD_ATTRIBUTE_INPUT = 0x00020000 # Attribute is input only +PROC_THREAD_ATTRIBUTE_ADDITIVE = 0x00040000 # Attribute may be "accumulated," e.g. bitmasks, counters, etc. + +# PROC_THREAD_ATTRIBUTE_NUM +ProcThreadAttributeParentProcess = 0 +ProcThreadAttributeExtendedFlags = 1 +ProcThreadAttributeHandleList = 2 +ProcThreadAttributeGroupAffinity = 3 +ProcThreadAttributePreferredNode = 4 +ProcThreadAttributeIdealProcessor = 5 +ProcThreadAttributeUmsThread = 6 +ProcThreadAttributeMitigationPolicy = 7 +ProcThreadAttributeMax = 8 + +PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = ProcThreadAttributeParentProcess | PROC_THREAD_ATTRIBUTE_INPUT +PROC_THREAD_ATTRIBUTE_EXTENDED_FLAGS = ProcThreadAttributeExtendedFlags | PROC_THREAD_ATTRIBUTE_INPUT | PROC_THREAD_ATTRIBUTE_ADDITIVE +PROC_THREAD_ATTRIBUTE_HANDLE_LIST = ProcThreadAttributeHandleList | PROC_THREAD_ATTRIBUTE_INPUT +PROC_THREAD_ATTRIBUTE_GROUP_AFFINITY = ProcThreadAttributeGroupAffinity | PROC_THREAD_ATTRIBUTE_THREAD | PROC_THREAD_ATTRIBUTE_INPUT +PROC_THREAD_ATTRIBUTE_PREFERRED_NODE = ProcThreadAttributePreferredNode | PROC_THREAD_ATTRIBUTE_INPUT +PROC_THREAD_ATTRIBUTE_IDEAL_PROCESSOR = ProcThreadAttributeIdealProcessor | PROC_THREAD_ATTRIBUTE_THREAD | PROC_THREAD_ATTRIBUTE_INPUT +PROC_THREAD_ATTRIBUTE_UMS_THREAD = ProcThreadAttributeUmsThread | PROC_THREAD_ATTRIBUTE_THREAD | PROC_THREAD_ATTRIBUTE_INPUT +PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY = ProcThreadAttributeMitigationPolicy | PROC_THREAD_ATTRIBUTE_INPUT + +PROCESS_CREATION_MITIGATION_POLICY_DEP_ENABLE = 0x01 +PROCESS_CREATION_MITIGATION_POLICY_DEP_ATL_THUNK_ENABLE = 0x02 +PROCESS_CREATION_MITIGATION_POLICY_SEHOP_ENABLE = 0x04 + +#--- VS_FIXEDFILEINFO structure ----------------------------------------------- + +# struct VS_FIXEDFILEINFO { +# DWORD dwSignature; +# DWORD dwStrucVersion; +# DWORD dwFileVersionMS; +# DWORD dwFileVersionLS; +# DWORD dwProductVersionMS; +# DWORD dwProductVersionLS; +# DWORD dwFileFlagsMask; +# DWORD dwFileFlags; +# DWORD dwFileOS; +# DWORD dwFileType; +# DWORD dwFileSubtype; +# DWORD dwFileDateMS; +# DWORD dwFileDateLS; +# }; +class VS_FIXEDFILEINFO (Structure): + _fields_ = [ + ("dwSignature", DWORD), # 0xFEEF04BD + ("dwStrucVersion", DWORD), + ("dwFileVersionMS", DWORD), + ("dwFileVersionLS", DWORD), + ("dwProductVersionMS", DWORD), + ("dwProductVersionLS", DWORD), + ("dwFileFlagsMask", DWORD), + ("dwFileFlags", DWORD), + ("dwFileOS", DWORD), + ("dwFileType", DWORD), + ("dwFileSubtype", DWORD), + ("dwFileDateMS", DWORD), + ("dwFileDateLS", DWORD), + ] + +#--- THREADNAME_INFO structure ------------------------------------------------ + +# typedef struct tagTHREADNAME_INFO +# { +# DWORD dwType; // Must be 0x1000. +# LPCSTR szName; // Pointer to name (in user addr space). +# DWORD dwThreadID; // Thread ID (-1=caller thread). +# DWORD dwFlags; // Reserved for future use, must be zero. +# } THREADNAME_INFO; +class THREADNAME_INFO(Structure): + _fields_ = [ + ("dwType", DWORD), # 0x1000 + ("szName", LPVOID), # remote pointer + ("dwThreadID", DWORD), # -1 usually + ("dwFlags", DWORD), # 0 + ] + +#--- MEMORY_BASIC_INFORMATION structure --------------------------------------- + +# typedef struct _MEMORY_BASIC_INFORMATION32 { +# DWORD BaseAddress; +# DWORD AllocationBase; +# DWORD AllocationProtect; +# DWORD RegionSize; +# DWORD State; +# DWORD Protect; +# DWORD Type; +# } MEMORY_BASIC_INFORMATION32, *PMEMORY_BASIC_INFORMATION32; +class MEMORY_BASIC_INFORMATION32(Structure): + _fields_ = [ + ('BaseAddress', DWORD), # remote pointer + ('AllocationBase', DWORD), # remote pointer + ('AllocationProtect', DWORD), + ('RegionSize', DWORD), + ('State', DWORD), + ('Protect', DWORD), + ('Type', DWORD), + ] + +# typedef struct DECLSPEC_ALIGN(16) _MEMORY_BASIC_INFORMATION64 { +# ULONGLONG BaseAddress; +# ULONGLONG AllocationBase; +# DWORD AllocationProtect; +# DWORD __alignment1; +# ULONGLONG RegionSize; +# DWORD State; +# DWORD Protect; +# DWORD Type; +# DWORD __alignment2; +# } MEMORY_BASIC_INFORMATION64, *PMEMORY_BASIC_INFORMATION64; +class MEMORY_BASIC_INFORMATION64(Structure): + _fields_ = [ + ('BaseAddress', ULONGLONG), # remote pointer + ('AllocationBase', ULONGLONG), # remote pointer + ('AllocationProtect', DWORD), + ('__alignment1', DWORD), + ('RegionSize', ULONGLONG), + ('State', DWORD), + ('Protect', DWORD), + ('Type', DWORD), + ('__alignment2', DWORD), + ] + +# typedef struct _MEMORY_BASIC_INFORMATION { +# PVOID BaseAddress; +# PVOID AllocationBase; +# DWORD AllocationProtect; +# SIZE_T RegionSize; +# DWORD State; +# DWORD Protect; +# DWORD Type; +# } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION; +class MEMORY_BASIC_INFORMATION(Structure): + _fields_ = [ + ('BaseAddress', SIZE_T), # remote pointer + ('AllocationBase', SIZE_T), # remote pointer + ('AllocationProtect', DWORD), + ('RegionSize', SIZE_T), + ('State', DWORD), + ('Protect', DWORD), + ('Type', DWORD), + ] +PMEMORY_BASIC_INFORMATION = POINTER(MEMORY_BASIC_INFORMATION) + +#--- BY_HANDLE_FILE_INFORMATION structure ------------------------------------- + +# typedef struct _FILETIME { +# DWORD dwLowDateTime; +# DWORD dwHighDateTime; +# } FILETIME, *PFILETIME; +class FILETIME(Structure): + _fields_ = [ + ('dwLowDateTime', DWORD), + ('dwHighDateTime', DWORD), + ] +LPFILETIME = POINTER(FILETIME) + +# typedef struct _SYSTEMTIME { +# WORD wYear; +# WORD wMonth; +# WORD wDayOfWeek; +# WORD wDay; +# WORD wHour; +# WORD wMinute; +# WORD wSecond; +# WORD wMilliseconds; +# }SYSTEMTIME, *PSYSTEMTIME; +class SYSTEMTIME(Structure): + _fields_ = [ + ('wYear', WORD), + ('wMonth', WORD), + ('wDayOfWeek', WORD), + ('wDay', WORD), + ('wHour', WORD), + ('wMinute', WORD), + ('wSecond', WORD), + ('wMilliseconds', WORD), + ] +LPSYSTEMTIME = POINTER(SYSTEMTIME) + +# typedef struct _BY_HANDLE_FILE_INFORMATION { +# DWORD dwFileAttributes; +# FILETIME ftCreationTime; +# FILETIME ftLastAccessTime; +# FILETIME ftLastWriteTime; +# DWORD dwVolumeSerialNumber; +# DWORD nFileSizeHigh; +# DWORD nFileSizeLow; +# DWORD nNumberOfLinks; +# DWORD nFileIndexHigh; +# DWORD nFileIndexLow; +# } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION; +class BY_HANDLE_FILE_INFORMATION(Structure): + _fields_ = [ + ('dwFileAttributes', DWORD), + ('ftCreationTime', FILETIME), + ('ftLastAccessTime', FILETIME), + ('ftLastWriteTime', FILETIME), + ('dwVolumeSerialNumber', DWORD), + ('nFileSizeHigh', DWORD), + ('nFileSizeLow', DWORD), + ('nNumberOfLinks', DWORD), + ('nFileIndexHigh', DWORD), + ('nFileIndexLow', DWORD), + ] +LPBY_HANDLE_FILE_INFORMATION = POINTER(BY_HANDLE_FILE_INFORMATION) + +# typedef enum _FILE_INFO_BY_HANDLE_CLASS { +# FileBasicInfo = 0, +# FileStandardInfo = 1, +# FileNameInfo = 2, +# FileRenameInfo = 3, +# FileDispositionInfo = 4, +# FileAllocationInfo = 5, +# FileEndOfFileInfo = 6, +# FileStreamInfo = 7, +# FileCompressionInfo = 8, +# FileAttributeTagInfo = 9, +# FileIdBothDirectoryInfo = 10, +# FileIdBothDirectoryRestartInfo = 11, +# FileIoPriorityHintInfo = 12, +# MaximumFileInfoByHandlesClass = 13 +# } FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS; +class FILE_INFO_BY_HANDLE_CLASS(object): + FileBasicInfo = 0 + FileStandardInfo = 1 + FileNameInfo = 2 + FileRenameInfo = 3 + FileDispositionInfo = 4 + FileAllocationInfo = 5 + FileEndOfFileInfo = 6 + FileStreamInfo = 7 + FileCompressionInfo = 8 + FileAttributeTagInfo = 9 + FileIdBothDirectoryInfo = 10 + FileIdBothDirectoryRestartInfo = 11 + FileIoPriorityHintInfo = 12 + MaximumFileInfoByHandlesClass = 13 + +# typedef struct _FILE_NAME_INFO { +# DWORD FileNameLength; +# WCHAR FileName[1]; +# } FILE_NAME_INFO, *PFILE_NAME_INFO; +##class FILE_NAME_INFO(Structure): +## _fields_ = [ +## ('FileNameLength', DWORD), +## ('FileName', WCHAR * 1), +## ] + +# TO DO: add more structures used by GetFileInformationByHandleEx() + +#--- PROCESS_INFORMATION structure -------------------------------------------- + +# typedef struct _PROCESS_INFORMATION { +# HANDLE hProcess; +# HANDLE hThread; +# DWORD dwProcessId; +# DWORD dwThreadId; +# } PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION; +class PROCESS_INFORMATION(Structure): + _fields_ = [ + ('hProcess', HANDLE), + ('hThread', HANDLE), + ('dwProcessId', DWORD), + ('dwThreadId', DWORD), + ] +LPPROCESS_INFORMATION = POINTER(PROCESS_INFORMATION) + +#--- STARTUPINFO and STARTUPINFOEX structures --------------------------------- + +# typedef struct _STARTUPINFO { +# DWORD cb; +# LPTSTR lpReserved; +# LPTSTR lpDesktop; +# LPTSTR lpTitle; +# DWORD dwX; +# DWORD dwY; +# DWORD dwXSize; +# DWORD dwYSize; +# DWORD dwXCountChars; +# DWORD dwYCountChars; +# DWORD dwFillAttribute; +# DWORD dwFlags; +# WORD wShowWindow; +# WORD cbReserved2; +# LPBYTE lpReserved2; +# HANDLE hStdInput; +# HANDLE hStdOutput; +# HANDLE hStdError; +# }STARTUPINFO, *LPSTARTUPINFO; +class STARTUPINFO(Structure): + _fields_ = [ + ('cb', DWORD), + ('lpReserved', LPSTR), + ('lpDesktop', LPSTR), + ('lpTitle', LPSTR), + ('dwX', DWORD), + ('dwY', DWORD), + ('dwXSize', DWORD), + ('dwYSize', DWORD), + ('dwXCountChars', DWORD), + ('dwYCountChars', DWORD), + ('dwFillAttribute', DWORD), + ('dwFlags', DWORD), + ('wShowWindow', WORD), + ('cbReserved2', WORD), + ('lpReserved2', LPVOID), # LPBYTE + ('hStdInput', HANDLE), + ('hStdOutput', HANDLE), + ('hStdError', HANDLE), + ] +LPSTARTUPINFO = POINTER(STARTUPINFO) + +# typedef struct _STARTUPINFOEX { +# STARTUPINFO StartupInfo; +# PPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; +# } STARTUPINFOEX, *LPSTARTUPINFOEX; +class STARTUPINFOEX(Structure): + _fields_ = [ + ('StartupInfo', STARTUPINFO), + ('lpAttributeList', PPROC_THREAD_ATTRIBUTE_LIST), + ] +LPSTARTUPINFOEX = POINTER(STARTUPINFOEX) + +class STARTUPINFOW(Structure): + _fields_ = [ + ('cb', DWORD), + ('lpReserved', LPWSTR), + ('lpDesktop', LPWSTR), + ('lpTitle', LPWSTR), + ('dwX', DWORD), + ('dwY', DWORD), + ('dwXSize', DWORD), + ('dwYSize', DWORD), + ('dwXCountChars', DWORD), + ('dwYCountChars', DWORD), + ('dwFillAttribute', DWORD), + ('dwFlags', DWORD), + ('wShowWindow', WORD), + ('cbReserved2', WORD), + ('lpReserved2', LPVOID), # LPBYTE + ('hStdInput', HANDLE), + ('hStdOutput', HANDLE), + ('hStdError', HANDLE), + ] +LPSTARTUPINFOW = POINTER(STARTUPINFOW) + +class STARTUPINFOEXW(Structure): + _fields_ = [ + ('StartupInfo', STARTUPINFOW), + ('lpAttributeList', PPROC_THREAD_ATTRIBUTE_LIST), + ] +LPSTARTUPINFOEXW = POINTER(STARTUPINFOEXW) + +#--- JIT_DEBUG_INFO structure ------------------------------------------------- + +# typedef struct _JIT_DEBUG_INFO { +# DWORD dwSize; +# DWORD dwProcessorArchitecture; +# DWORD dwThreadID; +# DWORD dwReserved0; +# ULONG64 lpExceptionAddress; +# ULONG64 lpExceptionRecord; +# ULONG64 lpContextRecord; +# } JIT_DEBUG_INFO, *LPJIT_DEBUG_INFO; +class JIT_DEBUG_INFO(Structure): + _fields_ = [ + ('dwSize', DWORD), + ('dwProcessorArchitecture', DWORD), + ('dwThreadID', DWORD), + ('dwReserved0', DWORD), + ('lpExceptionAddress', ULONG64), + ('lpExceptionRecord', ULONG64), + ('lpContextRecord', ULONG64), + ] +JIT_DEBUG_INFO32 = JIT_DEBUG_INFO +JIT_DEBUG_INFO64 = JIT_DEBUG_INFO + +LPJIT_DEBUG_INFO = POINTER(JIT_DEBUG_INFO) +LPJIT_DEBUG_INFO32 = POINTER(JIT_DEBUG_INFO32) +LPJIT_DEBUG_INFO64 = POINTER(JIT_DEBUG_INFO64) + +#--- DEBUG_EVENT structure ---------------------------------------------------- + +# typedef struct _EXCEPTION_RECORD32 { +# DWORD ExceptionCode; +# DWORD ExceptionFlags; +# DWORD ExceptionRecord; +# DWORD ExceptionAddress; +# DWORD NumberParameters; +# DWORD ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; +# } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32; +class EXCEPTION_RECORD32(Structure): + _fields_ = [ + ('ExceptionCode', DWORD), + ('ExceptionFlags', DWORD), + ('ExceptionRecord', DWORD), + ('ExceptionAddress', DWORD), + ('NumberParameters', DWORD), + ('ExceptionInformation', DWORD * EXCEPTION_MAXIMUM_PARAMETERS), + ] + +PEXCEPTION_RECORD32 = POINTER(EXCEPTION_RECORD32) + +# typedef struct _EXCEPTION_RECORD64 { +# DWORD ExceptionCode; +# DWORD ExceptionFlags; +# DWORD64 ExceptionRecord; +# DWORD64 ExceptionAddress; +# DWORD NumberParameters; +# DWORD __unusedAlignment; +# DWORD64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; +# } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64; +class EXCEPTION_RECORD64(Structure): + _fields_ = [ + ('ExceptionCode', DWORD), + ('ExceptionFlags', DWORD), + ('ExceptionRecord', DWORD64), + ('ExceptionAddress', DWORD64), + ('NumberParameters', DWORD), + ('__unusedAlignment', DWORD), + ('ExceptionInformation', DWORD64 * EXCEPTION_MAXIMUM_PARAMETERS), + ] + +PEXCEPTION_RECORD64 = POINTER(EXCEPTION_RECORD64) + +# typedef struct _EXCEPTION_RECORD { +# DWORD ExceptionCode; +# DWORD ExceptionFlags; +# LPVOID ExceptionRecord; +# LPVOID ExceptionAddress; +# DWORD NumberParameters; +# LPVOID ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]; +# } EXCEPTION_RECORD, *PEXCEPTION_RECORD; +class EXCEPTION_RECORD(Structure): + pass +PEXCEPTION_RECORD = POINTER(EXCEPTION_RECORD) +EXCEPTION_RECORD._fields_ = [ + ('ExceptionCode', DWORD), + ('ExceptionFlags', DWORD), + ('ExceptionRecord', PEXCEPTION_RECORD), + ('ExceptionAddress', LPVOID), + ('NumberParameters', DWORD), + ('ExceptionInformation', LPVOID * EXCEPTION_MAXIMUM_PARAMETERS), + ] + +# typedef struct _EXCEPTION_DEBUG_INFO { +# EXCEPTION_RECORD ExceptionRecord; +# DWORD dwFirstChance; +# } EXCEPTION_DEBUG_INFO; +class EXCEPTION_DEBUG_INFO(Structure): + _fields_ = [ + ('ExceptionRecord', EXCEPTION_RECORD), + ('dwFirstChance', DWORD), + ] + +# typedef struct _CREATE_THREAD_DEBUG_INFO { +# HANDLE hThread; +# LPVOID lpThreadLocalBase; +# LPTHREAD_START_ROUTINE lpStartAddress; +# } CREATE_THREAD_DEBUG_INFO; +class CREATE_THREAD_DEBUG_INFO(Structure): + _fields_ = [ + ('hThread', HANDLE), + ('lpThreadLocalBase', LPVOID), + ('lpStartAddress', LPVOID), + ] + +# typedef struct _CREATE_PROCESS_DEBUG_INFO { +# HANDLE hFile; +# HANDLE hProcess; +# HANDLE hThread; +# LPVOID lpBaseOfImage; +# DWORD dwDebugInfoFileOffset; +# DWORD nDebugInfoSize; +# LPVOID lpThreadLocalBase; +# LPTHREAD_START_ROUTINE lpStartAddress; +# LPVOID lpImageName; +# WORD fUnicode; +# } CREATE_PROCESS_DEBUG_INFO; +class CREATE_PROCESS_DEBUG_INFO(Structure): + _fields_ = [ + ('hFile', HANDLE), + ('hProcess', HANDLE), + ('hThread', HANDLE), + ('lpBaseOfImage', LPVOID), + ('dwDebugInfoFileOffset', DWORD), + ('nDebugInfoSize', DWORD), + ('lpThreadLocalBase', LPVOID), + ('lpStartAddress', LPVOID), + ('lpImageName', LPVOID), + ('fUnicode', WORD), + ] + +# typedef struct _EXIT_THREAD_DEBUG_INFO { +# DWORD dwExitCode; +# } EXIT_THREAD_DEBUG_INFO; +class EXIT_THREAD_DEBUG_INFO(Structure): + _fields_ = [ + ('dwExitCode', DWORD), + ] + +# typedef struct _EXIT_PROCESS_DEBUG_INFO { +# DWORD dwExitCode; +# } EXIT_PROCESS_DEBUG_INFO; +class EXIT_PROCESS_DEBUG_INFO(Structure): + _fields_ = [ + ('dwExitCode', DWORD), + ] + +# typedef struct _LOAD_DLL_DEBUG_INFO { +# HANDLE hFile; +# LPVOID lpBaseOfDll; +# DWORD dwDebugInfoFileOffset; +# DWORD nDebugInfoSize; +# LPVOID lpImageName; +# WORD fUnicode; +# } LOAD_DLL_DEBUG_INFO; +class LOAD_DLL_DEBUG_INFO(Structure): + _fields_ = [ + ('hFile', HANDLE), + ('lpBaseOfDll', LPVOID), + ('dwDebugInfoFileOffset', DWORD), + ('nDebugInfoSize', DWORD), + ('lpImageName', LPVOID), + ('fUnicode', WORD), + ] + +# typedef struct _UNLOAD_DLL_DEBUG_INFO { +# LPVOID lpBaseOfDll; +# } UNLOAD_DLL_DEBUG_INFO; +class UNLOAD_DLL_DEBUG_INFO(Structure): + _fields_ = [ + ('lpBaseOfDll', LPVOID), + ] + +# typedef struct _OUTPUT_DEBUG_STRING_INFO { +# LPSTR lpDebugStringData; +# WORD fUnicode; +# WORD nDebugStringLength; +# } OUTPUT_DEBUG_STRING_INFO; +class OUTPUT_DEBUG_STRING_INFO(Structure): + _fields_ = [ + ('lpDebugStringData', LPVOID), # don't use LPSTR + ('fUnicode', WORD), + ('nDebugStringLength', WORD), + ] + +# typedef struct _RIP_INFO { +# DWORD dwError; +# DWORD dwType; +# } RIP_INFO, *LPRIP_INFO; +class RIP_INFO(Structure): + _fields_ = [ + ('dwError', DWORD), + ('dwType', DWORD), + ] + +# typedef struct _DEBUG_EVENT { +# DWORD dwDebugEventCode; +# DWORD dwProcessId; +# DWORD dwThreadId; +# union { +# EXCEPTION_DEBUG_INFO Exception; +# CREATE_THREAD_DEBUG_INFO CreateThread; +# CREATE_PROCESS_DEBUG_INFO CreateProcessInfo; +# EXIT_THREAD_DEBUG_INFO ExitThread; +# EXIT_PROCESS_DEBUG_INFO ExitProcess; +# LOAD_DLL_DEBUG_INFO LoadDll; +# UNLOAD_DLL_DEBUG_INFO UnloadDll; +# OUTPUT_DEBUG_STRING_INFO DebugString; +# RIP_INFO RipInfo; +# } u; +# } DEBUG_EVENT;. +class _DEBUG_EVENT_UNION_(Union): + _fields_ = [ + ('Exception', EXCEPTION_DEBUG_INFO), + ('CreateThread', CREATE_THREAD_DEBUG_INFO), + ('CreateProcessInfo', CREATE_PROCESS_DEBUG_INFO), + ('ExitThread', EXIT_THREAD_DEBUG_INFO), + ('ExitProcess', EXIT_PROCESS_DEBUG_INFO), + ('LoadDll', LOAD_DLL_DEBUG_INFO), + ('UnloadDll', UNLOAD_DLL_DEBUG_INFO), + ('DebugString', OUTPUT_DEBUG_STRING_INFO), + ('RipInfo', RIP_INFO), + ] +class DEBUG_EVENT(Structure): + _fields_ = [ + ('dwDebugEventCode', DWORD), + ('dwProcessId', DWORD), + ('dwThreadId', DWORD), + ('u', _DEBUG_EVENT_UNION_), + ] +LPDEBUG_EVENT = POINTER(DEBUG_EVENT) + +#--- Console API defines and structures --------------------------------------- + +FOREGROUND_MASK = 0x000F +BACKGROUND_MASK = 0x00F0 +COMMON_LVB_MASK = 0xFF00 + +FOREGROUND_BLACK = 0x0000 +FOREGROUND_BLUE = 0x0001 +FOREGROUND_GREEN = 0x0002 +FOREGROUND_CYAN = 0x0003 +FOREGROUND_RED = 0x0004 +FOREGROUND_MAGENTA = 0x0005 +FOREGROUND_YELLOW = 0x0006 +FOREGROUND_GREY = 0x0007 +FOREGROUND_INTENSITY = 0x0008 + +BACKGROUND_BLACK = 0x0000 +BACKGROUND_BLUE = 0x0010 +BACKGROUND_GREEN = 0x0020 +BACKGROUND_CYAN = 0x0030 +BACKGROUND_RED = 0x0040 +BACKGROUND_MAGENTA = 0x0050 +BACKGROUND_YELLOW = 0x0060 +BACKGROUND_GREY = 0x0070 +BACKGROUND_INTENSITY = 0x0080 + +COMMON_LVB_LEADING_BYTE = 0x0100 +COMMON_LVB_TRAILING_BYTE = 0x0200 +COMMON_LVB_GRID_HORIZONTAL = 0x0400 +COMMON_LVB_GRID_LVERTICAL = 0x0800 +COMMON_LVB_GRID_RVERTICAL = 0x1000 +COMMON_LVB_REVERSE_VIDEO = 0x4000 +COMMON_LVB_UNDERSCORE = 0x8000 + +# typedef struct _CHAR_INFO { +# union { +# WCHAR UnicodeChar; +# CHAR AsciiChar; +# } Char; +# WORD Attributes; +# } CHAR_INFO, *PCHAR_INFO; +class _CHAR_INFO_CHAR(Union): + _fields_ = [ + ('UnicodeChar', WCHAR), + ('AsciiChar', CHAR), + ] +class CHAR_INFO(Structure): + _fields_ = [ + ('Char', _CHAR_INFO_CHAR), + ('Attributes', WORD), + ] +PCHAR_INFO = POINTER(CHAR_INFO) + +# typedef struct _COORD { +# SHORT X; +# SHORT Y; +# } COORD, *PCOORD; +class COORD(Structure): + _fields_ = [ + ('X', SHORT), + ('Y', SHORT), + ] +PCOORD = POINTER(COORD) + +# typedef struct _SMALL_RECT { +# SHORT Left; +# SHORT Top; +# SHORT Right; +# SHORT Bottom; +# } SMALL_RECT; +class SMALL_RECT(Structure): + _fields_ = [ + ('Left', SHORT), + ('Top', SHORT), + ('Right', SHORT), + ('Bottom', SHORT), + ] +PSMALL_RECT = POINTER(SMALL_RECT) + +# typedef struct _CONSOLE_SCREEN_BUFFER_INFO { +# COORD dwSize; +# COORD dwCursorPosition; +# WORD wAttributes; +# SMALL_RECT srWindow; +# COORD dwMaximumWindowSize; +# } CONSOLE_SCREEN_BUFFER_INFO; +class CONSOLE_SCREEN_BUFFER_INFO(Structure): + _fields_ = [ + ('dwSize', COORD), + ('dwCursorPosition', COORD), + ('wAttributes', WORD), + ('srWindow', SMALL_RECT), + ('dwMaximumWindowSize', COORD), + ] +PCONSOLE_SCREEN_BUFFER_INFO = POINTER(CONSOLE_SCREEN_BUFFER_INFO) + +#--- Toolhelp library defines and structures ---------------------------------- + +TH32CS_SNAPHEAPLIST = 0x00000001 +TH32CS_SNAPPROCESS = 0x00000002 +TH32CS_SNAPTHREAD = 0x00000004 +TH32CS_SNAPMODULE = 0x00000008 +TH32CS_INHERIT = 0x80000000 +TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE) + +# typedef struct tagTHREADENTRY32 { +# DWORD dwSize; +# DWORD cntUsage; +# DWORD th32ThreadID; +# DWORD th32OwnerProcessID; +# LONG tpBasePri; +# LONG tpDeltaPri; +# DWORD dwFlags; +# } THREADENTRY32, *PTHREADENTRY32; +class THREADENTRY32(Structure): + _fields_ = [ + ('dwSize', DWORD), + ('cntUsage', DWORD), + ('th32ThreadID', DWORD), + ('th32OwnerProcessID', DWORD), + ('tpBasePri', LONG), + ('tpDeltaPri', LONG), + ('dwFlags', DWORD), + ] +LPTHREADENTRY32 = POINTER(THREADENTRY32) + +# typedef struct tagPROCESSENTRY32 { +# DWORD dwSize; +# DWORD cntUsage; +# DWORD th32ProcessID; +# ULONG_PTR th32DefaultHeapID; +# DWORD th32ModuleID; +# DWORD cntThreads; +# DWORD th32ParentProcessID; +# LONG pcPriClassBase; +# DWORD dwFlags; +# TCHAR szExeFile[MAX_PATH]; +# } PROCESSENTRY32, *PPROCESSENTRY32; +class PROCESSENTRY32(Structure): + _fields_ = [ + ('dwSize', DWORD), + ('cntUsage', DWORD), + ('th32ProcessID', DWORD), + ('th32DefaultHeapID', ULONG_PTR), + ('th32ModuleID', DWORD), + ('cntThreads', DWORD), + ('th32ParentProcessID', DWORD), + ('pcPriClassBase', LONG), + ('dwFlags', DWORD), + ('szExeFile', TCHAR * 260), + ] +LPPROCESSENTRY32 = POINTER(PROCESSENTRY32) + +# typedef struct tagMODULEENTRY32 { +# DWORD dwSize; +# DWORD th32ModuleID; +# DWORD th32ProcessID; +# DWORD GlblcntUsage; +# DWORD ProccntUsage; +# BYTE* modBaseAddr; +# DWORD modBaseSize; +# HMODULE hModule; +# TCHAR szModule[MAX_MODULE_NAME32 + 1]; +# TCHAR szExePath[MAX_PATH]; +# } MODULEENTRY32, *PMODULEENTRY32; +class MODULEENTRY32(Structure): + _fields_ = [ + ("dwSize", DWORD), + ("th32ModuleID", DWORD), + ("th32ProcessID", DWORD), + ("GlblcntUsage", DWORD), + ("ProccntUsage", DWORD), + ("modBaseAddr", LPVOID), # BYTE* + ("modBaseSize", DWORD), + ("hModule", HMODULE), + ("szModule", TCHAR * (MAX_MODULE_NAME32 + 1)), + ("szExePath", TCHAR * MAX_PATH), + ] +LPMODULEENTRY32 = POINTER(MODULEENTRY32) + +# typedef struct tagHEAPENTRY32 { +# SIZE_T dwSize; +# HANDLE hHandle; +# ULONG_PTR dwAddress; +# SIZE_T dwBlockSize; +# DWORD dwFlags; +# DWORD dwLockCount; +# DWORD dwResvd; +# DWORD th32ProcessID; +# ULONG_PTR th32HeapID; +# } HEAPENTRY32, +# *PHEAPENTRY32; +class HEAPENTRY32(Structure): + _fields_ = [ + ("dwSize", SIZE_T), + ("hHandle", HANDLE), + ("dwAddress", ULONG_PTR), + ("dwBlockSize", SIZE_T), + ("dwFlags", DWORD), + ("dwLockCount", DWORD), + ("dwResvd", DWORD), + ("th32ProcessID", DWORD), + ("th32HeapID", ULONG_PTR), +] +LPHEAPENTRY32 = POINTER(HEAPENTRY32) + +# typedef struct tagHEAPLIST32 { +# SIZE_T dwSize; +# DWORD th32ProcessID; +# ULONG_PTR th32HeapID; +# DWORD dwFlags; +# } HEAPLIST32, +# *PHEAPLIST32; +class HEAPLIST32(Structure): + _fields_ = [ + ("dwSize", SIZE_T), + ("th32ProcessID", DWORD), + ("th32HeapID", ULONG_PTR), + ("dwFlags", DWORD), +] +LPHEAPLIST32 = POINTER(HEAPLIST32) + +#--- kernel32.dll ------------------------------------------------------------- + +# DWORD WINAPI GetLastError(void); +def GetLastError(): + _GetLastError = windll.kernel32.GetLastError + _GetLastError.argtypes = [] + _GetLastError.restype = DWORD + return _GetLastError() + +# void WINAPI SetLastError( +# __in DWORD dwErrCode +# ); +def SetLastError(dwErrCode): + _SetLastError = windll.kernel32.SetLastError + _SetLastError.argtypes = [DWORD] + _SetLastError.restype = None + _SetLastError(dwErrCode) + +# UINT WINAPI GetErrorMode(void); +def GetErrorMode(): + _GetErrorMode = windll.kernel32.GetErrorMode + _GetErrorMode.argtypes = [] + _GetErrorMode.restype = UINT + return _GetErrorMode() + +# UINT WINAPI SetErrorMode( +# __in UINT uMode +# ); +def SetErrorMode(uMode): + _SetErrorMode = windll.kernel32.SetErrorMode + _SetErrorMode.argtypes = [UINT] + _SetErrorMode.restype = UINT + return _SetErrorMode(dwErrCode) + +# DWORD GetThreadErrorMode(void); +def GetThreadErrorMode(): + _GetThreadErrorMode = windll.kernel32.GetThreadErrorMode + _GetThreadErrorMode.argtypes = [] + _GetThreadErrorMode.restype = DWORD + return _GetThreadErrorMode() + +# BOOL SetThreadErrorMode( +# __in DWORD dwNewMode, +# __out LPDWORD lpOldMode +# ); +def SetThreadErrorMode(dwNewMode): + _SetThreadErrorMode = windll.kernel32.SetThreadErrorMode + _SetThreadErrorMode.argtypes = [DWORD, LPDWORD] + _SetThreadErrorMode.restype = BOOL + _SetThreadErrorMode.errcheck = RaiseIfZero + + old = DWORD(0) + _SetThreadErrorMode(dwErrCode, byref(old)) + return old.value + +# BOOL WINAPI CloseHandle( +# __in HANDLE hObject +# ); +def CloseHandle(hHandle): + if isinstance(hHandle, Handle): + # Prevents the handle from being closed without notifying the Handle object. + hHandle.close() + else: + _CloseHandle = windll.kernel32.CloseHandle + _CloseHandle.argtypes = [HANDLE] + _CloseHandle.restype = bool + _CloseHandle.errcheck = RaiseIfZero + _CloseHandle(hHandle) + +# BOOL WINAPI DuplicateHandle( +# __in HANDLE hSourceProcessHandle, +# __in HANDLE hSourceHandle, +# __in HANDLE hTargetProcessHandle, +# __out LPHANDLE lpTargetHandle, +# __in DWORD dwDesiredAccess, +# __in BOOL bInheritHandle, +# __in DWORD dwOptions +# ); +def DuplicateHandle(hSourceHandle, hSourceProcessHandle = None, hTargetProcessHandle = None, dwDesiredAccess = STANDARD_RIGHTS_ALL, bInheritHandle = False, dwOptions = DUPLICATE_SAME_ACCESS): + _DuplicateHandle = windll.kernel32.DuplicateHandle + _DuplicateHandle.argtypes = [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, DWORD] + _DuplicateHandle.restype = bool + _DuplicateHandle.errcheck = RaiseIfZero + + # NOTE: the arguments to this function are in a different order, + # so we can set default values for all of them but one (hSourceHandle). + + if hSourceProcessHandle is None: + hSourceProcessHandle = GetCurrentProcess() + if hTargetProcessHandle is None: + hTargetProcessHandle = hSourceProcessHandle + lpTargetHandle = HANDLE(INVALID_HANDLE_VALUE) + _DuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, byref(lpTargetHandle), dwDesiredAccess, bool(bInheritHandle), dwOptions) + if isinstance(hSourceHandle, Handle): + HandleClass = hSourceHandle.__class__ + else: + HandleClass = Handle + if hasattr(hSourceHandle, 'dwAccess'): + return HandleClass(lpTargetHandle.value, dwAccess = hSourceHandle.dwAccess) + else: + return HandleClass(lpTargetHandle.value) + +# HLOCAL WINAPI LocalFree( +# __in HLOCAL hMem +# ); +def LocalFree(hMem): + _LocalFree = windll.kernel32.LocalFree + _LocalFree.argtypes = [HLOCAL] + _LocalFree.restype = HLOCAL + + result = _LocalFree(hMem) + if result != NULL: + ctypes.WinError() + +#------------------------------------------------------------------------------ +# Console API + +# HANDLE WINAPI GetStdHandle( +# _In_ DWORD nStdHandle +# ); +def GetStdHandle(nStdHandle): + _GetStdHandle = windll.kernel32.GetStdHandle + _GetStdHandle.argytpes = [DWORD] + _GetStdHandle.restype = HANDLE + _GetStdHandle.errcheck = RaiseIfZero + return Handle( _GetStdHandle(nStdHandle), bOwnership = False ) + +# BOOL WINAPI SetStdHandle( +# _In_ DWORD nStdHandle, +# _In_ HANDLE hHandle +# ); + +# TODO + +# UINT WINAPI GetConsoleCP(void); +def GetConsoleCP(): + _GetConsoleCP = windll.kernel32.GetConsoleCP + _GetConsoleCP.argytpes = [] + _GetConsoleCP.restype = UINT + return _GetConsoleCP() + +# UINT WINAPI GetConsoleOutputCP(void); +def GetConsoleOutputCP(): + _GetConsoleOutputCP = windll.kernel32.GetConsoleOutputCP + _GetConsoleOutputCP.argytpes = [] + _GetConsoleOutputCP.restype = UINT + return _GetConsoleOutputCP() + +#BOOL WINAPI SetConsoleCP( +# _In_ UINT wCodePageID +#); +def SetConsoleCP(wCodePageID): + _SetConsoleCP = windll.kernel32.SetConsoleCP + _SetConsoleCP.argytpes = [UINT] + _SetConsoleCP.restype = bool + _SetConsoleCP.errcheck = RaiseIfZero + _SetConsoleCP(wCodePageID) + +#BOOL WINAPI SetConsoleOutputCP( +# _In_ UINT wCodePageID +#); +def SetConsoleOutputCP(wCodePageID): + _SetConsoleOutputCP = windll.kernel32.SetConsoleOutputCP + _SetConsoleOutputCP.argytpes = [UINT] + _SetConsoleOutputCP.restype = bool + _SetConsoleOutputCP.errcheck = RaiseIfZero + _SetConsoleOutputCP(wCodePageID) + +# HANDLE WINAPI CreateConsoleScreenBuffer( +# _In_ DWORD dwDesiredAccess, +# _In_ DWORD dwShareMode, +# _In_opt_ const SECURITY_ATTRIBUTES *lpSecurityAttributes, +# _In_ DWORD dwFlags, +# _Reserved_ LPVOID lpScreenBufferData +# ); + +# TODO + +# BOOL WINAPI SetConsoleActiveScreenBuffer( +# _In_ HANDLE hConsoleOutput +# ); +def SetConsoleActiveScreenBuffer(hConsoleOutput = None): + _SetConsoleActiveScreenBuffer = windll.kernel32.SetConsoleActiveScreenBuffer + _SetConsoleActiveScreenBuffer.argytpes = [HANDLE] + _SetConsoleActiveScreenBuffer.restype = bool + _SetConsoleActiveScreenBuffer.errcheck = RaiseIfZero + + if hConsoleOutput is None: + hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE) + _SetConsoleActiveScreenBuffer(hConsoleOutput) + +# BOOL WINAPI GetConsoleScreenBufferInfo( +# _In_ HANDLE hConsoleOutput, +# _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo +# ); +def GetConsoleScreenBufferInfo(hConsoleOutput = None): + _GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo + _GetConsoleScreenBufferInfo.argytpes = [HANDLE, PCONSOLE_SCREEN_BUFFER_INFO] + _GetConsoleScreenBufferInfo.restype = bool + _GetConsoleScreenBufferInfo.errcheck = RaiseIfZero + + if hConsoleOutput is None: + hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE) + ConsoleScreenBufferInfo = CONSOLE_SCREEN_BUFFER_INFO() + _GetConsoleScreenBufferInfo(hConsoleOutput, byref(ConsoleScreenBufferInfo)) + return ConsoleScreenBufferInfo + +# BOOL WINAPI GetConsoleScreenBufferInfoEx( +# _In_ HANDLE hConsoleOutput, +# _Out_ PCONSOLE_SCREEN_BUFFER_INFOEX lpConsoleScreenBufferInfoEx +# ); + +# TODO + +# BOOL WINAPI SetConsoleWindowInfo( +# _In_ HANDLE hConsoleOutput, +# _In_ BOOL bAbsolute, +# _In_ const SMALL_RECT *lpConsoleWindow +# ); +def SetConsoleWindowInfo(hConsoleOutput, bAbsolute, lpConsoleWindow): + _SetConsoleWindowInfo = windll.kernel32.SetConsoleWindowInfo + _SetConsoleWindowInfo.argytpes = [HANDLE, BOOL, PSMALL_RECT] + _SetConsoleWindowInfo.restype = bool + _SetConsoleWindowInfo.errcheck = RaiseIfZero + + if hConsoleOutput is None: + hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE) + if isinstance(lpConsoleWindow, SMALL_RECT): + ConsoleWindow = lpConsoleWindow + else: + ConsoleWindow = SMALL_RECT(*lpConsoleWindow) + _SetConsoleWindowInfo(hConsoleOutput, bAbsolute, byref(ConsoleWindow)) + +# BOOL WINAPI SetConsoleTextAttribute( +# _In_ HANDLE hConsoleOutput, +# _In_ WORD wAttributes +# ); +def SetConsoleTextAttribute(hConsoleOutput = None, wAttributes = 0): + _SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute + _SetConsoleTextAttribute.argytpes = [HANDLE, WORD] + _SetConsoleTextAttribute.restype = bool + _SetConsoleTextAttribute.errcheck = RaiseIfZero + + if hConsoleOutput is None: + hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE) + _SetConsoleTextAttribute(hConsoleOutput, wAttributes) + +# HANDLE WINAPI CreateConsoleScreenBuffer( +# _In_ DWORD dwDesiredAccess, +# _In_ DWORD dwShareMode, +# _In_opt_ const SECURITY_ATTRIBUTES *lpSecurityAttributes, +# _In_ DWORD dwFlags, +# _Reserved_ LPVOID lpScreenBufferData +# ); + +# TODO + +# BOOL WINAPI AllocConsole(void); +def AllocConsole(): + _AllocConsole = windll.kernel32.AllocConsole + _AllocConsole.argytpes = [] + _AllocConsole.restype = bool + _AllocConsole.errcheck = RaiseIfZero + _AllocConsole() + +# BOOL WINAPI AttachConsole( +# _In_ DWORD dwProcessId +# ); +def AttachConsole(dwProcessId = ATTACH_PARENT_PROCESS): + _AttachConsole = windll.kernel32.AttachConsole + _AttachConsole.argytpes = [DWORD] + _AttachConsole.restype = bool + _AttachConsole.errcheck = RaiseIfZero + _AttachConsole(dwProcessId) + +# BOOL WINAPI FreeConsole(void); +def FreeConsole(): + _FreeConsole = windll.kernel32.FreeConsole + _FreeConsole.argytpes = [] + _FreeConsole.restype = bool + _FreeConsole.errcheck = RaiseIfZero + _FreeConsole() + +# DWORD WINAPI GetConsoleProcessList( +# _Out_ LPDWORD lpdwProcessList, +# _In_ DWORD dwProcessCount +# ); + +# TODO + +# DWORD WINAPI GetConsoleTitle( +# _Out_ LPTSTR lpConsoleTitle, +# _In_ DWORD nSize +# ); + +# TODO + +#BOOL WINAPI SetConsoleTitle( +# _In_ LPCTSTR lpConsoleTitle +#); + +# TODO + +# COORD WINAPI GetLargestConsoleWindowSize( +# _In_ HANDLE hConsoleOutput +# ); + +# TODO + +# BOOL WINAPI GetConsoleHistoryInfo( +# _Out_ PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo +# ); + +# TODO + +#------------------------------------------------------------------------------ +# DLL API + +# DWORD WINAPI GetDllDirectory( +# __in DWORD nBufferLength, +# __out LPTSTR lpBuffer +# ); +def GetDllDirectoryA(): + _GetDllDirectoryA = windll.kernel32.GetDllDirectoryA + _GetDllDirectoryA.argytpes = [DWORD, LPSTR] + _GetDllDirectoryA.restype = DWORD + + nBufferLength = _GetDllDirectoryA(0, None) + if nBufferLength == 0: + return None + lpBuffer = ctypes.create_string_buffer("", nBufferLength) + _GetDllDirectoryA(nBufferLength, byref(lpBuffer)) + return lpBuffer.value + +def GetDllDirectoryW(): + _GetDllDirectoryW = windll.kernel32.GetDllDirectoryW + _GetDllDirectoryW.argytpes = [DWORD, LPWSTR] + _GetDllDirectoryW.restype = DWORD + + nBufferLength = _GetDllDirectoryW(0, None) + if nBufferLength == 0: + return None + lpBuffer = ctypes.create_unicode_buffer(u"", nBufferLength) + _GetDllDirectoryW(nBufferLength, byref(lpBuffer)) + return lpBuffer.value + +GetDllDirectory = GuessStringType(GetDllDirectoryA, GetDllDirectoryW) + +# BOOL WINAPI SetDllDirectory( +# __in_opt LPCTSTR lpPathName +# ); +def SetDllDirectoryA(lpPathName = None): + _SetDllDirectoryA = windll.kernel32.SetDllDirectoryA + _SetDllDirectoryA.argytpes = [LPSTR] + _SetDllDirectoryA.restype = bool + _SetDllDirectoryA.errcheck = RaiseIfZero + _SetDllDirectoryA(lpPathName) + +def SetDllDirectoryW(lpPathName): + _SetDllDirectoryW = windll.kernel32.SetDllDirectoryW + _SetDllDirectoryW.argytpes = [LPWSTR] + _SetDllDirectoryW.restype = bool + _SetDllDirectoryW.errcheck = RaiseIfZero + _SetDllDirectoryW(lpPathName) + +SetDllDirectory = GuessStringType(SetDllDirectoryA, SetDllDirectoryW) + +# HMODULE WINAPI LoadLibrary( +# __in LPCTSTR lpFileName +# ); +def LoadLibraryA(pszLibrary): + _LoadLibraryA = windll.kernel32.LoadLibraryA + _LoadLibraryA.argtypes = [LPSTR] + _LoadLibraryA.restype = HMODULE + hModule = _LoadLibraryA(pszLibrary) + if hModule == NULL: + raise ctypes.WinError() + return hModule + +def LoadLibraryW(pszLibrary): + _LoadLibraryW = windll.kernel32.LoadLibraryW + _LoadLibraryW.argtypes = [LPWSTR] + _LoadLibraryW.restype = HMODULE + hModule = _LoadLibraryW(pszLibrary) + if hModule == NULL: + raise ctypes.WinError() + return hModule + +LoadLibrary = GuessStringType(LoadLibraryA, LoadLibraryW) + +# HMODULE WINAPI LoadLibraryEx( +# __in LPCTSTR lpFileName, +# __reserved HANDLE hFile, +# __in DWORD dwFlags +# ); +def LoadLibraryExA(pszLibrary, dwFlags = 0): + _LoadLibraryExA = windll.kernel32.LoadLibraryExA + _LoadLibraryExA.argtypes = [LPSTR, HANDLE, DWORD] + _LoadLibraryExA.restype = HMODULE + hModule = _LoadLibraryExA(pszLibrary, NULL, dwFlags) + if hModule == NULL: + raise ctypes.WinError() + return hModule + +def LoadLibraryExW(pszLibrary, dwFlags = 0): + _LoadLibraryExW = windll.kernel32.LoadLibraryExW + _LoadLibraryExW.argtypes = [LPWSTR, HANDLE, DWORD] + _LoadLibraryExW.restype = HMODULE + hModule = _LoadLibraryExW(pszLibrary, NULL, dwFlags) + if hModule == NULL: + raise ctypes.WinError() + return hModule + +LoadLibraryEx = GuessStringType(LoadLibraryExA, LoadLibraryExW) + +# HMODULE WINAPI GetModuleHandle( +# __in_opt LPCTSTR lpModuleName +# ); +def GetModuleHandleA(lpModuleName): + _GetModuleHandleA = windll.kernel32.GetModuleHandleA + _GetModuleHandleA.argtypes = [LPSTR] + _GetModuleHandleA.restype = HMODULE + hModule = _GetModuleHandleA(lpModuleName) + if hModule == NULL: + raise ctypes.WinError() + return hModule + +def GetModuleHandleW(lpModuleName): + _GetModuleHandleW = windll.kernel32.GetModuleHandleW + _GetModuleHandleW.argtypes = [LPWSTR] + _GetModuleHandleW.restype = HMODULE + hModule = _GetModuleHandleW(lpModuleName) + if hModule == NULL: + raise ctypes.WinError() + return hModule + +GetModuleHandle = GuessStringType(GetModuleHandleA, GetModuleHandleW) + +# FARPROC WINAPI GetProcAddress( +# __in HMODULE hModule, +# __in LPCSTR lpProcName +# ); +def GetProcAddressA(hModule, lpProcName): + _GetProcAddress = windll.kernel32.GetProcAddress + _GetProcAddress.argtypes = [HMODULE, LPVOID] + _GetProcAddress.restype = LPVOID + + if type(lpProcName) in (type(0), type(long(0))): + lpProcName = LPVOID(lpProcName) + if lpProcName.value & (~0xFFFF): + raise ValueError('Ordinal number too large: %d' % lpProcName.value) + elif type(lpProcName) == type(compat.b("")): + lpProcName = ctypes.c_char_p(lpProcName) + else: + raise TypeError(str(type(lpProcName))) + return _GetProcAddress(hModule, lpProcName) + +GetProcAddressW = MakeWideVersion(GetProcAddressA) +GetProcAddress = GuessStringType(GetProcAddressA, GetProcAddressW) + +# BOOL WINAPI FreeLibrary( +# __in HMODULE hModule +# ); +def FreeLibrary(hModule): + _FreeLibrary = windll.kernel32.FreeLibrary + _FreeLibrary.argtypes = [HMODULE] + _FreeLibrary.restype = bool + _FreeLibrary.errcheck = RaiseIfZero + _FreeLibrary(hModule) + +# PVOID WINAPI RtlPcToFileHeader( +# __in PVOID PcValue, +# __out PVOID *BaseOfImage +# ); +def RtlPcToFileHeader(PcValue): + _RtlPcToFileHeader = windll.kernel32.RtlPcToFileHeader + _RtlPcToFileHeader.argtypes = [PVOID, POINTER(PVOID)] + _RtlPcToFileHeader.restype = PRUNTIME_FUNCTION + + BaseOfImage = PVOID(0) + _RtlPcToFileHeader(PcValue, byref(BaseOfImage)) + return BaseOfImage.value + +#------------------------------------------------------------------------------ +# File API and related + +# BOOL WINAPI GetHandleInformation( +# __in HANDLE hObject, +# __out LPDWORD lpdwFlags +# ); +def GetHandleInformation(hObject): + _GetHandleInformation = windll.kernel32.GetHandleInformation + _GetHandleInformation.argtypes = [HANDLE, PDWORD] + _GetHandleInformation.restype = bool + _GetHandleInformation.errcheck = RaiseIfZero + + dwFlags = DWORD(0) + _GetHandleInformation(hObject, byref(dwFlags)) + return dwFlags.value + +# BOOL WINAPI SetHandleInformation( +# __in HANDLE hObject, +# __in DWORD dwMask, +# __in DWORD dwFlags +# ); +def SetHandleInformation(hObject, dwMask, dwFlags): + _SetHandleInformation = windll.kernel32.SetHandleInformation + _SetHandleInformation.argtypes = [HANDLE, DWORD, DWORD] + _SetHandleInformation.restype = bool + _SetHandleInformation.errcheck = RaiseIfZero + _SetHandleInformation(hObject, dwMask, dwFlags) + +# UINT WINAPI GetWindowModuleFileName( +# __in HWND hwnd, +# __out LPTSTR lpszFileName, +# __in UINT cchFileNameMax +# ); +# Not included because it doesn't work in other processes. +# See: http://support.microsoft.com/?id=228469 + +# BOOL WINAPI QueryFullProcessImageName( +# __in HANDLE hProcess, +# __in DWORD dwFlags, +# __out LPTSTR lpExeName, +# __inout PDWORD lpdwSize +# ); +def QueryFullProcessImageNameA(hProcess, dwFlags = 0): + _QueryFullProcessImageNameA = windll.kernel32.QueryFullProcessImageNameA + _QueryFullProcessImageNameA.argtypes = [HANDLE, DWORD, LPSTR, PDWORD] + _QueryFullProcessImageNameA.restype = bool + + dwSize = MAX_PATH + while 1: + lpdwSize = DWORD(dwSize) + lpExeName = ctypes.create_string_buffer('', lpdwSize.value + 1) + success = _QueryFullProcessImageNameA(hProcess, dwFlags, lpExeName, byref(lpdwSize)) + if success and 0 < lpdwSize.value < dwSize: + break + error = GetLastError() + if error != ERROR_INSUFFICIENT_BUFFER: + raise ctypes.WinError(error) + dwSize = dwSize + 256 + if dwSize > 0x1000: + # this prevents an infinite loop in Windows 2008 when the path has spaces, + # see http://msdn.microsoft.com/en-us/library/ms684919(VS.85).aspx#4 + raise ctypes.WinError(error) + return lpExeName.value + +def QueryFullProcessImageNameW(hProcess, dwFlags = 0): + _QueryFullProcessImageNameW = windll.kernel32.QueryFullProcessImageNameW + _QueryFullProcessImageNameW.argtypes = [HANDLE, DWORD, LPWSTR, PDWORD] + _QueryFullProcessImageNameW.restype = bool + + dwSize = MAX_PATH + while 1: + lpdwSize = DWORD(dwSize) + lpExeName = ctypes.create_unicode_buffer('', lpdwSize.value + 1) + success = _QueryFullProcessImageNameW(hProcess, dwFlags, lpExeName, byref(lpdwSize)) + if success and 0 < lpdwSize.value < dwSize: + break + error = GetLastError() + if error != ERROR_INSUFFICIENT_BUFFER: + raise ctypes.WinError(error) + dwSize = dwSize + 256 + if dwSize > 0x1000: + # this prevents an infinite loop in Windows 2008 when the path has spaces, + # see http://msdn.microsoft.com/en-us/library/ms684919(VS.85).aspx#4 + raise ctypes.WinError(error) + return lpExeName.value + +QueryFullProcessImageName = GuessStringType(QueryFullProcessImageNameA, QueryFullProcessImageNameW) + +# DWORD WINAPI GetLogicalDriveStrings( +# __in DWORD nBufferLength, +# __out LPTSTR lpBuffer +# ); +def GetLogicalDriveStringsA(): + _GetLogicalDriveStringsA = ctypes.windll.kernel32.GetLogicalDriveStringsA + _GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR] + _GetLogicalDriveStringsA.restype = DWORD + _GetLogicalDriveStringsA.errcheck = RaiseIfZero + + nBufferLength = (4 * 26) + 1 # "X:\\\0" from A to Z plus empty string + lpBuffer = ctypes.create_string_buffer('', nBufferLength) + _GetLogicalDriveStringsA(nBufferLength, lpBuffer) + drive_strings = list() + string_p = addressof(lpBuffer) + sizeof_char = sizeof(ctypes.c_char) + while True: + string_v = ctypes.string_at(string_p) + if string_v == '': + break + drive_strings.append(string_v) + string_p += len(string_v) + sizeof_char + return drive_strings + +def GetLogicalDriveStringsW(): + _GetLogicalDriveStringsW = ctypes.windll.kernel32.GetLogicalDriveStringsW + _GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR] + _GetLogicalDriveStringsW.restype = DWORD + _GetLogicalDriveStringsW.errcheck = RaiseIfZero + + nBufferLength = (4 * 26) + 1 # "X:\\\0" from A to Z plus empty string + lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength) + _GetLogicalDriveStringsW(nBufferLength, lpBuffer) + drive_strings = list() + string_p = addressof(lpBuffer) + sizeof_wchar = sizeof(ctypes.c_wchar) + while True: + string_v = ctypes.wstring_at(string_p) + if string_v == u'': + break + drive_strings.append(string_v) + string_p += (len(string_v) * sizeof_wchar) + sizeof_wchar + return drive_strings + +##def GetLogicalDriveStringsA(): +## _GetLogicalDriveStringsA = windll.kernel32.GetLogicalDriveStringsA +## _GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR] +## _GetLogicalDriveStringsA.restype = DWORD +## _GetLogicalDriveStringsA.errcheck = RaiseIfZero +## +## nBufferLength = (4 * 26) + 1 # "X:\\\0" from A to Z plus empty string +## lpBuffer = ctypes.create_string_buffer('', nBufferLength) +## _GetLogicalDriveStringsA(nBufferLength, lpBuffer) +## result = list() +## index = 0 +## while 1: +## string = list() +## while 1: +## character = lpBuffer[index] +## index = index + 1 +## if character == '\0': +## break +## string.append(character) +## if not string: +## break +## result.append(''.join(string)) +## return result +## +##def GetLogicalDriveStringsW(): +## _GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW +## _GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR] +## _GetLogicalDriveStringsW.restype = DWORD +## _GetLogicalDriveStringsW.errcheck = RaiseIfZero +## +## nBufferLength = (4 * 26) + 1 # "X:\\\0" from A to Z plus empty string +## lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength) +## _GetLogicalDriveStringsW(nBufferLength, lpBuffer) +## result = list() +## index = 0 +## while 1: +## string = list() +## while 1: +## character = lpBuffer[index] +## index = index + 1 +## if character == u'\0': +## break +## string.append(character) +## if not string: +## break +## result.append(u''.join(string)) +## return result + +GetLogicalDriveStrings = GuessStringType(GetLogicalDriveStringsA, GetLogicalDriveStringsW) + +# DWORD WINAPI QueryDosDevice( +# __in_opt LPCTSTR lpDeviceName, +# __out LPTSTR lpTargetPath, +# __in DWORD ucchMax +# ); +def QueryDosDeviceA(lpDeviceName = None): + _QueryDosDeviceA = windll.kernel32.QueryDosDeviceA + _QueryDosDeviceA.argtypes = [LPSTR, LPSTR, DWORD] + _QueryDosDeviceA.restype = DWORD + _QueryDosDeviceA.errcheck = RaiseIfZero + + if not lpDeviceName: + lpDeviceName = None + ucchMax = 0x1000 + lpTargetPath = ctypes.create_string_buffer('', ucchMax) + _QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax) + return lpTargetPath.value + +def QueryDosDeviceW(lpDeviceName): + _QueryDosDeviceW = windll.kernel32.QueryDosDeviceW + _QueryDosDeviceW.argtypes = [LPWSTR, LPWSTR, DWORD] + _QueryDosDeviceW.restype = DWORD + _QueryDosDeviceW.errcheck = RaiseIfZero + + if not lpDeviceName: + lpDeviceName = None + ucchMax = 0x1000 + lpTargetPath = ctypes.create_unicode_buffer(u'', ucchMax) + _QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax) + return lpTargetPath.value + +QueryDosDevice = GuessStringType(QueryDosDeviceA, QueryDosDeviceW) + +# LPVOID WINAPI MapViewOfFile( +# __in HANDLE hFileMappingObject, +# __in DWORD dwDesiredAccess, +# __in DWORD dwFileOffsetHigh, +# __in DWORD dwFileOffsetLow, +# __in SIZE_T dwNumberOfBytesToMap +# ); +def MapViewOfFile(hFileMappingObject, dwDesiredAccess = FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, dwFileOffsetHigh = 0, dwFileOffsetLow = 0, dwNumberOfBytesToMap = 0): + _MapViewOfFile = windll.kernel32.MapViewOfFile + _MapViewOfFile.argtypes = [HANDLE, DWORD, DWORD, DWORD, SIZE_T] + _MapViewOfFile.restype = LPVOID + lpBaseAddress = _MapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap) + if lpBaseAddress == NULL: + raise ctypes.WinError() + return lpBaseAddress + +# BOOL WINAPI UnmapViewOfFile( +# __in LPCVOID lpBaseAddress +# ); +def UnmapViewOfFile(lpBaseAddress): + _UnmapViewOfFile = windll.kernel32.UnmapViewOfFile + _UnmapViewOfFile.argtypes = [LPVOID] + _UnmapViewOfFile.restype = bool + _UnmapViewOfFile.errcheck = RaiseIfZero + _UnmapViewOfFile(lpBaseAddress) + +# HANDLE WINAPI OpenFileMapping( +# __in DWORD dwDesiredAccess, +# __in BOOL bInheritHandle, +# __in LPCTSTR lpName +# ); +def OpenFileMappingA(dwDesiredAccess, bInheritHandle, lpName): + _OpenFileMappingA = windll.kernel32.OpenFileMappingA + _OpenFileMappingA.argtypes = [DWORD, BOOL, LPSTR] + _OpenFileMappingA.restype = HANDLE + _OpenFileMappingA.errcheck = RaiseIfZero + hFileMappingObject = _OpenFileMappingA(dwDesiredAccess, bool(bInheritHandle), lpName) + return FileMappingHandle(hFileMappingObject) + +def OpenFileMappingW(dwDesiredAccess, bInheritHandle, lpName): + _OpenFileMappingW = windll.kernel32.OpenFileMappingW + _OpenFileMappingW.argtypes = [DWORD, BOOL, LPWSTR] + _OpenFileMappingW.restype = HANDLE + _OpenFileMappingW.errcheck = RaiseIfZero + hFileMappingObject = _OpenFileMappingW(dwDesiredAccess, bool(bInheritHandle), lpName) + return FileMappingHandle(hFileMappingObject) + +OpenFileMapping = GuessStringType(OpenFileMappingA, OpenFileMappingW) + +# HANDLE WINAPI CreateFileMapping( +# __in HANDLE hFile, +# __in_opt LPSECURITY_ATTRIBUTES lpAttributes, +# __in DWORD flProtect, +# __in DWORD dwMaximumSizeHigh, +# __in DWORD dwMaximumSizeLow, +# __in_opt LPCTSTR lpName +# ); +def CreateFileMappingA(hFile, lpAttributes = None, flProtect = PAGE_EXECUTE_READWRITE, dwMaximumSizeHigh = 0, dwMaximumSizeLow = 0, lpName = None): + _CreateFileMappingA = windll.kernel32.CreateFileMappingA + _CreateFileMappingA.argtypes = [HANDLE, LPVOID, DWORD, DWORD, DWORD, LPSTR] + _CreateFileMappingA.restype = HANDLE + _CreateFileMappingA.errcheck = RaiseIfZero + + if lpAttributes: + lpAttributes = ctypes.pointer(lpAttributes) + if not lpName: + lpName = None + hFileMappingObject = _CreateFileMappingA(hFile, lpAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName) + return FileMappingHandle(hFileMappingObject) + +def CreateFileMappingW(hFile, lpAttributes = None, flProtect = PAGE_EXECUTE_READWRITE, dwMaximumSizeHigh = 0, dwMaximumSizeLow = 0, lpName = None): + _CreateFileMappingW = windll.kernel32.CreateFileMappingW + _CreateFileMappingW.argtypes = [HANDLE, LPVOID, DWORD, DWORD, DWORD, LPWSTR] + _CreateFileMappingW.restype = HANDLE + _CreateFileMappingW.errcheck = RaiseIfZero + + if lpAttributes: + lpAttributes = ctypes.pointer(lpAttributes) + if not lpName: + lpName = None + hFileMappingObject = _CreateFileMappingW(hFile, lpAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName) + return FileMappingHandle(hFileMappingObject) + +CreateFileMapping = GuessStringType(CreateFileMappingA, CreateFileMappingW) + +# HANDLE WINAPI CreateFile( +# __in LPCTSTR lpFileName, +# __in DWORD dwDesiredAccess, +# __in DWORD dwShareMode, +# __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, +# __in DWORD dwCreationDisposition, +# __in DWORD dwFlagsAndAttributes, +# __in_opt HANDLE hTemplateFile +# ); +def CreateFileA(lpFileName, dwDesiredAccess = GENERIC_ALL, dwShareMode = 0, lpSecurityAttributes = None, dwCreationDisposition = OPEN_ALWAYS, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, hTemplateFile = None): + _CreateFileA = windll.kernel32.CreateFileA + _CreateFileA.argtypes = [LPSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE] + _CreateFileA.restype = HANDLE + + if not lpFileName: + lpFileName = None + if lpSecurityAttributes: + lpSecurityAttributes = ctypes.pointer(lpSecurityAttributes) + hFile = _CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) + if hFile == INVALID_HANDLE_VALUE: + raise ctypes.WinError() + return FileHandle(hFile) + +def CreateFileW(lpFileName, dwDesiredAccess = GENERIC_ALL, dwShareMode = 0, lpSecurityAttributes = None, dwCreationDisposition = OPEN_ALWAYS, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, hTemplateFile = None): + _CreateFileW = windll.kernel32.CreateFileW + _CreateFileW.argtypes = [LPWSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE] + _CreateFileW.restype = HANDLE + + if not lpFileName: + lpFileName = None + if lpSecurityAttributes: + lpSecurityAttributes = ctypes.pointer(lpSecurityAttributes) + hFile = _CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) + if hFile == INVALID_HANDLE_VALUE: + raise ctypes.WinError() + return FileHandle(hFile) + +CreateFile = GuessStringType(CreateFileA, CreateFileW) + +# BOOL WINAPI FlushFileBuffers( +# __in HANDLE hFile +# ); +def FlushFileBuffers(hFile): + _FlushFileBuffers = windll.kernel32.FlushFileBuffers + _FlushFileBuffers.argtypes = [HANDLE] + _FlushFileBuffers.restype = bool + _FlushFileBuffers.errcheck = RaiseIfZero + _FlushFileBuffers(hFile) + +# BOOL WINAPI FlushViewOfFile( +# __in LPCVOID lpBaseAddress, +# __in SIZE_T dwNumberOfBytesToFlush +# ); +def FlushViewOfFile(lpBaseAddress, dwNumberOfBytesToFlush = 0): + _FlushViewOfFile = windll.kernel32.FlushViewOfFile + _FlushViewOfFile.argtypes = [LPVOID, SIZE_T] + _FlushViewOfFile.restype = bool + _FlushViewOfFile.errcheck = RaiseIfZero + _FlushViewOfFile(lpBaseAddress, dwNumberOfBytesToFlush) + +# DWORD WINAPI SearchPath( +# __in_opt LPCTSTR lpPath, +# __in LPCTSTR lpFileName, +# __in_opt LPCTSTR lpExtension, +# __in DWORD nBufferLength, +# __out LPTSTR lpBuffer, +# __out_opt LPTSTR *lpFilePart +# ); +def SearchPathA(lpPath, lpFileName, lpExtension): + _SearchPathA = windll.kernel32.SearchPathA + _SearchPathA.argtypes = [LPSTR, LPSTR, LPSTR, DWORD, LPSTR, POINTER(LPSTR)] + _SearchPathA.restype = DWORD + _SearchPathA.errcheck = RaiseIfZero + + if not lpPath: + lpPath = None + if not lpExtension: + lpExtension = None + nBufferLength = _SearchPathA(lpPath, lpFileName, lpExtension, 0, None, None) + lpBuffer = ctypes.create_string_buffer('', nBufferLength + 1) + lpFilePart = LPSTR() + _SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, byref(lpFilePart)) + lpFilePart = lpFilePart.value + lpBuffer = lpBuffer.value + if lpBuffer == '': + if GetLastError() == ERROR_SUCCESS: + raise ctypes.WinError(ERROR_FILE_NOT_FOUND) + raise ctypes.WinError() + return (lpBuffer, lpFilePart) + +def SearchPathW(lpPath, lpFileName, lpExtension): + _SearchPathW = windll.kernel32.SearchPathW + _SearchPathW.argtypes = [LPWSTR, LPWSTR, LPWSTR, DWORD, LPWSTR, POINTER(LPWSTR)] + _SearchPathW.restype = DWORD + _SearchPathW.errcheck = RaiseIfZero + + if not lpPath: + lpPath = None + if not lpExtension: + lpExtension = None + nBufferLength = _SearchPathW(lpPath, lpFileName, lpExtension, 0, None, None) + lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength + 1) + lpFilePart = LPWSTR() + _SearchPathW(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, byref(lpFilePart)) + lpFilePart = lpFilePart.value + lpBuffer = lpBuffer.value + if lpBuffer == u'': + if GetLastError() == ERROR_SUCCESS: + raise ctypes.WinError(ERROR_FILE_NOT_FOUND) + raise ctypes.WinError() + return (lpBuffer, lpFilePart) + +SearchPath = GuessStringType(SearchPathA, SearchPathW) + +# BOOL SetSearchPathMode( +# __in DWORD Flags +# ); +def SetSearchPathMode(Flags): + _SetSearchPathMode = windll.kernel32.SetSearchPathMode + _SetSearchPathMode.argtypes = [DWORD] + _SetSearchPathMode.restype = bool + _SetSearchPathMode.errcheck = RaiseIfZero + _SetSearchPathMode(Flags) + +# BOOL WINAPI DeviceIoControl( +# __in HANDLE hDevice, +# __in DWORD dwIoControlCode, +# __in_opt LPVOID lpInBuffer, +# __in DWORD nInBufferSize, +# __out_opt LPVOID lpOutBuffer, +# __in DWORD nOutBufferSize, +# __out_opt LPDWORD lpBytesReturned, +# __inout_opt LPOVERLAPPED lpOverlapped +# ); +def DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpOverlapped): + _DeviceIoControl = windll.kernel32.DeviceIoControl + _DeviceIoControl.argtypes = [HANDLE, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPOVERLAPPED] + _DeviceIoControl.restype = bool + _DeviceIoControl.errcheck = RaiseIfZero + + if not lpInBuffer: + lpInBuffer = None + if not lpOutBuffer: + lpOutBuffer = None + if lpOverlapped: + lpOverlapped = ctypes.pointer(lpOverlapped) + lpBytesReturned = DWORD(0) + _DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, byref(lpBytesReturned), lpOverlapped) + return lpBytesReturned.value + +# BOOL GetFileInformationByHandle( +# HANDLE hFile, +# LPBY_HANDLE_FILE_INFORMATION lpFileInformation +# ); +def GetFileInformationByHandle(hFile): + _GetFileInformationByHandle = windll.kernel32.GetFileInformationByHandle + _GetFileInformationByHandle.argtypes = [HANDLE, LPBY_HANDLE_FILE_INFORMATION] + _GetFileInformationByHandle.restype = bool + _GetFileInformationByHandle.errcheck = RaiseIfZero + + lpFileInformation = BY_HANDLE_FILE_INFORMATION() + _GetFileInformationByHandle(hFile, byref(lpFileInformation)) + return lpFileInformation + +# BOOL WINAPI GetFileInformationByHandleEx( +# __in HANDLE hFile, +# __in FILE_INFO_BY_HANDLE_CLASS FileInformationClass, +# __out LPVOID lpFileInformation, +# __in DWORD dwBufferSize +# ); +def GetFileInformationByHandleEx(hFile, FileInformationClass, lpFileInformation, dwBufferSize): + _GetFileInformationByHandleEx = windll.kernel32.GetFileInformationByHandleEx + _GetFileInformationByHandleEx.argtypes = [HANDLE, DWORD, LPVOID, DWORD] + _GetFileInformationByHandleEx.restype = bool + _GetFileInformationByHandleEx.errcheck = RaiseIfZero + # XXX TODO + # support each FileInformationClass so the function can allocate the + # corresponding structure for the lpFileInformation parameter + _GetFileInformationByHandleEx(hFile, FileInformationClass, byref(lpFileInformation), dwBufferSize) + +# DWORD WINAPI GetFinalPathNameByHandle( +# __in HANDLE hFile, +# __out LPTSTR lpszFilePath, +# __in DWORD cchFilePath, +# __in DWORD dwFlags +# ); +def GetFinalPathNameByHandleA(hFile, dwFlags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS): + _GetFinalPathNameByHandleA = windll.kernel32.GetFinalPathNameByHandleA + _GetFinalPathNameByHandleA.argtypes = [HANDLE, LPSTR, DWORD, DWORD] + _GetFinalPathNameByHandleA.restype = DWORD + + cchFilePath = _GetFinalPathNameByHandleA(hFile, None, 0, dwFlags) + if cchFilePath == 0: + raise ctypes.WinError() + lpszFilePath = ctypes.create_string_buffer('', cchFilePath + 1) + nCopied = _GetFinalPathNameByHandleA(hFile, lpszFilePath, cchFilePath, dwFlags) + if nCopied <= 0 or nCopied > cchFilePath: + raise ctypes.WinError() + return lpszFilePath.value + +def GetFinalPathNameByHandleW(hFile, dwFlags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS): + _GetFinalPathNameByHandleW = windll.kernel32.GetFinalPathNameByHandleW + _GetFinalPathNameByHandleW.argtypes = [HANDLE, LPWSTR, DWORD, DWORD] + _GetFinalPathNameByHandleW.restype = DWORD + + cchFilePath = _GetFinalPathNameByHandleW(hFile, None, 0, dwFlags) + if cchFilePath == 0: + raise ctypes.WinError() + lpszFilePath = ctypes.create_unicode_buffer(u'', cchFilePath + 1) + nCopied = _GetFinalPathNameByHandleW(hFile, lpszFilePath, cchFilePath, dwFlags) + if nCopied <= 0 or nCopied > cchFilePath: + raise ctypes.WinError() + return lpszFilePath.value + +GetFinalPathNameByHandle = GuessStringType(GetFinalPathNameByHandleA, GetFinalPathNameByHandleW) + +# DWORD GetFullPathName( +# LPCTSTR lpFileName, +# DWORD nBufferLength, +# LPTSTR lpBuffer, +# LPTSTR* lpFilePart +# ); +def GetFullPathNameA(lpFileName): + _GetFullPathNameA = windll.kernel32.GetFullPathNameA + _GetFullPathNameA.argtypes = [LPSTR, DWORD, LPSTR, POINTER(LPSTR)] + _GetFullPathNameA.restype = DWORD + + nBufferLength = _GetFullPathNameA(lpFileName, 0, None, None) + if nBufferLength <= 0: + raise ctypes.WinError() + lpBuffer = ctypes.create_string_buffer('', nBufferLength + 1) + lpFilePart = LPSTR() + nCopied = _GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, byref(lpFilePart)) + if nCopied > nBufferLength or nCopied == 0: + raise ctypes.WinError() + return lpBuffer.value, lpFilePart.value + +def GetFullPathNameW(lpFileName): + _GetFullPathNameW = windll.kernel32.GetFullPathNameW + _GetFullPathNameW.argtypes = [LPWSTR, DWORD, LPWSTR, POINTER(LPWSTR)] + _GetFullPathNameW.restype = DWORD + + nBufferLength = _GetFullPathNameW(lpFileName, 0, None, None) + if nBufferLength <= 0: + raise ctypes.WinError() + lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength + 1) + lpFilePart = LPWSTR() + nCopied = _GetFullPathNameW(lpFileName, nBufferLength, lpBuffer, byref(lpFilePart)) + if nCopied > nBufferLength or nCopied == 0: + raise ctypes.WinError() + return lpBuffer.value, lpFilePart.value + +GetFullPathName = GuessStringType(GetFullPathNameA, GetFullPathNameW) + +# DWORD WINAPI GetTempPath( +# __in DWORD nBufferLength, +# __out LPTSTR lpBuffer +# ); +def GetTempPathA(): + _GetTempPathA = windll.kernel32.GetTempPathA + _GetTempPathA.argtypes = [DWORD, LPSTR] + _GetTempPathA.restype = DWORD + + nBufferLength = _GetTempPathA(0, None) + if nBufferLength <= 0: + raise ctypes.WinError() + lpBuffer = ctypes.create_string_buffer('', nBufferLength) + nCopied = _GetTempPathA(nBufferLength, lpBuffer) + if nCopied > nBufferLength or nCopied == 0: + raise ctypes.WinError() + return lpBuffer.value + +def GetTempPathW(): + _GetTempPathW = windll.kernel32.GetTempPathW + _GetTempPathW.argtypes = [DWORD, LPWSTR] + _GetTempPathW.restype = DWORD + + nBufferLength = _GetTempPathW(0, None) + if nBufferLength <= 0: + raise ctypes.WinError() + lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength) + nCopied = _GetTempPathW(nBufferLength, lpBuffer) + if nCopied > nBufferLength or nCopied == 0: + raise ctypes.WinError() + return lpBuffer.value + +GetTempPath = GuessStringType(GetTempPathA, GetTempPathW) + +# UINT WINAPI GetTempFileName( +# __in LPCTSTR lpPathName, +# __in LPCTSTR lpPrefixString, +# __in UINT uUnique, +# __out LPTSTR lpTempFileName +# ); +def GetTempFileNameA(lpPathName = None, lpPrefixString = "TMP", uUnique = 0): + _GetTempFileNameA = windll.kernel32.GetTempFileNameA + _GetTempFileNameA.argtypes = [LPSTR, LPSTR, UINT, LPSTR] + _GetTempFileNameA.restype = UINT + + if lpPathName is None: + lpPathName = GetTempPathA() + lpTempFileName = ctypes.create_string_buffer('', MAX_PATH) + uUnique = _GetTempFileNameA(lpPathName, lpPrefixString, uUnique, lpTempFileName) + if uUnique == 0: + raise ctypes.WinError() + return lpTempFileName.value, uUnique + +def GetTempFileNameW(lpPathName = None, lpPrefixString = u"TMP", uUnique = 0): + _GetTempFileNameW = windll.kernel32.GetTempFileNameW + _GetTempFileNameW.argtypes = [LPWSTR, LPWSTR, UINT, LPWSTR] + _GetTempFileNameW.restype = UINT + + if lpPathName is None: + lpPathName = GetTempPathW() + lpTempFileName = ctypes.create_unicode_buffer(u'', MAX_PATH) + uUnique = _GetTempFileNameW(lpPathName, lpPrefixString, uUnique, lpTempFileName) + if uUnique == 0: + raise ctypes.WinError() + return lpTempFileName.value, uUnique + +GetTempFileName = GuessStringType(GetTempFileNameA, GetTempFileNameW) + +# DWORD WINAPI GetCurrentDirectory( +# __in DWORD nBufferLength, +# __out LPTSTR lpBuffer +# ); +def GetCurrentDirectoryA(): + _GetCurrentDirectoryA = windll.kernel32.GetCurrentDirectoryA + _GetCurrentDirectoryA.argtypes = [DWORD, LPSTR] + _GetCurrentDirectoryA.restype = DWORD + + nBufferLength = _GetCurrentDirectoryA(0, None) + if nBufferLength <= 0: + raise ctypes.WinError() + lpBuffer = ctypes.create_string_buffer('', nBufferLength) + nCopied = _GetCurrentDirectoryA(nBufferLength, lpBuffer) + if nCopied > nBufferLength or nCopied == 0: + raise ctypes.WinError() + return lpBuffer.value + +def GetCurrentDirectoryW(): + _GetCurrentDirectoryW = windll.kernel32.GetCurrentDirectoryW + _GetCurrentDirectoryW.argtypes = [DWORD, LPWSTR] + _GetCurrentDirectoryW.restype = DWORD + + nBufferLength = _GetCurrentDirectoryW(0, None) + if nBufferLength <= 0: + raise ctypes.WinError() + lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength) + nCopied = _GetCurrentDirectoryW(nBufferLength, lpBuffer) + if nCopied > nBufferLength or nCopied == 0: + raise ctypes.WinError() + return lpBuffer.value + +GetCurrentDirectory = GuessStringType(GetCurrentDirectoryA, GetCurrentDirectoryW) + +#------------------------------------------------------------------------------ +# Contrl-C handler + +# BOOL WINAPI HandlerRoutine( +# __in DWORD dwCtrlType +# ); +PHANDLER_ROUTINE = ctypes.WINFUNCTYPE(BOOL, DWORD) + +# BOOL WINAPI SetConsoleCtrlHandler( +# __in_opt PHANDLER_ROUTINE HandlerRoutine, +# __in BOOL Add +# ); +def SetConsoleCtrlHandler(HandlerRoutine = None, Add = True): + _SetConsoleCtrlHandler = windll.kernel32.SetConsoleCtrlHandler + _SetConsoleCtrlHandler.argtypes = [PHANDLER_ROUTINE, BOOL] + _SetConsoleCtrlHandler.restype = bool + _SetConsoleCtrlHandler.errcheck = RaiseIfZero + _SetConsoleCtrlHandler(HandlerRoutine, bool(Add)) + # we can't automagically transform Python functions to PHANDLER_ROUTINE + # because a) the actual pointer value is meaningful to the API + # and b) if it gets garbage collected bad things would happen + +# BOOL WINAPI GenerateConsoleCtrlEvent( +# __in DWORD dwCtrlEvent, +# __in DWORD dwProcessGroupId +# ); +def GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId): + _GenerateConsoleCtrlEvent = windll.kernel32.GenerateConsoleCtrlEvent + _GenerateConsoleCtrlEvent.argtypes = [DWORD, DWORD] + _GenerateConsoleCtrlEvent.restype = bool + _GenerateConsoleCtrlEvent.errcheck = RaiseIfZero + _GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId) + +#------------------------------------------------------------------------------ +# Synchronization API + +# XXX NOTE +# +# Instead of waiting forever, we wait for a small period of time and loop. +# This is a workaround for an unwanted behavior of psyco-accelerated code: +# you can't interrupt a blocking call using Ctrl+C, because signal processing +# is only done between C calls. +# +# Also see: bug #2793618 in Psyco project +# http://sourceforge.net/tracker/?func=detail&aid=2793618&group_id=41036&atid=429622 + +# DWORD WINAPI WaitForSingleObject( +# HANDLE hHandle, +# DWORD dwMilliseconds +# ); +def WaitForSingleObject(hHandle, dwMilliseconds = INFINITE): + _WaitForSingleObject = windll.kernel32.WaitForSingleObject + _WaitForSingleObject.argtypes = [HANDLE, DWORD] + _WaitForSingleObject.restype = DWORD + + if not dwMilliseconds and dwMilliseconds != 0: + dwMilliseconds = INFINITE + if dwMilliseconds != INFINITE: + r = _WaitForSingleObject(hHandle, dwMilliseconds) + if r == WAIT_FAILED: + raise ctypes.WinError() + else: + while 1: + r = _WaitForSingleObject(hHandle, 100) + if r == WAIT_FAILED: + raise ctypes.WinError() + if r != WAIT_TIMEOUT: + break + return r + +# DWORD WINAPI WaitForSingleObjectEx( +# HANDLE hHandle, +# DWORD dwMilliseconds, +# BOOL bAlertable +# ); +def WaitForSingleObjectEx(hHandle, dwMilliseconds = INFINITE, bAlertable = True): + _WaitForSingleObjectEx = windll.kernel32.WaitForSingleObjectEx + _WaitForSingleObjectEx.argtypes = [HANDLE, DWORD, BOOL] + _WaitForSingleObjectEx.restype = DWORD + + if not dwMilliseconds and dwMilliseconds != 0: + dwMilliseconds = INFINITE + if dwMilliseconds != INFINITE: + r = _WaitForSingleObjectEx(hHandle, dwMilliseconds, bool(bAlertable)) + if r == WAIT_FAILED: + raise ctypes.WinError() + else: + while 1: + r = _WaitForSingleObjectEx(hHandle, 100, bool(bAlertable)) + if r == WAIT_FAILED: + raise ctypes.WinError() + if r != WAIT_TIMEOUT: + break + return r + +# DWORD WINAPI WaitForMultipleObjects( +# DWORD nCount, +# const HANDLE *lpHandles, +# BOOL bWaitAll, +# DWORD dwMilliseconds +# ); +def WaitForMultipleObjects(handles, bWaitAll = False, dwMilliseconds = INFINITE): + _WaitForMultipleObjects = windll.kernel32.WaitForMultipleObjects + _WaitForMultipleObjects.argtypes = [DWORD, POINTER(HANDLE), BOOL, DWORD] + _WaitForMultipleObjects.restype = DWORD + + if not dwMilliseconds and dwMilliseconds != 0: + dwMilliseconds = INFINITE + nCount = len(handles) + lpHandlesType = HANDLE * nCount + lpHandles = lpHandlesType(*handles) + if dwMilliseconds != INFINITE: + r = _WaitForMultipleObjects(byref(lpHandles), bool(bWaitAll), dwMilliseconds) + if r == WAIT_FAILED: + raise ctypes.WinError() + else: + while 1: + r = _WaitForMultipleObjects(byref(lpHandles), bool(bWaitAll), 100) + if r == WAIT_FAILED: + raise ctypes.WinError() + if r != WAIT_TIMEOUT: + break + return r + +# DWORD WINAPI WaitForMultipleObjectsEx( +# DWORD nCount, +# const HANDLE *lpHandles, +# BOOL bWaitAll, +# DWORD dwMilliseconds, +# BOOL bAlertable +# ); +def WaitForMultipleObjectsEx(handles, bWaitAll = False, dwMilliseconds = INFINITE, bAlertable = True): + _WaitForMultipleObjectsEx = windll.kernel32.WaitForMultipleObjectsEx + _WaitForMultipleObjectsEx.argtypes = [DWORD, POINTER(HANDLE), BOOL, DWORD] + _WaitForMultipleObjectsEx.restype = DWORD + + if not dwMilliseconds and dwMilliseconds != 0: + dwMilliseconds = INFINITE + nCount = len(handles) + lpHandlesType = HANDLE * nCount + lpHandles = lpHandlesType(*handles) + if dwMilliseconds != INFINITE: + r = _WaitForMultipleObjectsEx(byref(lpHandles), bool(bWaitAll), dwMilliseconds, bool(bAlertable)) + if r == WAIT_FAILED: + raise ctypes.WinError() + else: + while 1: + r = _WaitForMultipleObjectsEx(byref(lpHandles), bool(bWaitAll), 100, bool(bAlertable)) + if r == WAIT_FAILED: + raise ctypes.WinError() + if r != WAIT_TIMEOUT: + break + return r + +# HANDLE WINAPI CreateMutex( +# _In_opt_ LPSECURITY_ATTRIBUTES lpMutexAttributes, +# _In_ BOOL bInitialOwner, +# _In_opt_ LPCTSTR lpName +# ); +def CreateMutexA(lpMutexAttributes = None, bInitialOwner = True, lpName = None): + _CreateMutexA = windll.kernel32.CreateMutexA + _CreateMutexA.argtypes = [LPVOID, BOOL, LPSTR] + _CreateMutexA.restype = HANDLE + _CreateMutexA.errcheck = RaiseIfZero + return Handle( _CreateMutexA(lpMutexAttributes, bInitialOwner, lpName) ) + +def CreateMutexW(lpMutexAttributes = None, bInitialOwner = True, lpName = None): + _CreateMutexW = windll.kernel32.CreateMutexW + _CreateMutexW.argtypes = [LPVOID, BOOL, LPWSTR] + _CreateMutexW.restype = HANDLE + _CreateMutexW.errcheck = RaiseIfZero + return Handle( _CreateMutexW(lpMutexAttributes, bInitialOwner, lpName) ) + +CreateMutex = GuessStringType(CreateMutexA, CreateMutexW) + +# HANDLE WINAPI OpenMutex( +# _In_ DWORD dwDesiredAccess, +# _In_ BOOL bInheritHandle, +# _In_ LPCTSTR lpName +# ); +def OpenMutexA(dwDesiredAccess = MUTEX_ALL_ACCESS, bInitialOwner = True, lpName = None): + _OpenMutexA = windll.kernel32.OpenMutexA + _OpenMutexA.argtypes = [DWORD, BOOL, LPSTR] + _OpenMutexA.restype = HANDLE + _OpenMutexA.errcheck = RaiseIfZero + return Handle( _OpenMutexA(lpMutexAttributes, bInitialOwner, lpName) ) + +def OpenMutexW(dwDesiredAccess = MUTEX_ALL_ACCESS, bInitialOwner = True, lpName = None): + _OpenMutexW = windll.kernel32.OpenMutexW + _OpenMutexW.argtypes = [DWORD, BOOL, LPWSTR] + _OpenMutexW.restype = HANDLE + _OpenMutexW.errcheck = RaiseIfZero + return Handle( _OpenMutexW(lpMutexAttributes, bInitialOwner, lpName) ) + +OpenMutex = GuessStringType(OpenMutexA, OpenMutexW) + +# HANDLE WINAPI CreateEvent( +# _In_opt_ LPSECURITY_ATTRIBUTES lpEventAttributes, +# _In_ BOOL bManualReset, +# _In_ BOOL bInitialState, +# _In_opt_ LPCTSTR lpName +# ); +def CreateEventA(lpMutexAttributes = None, bManualReset = False, bInitialState = False, lpName = None): + _CreateEventA = windll.kernel32.CreateEventA + _CreateEventA.argtypes = [LPVOID, BOOL, BOOL, LPSTR] + _CreateEventA.restype = HANDLE + _CreateEventA.errcheck = RaiseIfZero + return Handle( _CreateEventA(lpMutexAttributes, bManualReset, bInitialState, lpName) ) + +def CreateEventW(lpMutexAttributes = None, bManualReset = False, bInitialState = False, lpName = None): + _CreateEventW = windll.kernel32.CreateEventW + _CreateEventW.argtypes = [LPVOID, BOOL, BOOL, LPWSTR] + _CreateEventW.restype = HANDLE + _CreateEventW.errcheck = RaiseIfZero + return Handle( _CreateEventW(lpMutexAttributes, bManualReset, bInitialState, lpName) ) + +CreateEvent = GuessStringType(CreateEventA, CreateEventW) + +# HANDLE WINAPI OpenEvent( +# _In_ DWORD dwDesiredAccess, +# _In_ BOOL bInheritHandle, +# _In_ LPCTSTR lpName +# ); +def OpenEventA(dwDesiredAccess = EVENT_ALL_ACCESS, bInheritHandle = False, lpName = None): + _OpenEventA = windll.kernel32.OpenEventA + _OpenEventA.argtypes = [DWORD, BOOL, LPSTR] + _OpenEventA.restype = HANDLE + _OpenEventA.errcheck = RaiseIfZero + return Handle( _OpenEventA(dwDesiredAccess, bInheritHandle, lpName) ) + +def OpenEventW(dwDesiredAccess = EVENT_ALL_ACCESS, bInheritHandle = False, lpName = None): + _OpenEventW = windll.kernel32.OpenEventW + _OpenEventW.argtypes = [DWORD, BOOL, LPWSTR] + _OpenEventW.restype = HANDLE + _OpenEventW.errcheck = RaiseIfZero + return Handle( _OpenEventW(dwDesiredAccess, bInheritHandle, lpName) ) + +OpenEvent = GuessStringType(OpenEventA, OpenEventW) + +# HANDLE WINAPI CreateSemaphore( +# _In_opt_ LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, +# _In_ LONG lInitialCount, +# _In_ LONG lMaximumCount, +# _In_opt_ LPCTSTR lpName +# ); + +# TODO + +# HANDLE WINAPI OpenSemaphore( +# _In_ DWORD dwDesiredAccess, +# _In_ BOOL bInheritHandle, +# _In_ LPCTSTR lpName +# ); + +# TODO + +# BOOL WINAPI ReleaseMutex( +# _In_ HANDLE hMutex +# ); +def ReleaseMutex(hMutex): + _ReleaseMutex = windll.kernel32.ReleaseMutex + _ReleaseMutex.argtypes = [HANDLE] + _ReleaseMutex.restype = bool + _ReleaseMutex.errcheck = RaiseIfZero + _ReleaseMutex(hMutex) + +# BOOL WINAPI SetEvent( +# _In_ HANDLE hEvent +# ); +def SetEvent(hEvent): + _SetEvent = windll.kernel32.SetEvent + _SetEvent.argtypes = [HANDLE] + _SetEvent.restype = bool + _SetEvent.errcheck = RaiseIfZero + _SetEvent(hEvent) + +# BOOL WINAPI ResetEvent( +# _In_ HANDLE hEvent +# ); +def ResetEvent(hEvent): + _ResetEvent = windll.kernel32.ResetEvent + _ResetEvent.argtypes = [HANDLE] + _ResetEvent.restype = bool + _ResetEvent.errcheck = RaiseIfZero + _ResetEvent(hEvent) + +# BOOL WINAPI PulseEvent( +# _In_ HANDLE hEvent +# ); +def PulseEvent(hEvent): + _PulseEvent = windll.kernel32.PulseEvent + _PulseEvent.argtypes = [HANDLE] + _PulseEvent.restype = bool + _PulseEvent.errcheck = RaiseIfZero + _PulseEvent(hEvent) + +# BOOL WINAPI ReleaseSemaphore( +# _In_ HANDLE hSemaphore, +# _In_ LONG lReleaseCount, +# _Out_opt_ LPLONG lpPreviousCount +# ); + +# TODO + +#------------------------------------------------------------------------------ +# Debug API + +# BOOL WaitForDebugEvent( +# LPDEBUG_EVENT lpDebugEvent, +# DWORD dwMilliseconds +# ); +def WaitForDebugEvent(dwMilliseconds = INFINITE): + _WaitForDebugEvent = windll.kernel32.WaitForDebugEvent + _WaitForDebugEvent.argtypes = [LPDEBUG_EVENT, DWORD] + _WaitForDebugEvent.restype = DWORD + + if not dwMilliseconds and dwMilliseconds != 0: + dwMilliseconds = INFINITE + lpDebugEvent = DEBUG_EVENT() + lpDebugEvent.dwDebugEventCode = 0 + lpDebugEvent.dwProcessId = 0 + lpDebugEvent.dwThreadId = 0 + if dwMilliseconds != INFINITE: + success = _WaitForDebugEvent(byref(lpDebugEvent), dwMilliseconds) + if success == 0: + raise ctypes.WinError() + else: + # this avoids locking the Python GIL for too long + while 1: + success = _WaitForDebugEvent(byref(lpDebugEvent), 100) + if success != 0: + break + code = GetLastError() + if code not in (ERROR_SEM_TIMEOUT, WAIT_TIMEOUT): + raise ctypes.WinError(code) + return lpDebugEvent + +# BOOL ContinueDebugEvent( +# DWORD dwProcessId, +# DWORD dwThreadId, +# DWORD dwContinueStatus +# ); +def ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED): + _ContinueDebugEvent = windll.kernel32.ContinueDebugEvent + _ContinueDebugEvent.argtypes = [DWORD, DWORD, DWORD] + _ContinueDebugEvent.restype = bool + _ContinueDebugEvent.errcheck = RaiseIfZero + _ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus) + +# BOOL WINAPI FlushInstructionCache( +# __in HANDLE hProcess, +# __in LPCVOID lpBaseAddress, +# __in SIZE_T dwSize +# ); +def FlushInstructionCache(hProcess, lpBaseAddress = None, dwSize = 0): + # http://blogs.msdn.com/oldnewthing/archive/2003/12/08/55954.aspx#55958 + _FlushInstructionCache = windll.kernel32.FlushInstructionCache + _FlushInstructionCache.argtypes = [HANDLE, LPVOID, SIZE_T] + _FlushInstructionCache.restype = bool + _FlushInstructionCache.errcheck = RaiseIfZero + _FlushInstructionCache(hProcess, lpBaseAddress, dwSize) + +# BOOL DebugActiveProcess( +# DWORD dwProcessId +# ); +def DebugActiveProcess(dwProcessId): + _DebugActiveProcess = windll.kernel32.DebugActiveProcess + _DebugActiveProcess.argtypes = [DWORD] + _DebugActiveProcess.restype = bool + _DebugActiveProcess.errcheck = RaiseIfZero + _DebugActiveProcess(dwProcessId) + +# BOOL DebugActiveProcessStop( +# DWORD dwProcessId +# ); +def DebugActiveProcessStop(dwProcessId): + _DebugActiveProcessStop = windll.kernel32.DebugActiveProcessStop + _DebugActiveProcessStop.argtypes = [DWORD] + _DebugActiveProcessStop.restype = bool + _DebugActiveProcessStop.errcheck = RaiseIfZero + _DebugActiveProcessStop(dwProcessId) + +# BOOL CheckRemoteDebuggerPresent( +# HANDLE hProcess, +# PBOOL pbDebuggerPresent +# ); +def CheckRemoteDebuggerPresent(hProcess): + _CheckRemoteDebuggerPresent = windll.kernel32.CheckRemoteDebuggerPresent + _CheckRemoteDebuggerPresent.argtypes = [HANDLE, PBOOL] + _CheckRemoteDebuggerPresent.restype = bool + _CheckRemoteDebuggerPresent.errcheck = RaiseIfZero + + pbDebuggerPresent = BOOL(0) + _CheckRemoteDebuggerPresent(hProcess, byref(pbDebuggerPresent)) + return bool(pbDebuggerPresent.value) + +# BOOL DebugSetProcessKillOnExit( +# BOOL KillOnExit +# ); +def DebugSetProcessKillOnExit(KillOnExit): + _DebugSetProcessKillOnExit = windll.kernel32.DebugSetProcessKillOnExit + _DebugSetProcessKillOnExit.argtypes = [BOOL] + _DebugSetProcessKillOnExit.restype = bool + _DebugSetProcessKillOnExit.errcheck = RaiseIfZero + _DebugSetProcessKillOnExit(bool(KillOnExit)) + +# BOOL DebugBreakProcess( +# HANDLE Process +# ); +def DebugBreakProcess(hProcess): + _DebugBreakProcess = windll.kernel32.DebugBreakProcess + _DebugBreakProcess.argtypes = [HANDLE] + _DebugBreakProcess.restype = bool + _DebugBreakProcess.errcheck = RaiseIfZero + _DebugBreakProcess(hProcess) + +# void WINAPI OutputDebugString( +# __in_opt LPCTSTR lpOutputString +# ); +def OutputDebugStringA(lpOutputString): + _OutputDebugStringA = windll.kernel32.OutputDebugStringA + _OutputDebugStringA.argtypes = [LPSTR] + _OutputDebugStringA.restype = None + _OutputDebugStringA(lpOutputString) + +def OutputDebugStringW(lpOutputString): + _OutputDebugStringW = windll.kernel32.OutputDebugStringW + _OutputDebugStringW.argtypes = [LPWSTR] + _OutputDebugStringW.restype = None + _OutputDebugStringW(lpOutputString) + +OutputDebugString = GuessStringType(OutputDebugStringA, OutputDebugStringW) + +# BOOL WINAPI ReadProcessMemory( +# __in HANDLE hProcess, +# __in LPCVOID lpBaseAddress, +# __out LPVOID lpBuffer, +# __in SIZE_T nSize, +# __out SIZE_T* lpNumberOfBytesRead +# ); +def ReadProcessMemory(hProcess, lpBaseAddress, nSize): + _ReadProcessMemory = windll.kernel32.ReadProcessMemory + _ReadProcessMemory.argtypes = [HANDLE, LPVOID, LPVOID, SIZE_T, POINTER(SIZE_T)] + _ReadProcessMemory.restype = bool + + lpBuffer = ctypes.create_string_buffer(compat.b(''), nSize) + lpNumberOfBytesRead = SIZE_T(0) + success = _ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, byref(lpNumberOfBytesRead)) + if not success and GetLastError() != ERROR_PARTIAL_COPY: + raise ctypes.WinError() + return compat.b(lpBuffer.raw)[:lpNumberOfBytesRead.value] + +# BOOL WINAPI WriteProcessMemory( +# __in HANDLE hProcess, +# __in LPCVOID lpBaseAddress, +# __in LPVOID lpBuffer, +# __in SIZE_T nSize, +# __out SIZE_T* lpNumberOfBytesWritten +# ); +def WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer): + _WriteProcessMemory = windll.kernel32.WriteProcessMemory + _WriteProcessMemory.argtypes = [HANDLE, LPVOID, LPVOID, SIZE_T, POINTER(SIZE_T)] + _WriteProcessMemory.restype = bool + + nSize = len(lpBuffer) + lpBuffer = ctypes.create_string_buffer(lpBuffer) + lpNumberOfBytesWritten = SIZE_T(0) + success = _WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, byref(lpNumberOfBytesWritten)) + if not success and GetLastError() != ERROR_PARTIAL_COPY: + raise ctypes.WinError() + return lpNumberOfBytesWritten.value + +# LPVOID WINAPI VirtualAllocEx( +# __in HANDLE hProcess, +# __in_opt LPVOID lpAddress, +# __in SIZE_T dwSize, +# __in DWORD flAllocationType, +# __in DWORD flProtect +# ); +def VirtualAllocEx(hProcess, lpAddress = 0, dwSize = 0x1000, flAllocationType = MEM_COMMIT | MEM_RESERVE, flProtect = PAGE_EXECUTE_READWRITE): + _VirtualAllocEx = windll.kernel32.VirtualAllocEx + _VirtualAllocEx.argtypes = [HANDLE, LPVOID, SIZE_T, DWORD, DWORD] + _VirtualAllocEx.restype = LPVOID + + lpAddress = _VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect) + if lpAddress == NULL: + raise ctypes.WinError() + return lpAddress + +# SIZE_T WINAPI VirtualQueryEx( +# __in HANDLE hProcess, +# __in_opt LPCVOID lpAddress, +# __out PMEMORY_BASIC_INFORMATION lpBuffer, +# __in SIZE_T dwLength +# ); +def VirtualQueryEx(hProcess, lpAddress): + _VirtualQueryEx = windll.kernel32.VirtualQueryEx + _VirtualQueryEx.argtypes = [HANDLE, LPVOID, PMEMORY_BASIC_INFORMATION, SIZE_T] + _VirtualQueryEx.restype = SIZE_T + + lpBuffer = MEMORY_BASIC_INFORMATION() + dwLength = sizeof(MEMORY_BASIC_INFORMATION) + success = _VirtualQueryEx(hProcess, lpAddress, byref(lpBuffer), dwLength) + if success == 0: + raise ctypes.WinError() + return MemoryBasicInformation(lpBuffer) + +# BOOL WINAPI VirtualProtectEx( +# __in HANDLE hProcess, +# __in LPVOID lpAddress, +# __in SIZE_T dwSize, +# __in DWORD flNewProtect, +# __out PDWORD lpflOldProtect +# ); +def VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect = PAGE_EXECUTE_READWRITE): + _VirtualProtectEx = windll.kernel32.VirtualProtectEx + _VirtualProtectEx.argtypes = [HANDLE, LPVOID, SIZE_T, DWORD, PDWORD] + _VirtualProtectEx.restype = bool + _VirtualProtectEx.errcheck = RaiseIfZero + + flOldProtect = DWORD(0) + _VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect, byref(flOldProtect)) + return flOldProtect.value + +# BOOL WINAPI VirtualFreeEx( +# __in HANDLE hProcess, +# __in LPVOID lpAddress, +# __in SIZE_T dwSize, +# __in DWORD dwFreeType +# ); +def VirtualFreeEx(hProcess, lpAddress, dwSize = 0, dwFreeType = MEM_RELEASE): + _VirtualFreeEx = windll.kernel32.VirtualFreeEx + _VirtualFreeEx.argtypes = [HANDLE, LPVOID, SIZE_T, DWORD] + _VirtualFreeEx.restype = bool + _VirtualFreeEx.errcheck = RaiseIfZero + _VirtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) + +# HANDLE WINAPI CreateRemoteThread( +# __in HANDLE hProcess, +# __in LPSECURITY_ATTRIBUTES lpThreadAttributes, +# __in SIZE_T dwStackSize, +# __in LPTHREAD_START_ROUTINE lpStartAddress, +# __in LPVOID lpParameter, +# __in DWORD dwCreationFlags, +# __out LPDWORD lpThreadId +# ); +def CreateRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags): + _CreateRemoteThread = windll.kernel32.CreateRemoteThread + _CreateRemoteThread.argtypes = [HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPVOID, LPVOID, DWORD, LPDWORD] + _CreateRemoteThread.restype = HANDLE + + if not lpThreadAttributes: + lpThreadAttributes = None + else: + lpThreadAttributes = byref(lpThreadAttributes) + dwThreadId = DWORD(0) + hThread = _CreateRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, byref(dwThreadId)) + if not hThread: + raise ctypes.WinError() + return ThreadHandle(hThread), dwThreadId.value + +#------------------------------------------------------------------------------ +# Process API + +# BOOL WINAPI CreateProcess( +# __in_opt LPCTSTR lpApplicationName, +# __inout_opt LPTSTR lpCommandLine, +# __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, +# __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, +# __in BOOL bInheritHandles, +# __in DWORD dwCreationFlags, +# __in_opt LPVOID lpEnvironment, +# __in_opt LPCTSTR lpCurrentDirectory, +# __in LPSTARTUPINFO lpStartupInfo, +# __out LPPROCESS_INFORMATION lpProcessInformation +# ); +def CreateProcessA(lpApplicationName, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None): + _CreateProcessA = windll.kernel32.CreateProcessA + _CreateProcessA.argtypes = [LPSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPSTR, LPVOID, LPPROCESS_INFORMATION] + _CreateProcessA.restype = bool + _CreateProcessA.errcheck = RaiseIfZero + + if not lpApplicationName: + lpApplicationName = None + if not lpCommandLine: + lpCommandLine = None + else: + lpCommandLine = ctypes.create_string_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine))) + if not lpEnvironment: + lpEnvironment = None + else: + lpEnvironment = ctypes.create_string_buffer(lpEnvironment) + if not lpCurrentDirectory: + lpCurrentDirectory = None + if not lpProcessAttributes: + lpProcessAttributes = None + else: + lpProcessAttributes = byref(lpProcessAttributes) + if not lpThreadAttributes: + lpThreadAttributes = None + else: + lpThreadAttributes = byref(lpThreadAttributes) + if not lpStartupInfo: + lpStartupInfo = STARTUPINFO() + lpStartupInfo.cb = sizeof(STARTUPINFO) + lpStartupInfo.lpReserved = 0 + lpStartupInfo.lpDesktop = 0 + lpStartupInfo.lpTitle = 0 + lpStartupInfo.dwFlags = 0 + lpStartupInfo.cbReserved2 = 0 + lpStartupInfo.lpReserved2 = 0 + lpProcessInformation = PROCESS_INFORMATION() + lpProcessInformation.hProcess = INVALID_HANDLE_VALUE + lpProcessInformation.hThread = INVALID_HANDLE_VALUE + lpProcessInformation.dwProcessId = 0 + lpProcessInformation.dwThreadId = 0 + _CreateProcessA(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) + return ProcessInformation(lpProcessInformation) + +def CreateProcessW(lpApplicationName, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None): + _CreateProcessW = windll.kernel32.CreateProcessW + _CreateProcessW.argtypes = [LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] + _CreateProcessW.restype = bool + _CreateProcessW.errcheck = RaiseIfZero + + if not lpApplicationName: + lpApplicationName = None + if not lpCommandLine: + lpCommandLine = None + else: + lpCommandLine = ctypes.create_unicode_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine))) + if not lpEnvironment: + lpEnvironment = None + else: + lpEnvironment = ctypes.create_unicode_buffer(lpEnvironment) + if not lpCurrentDirectory: + lpCurrentDirectory = None + if not lpProcessAttributes: + lpProcessAttributes = None + else: + lpProcessAttributes = byref(lpProcessAttributes) + if not lpThreadAttributes: + lpThreadAttributes = None + else: + lpThreadAttributes = byref(lpThreadAttributes) + if not lpStartupInfo: + lpStartupInfo = STARTUPINFO() + lpStartupInfo.cb = sizeof(STARTUPINFO) + lpStartupInfo.lpReserved = 0 + lpStartupInfo.lpDesktop = 0 + lpStartupInfo.lpTitle = 0 + lpStartupInfo.dwFlags = 0 + lpStartupInfo.cbReserved2 = 0 + lpStartupInfo.lpReserved2 = 0 + lpProcessInformation = PROCESS_INFORMATION() + lpProcessInformation.hProcess = INVALID_HANDLE_VALUE + lpProcessInformation.hThread = INVALID_HANDLE_VALUE + lpProcessInformation.dwProcessId = 0 + lpProcessInformation.dwThreadId = 0 + _CreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) + return ProcessInformation(lpProcessInformation) + +CreateProcess = GuessStringType(CreateProcessA, CreateProcessW) + +# BOOL WINAPI InitializeProcThreadAttributeList( +# __out_opt LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, +# __in DWORD dwAttributeCount, +# __reserved DWORD dwFlags, +# __inout PSIZE_T lpSize +# ); +def InitializeProcThreadAttributeList(dwAttributeCount): + _InitializeProcThreadAttributeList = windll.kernel32.InitializeProcThreadAttributeList + _InitializeProcThreadAttributeList.argtypes = [LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T] + _InitializeProcThreadAttributeList.restype = bool + + Size = SIZE_T(0) + _InitializeProcThreadAttributeList(None, dwAttributeCount, 0, byref(Size)) + RaiseIfZero(Size.value) + AttributeList = (BYTE * Size.value)() + success = _InitializeProcThreadAttributeList(byref(AttributeList), dwAttributeCount, 0, byref(Size)) + RaiseIfZero(success) + return AttributeList + +# BOOL WINAPI UpdateProcThreadAttribute( +# __inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, +# __in DWORD dwFlags, +# __in DWORD_PTR Attribute, +# __in PVOID lpValue, +# __in SIZE_T cbSize, +# __out_opt PVOID lpPreviousValue, +# __in_opt PSIZE_T lpReturnSize +# ); +def UpdateProcThreadAttribute(lpAttributeList, Attribute, Value, cbSize = None): + _UpdateProcThreadAttribute = windll.kernel32.UpdateProcThreadAttribute + _UpdateProcThreadAttribute.argtypes = [LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T] + _UpdateProcThreadAttribute.restype = bool + _UpdateProcThreadAttribute.errcheck = RaiseIfZero + + if cbSize is None: + cbSize = sizeof(Value) + _UpdateProcThreadAttribute(byref(lpAttributeList), 0, Attribute, byref(Value), cbSize, None, None) + +# VOID WINAPI DeleteProcThreadAttributeList( +# __inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList +# ); +def DeleteProcThreadAttributeList(lpAttributeList): + _DeleteProcThreadAttributeList = windll.kernel32.DeleteProcThreadAttributeList + _DeleteProcThreadAttributeList.restype = None + _DeleteProcThreadAttributeList(byref(lpAttributeList)) + +# HANDLE WINAPI OpenProcess( +# __in DWORD dwDesiredAccess, +# __in BOOL bInheritHandle, +# __in DWORD dwProcessId +# ); +def OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId): + _OpenProcess = windll.kernel32.OpenProcess + _OpenProcess.argtypes = [DWORD, BOOL, DWORD] + _OpenProcess.restype = HANDLE + + hProcess = _OpenProcess(dwDesiredAccess, bool(bInheritHandle), dwProcessId) + if hProcess == NULL: + raise ctypes.WinError() + return ProcessHandle(hProcess, dwAccess = dwDesiredAccess) + +# HANDLE WINAPI OpenThread( +# __in DWORD dwDesiredAccess, +# __in BOOL bInheritHandle, +# __in DWORD dwThreadId +# ); +def OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId): + _OpenThread = windll.kernel32.OpenThread + _OpenThread.argtypes = [DWORD, BOOL, DWORD] + _OpenThread.restype = HANDLE + + hThread = _OpenThread(dwDesiredAccess, bool(bInheritHandle), dwThreadId) + if hThread == NULL: + raise ctypes.WinError() + return ThreadHandle(hThread, dwAccess = dwDesiredAccess) + +# DWORD WINAPI SuspendThread( +# __in HANDLE hThread +# ); +def SuspendThread(hThread): + _SuspendThread = windll.kernel32.SuspendThread + _SuspendThread.argtypes = [HANDLE] + _SuspendThread.restype = DWORD + + previousCount = _SuspendThread(hThread) + if previousCount == DWORD(-1).value: + raise ctypes.WinError() + return previousCount + +# DWORD WINAPI ResumeThread( +# __in HANDLE hThread +# ); +def ResumeThread(hThread): + _ResumeThread = windll.kernel32.ResumeThread + _ResumeThread.argtypes = [HANDLE] + _ResumeThread.restype = DWORD + + previousCount = _ResumeThread(hThread) + if previousCount == DWORD(-1).value: + raise ctypes.WinError() + return previousCount + +# BOOL WINAPI TerminateThread( +# __inout HANDLE hThread, +# __in DWORD dwExitCode +# ); +def TerminateThread(hThread, dwExitCode = 0): + _TerminateThread = windll.kernel32.TerminateThread + _TerminateThread.argtypes = [HANDLE, DWORD] + _TerminateThread.restype = bool + _TerminateThread.errcheck = RaiseIfZero + _TerminateThread(hThread, dwExitCode) + +# BOOL WINAPI TerminateProcess( +# __inout HANDLE hProcess, +# __in DWORD dwExitCode +# ); +def TerminateProcess(hProcess, dwExitCode = 0): + _TerminateProcess = windll.kernel32.TerminateProcess + _TerminateProcess.argtypes = [HANDLE, DWORD] + _TerminateProcess.restype = bool + _TerminateProcess.errcheck = RaiseIfZero + _TerminateProcess(hProcess, dwExitCode) + +# DWORD WINAPI GetCurrentProcessId(void); +def GetCurrentProcessId(): + _GetCurrentProcessId = windll.kernel32.GetCurrentProcessId + _GetCurrentProcessId.argtypes = [] + _GetCurrentProcessId.restype = DWORD + return _GetCurrentProcessId() + +# DWORD WINAPI GetCurrentThreadId(void); +def GetCurrentThreadId(): + _GetCurrentThreadId = windll.kernel32.GetCurrentThreadId + _GetCurrentThreadId.argtypes = [] + _GetCurrentThreadId.restype = DWORD + return _GetCurrentThreadId() + +# DWORD WINAPI GetProcessId( +# __in HANDLE hProcess +# ); +def GetProcessId(hProcess): + _GetProcessId = windll.kernel32.GetProcessId + _GetProcessId.argtypes = [HANDLE] + _GetProcessId.restype = DWORD + _GetProcessId.errcheck = RaiseIfZero + return _GetProcessId(hProcess) + +# DWORD WINAPI GetThreadId( +# __in HANDLE hThread +# ); +def GetThreadId(hThread): + _GetThreadId = windll.kernel32._GetThreadId + _GetThreadId.argtypes = [HANDLE] + _GetThreadId.restype = DWORD + + dwThreadId = _GetThreadId(hThread) + if dwThreadId == 0: + raise ctypes.WinError() + return dwThreadId + +# DWORD WINAPI GetProcessIdOfThread( +# __in HANDLE hThread +# ); +def GetProcessIdOfThread(hThread): + _GetProcessIdOfThread = windll.kernel32.GetProcessIdOfThread + _GetProcessIdOfThread.argtypes = [HANDLE] + _GetProcessIdOfThread.restype = DWORD + + dwProcessId = _GetProcessIdOfThread(hThread) + if dwProcessId == 0: + raise ctypes.WinError() + return dwProcessId + +# BOOL WINAPI GetExitCodeProcess( +# __in HANDLE hProcess, +# __out LPDWORD lpExitCode +# ); +def GetExitCodeProcess(hProcess): + _GetExitCodeProcess = windll.kernel32.GetExitCodeProcess + _GetExitCodeProcess.argtypes = [HANDLE] + _GetExitCodeProcess.restype = bool + _GetExitCodeProcess.errcheck = RaiseIfZero + + lpExitCode = DWORD(0) + _GetExitCodeProcess(hProcess, byref(lpExitCode)) + return lpExitCode.value + +# BOOL WINAPI GetExitCodeThread( +# __in HANDLE hThread, +# __out LPDWORD lpExitCode +# ); +def GetExitCodeThread(hThread): + _GetExitCodeThread = windll.kernel32.GetExitCodeThread + _GetExitCodeThread.argtypes = [HANDLE] + _GetExitCodeThread.restype = bool + _GetExitCodeThread.errcheck = RaiseIfZero + + lpExitCode = DWORD(0) + _GetExitCodeThread(hThread, byref(lpExitCode)) + return lpExitCode.value + +# DWORD WINAPI GetProcessVersion( +# __in DWORD ProcessId +# ); +def GetProcessVersion(ProcessId): + _GetProcessVersion = windll.kernel32.GetProcessVersion + _GetProcessVersion.argtypes = [DWORD] + _GetProcessVersion.restype = DWORD + + retval = _GetProcessVersion(ProcessId) + if retval == 0: + raise ctypes.WinError() + return retval + +# DWORD WINAPI GetPriorityClass( +# __in HANDLE hProcess +# ); +def GetPriorityClass(hProcess): + _GetPriorityClass = windll.kernel32.GetPriorityClass + _GetPriorityClass.argtypes = [HANDLE] + _GetPriorityClass.restype = DWORD + + retval = _GetPriorityClass(hProcess) + if retval == 0: + raise ctypes.WinError() + return retval + +# BOOL WINAPI SetPriorityClass( +# __in HANDLE hProcess, +# __in DWORD dwPriorityClass +# ); +def SetPriorityClass(hProcess, dwPriorityClass = NORMAL_PRIORITY_CLASS): + _SetPriorityClass = windll.kernel32.SetPriorityClass + _SetPriorityClass.argtypes = [HANDLE, DWORD] + _SetPriorityClass.restype = bool + _SetPriorityClass.errcheck = RaiseIfZero + _SetPriorityClass(hProcess, dwPriorityClass) + +# BOOL WINAPI GetProcessPriorityBoost( +# __in HANDLE hProcess, +# __out PBOOL pDisablePriorityBoost +# ); +def GetProcessPriorityBoost(hProcess): + _GetProcessPriorityBoost = windll.kernel32.GetProcessPriorityBoost + _GetProcessPriorityBoost.argtypes = [HANDLE, PBOOL] + _GetProcessPriorityBoost.restype = bool + _GetProcessPriorityBoost.errcheck = RaiseIfZero + + pDisablePriorityBoost = BOOL(False) + _GetProcessPriorityBoost(hProcess, byref(pDisablePriorityBoost)) + return bool(pDisablePriorityBoost.value) + +# BOOL WINAPI SetProcessPriorityBoost( +# __in HANDLE hProcess, +# __in BOOL DisablePriorityBoost +# ); +def SetProcessPriorityBoost(hProcess, DisablePriorityBoost): + _SetProcessPriorityBoost = windll.kernel32.SetProcessPriorityBoost + _SetProcessPriorityBoost.argtypes = [HANDLE, BOOL] + _SetProcessPriorityBoost.restype = bool + _SetProcessPriorityBoost.errcheck = RaiseIfZero + _SetProcessPriorityBoost(hProcess, bool(DisablePriorityBoost)) + +# BOOL WINAPI GetProcessAffinityMask( +# __in HANDLE hProcess, +# __out PDWORD_PTR lpProcessAffinityMask, +# __out PDWORD_PTR lpSystemAffinityMask +# ); +def GetProcessAffinityMask(hProcess): + _GetProcessAffinityMask = windll.kernel32.GetProcessAffinityMask + _GetProcessAffinityMask.argtypes = [HANDLE, PDWORD_PTR, PDWORD_PTR] + _GetProcessAffinityMask.restype = bool + _GetProcessAffinityMask.errcheck = RaiseIfZero + + lpProcessAffinityMask = DWORD_PTR(0) + lpSystemAffinityMask = DWORD_PTR(0) + _GetProcessAffinityMask(hProcess, byref(lpProcessAffinityMask), byref(lpSystemAffinityMask)) + return lpProcessAffinityMask.value, lpSystemAffinityMask.value + +# BOOL WINAPI SetProcessAffinityMask( +# __in HANDLE hProcess, +# __in DWORD_PTR dwProcessAffinityMask +# ); +def SetProcessAffinityMask(hProcess, dwProcessAffinityMask): + _SetProcessAffinityMask = windll.kernel32.SetProcessAffinityMask + _SetProcessAffinityMask.argtypes = [HANDLE, DWORD_PTR] + _SetProcessAffinityMask.restype = bool + _SetProcessAffinityMask.errcheck = RaiseIfZero + _SetProcessAffinityMask(hProcess, dwProcessAffinityMask) + +#------------------------------------------------------------------------------ +# Toolhelp32 API + +# HANDLE WINAPI CreateToolhelp32Snapshot( +# __in DWORD dwFlags, +# __in DWORD th32ProcessID +# ); +def CreateToolhelp32Snapshot(dwFlags = TH32CS_SNAPALL, th32ProcessID = 0): + _CreateToolhelp32Snapshot = windll.kernel32.CreateToolhelp32Snapshot + _CreateToolhelp32Snapshot.argtypes = [DWORD, DWORD] + _CreateToolhelp32Snapshot.restype = HANDLE + + hSnapshot = _CreateToolhelp32Snapshot(dwFlags, th32ProcessID) + if hSnapshot == INVALID_HANDLE_VALUE: + raise ctypes.WinError() + return SnapshotHandle(hSnapshot) + +# BOOL WINAPI Process32First( +# __in HANDLE hSnapshot, +# __inout LPPROCESSENTRY32 lppe +# ); +def Process32First(hSnapshot): + _Process32First = windll.kernel32.Process32First + _Process32First.argtypes = [HANDLE, LPPROCESSENTRY32] + _Process32First.restype = bool + + pe = PROCESSENTRY32() + pe.dwSize = sizeof(PROCESSENTRY32) + success = _Process32First(hSnapshot, byref(pe)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return pe + +# BOOL WINAPI Process32Next( +# __in HANDLE hSnapshot, +# __out LPPROCESSENTRY32 lppe +# ); +def Process32Next(hSnapshot, pe = None): + _Process32Next = windll.kernel32.Process32Next + _Process32Next.argtypes = [HANDLE, LPPROCESSENTRY32] + _Process32Next.restype = bool + + if pe is None: + pe = PROCESSENTRY32() + pe.dwSize = sizeof(PROCESSENTRY32) + success = _Process32Next(hSnapshot, byref(pe)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return pe + +# BOOL WINAPI Thread32First( +# __in HANDLE hSnapshot, +# __inout LPTHREADENTRY32 lpte +# ); +def Thread32First(hSnapshot): + _Thread32First = windll.kernel32.Thread32First + _Thread32First.argtypes = [HANDLE, LPTHREADENTRY32] + _Thread32First.restype = bool + + te = THREADENTRY32() + te.dwSize = sizeof(THREADENTRY32) + success = _Thread32First(hSnapshot, byref(te)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return te + +# BOOL WINAPI Thread32Next( +# __in HANDLE hSnapshot, +# __out LPTHREADENTRY32 lpte +# ); +def Thread32Next(hSnapshot, te = None): + _Thread32Next = windll.kernel32.Thread32Next + _Thread32Next.argtypes = [HANDLE, LPTHREADENTRY32] + _Thread32Next.restype = bool + + if te is None: + te = THREADENTRY32() + te.dwSize = sizeof(THREADENTRY32) + success = _Thread32Next(hSnapshot, byref(te)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return te + +# BOOL WINAPI Module32First( +# __in HANDLE hSnapshot, +# __inout LPMODULEENTRY32 lpme +# ); +def Module32First(hSnapshot): + _Module32First = windll.kernel32.Module32First + _Module32First.argtypes = [HANDLE, LPMODULEENTRY32] + _Module32First.restype = bool + + me = MODULEENTRY32() + me.dwSize = sizeof(MODULEENTRY32) + success = _Module32First(hSnapshot, byref(me)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return me + +# BOOL WINAPI Module32Next( +# __in HANDLE hSnapshot, +# __out LPMODULEENTRY32 lpme +# ); +def Module32Next(hSnapshot, me = None): + _Module32Next = windll.kernel32.Module32Next + _Module32Next.argtypes = [HANDLE, LPMODULEENTRY32] + _Module32Next.restype = bool + + if me is None: + me = MODULEENTRY32() + me.dwSize = sizeof(MODULEENTRY32) + success = _Module32Next(hSnapshot, byref(me)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return me + +# BOOL WINAPI Heap32First( +# __inout LPHEAPENTRY32 lphe, +# __in DWORD th32ProcessID, +# __in ULONG_PTR th32HeapID +# ); +def Heap32First(th32ProcessID, th32HeapID): + _Heap32First = windll.kernel32.Heap32First + _Heap32First.argtypes = [LPHEAPENTRY32, DWORD, ULONG_PTR] + _Heap32First.restype = bool + + he = HEAPENTRY32() + he.dwSize = sizeof(HEAPENTRY32) + success = _Heap32First(byref(he), th32ProcessID, th32HeapID) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return he + +# BOOL WINAPI Heap32Next( +# __out LPHEAPENTRY32 lphe +# ); +def Heap32Next(he): + _Heap32Next = windll.kernel32.Heap32Next + _Heap32Next.argtypes = [LPHEAPENTRY32] + _Heap32Next.restype = bool + + he.dwSize = sizeof(HEAPENTRY32) + success = _Heap32Next(byref(he)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return he + +# BOOL WINAPI Heap32ListFirst( +# __in HANDLE hSnapshot, +# __inout LPHEAPLIST32 lphl +# ); +def Heap32ListFirst(hSnapshot): + _Heap32ListFirst = windll.kernel32.Heap32ListFirst + _Heap32ListFirst.argtypes = [HANDLE, LPHEAPLIST32] + _Heap32ListFirst.restype = bool + + hl = HEAPLIST32() + hl.dwSize = sizeof(HEAPLIST32) + success = _Heap32ListFirst(hSnapshot, byref(hl)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return hl + +# BOOL WINAPI Heap32ListNext( +# __in HANDLE hSnapshot, +# __out LPHEAPLIST32 lphl +# ); +def Heap32ListNext(hSnapshot, hl = None): + _Heap32ListNext = windll.kernel32.Heap32ListNext + _Heap32ListNext.argtypes = [HANDLE, LPHEAPLIST32] + _Heap32ListNext.restype = bool + + if hl is None: + hl = HEAPLIST32() + hl.dwSize = sizeof(HEAPLIST32) + success = _Heap32ListNext(hSnapshot, byref(hl)) + if not success: + if GetLastError() == ERROR_NO_MORE_FILES: + return None + raise ctypes.WinError() + return hl + +# BOOL WINAPI Toolhelp32ReadProcessMemory( +# __in DWORD th32ProcessID, +# __in LPCVOID lpBaseAddress, +# __out LPVOID lpBuffer, +# __in SIZE_T cbRead, +# __out SIZE_T lpNumberOfBytesRead +# ); +def Toolhelp32ReadProcessMemory(th32ProcessID, lpBaseAddress, cbRead): + _Toolhelp32ReadProcessMemory = windll.kernel32.Toolhelp32ReadProcessMemory + _Toolhelp32ReadProcessMemory.argtypes = [DWORD, LPVOID, LPVOID, SIZE_T, POINTER(SIZE_T)] + _Toolhelp32ReadProcessMemory.restype = bool + + lpBuffer = ctypes.create_string_buffer('', cbRead) + lpNumberOfBytesRead = SIZE_T(0) + success = _Toolhelp32ReadProcessMemory(th32ProcessID, lpBaseAddress, lpBuffer, cbRead, byref(lpNumberOfBytesRead)) + if not success and GetLastError() != ERROR_PARTIAL_COPY: + raise ctypes.WinError() + return str(lpBuffer.raw)[:lpNumberOfBytesRead.value] + +#------------------------------------------------------------------------------ +# Miscellaneous system information + +# BOOL WINAPI GetProcessDEPPolicy( +# __in HANDLE hProcess, +# __out LPDWORD lpFlags, +# __out PBOOL lpPermanent +# ); +# Contribution by ivanlef0u (http://ivanlef0u.fr/) +# XP SP3 and > only +def GetProcessDEPPolicy(hProcess): + _GetProcessDEPPolicy = windll.kernel32.GetProcessDEPPolicy + _GetProcessDEPPolicy.argtypes = [HANDLE, LPDWORD, PBOOL] + _GetProcessDEPPolicy.restype = bool + _GetProcessDEPPolicy.errcheck = RaiseIfZero + + lpFlags = DWORD(0) + lpPermanent = BOOL(0) + _GetProcessDEPPolicy(hProcess, byref(lpFlags), byref(lpPermanent)) + return (lpFlags.value, lpPermanent.value) + +# DWORD WINAPI GetCurrentProcessorNumber(void); +def GetCurrentProcessorNumber(): + _GetCurrentProcessorNumber = windll.kernel32.GetCurrentProcessorNumber + _GetCurrentProcessorNumber.argtypes = [] + _GetCurrentProcessorNumber.restype = DWORD + _GetCurrentProcessorNumber.errcheck = RaiseIfZero + return _GetCurrentProcessorNumber() + +# VOID WINAPI FlushProcessWriteBuffers(void); +def FlushProcessWriteBuffers(): + _FlushProcessWriteBuffers = windll.kernel32.FlushProcessWriteBuffers + _FlushProcessWriteBuffers.argtypes = [] + _FlushProcessWriteBuffers.restype = None + _FlushProcessWriteBuffers() + +# BOOL WINAPI GetLogicalProcessorInformation( +# __out PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer, +# __inout PDWORD ReturnLength +# ); + +# TO DO http://msdn.microsoft.com/en-us/library/ms683194(VS.85).aspx + +# BOOL WINAPI GetProcessIoCounters( +# __in HANDLE hProcess, +# __out PIO_COUNTERS lpIoCounters +# ); + +# TO DO http://msdn.microsoft.com/en-us/library/ms683218(VS.85).aspx + +# DWORD WINAPI GetGuiResources( +# __in HANDLE hProcess, +# __in DWORD uiFlags +# ); +def GetGuiResources(hProcess, uiFlags = GR_GDIOBJECTS): + _GetGuiResources = windll.kernel32.GetGuiResources + _GetGuiResources.argtypes = [HANDLE, DWORD] + _GetGuiResources.restype = DWORD + + dwCount = _GetGuiResources(hProcess, uiFlags) + if dwCount == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return dwCount + +# BOOL WINAPI GetProcessHandleCount( +# __in HANDLE hProcess, +# __inout PDWORD pdwHandleCount +# ); +def GetProcessHandleCount(hProcess): + _GetProcessHandleCount = windll.kernel32.GetProcessHandleCount + _GetProcessHandleCount.argtypes = [HANDLE, PDWORD] + _GetProcessHandleCount.restype = DWORD + _GetProcessHandleCount.errcheck = RaiseIfZero + + pdwHandleCount = DWORD(0) + _GetProcessHandleCount(hProcess, byref(pdwHandleCount)) + return pdwHandleCount.value + +# BOOL WINAPI GetProcessTimes( +# __in HANDLE hProcess, +# __out LPFILETIME lpCreationTime, +# __out LPFILETIME lpExitTime, +# __out LPFILETIME lpKernelTime, +# __out LPFILETIME lpUserTime +# ); +def GetProcessTimes(hProcess = None): + _GetProcessTimes = windll.kernel32.GetProcessTimes + _GetProcessTimes.argtypes = [HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME] + _GetProcessTimes.restype = bool + _GetProcessTimes.errcheck = RaiseIfZero + + if hProcess is None: + hProcess = GetCurrentProcess() + + CreationTime = FILETIME() + ExitTime = FILETIME() + KernelTime = FILETIME() + UserTime = FILETIME() + + _GetProcessTimes(hProcess, byref(CreationTime), byref(ExitTime), byref(KernelTime), byref(UserTime)) + + return (CreationTime, ExitTime, KernelTime, UserTime) + +# BOOL WINAPI FileTimeToSystemTime( +# __in const FILETIME *lpFileTime, +# __out LPSYSTEMTIME lpSystemTime +# ); +def FileTimeToSystemTime(lpFileTime): + _FileTimeToSystemTime = windll.kernel32.FileTimeToSystemTime + _FileTimeToSystemTime.argtypes = [LPFILETIME, LPSYSTEMTIME] + _FileTimeToSystemTime.restype = bool + _FileTimeToSystemTime.errcheck = RaiseIfZero + + if isinstance(lpFileTime, FILETIME): + FileTime = lpFileTime + else: + FileTime = FILETIME() + FileTime.dwLowDateTime = lpFileTime & 0xFFFFFFFF + FileTime.dwHighDateTime = lpFileTime >> 32 + SystemTime = SYSTEMTIME() + _FileTimeToSystemTime(byref(FileTime), byref(SystemTime)) + return SystemTime + +# void WINAPI GetSystemTimeAsFileTime( +# __out LPFILETIME lpSystemTimeAsFileTime +# ); +def GetSystemTimeAsFileTime(): + _GetSystemTimeAsFileTime = windll.kernel32.GetSystemTimeAsFileTime + _GetSystemTimeAsFileTime.argtypes = [LPFILETIME] + _GetSystemTimeAsFileTime.restype = None + + FileTime = FILETIME() + _GetSystemTimeAsFileTime(byref(FileTime)) + return FileTime + +#------------------------------------------------------------------------------ +# Global ATOM API + +# ATOM GlobalAddAtom( +# __in LPCTSTR lpString +# ); +def GlobalAddAtomA(lpString): + _GlobalAddAtomA = windll.kernel32.GlobalAddAtomA + _GlobalAddAtomA.argtypes = [LPSTR] + _GlobalAddAtomA.restype = ATOM + _GlobalAddAtomA.errcheck = RaiseIfZero + return _GlobalAddAtomA(lpString) + +def GlobalAddAtomW(lpString): + _GlobalAddAtomW = windll.kernel32.GlobalAddAtomW + _GlobalAddAtomW.argtypes = [LPWSTR] + _GlobalAddAtomW.restype = ATOM + _GlobalAddAtomW.errcheck = RaiseIfZero + return _GlobalAddAtomW(lpString) + +GlobalAddAtom = GuessStringType(GlobalAddAtomA, GlobalAddAtomW) + +# ATOM GlobalFindAtom( +# __in LPCTSTR lpString +# ); +def GlobalFindAtomA(lpString): + _GlobalFindAtomA = windll.kernel32.GlobalFindAtomA + _GlobalFindAtomA.argtypes = [LPSTR] + _GlobalFindAtomA.restype = ATOM + _GlobalFindAtomA.errcheck = RaiseIfZero + return _GlobalFindAtomA(lpString) + +def GlobalFindAtomW(lpString): + _GlobalFindAtomW = windll.kernel32.GlobalFindAtomW + _GlobalFindAtomW.argtypes = [LPWSTR] + _GlobalFindAtomW.restype = ATOM + _GlobalFindAtomW.errcheck = RaiseIfZero + return _GlobalFindAtomW(lpString) + +GlobalFindAtom = GuessStringType(GlobalFindAtomA, GlobalFindAtomW) + +# UINT GlobalGetAtomName( +# __in ATOM nAtom, +# __out LPTSTR lpBuffer, +# __in int nSize +# ); +def GlobalGetAtomNameA(nAtom): + _GlobalGetAtomNameA = windll.kernel32.GlobalGetAtomNameA + _GlobalGetAtomNameA.argtypes = [ATOM, LPSTR, ctypes.c_int] + _GlobalGetAtomNameA.restype = UINT + _GlobalGetAtomNameA.errcheck = RaiseIfZero + + nSize = 64 + while 1: + lpBuffer = ctypes.create_string_buffer("", nSize) + nCopied = _GlobalGetAtomNameA(nAtom, lpBuffer, nSize) + if nCopied < nSize - 1: + break + nSize = nSize + 64 + return lpBuffer.value + +def GlobalGetAtomNameW(nAtom): + _GlobalGetAtomNameW = windll.kernel32.GlobalGetAtomNameW + _GlobalGetAtomNameW.argtypes = [ATOM, LPWSTR, ctypes.c_int] + _GlobalGetAtomNameW.restype = UINT + _GlobalGetAtomNameW.errcheck = RaiseIfZero + + nSize = 64 + while 1: + lpBuffer = ctypes.create_unicode_buffer(u"", nSize) + nCopied = _GlobalGetAtomNameW(nAtom, lpBuffer, nSize) + if nCopied < nSize - 1: + break + nSize = nSize + 64 + return lpBuffer.value + +GlobalGetAtomName = GuessStringType(GlobalGetAtomNameA, GlobalGetAtomNameW) + +# ATOM GlobalDeleteAtom( +# __in ATOM nAtom +# ); +def GlobalDeleteAtom(nAtom): + _GlobalDeleteAtom = windll.kernel32.GlobalDeleteAtom + _GlobalDeleteAtom.argtypes + _GlobalDeleteAtom.restype + SetLastError(ERROR_SUCCESS) + _GlobalDeleteAtom(nAtom) + error = GetLastError() + if error != ERROR_SUCCESS: + raise ctypes.WinError(error) + +#------------------------------------------------------------------------------ +# Wow64 + +# DWORD WINAPI Wow64SuspendThread( +# _In_ HANDLE hThread +# ); +def Wow64SuspendThread(hThread): + _Wow64SuspendThread = windll.kernel32.Wow64SuspendThread + _Wow64SuspendThread.argtypes = [HANDLE] + _Wow64SuspendThread.restype = DWORD + + previousCount = _Wow64SuspendThread(hThread) + if previousCount == DWORD(-1).value: + raise ctypes.WinError() + return previousCount + +# BOOLEAN WINAPI Wow64EnableWow64FsRedirection( +# __in BOOLEAN Wow64FsEnableRedirection +# ); +def Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection): + """ + This function may not work reliably when there are nested calls. Therefore, + this function has been replaced by the L{Wow64DisableWow64FsRedirection} + and L{Wow64RevertWow64FsRedirection} functions. + + @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/aa365744(v=vs.85).aspx} + """ + _Wow64EnableWow64FsRedirection = windll.kernel32.Wow64EnableWow64FsRedirection + _Wow64EnableWow64FsRedirection.argtypes = [BOOLEAN] + _Wow64EnableWow64FsRedirection.restype = BOOLEAN + _Wow64EnableWow64FsRedirection.errcheck = RaiseIfZero + +# BOOL WINAPI Wow64DisableWow64FsRedirection( +# __out PVOID *OldValue +# ); +def Wow64DisableWow64FsRedirection(): + _Wow64DisableWow64FsRedirection = windll.kernel32.Wow64DisableWow64FsRedirection + _Wow64DisableWow64FsRedirection.argtypes = [PPVOID] + _Wow64DisableWow64FsRedirection.restype = BOOL + _Wow64DisableWow64FsRedirection.errcheck = RaiseIfZero + + OldValue = PVOID(None) + _Wow64DisableWow64FsRedirection(byref(OldValue)) + return OldValue + +# BOOL WINAPI Wow64RevertWow64FsRedirection( +# __in PVOID OldValue +# ); +def Wow64RevertWow64FsRedirection(OldValue): + _Wow64RevertWow64FsRedirection = windll.kernel32.Wow64RevertWow64FsRedirection + _Wow64RevertWow64FsRedirection.argtypes = [PVOID] + _Wow64RevertWow64FsRedirection.restype = BOOL + _Wow64RevertWow64FsRedirection.errcheck = RaiseIfZero + _Wow64RevertWow64FsRedirection(OldValue) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== + +#============================================================================== +# Mark functions that Psyco cannot compile. +# In your programs, don't use psyco.full(). +# Call psyco.bind() on your main function instead. + +try: + import psyco + psyco.cannotcompile(WaitForDebugEvent) + psyco.cannotcompile(WaitForSingleObject) + psyco.cannotcompile(WaitForSingleObjectEx) + psyco.cannotcompile(WaitForMultipleObjects) + psyco.cannotcompile(WaitForMultipleObjectsEx) +except ImportError: + pass +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/ntdll.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/ntdll.py new file mode 100644 index 0000000..3903766 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/ntdll.py @@ -0,0 +1,539 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for ntdll.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +_all.add('peb_teb') +#============================================================================== + +from winappdbg.win32.peb_teb import * + +#--- Types -------------------------------------------------------------------- + +SYSDBG_COMMAND = DWORD +PROCESSINFOCLASS = DWORD +THREADINFOCLASS = DWORD +FILE_INFORMATION_CLASS = DWORD + +#--- Constants ---------------------------------------------------------------- + +# DEP flags for ProcessExecuteFlags +MEM_EXECUTE_OPTION_ENABLE = 1 +MEM_EXECUTE_OPTION_DISABLE = 2 +MEM_EXECUTE_OPTION_ATL7_THUNK_EMULATION = 4 +MEM_EXECUTE_OPTION_PERMANENT = 8 + +# SYSTEM_INFORMATION_CLASS +# http://www.informit.com/articles/article.aspx?p=22442&seqNum=4 +SystemBasicInformation = 1 # 0x002C +SystemProcessorInformation = 2 # 0x000C +SystemPerformanceInformation = 3 # 0x0138 +SystemTimeInformation = 4 # 0x0020 +SystemPathInformation = 5 # not implemented +SystemProcessInformation = 6 # 0x00F8 + per process +SystemCallInformation = 7 # 0x0018 + (n * 0x0004) +SystemConfigurationInformation = 8 # 0x0018 +SystemProcessorCounters = 9 # 0x0030 per cpu +SystemGlobalFlag = 10 # 0x0004 +SystemInfo10 = 11 # not implemented +SystemModuleInformation = 12 # 0x0004 + (n * 0x011C) +SystemLockInformation = 13 # 0x0004 + (n * 0x0024) +SystemInfo13 = 14 # not implemented +SystemPagedPoolInformation = 15 # checked build only +SystemNonPagedPoolInformation = 16 # checked build only +SystemHandleInformation = 17 # 0x0004 + (n * 0x0010) +SystemObjectInformation = 18 # 0x0038+ + (n * 0x0030+) +SystemPagefileInformation = 19 # 0x0018+ per page file +SystemInstemulInformation = 20 # 0x0088 +SystemInfo20 = 21 # invalid info class +SystemCacheInformation = 22 # 0x0024 +SystemPoolTagInformation = 23 # 0x0004 + (n * 0x001C) +SystemProcessorStatistics = 24 # 0x0000, or 0x0018 per cpu +SystemDpcInformation = 25 # 0x0014 +SystemMemoryUsageInformation1 = 26 # checked build only +SystemLoadImage = 27 # 0x0018, set mode only +SystemUnloadImage = 28 # 0x0004, set mode only +SystemTimeAdjustmentInformation = 29 # 0x000C, 0x0008 writeable +SystemMemoryUsageInformation2 = 30 # checked build only +SystemInfo30 = 31 # checked build only +SystemInfo31 = 32 # checked build only +SystemCrashDumpInformation = 33 # 0x0004 +SystemExceptionInformation = 34 # 0x0010 +SystemCrashDumpStateInformation = 35 # 0x0008 +SystemDebuggerInformation = 36 # 0x0002 +SystemThreadSwitchInformation = 37 # 0x0030 +SystemRegistryQuotaInformation = 38 # 0x000C +SystemLoadDriver = 39 # 0x0008, set mode only +SystemPrioritySeparationInformation = 40 # 0x0004, set mode only +SystemInfo40 = 41 # not implemented +SystemInfo41 = 42 # not implemented +SystemInfo42 = 43 # invalid info class +SystemInfo43 = 44 # invalid info class +SystemTimeZoneInformation = 45 # 0x00AC +SystemLookasideInformation = 46 # n * 0x0020 +# info classes specific to Windows 2000 +# WTS = Windows Terminal Server +SystemSetTimeSlipEvent = 47 # set mode only +SystemCreateSession = 48 # WTS, set mode only +SystemDeleteSession = 49 # WTS, set mode only +SystemInfo49 = 50 # invalid info class +SystemRangeStartInformation = 51 # 0x0004 +SystemVerifierInformation = 52 # 0x0068 +SystemAddVerifier = 53 # set mode only +SystemSessionProcessesInformation = 54 # WTS + +# NtQueryInformationProcess constants (from MSDN) +##ProcessBasicInformation = 0 +##ProcessDebugPort = 7 +##ProcessWow64Information = 26 +##ProcessImageFileName = 27 + +# PROCESS_INFORMATION_CLASS +# http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Process/PROCESS_INFORMATION_CLASS.html +ProcessBasicInformation = 0 +ProcessQuotaLimits = 1 +ProcessIoCounters = 2 +ProcessVmCounters = 3 +ProcessTimes = 4 +ProcessBasePriority = 5 +ProcessRaisePriority = 6 +ProcessDebugPort = 7 +ProcessExceptionPort = 8 +ProcessAccessToken = 9 +ProcessLdtInformation = 10 +ProcessLdtSize = 11 +ProcessDefaultHardErrorMode = 12 +ProcessIoPortHandlers = 13 +ProcessPooledUsageAndLimits = 14 +ProcessWorkingSetWatch = 15 +ProcessUserModeIOPL = 16 +ProcessEnableAlignmentFaultFixup = 17 +ProcessPriorityClass = 18 +ProcessWx86Information = 19 +ProcessHandleCount = 20 +ProcessAffinityMask = 21 +ProcessPriorityBoost = 22 + +ProcessWow64Information = 26 +ProcessImageFileName = 27 + +# http://www.codeproject.com/KB/security/AntiReverseEngineering.aspx +ProcessDebugObjectHandle = 30 + +ProcessExecuteFlags = 34 + +# THREAD_INFORMATION_CLASS +ThreadBasicInformation = 0 +ThreadTimes = 1 +ThreadPriority = 2 +ThreadBasePriority = 3 +ThreadAffinityMask = 4 +ThreadImpersonationToken = 5 +ThreadDescriptorTableEntry = 6 +ThreadEnableAlignmentFaultFixup = 7 +ThreadEventPair = 8 +ThreadQuerySetWin32StartAddress = 9 +ThreadZeroTlsCell = 10 +ThreadPerformanceCount = 11 +ThreadAmILastThread = 12 +ThreadIdealProcessor = 13 +ThreadPriorityBoost = 14 +ThreadSetTlsArrayAddress = 15 +ThreadIsIoPending = 16 +ThreadHideFromDebugger = 17 + +# OBJECT_INFORMATION_CLASS +ObjectBasicInformation = 0 +ObjectNameInformation = 1 +ObjectTypeInformation = 2 +ObjectAllTypesInformation = 3 +ObjectHandleInformation = 4 + +# FILE_INFORMATION_CLASS +FileDirectoryInformation = 1 +FileFullDirectoryInformation = 2 +FileBothDirectoryInformation = 3 +FileBasicInformation = 4 +FileStandardInformation = 5 +FileInternalInformation = 6 +FileEaInformation = 7 +FileAccessInformation = 8 +FileNameInformation = 9 +FileRenameInformation = 10 +FileLinkInformation = 11 +FileNamesInformation = 12 +FileDispositionInformation = 13 +FilePositionInformation = 14 +FileFullEaInformation = 15 +FileModeInformation = 16 +FileAlignmentInformation = 17 +FileAllInformation = 18 +FileAllocationInformation = 19 +FileEndOfFileInformation = 20 +FileAlternateNameInformation = 21 +FileStreamInformation = 22 +FilePipeInformation = 23 +FilePipeLocalInformation = 24 +FilePipeRemoteInformation = 25 +FileMailslotQueryInformation = 26 +FileMailslotSetInformation = 27 +FileCompressionInformation = 28 +FileCopyOnWriteInformation = 29 +FileCompletionInformation = 30 +FileMoveClusterInformation = 31 +FileQuotaInformation = 32 +FileReparsePointInformation = 33 +FileNetworkOpenInformation = 34 +FileObjectIdInformation = 35 +FileTrackingInformation = 36 +FileOleDirectoryInformation = 37 +FileContentIndexInformation = 38 +FileInheritContentIndexInformation = 37 +FileOleInformation = 39 +FileMaximumInformation = 40 + +# From http://www.nirsoft.net/kernel_struct/vista/EXCEPTION_DISPOSITION.html +# typedef enum _EXCEPTION_DISPOSITION +# { +# ExceptionContinueExecution = 0, +# ExceptionContinueSearch = 1, +# ExceptionNestedException = 2, +# ExceptionCollidedUnwind = 3 +# } EXCEPTION_DISPOSITION; +ExceptionContinueExecution = 0 +ExceptionContinueSearch = 1 +ExceptionNestedException = 2 +ExceptionCollidedUnwind = 3 + +#--- PROCESS_BASIC_INFORMATION structure -------------------------------------- + +# From MSDN: +# +# typedef struct _PROCESS_BASIC_INFORMATION { +# PVOID Reserved1; +# PPEB PebBaseAddress; +# PVOID Reserved2[2]; +# ULONG_PTR UniqueProcessId; +# PVOID Reserved3; +# } PROCESS_BASIC_INFORMATION; +##class PROCESS_BASIC_INFORMATION(Structure): +## _fields_ = [ +## ("Reserved1", PVOID), +## ("PebBaseAddress", PPEB), +## ("Reserved2", PVOID * 2), +## ("UniqueProcessId", ULONG_PTR), +## ("Reserved3", PVOID), +##] + +# From http://catch22.net/tuts/tips2 +# (Only valid for 32 bits) +# +# typedef struct +# { +# ULONG ExitStatus; +# PVOID PebBaseAddress; +# ULONG AffinityMask; +# ULONG BasePriority; +# ULONG_PTR UniqueProcessId; +# ULONG_PTR InheritedFromUniqueProcessId; +# } PROCESS_BASIC_INFORMATION; + +# My own definition follows: +class PROCESS_BASIC_INFORMATION(Structure): + _fields_ = [ + ("ExitStatus", SIZE_T), + ("PebBaseAddress", PVOID), # PPEB + ("AffinityMask", KAFFINITY), + ("BasePriority", SDWORD), + ("UniqueProcessId", ULONG_PTR), + ("InheritedFromUniqueProcessId", ULONG_PTR), +] + +#--- THREAD_BASIC_INFORMATION structure --------------------------------------- + +# From http://undocumented.ntinternals.net/UserMode/Structures/THREAD_BASIC_INFORMATION.html +# +# typedef struct _THREAD_BASIC_INFORMATION { +# NTSTATUS ExitStatus; +# PVOID TebBaseAddress; +# CLIENT_ID ClientId; +# KAFFINITY AffinityMask; +# KPRIORITY Priority; +# KPRIORITY BasePriority; +# } THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION; +class THREAD_BASIC_INFORMATION(Structure): + _fields_ = [ + ("ExitStatus", NTSTATUS), + ("TebBaseAddress", PVOID), # PTEB + ("ClientId", CLIENT_ID), + ("AffinityMask", KAFFINITY), + ("Priority", SDWORD), + ("BasePriority", SDWORD), +] + +#--- FILE_NAME_INFORMATION structure ------------------------------------------ + +# typedef struct _FILE_NAME_INFORMATION { +# ULONG FileNameLength; +# WCHAR FileName[1]; +# } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION; +class FILE_NAME_INFORMATION(Structure): + _fields_ = [ + ("FileNameLength", ULONG), + ("FileName", WCHAR * 1), + ] + +#--- SYSDBG_MSR structure and constants --------------------------------------- + +SysDbgReadMsr = 16 +SysDbgWriteMsr = 17 + +class SYSDBG_MSR(Structure): + _fields_ = [ + ("Address", ULONG), + ("Data", ULONGLONG), +] + +#--- IO_STATUS_BLOCK structure ------------------------------------------------ + +# typedef struct _IO_STATUS_BLOCK { +# union { +# NTSTATUS Status; +# PVOID Pointer; +# }; +# ULONG_PTR Information; +# } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; +class IO_STATUS_BLOCK(Structure): + _fields_ = [ + ("Status", NTSTATUS), + ("Information", ULONG_PTR), + ] + def __get_Pointer(self): + return PVOID(self.Status) + def __set_Pointer(self, ptr): + self.Status = ptr.value + Pointer = property(__get_Pointer, __set_Pointer) + +PIO_STATUS_BLOCK = POINTER(IO_STATUS_BLOCK) + +#--- ntdll.dll ---------------------------------------------------------------- + +# ULONG WINAPI RtlNtStatusToDosError( +# __in NTSTATUS Status +# ); +def RtlNtStatusToDosError(Status): + _RtlNtStatusToDosError = windll.ntdll.RtlNtStatusToDosError + _RtlNtStatusToDosError.argtypes = [NTSTATUS] + _RtlNtStatusToDosError.restype = ULONG + return _RtlNtStatusToDosError(Status) + +# NTSYSAPI NTSTATUS NTAPI NtSystemDebugControl( +# IN SYSDBG_COMMAND Command, +# IN PVOID InputBuffer OPTIONAL, +# IN ULONG InputBufferLength, +# OUT PVOID OutputBuffer OPTIONAL, +# IN ULONG OutputBufferLength, +# OUT PULONG ReturnLength OPTIONAL +# ); +def NtSystemDebugControl(Command, InputBuffer = None, InputBufferLength = None, OutputBuffer = None, OutputBufferLength = None): + _NtSystemDebugControl = windll.ntdll.NtSystemDebugControl + _NtSystemDebugControl.argtypes = [SYSDBG_COMMAND, PVOID, ULONG, PVOID, ULONG, PULONG] + _NtSystemDebugControl.restype = NTSTATUS + + # Validate the input buffer + if InputBuffer is None: + if InputBufferLength is None: + InputBufferLength = 0 + else: + raise ValueError( + "Invalid call to NtSystemDebugControl: " + "input buffer length given but no input buffer!") + else: + if InputBufferLength is None: + InputBufferLength = sizeof(InputBuffer) + InputBuffer = byref(InputBuffer) + + # Validate the output buffer + if OutputBuffer is None: + if OutputBufferLength is None: + OutputBufferLength = 0 + else: + OutputBuffer = ctypes.create_string_buffer("", OutputBufferLength) + elif OutputBufferLength is None: + OutputBufferLength = sizeof(OutputBuffer) + + # Make the call (with an output buffer) + if OutputBuffer is not None: + ReturnLength = ULONG(0) + ntstatus = _NtSystemDebugControl(Command, InputBuffer, InputBufferLength, byref(OutputBuffer), OutputBufferLength, byref(ReturnLength)) + if ntstatus != 0: + raise ctypes.WinError( RtlNtStatusToDosError(ntstatus) ) + ReturnLength = ReturnLength.value + if ReturnLength != OutputBufferLength: + raise ctypes.WinError(ERROR_BAD_LENGTH) + return OutputBuffer, ReturnLength + + # Make the call (without an output buffer) + ntstatus = _NtSystemDebugControl(Command, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength, None) + if ntstatus != 0: + raise ctypes.WinError( RtlNtStatusToDosError(ntstatus) ) + +ZwSystemDebugControl = NtSystemDebugControl + +# NTSTATUS WINAPI NtQueryInformationProcess( +# __in HANDLE ProcessHandle, +# __in PROCESSINFOCLASS ProcessInformationClass, +# __out PVOID ProcessInformation, +# __in ULONG ProcessInformationLength, +# __out_opt PULONG ReturnLength +# ); +def NtQueryInformationProcess(ProcessHandle, ProcessInformationClass, ProcessInformationLength = None): + _NtQueryInformationProcess = windll.ntdll.NtQueryInformationProcess + _NtQueryInformationProcess.argtypes = [HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG] + _NtQueryInformationProcess.restype = NTSTATUS + if ProcessInformationLength is not None: + ProcessInformation = ctypes.create_string_buffer("", ProcessInformationLength) + else: + if ProcessInformationClass == ProcessBasicInformation: + ProcessInformation = PROCESS_BASIC_INFORMATION() + ProcessInformationLength = sizeof(PROCESS_BASIC_INFORMATION) + elif ProcessInformationClass == ProcessImageFileName: + unicode_buffer = ctypes.create_unicode_buffer(u"", 0x1000) + ProcessInformation = UNICODE_STRING(0, 0x1000, addressof(unicode_buffer)) + ProcessInformationLength = sizeof(UNICODE_STRING) + elif ProcessInformationClass in (ProcessDebugPort, ProcessWow64Information, ProcessWx86Information, ProcessHandleCount, ProcessPriorityBoost): + ProcessInformation = DWORD() + ProcessInformationLength = sizeof(DWORD) + else: + raise Exception("Unknown ProcessInformationClass, use an explicit ProcessInformationLength value instead") + ReturnLength = ULONG(0) + ntstatus = _NtQueryInformationProcess(ProcessHandle, ProcessInformationClass, byref(ProcessInformation), ProcessInformationLength, byref(ReturnLength)) + if ntstatus != 0: + raise ctypes.WinError( RtlNtStatusToDosError(ntstatus) ) + if ProcessInformationClass == ProcessBasicInformation: + retval = ProcessInformation + elif ProcessInformationClass in (ProcessDebugPort, ProcessWow64Information, ProcessWx86Information, ProcessHandleCount, ProcessPriorityBoost): + retval = ProcessInformation.value + elif ProcessInformationClass == ProcessImageFileName: + vptr = ctypes.c_void_p(ProcessInformation.Buffer) + cptr = ctypes.cast( vptr, ctypes.c_wchar * ProcessInformation.Length ) + retval = cptr.contents.raw + else: + retval = ProcessInformation.raw[:ReturnLength.value] + return retval + +ZwQueryInformationProcess = NtQueryInformationProcess + +# NTSTATUS WINAPI NtQueryInformationThread( +# __in HANDLE ThreadHandle, +# __in THREADINFOCLASS ThreadInformationClass, +# __out PVOID ThreadInformation, +# __in ULONG ThreadInformationLength, +# __out_opt PULONG ReturnLength +# ); +def NtQueryInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformationLength = None): + _NtQueryInformationThread = windll.ntdll.NtQueryInformationThread + _NtQueryInformationThread.argtypes = [HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG] + _NtQueryInformationThread.restype = NTSTATUS + if ThreadInformationLength is not None: + ThreadInformation = ctypes.create_string_buffer("", ThreadInformationLength) + else: + if ThreadInformationClass == ThreadBasicInformation: + ThreadInformation = THREAD_BASIC_INFORMATION() + elif ThreadInformationClass == ThreadHideFromDebugger: + ThreadInformation = BOOLEAN() + elif ThreadInformationClass == ThreadQuerySetWin32StartAddress: + ThreadInformation = PVOID() + elif ThreadInformationClass in (ThreadAmILastThread, ThreadPriorityBoost): + ThreadInformation = DWORD() + elif ThreadInformationClass == ThreadPerformanceCount: + ThreadInformation = LONGLONG() # LARGE_INTEGER + else: + raise Exception("Unknown ThreadInformationClass, use an explicit ThreadInformationLength value instead") + ThreadInformationLength = sizeof(ThreadInformation) + ReturnLength = ULONG(0) + ntstatus = _NtQueryInformationThread(ThreadHandle, ThreadInformationClass, byref(ThreadInformation), ThreadInformationLength, byref(ReturnLength)) + if ntstatus != 0: + raise ctypes.WinError( RtlNtStatusToDosError(ntstatus) ) + if ThreadInformationClass == ThreadBasicInformation: + retval = ThreadInformation + elif ThreadInformationClass == ThreadHideFromDebugger: + retval = bool(ThreadInformation.value) + elif ThreadInformationClass in (ThreadQuerySetWin32StartAddress, ThreadAmILastThread, ThreadPriorityBoost, ThreadPerformanceCount): + retval = ThreadInformation.value + else: + retval = ThreadInformation.raw[:ReturnLength.value] + return retval + +ZwQueryInformationThread = NtQueryInformationThread + +# NTSTATUS +# NtQueryInformationFile( +# IN HANDLE FileHandle, +# OUT PIO_STATUS_BLOCK IoStatusBlock, +# OUT PVOID FileInformation, +# IN ULONG Length, +# IN FILE_INFORMATION_CLASS FileInformationClass +# ); +def NtQueryInformationFile(FileHandle, FileInformationClass, FileInformation, Length): + _NtQueryInformationFile = windll.ntdll.NtQueryInformationFile + _NtQueryInformationFile.argtypes = [HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, DWORD] + _NtQueryInformationFile.restype = NTSTATUS + IoStatusBlock = IO_STATUS_BLOCK() + ntstatus = _NtQueryInformationFile(FileHandle, byref(IoStatusBlock), byref(FileInformation), Length, FileInformationClass) + if ntstatus != 0: + raise ctypes.WinError( RtlNtStatusToDosError(ntstatus) ) + return IoStatusBlock + +ZwQueryInformationFile = NtQueryInformationFile + +# DWORD STDCALL CsrGetProcessId (VOID); +def CsrGetProcessId(): + _CsrGetProcessId = windll.ntdll.CsrGetProcessId + _CsrGetProcessId.argtypes = [] + _CsrGetProcessId.restype = DWORD + return _CsrGetProcessId() + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/peb_teb.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/peb_teb.py new file mode 100644 index 0000000..9d101c7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/peb_teb.py @@ -0,0 +1,3435 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +PEB and TEB structures, constants and data types. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.version import os + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- PEB and TEB structures, constants and data types ------------------------- + +# From http://www.nirsoft.net/kernel_struct/vista/CLIENT_ID.html +# +# typedef struct _CLIENT_ID +# { +# PVOID UniqueProcess; +# PVOID UniqueThread; +# } CLIENT_ID, *PCLIENT_ID; +class CLIENT_ID(Structure): + _fields_ = [ + ("UniqueProcess", PVOID), + ("UniqueThread", PVOID), +] + +# From MSDN: +# +# typedef struct _LDR_DATA_TABLE_ENTRY { +# BYTE Reserved1[2]; +# LIST_ENTRY InMemoryOrderLinks; +# PVOID Reserved2[2]; +# PVOID DllBase; +# PVOID EntryPoint; +# PVOID Reserved3; +# UNICODE_STRING FullDllName; +# BYTE Reserved4[8]; +# PVOID Reserved5[3]; +# union { +# ULONG CheckSum; +# PVOID Reserved6; +# }; +# ULONG TimeDateStamp; +# } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; +##class LDR_DATA_TABLE_ENTRY(Structure): +## _fields_ = [ +## ("Reserved1", BYTE * 2), +## ("InMemoryOrderLinks", LIST_ENTRY), +## ("Reserved2", PVOID * 2), +## ("DllBase", PVOID), +## ("EntryPoint", PVOID), +## ("Reserved3", PVOID), +## ("FullDllName", UNICODE_STRING), +## ("Reserved4", BYTE * 8), +## ("Reserved5", PVOID * 3), +## ("CheckSum", ULONG), +## ("TimeDateStamp", ULONG), +##] + +# From MSDN: +# +# typedef struct _PEB_LDR_DATA { +# BYTE Reserved1[8]; +# PVOID Reserved2[3]; +# LIST_ENTRY InMemoryOrderModuleList; +# } PEB_LDR_DATA, +# *PPEB_LDR_DATA; +##class PEB_LDR_DATA(Structure): +## _fields_ = [ +## ("Reserved1", BYTE), +## ("Reserved2", PVOID), +## ("InMemoryOrderModuleList", LIST_ENTRY), +##] + +# From http://undocumented.ntinternals.net/UserMode/Structures/RTL_USER_PROCESS_PARAMETERS.html +# typedef struct _RTL_USER_PROCESS_PARAMETERS { +# ULONG MaximumLength; +# ULONG Length; +# ULONG Flags; +# ULONG DebugFlags; +# PVOID ConsoleHandle; +# ULONG ConsoleFlags; +# HANDLE StdInputHandle; +# HANDLE StdOutputHandle; +# HANDLE StdErrorHandle; +# UNICODE_STRING CurrentDirectoryPath; +# HANDLE CurrentDirectoryHandle; +# UNICODE_STRING DllPath; +# UNICODE_STRING ImagePathName; +# UNICODE_STRING CommandLine; +# PVOID Environment; +# ULONG StartingPositionLeft; +# ULONG StartingPositionTop; +# ULONG Width; +# ULONG Height; +# ULONG CharWidth; +# ULONG CharHeight; +# ULONG ConsoleTextAttributes; +# ULONG WindowFlags; +# ULONG ShowWindowFlags; +# UNICODE_STRING WindowTitle; +# UNICODE_STRING DesktopName; +# UNICODE_STRING ShellInfo; +# UNICODE_STRING RuntimeData; +# RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20]; +# } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS; + +# kd> dt _RTL_USER_PROCESS_PARAMETERS +# ntdll!_RTL_USER_PROCESS_PARAMETERS +# +0x000 MaximumLength : Uint4B +# +0x004 Length : Uint4B +# +0x008 Flags : Uint4B +# +0x00c DebugFlags : Uint4B +# +0x010 ConsoleHandle : Ptr32 Void +# +0x014 ConsoleFlags : Uint4B +# +0x018 StandardInput : Ptr32 Void +# +0x01c StandardOutput : Ptr32 Void +# +0x020 StandardError : Ptr32 Void +# +0x024 CurrentDirectory : _CURDIR +# +0x030 DllPath : _UNICODE_STRING +# +0x038 ImagePathName : _UNICODE_STRING +# +0x040 CommandLine : _UNICODE_STRING +# +0x048 Environment : Ptr32 Void +# +0x04c StartingX : Uint4B +# +0x050 StartingY : Uint4B +# +0x054 CountX : Uint4B +# +0x058 CountY : Uint4B +# +0x05c CountCharsX : Uint4B +# +0x060 CountCharsY : Uint4B +# +0x064 FillAttribute : Uint4B +# +0x068 WindowFlags : Uint4B +# +0x06c ShowWindowFlags : Uint4B +# +0x070 WindowTitle : _UNICODE_STRING +# +0x078 DesktopInfo : _UNICODE_STRING +# +0x080 ShellInfo : _UNICODE_STRING +# +0x088 RuntimeData : _UNICODE_STRING +# +0x090 CurrentDirectores : [32] _RTL_DRIVE_LETTER_CURDIR +# +0x290 EnvironmentSize : Uint4B +##class RTL_USER_PROCESS_PARAMETERS(Structure): +## _fields_ = [ +## ("MaximumLength", ULONG), +## ("Length", ULONG), +## ("Flags", ULONG), +## ("DebugFlags", ULONG), +## ("ConsoleHandle", PVOID), +## ("ConsoleFlags", ULONG), +## ("StandardInput", HANDLE), +## ("StandardOutput", HANDLE), +## ("StandardError", HANDLE), +## ("CurrentDirectory", CURDIR), +## ("DllPath", UNICODE_STRING), +## ("ImagePathName", UNICODE_STRING), +## ("CommandLine", UNICODE_STRING), +## ("Environment", PVOID), +## ("StartingX", ULONG), +## ("StartingY", ULONG), +## ("CountX", ULONG), +## ("CountY", ULONG), +## ("CountCharsX", ULONG), +## ("CountCharsY", ULONG), +## ("FillAttribute", ULONG), +## ("WindowFlags", ULONG), +## ("ShowWindowFlags", ULONG), +## ("WindowTitle", UNICODE_STRING), +## ("DesktopInfo", UNICODE_STRING), +## ("ShellInfo", UNICODE_STRING), +## ("RuntimeData", UNICODE_STRING), +## ("CurrentDirectores", RTL_DRIVE_LETTER_CURDIR * 32), # typo here? +## +## # Windows 2008 and Vista +## ("EnvironmentSize", ULONG), +##] +## @property +## def CurrentDirectories(self): +## return self.CurrentDirectores + +# From MSDN: +# +# typedef struct _RTL_USER_PROCESS_PARAMETERS { +# BYTE Reserved1[16]; +# PVOID Reserved2[10]; +# UNICODE_STRING ImagePathName; +# UNICODE_STRING CommandLine; +# } RTL_USER_PROCESS_PARAMETERS, +# *PRTL_USER_PROCESS_PARAMETERS; +class RTL_USER_PROCESS_PARAMETERS(Structure): + _fields_ = [ + ("Reserved1", BYTE * 16), + ("Reserved2", PVOID * 10), + ("ImagePathName", UNICODE_STRING), + ("CommandLine", UNICODE_STRING), + ("Environment", PVOID), # undocumented! + # + # XXX TODO + # This structure should be defined with all undocumented fields for + # each version of Windows, just like it's being done for PEB and TEB. + # +] + +PPS_POST_PROCESS_INIT_ROUTINE = PVOID + +#from MSDN: +# +# typedef struct _PEB { +# BYTE Reserved1[2]; +# BYTE BeingDebugged; +# BYTE Reserved2[21]; +# PPEB_LDR_DATA LoaderData; +# PRTL_USER_PROCESS_PARAMETERS ProcessParameters; +# BYTE Reserved3[520]; +# PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine; +# BYTE Reserved4[136]; +# ULONG SessionId; +# } PEB; +##class PEB(Structure): +## _fields_ = [ +## ("Reserved1", BYTE * 2), +## ("BeingDebugged", BYTE), +## ("Reserved2", BYTE * 21), +## ("LoaderData", PVOID, # PPEB_LDR_DATA +## ("ProcessParameters", PVOID, # PRTL_USER_PROCESS_PARAMETERS +## ("Reserved3", BYTE * 520), +## ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), +## ("Reserved4", BYTE), +## ("SessionId", ULONG), +##] + +# from MSDN: +# +# typedef struct _TEB { +# BYTE Reserved1[1952]; +# PVOID Reserved2[412]; +# PVOID TlsSlots[64]; +# BYTE Reserved3[8]; +# PVOID Reserved4[26]; +# PVOID ReservedForOle; +# PVOID Reserved5[4]; +# PVOID TlsExpansionSlots; +# } TEB, +# *PTEB; +##class TEB(Structure): +## _fields_ = [ +## ("Reserved1", PVOID * 1952), +## ("Reserved2", PVOID * 412), +## ("TlsSlots", PVOID * 64), +## ("Reserved3", BYTE * 8), +## ("Reserved4", PVOID * 26), +## ("ReservedForOle", PVOID), +## ("Reserved5", PVOID * 4), +## ("TlsExpansionSlots", PVOID), +##] + +# from http://undocumented.ntinternals.net/UserMode/Structures/LDR_MODULE.html +# +# typedef struct _LDR_MODULE { +# LIST_ENTRY InLoadOrderModuleList; +# LIST_ENTRY InMemoryOrderModuleList; +# LIST_ENTRY InInitializationOrderModuleList; +# PVOID BaseAddress; +# PVOID EntryPoint; +# ULONG SizeOfImage; +# UNICODE_STRING FullDllName; +# UNICODE_STRING BaseDllName; +# ULONG Flags; +# SHORT LoadCount; +# SHORT TlsIndex; +# LIST_ENTRY HashTableEntry; +# ULONG TimeDateStamp; +# } LDR_MODULE, *PLDR_MODULE; +class LDR_MODULE(Structure): + _fields_ = [ + ("InLoadOrderModuleList", LIST_ENTRY), + ("InMemoryOrderModuleList", LIST_ENTRY), + ("InInitializationOrderModuleList", LIST_ENTRY), + ("BaseAddress", PVOID), + ("EntryPoint", PVOID), + ("SizeOfImage", ULONG), + ("FullDllName", UNICODE_STRING), + ("BaseDllName", UNICODE_STRING), + ("Flags", ULONG), + ("LoadCount", SHORT), + ("TlsIndex", SHORT), + ("HashTableEntry", LIST_ENTRY), + ("TimeDateStamp", ULONG), +] + +# from http://undocumented.ntinternals.net/UserMode/Structures/PEB_LDR_DATA.html +# +# typedef struct _PEB_LDR_DATA { +# ULONG Length; +# BOOLEAN Initialized; +# PVOID SsHandle; +# LIST_ENTRY InLoadOrderModuleList; +# LIST_ENTRY InMemoryOrderModuleList; +# LIST_ENTRY InInitializationOrderModuleList; +# } PEB_LDR_DATA, *PPEB_LDR_DATA; +class PEB_LDR_DATA(Structure): + _fields_ = [ + ("Length", ULONG), + ("Initialized", BOOLEAN), + ("SsHandle", PVOID), + ("InLoadOrderModuleList", LIST_ENTRY), + ("InMemoryOrderModuleList", LIST_ENTRY), + ("InInitializationOrderModuleList", LIST_ENTRY), +] + +# From http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Process/PEB_FREE_BLOCK.html +# +# typedef struct _PEB_FREE_BLOCK { +# PEB_FREE_BLOCK *Next; +# ULONG Size; +# } PEB_FREE_BLOCK, *PPEB_FREE_BLOCK; +class PEB_FREE_BLOCK(Structure): + pass + +##PPEB_FREE_BLOCK = POINTER(PEB_FREE_BLOCK) +PPEB_FREE_BLOCK = PVOID + +PEB_FREE_BLOCK._fields_ = [ + ("Next", PPEB_FREE_BLOCK), + ("Size", ULONG), +] + +# From http://undocumented.ntinternals.net/UserMode/Structures/RTL_DRIVE_LETTER_CURDIR.html +# +# typedef struct _RTL_DRIVE_LETTER_CURDIR { +# USHORT Flags; +# USHORT Length; +# ULONG TimeStamp; +# UNICODE_STRING DosPath; +# } RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR; +class RTL_DRIVE_LETTER_CURDIR(Structure): + _fields_ = [ + ("Flags", USHORT), + ("Length", USHORT), + ("TimeStamp", ULONG), + ("DosPath", UNICODE_STRING), +] + +# From http://www.nirsoft.net/kernel_struct/vista/CURDIR.html +# +# typedef struct _CURDIR +# { +# UNICODE_STRING DosPath; +# PVOID Handle; +# } CURDIR, *PCURDIR; +class CURDIR(Structure): + _fields_ = [ + ("DosPath", UNICODE_STRING), + ("Handle", PVOID), +] + +# From http://www.nirsoft.net/kernel_struct/vista/RTL_CRITICAL_SECTION_DEBUG.html +# +# typedef struct _RTL_CRITICAL_SECTION_DEBUG +# { +# WORD Type; +# WORD CreatorBackTraceIndex; +# PRTL_CRITICAL_SECTION CriticalSection; +# LIST_ENTRY ProcessLocksList; +# ULONG EntryCount; +# ULONG ContentionCount; +# ULONG Flags; +# WORD CreatorBackTraceIndexHigh; +# WORD SpareUSHORT; +# } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG; +# +# From http://www.nirsoft.net/kernel_struct/vista/RTL_CRITICAL_SECTION.html +# +# typedef struct _RTL_CRITICAL_SECTION +# { +# PRTL_CRITICAL_SECTION_DEBUG DebugInfo; +# LONG LockCount; +# LONG RecursionCount; +# PVOID OwningThread; +# PVOID LockSemaphore; +# ULONG SpinCount; +# } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION; +# +class RTL_CRITICAL_SECTION(Structure): + _fields_ = [ + ("DebugInfo", PVOID), # PRTL_CRITICAL_SECTION_DEBUG + ("LockCount", LONG), + ("RecursionCount", LONG), + ("OwningThread", PVOID), + ("LockSemaphore", PVOID), + ("SpinCount", ULONG), +] +class RTL_CRITICAL_SECTION_DEBUG(Structure): + _fields_ = [ + ("Type", WORD), + ("CreatorBackTraceIndex", WORD), + ("CriticalSection", PVOID), # PRTL_CRITICAL_SECTION + ("ProcessLocksList", LIST_ENTRY), + ("EntryCount", ULONG), + ("ContentionCount", ULONG), + ("Flags", ULONG), + ("CreatorBackTraceIndexHigh", WORD), + ("SpareUSHORT", WORD), +] +PRTL_CRITICAL_SECTION = POINTER(RTL_CRITICAL_SECTION) +PRTL_CRITICAL_SECTION_DEBUG = POINTER(RTL_CRITICAL_SECTION_DEBUG) + +PPEB_LDR_DATA = POINTER(PEB_LDR_DATA) +PRTL_USER_PROCESS_PARAMETERS = POINTER(RTL_USER_PROCESS_PARAMETERS) + +PPEBLOCKROUTINE = PVOID + +# BitField +ImageUsesLargePages = 1 << 0 +IsProtectedProcess = 1 << 1 +IsLegacyProcess = 1 << 2 +IsImageDynamicallyRelocated = 1 << 3 +SkipPatchingUser32Forwarders = 1 << 4 + +# CrossProcessFlags +ProcessInJob = 1 << 0 +ProcessInitializing = 1 << 1 +ProcessUsingVEH = 1 << 2 +ProcessUsingVCH = 1 << 3 +ProcessUsingFTH = 1 << 4 + +# TracingFlags +HeapTracingEnabled = 1 << 0 +CritSecTracingEnabled = 1 << 1 + +# NtGlobalFlags +FLG_VALID_BITS = 0x003FFFFF # not a flag +FLG_STOP_ON_EXCEPTION = 0x00000001 +FLG_SHOW_LDR_SNAPS = 0x00000002 +FLG_DEBUG_INITIAL_COMMAND = 0x00000004 +FLG_STOP_ON_HUNG_GUI = 0x00000008 +FLG_HEAP_ENABLE_TAIL_CHECK = 0x00000010 +FLG_HEAP_ENABLE_FREE_CHECK = 0x00000020 +FLG_HEAP_VALIDATE_PARAMETERS = 0x00000040 +FLG_HEAP_VALIDATE_ALL = 0x00000080 +FLG_POOL_ENABLE_TAIL_CHECK = 0x00000100 +FLG_POOL_ENABLE_FREE_CHECK = 0x00000200 +FLG_POOL_ENABLE_TAGGING = 0x00000400 +FLG_HEAP_ENABLE_TAGGING = 0x00000800 +FLG_USER_STACK_TRACE_DB = 0x00001000 +FLG_KERNEL_STACK_TRACE_DB = 0x00002000 +FLG_MAINTAIN_OBJECT_TYPELIST = 0x00004000 +FLG_HEAP_ENABLE_TAG_BY_DLL = 0x00008000 +FLG_IGNORE_DEBUG_PRIV = 0x00010000 +FLG_ENABLE_CSRDEBUG = 0x00020000 +FLG_ENABLE_KDEBUG_SYMBOL_LOAD = 0x00040000 +FLG_DISABLE_PAGE_KERNEL_STACKS = 0x00080000 +FLG_HEAP_ENABLE_CALL_TRACING = 0x00100000 +FLG_HEAP_DISABLE_COALESCING = 0x00200000 +FLG_ENABLE_CLOSE_EXCEPTION = 0x00400000 +FLG_ENABLE_EXCEPTION_LOGGING = 0x00800000 +FLG_ENABLE_HANDLE_TYPE_TAGGING = 0x01000000 +FLG_HEAP_PAGE_ALLOCS = 0x02000000 +FLG_DEBUG_WINLOGON = 0x04000000 +FLG_ENABLE_DBGPRINT_BUFFERING = 0x08000000 +FLG_EARLY_CRITICAL_SECTION_EVT = 0x10000000 +FLG_DISABLE_DLL_VERIFICATION = 0x80000000 + +class _PEB_NT(Structure): + _pack_ = 4 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), + ("FastPebLockRoutine", PVOID), # PPEBLOCKROUTINE + ("FastPebUnlockRoutine", PVOID), # PPEBLOCKROUTINE + ("EnvironmentUpdateCount", ULONG), + ("KernelCallbackTable", PVOID), # Ptr32 Ptr32 Void + ("EventLogSection", PVOID), + ("EventLog", PVOID), + ("FreeList", PVOID), # PPEB_FREE_BLOCK + ("TlsExpansionCounter", ULONG), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", ULONG * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("ReadOnlySharedMemoryHeap", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", ULONG), + ("NtGlobalFlag", ULONG), + ("Spare2", BYTE * 4), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", ULONG), + ("HeapSegmentCommit", ULONG), + ("HeapDeCommitTotalFreeThreshold", ULONG), + ("HeapDeCommitFreeBlockThreshold", ULONG), + ("NumberOfHeaps", ULONG), + ("MaximumNumberOfHeaps", ULONG), + ("ProcessHeaps", PVOID), # Ptr32 Ptr32 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", PVOID), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", ULONG), + ("OSMinorVersion", ULONG), + ("OSBuildNumber", ULONG), + ("OSPlatformId", ULONG), + ("ImageSubSystem", ULONG), + ("ImageSubSystemMajorVersion", ULONG), + ("ImageSubSystemMinorVersion", ULONG), + ("ImageProcessAffinityMask", ULONG), + ("GdiHandleBuffer", ULONG * 34), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", ULONG), + ("TlsExpansionBitmapBits", BYTE * 128), + ("SessionId", ULONG), + ] + +# not really, but "dt _PEB" in w2k isn't working for me :( +_PEB_2000 = _PEB_NT + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 SpareBool : UChar +# +0x004 Mutant : Ptr32 Void +# +0x008 ImageBaseAddress : Ptr32 Void +# +0x00c Ldr : Ptr32 _PEB_LDR_DATA +# +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +# +0x014 SubSystemData : Ptr32 Void +# +0x018 ProcessHeap : Ptr32 Void +# +0x01c FastPebLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x020 FastPebLockRoutine : Ptr32 Void +# +0x024 FastPebUnlockRoutine : Ptr32 Void +# +0x028 EnvironmentUpdateCount : Uint4B +# +0x02c KernelCallbackTable : Ptr32 Void +# +0x030 SystemReserved : [1] Uint4B +# +0x034 AtlThunkSListPtr32 : Uint4B +# +0x038 FreeList : Ptr32 _PEB_FREE_BLOCK +# +0x03c TlsExpansionCounter : Uint4B +# +0x040 TlsBitmap : Ptr32 Void +# +0x044 TlsBitmapBits : [2] Uint4B +# +0x04c ReadOnlySharedMemoryBase : Ptr32 Void +# +0x050 ReadOnlySharedMemoryHeap : Ptr32 Void +# +0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void +# +0x058 AnsiCodePageData : Ptr32 Void +# +0x05c OemCodePageData : Ptr32 Void +# +0x060 UnicodeCaseTableData : Ptr32 Void +# +0x064 NumberOfProcessors : Uint4B +# +0x068 NtGlobalFlag : Uint4B +# +0x070 CriticalSectionTimeout : _LARGE_INTEGER +# +0x078 HeapSegmentReserve : Uint4B +# +0x07c HeapSegmentCommit : Uint4B +# +0x080 HeapDeCommitTotalFreeThreshold : Uint4B +# +0x084 HeapDeCommitFreeBlockThreshold : Uint4B +# +0x088 NumberOfHeaps : Uint4B +# +0x08c MaximumNumberOfHeaps : Uint4B +# +0x090 ProcessHeaps : Ptr32 Ptr32 Void +# +0x094 GdiSharedHandleTable : Ptr32 Void +# +0x098 ProcessStarterHelper : Ptr32 Void +# +0x09c GdiDCAttributeList : Uint4B +# +0x0a0 LoaderLock : Ptr32 Void +# +0x0a4 OSMajorVersion : Uint4B +# +0x0a8 OSMinorVersion : Uint4B +# +0x0ac OSBuildNumber : Uint2B +# +0x0ae OSCSDVersion : Uint2B +# +0x0b0 OSPlatformId : Uint4B +# +0x0b4 ImageSubsystem : Uint4B +# +0x0b8 ImageSubsystemMajorVersion : Uint4B +# +0x0bc ImageSubsystemMinorVersion : Uint4B +# +0x0c0 ImageProcessAffinityMask : Uint4B +# +0x0c4 GdiHandleBuffer : [34] Uint4B +# +0x14c PostProcessInitRoutine : Ptr32 void +# +0x150 TlsExpansionBitmap : Ptr32 Void +# +0x154 TlsExpansionBitmapBits : [32] Uint4B +# +0x1d4 SessionId : Uint4B +# +0x1d8 AppCompatFlags : _ULARGE_INTEGER +# +0x1e0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x1e8 pShimData : Ptr32 Void +# +0x1ec AppCompatInfo : Ptr32 Void +# +0x1f0 CSDVersion : _UNICODE_STRING +# +0x1f8 ActivationContextData : Ptr32 Void +# +0x1fc ProcessAssemblyStorageMap : Ptr32 Void +# +0x200 SystemDefaultActivationContextData : Ptr32 Void +# +0x204 SystemAssemblyStorageMap : Ptr32 Void +# +0x208 MinimumStackCommit : Uint4B +class _PEB_XP(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("SpareBool", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), + ("FastPebLockRoutine", PVOID), + ("FastPebUnlockRoutine", PVOID), + ("EnvironmentUpdateCount", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("AtlThunkSListPtr32", DWORD), + ("FreeList", PVOID), # PPEB_FREE_BLOCK + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("ReadOnlySharedMemoryHeap", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", DWORD), + ("HeapSegmentCommit", DWORD), + ("HeapDeCommitTotalFreeThreshold", DWORD), + ("HeapDeCommitFreeBlockThreshold", DWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr32 Ptr32 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ImageProcessAffinityMask", DWORD), + ("GdiHandleBuffer", DWORD * 34), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", DWORD), + ] + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 SpareBits : Pos 1, 7 Bits +# +0x008 Mutant : Ptr64 Void +# +0x010 ImageBaseAddress : Ptr64 Void +# +0x018 Ldr : Ptr64 _PEB_LDR_DATA +# +0x020 ProcessParameters : Ptr64 _RTL_USER_PROCESS_PARAMETERS +# +0x028 SubSystemData : Ptr64 Void +# +0x030 ProcessHeap : Ptr64 Void +# +0x038 FastPebLock : Ptr64 _RTL_CRITICAL_SECTION +# +0x040 AtlThunkSListPtr : Ptr64 Void +# +0x048 SparePtr2 : Ptr64 Void +# +0x050 EnvironmentUpdateCount : Uint4B +# +0x058 KernelCallbackTable : Ptr64 Void +# +0x060 SystemReserved : [1] Uint4B +# +0x064 SpareUlong : Uint4B +# +0x068 FreeList : Ptr64 _PEB_FREE_BLOCK +# +0x070 TlsExpansionCounter : Uint4B +# +0x078 TlsBitmap : Ptr64 Void +# +0x080 TlsBitmapBits : [2] Uint4B +# +0x088 ReadOnlySharedMemoryBase : Ptr64 Void +# +0x090 ReadOnlySharedMemoryHeap : Ptr64 Void +# +0x098 ReadOnlyStaticServerData : Ptr64 Ptr64 Void +# +0x0a0 AnsiCodePageData : Ptr64 Void +# +0x0a8 OemCodePageData : Ptr64 Void +# +0x0b0 UnicodeCaseTableData : Ptr64 Void +# +0x0b8 NumberOfProcessors : Uint4B +# +0x0bc NtGlobalFlag : Uint4B +# +0x0c0 CriticalSectionTimeout : _LARGE_INTEGER +# +0x0c8 HeapSegmentReserve : Uint8B +# +0x0d0 HeapSegmentCommit : Uint8B +# +0x0d8 HeapDeCommitTotalFreeThreshold : Uint8B +# +0x0e0 HeapDeCommitFreeBlockThreshold : Uint8B +# +0x0e8 NumberOfHeaps : Uint4B +# +0x0ec MaximumNumberOfHeaps : Uint4B +# +0x0f0 ProcessHeaps : Ptr64 Ptr64 Void +# +0x0f8 GdiSharedHandleTable : Ptr64 Void +# +0x100 ProcessStarterHelper : Ptr64 Void +# +0x108 GdiDCAttributeList : Uint4B +# +0x110 LoaderLock : Ptr64 _RTL_CRITICAL_SECTION +# +0x118 OSMajorVersion : Uint4B +# +0x11c OSMinorVersion : Uint4B +# +0x120 OSBuildNumber : Uint2B +# +0x122 OSCSDVersion : Uint2B +# +0x124 OSPlatformId : Uint4B +# +0x128 ImageSubsystem : Uint4B +# +0x12c ImageSubsystemMajorVersion : Uint4B +# +0x130 ImageSubsystemMinorVersion : Uint4B +# +0x138 ImageProcessAffinityMask : Uint8B +# +0x140 GdiHandleBuffer : [60] Uint4B +# +0x230 PostProcessInitRoutine : Ptr64 void +# +0x238 TlsExpansionBitmap : Ptr64 Void +# +0x240 TlsExpansionBitmapBits : [32] Uint4B +# +0x2c0 SessionId : Uint4B +# +0x2c8 AppCompatFlags : _ULARGE_INTEGER +# +0x2d0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x2d8 pShimData : Ptr64 Void +# +0x2e0 AppCompatInfo : Ptr64 Void +# +0x2e8 CSDVersion : _UNICODE_STRING +# +0x2f8 ActivationContextData : Ptr64 _ACTIVATION_CONTEXT_DATA +# +0x300 ProcessAssemblyStorageMap : Ptr64 _ASSEMBLY_STORAGE_MAP +# +0x308 SystemDefaultActivationContextData : Ptr64 _ACTIVATION_CONTEXT_DATA +# +0x310 SystemAssemblyStorageMap : Ptr64 _ASSEMBLY_STORAGE_MAP +# +0x318 MinimumStackCommit : Uint8B +# +0x320 FlsCallback : Ptr64 Ptr64 Void +# +0x328 FlsListHead : _LIST_ENTRY +# +0x338 FlsBitmap : Ptr64 Void +# +0x340 FlsBitmapBits : [4] Uint4B +# +0x350 FlsHighIndex : Uint4B +class _PEB_XP_64(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("SparePtr2", PVOID), + ("EnvironmentUpdateCount", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("SpareUlong", DWORD), + ("FreeList", PVOID), # PPEB_FREE_BLOCK + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("ReadOnlySharedMemoryHeap", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr64 Ptr64 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", QWORD), + ("HeapSegmentCommit", QWORD), + ("HeapDeCommitTotalFreeThreshold", QWORD), + ("HeapDeCommitFreeBlockThreshold", QWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr64 Ptr64 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ImageProcessAffinityMask", QWORD), + ("GdiHandleBuffer", DWORD * 60), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", QWORD), + ("FlsCallback", PVOID), # Ptr64 Ptr64 Void + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ] + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 SpareBits : Pos 1, 7 Bits +# +0x004 Mutant : Ptr32 Void +# +0x008 ImageBaseAddress : Ptr32 Void +# +0x00c Ldr : Ptr32 _PEB_LDR_DATA +# +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +# +0x014 SubSystemData : Ptr32 Void +# +0x018 ProcessHeap : Ptr32 Void +# +0x01c FastPebLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x020 AtlThunkSListPtr : Ptr32 Void +# +0x024 SparePtr2 : Ptr32 Void +# +0x028 EnvironmentUpdateCount : Uint4B +# +0x02c KernelCallbackTable : Ptr32 Void +# +0x030 SystemReserved : [1] Uint4B +# +0x034 SpareUlong : Uint4B +# +0x038 FreeList : Ptr32 _PEB_FREE_BLOCK +# +0x03c TlsExpansionCounter : Uint4B +# +0x040 TlsBitmap : Ptr32 Void +# +0x044 TlsBitmapBits : [2] Uint4B +# +0x04c ReadOnlySharedMemoryBase : Ptr32 Void +# +0x050 ReadOnlySharedMemoryHeap : Ptr32 Void +# +0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void +# +0x058 AnsiCodePageData : Ptr32 Void +# +0x05c OemCodePageData : Ptr32 Void +# +0x060 UnicodeCaseTableData : Ptr32 Void +# +0x064 NumberOfProcessors : Uint4B +# +0x068 NtGlobalFlag : Uint4B +# +0x070 CriticalSectionTimeout : _LARGE_INTEGER +# +0x078 HeapSegmentReserve : Uint4B +# +0x07c HeapSegmentCommit : Uint4B +# +0x080 HeapDeCommitTotalFreeThreshold : Uint4B +# +0x084 HeapDeCommitFreeBlockThreshold : Uint4B +# +0x088 NumberOfHeaps : Uint4B +# +0x08c MaximumNumberOfHeaps : Uint4B +# +0x090 ProcessHeaps : Ptr32 Ptr32 Void +# +0x094 GdiSharedHandleTable : Ptr32 Void +# +0x098 ProcessStarterHelper : Ptr32 Void +# +0x09c GdiDCAttributeList : Uint4B +# +0x0a0 LoaderLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x0a4 OSMajorVersion : Uint4B +# +0x0a8 OSMinorVersion : Uint4B +# +0x0ac OSBuildNumber : Uint2B +# +0x0ae OSCSDVersion : Uint2B +# +0x0b0 OSPlatformId : Uint4B +# +0x0b4 ImageSubsystem : Uint4B +# +0x0b8 ImageSubsystemMajorVersion : Uint4B +# +0x0bc ImageSubsystemMinorVersion : Uint4B +# +0x0c0 ImageProcessAffinityMask : Uint4B +# +0x0c4 GdiHandleBuffer : [34] Uint4B +# +0x14c PostProcessInitRoutine : Ptr32 void +# +0x150 TlsExpansionBitmap : Ptr32 Void +# +0x154 TlsExpansionBitmapBits : [32] Uint4B +# +0x1d4 SessionId : Uint4B +# +0x1d8 AppCompatFlags : _ULARGE_INTEGER +# +0x1e0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x1e8 pShimData : Ptr32 Void +# +0x1ec AppCompatInfo : Ptr32 Void +# +0x1f0 CSDVersion : _UNICODE_STRING +# +0x1f8 ActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x1fc ProcessAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x200 SystemDefaultActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x204 SystemAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x208 MinimumStackCommit : Uint4B +# +0x20c FlsCallback : Ptr32 Ptr32 Void +# +0x210 FlsListHead : _LIST_ENTRY +# +0x218 FlsBitmap : Ptr32 Void +# +0x21c FlsBitmapBits : [4] Uint4B +# +0x22c FlsHighIndex : Uint4B +class _PEB_2003(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("SparePtr2", PVOID), + ("EnvironmentUpdateCount", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("SpareUlong", DWORD), + ("FreeList", PVOID), # PPEB_FREE_BLOCK + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("ReadOnlySharedMemoryHeap", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", DWORD), + ("HeapSegmentCommit", DWORD), + ("HeapDeCommitTotalFreeThreshold", DWORD), + ("HeapDeCommitFreeBlockThreshold", DWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr32 Ptr32 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ImageProcessAffinityMask", DWORD), + ("GdiHandleBuffer", DWORD * 34), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", QWORD), + ("FlsCallback", PVOID), # Ptr32 Ptr32 Void + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ] + +_PEB_2003_64 = _PEB_XP_64 +_PEB_2003_R2 = _PEB_2003 +_PEB_2003_R2_64 = _PEB_2003_64 + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 IsProtectedProcess : Pos 1, 1 Bit +# +0x003 IsLegacyProcess : Pos 2, 1 Bit +# +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +# +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +# +0x003 SpareBits : Pos 5, 3 Bits +# +0x004 Mutant : Ptr32 Void +# +0x008 ImageBaseAddress : Ptr32 Void +# +0x00c Ldr : Ptr32 _PEB_LDR_DATA +# +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +# +0x014 SubSystemData : Ptr32 Void +# +0x018 ProcessHeap : Ptr32 Void +# +0x01c FastPebLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x020 AtlThunkSListPtr : Ptr32 Void +# +0x024 IFEOKey : Ptr32 Void +# +0x028 CrossProcessFlags : Uint4B +# +0x028 ProcessInJob : Pos 0, 1 Bit +# +0x028 ProcessInitializing : Pos 1, 1 Bit +# +0x028 ProcessUsingVEH : Pos 2, 1 Bit +# +0x028 ProcessUsingVCH : Pos 3, 1 Bit +# +0x028 ReservedBits0 : Pos 4, 28 Bits +# +0x02c KernelCallbackTable : Ptr32 Void +# +0x02c UserSharedInfoPtr : Ptr32 Void +# +0x030 SystemReserved : [1] Uint4B +# +0x034 SpareUlong : Uint4B +# +0x038 SparePebPtr0 : Uint4B +# +0x03c TlsExpansionCounter : Uint4B +# +0x040 TlsBitmap : Ptr32 Void +# +0x044 TlsBitmapBits : [2] Uint4B +# +0x04c ReadOnlySharedMemoryBase : Ptr32 Void +# +0x050 HotpatchInformation : Ptr32 Void +# +0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void +# +0x058 AnsiCodePageData : Ptr32 Void +# +0x05c OemCodePageData : Ptr32 Void +# +0x060 UnicodeCaseTableData : Ptr32 Void +# +0x064 NumberOfProcessors : Uint4B +# +0x068 NtGlobalFlag : Uint4B +# +0x070 CriticalSectionTimeout : _LARGE_INTEGER +# +0x078 HeapSegmentReserve : Uint4B +# +0x07c HeapSegmentCommit : Uint4B +# +0x080 HeapDeCommitTotalFreeThreshold : Uint4B +# +0x084 HeapDeCommitFreeBlockThreshold : Uint4B +# +0x088 NumberOfHeaps : Uint4B +# +0x08c MaximumNumberOfHeaps : Uint4B +# +0x090 ProcessHeaps : Ptr32 Ptr32 Void +# +0x094 GdiSharedHandleTable : Ptr32 Void +# +0x098 ProcessStarterHelper : Ptr32 Void +# +0x09c GdiDCAttributeList : Uint4B +# +0x0a0 LoaderLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x0a4 OSMajorVersion : Uint4B +# +0x0a8 OSMinorVersion : Uint4B +# +0x0ac OSBuildNumber : Uint2B +# +0x0ae OSCSDVersion : Uint2B +# +0x0b0 OSPlatformId : Uint4B +# +0x0b4 ImageSubsystem : Uint4B +# +0x0b8 ImageSubsystemMajorVersion : Uint4B +# +0x0bc ImageSubsystemMinorVersion : Uint4B +# +0x0c0 ActiveProcessAffinityMask : Uint4B +# +0x0c4 GdiHandleBuffer : [34] Uint4B +# +0x14c PostProcessInitRoutine : Ptr32 void +# +0x150 TlsExpansionBitmap : Ptr32 Void +# +0x154 TlsExpansionBitmapBits : [32] Uint4B +# +0x1d4 SessionId : Uint4B +# +0x1d8 AppCompatFlags : _ULARGE_INTEGER +# +0x1e0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x1e8 pShimData : Ptr32 Void +# +0x1ec AppCompatInfo : Ptr32 Void +# +0x1f0 CSDVersion : _UNICODE_STRING +# +0x1f8 ActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x1fc ProcessAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x200 SystemDefaultActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x204 SystemAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x208 MinimumStackCommit : Uint4B +# +0x20c FlsCallback : Ptr32 _FLS_CALLBACK_INFO +# +0x210 FlsListHead : _LIST_ENTRY +# +0x218 FlsBitmap : Ptr32 Void +# +0x21c FlsBitmapBits : [4] Uint4B +# +0x22c FlsHighIndex : Uint4B +# +0x230 WerRegistrationData : Ptr32 Void +# +0x234 WerShipAssertPtr : Ptr32 Void +class _PEB_2008(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("IFEOKey", PVOID), + ("CrossProcessFlags", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("SpareUlong", DWORD), + ("SparePebPtr0", PVOID), + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("HotpatchInformation", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", DWORD), + ("HeapSegmentCommit", DWORD), + ("HeapDeCommitTotalFreeThreshold", DWORD), + ("HeapDeCommitFreeBlockThreshold", DWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr32 Ptr32 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ActiveProcessAffinityMask", DWORD), + ("GdiHandleBuffer", DWORD * 34), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", DWORD), + ("FlsCallback", PVOID), # PFLS_CALLBACK_INFO + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ("WerRegistrationData", PVOID), + ("WerShipAssertPtr", PVOID), + ] + def __get_UserSharedInfoPtr(self): + return self.KernelCallbackTable + def __set_UserSharedInfoPtr(self, value): + self.KernelCallbackTable = value + UserSharedInfoPtr = property(__get_UserSharedInfoPtr, __set_UserSharedInfoPtr) + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 IsProtectedProcess : Pos 1, 1 Bit +# +0x003 IsLegacyProcess : Pos 2, 1 Bit +# +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +# +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +# +0x003 SpareBits : Pos 5, 3 Bits +# +0x008 Mutant : Ptr64 Void +# +0x010 ImageBaseAddress : Ptr64 Void +# +0x018 Ldr : Ptr64 _PEB_LDR_DATA +# +0x020 ProcessParameters : Ptr64 _RTL_USER_PROCESS_PARAMETERS +# +0x028 SubSystemData : Ptr64 Void +# +0x030 ProcessHeap : Ptr64 Void +# +0x038 FastPebLock : Ptr64 _RTL_CRITICAL_SECTION +# +0x040 AtlThunkSListPtr : Ptr64 Void +# +0x048 IFEOKey : Ptr64 Void +# +0x050 CrossProcessFlags : Uint4B +# +0x050 ProcessInJob : Pos 0, 1 Bit +# +0x050 ProcessInitializing : Pos 1, 1 Bit +# +0x050 ProcessUsingVEH : Pos 2, 1 Bit +# +0x050 ProcessUsingVCH : Pos 3, 1 Bit +# +0x050 ReservedBits0 : Pos 4, 28 Bits +# +0x058 KernelCallbackTable : Ptr64 Void +# +0x058 UserSharedInfoPtr : Ptr64 Void +# +0x060 SystemReserved : [1] Uint4B +# +0x064 SpareUlong : Uint4B +# +0x068 SparePebPtr0 : Uint8B +# +0x070 TlsExpansionCounter : Uint4B +# +0x078 TlsBitmap : Ptr64 Void +# +0x080 TlsBitmapBits : [2] Uint4B +# +0x088 ReadOnlySharedMemoryBase : Ptr64 Void +# +0x090 HotpatchInformation : Ptr64 Void +# +0x098 ReadOnlyStaticServerData : Ptr64 Ptr64 Void +# +0x0a0 AnsiCodePageData : Ptr64 Void +# +0x0a8 OemCodePageData : Ptr64 Void +# +0x0b0 UnicodeCaseTableData : Ptr64 Void +# +0x0b8 NumberOfProcessors : Uint4B +# +0x0bc NtGlobalFlag : Uint4B +# +0x0c0 CriticalSectionTimeout : _LARGE_INTEGER +# +0x0c8 HeapSegmentReserve : Uint8B +# +0x0d0 HeapSegmentCommit : Uint8B +# +0x0d8 HeapDeCommitTotalFreeThreshold : Uint8B +# +0x0e0 HeapDeCommitFreeBlockThreshold : Uint8B +# +0x0e8 NumberOfHeaps : Uint4B +# +0x0ec MaximumNumberOfHeaps : Uint4B +# +0x0f0 ProcessHeaps : Ptr64 Ptr64 Void +# +0x0f8 GdiSharedHandleTable : Ptr64 Void +# +0x100 ProcessStarterHelper : Ptr64 Void +# +0x108 GdiDCAttributeList : Uint4B +# +0x110 LoaderLock : Ptr64 _RTL_CRITICAL_SECTION +# +0x118 OSMajorVersion : Uint4B +# +0x11c OSMinorVersion : Uint4B +# +0x120 OSBuildNumber : Uint2B +# +0x122 OSCSDVersion : Uint2B +# +0x124 OSPlatformId : Uint4B +# +0x128 ImageSubsystem : Uint4B +# +0x12c ImageSubsystemMajorVersion : Uint4B +# +0x130 ImageSubsystemMinorVersion : Uint4B +# +0x138 ActiveProcessAffinityMask : Uint8B +# +0x140 GdiHandleBuffer : [60] Uint4B +# +0x230 PostProcessInitRoutine : Ptr64 void +# +0x238 TlsExpansionBitmap : Ptr64 Void +# +0x240 TlsExpansionBitmapBits : [32] Uint4B +# +0x2c0 SessionId : Uint4B +# +0x2c8 AppCompatFlags : _ULARGE_INTEGER +# +0x2d0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x2d8 pShimData : Ptr64 Void +# +0x2e0 AppCompatInfo : Ptr64 Void +# +0x2e8 CSDVersion : _UNICODE_STRING +# +0x2f8 ActivationContextData : Ptr64 _ACTIVATION_CONTEXT_DATA +# +0x300 ProcessAssemblyStorageMap : Ptr64 _ASSEMBLY_STORAGE_MAP +# +0x308 SystemDefaultActivationContextData : Ptr64 _ACTIVATION_CONTEXT_DATA +# +0x310 SystemAssemblyStorageMap : Ptr64 _ASSEMBLY_STORAGE_MAP +# +0x318 MinimumStackCommit : Uint8B +# +0x320 FlsCallback : Ptr64 _FLS_CALLBACK_INFO +# +0x328 FlsListHead : _LIST_ENTRY +# +0x338 FlsBitmap : Ptr64 Void +# +0x340 FlsBitmapBits : [4] Uint4B +# +0x350 FlsHighIndex : Uint4B +# +0x358 WerRegistrationData : Ptr64 Void +# +0x360 WerShipAssertPtr : Ptr64 Void +class _PEB_2008_64(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("IFEOKey", PVOID), + ("CrossProcessFlags", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("SpareUlong", DWORD), + ("SparePebPtr0", PVOID), + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("HotpatchInformation", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr64 Ptr64 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", QWORD), + ("HeapSegmentCommit", QWORD), + ("HeapDeCommitTotalFreeThreshold", QWORD), + ("HeapDeCommitFreeBlockThreshold", QWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr64 Ptr64 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ActiveProcessAffinityMask", QWORD), + ("GdiHandleBuffer", DWORD * 60), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", QWORD), + ("FlsCallback", PVOID), # PFLS_CALLBACK_INFO + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ("WerRegistrationData", PVOID), + ("WerShipAssertPtr", PVOID), + ] + def __get_UserSharedInfoPtr(self): + return self.KernelCallbackTable + def __set_UserSharedInfoPtr(self, value): + self.KernelCallbackTable = value + UserSharedInfoPtr = property(__get_UserSharedInfoPtr, __set_UserSharedInfoPtr) + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 IsProtectedProcess : Pos 1, 1 Bit +# +0x003 IsLegacyProcess : Pos 2, 1 Bit +# +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +# +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +# +0x003 SpareBits : Pos 5, 3 Bits +# +0x004 Mutant : Ptr32 Void +# +0x008 ImageBaseAddress : Ptr32 Void +# +0x00c Ldr : Ptr32 _PEB_LDR_DATA +# +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +# +0x014 SubSystemData : Ptr32 Void +# +0x018 ProcessHeap : Ptr32 Void +# +0x01c FastPebLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x020 AtlThunkSListPtr : Ptr32 Void +# +0x024 IFEOKey : Ptr32 Void +# +0x028 CrossProcessFlags : Uint4B +# +0x028 ProcessInJob : Pos 0, 1 Bit +# +0x028 ProcessInitializing : Pos 1, 1 Bit +# +0x028 ProcessUsingVEH : Pos 2, 1 Bit +# +0x028 ProcessUsingVCH : Pos 3, 1 Bit +# +0x028 ProcessUsingFTH : Pos 4, 1 Bit +# +0x028 ReservedBits0 : Pos 5, 27 Bits +# +0x02c KernelCallbackTable : Ptr32 Void +# +0x02c UserSharedInfoPtr : Ptr32 Void +# +0x030 SystemReserved : [1] Uint4B +# +0x034 AtlThunkSListPtr32 : Uint4B +# +0x038 ApiSetMap : Ptr32 Void +# +0x03c TlsExpansionCounter : Uint4B +# +0x040 TlsBitmap : Ptr32 Void +# +0x044 TlsBitmapBits : [2] Uint4B +# +0x04c ReadOnlySharedMemoryBase : Ptr32 Void +# +0x050 HotpatchInformation : Ptr32 Void +# +0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void +# +0x058 AnsiCodePageData : Ptr32 Void +# +0x05c OemCodePageData : Ptr32 Void +# +0x060 UnicodeCaseTableData : Ptr32 Void +# +0x064 NumberOfProcessors : Uint4B +# +0x068 NtGlobalFlag : Uint4B +# +0x070 CriticalSectionTimeout : _LARGE_INTEGER +# +0x078 HeapSegmentReserve : Uint4B +# +0x07c HeapSegmentCommit : Uint4B +# +0x080 HeapDeCommitTotalFreeThreshold : Uint4B +# +0x084 HeapDeCommitFreeBlockThreshold : Uint4B +# +0x088 NumberOfHeaps : Uint4B +# +0x08c MaximumNumberOfHeaps : Uint4B +# +0x090 ProcessHeaps : Ptr32 Ptr32 Void +# +0x094 GdiSharedHandleTable : Ptr32 Void +# +0x098 ProcessStarterHelper : Ptr32 Void +# +0x09c GdiDCAttributeList : Uint4B +# +0x0a0 LoaderLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x0a4 OSMajorVersion : Uint4B +# +0x0a8 OSMinorVersion : Uint4B +# +0x0ac OSBuildNumber : Uint2B +# +0x0ae OSCSDVersion : Uint2B +# +0x0b0 OSPlatformId : Uint4B +# +0x0b4 ImageSubsystem : Uint4B +# +0x0b8 ImageSubsystemMajorVersion : Uint4B +# +0x0bc ImageSubsystemMinorVersion : Uint4B +# +0x0c0 ActiveProcessAffinityMask : Uint4B +# +0x0c4 GdiHandleBuffer : [34] Uint4B +# +0x14c PostProcessInitRoutine : Ptr32 void +# +0x150 TlsExpansionBitmap : Ptr32 Void +# +0x154 TlsExpansionBitmapBits : [32] Uint4B +# +0x1d4 SessionId : Uint4B +# +0x1d8 AppCompatFlags : _ULARGE_INTEGER +# +0x1e0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x1e8 pShimData : Ptr32 Void +# +0x1ec AppCompatInfo : Ptr32 Void +# +0x1f0 CSDVersion : _UNICODE_STRING +# +0x1f8 ActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x1fc ProcessAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x200 SystemDefaultActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x204 SystemAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x208 MinimumStackCommit : Uint4B +# +0x20c FlsCallback : Ptr32 _FLS_CALLBACK_INFO +# +0x210 FlsListHead : _LIST_ENTRY +# +0x218 FlsBitmap : Ptr32 Void +# +0x21c FlsBitmapBits : [4] Uint4B +# +0x22c FlsHighIndex : Uint4B +# +0x230 WerRegistrationData : Ptr32 Void +# +0x234 WerShipAssertPtr : Ptr32 Void +# +0x238 pContextData : Ptr32 Void +# +0x23c pImageHeaderHash : Ptr32 Void +# +0x240 TracingFlags : Uint4B +# +0x240 HeapTracingEnabled : Pos 0, 1 Bit +# +0x240 CritSecTracingEnabled : Pos 1, 1 Bit +# +0x240 SpareTracingBits : Pos 2, 30 Bits +class _PEB_2008_R2(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("IFEOKey", PVOID), + ("CrossProcessFlags", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("AtlThunkSListPtr32", PVOID), + ("ApiSetMap", PVOID), + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("HotpatchInformation", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", DWORD), + ("HeapSegmentCommit", DWORD), + ("HeapDeCommitTotalFreeThreshold", DWORD), + ("HeapDeCommitFreeBlockThreshold", DWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr32 Ptr32 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ActiveProcessAffinityMask", DWORD), + ("GdiHandleBuffer", DWORD * 34), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", DWORD), + ("FlsCallback", PVOID), # PFLS_CALLBACK_INFO + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ("WerRegistrationData", PVOID), + ("WerShipAssertPtr", PVOID), + ("pContextData", PVOID), + ("pImageHeaderHash", PVOID), + ("TracingFlags", DWORD), + ] + def __get_UserSharedInfoPtr(self): + return self.KernelCallbackTable + def __set_UserSharedInfoPtr(self, value): + self.KernelCallbackTable = value + UserSharedInfoPtr = property(__get_UserSharedInfoPtr, __set_UserSharedInfoPtr) + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 IsProtectedProcess : Pos 1, 1 Bit +# +0x003 IsLegacyProcess : Pos 2, 1 Bit +# +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +# +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +# +0x003 SpareBits : Pos 5, 3 Bits +# +0x008 Mutant : Ptr64 Void +# +0x010 ImageBaseAddress : Ptr64 Void +# +0x018 Ldr : Ptr64 _PEB_LDR_DATA +# +0x020 ProcessParameters : Ptr64 _RTL_USER_PROCESS_PARAMETERS +# +0x028 SubSystemData : Ptr64 Void +# +0x030 ProcessHeap : Ptr64 Void +# +0x038 FastPebLock : Ptr64 _RTL_CRITICAL_SECTION +# +0x040 AtlThunkSListPtr : Ptr64 Void +# +0x048 IFEOKey : Ptr64 Void +# +0x050 CrossProcessFlags : Uint4B +# +0x050 ProcessInJob : Pos 0, 1 Bit +# +0x050 ProcessInitializing : Pos 1, 1 Bit +# +0x050 ProcessUsingVEH : Pos 2, 1 Bit +# +0x050 ProcessUsingVCH : Pos 3, 1 Bit +# +0x050 ProcessUsingFTH : Pos 4, 1 Bit +# +0x050 ReservedBits0 : Pos 5, 27 Bits +# +0x058 KernelCallbackTable : Ptr64 Void +# +0x058 UserSharedInfoPtr : Ptr64 Void +# +0x060 SystemReserved : [1] Uint4B +# +0x064 AtlThunkSListPtr32 : Uint4B +# +0x068 ApiSetMap : Ptr64 Void +# +0x070 TlsExpansionCounter : Uint4B +# +0x078 TlsBitmap : Ptr64 Void +# +0x080 TlsBitmapBits : [2] Uint4B +# +0x088 ReadOnlySharedMemoryBase : Ptr64 Void +# +0x090 HotpatchInformation : Ptr64 Void +# +0x098 ReadOnlyStaticServerData : Ptr64 Ptr64 Void +# +0x0a0 AnsiCodePageData : Ptr64 Void +# +0x0a8 OemCodePageData : Ptr64 Void +# +0x0b0 UnicodeCaseTableData : Ptr64 Void +# +0x0b8 NumberOfProcessors : Uint4B +# +0x0bc NtGlobalFlag : Uint4B +# +0x0c0 CriticalSectionTimeout : _LARGE_INTEGER +# +0x0c8 HeapSegmentReserve : Uint8B +# +0x0d0 HeapSegmentCommit : Uint8B +# +0x0d8 HeapDeCommitTotalFreeThreshold : Uint8B +# +0x0e0 HeapDeCommitFreeBlockThreshold : Uint8B +# +0x0e8 NumberOfHeaps : Uint4B +# +0x0ec MaximumNumberOfHeaps : Uint4B +# +0x0f0 ProcessHeaps : Ptr64 Ptr64 Void +# +0x0f8 GdiSharedHandleTable : Ptr64 Void +# +0x100 ProcessStarterHelper : Ptr64 Void +# +0x108 GdiDCAttributeList : Uint4B +# +0x110 LoaderLock : Ptr64 _RTL_CRITICAL_SECTION +# +0x118 OSMajorVersion : Uint4B +# +0x11c OSMinorVersion : Uint4B +# +0x120 OSBuildNumber : Uint2B +# +0x122 OSCSDVersion : Uint2B +# +0x124 OSPlatformId : Uint4B +# +0x128 ImageSubsystem : Uint4B +# +0x12c ImageSubsystemMajorVersion : Uint4B +# +0x130 ImageSubsystemMinorVersion : Uint4B +# +0x138 ActiveProcessAffinityMask : Uint8B +# +0x140 GdiHandleBuffer : [60] Uint4B +# +0x230 PostProcessInitRoutine : Ptr64 void +# +0x238 TlsExpansionBitmap : Ptr64 Void +# +0x240 TlsExpansionBitmapBits : [32] Uint4B +# +0x2c0 SessionId : Uint4B +# +0x2c8 AppCompatFlags : _ULARGE_INTEGER +# +0x2d0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x2d8 pShimData : Ptr64 Void +# +0x2e0 AppCompatInfo : Ptr64 Void +# +0x2e8 CSDVersion : _UNICODE_STRING +# +0x2f8 ActivationContextData : Ptr64 _ACTIVATION_CONTEXT_DATA +# +0x300 ProcessAssemblyStorageMap : Ptr64 _ASSEMBLY_STORAGE_MAP +# +0x308 SystemDefaultActivationContextData : Ptr64 _ACTIVATION_CONTEXT_DATA +# +0x310 SystemAssemblyStorageMap : Ptr64 _ASSEMBLY_STORAGE_MAP +# +0x318 MinimumStackCommit : Uint8B +# +0x320 FlsCallback : Ptr64 _FLS_CALLBACK_INFO +# +0x328 FlsListHead : _LIST_ENTRY +# +0x338 FlsBitmap : Ptr64 Void +# +0x340 FlsBitmapBits : [4] Uint4B +# +0x350 FlsHighIndex : Uint4B +# +0x358 WerRegistrationData : Ptr64 Void +# +0x360 WerShipAssertPtr : Ptr64 Void +# +0x368 pContextData : Ptr64 Void +# +0x370 pImageHeaderHash : Ptr64 Void +# +0x378 TracingFlags : Uint4B +# +0x378 HeapTracingEnabled : Pos 0, 1 Bit +# +0x378 CritSecTracingEnabled : Pos 1, 1 Bit +# +0x378 SpareTracingBits : Pos 2, 30 Bits +class _PEB_2008_R2_64(Structure): + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("IFEOKey", PVOID), + ("CrossProcessFlags", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("AtlThunkSListPtr32", DWORD), + ("ApiSetMap", PVOID), + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("HotpatchInformation", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", QWORD), + ("HeapSegmentCommit", QWORD), + ("HeapDeCommitTotalFreeThreshold", QWORD), + ("HeapDeCommitFreeBlockThreshold", QWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr64 Ptr64 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ActiveProcessAffinityMask", QWORD), + ("GdiHandleBuffer", DWORD * 60), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", QWORD), + ("FlsCallback", PVOID), # PFLS_CALLBACK_INFO + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ("WerRegistrationData", PVOID), + ("WerShipAssertPtr", PVOID), + ("pContextData", PVOID), + ("pImageHeaderHash", PVOID), + ("TracingFlags", DWORD), + ] + def __get_UserSharedInfoPtr(self): + return self.KernelCallbackTable + def __set_UserSharedInfoPtr(self, value): + self.KernelCallbackTable = value + UserSharedInfoPtr = property(__get_UserSharedInfoPtr, __set_UserSharedInfoPtr) + +_PEB_Vista = _PEB_2008 +_PEB_Vista_64 = _PEB_2008_64 +_PEB_W7 = _PEB_2008_R2 +_PEB_W7_64 = _PEB_2008_R2_64 + +# +0x000 InheritedAddressSpace : UChar +# +0x001 ReadImageFileExecOptions : UChar +# +0x002 BeingDebugged : UChar +# +0x003 BitField : UChar +# +0x003 ImageUsesLargePages : Pos 0, 1 Bit +# +0x003 IsProtectedProcess : Pos 1, 1 Bit +# +0x003 IsLegacyProcess : Pos 2, 1 Bit +# +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +# +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +# +0x003 SpareBits : Pos 5, 3 Bits +# +0x004 Mutant : Ptr32 Void +# +0x008 ImageBaseAddress : Ptr32 Void +# +0x00c Ldr : Ptr32 _PEB_LDR_DATA +# +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +# +0x014 SubSystemData : Ptr32 Void +# +0x018 ProcessHeap : Ptr32 Void +# +0x01c FastPebLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x020 AtlThunkSListPtr : Ptr32 Void +# +0x024 IFEOKey : Ptr32 Void +# +0x028 CrossProcessFlags : Uint4B +# +0x028 ProcessInJob : Pos 0, 1 Bit +# +0x028 ProcessInitializing : Pos 1, 1 Bit +# +0x028 ProcessUsingVEH : Pos 2, 1 Bit +# +0x028 ProcessUsingVCH : Pos 3, 1 Bit +# +0x028 ProcessUsingFTH : Pos 4, 1 Bit +# +0x028 ReservedBits0 : Pos 5, 27 Bits +# +0x02c KernelCallbackTable : Ptr32 Void +# +0x02c UserSharedInfoPtr : Ptr32 Void +# +0x030 SystemReserved : [1] Uint4B +# +0x034 TracingFlags : Uint4B +# +0x034 HeapTracingEnabled : Pos 0, 1 Bit +# +0x034 CritSecTracingEnabled : Pos 1, 1 Bit +# +0x034 SpareTracingBits : Pos 2, 30 Bits +# +0x038 ApiSetMap : Ptr32 Void +# +0x03c TlsExpansionCounter : Uint4B +# +0x040 TlsBitmap : Ptr32 Void +# +0x044 TlsBitmapBits : [2] Uint4B +# +0x04c ReadOnlySharedMemoryBase : Ptr32 Void +# +0x050 HotpatchInformation : Ptr32 Void +# +0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void +# +0x058 AnsiCodePageData : Ptr32 Void +# +0x05c OemCodePageData : Ptr32 Void +# +0x060 UnicodeCaseTableData : Ptr32 Void +# +0x064 NumberOfProcessors : Uint4B +# +0x068 NtGlobalFlag : Uint4B +# +0x070 CriticalSectionTimeout : _LARGE_INTEGER +# +0x078 HeapSegmentReserve : Uint4B +# +0x07c HeapSegmentCommit : Uint4B +# +0x080 HeapDeCommitTotalFreeThreshold : Uint4B +# +0x084 HeapDeCommitFreeBlockThreshold : Uint4B +# +0x088 NumberOfHeaps : Uint4B +# +0x08c MaximumNumberOfHeaps : Uint4B +# +0x090 ProcessHeaps : Ptr32 Ptr32 Void +# +0x094 GdiSharedHandleTable : Ptr32 Void +# +0x098 ProcessStarterHelper : Ptr32 Void +# +0x09c GdiDCAttributeList : Uint4B +# +0x0a0 LoaderLock : Ptr32 _RTL_CRITICAL_SECTION +# +0x0a4 OSMajorVersion : Uint4B +# +0x0a8 OSMinorVersion : Uint4B +# +0x0ac OSBuildNumber : Uint2B +# +0x0ae OSCSDVersion : Uint2B +# +0x0b0 OSPlatformId : Uint4B +# +0x0b4 ImageSubsystem : Uint4B +# +0x0b8 ImageSubsystemMajorVersion : Uint4B +# +0x0bc ImageSubsystemMinorVersion : Uint4B +# +0x0c0 ActiveProcessAffinityMask : Uint4B +# +0x0c4 GdiHandleBuffer : [34] Uint4B +# +0x14c PostProcessInitRoutine : Ptr32 void +# +0x150 TlsExpansionBitmap : Ptr32 Void +# +0x154 TlsExpansionBitmapBits : [32] Uint4B +# +0x1d4 SessionId : Uint4B +# +0x1d8 AppCompatFlags : _ULARGE_INTEGER +# +0x1e0 AppCompatFlagsUser : _ULARGE_INTEGER +# +0x1e8 pShimData : Ptr32 Void +# +0x1ec AppCompatInfo : Ptr32 Void +# +0x1f0 CSDVersion : _UNICODE_STRING +# +0x1f8 ActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x1fc ProcessAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x200 SystemDefaultActivationContextData : Ptr32 _ACTIVATION_CONTEXT_DATA +# +0x204 SystemAssemblyStorageMap : Ptr32 _ASSEMBLY_STORAGE_MAP +# +0x208 MinimumStackCommit : Uint4B +# +0x20c FlsCallback : Ptr32 _FLS_CALLBACK_INFO +# +0x210 FlsListHead : _LIST_ENTRY +# +0x218 FlsBitmap : Ptr32 Void +# +0x21c FlsBitmapBits : [4] Uint4B +# +0x22c FlsHighIndex : Uint4B +# +0x230 WerRegistrationData : Ptr32 Void +# +0x234 WerShipAssertPtr : Ptr32 Void +# +0x238 pContextData : Ptr32 Void +# +0x23c pImageHeaderHash : Ptr32 Void +class _PEB_W7_Beta(Structure): + """ + This definition of the PEB structure is only valid for the beta versions + of Windows 7. For the final version of Windows 7 use L{_PEB_W7} instead. + This structure is not chosen automatically. + """ + _pack_ = 8 + _fields_ = [ + ("InheritedAddressSpace", BOOLEAN), + ("ReadImageFileExecOptions", UCHAR), + ("BeingDebugged", BOOLEAN), + ("BitField", UCHAR), + ("Mutant", HANDLE), + ("ImageBaseAddress", PVOID), + ("Ldr", PVOID), # PPEB_LDR_DATA + ("ProcessParameters", PVOID), # PRTL_USER_PROCESS_PARAMETERS + ("SubSystemData", PVOID), + ("ProcessHeap", PVOID), + ("FastPebLock", PVOID), # PRTL_CRITICAL_SECTION + ("AtlThunkSListPtr", PVOID), + ("IFEOKey", PVOID), + ("CrossProcessFlags", DWORD), + ("KernelCallbackTable", PVOID), + ("SystemReserved", DWORD), + ("TracingFlags", DWORD), + ("ApiSetMap", PVOID), + ("TlsExpansionCounter", DWORD), + ("TlsBitmap", PVOID), + ("TlsBitmapBits", DWORD * 2), + ("ReadOnlySharedMemoryBase", PVOID), + ("HotpatchInformation", PVOID), + ("ReadOnlyStaticServerData", PVOID), # Ptr32 Ptr32 Void + ("AnsiCodePageData", PVOID), + ("OemCodePageData", PVOID), + ("UnicodeCaseTableData", PVOID), + ("NumberOfProcessors", DWORD), + ("NtGlobalFlag", DWORD), + ("CriticalSectionTimeout", LONGLONG), # LARGE_INTEGER + ("HeapSegmentReserve", DWORD), + ("HeapSegmentCommit", DWORD), + ("HeapDeCommitTotalFreeThreshold", DWORD), + ("HeapDeCommitFreeBlockThreshold", DWORD), + ("NumberOfHeaps", DWORD), + ("MaximumNumberOfHeaps", DWORD), + ("ProcessHeaps", PVOID), # Ptr32 Ptr32 Void + ("GdiSharedHandleTable", PVOID), + ("ProcessStarterHelper", PVOID), + ("GdiDCAttributeList", DWORD), + ("LoaderLock", PVOID), # PRTL_CRITICAL_SECTION + ("OSMajorVersion", DWORD), + ("OSMinorVersion", DWORD), + ("OSBuildNumber", WORD), + ("OSCSDVersion", WORD), + ("OSPlatformId", DWORD), + ("ImageSubsystem", DWORD), + ("ImageSubsystemMajorVersion", DWORD), + ("ImageSubsystemMinorVersion", DWORD), + ("ActiveProcessAffinityMask", DWORD), + ("GdiHandleBuffer", DWORD * 34), + ("PostProcessInitRoutine", PPS_POST_PROCESS_INIT_ROUTINE), + ("TlsExpansionBitmap", PVOID), + ("TlsExpansionBitmapBits", DWORD * 32), + ("SessionId", DWORD), + ("AppCompatFlags", ULONGLONG), # ULARGE_INTEGER + ("AppCompatFlagsUser", ULONGLONG), # ULARGE_INTEGER + ("pShimData", PVOID), + ("AppCompatInfo", PVOID), + ("CSDVersion", UNICODE_STRING), + ("ActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("ProcessAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("SystemDefaultActivationContextData", PVOID), # ACTIVATION_CONTEXT_DATA + ("SystemAssemblyStorageMap", PVOID), # ASSEMBLY_STORAGE_MAP + ("MinimumStackCommit", DWORD), + ("FlsCallback", PVOID), # PFLS_CALLBACK_INFO + ("FlsListHead", LIST_ENTRY), + ("FlsBitmap", PVOID), + ("FlsBitmapBits", DWORD * 4), + ("FlsHighIndex", DWORD), + ("WerRegistrationData", PVOID), + ("WerShipAssertPtr", PVOID), + ("pContextData", PVOID), + ("pImageHeaderHash", PVOID), + ] + def __get_UserSharedInfoPtr(self): + return self.KernelCallbackTable + def __set_UserSharedInfoPtr(self, value): + self.KernelCallbackTable = value + UserSharedInfoPtr = property(__get_UserSharedInfoPtr, __set_UserSharedInfoPtr) + +# Use the correct PEB structure definition. +# Defaults to the latest Windows version. +class PEB(Structure): + _pack_ = 8 + if os == 'Windows NT': + _pack_ = _PEB_NT._pack_ + _fields_ = _PEB_NT._fields_ + elif os == 'Windows 2000': + _pack_ = _PEB_2000._pack_ + _fields_ = _PEB_2000._fields_ + elif os == 'Windows XP': + _fields_ = _PEB_XP._fields_ + elif os == 'Windows XP (64 bits)': + _fields_ = _PEB_XP_64._fields_ + elif os == 'Windows 2003': + _fields_ = _PEB_2003._fields_ + elif os == 'Windows 2003 (64 bits)': + _fields_ = _PEB_2003_64._fields_ + elif os == 'Windows 2003 R2': + _fields_ = _PEB_2003_R2._fields_ + elif os == 'Windows 2003 R2 (64 bits)': + _fields_ = _PEB_2003_R2_64._fields_ + elif os == 'Windows 2008': + _fields_ = _PEB_2008._fields_ + elif os == 'Windows 2008 (64 bits)': + _fields_ = _PEB_2008_64._fields_ + elif os == 'Windows 2008 R2': + _fields_ = _PEB_2008_R2._fields_ + elif os == 'Windows 2008 R2 (64 bits)': + _fields_ = _PEB_2008_R2_64._fields_ + elif os == 'Windows Vista': + _fields_ = _PEB_Vista._fields_ + elif os == 'Windows Vista (64 bits)': + _fields_ = _PEB_Vista_64._fields_ + elif os == 'Windows 7': + _fields_ = _PEB_W7._fields_ + elif os == 'Windows 7 (64 bits)': + _fields_ = _PEB_W7_64._fields_ + elif sizeof(SIZE_T) == sizeof(DWORD): + _fields_ = _PEB_W7._fields_ + else: + _fields_ = _PEB_W7_64._fields_ +PPEB = POINTER(PEB) + +# PEB structure for WOW64 processes. +class PEB_32(Structure): + _pack_ = 8 + if os == 'Windows NT': + _pack_ = _PEB_NT._pack_ + _fields_ = _PEB_NT._fields_ + elif os == 'Windows 2000': + _pack_ = _PEB_2000._pack_ + _fields_ = _PEB_2000._fields_ + elif os.startswith('Windows XP'): + _fields_ = _PEB_XP._fields_ + elif os.startswith('Windows 2003 R2'): + _fields_ = _PEB_2003_R2._fields_ + elif os.startswith('Windows 2003'): + _fields_ = _PEB_2003._fields_ + elif os.startswith('Windows 2008 R2'): + _fields_ = _PEB_2008_R2._fields_ + elif os.startswith('Windows 2008'): + _fields_ = _PEB_2008._fields_ + elif os.startswith('Windows Vista'): + _fields_ = _PEB_Vista._fields_ + else: #if os.startswith('Windows 7'): + _fields_ = _PEB_W7._fields_ + +# from https://vmexplorer.svn.codeplex.com/svn/VMExplorer/src/Win32/Threads.cs +# +# [StructLayout (LayoutKind.Sequential, Size = 0x0C)] +# public struct Wx86ThreadState +# { +# public IntPtr CallBx86Eip; // Ptr32 to Uint4B +# public IntPtr DeallocationCpu; // Ptr32 to Void +# public Byte UseKnownWx86Dll; // UChar +# public Byte OleStubInvoked; // Char +# }; +class Wx86ThreadState(Structure): + _fields_ = [ + ("CallBx86Eip", PVOID), + ("DeallocationCpu", PVOID), + ("UseKnownWx86Dll", UCHAR), + ("OleStubInvoked", CHAR), +] + +# ntdll!_RTL_ACTIVATION_CONTEXT_STACK_FRAME +# +0x000 Previous : Ptr64 _RTL_ACTIVATION_CONTEXT_STACK_FRAME +# +0x008 ActivationContext : Ptr64 _ACTIVATION_CONTEXT +# +0x010 Flags : Uint4B +class RTL_ACTIVATION_CONTEXT_STACK_FRAME(Structure): + _fields_ = [ + ("Previous", PVOID), + ("ActivationContext", PVOID), + ("Flags", DWORD), +] + +# ntdll!_ACTIVATION_CONTEXT_STACK +# +0x000 ActiveFrame : Ptr64 _RTL_ACTIVATION_CONTEXT_STACK_FRAME +# +0x008 FrameListCache : _LIST_ENTRY +# +0x018 Flags : Uint4B +# +0x01c NextCookieSequenceNumber : Uint4B +# +0x020 StackId : Uint4B +class ACTIVATION_CONTEXT_STACK(Structure): + _fields_ = [ + ("ActiveFrame", PVOID), + ("FrameListCache", LIST_ENTRY), + ("Flags", DWORD), + ("NextCookieSequenceNumber", DWORD), + ("StackId", DWORD), +] + +# typedef struct _PROCESSOR_NUMBER { +# WORD Group; +# BYTE Number; +# BYTE Reserved; +# }PROCESSOR_NUMBER, *PPROCESSOR_NUMBER; +class PROCESSOR_NUMBER(Structure): + _fields_ = [ + ("Group", WORD), + ("Number", BYTE), + ("Reserved", BYTE), +] + +# from http://www.nirsoft.net/kernel_struct/vista/NT_TIB.html +# +# typedef struct _NT_TIB +# { +# PEXCEPTION_REGISTRATION_RECORD ExceptionList; +# PVOID StackBase; +# PVOID StackLimit; +# PVOID SubSystemTib; +# union +# { +# PVOID FiberData; +# ULONG Version; +# }; +# PVOID ArbitraryUserPointer; +# PNT_TIB Self; +# } NT_TIB, *PNT_TIB; +class _NT_TIB_UNION(Union): + _fields_ = [ + ("FiberData", PVOID), + ("Version", ULONG), + ] +class NT_TIB(Structure): + _fields_ = [ + ("ExceptionList", PVOID), # PEXCEPTION_REGISTRATION_RECORD + ("StackBase", PVOID), + ("StackLimit", PVOID), + ("SubSystemTib", PVOID), + ("u", _NT_TIB_UNION), + ("ArbitraryUserPointer", PVOID), + ("Self", PVOID), # PNTTIB + ] + + def __get_FiberData(self): + return self.u.FiberData + def __set_FiberData(self, value): + self.u.FiberData = value + FiberData = property(__get_FiberData, __set_FiberData) + + def __get_Version(self): + return self.u.Version + def __set_Version(self, value): + self.u.Version = value + Version = property(__get_Version, __set_Version) + +PNTTIB = POINTER(NT_TIB) + +# From http://www.nirsoft.net/kernel_struct/vista/EXCEPTION_REGISTRATION_RECORD.html +# +# typedef struct _EXCEPTION_REGISTRATION_RECORD +# { +# PEXCEPTION_REGISTRATION_RECORD Next; +# PEXCEPTION_DISPOSITION Handler; +# } EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD; +class EXCEPTION_REGISTRATION_RECORD(Structure): + pass + +EXCEPTION_DISPOSITION = DWORD +##PEXCEPTION_DISPOSITION = POINTER(EXCEPTION_DISPOSITION) +##PEXCEPTION_REGISTRATION_RECORD = POINTER(EXCEPTION_REGISTRATION_RECORD) +PEXCEPTION_DISPOSITION = PVOID +PEXCEPTION_REGISTRATION_RECORD = PVOID + +EXCEPTION_REGISTRATION_RECORD._fields_ = [ + ("Next", PEXCEPTION_REGISTRATION_RECORD), + ("Handler", PEXCEPTION_DISPOSITION), +] + +##PPEB = POINTER(PEB) +PPEB = PVOID + +# From http://www.nirsoft.net/kernel_struct/vista/GDI_TEB_BATCH.html +# +# typedef struct _GDI_TEB_BATCH +# { +# ULONG Offset; +# ULONG HDC; +# ULONG Buffer[310]; +# } GDI_TEB_BATCH, *PGDI_TEB_BATCH; +class GDI_TEB_BATCH(Structure): + _fields_ = [ + ("Offset", ULONG), + ("HDC", ULONG), + ("Buffer", ULONG * 310), +] + +# ntdll!_TEB_ACTIVE_FRAME_CONTEXT +# +0x000 Flags : Uint4B +# +0x008 FrameName : Ptr64 Char +class TEB_ACTIVE_FRAME_CONTEXT(Structure): + _fields_ = [ + ("Flags", DWORD), + ("FrameName", LPVOID), # LPCHAR +] +PTEB_ACTIVE_FRAME_CONTEXT = POINTER(TEB_ACTIVE_FRAME_CONTEXT) + +# ntdll!_TEB_ACTIVE_FRAME +# +0x000 Flags : Uint4B +# +0x008 Previous : Ptr64 _TEB_ACTIVE_FRAME +# +0x010 Context : Ptr64 _TEB_ACTIVE_FRAME_CONTEXT +class TEB_ACTIVE_FRAME(Structure): + _fields_ = [ + ("Flags", DWORD), + ("Previous", LPVOID), # PTEB_ACTIVE_FRAME + ("Context", LPVOID), # PTEB_ACTIVE_FRAME_CONTEXT +] +PTEB_ACTIVE_FRAME = POINTER(TEB_ACTIVE_FRAME) + +# SameTebFlags +DbgSafeThunkCall = 1 << 0 +DbgInDebugPrint = 1 << 1 +DbgHasFiberData = 1 << 2 +DbgSkipThreadAttach = 1 << 3 +DbgWerInShipAssertCode = 1 << 4 +DbgRanProcessInit = 1 << 5 +DbgClonedThread = 1 << 6 +DbgSuppressDebugMsg = 1 << 7 +RtlDisableUserStackWalk = 1 << 8 +RtlExceptionAttached = 1 << 9 +RtlInitialThread = 1 << 10 + +# XXX This is quite wrong :P +class _TEB_NT(Structure): + _pack_ = 4 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PPEB), + ("LastErrorValue", ULONG), + ("CountOfOwnedCriticalSections", ULONG), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", ULONG * 26), + ("UserReserved", ULONG * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", ULONG), + ("FpSoftwareStatusRegister", ULONG), + ("SystemReserved1", PVOID * 54), + ("Spare1", PVOID), + ("ExceptionCode", ULONG), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes1", ULONG * 36), + ("TxFsContext", ULONG), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", PVOID), + ("GdiClientPID", ULONG), + ("GdiClientTID", ULONG), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", PVOID * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", ULONG * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorDisabled", ULONG), + ("Instrumentation", PVOID * 9), + ("ActivityId", GUID), + ("SubProcessTag", PVOID), + ("EtwLocalData", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", ULONG), + ("SpareBool0", BOOLEAN), + ("SpareBool1", BOOLEAN), + ("SpareBool2", BOOLEAN), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", ULONG), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", ULONG), + ("StackCommit", PVOID), + ("StackCommitMax", PVOID), + ("StackReserved", PVOID), +] + +# not really, but "dt _TEB" in w2k isn't working for me :( +_TEB_2000 = _TEB_NT + +# +0x000 NtTib : _NT_TIB +# +0x01c EnvironmentPointer : Ptr32 Void +# +0x020 ClientId : _CLIENT_ID +# +0x028 ActiveRpcHandle : Ptr32 Void +# +0x02c ThreadLocalStoragePointer : Ptr32 Void +# +0x030 ProcessEnvironmentBlock : Ptr32 _PEB +# +0x034 LastErrorValue : Uint4B +# +0x038 CountOfOwnedCriticalSections : Uint4B +# +0x03c CsrClientThread : Ptr32 Void +# +0x040 Win32ThreadInfo : Ptr32 Void +# +0x044 User32Reserved : [26] Uint4B +# +0x0ac UserReserved : [5] Uint4B +# +0x0c0 WOW32Reserved : Ptr32 Void +# +0x0c4 CurrentLocale : Uint4B +# +0x0c8 FpSoftwareStatusRegister : Uint4B +# +0x0cc SystemReserved1 : [54] Ptr32 Void +# +0x1a4 ExceptionCode : Int4B +# +0x1a8 ActivationContextStack : _ACTIVATION_CONTEXT_STACK +# +0x1bc SpareBytes1 : [24] UChar +# +0x1d4 GdiTebBatch : _GDI_TEB_BATCH +# +0x6b4 RealClientId : _CLIENT_ID +# +0x6bc GdiCachedProcessHandle : Ptr32 Void +# +0x6c0 GdiClientPID : Uint4B +# +0x6c4 GdiClientTID : Uint4B +# +0x6c8 GdiThreadLocalInfo : Ptr32 Void +# +0x6cc Win32ClientInfo : [62] Uint4B +# +0x7c4 glDispatchTable : [233] Ptr32 Void +# +0xb68 glReserved1 : [29] Uint4B +# +0xbdc glReserved2 : Ptr32 Void +# +0xbe0 glSectionInfo : Ptr32 Void +# +0xbe4 glSection : Ptr32 Void +# +0xbe8 glTable : Ptr32 Void +# +0xbec glCurrentRC : Ptr32 Void +# +0xbf0 glContext : Ptr32 Void +# +0xbf4 LastStatusValue : Uint4B +# +0xbf8 StaticUnicodeString : _UNICODE_STRING +# +0xc00 StaticUnicodeBuffer : [261] Uint2B +# +0xe0c DeallocationStack : Ptr32 Void +# +0xe10 TlsSlots : [64] Ptr32 Void +# +0xf10 TlsLinks : _LIST_ENTRY +# +0xf18 Vdm : Ptr32 Void +# +0xf1c ReservedForNtRpc : Ptr32 Void +# +0xf20 DbgSsReserved : [2] Ptr32 Void +# +0xf28 HardErrorsAreDisabled : Uint4B +# +0xf2c Instrumentation : [16] Ptr32 Void +# +0xf6c WinSockData : Ptr32 Void +# +0xf70 GdiBatchCount : Uint4B +# +0xf74 InDbgPrint : UChar +# +0xf75 FreeStackOnTermination : UChar +# +0xf76 HasFiberData : UChar +# +0xf77 IdealProcessor : UChar +# +0xf78 Spare3 : Uint4B +# +0xf7c ReservedForPerf : Ptr32 Void +# +0xf80 ReservedForOle : Ptr32 Void +# +0xf84 WaitingOnLoaderLock : Uint4B +# +0xf88 Wx86Thread : _Wx86ThreadState +# +0xf94 TlsExpansionSlots : Ptr32 Ptr32 Void +# +0xf98 ImpersonationLocale : Uint4B +# +0xf9c IsImpersonating : Uint4B +# +0xfa0 NlsCache : Ptr32 Void +# +0xfa4 pShimData : Ptr32 Void +# +0xfa8 HeapVirtualAffinity : Uint4B +# +0xfac CurrentTransactionHandle : Ptr32 Void +# +0xfb0 ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME +# +0xfb4 SafeThunkCall : UChar +# +0xfb5 BooleanSpare : [3] UChar +class _TEB_XP(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes1", UCHAR * 24), + ("TxFsContext", DWORD), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", DWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", DWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorsAreDisabled", DWORD), + ("Instrumentation", PVOID * 16), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("InDbgPrint", BOOLEAN), + ("FreeStackOnTermination", BOOLEAN), + ("HasFiberData", BOOLEAN), + ("IdealProcessor", UCHAR), + ("Spare3", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("Wx86Thread", Wx86ThreadState), + ("TlsExpansionSlots", PVOID), # Ptr32 Ptr32 Void + ("ImpersonationLocale", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("SafeThunkCall", BOOLEAN), + ("BooleanSpare", BOOLEAN * 3), +] + +# +0x000 NtTib : _NT_TIB +# +0x038 EnvironmentPointer : Ptr64 Void +# +0x040 ClientId : _CLIENT_ID +# +0x050 ActiveRpcHandle : Ptr64 Void +# +0x058 ThreadLocalStoragePointer : Ptr64 Void +# +0x060 ProcessEnvironmentBlock : Ptr64 _PEB +# +0x068 LastErrorValue : Uint4B +# +0x06c CountOfOwnedCriticalSections : Uint4B +# +0x070 CsrClientThread : Ptr64 Void +# +0x078 Win32ThreadInfo : Ptr64 Void +# +0x080 User32Reserved : [26] Uint4B +# +0x0e8 UserReserved : [5] Uint4B +# +0x100 WOW32Reserved : Ptr64 Void +# +0x108 CurrentLocale : Uint4B +# +0x10c FpSoftwareStatusRegister : Uint4B +# +0x110 SystemReserved1 : [54] Ptr64 Void +# +0x2c0 ExceptionCode : Int4B +# +0x2c8 ActivationContextStackPointer : Ptr64 _ACTIVATION_CONTEXT_STACK +# +0x2d0 SpareBytes1 : [28] UChar +# +0x2f0 GdiTebBatch : _GDI_TEB_BATCH +# +0x7d8 RealClientId : _CLIENT_ID +# +0x7e8 GdiCachedProcessHandle : Ptr64 Void +# +0x7f0 GdiClientPID : Uint4B +# +0x7f4 GdiClientTID : Uint4B +# +0x7f8 GdiThreadLocalInfo : Ptr64 Void +# +0x800 Win32ClientInfo : [62] Uint8B +# +0x9f0 glDispatchTable : [233] Ptr64 Void +# +0x1138 glReserved1 : [29] Uint8B +# +0x1220 glReserved2 : Ptr64 Void +# +0x1228 glSectionInfo : Ptr64 Void +# +0x1230 glSection : Ptr64 Void +# +0x1238 glTable : Ptr64 Void +# +0x1240 glCurrentRC : Ptr64 Void +# +0x1248 glContext : Ptr64 Void +# +0x1250 LastStatusValue : Uint4B +# +0x1258 StaticUnicodeString : _UNICODE_STRING +# +0x1268 StaticUnicodeBuffer : [261] Uint2B +# +0x1478 DeallocationStack : Ptr64 Void +# +0x1480 TlsSlots : [64] Ptr64 Void +# +0x1680 TlsLinks : _LIST_ENTRY +# +0x1690 Vdm : Ptr64 Void +# +0x1698 ReservedForNtRpc : Ptr64 Void +# +0x16a0 DbgSsReserved : [2] Ptr64 Void +# +0x16b0 HardErrorMode : Uint4B +# +0x16b8 Instrumentation : [14] Ptr64 Void +# +0x1728 SubProcessTag : Ptr64 Void +# +0x1730 EtwTraceData : Ptr64 Void +# +0x1738 WinSockData : Ptr64 Void +# +0x1740 GdiBatchCount : Uint4B +# +0x1744 InDbgPrint : UChar +# +0x1745 FreeStackOnTermination : UChar +# +0x1746 HasFiberData : UChar +# +0x1747 IdealProcessor : UChar +# +0x1748 GuaranteedStackBytes : Uint4B +# +0x1750 ReservedForPerf : Ptr64 Void +# +0x1758 ReservedForOle : Ptr64 Void +# +0x1760 WaitingOnLoaderLock : Uint4B +# +0x1768 SparePointer1 : Uint8B +# +0x1770 SoftPatchPtr1 : Uint8B +# +0x1778 SoftPatchPtr2 : Uint8B +# +0x1780 TlsExpansionSlots : Ptr64 Ptr64 Void +# +0x1788 DeallocationBStore : Ptr64 Void +# +0x1790 BStoreLimit : Ptr64 Void +# +0x1798 ImpersonationLocale : Uint4B +# +0x179c IsImpersonating : Uint4B +# +0x17a0 NlsCache : Ptr64 Void +# +0x17a8 pShimData : Ptr64 Void +# +0x17b0 HeapVirtualAffinity : Uint4B +# +0x17b8 CurrentTransactionHandle : Ptr64 Void +# +0x17c0 ActiveFrame : Ptr64 _TEB_ACTIVE_FRAME +# +0x17c8 FlsData : Ptr64 Void +# +0x17d0 SafeThunkCall : UChar +# +0x17d1 BooleanSpare : [3] UChar +class _TEB_XP_64(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", PVOID), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes1", UCHAR * 28), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", QWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", QWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorMode", DWORD), + ("Instrumentation", PVOID * 14), + ("SubProcessTag", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("InDbgPrint", BOOLEAN), + ("FreeStackOnTermination", BOOLEAN), + ("HasFiberData", BOOLEAN), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("SparePointer1", PVOID), + ("SoftPatchPtr1", PVOID), + ("SoftPatchPtr2", PVOID), + ("TlsExpansionSlots", PVOID), # Ptr64 Ptr64 Void + ("DeallocationBStore", PVOID), + ("BStoreLimit", PVOID), + ("ImpersonationLocale", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("FlsData", PVOID), + ("SafeThunkCall", BOOLEAN), + ("BooleanSpare", BOOLEAN * 3), +] + +# +0x000 NtTib : _NT_TIB +# +0x01c EnvironmentPointer : Ptr32 Void +# +0x020 ClientId : _CLIENT_ID +# +0x028 ActiveRpcHandle : Ptr32 Void +# +0x02c ThreadLocalStoragePointer : Ptr32 Void +# +0x030 ProcessEnvironmentBlock : Ptr32 _PEB +# +0x034 LastErrorValue : Uint4B +# +0x038 CountOfOwnedCriticalSections : Uint4B +# +0x03c CsrClientThread : Ptr32 Void +# +0x040 Win32ThreadInfo : Ptr32 Void +# +0x044 User32Reserved : [26] Uint4B +# +0x0ac UserReserved : [5] Uint4B +# +0x0c0 WOW32Reserved : Ptr32 Void +# +0x0c4 CurrentLocale : Uint4B +# +0x0c8 FpSoftwareStatusRegister : Uint4B +# +0x0cc SystemReserved1 : [54] Ptr32 Void +# +0x1a4 ExceptionCode : Int4B +# +0x1a8 ActivationContextStackPointer : Ptr32 _ACTIVATION_CONTEXT_STACK +# +0x1ac SpareBytes1 : [40] UChar +# +0x1d4 GdiTebBatch : _GDI_TEB_BATCH +# +0x6b4 RealClientId : _CLIENT_ID +# +0x6bc GdiCachedProcessHandle : Ptr32 Void +# +0x6c0 GdiClientPID : Uint4B +# +0x6c4 GdiClientTID : Uint4B +# +0x6c8 GdiThreadLocalInfo : Ptr32 Void +# +0x6cc Win32ClientInfo : [62] Uint4B +# +0x7c4 glDispatchTable : [233] Ptr32 Void +# +0xb68 glReserved1 : [29] Uint4B +# +0xbdc glReserved2 : Ptr32 Void +# +0xbe0 glSectionInfo : Ptr32 Void +# +0xbe4 glSection : Ptr32 Void +# +0xbe8 glTable : Ptr32 Void +# +0xbec glCurrentRC : Ptr32 Void +# +0xbf0 glContext : Ptr32 Void +# +0xbf4 LastStatusValue : Uint4B +# +0xbf8 StaticUnicodeString : _UNICODE_STRING +# +0xc00 StaticUnicodeBuffer : [261] Uint2B +# +0xe0c DeallocationStack : Ptr32 Void +# +0xe10 TlsSlots : [64] Ptr32 Void +# +0xf10 TlsLinks : _LIST_ENTRY +# +0xf18 Vdm : Ptr32 Void +# +0xf1c ReservedForNtRpc : Ptr32 Void +# +0xf20 DbgSsReserved : [2] Ptr32 Void +# +0xf28 HardErrorMode : Uint4B +# +0xf2c Instrumentation : [14] Ptr32 Void +# +0xf64 SubProcessTag : Ptr32 Void +# +0xf68 EtwTraceData : Ptr32 Void +# +0xf6c WinSockData : Ptr32 Void +# +0xf70 GdiBatchCount : Uint4B +# +0xf74 InDbgPrint : UChar +# +0xf75 FreeStackOnTermination : UChar +# +0xf76 HasFiberData : UChar +# +0xf77 IdealProcessor : UChar +# +0xf78 GuaranteedStackBytes : Uint4B +# +0xf7c ReservedForPerf : Ptr32 Void +# +0xf80 ReservedForOle : Ptr32 Void +# +0xf84 WaitingOnLoaderLock : Uint4B +# +0xf88 SparePointer1 : Uint4B +# +0xf8c SoftPatchPtr1 : Uint4B +# +0xf90 SoftPatchPtr2 : Uint4B +# +0xf94 TlsExpansionSlots : Ptr32 Ptr32 Void +# +0xf98 ImpersonationLocale : Uint4B +# +0xf9c IsImpersonating : Uint4B +# +0xfa0 NlsCache : Ptr32 Void +# +0xfa4 pShimData : Ptr32 Void +# +0xfa8 HeapVirtualAffinity : Uint4B +# +0xfac CurrentTransactionHandle : Ptr32 Void +# +0xfb0 ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME +# +0xfb4 FlsData : Ptr32 Void +# +0xfb8 SafeThunkCall : UChar +# +0xfb9 BooleanSpare : [3] UChar +class _TEB_2003(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes1", UCHAR * 40), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", DWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", DWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorMode", DWORD), + ("Instrumentation", PVOID * 14), + ("SubProcessTag", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("InDbgPrint", BOOLEAN), + ("FreeStackOnTermination", BOOLEAN), + ("HasFiberData", BOOLEAN), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("SparePointer1", PVOID), + ("SoftPatchPtr1", PVOID), + ("SoftPatchPtr2", PVOID), + ("TlsExpansionSlots", PVOID), # Ptr32 Ptr32 Void + ("ImpersonationLocale", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("FlsData", PVOID), + ("SafeThunkCall", BOOLEAN), + ("BooleanSpare", BOOLEAN * 3), +] + +_TEB_2003_64 = _TEB_XP_64 +_TEB_2003_R2 = _TEB_2003 +_TEB_2003_R2_64 = _TEB_2003_64 + +# +0x000 NtTib : _NT_TIB +# +0x01c EnvironmentPointer : Ptr32 Void +# +0x020 ClientId : _CLIENT_ID +# +0x028 ActiveRpcHandle : Ptr32 Void +# +0x02c ThreadLocalStoragePointer : Ptr32 Void +# +0x030 ProcessEnvironmentBlock : Ptr32 _PEB +# +0x034 LastErrorValue : Uint4B +# +0x038 CountOfOwnedCriticalSections : Uint4B +# +0x03c CsrClientThread : Ptr32 Void +# +0x040 Win32ThreadInfo : Ptr32 Void +# +0x044 User32Reserved : [26] Uint4B +# +0x0ac UserReserved : [5] Uint4B +# +0x0c0 WOW32Reserved : Ptr32 Void +# +0x0c4 CurrentLocale : Uint4B +# +0x0c8 FpSoftwareStatusRegister : Uint4B +# +0x0cc SystemReserved1 : [54] Ptr32 Void +# +0x1a4 ExceptionCode : Int4B +# +0x1a8 ActivationContextStackPointer : Ptr32 _ACTIVATION_CONTEXT_STACK +# +0x1ac SpareBytes1 : [36] UChar +# +0x1d0 TxFsContext : Uint4B +# +0x1d4 GdiTebBatch : _GDI_TEB_BATCH +# +0x6b4 RealClientId : _CLIENT_ID +# +0x6bc GdiCachedProcessHandle : Ptr32 Void +# +0x6c0 GdiClientPID : Uint4B +# +0x6c4 GdiClientTID : Uint4B +# +0x6c8 GdiThreadLocalInfo : Ptr32 Void +# +0x6cc Win32ClientInfo : [62] Uint4B +# +0x7c4 glDispatchTable : [233] Ptr32 Void +# +0xb68 glReserved1 : [29] Uint4B +# +0xbdc glReserved2 : Ptr32 Void +# +0xbe0 glSectionInfo : Ptr32 Void +# +0xbe4 glSection : Ptr32 Void +# +0xbe8 glTable : Ptr32 Void +# +0xbec glCurrentRC : Ptr32 Void +# +0xbf0 glContext : Ptr32 Void +# +0xbf4 LastStatusValue : Uint4B +# +0xbf8 StaticUnicodeString : _UNICODE_STRING +# +0xc00 StaticUnicodeBuffer : [261] Wchar +# +0xe0c DeallocationStack : Ptr32 Void +# +0xe10 TlsSlots : [64] Ptr32 Void +# +0xf10 TlsLinks : _LIST_ENTRY +# +0xf18 Vdm : Ptr32 Void +# +0xf1c ReservedForNtRpc : Ptr32 Void +# +0xf20 DbgSsReserved : [2] Ptr32 Void +# +0xf28 HardErrorMode : Uint4B +# +0xf2c Instrumentation : [9] Ptr32 Void +# +0xf50 ActivityId : _GUID +# +0xf60 SubProcessTag : Ptr32 Void +# +0xf64 EtwLocalData : Ptr32 Void +# +0xf68 EtwTraceData : Ptr32 Void +# +0xf6c WinSockData : Ptr32 Void +# +0xf70 GdiBatchCount : Uint4B +# +0xf74 SpareBool0 : UChar +# +0xf75 SpareBool1 : UChar +# +0xf76 SpareBool2 : UChar +# +0xf77 IdealProcessor : UChar +# +0xf78 GuaranteedStackBytes : Uint4B +# +0xf7c ReservedForPerf : Ptr32 Void +# +0xf80 ReservedForOle : Ptr32 Void +# +0xf84 WaitingOnLoaderLock : Uint4B +# +0xf88 SavedPriorityState : Ptr32 Void +# +0xf8c SoftPatchPtr1 : Uint4B +# +0xf90 ThreadPoolData : Ptr32 Void +# +0xf94 TlsExpansionSlots : Ptr32 Ptr32 Void +# +0xf98 ImpersonationLocale : Uint4B +# +0xf9c IsImpersonating : Uint4B +# +0xfa0 NlsCache : Ptr32 Void +# +0xfa4 pShimData : Ptr32 Void +# +0xfa8 HeapVirtualAffinity : Uint4B +# +0xfac CurrentTransactionHandle : Ptr32 Void +# +0xfb0 ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME +# +0xfb4 FlsData : Ptr32 Void +# +0xfb8 PreferredLanguages : Ptr32 Void +# +0xfbc UserPrefLanguages : Ptr32 Void +# +0xfc0 MergedPrefLanguages : Ptr32 Void +# +0xfc4 MuiImpersonation : Uint4B +# +0xfc8 CrossTebFlags : Uint2B +# +0xfc8 SpareCrossTebBits : Pos 0, 16 Bits +# +0xfca SameTebFlags : Uint2B +# +0xfca DbgSafeThunkCall : Pos 0, 1 Bit +# +0xfca DbgInDebugPrint : Pos 1, 1 Bit +# +0xfca DbgHasFiberData : Pos 2, 1 Bit +# +0xfca DbgSkipThreadAttach : Pos 3, 1 Bit +# +0xfca DbgWerInShipAssertCode : Pos 4, 1 Bit +# +0xfca DbgRanProcessInit : Pos 5, 1 Bit +# +0xfca DbgClonedThread : Pos 6, 1 Bit +# +0xfca DbgSuppressDebugMsg : Pos 7, 1 Bit +# +0xfca RtlDisableUserStackWalk : Pos 8, 1 Bit +# +0xfca RtlExceptionAttached : Pos 9, 1 Bit +# +0xfca SpareSameTebBits : Pos 10, 6 Bits +# +0xfcc TxnScopeEnterCallback : Ptr32 Void +# +0xfd0 TxnScopeExitCallback : Ptr32 Void +# +0xfd4 TxnScopeContext : Ptr32 Void +# +0xfd8 LockCount : Uint4B +# +0xfdc ProcessRundown : Uint4B +# +0xfe0 LastSwitchTime : Uint8B +# +0xfe8 TotalSwitchOutTime : Uint8B +# +0xff0 WaitReasonBitMap : _LARGE_INTEGER +class _TEB_2008(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes1", UCHAR * 36), + ("TxFsContext", DWORD), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", DWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", DWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorMode", DWORD), + ("Instrumentation", PVOID * 9), + ("ActivityId", GUID), + ("SubProcessTag", PVOID), + ("EtwLocalData", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("SpareBool0", BOOLEAN), + ("SpareBool1", BOOLEAN), + ("SpareBool2", BOOLEAN), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("SavedPriorityState", PVOID), + ("SoftPatchPtr1", PVOID), + ("ThreadPoolData", PVOID), + ("TlsExpansionSlots", PVOID), # Ptr32 Ptr32 Void + ("ImpersonationLocale", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("FlsData", PVOID), + ("PreferredLanguages", PVOID), + ("UserPrefLanguages", PVOID), + ("MergedPrefLanguages", PVOID), + ("MuiImpersonation", BOOL), + ("CrossTebFlags", WORD), + ("SameTebFlags", WORD), + ("TxnScopeEnterCallback", PVOID), + ("TxnScopeExitCallback", PVOID), + ("TxnScopeContext", PVOID), + ("LockCount", DWORD), + ("ProcessRundown", DWORD), + ("LastSwitchTime", QWORD), + ("TotalSwitchOutTime", QWORD), + ("WaitReasonBitMap", LONGLONG), # LARGE_INTEGER +] + +# +0x000 NtTib : _NT_TIB +# +0x038 EnvironmentPointer : Ptr64 Void +# +0x040 ClientId : _CLIENT_ID +# +0x050 ActiveRpcHandle : Ptr64 Void +# +0x058 ThreadLocalStoragePointer : Ptr64 Void +# +0x060 ProcessEnvironmentBlock : Ptr64 _PEB +# +0x068 LastErrorValue : Uint4B +# +0x06c CountOfOwnedCriticalSections : Uint4B +# +0x070 CsrClientThread : Ptr64 Void +# +0x078 Win32ThreadInfo : Ptr64 Void +# +0x080 User32Reserved : [26] Uint4B +# +0x0e8 UserReserved : [5] Uint4B +# +0x100 WOW32Reserved : Ptr64 Void +# +0x108 CurrentLocale : Uint4B +# +0x10c FpSoftwareStatusRegister : Uint4B +# +0x110 SystemReserved1 : [54] Ptr64 Void +# +0x2c0 ExceptionCode : Int4B +# +0x2c8 ActivationContextStackPointer : Ptr64 _ACTIVATION_CONTEXT_STACK +# +0x2d0 SpareBytes1 : [24] UChar +# +0x2e8 TxFsContext : Uint4B +# +0x2f0 GdiTebBatch : _GDI_TEB_BATCH +# +0x7d8 RealClientId : _CLIENT_ID +# +0x7e8 GdiCachedProcessHandle : Ptr64 Void +# +0x7f0 GdiClientPID : Uint4B +# +0x7f4 GdiClientTID : Uint4B +# +0x7f8 GdiThreadLocalInfo : Ptr64 Void +# +0x800 Win32ClientInfo : [62] Uint8B +# +0x9f0 glDispatchTable : [233] Ptr64 Void +# +0x1138 glReserved1 : [29] Uint8B +# +0x1220 glReserved2 : Ptr64 Void +# +0x1228 glSectionInfo : Ptr64 Void +# +0x1230 glSection : Ptr64 Void +# +0x1238 glTable : Ptr64 Void +# +0x1240 glCurrentRC : Ptr64 Void +# +0x1248 glContext : Ptr64 Void +# +0x1250 LastStatusValue : Uint4B +# +0x1258 StaticUnicodeString : _UNICODE_STRING +# +0x1268 StaticUnicodeBuffer : [261] Wchar +# +0x1478 DeallocationStack : Ptr64 Void +# +0x1480 TlsSlots : [64] Ptr64 Void +# +0x1680 TlsLinks : _LIST_ENTRY +# +0x1690 Vdm : Ptr64 Void +# +0x1698 ReservedForNtRpc : Ptr64 Void +# +0x16a0 DbgSsReserved : [2] Ptr64 Void +# +0x16b0 HardErrorMode : Uint4B +# +0x16b8 Instrumentation : [11] Ptr64 Void +# +0x1710 ActivityId : _GUID +# +0x1720 SubProcessTag : Ptr64 Void +# +0x1728 EtwLocalData : Ptr64 Void +# +0x1730 EtwTraceData : Ptr64 Void +# +0x1738 WinSockData : Ptr64 Void +# +0x1740 GdiBatchCount : Uint4B +# +0x1744 SpareBool0 : UChar +# +0x1745 SpareBool1 : UChar +# +0x1746 SpareBool2 : UChar +# +0x1747 IdealProcessor : UChar +# +0x1748 GuaranteedStackBytes : Uint4B +# +0x1750 ReservedForPerf : Ptr64 Void +# +0x1758 ReservedForOle : Ptr64 Void +# +0x1760 WaitingOnLoaderLock : Uint4B +# +0x1768 SavedPriorityState : Ptr64 Void +# +0x1770 SoftPatchPtr1 : Uint8B +# +0x1778 ThreadPoolData : Ptr64 Void +# +0x1780 TlsExpansionSlots : Ptr64 Ptr64 Void +# +0x1788 DeallocationBStore : Ptr64 Void +# +0x1790 BStoreLimit : Ptr64 Void +# +0x1798 ImpersonationLocale : Uint4B +# +0x179c IsImpersonating : Uint4B +# +0x17a0 NlsCache : Ptr64 Void +# +0x17a8 pShimData : Ptr64 Void +# +0x17b0 HeapVirtualAffinity : Uint4B +# +0x17b8 CurrentTransactionHandle : Ptr64 Void +# +0x17c0 ActiveFrame : Ptr64 _TEB_ACTIVE_FRAME +# +0x17c8 FlsData : Ptr64 Void +# +0x17d0 PreferredLanguages : Ptr64 Void +# +0x17d8 UserPrefLanguages : Ptr64 Void +# +0x17e0 MergedPrefLanguages : Ptr64 Void +# +0x17e8 MuiImpersonation : Uint4B +# +0x17ec CrossTebFlags : Uint2B +# +0x17ec SpareCrossTebBits : Pos 0, 16 Bits +# +0x17ee SameTebFlags : Uint2B +# +0x17ee DbgSafeThunkCall : Pos 0, 1 Bit +# +0x17ee DbgInDebugPrint : Pos 1, 1 Bit +# +0x17ee DbgHasFiberData : Pos 2, 1 Bit +# +0x17ee DbgSkipThreadAttach : Pos 3, 1 Bit +# +0x17ee DbgWerInShipAssertCode : Pos 4, 1 Bit +# +0x17ee DbgRanProcessInit : Pos 5, 1 Bit +# +0x17ee DbgClonedThread : Pos 6, 1 Bit +# +0x17ee DbgSuppressDebugMsg : Pos 7, 1 Bit +# +0x17ee RtlDisableUserStackWalk : Pos 8, 1 Bit +# +0x17ee RtlExceptionAttached : Pos 9, 1 Bit +# +0x17ee SpareSameTebBits : Pos 10, 6 Bits +# +0x17f0 TxnScopeEnterCallback : Ptr64 Void +# +0x17f8 TxnScopeExitCallback : Ptr64 Void +# +0x1800 TxnScopeContext : Ptr64 Void +# +0x1808 LockCount : Uint4B +# +0x180c ProcessRundown : Uint4B +# +0x1810 LastSwitchTime : Uint8B +# +0x1818 TotalSwitchOutTime : Uint8B +# +0x1820 WaitReasonBitMap : _LARGE_INTEGER +class _TEB_2008_64(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes1", UCHAR * 24), + ("TxFsContext", DWORD), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", QWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", QWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorMode", DWORD), + ("Instrumentation", PVOID * 11), + ("ActivityId", GUID), + ("SubProcessTag", PVOID), + ("EtwLocalData", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("SpareBool0", BOOLEAN), + ("SpareBool1", BOOLEAN), + ("SpareBool2", BOOLEAN), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("SavedPriorityState", PVOID), + ("SoftPatchPtr1", PVOID), + ("ThreadPoolData", PVOID), + ("TlsExpansionSlots", PVOID), # Ptr64 Ptr64 Void + ("DeallocationBStore", PVOID), + ("BStoreLimit", PVOID), + ("ImpersonationLocale", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("FlsData", PVOID), + ("PreferredLanguages", PVOID), + ("UserPrefLanguages", PVOID), + ("MergedPrefLanguages", PVOID), + ("MuiImpersonation", BOOL), + ("CrossTebFlags", WORD), + ("SameTebFlags", WORD), + ("TxnScopeEnterCallback", PVOID), + ("TxnScopeExitCallback", PVOID), + ("TxnScopeContext", PVOID), + ("LockCount", DWORD), + ("ProcessRundown", DWORD), + ("LastSwitchTime", QWORD), + ("TotalSwitchOutTime", QWORD), + ("WaitReasonBitMap", LONGLONG), # LARGE_INTEGER +] + +# +0x000 NtTib : _NT_TIB +# +0x01c EnvironmentPointer : Ptr32 Void +# +0x020 ClientId : _CLIENT_ID +# +0x028 ActiveRpcHandle : Ptr32 Void +# +0x02c ThreadLocalStoragePointer : Ptr32 Void +# +0x030 ProcessEnvironmentBlock : Ptr32 _PEB +# +0x034 LastErrorValue : Uint4B +# +0x038 CountOfOwnedCriticalSections : Uint4B +# +0x03c CsrClientThread : Ptr32 Void +# +0x040 Win32ThreadInfo : Ptr32 Void +# +0x044 User32Reserved : [26] Uint4B +# +0x0ac UserReserved : [5] Uint4B +# +0x0c0 WOW32Reserved : Ptr32 Void +# +0x0c4 CurrentLocale : Uint4B +# +0x0c8 FpSoftwareStatusRegister : Uint4B +# +0x0cc SystemReserved1 : [54] Ptr32 Void +# +0x1a4 ExceptionCode : Int4B +# +0x1a8 ActivationContextStackPointer : Ptr32 _ACTIVATION_CONTEXT_STACK +# +0x1ac SpareBytes : [36] UChar +# +0x1d0 TxFsContext : Uint4B +# +0x1d4 GdiTebBatch : _GDI_TEB_BATCH +# +0x6b4 RealClientId : _CLIENT_ID +# +0x6bc GdiCachedProcessHandle : Ptr32 Void +# +0x6c0 GdiClientPID : Uint4B +# +0x6c4 GdiClientTID : Uint4B +# +0x6c8 GdiThreadLocalInfo : Ptr32 Void +# +0x6cc Win32ClientInfo : [62] Uint4B +# +0x7c4 glDispatchTable : [233] Ptr32 Void +# +0xb68 glReserved1 : [29] Uint4B +# +0xbdc glReserved2 : Ptr32 Void +# +0xbe0 glSectionInfo : Ptr32 Void +# +0xbe4 glSection : Ptr32 Void +# +0xbe8 glTable : Ptr32 Void +# +0xbec glCurrentRC : Ptr32 Void +# +0xbf0 glContext : Ptr32 Void +# +0xbf4 LastStatusValue : Uint4B +# +0xbf8 StaticUnicodeString : _UNICODE_STRING +# +0xc00 StaticUnicodeBuffer : [261] Wchar +# +0xe0c DeallocationStack : Ptr32 Void +# +0xe10 TlsSlots : [64] Ptr32 Void +# +0xf10 TlsLinks : _LIST_ENTRY +# +0xf18 Vdm : Ptr32 Void +# +0xf1c ReservedForNtRpc : Ptr32 Void +# +0xf20 DbgSsReserved : [2] Ptr32 Void +# +0xf28 HardErrorMode : Uint4B +# +0xf2c Instrumentation : [9] Ptr32 Void +# +0xf50 ActivityId : _GUID +# +0xf60 SubProcessTag : Ptr32 Void +# +0xf64 EtwLocalData : Ptr32 Void +# +0xf68 EtwTraceData : Ptr32 Void +# +0xf6c WinSockData : Ptr32 Void +# +0xf70 GdiBatchCount : Uint4B +# +0xf74 CurrentIdealProcessor : _PROCESSOR_NUMBER +# +0xf74 IdealProcessorValue : Uint4B +# +0xf74 ReservedPad0 : UChar +# +0xf75 ReservedPad1 : UChar +# +0xf76 ReservedPad2 : UChar +# +0xf77 IdealProcessor : UChar +# +0xf78 GuaranteedStackBytes : Uint4B +# +0xf7c ReservedForPerf : Ptr32 Void +# +0xf80 ReservedForOle : Ptr32 Void +# +0xf84 WaitingOnLoaderLock : Uint4B +# +0xf88 SavedPriorityState : Ptr32 Void +# +0xf8c SoftPatchPtr1 : Uint4B +# +0xf90 ThreadPoolData : Ptr32 Void +# +0xf94 TlsExpansionSlots : Ptr32 Ptr32 Void +# +0xf98 MuiGeneration : Uint4B +# +0xf9c IsImpersonating : Uint4B +# +0xfa0 NlsCache : Ptr32 Void +# +0xfa4 pShimData : Ptr32 Void +# +0xfa8 HeapVirtualAffinity : Uint4B +# +0xfac CurrentTransactionHandle : Ptr32 Void +# +0xfb0 ActiveFrame : Ptr32 _TEB_ACTIVE_FRAME +# +0xfb4 FlsData : Ptr32 Void +# +0xfb8 PreferredLanguages : Ptr32 Void +# +0xfbc UserPrefLanguages : Ptr32 Void +# +0xfc0 MergedPrefLanguages : Ptr32 Void +# +0xfc4 MuiImpersonation : Uint4B +# +0xfc8 CrossTebFlags : Uint2B +# +0xfc8 SpareCrossTebBits : Pos 0, 16 Bits +# +0xfca SameTebFlags : Uint2B +# +0xfca SafeThunkCall : Pos 0, 1 Bit +# +0xfca InDebugPrint : Pos 1, 1 Bit +# +0xfca HasFiberData : Pos 2, 1 Bit +# +0xfca SkipThreadAttach : Pos 3, 1 Bit +# +0xfca WerInShipAssertCode : Pos 4, 1 Bit +# +0xfca RanProcessInit : Pos 5, 1 Bit +# +0xfca ClonedThread : Pos 6, 1 Bit +# +0xfca SuppressDebugMsg : Pos 7, 1 Bit +# +0xfca DisableUserStackWalk : Pos 8, 1 Bit +# +0xfca RtlExceptionAttached : Pos 9, 1 Bit +# +0xfca InitialThread : Pos 10, 1 Bit +# +0xfca SpareSameTebBits : Pos 11, 5 Bits +# +0xfcc TxnScopeEnterCallback : Ptr32 Void +# +0xfd0 TxnScopeExitCallback : Ptr32 Void +# +0xfd4 TxnScopeContext : Ptr32 Void +# +0xfd8 LockCount : Uint4B +# +0xfdc SpareUlong0 : Uint4B +# +0xfe0 ResourceRetValue : Ptr32 Void +class _TEB_2008_R2(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes", UCHAR * 36), + ("TxFsContext", DWORD), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", DWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", DWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorMode", DWORD), + ("Instrumentation", PVOID * 9), + ("ActivityId", GUID), + ("SubProcessTag", PVOID), + ("EtwLocalData", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("CurrentIdealProcessor", PROCESSOR_NUMBER), + ("IdealProcessorValue", DWORD), + ("ReservedPad0", UCHAR), + ("ReservedPad1", UCHAR), + ("ReservedPad2", UCHAR), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("SavedPriorityState", PVOID), + ("SoftPatchPtr1", PVOID), + ("ThreadPoolData", PVOID), + ("TlsExpansionSlots", PVOID), # Ptr32 Ptr32 Void + ("MuiGeneration", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("FlsData", PVOID), + ("PreferredLanguages", PVOID), + ("UserPrefLanguages", PVOID), + ("MergedPrefLanguages", PVOID), + ("MuiImpersonation", BOOL), + ("CrossTebFlags", WORD), + ("SameTebFlags", WORD), + ("TxnScopeEnterCallback", PVOID), + ("TxnScopeExitCallback", PVOID), + ("TxnScopeContext", PVOID), + ("LockCount", DWORD), + ("SpareUlong0", ULONG), + ("ResourceRetValue", PVOID), +] + +# +0x000 NtTib : _NT_TIB +# +0x038 EnvironmentPointer : Ptr64 Void +# +0x040 ClientId : _CLIENT_ID +# +0x050 ActiveRpcHandle : Ptr64 Void +# +0x058 ThreadLocalStoragePointer : Ptr64 Void +# +0x060 ProcessEnvironmentBlock : Ptr64 _PEB +# +0x068 LastErrorValue : Uint4B +# +0x06c CountOfOwnedCriticalSections : Uint4B +# +0x070 CsrClientThread : Ptr64 Void +# +0x078 Win32ThreadInfo : Ptr64 Void +# +0x080 User32Reserved : [26] Uint4B +# +0x0e8 UserReserved : [5] Uint4B +# +0x100 WOW32Reserved : Ptr64 Void +# +0x108 CurrentLocale : Uint4B +# +0x10c FpSoftwareStatusRegister : Uint4B +# +0x110 SystemReserved1 : [54] Ptr64 Void +# +0x2c0 ExceptionCode : Int4B +# +0x2c8 ActivationContextStackPointer : Ptr64 _ACTIVATION_CONTEXT_STACK +# +0x2d0 SpareBytes : [24] UChar +# +0x2e8 TxFsContext : Uint4B +# +0x2f0 GdiTebBatch : _GDI_TEB_BATCH +# +0x7d8 RealClientId : _CLIENT_ID +# +0x7e8 GdiCachedProcessHandle : Ptr64 Void +# +0x7f0 GdiClientPID : Uint4B +# +0x7f4 GdiClientTID : Uint4B +# +0x7f8 GdiThreadLocalInfo : Ptr64 Void +# +0x800 Win32ClientInfo : [62] Uint8B +# +0x9f0 glDispatchTable : [233] Ptr64 Void +# +0x1138 glReserved1 : [29] Uint8B +# +0x1220 glReserved2 : Ptr64 Void +# +0x1228 glSectionInfo : Ptr64 Void +# +0x1230 glSection : Ptr64 Void +# +0x1238 glTable : Ptr64 Void +# +0x1240 glCurrentRC : Ptr64 Void +# +0x1248 glContext : Ptr64 Void +# +0x1250 LastStatusValue : Uint4B +# +0x1258 StaticUnicodeString : _UNICODE_STRING +# +0x1268 StaticUnicodeBuffer : [261] Wchar +# +0x1478 DeallocationStack : Ptr64 Void +# +0x1480 TlsSlots : [64] Ptr64 Void +# +0x1680 TlsLinks : _LIST_ENTRY +# +0x1690 Vdm : Ptr64 Void +# +0x1698 ReservedForNtRpc : Ptr64 Void +# +0x16a0 DbgSsReserved : [2] Ptr64 Void +# +0x16b0 HardErrorMode : Uint4B +# +0x16b8 Instrumentation : [11] Ptr64 Void +# +0x1710 ActivityId : _GUID +# +0x1720 SubProcessTag : Ptr64 Void +# +0x1728 EtwLocalData : Ptr64 Void +# +0x1730 EtwTraceData : Ptr64 Void +# +0x1738 WinSockData : Ptr64 Void +# +0x1740 GdiBatchCount : Uint4B +# +0x1744 CurrentIdealProcessor : _PROCESSOR_NUMBER +# +0x1744 IdealProcessorValue : Uint4B +# +0x1744 ReservedPad0 : UChar +# +0x1745 ReservedPad1 : UChar +# +0x1746 ReservedPad2 : UChar +# +0x1747 IdealProcessor : UChar +# +0x1748 GuaranteedStackBytes : Uint4B +# +0x1750 ReservedForPerf : Ptr64 Void +# +0x1758 ReservedForOle : Ptr64 Void +# +0x1760 WaitingOnLoaderLock : Uint4B +# +0x1768 SavedPriorityState : Ptr64 Void +# +0x1770 SoftPatchPtr1 : Uint8B +# +0x1778 ThreadPoolData : Ptr64 Void +# +0x1780 TlsExpansionSlots : Ptr64 Ptr64 Void +# +0x1788 DeallocationBStore : Ptr64 Void +# +0x1790 BStoreLimit : Ptr64 Void +# +0x1798 MuiGeneration : Uint4B +# +0x179c IsImpersonating : Uint4B +# +0x17a0 NlsCache : Ptr64 Void +# +0x17a8 pShimData : Ptr64 Void +# +0x17b0 HeapVirtualAffinity : Uint4B +# +0x17b8 CurrentTransactionHandle : Ptr64 Void +# +0x17c0 ActiveFrame : Ptr64 _TEB_ACTIVE_FRAME +# +0x17c8 FlsData : Ptr64 Void +# +0x17d0 PreferredLanguages : Ptr64 Void +# +0x17d8 UserPrefLanguages : Ptr64 Void +# +0x17e0 MergedPrefLanguages : Ptr64 Void +# +0x17e8 MuiImpersonation : Uint4B +# +0x17ec CrossTebFlags : Uint2B +# +0x17ec SpareCrossTebBits : Pos 0, 16 Bits +# +0x17ee SameTebFlags : Uint2B +# +0x17ee SafeThunkCall : Pos 0, 1 Bit +# +0x17ee InDebugPrint : Pos 1, 1 Bit +# +0x17ee HasFiberData : Pos 2, 1 Bit +# +0x17ee SkipThreadAttach : Pos 3, 1 Bit +# +0x17ee WerInShipAssertCode : Pos 4, 1 Bit +# +0x17ee RanProcessInit : Pos 5, 1 Bit +# +0x17ee ClonedThread : Pos 6, 1 Bit +# +0x17ee SuppressDebugMsg : Pos 7, 1 Bit +# +0x17ee DisableUserStackWalk : Pos 8, 1 Bit +# +0x17ee RtlExceptionAttached : Pos 9, 1 Bit +# +0x17ee InitialThread : Pos 10, 1 Bit +# +0x17ee SpareSameTebBits : Pos 11, 5 Bits +# +0x17f0 TxnScopeEnterCallback : Ptr64 Void +# +0x17f8 TxnScopeExitCallback : Ptr64 Void +# +0x1800 TxnScopeContext : Ptr64 Void +# +0x1808 LockCount : Uint4B +# +0x180c SpareUlong0 : Uint4B +# +0x1810 ResourceRetValue : Ptr64 Void +class _TEB_2008_R2_64(Structure): + _pack_ = 8 + _fields_ = [ + ("NtTib", NT_TIB), + ("EnvironmentPointer", PVOID), + ("ClientId", CLIENT_ID), + ("ActiveRpcHandle", HANDLE), + ("ThreadLocalStoragePointer", PVOID), + ("ProcessEnvironmentBlock", PVOID), # PPEB + ("LastErrorValue", DWORD), + ("CountOfOwnedCriticalSections", DWORD), + ("CsrClientThread", PVOID), + ("Win32ThreadInfo", PVOID), + ("User32Reserved", DWORD * 26), + ("UserReserved", DWORD * 5), + ("WOW32Reserved", PVOID), # ptr to wow64cpu!X86SwitchTo64BitMode + ("CurrentLocale", DWORD), + ("FpSoftwareStatusRegister", DWORD), + ("SystemReserved1", PVOID * 54), + ("ExceptionCode", SDWORD), + ("ActivationContextStackPointer", PVOID), # PACTIVATION_CONTEXT_STACK + ("SpareBytes", UCHAR * 24), + ("TxFsContext", DWORD), + ("GdiTebBatch", GDI_TEB_BATCH), + ("RealClientId", CLIENT_ID), + ("GdiCachedProcessHandle", HANDLE), + ("GdiClientPID", DWORD), + ("GdiClientTID", DWORD), + ("GdiThreadLocalInfo", PVOID), + ("Win32ClientInfo", DWORD * 62), + ("glDispatchTable", PVOID * 233), + ("glReserved1", QWORD * 29), + ("glReserved2", PVOID), + ("glSectionInfo", PVOID), + ("glSection", PVOID), + ("glTable", PVOID), + ("glCurrentRC", PVOID), + ("glContext", PVOID), + ("LastStatusValue", NTSTATUS), + ("StaticUnicodeString", UNICODE_STRING), + ("StaticUnicodeBuffer", WCHAR * 261), + ("DeallocationStack", PVOID), + ("TlsSlots", PVOID * 64), + ("TlsLinks", LIST_ENTRY), + ("Vdm", PVOID), + ("ReservedForNtRpc", PVOID), + ("DbgSsReserved", PVOID * 2), + ("HardErrorMode", DWORD), + ("Instrumentation", PVOID * 11), + ("ActivityId", GUID), + ("SubProcessTag", PVOID), + ("EtwLocalData", PVOID), + ("EtwTraceData", PVOID), + ("WinSockData", PVOID), + ("GdiBatchCount", DWORD), + ("CurrentIdealProcessor", PROCESSOR_NUMBER), + ("IdealProcessorValue", DWORD), + ("ReservedPad0", UCHAR), + ("ReservedPad1", UCHAR), + ("ReservedPad2", UCHAR), + ("IdealProcessor", UCHAR), + ("GuaranteedStackBytes", DWORD), + ("ReservedForPerf", PVOID), + ("ReservedForOle", PVOID), + ("WaitingOnLoaderLock", DWORD), + ("SavedPriorityState", PVOID), + ("SoftPatchPtr1", PVOID), + ("ThreadPoolData", PVOID), + ("TlsExpansionSlots", PVOID), # Ptr64 Ptr64 Void + ("DeallocationBStore", PVOID), + ("BStoreLimit", PVOID), + ("MuiGeneration", DWORD), + ("IsImpersonating", BOOL), + ("NlsCache", PVOID), + ("pShimData", PVOID), + ("HeapVirtualAffinity", DWORD), + ("CurrentTransactionHandle", HANDLE), + ("ActiveFrame", PVOID), # PTEB_ACTIVE_FRAME + ("FlsData", PVOID), + ("PreferredLanguages", PVOID), + ("UserPrefLanguages", PVOID), + ("MergedPrefLanguages", PVOID), + ("MuiImpersonation", BOOL), + ("CrossTebFlags", WORD), + ("SameTebFlags", WORD), + ("TxnScopeEnterCallback", PVOID), + ("TxnScopeExitCallback", PVOID), + ("TxnScopeContext", PVOID), + ("LockCount", DWORD), + ("SpareUlong0", ULONG), + ("ResourceRetValue", PVOID), +] + +_TEB_Vista = _TEB_2008 +_TEB_Vista_64 = _TEB_2008_64 +_TEB_W7 = _TEB_2008_R2 +_TEB_W7_64 = _TEB_2008_R2_64 + +# Use the correct TEB structure definition. +# Defaults to the latest Windows version. +class TEB(Structure): + _pack_ = 8 + if os == 'Windows NT': + _pack_ = _TEB_NT._pack_ + _fields_ = _TEB_NT._fields_ + elif os == 'Windows 2000': + _pack_ = _TEB_2000._pack_ + _fields_ = _TEB_2000._fields_ + elif os == 'Windows XP': + _fields_ = _TEB_XP._fields_ + elif os == 'Windows XP (64 bits)': + _fields_ = _TEB_XP_64._fields_ + elif os == 'Windows 2003': + _fields_ = _TEB_2003._fields_ + elif os == 'Windows 2003 (64 bits)': + _fields_ = _TEB_2003_64._fields_ + elif os == 'Windows 2008': + _fields_ = _TEB_2008._fields_ + elif os == 'Windows 2008 (64 bits)': + _fields_ = _TEB_2008_64._fields_ + elif os == 'Windows 2003 R2': + _fields_ = _TEB_2003_R2._fields_ + elif os == 'Windows 2003 R2 (64 bits)': + _fields_ = _TEB_2003_R2_64._fields_ + elif os == 'Windows 2008 R2': + _fields_ = _TEB_2008_R2._fields_ + elif os == 'Windows 2008 R2 (64 bits)': + _fields_ = _TEB_2008_R2_64._fields_ + elif os == 'Windows Vista': + _fields_ = _TEB_Vista._fields_ + elif os == 'Windows Vista (64 bits)': + _fields_ = _TEB_Vista_64._fields_ + elif os == 'Windows 7': + _fields_ = _TEB_W7._fields_ + elif os == 'Windows 7 (64 bits)': + _fields_ = _TEB_W7_64._fields_ + elif sizeof(SIZE_T) == sizeof(DWORD): + _fields_ = _TEB_W7._fields_ + else: + _fields_ = _TEB_W7_64._fields_ +PTEB = POINTER(TEB) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/psapi.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/psapi.py new file mode 100644 index 0000000..e353c7f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/psapi.py @@ -0,0 +1,387 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for psapi.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- PSAPI structures and constants ------------------------------------------- + +LIST_MODULES_DEFAULT = 0x00 +LIST_MODULES_32BIT = 0x01 +LIST_MODULES_64BIT = 0x02 +LIST_MODULES_ALL = 0x03 + +# typedef struct _MODULEINFO { +# LPVOID lpBaseOfDll; +# DWORD SizeOfImage; +# LPVOID EntryPoint; +# } MODULEINFO, *LPMODULEINFO; +class MODULEINFO(Structure): + _fields_ = [ + ("lpBaseOfDll", LPVOID), # remote pointer + ("SizeOfImage", DWORD), + ("EntryPoint", LPVOID), # remote pointer +] +LPMODULEINFO = POINTER(MODULEINFO) + +#--- psapi.dll ---------------------------------------------------------------- + +# BOOL WINAPI EnumDeviceDrivers( +# __out LPVOID *lpImageBase, +# __in DWORD cb, +# __out LPDWORD lpcbNeeded +# ); +def EnumDeviceDrivers(): + _EnumDeviceDrivers = windll.psapi.EnumDeviceDrivers + _EnumDeviceDrivers.argtypes = [LPVOID, DWORD, LPDWORD] + _EnumDeviceDrivers.restype = bool + _EnumDeviceDrivers.errcheck = RaiseIfZero + + size = 0x1000 + lpcbNeeded = DWORD(size) + unit = sizeof(LPVOID) + while 1: + lpImageBase = (LPVOID * (size // unit))() + _EnumDeviceDrivers(byref(lpImageBase), lpcbNeeded, byref(lpcbNeeded)) + needed = lpcbNeeded.value + if needed <= size: + break + size = needed + return [ lpImageBase[index] for index in compat.xrange(0, (needed // unit)) ] + +# BOOL WINAPI EnumProcesses( +# __out DWORD *pProcessIds, +# __in DWORD cb, +# __out DWORD *pBytesReturned +# ); +def EnumProcesses(): + _EnumProcesses = windll.psapi.EnumProcesses + _EnumProcesses.argtypes = [LPVOID, DWORD, LPDWORD] + _EnumProcesses.restype = bool + _EnumProcesses.errcheck = RaiseIfZero + + size = 0x1000 + cbBytesReturned = DWORD() + unit = sizeof(DWORD) + while 1: + ProcessIds = (DWORD * (size // unit))() + cbBytesReturned.value = size + _EnumProcesses(byref(ProcessIds), cbBytesReturned, byref(cbBytesReturned)) + returned = cbBytesReturned.value + if returned < size: + break + size = size + 0x1000 + ProcessIdList = list() + for ProcessId in ProcessIds: + if ProcessId is None: + break + ProcessIdList.append(ProcessId) + return ProcessIdList + +# BOOL WINAPI EnumProcessModules( +# __in HANDLE hProcess, +# __out HMODULE *lphModule, +# __in DWORD cb, +# __out LPDWORD lpcbNeeded +# ); +def EnumProcessModules(hProcess): + _EnumProcessModules = windll.psapi.EnumProcessModules + _EnumProcessModules.argtypes = [HANDLE, LPVOID, DWORD, LPDWORD] + _EnumProcessModules.restype = bool + _EnumProcessModules.errcheck = RaiseIfZero + + size = 0x1000 + lpcbNeeded = DWORD(size) + unit = sizeof(HMODULE) + while 1: + lphModule = (HMODULE * (size // unit))() + _EnumProcessModules(hProcess, byref(lphModule), lpcbNeeded, byref(lpcbNeeded)) + needed = lpcbNeeded.value + if needed <= size: + break + size = needed + return [ lphModule[index] for index in compat.xrange(0, int(needed // unit)) ] + +# BOOL WINAPI EnumProcessModulesEx( +# __in HANDLE hProcess, +# __out HMODULE *lphModule, +# __in DWORD cb, +# __out LPDWORD lpcbNeeded, +# __in DWORD dwFilterFlag +# ); +def EnumProcessModulesEx(hProcess, dwFilterFlag = LIST_MODULES_DEFAULT): + _EnumProcessModulesEx = windll.psapi.EnumProcessModulesEx + _EnumProcessModulesEx.argtypes = [HANDLE, LPVOID, DWORD, LPDWORD, DWORD] + _EnumProcessModulesEx.restype = bool + _EnumProcessModulesEx.errcheck = RaiseIfZero + + size = 0x1000 + lpcbNeeded = DWORD(size) + unit = sizeof(HMODULE) + while 1: + lphModule = (HMODULE * (size // unit))() + _EnumProcessModulesEx(hProcess, byref(lphModule), lpcbNeeded, byref(lpcbNeeded), dwFilterFlag) + needed = lpcbNeeded.value + if needed <= size: + break + size = needed + return [ lphModule[index] for index in compat.xrange(0, (needed // unit)) ] + +# DWORD WINAPI GetDeviceDriverBaseName( +# __in LPVOID ImageBase, +# __out LPTSTR lpBaseName, +# __in DWORD nSize +# ); +def GetDeviceDriverBaseNameA(ImageBase): + _GetDeviceDriverBaseNameA = windll.psapi.GetDeviceDriverBaseNameA + _GetDeviceDriverBaseNameA.argtypes = [LPVOID, LPSTR, DWORD] + _GetDeviceDriverBaseNameA.restype = DWORD + + nSize = MAX_PATH + while 1: + lpBaseName = ctypes.create_string_buffer("", nSize) + nCopied = _GetDeviceDriverBaseNameA(ImageBase, lpBaseName, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpBaseName.value + +def GetDeviceDriverBaseNameW(ImageBase): + _GetDeviceDriverBaseNameW = windll.psapi.GetDeviceDriverBaseNameW + _GetDeviceDriverBaseNameW.argtypes = [LPVOID, LPWSTR, DWORD] + _GetDeviceDriverBaseNameW.restype = DWORD + + nSize = MAX_PATH + while 1: + lpBaseName = ctypes.create_unicode_buffer(u"", nSize) + nCopied = _GetDeviceDriverBaseNameW(ImageBase, lpBaseName, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpBaseName.value + +GetDeviceDriverBaseName = GuessStringType(GetDeviceDriverBaseNameA, GetDeviceDriverBaseNameW) + +# DWORD WINAPI GetDeviceDriverFileName( +# __in LPVOID ImageBase, +# __out LPTSTR lpFilename, +# __in DWORD nSize +# ); +def GetDeviceDriverFileNameA(ImageBase): + _GetDeviceDriverFileNameA = windll.psapi.GetDeviceDriverFileNameA + _GetDeviceDriverFileNameA.argtypes = [LPVOID, LPSTR, DWORD] + _GetDeviceDriverFileNameA.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_string_buffer("", nSize) + nCopied = ctypes.windll.psapi.GetDeviceDriverFileNameA(ImageBase, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +def GetDeviceDriverFileNameW(ImageBase): + _GetDeviceDriverFileNameW = windll.psapi.GetDeviceDriverFileNameW + _GetDeviceDriverFileNameW.argtypes = [LPVOID, LPWSTR, DWORD] + _GetDeviceDriverFileNameW.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_unicode_buffer(u"", nSize) + nCopied = ctypes.windll.psapi.GetDeviceDriverFileNameW(ImageBase, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +GetDeviceDriverFileName = GuessStringType(GetDeviceDriverFileNameA, GetDeviceDriverFileNameW) + +# DWORD WINAPI GetMappedFileName( +# __in HANDLE hProcess, +# __in LPVOID lpv, +# __out LPTSTR lpFilename, +# __in DWORD nSize +# ); +def GetMappedFileNameA(hProcess, lpv): + _GetMappedFileNameA = ctypes.windll.psapi.GetMappedFileNameA + _GetMappedFileNameA.argtypes = [HANDLE, LPVOID, LPSTR, DWORD] + _GetMappedFileNameA.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_string_buffer("", nSize) + nCopied = _GetMappedFileNameA(hProcess, lpv, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +def GetMappedFileNameW(hProcess, lpv): + _GetMappedFileNameW = ctypes.windll.psapi.GetMappedFileNameW + _GetMappedFileNameW.argtypes = [HANDLE, LPVOID, LPWSTR, DWORD] + _GetMappedFileNameW.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_unicode_buffer(u"", nSize) + nCopied = _GetMappedFileNameW(hProcess, lpv, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +GetMappedFileName = GuessStringType(GetMappedFileNameA, GetMappedFileNameW) + +# DWORD WINAPI GetModuleFileNameEx( +# __in HANDLE hProcess, +# __in_opt HMODULE hModule, +# __out LPTSTR lpFilename, +# __in DWORD nSize +# ); +def GetModuleFileNameExA(hProcess, hModule = None): + _GetModuleFileNameExA = ctypes.windll.psapi.GetModuleFileNameExA + _GetModuleFileNameExA.argtypes = [HANDLE, HMODULE, LPSTR, DWORD] + _GetModuleFileNameExA.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_string_buffer("", nSize) + nCopied = _GetModuleFileNameExA(hProcess, hModule, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +def GetModuleFileNameExW(hProcess, hModule = None): + _GetModuleFileNameExW = ctypes.windll.psapi.GetModuleFileNameExW + _GetModuleFileNameExW.argtypes = [HANDLE, HMODULE, LPWSTR, DWORD] + _GetModuleFileNameExW.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_unicode_buffer(u"", nSize) + nCopied = _GetModuleFileNameExW(hProcess, hModule, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +GetModuleFileNameEx = GuessStringType(GetModuleFileNameExA, GetModuleFileNameExW) + +# BOOL WINAPI GetModuleInformation( +# __in HANDLE hProcess, +# __in HMODULE hModule, +# __out LPMODULEINFO lpmodinfo, +# __in DWORD cb +# ); +def GetModuleInformation(hProcess, hModule, lpmodinfo = None): + _GetModuleInformation = windll.psapi.GetModuleInformation + _GetModuleInformation.argtypes = [HANDLE, HMODULE, LPMODULEINFO, DWORD] + _GetModuleInformation.restype = bool + _GetModuleInformation.errcheck = RaiseIfZero + + if lpmodinfo is None: + lpmodinfo = MODULEINFO() + _GetModuleInformation(hProcess, hModule, byref(lpmodinfo), sizeof(lpmodinfo)) + return lpmodinfo + +# DWORD WINAPI GetProcessImageFileName( +# __in HANDLE hProcess, +# __out LPTSTR lpImageFileName, +# __in DWORD nSize +# ); +def GetProcessImageFileNameA(hProcess): + _GetProcessImageFileNameA = windll.psapi.GetProcessImageFileNameA + _GetProcessImageFileNameA.argtypes = [HANDLE, LPSTR, DWORD] + _GetProcessImageFileNameA.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_string_buffer("", nSize) + nCopied = _GetProcessImageFileNameA(hProcess, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +def GetProcessImageFileNameW(hProcess): + _GetProcessImageFileNameW = windll.psapi.GetProcessImageFileNameW + _GetProcessImageFileNameW.argtypes = [HANDLE, LPWSTR, DWORD] + _GetProcessImageFileNameW.restype = DWORD + + nSize = MAX_PATH + while 1: + lpFilename = ctypes.create_unicode_buffer(u"", nSize) + nCopied = _GetProcessImageFileNameW(hProcess, lpFilename, nSize) + if nCopied == 0: + raise ctypes.WinError() + if nCopied < (nSize - 1): + break + nSize = nSize + MAX_PATH + return lpFilename.value + +GetProcessImageFileName = GuessStringType(GetProcessImageFileNameA, GetProcessImageFileNameW) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shell32.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shell32.py new file mode 100644 index 0000000..5c945db --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shell32.py @@ -0,0 +1,382 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for shell32.dll in ctypes. +""" + +# TODO +# * Add a class wrapper to SHELLEXECUTEINFO +# * More logic into ShellExecuteEx + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.kernel32 import LocalFree + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- Constants ---------------------------------------------------------------- + +SEE_MASK_DEFAULT = 0x00000000 +SEE_MASK_CLASSNAME = 0x00000001 +SEE_MASK_CLASSKEY = 0x00000003 +SEE_MASK_IDLIST = 0x00000004 +SEE_MASK_INVOKEIDLIST = 0x0000000C +SEE_MASK_ICON = 0x00000010 +SEE_MASK_HOTKEY = 0x00000020 +SEE_MASK_NOCLOSEPROCESS = 0x00000040 +SEE_MASK_CONNECTNETDRV = 0x00000080 +SEE_MASK_NOASYNC = 0x00000100 +SEE_MASK_DOENVSUBST = 0x00000200 +SEE_MASK_FLAG_NO_UI = 0x00000400 +SEE_MASK_UNICODE = 0x00004000 +SEE_MASK_NO_CONSOLE = 0x00008000 +SEE_MASK_ASYNCOK = 0x00100000 +SEE_MASK_HMONITOR = 0x00200000 +SEE_MASK_NOZONECHECKS = 0x00800000 +SEE_MASK_WAITFORINPUTIDLE = 0x02000000 +SEE_MASK_FLAG_LOG_USAGE = 0x04000000 + +SE_ERR_FNF = 2 +SE_ERR_PNF = 3 +SE_ERR_ACCESSDENIED = 5 +SE_ERR_OOM = 8 +SE_ERR_DLLNOTFOUND = 32 +SE_ERR_SHARE = 26 +SE_ERR_ASSOCINCOMPLETE = 27 +SE_ERR_DDETIMEOUT = 28 +SE_ERR_DDEFAIL = 29 +SE_ERR_DDEBUSY = 30 +SE_ERR_NOASSOC = 31 + +SHGFP_TYPE_CURRENT = 0 +SHGFP_TYPE_DEFAULT = 1 + +CSIDL_DESKTOP = 0x0000 +CSIDL_INTERNET = 0x0001 +CSIDL_PROGRAMS = 0x0002 +CSIDL_CONTROLS = 0x0003 +CSIDL_PRINTERS = 0x0004 +CSIDL_PERSONAL = 0x0005 +CSIDL_FAVORITES = 0x0006 +CSIDL_STARTUP = 0x0007 +CSIDL_RECENT = 0x0008 +CSIDL_SENDTO = 0x0009 +CSIDL_BITBUCKET = 0x000a +CSIDL_STARTMENU = 0x000b +CSIDL_MYDOCUMENTS = CSIDL_PERSONAL +CSIDL_MYMUSIC = 0x000d +CSIDL_MYVIDEO = 0x000e +CSIDL_DESKTOPDIRECTORY = 0x0010 +CSIDL_DRIVES = 0x0011 +CSIDL_NETWORK = 0x0012 +CSIDL_NETHOOD = 0x0013 +CSIDL_FONTS = 0x0014 +CSIDL_TEMPLATES = 0x0015 +CSIDL_COMMON_STARTMENU = 0x0016 +CSIDL_COMMON_PROGRAMS = 0x0017 +CSIDL_COMMON_STARTUP = 0x0018 +CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019 +CSIDL_APPDATA = 0x001a +CSIDL_PRINTHOOD = 0x001b +CSIDL_LOCAL_APPDATA = 0x001c +CSIDL_ALTSTARTUP = 0x001d +CSIDL_COMMON_ALTSTARTUP = 0x001e +CSIDL_COMMON_FAVORITES = 0x001f +CSIDL_INTERNET_CACHE = 0x0020 +CSIDL_COOKIES = 0x0021 +CSIDL_HISTORY = 0x0022 +CSIDL_COMMON_APPDATA = 0x0023 +CSIDL_WINDOWS = 0x0024 +CSIDL_SYSTEM = 0x0025 +CSIDL_PROGRAM_FILES = 0x0026 +CSIDL_MYPICTURES = 0x0027 +CSIDL_PROFILE = 0x0028 +CSIDL_SYSTEMX86 = 0x0029 +CSIDL_PROGRAM_FILESX86 = 0x002a +CSIDL_PROGRAM_FILES_COMMON = 0x002b +CSIDL_PROGRAM_FILES_COMMONX86 = 0x002c +CSIDL_COMMON_TEMPLATES = 0x002d +CSIDL_COMMON_DOCUMENTS = 0x002e +CSIDL_COMMON_ADMINTOOLS = 0x002f +CSIDL_ADMINTOOLS = 0x0030 +CSIDL_CONNECTIONS = 0x0031 +CSIDL_COMMON_MUSIC = 0x0035 +CSIDL_COMMON_PICTURES = 0x0036 +CSIDL_COMMON_VIDEO = 0x0037 +CSIDL_RESOURCES = 0x0038 +CSIDL_RESOURCES_LOCALIZED = 0x0039 +CSIDL_COMMON_OEM_LINKS = 0x003a +CSIDL_CDBURN_AREA = 0x003b +CSIDL_COMPUTERSNEARME = 0x003d +CSIDL_PROFILES = 0x003e + +CSIDL_FOLDER_MASK = 0x00ff + +CSIDL_FLAG_PER_USER_INIT = 0x0800 +CSIDL_FLAG_NO_ALIAS = 0x1000 +CSIDL_FLAG_DONT_VERIFY = 0x4000 +CSIDL_FLAG_CREATE = 0x8000 + +CSIDL_FLAG_MASK = 0xff00 + +#--- Structures --------------------------------------------------------------- + +# typedef struct _SHELLEXECUTEINFO { +# DWORD cbSize; +# ULONG fMask; +# HWND hwnd; +# LPCTSTR lpVerb; +# LPCTSTR lpFile; +# LPCTSTR lpParameters; +# LPCTSTR lpDirectory; +# int nShow; +# HINSTANCE hInstApp; +# LPVOID lpIDList; +# LPCTSTR lpClass; +# HKEY hkeyClass; +# DWORD dwHotKey; +# union { +# HANDLE hIcon; +# HANDLE hMonitor; +# } DUMMYUNIONNAME; +# HANDLE hProcess; +# } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; + +class SHELLEXECUTEINFO(Structure): + _fields_ = [ + ("cbSize", DWORD), + ("fMask", ULONG), + ("hwnd", HWND), + ("lpVerb", LPSTR), + ("lpFile", LPSTR), + ("lpParameters", LPSTR), + ("lpDirectory", LPSTR), + ("nShow", ctypes.c_int), + ("hInstApp", HINSTANCE), + ("lpIDList", LPVOID), + ("lpClass", LPSTR), + ("hkeyClass", HKEY), + ("dwHotKey", DWORD), + ("hIcon", HANDLE), + ("hProcess", HANDLE), + ] + + def __get_hMonitor(self): + return self.hIcon + def __set_hMonitor(self, hMonitor): + self.hIcon = hMonitor + hMonitor = property(__get_hMonitor, __set_hMonitor) + +LPSHELLEXECUTEINFO = POINTER(SHELLEXECUTEINFO) + +#--- shell32.dll -------------------------------------------------------------- + +# LPWSTR *CommandLineToArgvW( +# LPCWSTR lpCmdLine, +# int *pNumArgs +# ); +def CommandLineToArgvW(lpCmdLine): + _CommandLineToArgvW = windll.shell32.CommandLineToArgvW + _CommandLineToArgvW.argtypes = [LPVOID, POINTER(ctypes.c_int)] + _CommandLineToArgvW.restype = LPVOID + + if not lpCmdLine: + lpCmdLine = None + argc = ctypes.c_int(0) + vptr = ctypes.windll.shell32.CommandLineToArgvW(lpCmdLine, byref(argc)) + if vptr == NULL: + raise ctypes.WinError() + argv = vptr + try: + argc = argc.value + if argc <= 0: + raise ctypes.WinError() + argv = ctypes.cast(argv, ctypes.POINTER(LPWSTR * argc) ) + argv = [ argv.contents[i] for i in compat.xrange(0, argc) ] + finally: + if vptr is not None: + LocalFree(vptr) + return argv + +def CommandLineToArgvA(lpCmdLine): + t_ansi = GuessStringType.t_ansi + t_unicode = GuessStringType.t_unicode + if isinstance(lpCmdLine, t_ansi): + cmdline = t_unicode(lpCmdLine) + else: + cmdline = lpCmdLine + return [t_ansi(x) for x in CommandLineToArgvW(cmdline)] + +CommandLineToArgv = GuessStringType(CommandLineToArgvA, CommandLineToArgvW) + +# HINSTANCE ShellExecute( +# HWND hwnd, +# LPCTSTR lpOperation, +# LPCTSTR lpFile, +# LPCTSTR lpParameters, +# LPCTSTR lpDirectory, +# INT nShowCmd +# ); +def ShellExecuteA(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None): + _ShellExecuteA = windll.shell32.ShellExecuteA + _ShellExecuteA.argtypes = [HWND, LPSTR, LPSTR, LPSTR, LPSTR, INT] + _ShellExecuteA.restype = HINSTANCE + + if not nShowCmd: + nShowCmd = 0 + success = _ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) + success = ctypes.cast(success, c_int) + success = success.value + if not success > 32: # weird! isn't it? + raise ctypes.WinError(success) + +def ShellExecuteW(hwnd = None, lpOperation = None, lpFile = None, lpParameters = None, lpDirectory = None, nShowCmd = None): + _ShellExecuteW = windll.shell32.ShellExecuteW + _ShellExecuteW.argtypes = [HWND, LPWSTR, LPWSTR, LPWSTR, LPWSTR, INT] + _ShellExecuteW.restype = HINSTANCE + + if not nShowCmd: + nShowCmd = 0 + success = _ShellExecuteW(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd) + success = ctypes.cast(success, c_int) + success = success.value + if not success > 32: # weird! isn't it? + raise ctypes.WinError(success) + +ShellExecute = GuessStringType(ShellExecuteA, ShellExecuteW) + +# BOOL ShellExecuteEx( +# __inout LPSHELLEXECUTEINFO lpExecInfo +# ); +def ShellExecuteEx(lpExecInfo): + if isinstance(lpExecInfo, SHELLEXECUTEINFOA): + ShellExecuteExA(lpExecInfo) + elif isinstance(lpExecInfo, SHELLEXECUTEINFOW): + ShellExecuteExW(lpExecInfo) + else: + raise TypeError("Expected SHELLEXECUTEINFOA or SHELLEXECUTEINFOW, got %s instead" % type(lpExecInfo)) + +def ShellExecuteExA(lpExecInfo): + _ShellExecuteExA = windll.shell32.ShellExecuteExA + _ShellExecuteExA.argtypes = [LPSHELLEXECUTEINFOA] + _ShellExecuteExA.restype = BOOL + _ShellExecuteExA.errcheck = RaiseIfZero + _ShellExecuteExA(byref(lpExecInfo)) + +def ShellExecuteExW(lpExecInfo): + _ShellExecuteExW = windll.shell32.ShellExecuteExW + _ShellExecuteExW.argtypes = [LPSHELLEXECUTEINFOW] + _ShellExecuteExW.restype = BOOL + _ShellExecuteExW.errcheck = RaiseIfZero + _ShellExecuteExW(byref(lpExecInfo)) + +# HINSTANCE FindExecutable( +# __in LPCTSTR lpFile, +# __in_opt LPCTSTR lpDirectory, +# __out LPTSTR lpResult +# ); +def FindExecutableA(lpFile, lpDirectory = None): + _FindExecutableA = windll.shell32.FindExecutableA + _FindExecutableA.argtypes = [LPSTR, LPSTR, LPSTR] + _FindExecutableA.restype = HINSTANCE + + lpResult = ctypes.create_string_buffer(MAX_PATH) + success = _FindExecutableA(lpFile, lpDirectory, lpResult) + success = ctypes.cast(success, ctypes.c_void_p) + success = success.value + if not success > 32: # weird! isn't it? + raise ctypes.WinError(success) + return lpResult.value + +def FindExecutableW(lpFile, lpDirectory = None): + _FindExecutableW = windll.shell32.FindExecutableW + _FindExecutableW.argtypes = [LPWSTR, LPWSTR, LPWSTR] + _FindExecutableW.restype = HINSTANCE + + lpResult = ctypes.create_unicode_buffer(MAX_PATH) + success = _FindExecutableW(lpFile, lpDirectory, lpResult) + success = ctypes.cast(success, ctypes.c_void_p) + success = success.value + if not success > 32: # weird! isn't it? + raise ctypes.WinError(success) + return lpResult.value + +FindExecutable = GuessStringType(FindExecutableA, FindExecutableW) + +# HRESULT SHGetFolderPath( +# __in HWND hwndOwner, +# __in int nFolder, +# __in HANDLE hToken, +# __in DWORD dwFlags, +# __out LPTSTR pszPath +# ); +def SHGetFolderPathA(nFolder, hToken = None, dwFlags = SHGFP_TYPE_CURRENT): + _SHGetFolderPathA = windll.shell32.SHGetFolderPathA # shfolder.dll in older win versions + _SHGetFolderPathA.argtypes = [HWND, ctypes.c_int, HANDLE, DWORD, LPSTR] + _SHGetFolderPathA.restype = HRESULT + _SHGetFolderPathA.errcheck = RaiseIfNotZero # S_OK == 0 + + pszPath = ctypes.create_string_buffer(MAX_PATH + 1) + _SHGetFolderPathA(None, nFolder, hToken, dwFlags, pszPath) + return pszPath.value + +def SHGetFolderPathW(nFolder, hToken = None, dwFlags = SHGFP_TYPE_CURRENT): + _SHGetFolderPathW = windll.shell32.SHGetFolderPathW # shfolder.dll in older win versions + _SHGetFolderPathW.argtypes = [HWND, ctypes.c_int, HANDLE, DWORD, LPWSTR] + _SHGetFolderPathW.restype = HRESULT + _SHGetFolderPathW.errcheck = RaiseIfNotZero # S_OK == 0 + + pszPath = ctypes.create_unicode_buffer(MAX_PATH + 1) + _SHGetFolderPathW(None, nFolder, hToken, dwFlags, pszPath) + return pszPath.value + +SHGetFolderPath = DefaultStringType(SHGetFolderPathA, SHGetFolderPathW) + +# BOOL IsUserAnAdmin(void); +def IsUserAnAdmin(): + # Supposedly, IsUserAnAdmin() is deprecated in Vista. + # But I tried it on Windows 7 and it works just fine. + _IsUserAnAdmin = windll.shell32.IsUserAnAdmin + _IsUserAnAdmin.argtypes = [] + _IsUserAnAdmin.restype = bool + return _IsUserAnAdmin() + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shlwapi.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shlwapi.py new file mode 100644 index 0000000..5f6eb3e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/shlwapi.py @@ -0,0 +1,756 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for shlwapi.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.kernel32 import * + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +OS_WINDOWS = 0 +OS_NT = 1 +OS_WIN95ORGREATER = 2 +OS_NT4ORGREATER = 3 +OS_WIN98ORGREATER = 5 +OS_WIN98_GOLD = 6 +OS_WIN2000ORGREATER = 7 +OS_WIN2000PRO = 8 +OS_WIN2000SERVER = 9 +OS_WIN2000ADVSERVER = 10 +OS_WIN2000DATACENTER = 11 +OS_WIN2000TERMINAL = 12 +OS_EMBEDDED = 13 +OS_TERMINALCLIENT = 14 +OS_TERMINALREMOTEADMIN = 15 +OS_WIN95_GOLD = 16 +OS_MEORGREATER = 17 +OS_XPORGREATER = 18 +OS_HOME = 19 +OS_PROFESSIONAL = 20 +OS_DATACENTER = 21 +OS_ADVSERVER = 22 +OS_SERVER = 23 +OS_TERMINALSERVER = 24 +OS_PERSONALTERMINALSERVER = 25 +OS_FASTUSERSWITCHING = 26 +OS_WELCOMELOGONUI = 27 +OS_DOMAINMEMBER = 28 +OS_ANYSERVER = 29 +OS_WOW6432 = 30 +OS_WEBSERVER = 31 +OS_SMALLBUSINESSSERVER = 32 +OS_TABLETPC = 33 +OS_SERVERADMINUI = 34 +OS_MEDIACENTER = 35 +OS_APPLIANCE = 36 + +#--- shlwapi.dll -------------------------------------------------------------- + +# BOOL IsOS( +# DWORD dwOS +# ); +def IsOS(dwOS): + try: + _IsOS = windll.shlwapi.IsOS + _IsOS.argtypes = [DWORD] + _IsOS.restype = bool + except AttributeError: + # According to MSDN, on Windows versions prior to Vista + # this function is exported only by ordinal number 437. + # http://msdn.microsoft.com/en-us/library/bb773795%28VS.85%29.aspx + _GetProcAddress = windll.kernel32.GetProcAddress + _GetProcAddress.argtypes = [HINSTANCE, DWORD] + _GetProcAddress.restype = LPVOID + _IsOS = windll.kernel32.GetProcAddress(windll.shlwapi._handle, 437) + _IsOS = WINFUNCTYPE(bool, DWORD)(_IsOS) + return _IsOS(dwOS) + +# LPTSTR PathAddBackslash( +# LPTSTR lpszPath +# ); +def PathAddBackslashA(lpszPath): + _PathAddBackslashA = windll.shlwapi.PathAddBackslashA + _PathAddBackslashA.argtypes = [LPSTR] + _PathAddBackslashA.restype = LPSTR + + lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH) + retval = _PathAddBackslashA(lpszPath) + if retval == NULL: + raise ctypes.WinError() + return lpszPath.value + +def PathAddBackslashW(lpszPath): + _PathAddBackslashW = windll.shlwapi.PathAddBackslashW + _PathAddBackslashW.argtypes = [LPWSTR] + _PathAddBackslashW.restype = LPWSTR + + lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH) + retval = _PathAddBackslashW(lpszPath) + if retval == NULL: + raise ctypes.WinError() + return lpszPath.value + +PathAddBackslash = GuessStringType(PathAddBackslashA, PathAddBackslashW) + +# BOOL PathAddExtension( +# LPTSTR pszPath, +# LPCTSTR pszExtension +# ); +def PathAddExtensionA(lpszPath, pszExtension = None): + _PathAddExtensionA = windll.shlwapi.PathAddExtensionA + _PathAddExtensionA.argtypes = [LPSTR, LPSTR] + _PathAddExtensionA.restype = bool + _PathAddExtensionA.errcheck = RaiseIfZero + + if not pszExtension: + pszExtension = None + lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH) + _PathAddExtensionA(lpszPath, pszExtension) + return lpszPath.value + +def PathAddExtensionW(lpszPath, pszExtension = None): + _PathAddExtensionW = windll.shlwapi.PathAddExtensionW + _PathAddExtensionW.argtypes = [LPWSTR, LPWSTR] + _PathAddExtensionW.restype = bool + _PathAddExtensionW.errcheck = RaiseIfZero + + if not pszExtension: + pszExtension = None + lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH) + _PathAddExtensionW(lpszPath, pszExtension) + return lpszPath.value + +PathAddExtension = GuessStringType(PathAddExtensionA, PathAddExtensionW) + +# BOOL PathAppend( +# LPTSTR pszPath, +# LPCTSTR pszMore +# ); +def PathAppendA(lpszPath, pszMore = None): + _PathAppendA = windll.shlwapi.PathAppendA + _PathAppendA.argtypes = [LPSTR, LPSTR] + _PathAppendA.restype = bool + _PathAppendA.errcheck = RaiseIfZero + + if not pszMore: + pszMore = None + lpszPath = ctypes.create_string_buffer(lpszPath, MAX_PATH) + _PathAppendA(lpszPath, pszMore) + return lpszPath.value + +def PathAppendW(lpszPath, pszMore = None): + _PathAppendW = windll.shlwapi.PathAppendW + _PathAppendW.argtypes = [LPWSTR, LPWSTR] + _PathAppendW.restype = bool + _PathAppendW.errcheck = RaiseIfZero + + if not pszMore: + pszMore = None + lpszPath = ctypes.create_unicode_buffer(lpszPath, MAX_PATH) + _PathAppendW(lpszPath, pszMore) + return lpszPath.value + +PathAppend = GuessStringType(PathAppendA, PathAppendW) + +# LPTSTR PathCombine( +# LPTSTR lpszDest, +# LPCTSTR lpszDir, +# LPCTSTR lpszFile +# ); +def PathCombineA(lpszDir, lpszFile): + _PathCombineA = windll.shlwapi.PathCombineA + _PathCombineA.argtypes = [LPSTR, LPSTR, LPSTR] + _PathCombineA.restype = LPSTR + + lpszDest = ctypes.create_string_buffer("", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1)) + retval = _PathCombineA(lpszDest, lpszDir, lpszFile) + if retval == NULL: + return None + return lpszDest.value + +def PathCombineW(lpszDir, lpszFile): + _PathCombineW = windll.shlwapi.PathCombineW + _PathCombineW.argtypes = [LPWSTR, LPWSTR, LPWSTR] + _PathCombineW.restype = LPWSTR + + lpszDest = ctypes.create_unicode_buffer(u"", max(MAX_PATH, len(lpszDir) + len(lpszFile) + 1)) + retval = _PathCombineW(lpszDest, lpszDir, lpszFile) + if retval == NULL: + return None + return lpszDest.value + +PathCombine = GuessStringType(PathCombineA, PathCombineW) + +# BOOL PathCanonicalize( +# LPTSTR lpszDst, +# LPCTSTR lpszSrc +# ); +def PathCanonicalizeA(lpszSrc): + _PathCanonicalizeA = windll.shlwapi.PathCanonicalizeA + _PathCanonicalizeA.argtypes = [LPSTR, LPSTR] + _PathCanonicalizeA.restype = bool + _PathCanonicalizeA.errcheck = RaiseIfZero + + lpszDst = ctypes.create_string_buffer("", MAX_PATH) + _PathCanonicalizeA(lpszDst, lpszSrc) + return lpszDst.value + +def PathCanonicalizeW(lpszSrc): + _PathCanonicalizeW = windll.shlwapi.PathCanonicalizeW + _PathCanonicalizeW.argtypes = [LPWSTR, LPWSTR] + _PathCanonicalizeW.restype = bool + _PathCanonicalizeW.errcheck = RaiseIfZero + + lpszDst = ctypes.create_unicode_buffer(u"", MAX_PATH) + _PathCanonicalizeW(lpszDst, lpszSrc) + return lpszDst.value + +PathCanonicalize = GuessStringType(PathCanonicalizeA, PathCanonicalizeW) + +# BOOL PathRelativePathTo( +# _Out_ LPTSTR pszPath, +# _In_ LPCTSTR pszFrom, +# _In_ DWORD dwAttrFrom, +# _In_ LPCTSTR pszTo, +# _In_ DWORD dwAttrTo +# ); +def PathRelativePathToA(pszFrom = None, dwAttrFrom = FILE_ATTRIBUTE_DIRECTORY, pszTo = None, dwAttrTo = FILE_ATTRIBUTE_DIRECTORY): + _PathRelativePathToA = windll.shlwapi.PathRelativePathToA + _PathRelativePathToA.argtypes = [LPSTR, LPSTR, DWORD, LPSTR, DWORD] + _PathRelativePathToA.restype = bool + _PathRelativePathToA.errcheck = RaiseIfZero + + # Make the paths absolute or the function fails. + if pszFrom: + pszFrom = GetFullPathNameA(pszFrom)[0] + else: + pszFrom = GetCurrentDirectoryA() + if pszTo: + pszTo = GetFullPathNameA(pszTo)[0] + else: + pszTo = GetCurrentDirectoryA() + + # Argh, this function doesn't receive an output buffer size! + # We'll try to guess the maximum possible buffer size. + dwPath = max((len(pszFrom) + len(pszTo)) * 2 + 1, MAX_PATH + 1) + pszPath = ctypes.create_string_buffer('', dwPath) + + # Also, it doesn't set the last error value. + # Whoever coded it must have been drunk or tripping on acid. Or both. + # The only failure conditions I've seen were invalid paths, paths not + # on the same drive, or the path is not absolute. + SetLastError(ERROR_INVALID_PARAMETER) + + _PathRelativePathToA(pszPath, pszFrom, dwAttrFrom, pszTo, dwAttrTo) + return pszPath.value + +def PathRelativePathToW(pszFrom = None, dwAttrFrom = FILE_ATTRIBUTE_DIRECTORY, pszTo = None, dwAttrTo = FILE_ATTRIBUTE_DIRECTORY): + _PathRelativePathToW = windll.shlwapi.PathRelativePathToW + _PathRelativePathToW.argtypes = [LPWSTR, LPWSTR, DWORD, LPWSTR, DWORD] + _PathRelativePathToW.restype = bool + _PathRelativePathToW.errcheck = RaiseIfZero + + # Refer to PathRelativePathToA to know why this code is so ugly. + if pszFrom: + pszFrom = GetFullPathNameW(pszFrom)[0] + else: + pszFrom = GetCurrentDirectoryW() + if pszTo: + pszTo = GetFullPathNameW(pszTo)[0] + else: + pszTo = GetCurrentDirectoryW() + dwPath = max((len(pszFrom) + len(pszTo)) * 2 + 1, MAX_PATH + 1) + pszPath = ctypes.create_unicode_buffer(u'', dwPath) + SetLastError(ERROR_INVALID_PARAMETER) + _PathRelativePathToW(pszPath, pszFrom, dwAttrFrom, pszTo, dwAttrTo) + return pszPath.value + +PathRelativePathTo = GuessStringType(PathRelativePathToA, PathRelativePathToW) + +# BOOL PathFileExists( +# LPCTSTR pszPath +# ); +def PathFileExistsA(pszPath): + _PathFileExistsA = windll.shlwapi.PathFileExistsA + _PathFileExistsA.argtypes = [LPSTR] + _PathFileExistsA.restype = bool + return _PathFileExistsA(pszPath) + +def PathFileExistsW(pszPath): + _PathFileExistsW = windll.shlwapi.PathFileExistsW + _PathFileExistsW.argtypes = [LPWSTR] + _PathFileExistsW.restype = bool + return _PathFileExistsW(pszPath) + +PathFileExists = GuessStringType(PathFileExistsA, PathFileExistsW) + +# LPTSTR PathFindExtension( +# LPCTSTR pszPath +# ); +def PathFindExtensionA(pszPath): + _PathFindExtensionA = windll.shlwapi.PathFindExtensionA + _PathFindExtensionA.argtypes = [LPSTR] + _PathFindExtensionA.restype = LPSTR + pszPath = ctypes.create_string_buffer(pszPath) + return _PathFindExtensionA(pszPath) + +def PathFindExtensionW(pszPath): + _PathFindExtensionW = windll.shlwapi.PathFindExtensionW + _PathFindExtensionW.argtypes = [LPWSTR] + _PathFindExtensionW.restype = LPWSTR + pszPath = ctypes.create_unicode_buffer(pszPath) + return _PathFindExtensionW(pszPath) + +PathFindExtension = GuessStringType(PathFindExtensionA, PathFindExtensionW) + +# LPTSTR PathFindFileName( +# LPCTSTR pszPath +# ); +def PathFindFileNameA(pszPath): + _PathFindFileNameA = windll.shlwapi.PathFindFileNameA + _PathFindFileNameA.argtypes = [LPSTR] + _PathFindFileNameA.restype = LPSTR + pszPath = ctypes.create_string_buffer(pszPath) + return _PathFindFileNameA(pszPath) + +def PathFindFileNameW(pszPath): + _PathFindFileNameW = windll.shlwapi.PathFindFileNameW + _PathFindFileNameW.argtypes = [LPWSTR] + _PathFindFileNameW.restype = LPWSTR + pszPath = ctypes.create_unicode_buffer(pszPath) + return _PathFindFileNameW(pszPath) + +PathFindFileName = GuessStringType(PathFindFileNameA, PathFindFileNameW) + +# LPTSTR PathFindNextComponent( +# LPCTSTR pszPath +# ); +def PathFindNextComponentA(pszPath): + _PathFindNextComponentA = windll.shlwapi.PathFindNextComponentA + _PathFindNextComponentA.argtypes = [LPSTR] + _PathFindNextComponentA.restype = LPSTR + pszPath = ctypes.create_string_buffer(pszPath) + return _PathFindNextComponentA(pszPath) + +def PathFindNextComponentW(pszPath): + _PathFindNextComponentW = windll.shlwapi.PathFindNextComponentW + _PathFindNextComponentW.argtypes = [LPWSTR] + _PathFindNextComponentW.restype = LPWSTR + pszPath = ctypes.create_unicode_buffer(pszPath) + return _PathFindNextComponentW(pszPath) + +PathFindNextComponent = GuessStringType(PathFindNextComponentA, PathFindNextComponentW) + +# BOOL PathFindOnPath( +# LPTSTR pszFile, +# LPCTSTR *ppszOtherDirs +# ); +def PathFindOnPathA(pszFile, ppszOtherDirs = None): + _PathFindOnPathA = windll.shlwapi.PathFindOnPathA + _PathFindOnPathA.argtypes = [LPSTR, LPSTR] + _PathFindOnPathA.restype = bool + + pszFile = ctypes.create_string_buffer(pszFile, MAX_PATH) + if not ppszOtherDirs: + ppszOtherDirs = None + else: + szArray = "" + for pszOtherDirs in ppszOtherDirs: + if pszOtherDirs: + szArray = "%s%s\0" % (szArray, pszOtherDirs) + szArray = szArray + "\0" + pszOtherDirs = ctypes.create_string_buffer(szArray) + ppszOtherDirs = ctypes.pointer(pszOtherDirs) + if _PathFindOnPathA(pszFile, ppszOtherDirs): + return pszFile.value + return None + +def PathFindOnPathW(pszFile, ppszOtherDirs = None): + _PathFindOnPathW = windll.shlwapi.PathFindOnPathA + _PathFindOnPathW.argtypes = [LPWSTR, LPWSTR] + _PathFindOnPathW.restype = bool + + pszFile = ctypes.create_unicode_buffer(pszFile, MAX_PATH) + if not ppszOtherDirs: + ppszOtherDirs = None + else: + szArray = u"" + for pszOtherDirs in ppszOtherDirs: + if pszOtherDirs: + szArray = u"%s%s\0" % (szArray, pszOtherDirs) + szArray = szArray + u"\0" + pszOtherDirs = ctypes.create_unicode_buffer(szArray) + ppszOtherDirs = ctypes.pointer(pszOtherDirs) + if _PathFindOnPathW(pszFile, ppszOtherDirs): + return pszFile.value + return None + +PathFindOnPath = GuessStringType(PathFindOnPathA, PathFindOnPathW) + +# LPTSTR PathGetArgs( +# LPCTSTR pszPath +# ); +def PathGetArgsA(pszPath): + _PathGetArgsA = windll.shlwapi.PathGetArgsA + _PathGetArgsA.argtypes = [LPSTR] + _PathGetArgsA.restype = LPSTR + pszPath = ctypes.create_string_buffer(pszPath) + return _PathGetArgsA(pszPath) + +def PathGetArgsW(pszPath): + _PathGetArgsW = windll.shlwapi.PathGetArgsW + _PathGetArgsW.argtypes = [LPWSTR] + _PathGetArgsW.restype = LPWSTR + pszPath = ctypes.create_unicode_buffer(pszPath) + return _PathGetArgsW(pszPath) + +PathGetArgs = GuessStringType(PathGetArgsA, PathGetArgsW) + +# BOOL PathIsContentType( +# LPCTSTR pszPath, +# LPCTSTR pszContentType +# ); +def PathIsContentTypeA(pszPath, pszContentType): + _PathIsContentTypeA = windll.shlwapi.PathIsContentTypeA + _PathIsContentTypeA.argtypes = [LPSTR, LPSTR] + _PathIsContentTypeA.restype = bool + return _PathIsContentTypeA(pszPath, pszContentType) + +def PathIsContentTypeW(pszPath, pszContentType): + _PathIsContentTypeW = windll.shlwapi.PathIsContentTypeW + _PathIsContentTypeW.argtypes = [LPWSTR, LPWSTR] + _PathIsContentTypeW.restype = bool + return _PathIsContentTypeW(pszPath, pszContentType) + +PathIsContentType = GuessStringType(PathIsContentTypeA, PathIsContentTypeW) + +# BOOL PathIsDirectory( +# LPCTSTR pszPath +# ); +def PathIsDirectoryA(pszPath): + _PathIsDirectoryA = windll.shlwapi.PathIsDirectoryA + _PathIsDirectoryA.argtypes = [LPSTR] + _PathIsDirectoryA.restype = bool + return _PathIsDirectoryA(pszPath) + +def PathIsDirectoryW(pszPath): + _PathIsDirectoryW = windll.shlwapi.PathIsDirectoryW + _PathIsDirectoryW.argtypes = [LPWSTR] + _PathIsDirectoryW.restype = bool + return _PathIsDirectoryW(pszPath) + +PathIsDirectory = GuessStringType(PathIsDirectoryA, PathIsDirectoryW) + +# BOOL PathIsDirectoryEmpty( +# LPCTSTR pszPath +# ); +def PathIsDirectoryEmptyA(pszPath): + _PathIsDirectoryEmptyA = windll.shlwapi.PathIsDirectoryEmptyA + _PathIsDirectoryEmptyA.argtypes = [LPSTR] + _PathIsDirectoryEmptyA.restype = bool + return _PathIsDirectoryEmptyA(pszPath) + +def PathIsDirectoryEmptyW(pszPath): + _PathIsDirectoryEmptyW = windll.shlwapi.PathIsDirectoryEmptyW + _PathIsDirectoryEmptyW.argtypes = [LPWSTR] + _PathIsDirectoryEmptyW.restype = bool + return _PathIsDirectoryEmptyW(pszPath) + +PathIsDirectoryEmpty = GuessStringType(PathIsDirectoryEmptyA, PathIsDirectoryEmptyW) + +# BOOL PathIsNetworkPath( +# LPCTSTR pszPath +# ); +def PathIsNetworkPathA(pszPath): + _PathIsNetworkPathA = windll.shlwapi.PathIsNetworkPathA + _PathIsNetworkPathA.argtypes = [LPSTR] + _PathIsNetworkPathA.restype = bool + return _PathIsNetworkPathA(pszPath) + +def PathIsNetworkPathW(pszPath): + _PathIsNetworkPathW = windll.shlwapi.PathIsNetworkPathW + _PathIsNetworkPathW.argtypes = [LPWSTR] + _PathIsNetworkPathW.restype = bool + return _PathIsNetworkPathW(pszPath) + +PathIsNetworkPath = GuessStringType(PathIsNetworkPathA, PathIsNetworkPathW) + +# BOOL PathIsRelative( +# LPCTSTR lpszPath +# ); +def PathIsRelativeA(pszPath): + _PathIsRelativeA = windll.shlwapi.PathIsRelativeA + _PathIsRelativeA.argtypes = [LPSTR] + _PathIsRelativeA.restype = bool + return _PathIsRelativeA(pszPath) + +def PathIsRelativeW(pszPath): + _PathIsRelativeW = windll.shlwapi.PathIsRelativeW + _PathIsRelativeW.argtypes = [LPWSTR] + _PathIsRelativeW.restype = bool + return _PathIsRelativeW(pszPath) + +PathIsRelative = GuessStringType(PathIsRelativeA, PathIsRelativeW) + +# BOOL PathIsRoot( +# LPCTSTR pPath +# ); +def PathIsRootA(pszPath): + _PathIsRootA = windll.shlwapi.PathIsRootA + _PathIsRootA.argtypes = [LPSTR] + _PathIsRootA.restype = bool + return _PathIsRootA(pszPath) + +def PathIsRootW(pszPath): + _PathIsRootW = windll.shlwapi.PathIsRootW + _PathIsRootW.argtypes = [LPWSTR] + _PathIsRootW.restype = bool + return _PathIsRootW(pszPath) + +PathIsRoot = GuessStringType(PathIsRootA, PathIsRootW) + +# BOOL PathIsSameRoot( +# LPCTSTR pszPath1, +# LPCTSTR pszPath2 +# ); +def PathIsSameRootA(pszPath1, pszPath2): + _PathIsSameRootA = windll.shlwapi.PathIsSameRootA + _PathIsSameRootA.argtypes = [LPSTR, LPSTR] + _PathIsSameRootA.restype = bool + return _PathIsSameRootA(pszPath1, pszPath2) + +def PathIsSameRootW(pszPath1, pszPath2): + _PathIsSameRootW = windll.shlwapi.PathIsSameRootW + _PathIsSameRootW.argtypes = [LPWSTR, LPWSTR] + _PathIsSameRootW.restype = bool + return _PathIsSameRootW(pszPath1, pszPath2) + +PathIsSameRoot = GuessStringType(PathIsSameRootA, PathIsSameRootW) + +# BOOL PathIsUNC( +# LPCTSTR pszPath +# ); +def PathIsUNCA(pszPath): + _PathIsUNCA = windll.shlwapi.PathIsUNCA + _PathIsUNCA.argtypes = [LPSTR] + _PathIsUNCA.restype = bool + return _PathIsUNCA(pszPath) + +def PathIsUNCW(pszPath): + _PathIsUNCW = windll.shlwapi.PathIsUNCW + _PathIsUNCW.argtypes = [LPWSTR] + _PathIsUNCW.restype = bool + return _PathIsUNCW(pszPath) + +PathIsUNC = GuessStringType(PathIsUNCA, PathIsUNCW) + +# XXX WARNING +# PathMakePretty turns filenames into all lowercase. +# I'm not sure how well that might work on Wine. + +# BOOL PathMakePretty( +# LPCTSTR pszPath +# ); +def PathMakePrettyA(pszPath): + _PathMakePrettyA = windll.shlwapi.PathMakePrettyA + _PathMakePrettyA.argtypes = [LPSTR] + _PathMakePrettyA.restype = bool + _PathMakePrettyA.errcheck = RaiseIfZero + + pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH) + _PathMakePrettyA(pszPath) + return pszPath.value + +def PathMakePrettyW(pszPath): + _PathMakePrettyW = windll.shlwapi.PathMakePrettyW + _PathMakePrettyW.argtypes = [LPWSTR] + _PathMakePrettyW.restype = bool + _PathMakePrettyW.errcheck = RaiseIfZero + + pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH) + _PathMakePrettyW(pszPath) + return pszPath.value + +PathMakePretty = GuessStringType(PathMakePrettyA, PathMakePrettyW) + +# void PathRemoveArgs( +# LPTSTR pszPath +# ); +def PathRemoveArgsA(pszPath): + _PathRemoveArgsA = windll.shlwapi.PathRemoveArgsA + _PathRemoveArgsA.argtypes = [LPSTR] + + pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH) + _PathRemoveArgsA(pszPath) + return pszPath.value + +def PathRemoveArgsW(pszPath): + _PathRemoveArgsW = windll.shlwapi.PathRemoveArgsW + _PathRemoveArgsW.argtypes = [LPWSTR] + + pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH) + _PathRemoveArgsW(pszPath) + return pszPath.value + +PathRemoveArgs = GuessStringType(PathRemoveArgsA, PathRemoveArgsW) + +# void PathRemoveBackslash( +# LPTSTR pszPath +# ); +def PathRemoveBackslashA(pszPath): + _PathRemoveBackslashA = windll.shlwapi.PathRemoveBackslashA + _PathRemoveBackslashA.argtypes = [LPSTR] + + pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH) + _PathRemoveBackslashA(pszPath) + return pszPath.value + +def PathRemoveBackslashW(pszPath): + _PathRemoveBackslashW = windll.shlwapi.PathRemoveBackslashW + _PathRemoveBackslashW.argtypes = [LPWSTR] + + pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH) + _PathRemoveBackslashW(pszPath) + return pszPath.value + +PathRemoveBackslash = GuessStringType(PathRemoveBackslashA, PathRemoveBackslashW) + +# void PathRemoveExtension( +# LPTSTR pszPath +# ); +def PathRemoveExtensionA(pszPath): + _PathRemoveExtensionA = windll.shlwapi.PathRemoveExtensionA + _PathRemoveExtensionA.argtypes = [LPSTR] + + pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH) + _PathRemoveExtensionA(pszPath) + return pszPath.value + +def PathRemoveExtensionW(pszPath): + _PathRemoveExtensionW = windll.shlwapi.PathRemoveExtensionW + _PathRemoveExtensionW.argtypes = [LPWSTR] + + pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH) + _PathRemoveExtensionW(pszPath) + return pszPath.value + +PathRemoveExtension = GuessStringType(PathRemoveExtensionA, PathRemoveExtensionW) + +# void PathRemoveFileSpec( +# LPTSTR pszPath +# ); +def PathRemoveFileSpecA(pszPath): + _PathRemoveFileSpecA = windll.shlwapi.PathRemoveFileSpecA + _PathRemoveFileSpecA.argtypes = [LPSTR] + + pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH) + _PathRemoveFileSpecA(pszPath) + return pszPath.value + +def PathRemoveFileSpecW(pszPath): + _PathRemoveFileSpecW = windll.shlwapi.PathRemoveFileSpecW + _PathRemoveFileSpecW.argtypes = [LPWSTR] + + pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH) + _PathRemoveFileSpecW(pszPath) + return pszPath.value + +PathRemoveFileSpec = GuessStringType(PathRemoveFileSpecA, PathRemoveFileSpecW) + +# BOOL PathRenameExtension( +# LPTSTR pszPath, +# LPCTSTR pszExt +# ); +def PathRenameExtensionA(pszPath, pszExt): + _PathRenameExtensionA = windll.shlwapi.PathRenameExtensionA + _PathRenameExtensionA.argtypes = [LPSTR, LPSTR] + _PathRenameExtensionA.restype = bool + + pszPath = ctypes.create_string_buffer(pszPath, MAX_PATH) + if _PathRenameExtensionA(pszPath, pszExt): + return pszPath.value + return None + +def PathRenameExtensionW(pszPath, pszExt): + _PathRenameExtensionW = windll.shlwapi.PathRenameExtensionW + _PathRenameExtensionW.argtypes = [LPWSTR, LPWSTR] + _PathRenameExtensionW.restype = bool + + pszPath = ctypes.create_unicode_buffer(pszPath, MAX_PATH) + if _PathRenameExtensionW(pszPath, pszExt): + return pszPath.value + return None + +PathRenameExtension = GuessStringType(PathRenameExtensionA, PathRenameExtensionW) + +# BOOL PathUnExpandEnvStrings( +# LPCTSTR pszPath, +# LPTSTR pszBuf, +# UINT cchBuf +# ); +def PathUnExpandEnvStringsA(pszPath): + _PathUnExpandEnvStringsA = windll.shlwapi.PathUnExpandEnvStringsA + _PathUnExpandEnvStringsA.argtypes = [LPSTR, LPSTR] + _PathUnExpandEnvStringsA.restype = bool + _PathUnExpandEnvStringsA.errcheck = RaiseIfZero + + cchBuf = MAX_PATH + pszBuf = ctypes.create_string_buffer("", cchBuf) + _PathUnExpandEnvStringsA(pszPath, pszBuf, cchBuf) + return pszBuf.value + +def PathUnExpandEnvStringsW(pszPath): + _PathUnExpandEnvStringsW = windll.shlwapi.PathUnExpandEnvStringsW + _PathUnExpandEnvStringsW.argtypes = [LPWSTR, LPWSTR] + _PathUnExpandEnvStringsW.restype = bool + _PathUnExpandEnvStringsW.errcheck = RaiseIfZero + + cchBuf = MAX_PATH + pszBuf = ctypes.create_unicode_buffer(u"", cchBuf) + _PathUnExpandEnvStringsW(pszPath, pszBuf, cchBuf) + return pszBuf.value + +PathUnExpandEnvStrings = GuessStringType(PathUnExpandEnvStringsA, PathUnExpandEnvStringsW) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/user32.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/user32.py new file mode 100644 index 0000000..18560e5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/user32.py @@ -0,0 +1,1727 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for user32.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.version import bits +from winappdbg.win32.kernel32 import GetLastError, SetLastError +from winappdbg.win32.gdi32 import POINT, PPOINT, LPPOINT, RECT, PRECT, LPRECT + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- Helpers ------------------------------------------------------------------ + +def MAKE_WPARAM(wParam): + """ + Convert arguments to the WPARAM type. + Used automatically by SendMessage, PostMessage, etc. + You shouldn't need to call this function. + """ + wParam = ctypes.cast(wParam, LPVOID).value + if wParam is None: + wParam = 0 + return wParam + +def MAKE_LPARAM(lParam): + """ + Convert arguments to the LPARAM type. + Used automatically by SendMessage, PostMessage, etc. + You shouldn't need to call this function. + """ + return ctypes.cast(lParam, LPARAM) + +class __WindowEnumerator (object): + """ + Window enumerator class. Used internally by the window enumeration APIs. + """ + def __init__(self): + self.hwnd = list() + def __call__(self, hwnd, lParam): +## print hwnd # XXX DEBUG + self.hwnd.append(hwnd) + return TRUE + +#--- Types -------------------------------------------------------------------- + +WNDENUMPROC = WINFUNCTYPE(BOOL, HWND, PVOID) + +#--- Constants ---------------------------------------------------------------- + +HWND_DESKTOP = 0 +HWND_TOP = 1 +HWND_BOTTOM = 1 +HWND_TOPMOST = -1 +HWND_NOTOPMOST = -2 +HWND_MESSAGE = -3 + +# GetWindowLong / SetWindowLong +GWL_WNDPROC = -4 +GWL_HINSTANCE = -6 +GWL_HWNDPARENT = -8 +GWL_ID = -12 +GWL_STYLE = -16 +GWL_EXSTYLE = -20 +GWL_USERDATA = -21 + +# GetWindowLongPtr / SetWindowLongPtr +GWLP_WNDPROC = GWL_WNDPROC +GWLP_HINSTANCE = GWL_HINSTANCE +GWLP_HWNDPARENT = GWL_HWNDPARENT +GWLP_STYLE = GWL_STYLE +GWLP_EXSTYLE = GWL_EXSTYLE +GWLP_USERDATA = GWL_USERDATA +GWLP_ID = GWL_ID + +# ShowWindow +SW_HIDE = 0 +SW_SHOWNORMAL = 1 +SW_NORMAL = 1 +SW_SHOWMINIMIZED = 2 +SW_SHOWMAXIMIZED = 3 +SW_MAXIMIZE = 3 +SW_SHOWNOACTIVATE = 4 +SW_SHOW = 5 +SW_MINIMIZE = 6 +SW_SHOWMINNOACTIVE = 7 +SW_SHOWNA = 8 +SW_RESTORE = 9 +SW_SHOWDEFAULT = 10 +SW_FORCEMINIMIZE = 11 + +# SendMessageTimeout flags +SMTO_NORMAL = 0 +SMTO_BLOCK = 1 +SMTO_ABORTIFHUNG = 2 +SMTO_NOTIMEOUTIFNOTHUNG = 8 +SMTO_ERRORONEXIT = 0x20 + +# WINDOWPLACEMENT flags +WPF_SETMINPOSITION = 1 +WPF_RESTORETOMAXIMIZED = 2 +WPF_ASYNCWINDOWPLACEMENT = 4 + +# GetAncestor flags +GA_PARENT = 1 +GA_ROOT = 2 +GA_ROOTOWNER = 3 + +# GetWindow flags +GW_HWNDFIRST = 0 +GW_HWNDLAST = 1 +GW_HWNDNEXT = 2 +GW_HWNDPREV = 3 +GW_OWNER = 4 +GW_CHILD = 5 +GW_ENABLEDPOPUP = 6 + +#--- Window messages ---------------------------------------------------------- + +WM_USER = 0x400 +WM_APP = 0x800 + +WM_NULL = 0 +WM_CREATE = 1 +WM_DESTROY = 2 +WM_MOVE = 3 +WM_SIZE = 5 +WM_ACTIVATE = 6 +WA_INACTIVE = 0 +WA_ACTIVE = 1 +WA_CLICKACTIVE = 2 +WM_SETFOCUS = 7 +WM_KILLFOCUS = 8 +WM_ENABLE = 0x0A +WM_SETREDRAW = 0x0B +WM_SETTEXT = 0x0C +WM_GETTEXT = 0x0D +WM_GETTEXTLENGTH = 0x0E +WM_PAINT = 0x0F +WM_CLOSE = 0x10 +WM_QUERYENDSESSION = 0x11 +WM_QUIT = 0x12 +WM_QUERYOPEN = 0x13 +WM_ERASEBKGND = 0x14 +WM_SYSCOLORCHANGE = 0x15 +WM_ENDSESSION = 0x16 +WM_SHOWWINDOW = 0x18 +WM_WININICHANGE = 0x1A +WM_SETTINGCHANGE = WM_WININICHANGE +WM_DEVMODECHANGE = 0x1B +WM_ACTIVATEAPP = 0x1C +WM_FONTCHANGE = 0x1D +WM_TIMECHANGE = 0x1E +WM_CANCELMODE = 0x1F +WM_SETCURSOR = 0x20 +WM_MOUSEACTIVATE = 0x21 +WM_CHILDACTIVATE = 0x22 +WM_QUEUESYNC = 0x23 +WM_GETMINMAXINFO = 0x24 +WM_PAINTICON = 0x26 +WM_ICONERASEBKGND = 0x27 +WM_NEXTDLGCTL = 0x28 +WM_SPOOLERSTATUS = 0x2A +WM_DRAWITEM = 0x2B +WM_MEASUREITEM = 0x2C +WM_DELETEITEM = 0x2D +WM_VKEYTOITEM = 0x2E +WM_CHARTOITEM = 0x2F +WM_SETFONT = 0x30 +WM_GETFONT = 0x31 +WM_SETHOTKEY = 0x32 +WM_GETHOTKEY = 0x33 +WM_QUERYDRAGICON = 0x37 +WM_COMPAREITEM = 0x39 +WM_GETOBJECT = 0x3D +WM_COMPACTING = 0x41 +WM_OTHERWINDOWCREATED = 0x42 +WM_OTHERWINDOWDESTROYED = 0x43 +WM_COMMNOTIFY = 0x44 + +CN_RECEIVE = 0x1 +CN_TRANSMIT = 0x2 +CN_EVENT = 0x4 + +WM_WINDOWPOSCHANGING = 0x46 +WM_WINDOWPOSCHANGED = 0x47 +WM_POWER = 0x48 + +PWR_OK = 1 +PWR_FAIL = -1 +PWR_SUSPENDREQUEST = 1 +PWR_SUSPENDRESUME = 2 +PWR_CRITICALRESUME = 3 + +WM_COPYDATA = 0x4A +WM_CANCELJOURNAL = 0x4B +WM_NOTIFY = 0x4E +WM_INPUTLANGCHANGEREQUEST = 0x50 +WM_INPUTLANGCHANGE = 0x51 +WM_TCARD = 0x52 +WM_HELP = 0x53 +WM_USERCHANGED = 0x54 +WM_NOTIFYFORMAT = 0x55 +WM_CONTEXTMENU = 0x7B +WM_STYLECHANGING = 0x7C +WM_STYLECHANGED = 0x7D +WM_DISPLAYCHANGE = 0x7E +WM_GETICON = 0x7F +WM_SETICON = 0x80 +WM_NCCREATE = 0x81 +WM_NCDESTROY = 0x82 +WM_NCCALCSIZE = 0x83 +WM_NCHITTEST = 0x84 +WM_NCPAINT = 0x85 +WM_NCACTIVATE = 0x86 +WM_GETDLGCODE = 0x87 +WM_SYNCPAINT = 0x88 +WM_NCMOUSEMOVE = 0x0A0 +WM_NCLBUTTONDOWN = 0x0A1 +WM_NCLBUTTONUP = 0x0A2 +WM_NCLBUTTONDBLCLK = 0x0A3 +WM_NCRBUTTONDOWN = 0x0A4 +WM_NCRBUTTONUP = 0x0A5 +WM_NCRBUTTONDBLCLK = 0x0A6 +WM_NCMBUTTONDOWN = 0x0A7 +WM_NCMBUTTONUP = 0x0A8 +WM_NCMBUTTONDBLCLK = 0x0A9 +WM_KEYFIRST = 0x100 +WM_KEYDOWN = 0x100 +WM_KEYUP = 0x101 +WM_CHAR = 0x102 +WM_DEADCHAR = 0x103 +WM_SYSKEYDOWN = 0x104 +WM_SYSKEYUP = 0x105 +WM_SYSCHAR = 0x106 +WM_SYSDEADCHAR = 0x107 +WM_KEYLAST = 0x108 +WM_INITDIALOG = 0x110 +WM_COMMAND = 0x111 +WM_SYSCOMMAND = 0x112 +WM_TIMER = 0x113 +WM_HSCROLL = 0x114 +WM_VSCROLL = 0x115 +WM_INITMENU = 0x116 +WM_INITMENUPOPUP = 0x117 +WM_MENUSELECT = 0x11F +WM_MENUCHAR = 0x120 +WM_ENTERIDLE = 0x121 +WM_CTLCOLORMSGBOX = 0x132 +WM_CTLCOLOREDIT = 0x133 +WM_CTLCOLORLISTBOX = 0x134 +WM_CTLCOLORBTN = 0x135 +WM_CTLCOLORDLG = 0x136 +WM_CTLCOLORSCROLLBAR = 0x137 +WM_CTLCOLORSTATIC = 0x138 +WM_MOUSEFIRST = 0x200 +WM_MOUSEMOVE = 0x200 +WM_LBUTTONDOWN = 0x201 +WM_LBUTTONUP = 0x202 +WM_LBUTTONDBLCLK = 0x203 +WM_RBUTTONDOWN = 0x204 +WM_RBUTTONUP = 0x205 +WM_RBUTTONDBLCLK = 0x206 +WM_MBUTTONDOWN = 0x207 +WM_MBUTTONUP = 0x208 +WM_MBUTTONDBLCLK = 0x209 +WM_MOUSELAST = 0x209 +WM_PARENTNOTIFY = 0x210 +WM_ENTERMENULOOP = 0x211 +WM_EXITMENULOOP = 0x212 +WM_MDICREATE = 0x220 +WM_MDIDESTROY = 0x221 +WM_MDIACTIVATE = 0x222 +WM_MDIRESTORE = 0x223 +WM_MDINEXT = 0x224 +WM_MDIMAXIMIZE = 0x225 +WM_MDITILE = 0x226 +WM_MDICASCADE = 0x227 +WM_MDIICONARRANGE = 0x228 +WM_MDIGETACTIVE = 0x229 +WM_MDISETMENU = 0x230 +WM_DROPFILES = 0x233 +WM_MDIREFRESHMENU = 0x234 +WM_CUT = 0x300 +WM_COPY = 0x301 +WM_PASTE = 0x302 +WM_CLEAR = 0x303 +WM_UNDO = 0x304 +WM_RENDERFORMAT = 0x305 +WM_RENDERALLFORMATS = 0x306 +WM_DESTROYCLIPBOARD = 0x307 +WM_DRAWCLIPBOARD = 0x308 +WM_PAINTCLIPBOARD = 0x309 +WM_VSCROLLCLIPBOARD = 0x30A +WM_SIZECLIPBOARD = 0x30B +WM_ASKCBFORMATNAME = 0x30C +WM_CHANGECBCHAIN = 0x30D +WM_HSCROLLCLIPBOARD = 0x30E +WM_QUERYNEWPALETTE = 0x30F +WM_PALETTEISCHANGING = 0x310 +WM_PALETTECHANGED = 0x311 +WM_HOTKEY = 0x312 +WM_PRINT = 0x317 +WM_PRINTCLIENT = 0x318 +WM_PENWINFIRST = 0x380 +WM_PENWINLAST = 0x38F + +#--- Structures --------------------------------------------------------------- + +# typedef struct _WINDOWPLACEMENT { +# UINT length; +# UINT flags; +# UINT showCmd; +# POINT ptMinPosition; +# POINT ptMaxPosition; +# RECT rcNormalPosition; +# } WINDOWPLACEMENT; +class WINDOWPLACEMENT(Structure): + _fields_ = [ + ('length', UINT), + ('flags', UINT), + ('showCmd', UINT), + ('ptMinPosition', POINT), + ('ptMaxPosition', POINT), + ('rcNormalPosition', RECT), + ] +PWINDOWPLACEMENT = POINTER(WINDOWPLACEMENT) +LPWINDOWPLACEMENT = PWINDOWPLACEMENT + +# typedef struct tagGUITHREADINFO { +# DWORD cbSize; +# DWORD flags; +# HWND hwndActive; +# HWND hwndFocus; +# HWND hwndCapture; +# HWND hwndMenuOwner; +# HWND hwndMoveSize; +# HWND hwndCaret; +# RECT rcCaret; +# } GUITHREADINFO, *PGUITHREADINFO; +class GUITHREADINFO(Structure): + _fields_ = [ + ('cbSize', DWORD), + ('flags', DWORD), + ('hwndActive', HWND), + ('hwndFocus', HWND), + ('hwndCapture', HWND), + ('hwndMenuOwner', HWND), + ('hwndMoveSize', HWND), + ('hwndCaret', HWND), + ('rcCaret', RECT), + ] +PGUITHREADINFO = POINTER(GUITHREADINFO) +LPGUITHREADINFO = PGUITHREADINFO + +#--- High level classes ------------------------------------------------------- + +# Point() and Rect() are here instead of gdi32.py because they were mainly +# created to handle window coordinates rather than drawing on the screen. + +# XXX not sure if these classes should be psyco-optimized, +# it may not work if the user wants to serialize them for some reason + +class Point(object): + """ + Python wrapper over the L{POINT} class. + + @type x: int + @ivar x: Horizontal coordinate + @type y: int + @ivar y: Vertical coordinate + """ + + def __init__(self, x = 0, y = 0): + """ + @see: L{POINT} + @type x: int + @param x: Horizontal coordinate + @type y: int + @param y: Vertical coordinate + """ + self.x = x + self.y = y + + def __iter__(self): + return (self.x, self.y).__iter__() + + def __len__(self): + return 2 + + def __getitem__(self, index): + return (self.x, self.y) [index] + + def __setitem__(self, index, value): + if index == 0: + self.x = value + elif index == 1: + self.y = value + else: + raise IndexError("index out of range") + + @property + def _as_parameter_(self): + """ + Compatibility with ctypes. + Allows passing transparently a Point object to an API call. + """ + return POINT(self.x, self.y) + + def screen_to_client(self, hWnd): + """ + Translates window screen coordinates to client coordinates. + + @see: L{client_to_screen}, L{translate} + + @type hWnd: int or L{HWND} or L{system.Window} + @param hWnd: Window handle. + + @rtype: L{Point} + @return: New object containing the translated coordinates. + """ + return ScreenToClient(hWnd, self) + + def client_to_screen(self, hWnd): + """ + Translates window client coordinates to screen coordinates. + + @see: L{screen_to_client}, L{translate} + + @type hWnd: int or L{HWND} or L{system.Window} + @param hWnd: Window handle. + + @rtype: L{Point} + @return: New object containing the translated coordinates. + """ + return ClientToScreen(hWnd, self) + + def translate(self, hWndFrom = HWND_DESKTOP, hWndTo = HWND_DESKTOP): + """ + Translate coordinates from one window to another. + + @note: To translate multiple points it's more efficient to use the + L{MapWindowPoints} function instead. + + @see: L{client_to_screen}, L{screen_to_client} + + @type hWndFrom: int or L{HWND} or L{system.Window} + @param hWndFrom: Window handle to translate from. + Use C{HWND_DESKTOP} for screen coordinates. + + @type hWndTo: int or L{HWND} or L{system.Window} + @param hWndTo: Window handle to translate to. + Use C{HWND_DESKTOP} for screen coordinates. + + @rtype: L{Point} + @return: New object containing the translated coordinates. + """ + return MapWindowPoints(hWndFrom, hWndTo, [self]) + +class Rect(object): + """ + Python wrapper over the L{RECT} class. + + @type left: int + @ivar left: Horizontal coordinate for the top left corner. + @type top: int + @ivar top: Vertical coordinate for the top left corner. + @type right: int + @ivar right: Horizontal coordinate for the bottom right corner. + @type bottom: int + @ivar bottom: Vertical coordinate for the bottom right corner. + + @type width: int + @ivar width: Width in pixels. Same as C{right - left}. + @type height: int + @ivar height: Height in pixels. Same as C{bottom - top}. + """ + + def __init__(self, left = 0, top = 0, right = 0, bottom = 0): + """ + @see: L{RECT} + @type left: int + @param left: Horizontal coordinate for the top left corner. + @type top: int + @param top: Vertical coordinate for the top left corner. + @type right: int + @param right: Horizontal coordinate for the bottom right corner. + @type bottom: int + @param bottom: Vertical coordinate for the bottom right corner. + """ + self.left = left + self.top = top + self.right = right + self.bottom = bottom + + def __iter__(self): + return (self.left, self.top, self.right, self.bottom).__iter__() + + def __len__(self): + return 2 + + def __getitem__(self, index): + return (self.left, self.top, self.right, self.bottom) [index] + + def __setitem__(self, index, value): + if index == 0: + self.left = value + elif index == 1: + self.top = value + elif index == 2: + self.right = value + elif index == 3: + self.bottom = value + else: + raise IndexError("index out of range") + + @property + def _as_parameter_(self): + """ + Compatibility with ctypes. + Allows passing transparently a Point object to an API call. + """ + return RECT(self.left, self.top, self.right, self.bottom) + + def __get_width(self): + return self.right - self.left + + def __get_height(self): + return self.bottom - self.top + + def __set_width(self, value): + self.right = value - self.left + + def __set_height(self, value): + self.bottom = value - self.top + + width = property(__get_width, __set_width) + height = property(__get_height, __set_height) + + def screen_to_client(self, hWnd): + """ + Translates window screen coordinates to client coordinates. + + @see: L{client_to_screen}, L{translate} + + @type hWnd: int or L{HWND} or L{system.Window} + @param hWnd: Window handle. + + @rtype: L{Rect} + @return: New object containing the translated coordinates. + """ + topleft = ScreenToClient(hWnd, (self.left, self.top)) + bottomright = ScreenToClient(hWnd, (self.bottom, self.right)) + return Rect( topleft.x, topleft.y, bottomright.x, bottomright.y ) + + def client_to_screen(self, hWnd): + """ + Translates window client coordinates to screen coordinates. + + @see: L{screen_to_client}, L{translate} + + @type hWnd: int or L{HWND} or L{system.Window} + @param hWnd: Window handle. + + @rtype: L{Rect} + @return: New object containing the translated coordinates. + """ + topleft = ClientToScreen(hWnd, (self.left, self.top)) + bottomright = ClientToScreen(hWnd, (self.bottom, self.right)) + return Rect( topleft.x, topleft.y, bottomright.x, bottomright.y ) + + def translate(self, hWndFrom = HWND_DESKTOP, hWndTo = HWND_DESKTOP): + """ + Translate coordinates from one window to another. + + @see: L{client_to_screen}, L{screen_to_client} + + @type hWndFrom: int or L{HWND} or L{system.Window} + @param hWndFrom: Window handle to translate from. + Use C{HWND_DESKTOP} for screen coordinates. + + @type hWndTo: int or L{HWND} or L{system.Window} + @param hWndTo: Window handle to translate to. + Use C{HWND_DESKTOP} for screen coordinates. + + @rtype: L{Rect} + @return: New object containing the translated coordinates. + """ + points = [ (self.left, self.top), (self.right, self.bottom) ] + return MapWindowPoints(hWndFrom, hWndTo, points) + +class WindowPlacement(object): + """ + Python wrapper over the L{WINDOWPLACEMENT} class. + """ + + def __init__(self, wp = None): + """ + @type wp: L{WindowPlacement} or L{WINDOWPLACEMENT} + @param wp: Another window placement object. + """ + + # Initialize all properties with empty values. + self.flags = 0 + self.showCmd = 0 + self.ptMinPosition = Point() + self.ptMaxPosition = Point() + self.rcNormalPosition = Rect() + + # If a window placement was given copy it's properties. + if wp: + self.flags = wp.flags + self.showCmd = wp.showCmd + self.ptMinPosition = Point( wp.ptMinPosition.x, wp.ptMinPosition.y ) + self.ptMaxPosition = Point( wp.ptMaxPosition.x, wp.ptMaxPosition.y ) + self.rcNormalPosition = Rect( + wp.rcNormalPosition.left, + wp.rcNormalPosition.top, + wp.rcNormalPosition.right, + wp.rcNormalPosition.bottom, + ) + + @property + def _as_parameter_(self): + """ + Compatibility with ctypes. + Allows passing transparently a Point object to an API call. + """ + wp = WINDOWPLACEMENT() + wp.length = sizeof(wp) + wp.flags = self.flags + wp.showCmd = self.showCmd + wp.ptMinPosition.x = self.ptMinPosition.x + wp.ptMinPosition.y = self.ptMinPosition.y + wp.ptMaxPosition.x = self.ptMaxPosition.x + wp.ptMaxPosition.y = self.ptMaxPosition.y + wp.rcNormalPosition.left = self.rcNormalPosition.left + wp.rcNormalPosition.top = self.rcNormalPosition.top + wp.rcNormalPosition.right = self.rcNormalPosition.right + wp.rcNormalPosition.bottom = self.rcNormalPosition.bottom + return wp + +#--- user32.dll --------------------------------------------------------------- + +# void WINAPI SetLastErrorEx( +# __in DWORD dwErrCode, +# __in DWORD dwType +# ); +def SetLastErrorEx(dwErrCode, dwType = 0): + _SetLastErrorEx = windll.user32.SetLastErrorEx + _SetLastErrorEx.argtypes = [DWORD, DWORD] + _SetLastErrorEx.restype = None + _SetLastErrorEx(dwErrCode, dwType) + +# HWND FindWindow( +# LPCTSTR lpClassName, +# LPCTSTR lpWindowName +# ); +def FindWindowA(lpClassName = None, lpWindowName = None): + _FindWindowA = windll.user32.FindWindowA + _FindWindowA.argtypes = [LPSTR, LPSTR] + _FindWindowA.restype = HWND + + hWnd = _FindWindowA(lpClassName, lpWindowName) + if not hWnd: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return hWnd + +def FindWindowW(lpClassName = None, lpWindowName = None): + _FindWindowW = windll.user32.FindWindowW + _FindWindowW.argtypes = [LPWSTR, LPWSTR] + _FindWindowW.restype = HWND + + hWnd = _FindWindowW(lpClassName, lpWindowName) + if not hWnd: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return hWnd + +FindWindow = GuessStringType(FindWindowA, FindWindowW) + +# HWND WINAPI FindWindowEx( +# __in_opt HWND hwndParent, +# __in_opt HWND hwndChildAfter, +# __in_opt LPCTSTR lpszClass, +# __in_opt LPCTSTR lpszWindow +# ); +def FindWindowExA(hwndParent = None, hwndChildAfter = None, lpClassName = None, lpWindowName = None): + _FindWindowExA = windll.user32.FindWindowExA + _FindWindowExA.argtypes = [HWND, HWND, LPSTR, LPSTR] + _FindWindowExA.restype = HWND + + hWnd = _FindWindowExA(hwndParent, hwndChildAfter, lpClassName, lpWindowName) + if not hWnd: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return hWnd + +def FindWindowExW(hwndParent = None, hwndChildAfter = None, lpClassName = None, lpWindowName = None): + _FindWindowExW = windll.user32.FindWindowExW + _FindWindowExW.argtypes = [HWND, HWND, LPWSTR, LPWSTR] + _FindWindowExW.restype = HWND + + hWnd = _FindWindowExW(hwndParent, hwndChildAfter, lpClassName, lpWindowName) + if not hWnd: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return hWnd + +FindWindowEx = GuessStringType(FindWindowExA, FindWindowExW) + +# int GetClassName( +# HWND hWnd, +# LPTSTR lpClassName, +# int nMaxCount +# ); +def GetClassNameA(hWnd): + _GetClassNameA = windll.user32.GetClassNameA + _GetClassNameA.argtypes = [HWND, LPSTR, ctypes.c_int] + _GetClassNameA.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(CHAR) + while 1: + lpClassName = ctypes.create_string_buffer("", nMaxCount) + nCount = _GetClassNameA(hWnd, lpClassName, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return lpClassName.value + +def GetClassNameW(hWnd): + _GetClassNameW = windll.user32.GetClassNameW + _GetClassNameW.argtypes = [HWND, LPWSTR, ctypes.c_int] + _GetClassNameW.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(WCHAR) + while 1: + lpClassName = ctypes.create_unicode_buffer(u"", nMaxCount) + nCount = _GetClassNameW(hWnd, lpClassName, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return lpClassName.value + +GetClassName = GuessStringType(GetClassNameA, GetClassNameW) + +# int WINAPI GetWindowText( +# __in HWND hWnd, +# __out LPTSTR lpString, +# __in int nMaxCount +# ); +def GetWindowTextA(hWnd): + _GetWindowTextA = windll.user32.GetWindowTextA + _GetWindowTextA.argtypes = [HWND, LPSTR, ctypes.c_int] + _GetWindowTextA.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(CHAR) + while 1: + lpString = ctypes.create_string_buffer("", nMaxCount) + nCount = _GetWindowTextA(hWnd, lpString, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return lpString.value + +def GetWindowTextW(hWnd): + _GetWindowTextW = windll.user32.GetWindowTextW + _GetWindowTextW.argtypes = [HWND, LPWSTR, ctypes.c_int] + _GetWindowTextW.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(CHAR) + while 1: + lpString = ctypes.create_string_buffer("", nMaxCount) + nCount = _GetWindowTextW(hWnd, lpString, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return lpString.value + +GetWindowText = GuessStringType(GetWindowTextA, GetWindowTextW) + +# BOOL WINAPI SetWindowText( +# __in HWND hWnd, +# __in_opt LPCTSTR lpString +# ); +def SetWindowTextA(hWnd, lpString = None): + _SetWindowTextA = windll.user32.SetWindowTextA + _SetWindowTextA.argtypes = [HWND, LPSTR] + _SetWindowTextA.restype = bool + _SetWindowTextA.errcheck = RaiseIfZero + _SetWindowTextA(hWnd, lpString) + +def SetWindowTextW(hWnd, lpString = None): + _SetWindowTextW = windll.user32.SetWindowTextW + _SetWindowTextW.argtypes = [HWND, LPWSTR] + _SetWindowTextW.restype = bool + _SetWindowTextW.errcheck = RaiseIfZero + _SetWindowTextW(hWnd, lpString) + +SetWindowText = GuessStringType(SetWindowTextA, SetWindowTextW) + +# LONG GetWindowLong( +# HWND hWnd, +# int nIndex +# ); +def GetWindowLongA(hWnd, nIndex = 0): + _GetWindowLongA = windll.user32.GetWindowLongA + _GetWindowLongA.argtypes = [HWND, ctypes.c_int] + _GetWindowLongA.restype = DWORD + + SetLastError(ERROR_SUCCESS) + retval = _GetWindowLongA(hWnd, nIndex) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + +def GetWindowLongW(hWnd, nIndex = 0): + _GetWindowLongW = windll.user32.GetWindowLongW + _GetWindowLongW.argtypes = [HWND, ctypes.c_int] + _GetWindowLongW.restype = DWORD + + SetLastError(ERROR_SUCCESS) + retval = _GetWindowLongW(hWnd, nIndex) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + +GetWindowLong = DefaultStringType(GetWindowLongA, GetWindowLongW) + +# LONG_PTR WINAPI GetWindowLongPtr( +# _In_ HWND hWnd, +# _In_ int nIndex +# ); + +if bits == 32: + + GetWindowLongPtrA = GetWindowLongA + GetWindowLongPtrW = GetWindowLongW + GetWindowLongPtr = GetWindowLong + +else: + + def GetWindowLongPtrA(hWnd, nIndex = 0): + _GetWindowLongPtrA = windll.user32.GetWindowLongPtrA + _GetWindowLongPtrA.argtypes = [HWND, ctypes.c_int] + _GetWindowLongPtrA.restype = SIZE_T + + SetLastError(ERROR_SUCCESS) + retval = _GetWindowLongPtrA(hWnd, nIndex) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + + def GetWindowLongPtrW(hWnd, nIndex = 0): + _GetWindowLongPtrW = windll.user32.GetWindowLongPtrW + _GetWindowLongPtrW.argtypes = [HWND, ctypes.c_int] + _GetWindowLongPtrW.restype = DWORD + + SetLastError(ERROR_SUCCESS) + retval = _GetWindowLongPtrW(hWnd, nIndex) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + + GetWindowLongPtr = DefaultStringType(GetWindowLongPtrA, GetWindowLongPtrW) + +# LONG WINAPI SetWindowLong( +# _In_ HWND hWnd, +# _In_ int nIndex, +# _In_ LONG dwNewLong +# ); + +def SetWindowLongA(hWnd, nIndex, dwNewLong): + _SetWindowLongA = windll.user32.SetWindowLongA + _SetWindowLongA.argtypes = [HWND, ctypes.c_int, DWORD] + _SetWindowLongA.restype = DWORD + + SetLastError(ERROR_SUCCESS) + retval = _SetWindowLongA(hWnd, nIndex, dwNewLong) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + +def SetWindowLongW(hWnd, nIndex, dwNewLong): + _SetWindowLongW = windll.user32.SetWindowLongW + _SetWindowLongW.argtypes = [HWND, ctypes.c_int, DWORD] + _SetWindowLongW.restype = DWORD + + SetLastError(ERROR_SUCCESS) + retval = _SetWindowLongW(hWnd, nIndex, dwNewLong) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + +SetWindowLong = DefaultStringType(SetWindowLongA, SetWindowLongW) + +# LONG_PTR WINAPI SetWindowLongPtr( +# _In_ HWND hWnd, +# _In_ int nIndex, +# _In_ LONG_PTR dwNewLong +# ); + +if bits == 32: + + SetWindowLongPtrA = SetWindowLongA + SetWindowLongPtrW = SetWindowLongW + SetWindowLongPtr = SetWindowLong + +else: + + def SetWindowLongPtrA(hWnd, nIndex, dwNewLong): + _SetWindowLongPtrA = windll.user32.SetWindowLongPtrA + _SetWindowLongPtrA.argtypes = [HWND, ctypes.c_int, SIZE_T] + _SetWindowLongPtrA.restype = SIZE_T + + SetLastError(ERROR_SUCCESS) + retval = _SetWindowLongPtrA(hWnd, nIndex, dwNewLong) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + + def SetWindowLongPtrW(hWnd, nIndex, dwNewLong): + _SetWindowLongPtrW = windll.user32.SetWindowLongPtrW + _SetWindowLongPtrW.argtypes = [HWND, ctypes.c_int, SIZE_T] + _SetWindowLongPtrW.restype = SIZE_T + + SetLastError(ERROR_SUCCESS) + retval = _SetWindowLongPtrW(hWnd, nIndex, dwNewLong) + if retval == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return retval + + SetWindowLongPtr = DefaultStringType(SetWindowLongPtrA, SetWindowLongPtrW) + +# HWND GetShellWindow(VOID); +def GetShellWindow(): + _GetShellWindow = windll.user32.GetShellWindow + _GetShellWindow.argtypes = [] + _GetShellWindow.restype = HWND + _GetShellWindow.errcheck = RaiseIfZero + return _GetShellWindow() + +# DWORD GetWindowThreadProcessId( +# HWND hWnd, +# LPDWORD lpdwProcessId +# ); +def GetWindowThreadProcessId(hWnd): + _GetWindowThreadProcessId = windll.user32.GetWindowThreadProcessId + _GetWindowThreadProcessId.argtypes = [HWND, LPDWORD] + _GetWindowThreadProcessId.restype = DWORD + _GetWindowThreadProcessId.errcheck = RaiseIfZero + + dwProcessId = DWORD(0) + dwThreadId = _GetWindowThreadProcessId(hWnd, byref(dwProcessId)) + return (dwThreadId, dwProcessId.value) + +# HWND WINAPI GetWindow( +# __in HWND hwnd, +# __in UINT uCmd +# ); +def GetWindow(hWnd, uCmd): + _GetWindow = windll.user32.GetWindow + _GetWindow.argtypes = [HWND, UINT] + _GetWindow.restype = HWND + + SetLastError(ERROR_SUCCESS) + hWndTarget = _GetWindow(hWnd, uCmd) + if not hWndTarget: + winerr = GetLastError() + if winerr != ERROR_SUCCESS: + raise ctypes.WinError(winerr) + return hWndTarget + +# HWND GetParent( +# HWND hWnd +# ); +def GetParent(hWnd): + _GetParent = windll.user32.GetParent + _GetParent.argtypes = [HWND] + _GetParent.restype = HWND + + SetLastError(ERROR_SUCCESS) + hWndParent = _GetParent(hWnd) + if not hWndParent: + winerr = GetLastError() + if winerr != ERROR_SUCCESS: + raise ctypes.WinError(winerr) + return hWndParent + +# HWND WINAPI GetAncestor( +# __in HWND hwnd, +# __in UINT gaFlags +# ); +def GetAncestor(hWnd, gaFlags = GA_PARENT): + _GetAncestor = windll.user32.GetAncestor + _GetAncestor.argtypes = [HWND, UINT] + _GetAncestor.restype = HWND + + SetLastError(ERROR_SUCCESS) + hWndParent = _GetAncestor(hWnd, gaFlags) + if not hWndParent: + winerr = GetLastError() + if winerr != ERROR_SUCCESS: + raise ctypes.WinError(winerr) + return hWndParent + +# BOOL EnableWindow( +# HWND hWnd, +# BOOL bEnable +# ); +def EnableWindow(hWnd, bEnable = True): + _EnableWindow = windll.user32.EnableWindow + _EnableWindow.argtypes = [HWND, BOOL] + _EnableWindow.restype = bool + return _EnableWindow(hWnd, bool(bEnable)) + +# BOOL ShowWindow( +# HWND hWnd, +# int nCmdShow +# ); +def ShowWindow(hWnd, nCmdShow = SW_SHOW): + _ShowWindow = windll.user32.ShowWindow + _ShowWindow.argtypes = [HWND, ctypes.c_int] + _ShowWindow.restype = bool + return _ShowWindow(hWnd, nCmdShow) + +# BOOL ShowWindowAsync( +# HWND hWnd, +# int nCmdShow +# ); +def ShowWindowAsync(hWnd, nCmdShow = SW_SHOW): + _ShowWindowAsync = windll.user32.ShowWindowAsync + _ShowWindowAsync.argtypes = [HWND, ctypes.c_int] + _ShowWindowAsync.restype = bool + return _ShowWindowAsync(hWnd, nCmdShow) + +# HWND GetDesktopWindow(VOID); +def GetDesktopWindow(): + _GetDesktopWindow = windll.user32.GetDesktopWindow + _GetDesktopWindow.argtypes = [] + _GetDesktopWindow.restype = HWND + _GetDesktopWindow.errcheck = RaiseIfZero + return _GetDesktopWindow() + +# HWND GetForegroundWindow(VOID); +def GetForegroundWindow(): + _GetForegroundWindow = windll.user32.GetForegroundWindow + _GetForegroundWindow.argtypes = [] + _GetForegroundWindow.restype = HWND + _GetForegroundWindow.errcheck = RaiseIfZero + return _GetForegroundWindow() + +# BOOL IsWindow( +# HWND hWnd +# ); +def IsWindow(hWnd): + _IsWindow = windll.user32.IsWindow + _IsWindow.argtypes = [HWND] + _IsWindow.restype = bool + return _IsWindow(hWnd) + +# BOOL IsWindowVisible( +# HWND hWnd +# ); +def IsWindowVisible(hWnd): + _IsWindowVisible = windll.user32.IsWindowVisible + _IsWindowVisible.argtypes = [HWND] + _IsWindowVisible.restype = bool + return _IsWindowVisible(hWnd) + +# BOOL IsWindowEnabled( +# HWND hWnd +# ); +def IsWindowEnabled(hWnd): + _IsWindowEnabled = windll.user32.IsWindowEnabled + _IsWindowEnabled.argtypes = [HWND] + _IsWindowEnabled.restype = bool + return _IsWindowEnabled(hWnd) + +# BOOL IsZoomed( +# HWND hWnd +# ); +def IsZoomed(hWnd): + _IsZoomed = windll.user32.IsZoomed + _IsZoomed.argtypes = [HWND] + _IsZoomed.restype = bool + return _IsZoomed(hWnd) + +# BOOL IsIconic( +# HWND hWnd +# ); +def IsIconic(hWnd): + _IsIconic = windll.user32.IsIconic + _IsIconic.argtypes = [HWND] + _IsIconic.restype = bool + return _IsIconic(hWnd) + +# BOOL IsChild( +# HWND hWnd +# ); +def IsChild(hWnd): + _IsChild = windll.user32.IsChild + _IsChild.argtypes = [HWND] + _IsChild.restype = bool + return _IsChild(hWnd) + +# HWND WindowFromPoint( +# POINT Point +# ); +def WindowFromPoint(point): + _WindowFromPoint = windll.user32.WindowFromPoint + _WindowFromPoint.argtypes = [POINT] + _WindowFromPoint.restype = HWND + _WindowFromPoint.errcheck = RaiseIfZero + if isinstance(point, tuple): + point = POINT(*point) + return _WindowFromPoint(point) + +# HWND ChildWindowFromPoint( +# HWND hWndParent, +# POINT Point +# ); +def ChildWindowFromPoint(hWndParent, point): + _ChildWindowFromPoint = windll.user32.ChildWindowFromPoint + _ChildWindowFromPoint.argtypes = [HWND, POINT] + _ChildWindowFromPoint.restype = HWND + _ChildWindowFromPoint.errcheck = RaiseIfZero + if isinstance(point, tuple): + point = POINT(*point) + return _ChildWindowFromPoint(hWndParent, point) + +#HWND RealChildWindowFromPoint( +# HWND hwndParent, +# POINT ptParentClientCoords +#); +def RealChildWindowFromPoint(hWndParent, ptParentClientCoords): + _RealChildWindowFromPoint = windll.user32.RealChildWindowFromPoint + _RealChildWindowFromPoint.argtypes = [HWND, POINT] + _RealChildWindowFromPoint.restype = HWND + _RealChildWindowFromPoint.errcheck = RaiseIfZero + if isinstance(ptParentClientCoords, tuple): + ptParentClientCoords = POINT(*ptParentClientCoords) + return _RealChildWindowFromPoint(hWndParent, ptParentClientCoords) + +# BOOL ScreenToClient( +# __in HWND hWnd, +# LPPOINT lpPoint +# ); +def ScreenToClient(hWnd, lpPoint): + _ScreenToClient = windll.user32.ScreenToClient + _ScreenToClient.argtypes = [HWND, LPPOINT] + _ScreenToClient.restype = bool + _ScreenToClient.errcheck = RaiseIfZero + + if isinstance(lpPoint, tuple): + lpPoint = POINT(*lpPoint) + else: + lpPoint = POINT(lpPoint.x, lpPoint.y) + _ScreenToClient(hWnd, byref(lpPoint)) + return Point(lpPoint.x, lpPoint.y) + +# BOOL ClientToScreen( +# HWND hWnd, +# LPPOINT lpPoint +# ); +def ClientToScreen(hWnd, lpPoint): + _ClientToScreen = windll.user32.ClientToScreen + _ClientToScreen.argtypes = [HWND, LPPOINT] + _ClientToScreen.restype = bool + _ClientToScreen.errcheck = RaiseIfZero + + if isinstance(lpPoint, tuple): + lpPoint = POINT(*lpPoint) + else: + lpPoint = POINT(lpPoint.x, lpPoint.y) + _ClientToScreen(hWnd, byref(lpPoint)) + return Point(lpPoint.x, lpPoint.y) + +# int MapWindowPoints( +# __in HWND hWndFrom, +# __in HWND hWndTo, +# __inout LPPOINT lpPoints, +# __in UINT cPoints +# ); +def MapWindowPoints(hWndFrom, hWndTo, lpPoints): + _MapWindowPoints = windll.user32.MapWindowPoints + _MapWindowPoints.argtypes = [HWND, HWND, LPPOINT, UINT] + _MapWindowPoints.restype = ctypes.c_int + + cPoints = len(lpPoints) + lpPoints = (POINT * cPoints)(* lpPoints) + SetLastError(ERROR_SUCCESS) + number = _MapWindowPoints(hWndFrom, hWndTo, byref(lpPoints), cPoints) + if number == 0: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + x_delta = number & 0xFFFF + y_delta = (number >> 16) & 0xFFFF + return x_delta, y_delta, [ (Point.x, Point.y) for Point in lpPoints ] + +#BOOL SetForegroundWindow( +# HWND hWnd +#); +def SetForegroundWindow(hWnd): + _SetForegroundWindow = windll.user32.SetForegroundWindow + _SetForegroundWindow.argtypes = [HWND] + _SetForegroundWindow.restype = bool + _SetForegroundWindow.errcheck = RaiseIfZero + return _SetForegroundWindow(hWnd) + +# BOOL GetWindowPlacement( +# HWND hWnd, +# WINDOWPLACEMENT *lpwndpl +# ); +def GetWindowPlacement(hWnd): + _GetWindowPlacement = windll.user32.GetWindowPlacement + _GetWindowPlacement.argtypes = [HWND, PWINDOWPLACEMENT] + _GetWindowPlacement.restype = bool + _GetWindowPlacement.errcheck = RaiseIfZero + + lpwndpl = WINDOWPLACEMENT() + lpwndpl.length = sizeof(lpwndpl) + _GetWindowPlacement(hWnd, byref(lpwndpl)) + return WindowPlacement(lpwndpl) + +# BOOL SetWindowPlacement( +# HWND hWnd, +# WINDOWPLACEMENT *lpwndpl +# ); +def SetWindowPlacement(hWnd, lpwndpl): + _SetWindowPlacement = windll.user32.SetWindowPlacement + _SetWindowPlacement.argtypes = [HWND, PWINDOWPLACEMENT] + _SetWindowPlacement.restype = bool + _SetWindowPlacement.errcheck = RaiseIfZero + + if isinstance(lpwndpl, WINDOWPLACEMENT): + lpwndpl.length = sizeof(lpwndpl) + _SetWindowPlacement(hWnd, byref(lpwndpl)) + +# BOOL WINAPI GetWindowRect( +# __in HWND hWnd, +# __out LPRECT lpRect +# ); +def GetWindowRect(hWnd): + _GetWindowRect = windll.user32.GetWindowRect + _GetWindowRect.argtypes = [HWND, LPRECT] + _GetWindowRect.restype = bool + _GetWindowRect.errcheck = RaiseIfZero + + lpRect = RECT() + _GetWindowRect(hWnd, byref(lpRect)) + return Rect(lpRect.left, lpRect.top, lpRect.right, lpRect.bottom) + +# BOOL WINAPI GetClientRect( +# __in HWND hWnd, +# __out LPRECT lpRect +# ); +def GetClientRect(hWnd): + _GetClientRect = windll.user32.GetClientRect + _GetClientRect.argtypes = [HWND, LPRECT] + _GetClientRect.restype = bool + _GetClientRect.errcheck = RaiseIfZero + + lpRect = RECT() + _GetClientRect(hWnd, byref(lpRect)) + return Rect(lpRect.left, lpRect.top, lpRect.right, lpRect.bottom) + +#BOOL MoveWindow( +# HWND hWnd, +# int X, +# int Y, +# int nWidth, +# int nHeight, +# BOOL bRepaint +#); +def MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint = True): + _MoveWindow = windll.user32.MoveWindow + _MoveWindow.argtypes = [HWND, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, BOOL] + _MoveWindow.restype = bool + _MoveWindow.errcheck = RaiseIfZero + _MoveWindow(hWnd, X, Y, nWidth, nHeight, bool(bRepaint)) + +# BOOL GetGUIThreadInfo( +# DWORD idThread, +# LPGUITHREADINFO lpgui +# ); +def GetGUIThreadInfo(idThread): + _GetGUIThreadInfo = windll.user32.GetGUIThreadInfo + _GetGUIThreadInfo.argtypes = [DWORD, LPGUITHREADINFO] + _GetGUIThreadInfo.restype = bool + _GetGUIThreadInfo.errcheck = RaiseIfZero + + gui = GUITHREADINFO() + _GetGUIThreadInfo(idThread, byref(gui)) + return gui + +# BOOL CALLBACK EnumWndProc( +# HWND hwnd, +# LPARAM lParam +# ); +class __EnumWndProc (__WindowEnumerator): + pass + +# BOOL EnumWindows( +# WNDENUMPROC lpEnumFunc, +# LPARAM lParam +# ); +def EnumWindows(): + _EnumWindows = windll.user32.EnumWindows + _EnumWindows.argtypes = [WNDENUMPROC, LPARAM] + _EnumWindows.restype = bool + + EnumFunc = __EnumWndProc() + lpEnumFunc = WNDENUMPROC(EnumFunc) + if not _EnumWindows(lpEnumFunc, NULL): + errcode = GetLastError() + if errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS): + raise ctypes.WinError(errcode) + return EnumFunc.hwnd + +# BOOL CALLBACK EnumThreadWndProc( +# HWND hwnd, +# LPARAM lParam +# ); +class __EnumThreadWndProc (__WindowEnumerator): + pass + +# BOOL EnumThreadWindows( +# DWORD dwThreadId, +# WNDENUMPROC lpfn, +# LPARAM lParam +# ); +def EnumThreadWindows(dwThreadId): + _EnumThreadWindows = windll.user32.EnumThreadWindows + _EnumThreadWindows.argtypes = [DWORD, WNDENUMPROC, LPARAM] + _EnumThreadWindows.restype = bool + + fn = __EnumThreadWndProc() + lpfn = WNDENUMPROC(fn) + if not _EnumThreadWindows(dwThreadId, lpfn, NULL): + errcode = GetLastError() + if errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS): + raise ctypes.WinError(errcode) + return fn.hwnd + +# BOOL CALLBACK EnumChildProc( +# HWND hwnd, +# LPARAM lParam +# ); +class __EnumChildProc (__WindowEnumerator): + pass + +# BOOL EnumChildWindows( +# HWND hWndParent, +# WNDENUMPROC lpEnumFunc, +# LPARAM lParam +# ); +def EnumChildWindows(hWndParent = NULL): + _EnumChildWindows = windll.user32.EnumChildWindows + _EnumChildWindows.argtypes = [HWND, WNDENUMPROC, LPARAM] + _EnumChildWindows.restype = bool + + EnumFunc = __EnumChildProc() + lpEnumFunc = WNDENUMPROC(EnumFunc) + SetLastError(ERROR_SUCCESS) + _EnumChildWindows(hWndParent, lpEnumFunc, NULL) + errcode = GetLastError() + if errcode != ERROR_SUCCESS and errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS): + raise ctypes.WinError(errcode) + return EnumFunc.hwnd + +# LRESULT SendMessage( +# HWND hWnd, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam +# ); +def SendMessageA(hWnd, Msg, wParam = 0, lParam = 0): + _SendMessageA = windll.user32.SendMessageA + _SendMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM] + _SendMessageA.restype = LRESULT + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + return _SendMessageA(hWnd, Msg, wParam, lParam) + +def SendMessageW(hWnd, Msg, wParam = 0, lParam = 0): + _SendMessageW = windll.user32.SendMessageW + _SendMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] + _SendMessageW.restype = LRESULT + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + return _SendMessageW(hWnd, Msg, wParam, lParam) + +SendMessage = GuessStringType(SendMessageA, SendMessageW) + +# BOOL PostMessage( +# HWND hWnd, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam +# ); +def PostMessageA(hWnd, Msg, wParam = 0, lParam = 0): + _PostMessageA = windll.user32.PostMessageA + _PostMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM] + _PostMessageA.restype = bool + _PostMessageA.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + _PostMessageA(hWnd, Msg, wParam, lParam) + +def PostMessageW(hWnd, Msg, wParam = 0, lParam = 0): + _PostMessageW = windll.user32.PostMessageW + _PostMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] + _PostMessageW.restype = bool + _PostMessageW.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + _PostMessageW(hWnd, Msg, wParam, lParam) + +PostMessage = GuessStringType(PostMessageA, PostMessageW) + +# BOOL PostThreadMessage( +# DWORD idThread, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam +# ); +def PostThreadMessageA(idThread, Msg, wParam = 0, lParam = 0): + _PostThreadMessageA = windll.user32.PostThreadMessageA + _PostThreadMessageA.argtypes = [DWORD, UINT, WPARAM, LPARAM] + _PostThreadMessageA.restype = bool + _PostThreadMessageA.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + _PostThreadMessageA(idThread, Msg, wParam, lParam) + +def PostThreadMessageW(idThread, Msg, wParam = 0, lParam = 0): + _PostThreadMessageW = windll.user32.PostThreadMessageW + _PostThreadMessageW.argtypes = [DWORD, UINT, WPARAM, LPARAM] + _PostThreadMessageW.restype = bool + _PostThreadMessageW.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + _PostThreadMessageW(idThread, Msg, wParam, lParam) + +PostThreadMessage = GuessStringType(PostThreadMessageA, PostThreadMessageW) + +# LRESULT c( +# HWND hWnd, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam, +# UINT fuFlags, +# UINT uTimeout, +# PDWORD_PTR lpdwResult +# ); +def SendMessageTimeoutA(hWnd, Msg, wParam = 0, lParam = 0, fuFlags = 0, uTimeout = 0): + _SendMessageTimeoutA = windll.user32.SendMessageTimeoutA + _SendMessageTimeoutA.argtypes = [HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR] + _SendMessageTimeoutA.restype = LRESULT + _SendMessageTimeoutA.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + dwResult = DWORD(0) + _SendMessageTimeoutA(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, byref(dwResult)) + return dwResult.value + +def SendMessageTimeoutW(hWnd, Msg, wParam = 0, lParam = 0): + _SendMessageTimeoutW = windll.user32.SendMessageTimeoutW + _SendMessageTimeoutW.argtypes = [HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR] + _SendMessageTimeoutW.restype = LRESULT + _SendMessageTimeoutW.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + dwResult = DWORD(0) + _SendMessageTimeoutW(hWnd, Msg, wParam, lParam, fuFlags, uTimeout, byref(dwResult)) + return dwResult.value + +SendMessageTimeout = GuessStringType(SendMessageTimeoutA, SendMessageTimeoutW) + +# BOOL SendNotifyMessage( +# HWND hWnd, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam +# ); +def SendNotifyMessageA(hWnd, Msg, wParam = 0, lParam = 0): + _SendNotifyMessageA = windll.user32.SendNotifyMessageA + _SendNotifyMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM] + _SendNotifyMessageA.restype = bool + _SendNotifyMessageA.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + _SendNotifyMessageA(hWnd, Msg, wParam, lParam) + +def SendNotifyMessageW(hWnd, Msg, wParam = 0, lParam = 0): + _SendNotifyMessageW = windll.user32.SendNotifyMessageW + _SendNotifyMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] + _SendNotifyMessageW.restype = bool + _SendNotifyMessageW.errcheck = RaiseIfZero + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + _SendNotifyMessageW(hWnd, Msg, wParam, lParam) + +SendNotifyMessage = GuessStringType(SendNotifyMessageA, SendNotifyMessageW) + +# LRESULT SendDlgItemMessage( +# HWND hDlg, +# int nIDDlgItem, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam +# ); +def SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam = 0, lParam = 0): + _SendDlgItemMessageA = windll.user32.SendDlgItemMessageA + _SendDlgItemMessageA.argtypes = [HWND, ctypes.c_int, UINT, WPARAM, LPARAM] + _SendDlgItemMessageA.restype = LRESULT + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + return _SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, lParam) + +def SendDlgItemMessageW(hDlg, nIDDlgItem, Msg, wParam = 0, lParam = 0): + _SendDlgItemMessageW = windll.user32.SendDlgItemMessageW + _SendDlgItemMessageW.argtypes = [HWND, ctypes.c_int, UINT, WPARAM, LPARAM] + _SendDlgItemMessageW.restype = LRESULT + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + return _SendDlgItemMessageW(hDlg, nIDDlgItem, Msg, wParam, lParam) + +SendDlgItemMessage = GuessStringType(SendDlgItemMessageA, SendDlgItemMessageW) + +# DWORD WINAPI WaitForInputIdle( +# _In_ HANDLE hProcess, +# _In_ DWORD dwMilliseconds +# ); +def WaitForInputIdle(hProcess, dwMilliseconds = INFINITE): + _WaitForInputIdle = windll.user32.WaitForInputIdle + _WaitForInputIdle.argtypes = [HANDLE, DWORD] + _WaitForInputIdle.restype = DWORD + + r = _WaitForInputIdle(hProcess, dwMilliseconds) + if r == WAIT_FAILED: + raise ctypes.WinError() + return r + +# UINT RegisterWindowMessage( +# LPCTSTR lpString +# ); +def RegisterWindowMessageA(lpString): + _RegisterWindowMessageA = windll.user32.RegisterWindowMessageA + _RegisterWindowMessageA.argtypes = [LPSTR] + _RegisterWindowMessageA.restype = UINT + _RegisterWindowMessageA.errcheck = RaiseIfZero + return _RegisterWindowMessageA(lpString) + +def RegisterWindowMessageW(lpString): + _RegisterWindowMessageW = windll.user32.RegisterWindowMessageW + _RegisterWindowMessageW.argtypes = [LPWSTR] + _RegisterWindowMessageW.restype = UINT + _RegisterWindowMessageW.errcheck = RaiseIfZero + return _RegisterWindowMessageW(lpString) + +RegisterWindowMessage = GuessStringType(RegisterWindowMessageA, RegisterWindowMessageW) + +# UINT RegisterClipboardFormat( +# LPCTSTR lpString +# ); +def RegisterClipboardFormatA(lpString): + _RegisterClipboardFormatA = windll.user32.RegisterClipboardFormatA + _RegisterClipboardFormatA.argtypes = [LPSTR] + _RegisterClipboardFormatA.restype = UINT + _RegisterClipboardFormatA.errcheck = RaiseIfZero + return _RegisterClipboardFormatA(lpString) + +def RegisterClipboardFormatW(lpString): + _RegisterClipboardFormatW = windll.user32.RegisterClipboardFormatW + _RegisterClipboardFormatW.argtypes = [LPWSTR] + _RegisterClipboardFormatW.restype = UINT + _RegisterClipboardFormatW.errcheck = RaiseIfZero + return _RegisterClipboardFormatW(lpString) + +RegisterClipboardFormat = GuessStringType(RegisterClipboardFormatA, RegisterClipboardFormatW) + +# HANDLE WINAPI GetProp( +# __in HWND hWnd, +# __in LPCTSTR lpString +# ); +def GetPropA(hWnd, lpString): + _GetPropA = windll.user32.GetPropA + _GetPropA.argtypes = [HWND, LPSTR] + _GetPropA.restype = HANDLE + return _GetPropA(hWnd, lpString) + +def GetPropW(hWnd, lpString): + _GetPropW = windll.user32.GetPropW + _GetPropW.argtypes = [HWND, LPWSTR] + _GetPropW.restype = HANDLE + return _GetPropW(hWnd, lpString) + +GetProp = GuessStringType(GetPropA, GetPropW) + +# BOOL WINAPI SetProp( +# __in HWND hWnd, +# __in LPCTSTR lpString, +# __in_opt HANDLE hData +# ); +def SetPropA(hWnd, lpString, hData): + _SetPropA = windll.user32.SetPropA + _SetPropA.argtypes = [HWND, LPSTR, HANDLE] + _SetPropA.restype = BOOL + _SetPropA.errcheck = RaiseIfZero + _SetPropA(hWnd, lpString, hData) + +def SetPropW(hWnd, lpString, hData): + _SetPropW = windll.user32.SetPropW + _SetPropW.argtypes = [HWND, LPWSTR, HANDLE] + _SetPropW.restype = BOOL + _SetPropW.errcheck = RaiseIfZero + _SetPropW(hWnd, lpString, hData) + +SetProp = GuessStringType(SetPropA, SetPropW) + +# HANDLE WINAPI RemoveProp( +# __in HWND hWnd, +# __in LPCTSTR lpString +# ); +def RemovePropA(hWnd, lpString): + _RemovePropA = windll.user32.RemovePropA + _RemovePropA.argtypes = [HWND, LPSTR] + _RemovePropA.restype = HANDLE + return _RemovePropA(hWnd, lpString) + +def RemovePropW(hWnd, lpString): + _RemovePropW = windll.user32.RemovePropW + _RemovePropW.argtypes = [HWND, LPWSTR] + _RemovePropW.restype = HANDLE + return _RemovePropW(hWnd, lpString) + +RemoveProp = GuessStringType(RemovePropA, RemovePropW) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/version.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/version.py new file mode 100644 index 0000000..19b6d53 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/version.py @@ -0,0 +1,1038 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Detect the current architecture and operating system. + +Some functions here are really from kernel32.dll, others from version.dll. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- NTDDI version ------------------------------------------------------------ + +NTDDI_WIN8 = 0x06020000 +NTDDI_WIN7SP1 = 0x06010100 +NTDDI_WIN7 = 0x06010000 +NTDDI_WS08 = 0x06000100 +NTDDI_VISTASP1 = 0x06000100 +NTDDI_VISTA = 0x06000000 +NTDDI_LONGHORN = NTDDI_VISTA +NTDDI_WS03SP2 = 0x05020200 +NTDDI_WS03SP1 = 0x05020100 +NTDDI_WS03 = 0x05020000 +NTDDI_WINXPSP3 = 0x05010300 +NTDDI_WINXPSP2 = 0x05010200 +NTDDI_WINXPSP1 = 0x05010100 +NTDDI_WINXP = 0x05010000 +NTDDI_WIN2KSP4 = 0x05000400 +NTDDI_WIN2KSP3 = 0x05000300 +NTDDI_WIN2KSP2 = 0x05000200 +NTDDI_WIN2KSP1 = 0x05000100 +NTDDI_WIN2K = 0x05000000 +NTDDI_WINNT4 = 0x04000000 + +OSVERSION_MASK = 0xFFFF0000 +SPVERSION_MASK = 0x0000FF00 +SUBVERSION_MASK = 0x000000FF + +#--- OSVERSIONINFO and OSVERSIONINFOEX structures and constants --------------- + +VER_PLATFORM_WIN32s = 0 +VER_PLATFORM_WIN32_WINDOWS = 1 +VER_PLATFORM_WIN32_NT = 2 + +VER_SUITE_BACKOFFICE = 0x00000004 +VER_SUITE_BLADE = 0x00000400 +VER_SUITE_COMPUTE_SERVER = 0x00004000 +VER_SUITE_DATACENTER = 0x00000080 +VER_SUITE_ENTERPRISE = 0x00000002 +VER_SUITE_EMBEDDEDNT = 0x00000040 +VER_SUITE_PERSONAL = 0x00000200 +VER_SUITE_SINGLEUSERTS = 0x00000100 +VER_SUITE_SMALLBUSINESS = 0x00000001 +VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020 +VER_SUITE_STORAGE_SERVER = 0x00002000 +VER_SUITE_TERMINAL = 0x00000010 +VER_SUITE_WH_SERVER = 0x00008000 + +VER_NT_DOMAIN_CONTROLLER = 0x0000002 +VER_NT_SERVER = 0x0000003 +VER_NT_WORKSTATION = 0x0000001 + +VER_BUILDNUMBER = 0x0000004 +VER_MAJORVERSION = 0x0000002 +VER_MINORVERSION = 0x0000001 +VER_PLATFORMID = 0x0000008 +VER_PRODUCT_TYPE = 0x0000080 +VER_SERVICEPACKMAJOR = 0x0000020 +VER_SERVICEPACKMINOR = 0x0000010 +VER_SUITENAME = 0x0000040 + +VER_EQUAL = 1 +VER_GREATER = 2 +VER_GREATER_EQUAL = 3 +VER_LESS = 4 +VER_LESS_EQUAL = 5 +VER_AND = 6 +VER_OR = 7 + +# typedef struct _OSVERSIONINFO { +# DWORD dwOSVersionInfoSize; +# DWORD dwMajorVersion; +# DWORD dwMinorVersion; +# DWORD dwBuildNumber; +# DWORD dwPlatformId; +# TCHAR szCSDVersion[128]; +# }OSVERSIONINFO; +class OSVERSIONINFOA(Structure): + _fields_ = [ + ("dwOSVersionInfoSize", DWORD), + ("dwMajorVersion", DWORD), + ("dwMinorVersion", DWORD), + ("dwBuildNumber", DWORD), + ("dwPlatformId", DWORD), + ("szCSDVersion", CHAR * 128), + ] +class OSVERSIONINFOW(Structure): + _fields_ = [ + ("dwOSVersionInfoSize", DWORD), + ("dwMajorVersion", DWORD), + ("dwMinorVersion", DWORD), + ("dwBuildNumber", DWORD), + ("dwPlatformId", DWORD), + ("szCSDVersion", WCHAR * 128), + ] + +# typedef struct _OSVERSIONINFOEX { +# DWORD dwOSVersionInfoSize; +# DWORD dwMajorVersion; +# DWORD dwMinorVersion; +# DWORD dwBuildNumber; +# DWORD dwPlatformId; +# TCHAR szCSDVersion[128]; +# WORD wServicePackMajor; +# WORD wServicePackMinor; +# WORD wSuiteMask; +# BYTE wProductType; +# BYTE wReserved; +# }OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX; +class OSVERSIONINFOEXA(Structure): + _fields_ = [ + ("dwOSVersionInfoSize", DWORD), + ("dwMajorVersion", DWORD), + ("dwMinorVersion", DWORD), + ("dwBuildNumber", DWORD), + ("dwPlatformId", DWORD), + ("szCSDVersion", CHAR * 128), + ("wServicePackMajor", WORD), + ("wServicePackMinor", WORD), + ("wSuiteMask", WORD), + ("wProductType", BYTE), + ("wReserved", BYTE), + ] +class OSVERSIONINFOEXW(Structure): + _fields_ = [ + ("dwOSVersionInfoSize", DWORD), + ("dwMajorVersion", DWORD), + ("dwMinorVersion", DWORD), + ("dwBuildNumber", DWORD), + ("dwPlatformId", DWORD), + ("szCSDVersion", WCHAR * 128), + ("wServicePackMajor", WORD), + ("wServicePackMinor", WORD), + ("wSuiteMask", WORD), + ("wProductType", BYTE), + ("wReserved", BYTE), + ] + +LPOSVERSIONINFOA = POINTER(OSVERSIONINFOA) +LPOSVERSIONINFOW = POINTER(OSVERSIONINFOW) +LPOSVERSIONINFOEXA = POINTER(OSVERSIONINFOEXA) +LPOSVERSIONINFOEXW = POINTER(OSVERSIONINFOEXW) +POSVERSIONINFOA = LPOSVERSIONINFOA +POSVERSIONINFOW = LPOSVERSIONINFOW +POSVERSIONINFOEXA = LPOSVERSIONINFOEXA +POSVERSIONINFOEXW = LPOSVERSIONINFOA + +#--- GetSystemMetrics constants ----------------------------------------------- + +SM_CXSCREEN = 0 +SM_CYSCREEN = 1 +SM_CXVSCROLL = 2 +SM_CYHSCROLL = 3 +SM_CYCAPTION = 4 +SM_CXBORDER = 5 +SM_CYBORDER = 6 +SM_CXDLGFRAME = 7 +SM_CYDLGFRAME = 8 +SM_CYVTHUMB = 9 +SM_CXHTHUMB = 10 +SM_CXICON = 11 +SM_CYICON = 12 +SM_CXCURSOR = 13 +SM_CYCURSOR = 14 +SM_CYMENU = 15 +SM_CXFULLSCREEN = 16 +SM_CYFULLSCREEN = 17 +SM_CYKANJIWINDOW = 18 +SM_MOUSEPRESENT = 19 +SM_CYVSCROLL = 20 +SM_CXHSCROLL = 21 +SM_DEBUG = 22 +SM_SWAPBUTTON = 23 +SM_RESERVED1 = 24 +SM_RESERVED2 = 25 +SM_RESERVED3 = 26 +SM_RESERVED4 = 27 +SM_CXMIN = 28 +SM_CYMIN = 29 +SM_CXSIZE = 30 +SM_CYSIZE = 31 +SM_CXFRAME = 32 +SM_CYFRAME = 33 +SM_CXMINTRACK = 34 +SM_CYMINTRACK = 35 +SM_CXDOUBLECLK = 36 +SM_CYDOUBLECLK = 37 +SM_CXICONSPACING = 38 +SM_CYICONSPACING = 39 +SM_MENUDROPALIGNMENT = 40 +SM_PENWINDOWS = 41 +SM_DBCSENABLED = 42 +SM_CMOUSEBUTTONS = 43 + +SM_CXFIXEDFRAME = SM_CXDLGFRAME # ;win40 name change +SM_CYFIXEDFRAME = SM_CYDLGFRAME # ;win40 name change +SM_CXSIZEFRAME = SM_CXFRAME # ;win40 name change +SM_CYSIZEFRAME = SM_CYFRAME # ;win40 name change + +SM_SECURE = 44 +SM_CXEDGE = 45 +SM_CYEDGE = 46 +SM_CXMINSPACING = 47 +SM_CYMINSPACING = 48 +SM_CXSMICON = 49 +SM_CYSMICON = 50 +SM_CYSMCAPTION = 51 +SM_CXSMSIZE = 52 +SM_CYSMSIZE = 53 +SM_CXMENUSIZE = 54 +SM_CYMENUSIZE = 55 +SM_ARRANGE = 56 +SM_CXMINIMIZED = 57 +SM_CYMINIMIZED = 58 +SM_CXMAXTRACK = 59 +SM_CYMAXTRACK = 60 +SM_CXMAXIMIZED = 61 +SM_CYMAXIMIZED = 62 +SM_NETWORK = 63 +SM_CLEANBOOT = 67 +SM_CXDRAG = 68 +SM_CYDRAG = 69 +SM_SHOWSOUNDS = 70 +SM_CXMENUCHECK = 71 # Use instead of GetMenuCheckMarkDimensions()! +SM_CYMENUCHECK = 72 +SM_SLOWMACHINE = 73 +SM_MIDEASTENABLED = 74 +SM_MOUSEWHEELPRESENT = 75 +SM_XVIRTUALSCREEN = 76 +SM_YVIRTUALSCREEN = 77 +SM_CXVIRTUALSCREEN = 78 +SM_CYVIRTUALSCREEN = 79 +SM_CMONITORS = 80 +SM_SAMEDISPLAYFORMAT = 81 +SM_IMMENABLED = 82 +SM_CXFOCUSBORDER = 83 +SM_CYFOCUSBORDER = 84 +SM_TABLETPC = 86 +SM_MEDIACENTER = 87 +SM_STARTER = 88 +SM_SERVERR2 = 89 +SM_MOUSEHORIZONTALWHEELPRESENT = 91 +SM_CXPADDEDBORDER = 92 + +SM_CMETRICS = 93 + +SM_REMOTESESSION = 0x1000 +SM_SHUTTINGDOWN = 0x2000 +SM_REMOTECONTROL = 0x2001 +SM_CARETBLINKINGENABLED = 0x2002 + +#--- SYSTEM_INFO structure, GetSystemInfo() and GetNativeSystemInfo() --------- + +# Values used by Wine +# Documented values at MSDN are marked with an asterisk +PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF; # Unknown architecture. +PROCESSOR_ARCHITECTURE_INTEL = 0 # x86 (AMD or Intel) * +PROCESSOR_ARCHITECTURE_MIPS = 1 # MIPS +PROCESSOR_ARCHITECTURE_ALPHA = 2 # Alpha +PROCESSOR_ARCHITECTURE_PPC = 3 # Power PC +PROCESSOR_ARCHITECTURE_SHX = 4 # SHX +PROCESSOR_ARCHITECTURE_ARM = 5 # ARM +PROCESSOR_ARCHITECTURE_IA64 = 6 # Intel Itanium * +PROCESSOR_ARCHITECTURE_ALPHA64 = 7 # Alpha64 +PROCESSOR_ARCHITECTURE_MSIL = 8 # MSIL +PROCESSOR_ARCHITECTURE_AMD64 = 9 # x64 (AMD or Intel) * +PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10 # IA32 on Win64 +PROCESSOR_ARCHITECTURE_SPARC = 20 # Sparc (Wine) + +# Values used by Wine +# PROCESSOR_OPTIL value found at http://code.google.com/p/ddab-lib/ +# Documented values at MSDN are marked with an asterisk +PROCESSOR_INTEL_386 = 386 # Intel i386 * +PROCESSOR_INTEL_486 = 486 # Intel i486 * +PROCESSOR_INTEL_PENTIUM = 586 # Intel Pentium * +PROCESSOR_INTEL_IA64 = 2200 # Intel IA64 (Itanium) * +PROCESSOR_AMD_X8664 = 8664 # AMD X86 64 * +PROCESSOR_MIPS_R4000 = 4000 # MIPS R4000, R4101, R3910 +PROCESSOR_ALPHA_21064 = 21064 # Alpha 210 64 +PROCESSOR_PPC_601 = 601 # PPC 601 +PROCESSOR_PPC_603 = 603 # PPC 603 +PROCESSOR_PPC_604 = 604 # PPC 604 +PROCESSOR_PPC_620 = 620 # PPC 620 +PROCESSOR_HITACHI_SH3 = 10003 # Hitachi SH3 (Windows CE) +PROCESSOR_HITACHI_SH3E = 10004 # Hitachi SH3E (Windows CE) +PROCESSOR_HITACHI_SH4 = 10005 # Hitachi SH4 (Windows CE) +PROCESSOR_MOTOROLA_821 = 821 # Motorola 821 (Windows CE) +PROCESSOR_SHx_SH3 = 103 # SHx SH3 (Windows CE) +PROCESSOR_SHx_SH4 = 104 # SHx SH4 (Windows CE) +PROCESSOR_STRONGARM = 2577 # StrongARM (Windows CE) +PROCESSOR_ARM720 = 1824 # ARM 720 (Windows CE) +PROCESSOR_ARM820 = 2080 # ARM 820 (Windows CE) +PROCESSOR_ARM920 = 2336 # ARM 920 (Windows CE) +PROCESSOR_ARM_7TDMI = 70001 # ARM 7TDMI (Windows CE) +PROCESSOR_OPTIL = 0x494F # MSIL + +# typedef struct _SYSTEM_INFO { +# union { +# DWORD dwOemId; +# struct { +# WORD wProcessorArchitecture; +# WORD wReserved; +# } ; +# } ; +# DWORD dwPageSize; +# LPVOID lpMinimumApplicationAddress; +# LPVOID lpMaximumApplicationAddress; +# DWORD_PTR dwActiveProcessorMask; +# DWORD dwNumberOfProcessors; +# DWORD dwProcessorType; +# DWORD dwAllocationGranularity; +# WORD wProcessorLevel; +# WORD wProcessorRevision; +# } SYSTEM_INFO; + +class _SYSTEM_INFO_OEM_ID_STRUCT(Structure): + _fields_ = [ + ("wProcessorArchitecture", WORD), + ("wReserved", WORD), +] + +class _SYSTEM_INFO_OEM_ID(Union): + _fields_ = [ + ("dwOemId", DWORD), + ("w", _SYSTEM_INFO_OEM_ID_STRUCT), +] + +class SYSTEM_INFO(Structure): + _fields_ = [ + ("id", _SYSTEM_INFO_OEM_ID), + ("dwPageSize", DWORD), + ("lpMinimumApplicationAddress", LPVOID), + ("lpMaximumApplicationAddress", LPVOID), + ("dwActiveProcessorMask", DWORD_PTR), + ("dwNumberOfProcessors", DWORD), + ("dwProcessorType", DWORD), + ("dwAllocationGranularity", DWORD), + ("wProcessorLevel", WORD), + ("wProcessorRevision", WORD), + ] + + def __get_dwOemId(self): + return self.id.dwOemId + def __set_dwOemId(self, value): + self.id.dwOemId = value + dwOemId = property(__get_dwOemId, __set_dwOemId) + + def __get_wProcessorArchitecture(self): + return self.id.w.wProcessorArchitecture + def __set_wProcessorArchitecture(self, value): + self.id.w.wProcessorArchitecture = value + wProcessorArchitecture = property(__get_wProcessorArchitecture, __set_wProcessorArchitecture) + +LPSYSTEM_INFO = ctypes.POINTER(SYSTEM_INFO) + +# void WINAPI GetSystemInfo( +# __out LPSYSTEM_INFO lpSystemInfo +# ); +def GetSystemInfo(): + _GetSystemInfo = windll.kernel32.GetSystemInfo + _GetSystemInfo.argtypes = [LPSYSTEM_INFO] + _GetSystemInfo.restype = None + + sysinfo = SYSTEM_INFO() + _GetSystemInfo(byref(sysinfo)) + return sysinfo + +# void WINAPI GetNativeSystemInfo( +# __out LPSYSTEM_INFO lpSystemInfo +# ); +def GetNativeSystemInfo(): + _GetNativeSystemInfo = windll.kernel32.GetNativeSystemInfo + _GetNativeSystemInfo.argtypes = [LPSYSTEM_INFO] + _GetNativeSystemInfo.restype = None + + sysinfo = SYSTEM_INFO() + _GetNativeSystemInfo(byref(sysinfo)) + return sysinfo + +# int WINAPI GetSystemMetrics( +# __in int nIndex +# ); +def GetSystemMetrics(nIndex): + _GetSystemMetrics = windll.user32.GetSystemMetrics + _GetSystemMetrics.argtypes = [ctypes.c_int] + _GetSystemMetrics.restype = ctypes.c_int + return _GetSystemMetrics(nIndex) + +# SIZE_T WINAPI GetLargePageMinimum(void); +def GetLargePageMinimum(): + _GetLargePageMinimum = windll.user32.GetLargePageMinimum + _GetLargePageMinimum.argtypes = [] + _GetLargePageMinimum.restype = SIZE_T + return _GetLargePageMinimum() + +# HANDLE WINAPI GetCurrentProcess(void); +def GetCurrentProcess(): +## return 0xFFFFFFFFFFFFFFFFL + _GetCurrentProcess = windll.kernel32.GetCurrentProcess + _GetCurrentProcess.argtypes = [] + _GetCurrentProcess.restype = HANDLE + return _GetCurrentProcess() + +# HANDLE WINAPI GetCurrentThread(void); +def GetCurrentThread(): +## return 0xFFFFFFFFFFFFFFFEL + _GetCurrentThread = windll.kernel32.GetCurrentThread + _GetCurrentThread.argtypes = [] + _GetCurrentThread.restype = HANDLE + return _GetCurrentThread() + +# BOOL WINAPI IsWow64Process( +# __in HANDLE hProcess, +# __out PBOOL Wow64Process +# ); +def IsWow64Process(hProcess): + _IsWow64Process = windll.kernel32.IsWow64Process + _IsWow64Process.argtypes = [HANDLE, PBOOL] + _IsWow64Process.restype = bool + _IsWow64Process.errcheck = RaiseIfZero + + Wow64Process = BOOL(FALSE) + _IsWow64Process(hProcess, byref(Wow64Process)) + return bool(Wow64Process) + +# DWORD WINAPI GetVersion(void); +def GetVersion(): + _GetVersion = windll.kernel32.GetVersion + _GetVersion.argtypes = [] + _GetVersion.restype = DWORD + _GetVersion.errcheck = RaiseIfZero + + # See the example code here: + # http://msdn.microsoft.com/en-us/library/ms724439(VS.85).aspx + + dwVersion = _GetVersion() + dwMajorVersion = dwVersion & 0x000000FF + dwMinorVersion = (dwVersion & 0x0000FF00) >> 8 + if (dwVersion & 0x80000000) == 0: + dwBuild = (dwVersion & 0x7FFF0000) >> 16 + else: + dwBuild = None + return int(dwMajorVersion), int(dwMinorVersion), int(dwBuild) + +# BOOL WINAPI GetVersionEx( +# __inout LPOSVERSIONINFO lpVersionInfo +# ); +def GetVersionExA(): + _GetVersionExA = windll.kernel32.GetVersionExA + _GetVersionExA.argtypes = [POINTER(OSVERSIONINFOEXA)] + _GetVersionExA.restype = bool + _GetVersionExA.errcheck = RaiseIfZero + + osi = OSVERSIONINFOEXA() + osi.dwOSVersionInfoSize = sizeof(osi) + try: + _GetVersionExA(byref(osi)) + except WindowsError: + osi = OSVERSIONINFOA() + osi.dwOSVersionInfoSize = sizeof(osi) + _GetVersionExA.argtypes = [POINTER(OSVERSIONINFOA)] + _GetVersionExA(byref(osi)) + return osi + +def GetVersionExW(): + _GetVersionExW = windll.kernel32.GetVersionExW + _GetVersionExW.argtypes = [POINTER(OSVERSIONINFOEXW)] + _GetVersionExW.restype = bool + _GetVersionExW.errcheck = RaiseIfZero + + osi = OSVERSIONINFOEXW() + osi.dwOSVersionInfoSize = sizeof(osi) + try: + _GetVersionExW(byref(osi)) + except WindowsError: + osi = OSVERSIONINFOW() + osi.dwOSVersionInfoSize = sizeof(osi) + _GetVersionExW.argtypes = [POINTER(OSVERSIONINFOW)] + _GetVersionExW(byref(osi)) + return osi + +GetVersionEx = GuessStringType(GetVersionExA, GetVersionExW) + +# BOOL WINAPI GetProductInfo( +# __in DWORD dwOSMajorVersion, +# __in DWORD dwOSMinorVersion, +# __in DWORD dwSpMajorVersion, +# __in DWORD dwSpMinorVersion, +# __out PDWORD pdwReturnedProductType +# ); +def GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion): + _GetProductInfo = windll.kernel32.GetProductInfo + _GetProductInfo.argtypes = [DWORD, DWORD, DWORD, DWORD, PDWORD] + _GetProductInfo.restype = BOOL + _GetProductInfo.errcheck = RaiseIfZero + + dwReturnedProductType = DWORD(0) + _GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, byref(dwReturnedProductType)) + return dwReturnedProductType.value + +# BOOL WINAPI VerifyVersionInfo( +# __in LPOSVERSIONINFOEX lpVersionInfo, +# __in DWORD dwTypeMask, +# __in DWORDLONG dwlConditionMask +# ); +def VerifyVersionInfo(lpVersionInfo, dwTypeMask, dwlConditionMask): + if isinstance(lpVersionInfo, OSVERSIONINFOEXA): + return VerifyVersionInfoA(lpVersionInfo, dwTypeMask, dwlConditionMask) + if isinstance(lpVersionInfo, OSVERSIONINFOEXW): + return VerifyVersionInfoW(lpVersionInfo, dwTypeMask, dwlConditionMask) + raise TypeError("Bad OSVERSIONINFOEX structure") + +def VerifyVersionInfoA(lpVersionInfo, dwTypeMask, dwlConditionMask): + _VerifyVersionInfoA = windll.kernel32.VerifyVersionInfoA + _VerifyVersionInfoA.argtypes = [LPOSVERSIONINFOEXA, DWORD, DWORDLONG] + _VerifyVersionInfoA.restype = bool + return _VerifyVersionInfoA(byref(lpVersionInfo), dwTypeMask, dwlConditionMask) + +def VerifyVersionInfoW(lpVersionInfo, dwTypeMask, dwlConditionMask): + _VerifyVersionInfoW = windll.kernel32.VerifyVersionInfoW + _VerifyVersionInfoW.argtypes = [LPOSVERSIONINFOEXW, DWORD, DWORDLONG] + _VerifyVersionInfoW.restype = bool + return _VerifyVersionInfoW(byref(lpVersionInfo), dwTypeMask, dwlConditionMask) + +# ULONGLONG WINAPI VerSetConditionMask( +# __in ULONGLONG dwlConditionMask, +# __in DWORD dwTypeBitMask, +# __in BYTE dwConditionMask +# ); +def VerSetConditionMask(dwlConditionMask, dwTypeBitMask, dwConditionMask): + _VerSetConditionMask = windll.kernel32.VerSetConditionMask + _VerSetConditionMask.argtypes = [ULONGLONG, DWORD, BYTE] + _VerSetConditionMask.restype = ULONGLONG + return _VerSetConditionMask(dwlConditionMask, dwTypeBitMask, dwConditionMask) + +#--- get_bits, get_arch and get_os -------------------------------------------- + +ARCH_UNKNOWN = "unknown" +ARCH_I386 = "i386" +ARCH_MIPS = "mips" +ARCH_ALPHA = "alpha" +ARCH_PPC = "ppc" +ARCH_SHX = "shx" +ARCH_ARM = "arm" +ARCH_ARM64 = "arm64" +ARCH_THUMB = "thumb" +ARCH_IA64 = "ia64" +ARCH_ALPHA64 = "alpha64" +ARCH_MSIL = "msil" +ARCH_AMD64 = "amd64" +ARCH_SPARC = "sparc" + +# aliases +ARCH_IA32 = ARCH_I386 +ARCH_X86 = ARCH_I386 +ARCH_X64 = ARCH_AMD64 +ARCH_ARM7 = ARCH_ARM +ARCH_ARM8 = ARCH_ARM64 +ARCH_T32 = ARCH_THUMB +ARCH_AARCH32 = ARCH_ARM7 +ARCH_AARCH64 = ARCH_ARM8 +ARCH_POWERPC = ARCH_PPC +ARCH_HITACHI = ARCH_SHX +ARCH_ITANIUM = ARCH_IA64 + +# win32 constants -> our constants +_arch_map = { + PROCESSOR_ARCHITECTURE_INTEL : ARCH_I386, + PROCESSOR_ARCHITECTURE_MIPS : ARCH_MIPS, + PROCESSOR_ARCHITECTURE_ALPHA : ARCH_ALPHA, + PROCESSOR_ARCHITECTURE_PPC : ARCH_PPC, + PROCESSOR_ARCHITECTURE_SHX : ARCH_SHX, + PROCESSOR_ARCHITECTURE_ARM : ARCH_ARM, + PROCESSOR_ARCHITECTURE_IA64 : ARCH_IA64, + PROCESSOR_ARCHITECTURE_ALPHA64 : ARCH_ALPHA64, + PROCESSOR_ARCHITECTURE_MSIL : ARCH_MSIL, + PROCESSOR_ARCHITECTURE_AMD64 : ARCH_AMD64, + PROCESSOR_ARCHITECTURE_SPARC : ARCH_SPARC, +} + +OS_UNKNOWN = "Unknown" +OS_NT = "Windows NT" +OS_W2K = "Windows 2000" +OS_XP = "Windows XP" +OS_XP_64 = "Windows XP (64 bits)" +OS_W2K3 = "Windows 2003" +OS_W2K3_64 = "Windows 2003 (64 bits)" +OS_W2K3R2 = "Windows 2003 R2" +OS_W2K3R2_64 = "Windows 2003 R2 (64 bits)" +OS_W2K8 = "Windows 2008" +OS_W2K8_64 = "Windows 2008 (64 bits)" +OS_W2K8R2 = "Windows 2008 R2" +OS_W2K8R2_64 = "Windows 2008 R2 (64 bits)" +OS_VISTA = "Windows Vista" +OS_VISTA_64 = "Windows Vista (64 bits)" +OS_W7 = "Windows 7" +OS_W7_64 = "Windows 7 (64 bits)" + +OS_SEVEN = OS_W7 +OS_SEVEN_64 = OS_W7_64 + +OS_WINDOWS_NT = OS_NT +OS_WINDOWS_2000 = OS_W2K +OS_WINDOWS_XP = OS_XP +OS_WINDOWS_XP_64 = OS_XP_64 +OS_WINDOWS_2003 = OS_W2K3 +OS_WINDOWS_2003_64 = OS_W2K3_64 +OS_WINDOWS_2003_R2 = OS_W2K3R2 +OS_WINDOWS_2003_R2_64 = OS_W2K3R2_64 +OS_WINDOWS_2008 = OS_W2K8 +OS_WINDOWS_2008_64 = OS_W2K8_64 +OS_WINDOWS_2008_R2 = OS_W2K8R2 +OS_WINDOWS_2008_R2_64 = OS_W2K8R2_64 +OS_WINDOWS_VISTA = OS_VISTA +OS_WINDOWS_VISTA_64 = OS_VISTA_64 +OS_WINDOWS_SEVEN = OS_W7 +OS_WINDOWS_SEVEN_64 = OS_W7_64 + +def _get_bits(): + """ + Determines the current integer size in bits. + + This is useful to know if we're running in a 32 bits or a 64 bits machine. + + @rtype: int + @return: Returns the size of L{SIZE_T} in bits. + """ + return sizeof(SIZE_T) * 8 + +def _get_arch(): + """ + Determines the current processor architecture. + + @rtype: str + @return: + On error, returns: + + - L{ARCH_UNKNOWN} (C{"unknown"}) meaning the architecture could not be detected or is not known to WinAppDbg. + + On success, returns one of the following values: + + - L{ARCH_I386} (C{"i386"}) for Intel 32-bit x86 processor or compatible. + - L{ARCH_AMD64} (C{"amd64"}) for Intel 64-bit x86_64 processor or compatible. + + May also return one of the following values if you get both Python and + WinAppDbg to work in such machines... let me know if you do! :) + + - L{ARCH_MIPS} (C{"mips"}) for MIPS compatible processors. + - L{ARCH_ALPHA} (C{"alpha"}) for Alpha processors. + - L{ARCH_PPC} (C{"ppc"}) for PowerPC compatible processors. + - L{ARCH_SHX} (C{"shx"}) for Hitachi SH processors. + - L{ARCH_ARM} (C{"arm"}) for ARM compatible processors. + - L{ARCH_IA64} (C{"ia64"}) for Intel Itanium processor or compatible. + - L{ARCH_ALPHA64} (C{"alpha64"}) for Alpha64 processors. + - L{ARCH_MSIL} (C{"msil"}) for the .NET virtual machine. + - L{ARCH_SPARC} (C{"sparc"}) for Sun Sparc processors. + + Probably IronPython returns C{ARCH_MSIL} but I haven't tried it. Python + on Windows CE and Windows Mobile should return C{ARCH_ARM}. Python on + Solaris using Wine would return C{ARCH_SPARC}. Python in an Itanium + machine should return C{ARCH_IA64} both on Wine and proper Windows. + All other values should only be returned on Linux using Wine. + """ + try: + si = GetNativeSystemInfo() + except Exception: + si = GetSystemInfo() + try: + return _arch_map[si.id.w.wProcessorArchitecture] + except KeyError: + return ARCH_UNKNOWN + +def _get_wow64(): + """ + Determines if the current process is running in Windows-On-Windows 64 bits. + + @rtype: bool + @return: C{True} of the current process is a 32 bit program running in a + 64 bit version of Windows, C{False} if it's either a 32 bit program + in a 32 bit Windows or a 64 bit program in a 64 bit Windows. + """ + # Try to determine if the debugger itself is running on WOW64. + # On error assume False. + if bits == 64: + wow64 = False + else: + try: + wow64 = IsWow64Process( GetCurrentProcess() ) + except Exception: + wow64 = False + return wow64 + +def _get_os(osvi = None): + """ + Determines the current operating system. + + This function allows you to quickly tell apart major OS differences. + For more detailed information call L{GetVersionEx} instead. + + @note: + Wine reports itself as Windows XP 32 bits + (even if the Linux host is 64 bits). + ReactOS may report itself as Windows 2000 or Windows XP, + depending on the version of ReactOS. + + @type osvi: L{OSVERSIONINFOEXA} + @param osvi: Optional. The return value from L{GetVersionEx}. + + @rtype: str + @return: + One of the following values: + - L{OS_UNKNOWN} (C{"Unknown"}) + - L{OS_NT} (C{"Windows NT"}) + - L{OS_W2K} (C{"Windows 2000"}) + - L{OS_XP} (C{"Windows XP"}) + - L{OS_XP_64} (C{"Windows XP (64 bits)"}) + - L{OS_W2K3} (C{"Windows 2003"}) + - L{OS_W2K3_64} (C{"Windows 2003 (64 bits)"}) + - L{OS_W2K3R2} (C{"Windows 2003 R2"}) + - L{OS_W2K3R2_64} (C{"Windows 2003 R2 (64 bits)"}) + - L{OS_W2K8} (C{"Windows 2008"}) + - L{OS_W2K8_64} (C{"Windows 2008 (64 bits)"}) + - L{OS_W2K8R2} (C{"Windows 2008 R2"}) + - L{OS_W2K8R2_64} (C{"Windows 2008 R2 (64 bits)"}) + - L{OS_VISTA} (C{"Windows Vista"}) + - L{OS_VISTA_64} (C{"Windows Vista (64 bits)"}) + - L{OS_W7} (C{"Windows 7"}) + - L{OS_W7_64} (C{"Windows 7 (64 bits)"}) + """ + # rough port of http://msdn.microsoft.com/en-us/library/ms724429%28VS.85%29.aspx + if not osvi: + osvi = GetVersionEx() + if osvi.dwPlatformId == VER_PLATFORM_WIN32_NT and osvi.dwMajorVersion > 4: + if osvi.dwMajorVersion == 6: + if osvi.dwMinorVersion == 0: + if osvi.wProductType == VER_NT_WORKSTATION: + if bits == 64 or wow64: + return 'Windows Vista (64 bits)' + return 'Windows Vista' + else: + if bits == 64 or wow64: + return 'Windows 2008 (64 bits)' + return 'Windows 2008' + if osvi.dwMinorVersion == 1: + if osvi.wProductType == VER_NT_WORKSTATION: + if bits == 64 or wow64: + return 'Windows 7 (64 bits)' + return 'Windows 7' + else: + if bits == 64 or wow64: + return 'Windows 2008 R2 (64 bits)' + return 'Windows 2008 R2' + if osvi.dwMajorVersion == 5: + if osvi.dwMinorVersion == 2: + if GetSystemMetrics(SM_SERVERR2): + if bits == 64 or wow64: + return 'Windows 2003 R2 (64 bits)' + return 'Windows 2003 R2' + if osvi.wSuiteMask in (VER_SUITE_STORAGE_SERVER, VER_SUITE_WH_SERVER): + if bits == 64 or wow64: + return 'Windows 2003 (64 bits)' + return 'Windows 2003' + if osvi.wProductType == VER_NT_WORKSTATION and arch == ARCH_AMD64: + return 'Windows XP (64 bits)' + else: + if bits == 64 or wow64: + return 'Windows 2003 (64 bits)' + return 'Windows 2003' + if osvi.dwMinorVersion == 1: + return 'Windows XP' + if osvi.dwMinorVersion == 0: + return 'Windows 2000' + if osvi.dwMajorVersion == 4: + return 'Windows NT' + return 'Unknown' + +def _get_ntddi(osvi): + """ + Determines the current operating system. + + This function allows you to quickly tell apart major OS differences. + For more detailed information call L{kernel32.GetVersionEx} instead. + + @note: + Wine reports itself as Windows XP 32 bits + (even if the Linux host is 64 bits). + ReactOS may report itself as Windows 2000 or Windows XP, + depending on the version of ReactOS. + + @type osvi: L{OSVERSIONINFOEXA} + @param osvi: Optional. The return value from L{kernel32.GetVersionEx}. + + @rtype: int + @return: NTDDI version number. + """ + if not osvi: + osvi = GetVersionEx() + ntddi = 0 + ntddi += (osvi.dwMajorVersion & 0xFF) << 24 + ntddi += (osvi.dwMinorVersion & 0xFF) << 16 + ntddi += (osvi.wServicePackMajor & 0xFF) << 8 + ntddi += (osvi.wServicePackMinor & 0xFF) + return ntddi + +# The order of the following definitions DOES matter! + +# Current integer size in bits. See L{_get_bits} for more details. +bits = _get_bits() + +# Current processor architecture. See L{_get_arch} for more details. +arch = _get_arch() + +# Set to C{True} if the current process is running in WOW64. See L{_get_wow64} for more details. +wow64 = _get_wow64() + +_osvi = GetVersionEx() + +# Current operating system. See L{_get_os} for more details. +os = _get_os(_osvi) + +# Current operating system as an NTDDI constant. See L{_get_ntddi} for more details. +NTDDI_VERSION = _get_ntddi(_osvi) + +# Upper word of L{NTDDI_VERSION}, contains the OS major and minor version number. +WINVER = NTDDI_VERSION >> 16 + +#--- version.dll -------------------------------------------------------------- + +VS_FF_DEBUG = 0x00000001 +VS_FF_PRERELEASE = 0x00000002 +VS_FF_PATCHED = 0x00000004 +VS_FF_PRIVATEBUILD = 0x00000008 +VS_FF_INFOINFERRED = 0x00000010 +VS_FF_SPECIALBUILD = 0x00000020 + +VOS_UNKNOWN = 0x00000000 +VOS__WINDOWS16 = 0x00000001 +VOS__PM16 = 0x00000002 +VOS__PM32 = 0x00000003 +VOS__WINDOWS32 = 0x00000004 +VOS_DOS = 0x00010000 +VOS_OS216 = 0x00020000 +VOS_OS232 = 0x00030000 +VOS_NT = 0x00040000 + +VOS_DOS_WINDOWS16 = 0x00010001 +VOS_DOS_WINDOWS32 = 0x00010004 +VOS_NT_WINDOWS32 = 0x00040004 +VOS_OS216_PM16 = 0x00020002 +VOS_OS232_PM32 = 0x00030003 + +VFT_UNKNOWN = 0x00000000 +VFT_APP = 0x00000001 +VFT_DLL = 0x00000002 +VFT_DRV = 0x00000003 +VFT_FONT = 0x00000004 +VFT_VXD = 0x00000005 +VFT_RESERVED = 0x00000006 # undocumented +VFT_STATIC_LIB = 0x00000007 + +VFT2_UNKNOWN = 0x00000000 + +VFT2_DRV_PRINTER = 0x00000001 +VFT2_DRV_KEYBOARD = 0x00000002 +VFT2_DRV_LANGUAGE = 0x00000003 +VFT2_DRV_DISPLAY = 0x00000004 +VFT2_DRV_MOUSE = 0x00000005 +VFT2_DRV_NETWORK = 0x00000006 +VFT2_DRV_SYSTEM = 0x00000007 +VFT2_DRV_INSTALLABLE = 0x00000008 +VFT2_DRV_SOUND = 0x00000009 +VFT2_DRV_COMM = 0x0000000A +VFT2_DRV_RESERVED = 0x0000000B # undocumented +VFT2_DRV_VERSIONED_PRINTER = 0x0000000C + +VFT2_FONT_RASTER = 0x00000001 +VFT2_FONT_VECTOR = 0x00000002 +VFT2_FONT_TRUETYPE = 0x00000003 + +# typedef struct tagVS_FIXEDFILEINFO { +# DWORD dwSignature; +# DWORD dwStrucVersion; +# DWORD dwFileVersionMS; +# DWORD dwFileVersionLS; +# DWORD dwProductVersionMS; +# DWORD dwProductVersionLS; +# DWORD dwFileFlagsMask; +# DWORD dwFileFlags; +# DWORD dwFileOS; +# DWORD dwFileType; +# DWORD dwFileSubtype; +# DWORD dwFileDateMS; +# DWORD dwFileDateLS; +# } VS_FIXEDFILEINFO; +class VS_FIXEDFILEINFO(Structure): + _fields_ = [ + ("dwSignature", DWORD), + ("dwStrucVersion", DWORD), + ("dwFileVersionMS", DWORD), + ("dwFileVersionLS", DWORD), + ("dwProductVersionMS", DWORD), + ("dwProductVersionLS", DWORD), + ("dwFileFlagsMask", DWORD), + ("dwFileFlags", DWORD), + ("dwFileOS", DWORD), + ("dwFileType", DWORD), + ("dwFileSubtype", DWORD), + ("dwFileDateMS", DWORD), + ("dwFileDateLS", DWORD), +] +PVS_FIXEDFILEINFO = POINTER(VS_FIXEDFILEINFO) +LPVS_FIXEDFILEINFO = PVS_FIXEDFILEINFO + +# BOOL WINAPI GetFileVersionInfo( +# _In_ LPCTSTR lptstrFilename, +# _Reserved_ DWORD dwHandle, +# _In_ DWORD dwLen, +# _Out_ LPVOID lpData +# ); +# DWORD WINAPI GetFileVersionInfoSize( +# _In_ LPCTSTR lptstrFilename, +# _Out_opt_ LPDWORD lpdwHandle +# ); +def GetFileVersionInfoA(lptstrFilename): + _GetFileVersionInfoA = windll.version.GetFileVersionInfoA + _GetFileVersionInfoA.argtypes = [LPSTR, DWORD, DWORD, LPVOID] + _GetFileVersionInfoA.restype = bool + _GetFileVersionInfoA.errcheck = RaiseIfZero + + _GetFileVersionInfoSizeA = windll.version.GetFileVersionInfoSizeA + _GetFileVersionInfoSizeA.argtypes = [LPSTR, LPVOID] + _GetFileVersionInfoSizeA.restype = DWORD + _GetFileVersionInfoSizeA.errcheck = RaiseIfZero + + dwLen = _GetFileVersionInfoSizeA(lptstrFilename, None) + lpData = ctypes.create_string_buffer(dwLen) + _GetFileVersionInfoA(lptstrFilename, 0, dwLen, byref(lpData)) + return lpData + +def GetFileVersionInfoW(lptstrFilename): + _GetFileVersionInfoW = windll.version.GetFileVersionInfoW + _GetFileVersionInfoW.argtypes = [LPWSTR, DWORD, DWORD, LPVOID] + _GetFileVersionInfoW.restype = bool + _GetFileVersionInfoW.errcheck = RaiseIfZero + + _GetFileVersionInfoSizeW = windll.version.GetFileVersionInfoSizeW + _GetFileVersionInfoSizeW.argtypes = [LPWSTR, LPVOID] + _GetFileVersionInfoSizeW.restype = DWORD + _GetFileVersionInfoSizeW.errcheck = RaiseIfZero + + dwLen = _GetFileVersionInfoSizeW(lptstrFilename, None) + lpData = ctypes.create_string_buffer(dwLen) # not a string! + _GetFileVersionInfoW(lptstrFilename, 0, dwLen, byref(lpData)) + return lpData + +GetFileVersionInfo = GuessStringType(GetFileVersionInfoA, GetFileVersionInfoW) + +# BOOL WINAPI VerQueryValue( +# _In_ LPCVOID pBlock, +# _In_ LPCTSTR lpSubBlock, +# _Out_ LPVOID *lplpBuffer, +# _Out_ PUINT puLen +# ); +def VerQueryValueA(pBlock, lpSubBlock): + _VerQueryValueA = windll.version.VerQueryValueA + _VerQueryValueA.argtypes = [LPVOID, LPSTR, LPVOID, POINTER(UINT)] + _VerQueryValueA.restype = bool + _VerQueryValueA.errcheck = RaiseIfZero + + lpBuffer = LPVOID(0) + uLen = UINT(0) + _VerQueryValueA(pBlock, lpSubBlock, byref(lpBuffer), byref(uLen)) + return lpBuffer, uLen.value + +def VerQueryValueW(pBlock, lpSubBlock): + _VerQueryValueW = windll.version.VerQueryValueW + _VerQueryValueW.argtypes = [LPVOID, LPWSTR, LPVOID, POINTER(UINT)] + _VerQueryValueW.restype = bool + _VerQueryValueW.errcheck = RaiseIfZero + + lpBuffer = LPVOID(0) + uLen = UINT(0) + _VerQueryValueW(pBlock, lpSubBlock, byref(lpBuffer), byref(uLen)) + return lpBuffer, uLen.value + +VerQueryValue = GuessStringType(VerQueryValueA, VerQueryValueW) + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/wtsapi32.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/wtsapi32.py new file mode 100644 index 0000000..13227db --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/wtsapi32.py @@ -0,0 +1,337 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Wrapper for wtsapi32.dll in ctypes. +""" + +__revision__ = "$Id$" + +from winappdbg.win32.defines import * +from winappdbg.win32.advapi32 import * + +#============================================================================== +# This is used later on to calculate the list of exported symbols. +_all = None +_all = set(vars().keys()) +#============================================================================== + +#--- Constants ---------------------------------------------------------------- + +WTS_CURRENT_SERVER_HANDLE = 0 +WTS_CURRENT_SESSION = 1 + +#--- WTS_PROCESS_INFO structure ----------------------------------------------- + +# typedef struct _WTS_PROCESS_INFO { +# DWORD SessionId; +# DWORD ProcessId; +# LPTSTR pProcessName; +# PSID pUserSid; +# } WTS_PROCESS_INFO, *PWTS_PROCESS_INFO; + +class WTS_PROCESS_INFOA(Structure): + _fields_ = [ + ("SessionId", DWORD), + ("ProcessId", DWORD), + ("pProcessName", LPSTR), + ("pUserSid", PSID), + ] +PWTS_PROCESS_INFOA = POINTER(WTS_PROCESS_INFOA) + +class WTS_PROCESS_INFOW(Structure): + _fields_ = [ + ("SessionId", DWORD), + ("ProcessId", DWORD), + ("pProcessName", LPWSTR), + ("pUserSid", PSID), + ] +PWTS_PROCESS_INFOW = POINTER(WTS_PROCESS_INFOW) + +#--- WTSQuerySessionInformation enums and structures -------------------------- + +# typedef enum _WTS_INFO_CLASS { +# WTSInitialProgram = 0, +# WTSApplicationName = 1, +# WTSWorkingDirectory = 2, +# WTSOEMId = 3, +# WTSSessionId = 4, +# WTSUserName = 5, +# WTSWinStationName = 6, +# WTSDomainName = 7, +# WTSConnectState = 8, +# WTSClientBuildNumber = 9, +# WTSClientName = 10, +# WTSClientDirectory = 11, +# WTSClientProductId = 12, +# WTSClientHardwareId = 13, +# WTSClientAddress = 14, +# WTSClientDisplay = 15, +# WTSClientProtocolType = 16, +# WTSIdleTime = 17, +# WTSLogonTime = 18, +# WTSIncomingBytes = 19, +# WTSOutgoingBytes = 20, +# WTSIncomingFrames = 21, +# WTSOutgoingFrames = 22, +# WTSClientInfo = 23, +# WTSSessionInfo = 24, +# WTSSessionInfoEx = 25, +# WTSConfigInfo = 26, +# WTSValidationInfo = 27, +# WTSSessionAddressV4 = 28, +# WTSIsRemoteSession = 29 +# } WTS_INFO_CLASS; + +WTSInitialProgram = 0 +WTSApplicationName = 1 +WTSWorkingDirectory = 2 +WTSOEMId = 3 +WTSSessionId = 4 +WTSUserName = 5 +WTSWinStationName = 6 +WTSDomainName = 7 +WTSConnectState = 8 +WTSClientBuildNumber = 9 +WTSClientName = 10 +WTSClientDirectory = 11 +WTSClientProductId = 12 +WTSClientHardwareId = 13 +WTSClientAddress = 14 +WTSClientDisplay = 15 +WTSClientProtocolType = 16 +WTSIdleTime = 17 +WTSLogonTime = 18 +WTSIncomingBytes = 19 +WTSOutgoingBytes = 20 +WTSIncomingFrames = 21 +WTSOutgoingFrames = 22 +WTSClientInfo = 23 +WTSSessionInfo = 24 +WTSSessionInfoEx = 25 +WTSConfigInfo = 26 +WTSValidationInfo = 27 +WTSSessionAddressV4 = 28 +WTSIsRemoteSession = 29 + +WTS_INFO_CLASS = ctypes.c_int + +# typedef enum _WTS_CONNECTSTATE_CLASS { +# WTSActive, +# WTSConnected, +# WTSConnectQuery, +# WTSShadow, +# WTSDisconnected, +# WTSIdle, +# WTSListen, +# WTSReset, +# WTSDown, +# WTSInit +# } WTS_CONNECTSTATE_CLASS; + +WTSActive = 0 +WTSConnected = 1 +WTSConnectQuery = 2 +WTSShadow = 3 +WTSDisconnected = 4 +WTSIdle = 5 +WTSListen = 6 +WTSReset = 7 +WTSDown = 8 +WTSInit = 9 + +WTS_CONNECTSTATE_CLASS = ctypes.c_int + +# typedef struct _WTS_CLIENT_DISPLAY { +# DWORD HorizontalResolution; +# DWORD VerticalResolution; +# DWORD ColorDepth; +# } WTS_CLIENT_DISPLAY, *PWTS_CLIENT_DISPLAY; +class WTS_CLIENT_DISPLAY(Structure): + _fields_ = [ + ("HorizontalResolution", DWORD), + ("VerticalResolution", DWORD), + ("ColorDepth", DWORD), + ] +PWTS_CLIENT_DISPLAY = POINTER(WTS_CLIENT_DISPLAY) + +# typedef struct _WTS_CLIENT_ADDRESS { +# DWORD AddressFamily; +# BYTE Address[20]; +# } WTS_CLIENT_ADDRESS, *PWTS_CLIENT_ADDRESS; + +# XXX TODO + +# typedef struct _WTSCLIENT { +# WCHAR ClientName[CLIENTNAME_LENGTH + 1]; +# WCHAR Domain[DOMAIN_LENGTH + 1 ]; +# WCHAR UserName[USERNAME_LENGTH + 1]; +# WCHAR WorkDirectory[MAX_PATH + 1]; +# WCHAR InitialProgram[MAX_PATH + 1]; +# BYTE EncryptionLevel; +# ULONG ClientAddressFamily; +# USHORT ClientAddress[CLIENTADDRESS_LENGTH + 1]; +# USHORT HRes; +# USHORT VRes; +# USHORT ColorDepth; +# WCHAR ClientDirectory[MAX_PATH + 1]; +# ULONG ClientBuildNumber; +# ULONG ClientHardwareId; +# USHORT ClientProductId; +# USHORT OutBufCountHost; +# USHORT OutBufCountClient; +# USHORT OutBufLength; +# WCHAR DeviceId[MAX_PATH + 1]; +# } WTSCLIENT, *PWTSCLIENT; + +# XXX TODO + +# typedef struct _WTSINFO { +# WTS_CONNECTSTATE_CLASS State; +# DWORD SessionId; +# DWORD IncomingBytes; +# DWORD OutgoingBytes; +# DWORD IncomingCompressedBytes; +# DWORD OutgoingCompressedBytes; +# WCHAR WinStationName; +# WCHAR Domain; +# WCHAR UserName; +# LARGE_INTEGER ConnectTime; +# LARGE_INTEGER DisconnectTime; +# LARGE_INTEGER LastInputTime; +# LARGE_INTEGER LogonTime; +# LARGE_INTEGER CurrentTime; +# } WTSINFO, *PWTSINFO; + +# XXX TODO + +# typedef struct _WTSINFOEX { +# DWORD Level; +# WTSINFOEX_LEVEL Data; +# } WTSINFOEX, *PWTSINFOEX; + +# XXX TODO + +#--- wtsapi32.dll ------------------------------------------------------------- + +# void WTSFreeMemory( +# __in PVOID pMemory +# ); +def WTSFreeMemory(pMemory): + _WTSFreeMemory = windll.wtsapi32.WTSFreeMemory + _WTSFreeMemory.argtypes = [PVOID] + _WTSFreeMemory.restype = None + _WTSFreeMemory(pMemory) + +# BOOL WTSEnumerateProcesses( +# __in HANDLE hServer, +# __in DWORD Reserved, +# __in DWORD Version, +# __out PWTS_PROCESS_INFO *ppProcessInfo, +# __out DWORD *pCount +# ); +def WTSEnumerateProcessesA(hServer = WTS_CURRENT_SERVER_HANDLE): + _WTSEnumerateProcessesA = windll.wtsapi32.WTSEnumerateProcessesA + _WTSEnumerateProcessesA.argtypes = [HANDLE, DWORD, DWORD, POINTER(PWTS_PROCESS_INFOA), PDWORD] + _WTSEnumerateProcessesA.restype = bool + _WTSEnumerateProcessesA.errcheck = RaiseIfZero + + pProcessInfo = PWTS_PROCESS_INFOA() + Count = DWORD(0) + _WTSEnumerateProcessesA(hServer, 0, 1, byref(pProcessInfo), byref(Count)) + return pProcessInfo, Count.value + +def WTSEnumerateProcessesW(hServer = WTS_CURRENT_SERVER_HANDLE): + _WTSEnumerateProcessesW = windll.wtsapi32.WTSEnumerateProcessesW + _WTSEnumerateProcessesW.argtypes = [HANDLE, DWORD, DWORD, POINTER(PWTS_PROCESS_INFOW), PDWORD] + _WTSEnumerateProcessesW.restype = bool + _WTSEnumerateProcessesW.errcheck = RaiseIfZero + + pProcessInfo = PWTS_PROCESS_INFOW() + Count = DWORD(0) + _WTSEnumerateProcessesW(hServer, 0, 1, byref(pProcessInfo), byref(Count)) + return pProcessInfo, Count.value + +WTSEnumerateProcesses = DefaultStringType(WTSEnumerateProcessesA, WTSEnumerateProcessesW) + +# BOOL WTSTerminateProcess( +# __in HANDLE hServer, +# __in DWORD ProcessId, +# __in DWORD ExitCode +# ); +def WTSTerminateProcess(hServer, ProcessId, ExitCode): + _WTSTerminateProcess = windll.wtsapi32.WTSTerminateProcess + _WTSTerminateProcess.argtypes = [HANDLE, DWORD, DWORD] + _WTSTerminateProcess.restype = bool + _WTSTerminateProcess.errcheck = RaiseIfZero + _WTSTerminateProcess(hServer, ProcessId, ExitCode) + +# BOOL WTSQuerySessionInformation( +# __in HANDLE hServer, +# __in DWORD SessionId, +# __in WTS_INFO_CLASS WTSInfoClass, +# __out LPTSTR *ppBuffer, +# __out DWORD *pBytesReturned +# ); + +# XXX TODO + +#--- kernel32.dll ------------------------------------------------------------- + +# I've no idea why these functions are in kernel32.dll instead of wtsapi32.dll + +# BOOL ProcessIdToSessionId( +# __in DWORD dwProcessId, +# __out DWORD *pSessionId +# ); +def ProcessIdToSessionId(dwProcessId): + _ProcessIdToSessionId = windll.kernel32.ProcessIdToSessionId + _ProcessIdToSessionId.argtypes = [DWORD, PDWORD] + _ProcessIdToSessionId.restype = bool + _ProcessIdToSessionId.errcheck = RaiseIfZero + + dwSessionId = DWORD(0) + _ProcessIdToSessionId(dwProcessId, byref(dwSessionId)) + return dwSessionId.value + +# DWORD WTSGetActiveConsoleSessionId(void); +def WTSGetActiveConsoleSessionId(): + _WTSGetActiveConsoleSessionId = windll.kernel32.WTSGetActiveConsoleSessionId + _WTSGetActiveConsoleSessionId.argtypes = [] + _WTSGetActiveConsoleSessionId.restype = DWORD + _WTSGetActiveConsoleSessionId.errcheck = RaiseIfZero + return _WTSGetActiveConsoleSessionId() + +#============================================================================== +# This calculates the list of exported symbols. +_all = set(vars().keys()).difference(_all) +__all__ = [_x for _x in _all if not _x.startswith('_')] +__all__.sort() +#============================================================================== diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/window.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/window.py new file mode 100644 index 0000000..6e865e7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/window.py @@ -0,0 +1,759 @@ +#!~/.wine/drive_c/Python25/python.exe +# -*- coding: utf-8 -*- + +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +""" +Window instrumentation. + +@group Instrumentation: + Window +""" + +__revision__ = "$Id$" + +__all__ = ['Window'] + +from winappdbg import win32 + +# delayed imports +Process = None +Thread = None + +#============================================================================== + +# Unlike Process, Thread and Module, there's no container for Window objects. +# That's because Window objects don't really store any data besides the handle. + +# XXX TODO +# * implement sending fake user input (mouse and keyboard messages) +# * maybe implement low-level hooks? (they don't require a dll to be injected) + +# XXX TODO +# +# Will it be possible to implement window hooks too? That requires a DLL to be +# injected in the target process. Perhaps with CPython it could be done easier, +# compiling a native extension is the safe bet, but both require having a non +# pure Python module, which is something I was trying to avoid so far. +# +# Another possibility would be to malloc some CC's in the target process and +# point the hook callback to it. We'd need to have the remote procedure call +# feature first as (I believe) the hook can't be set remotely in this case. + +class Window (object): + """ + Interface to an open window in the current desktop. + + @group Properties: + get_handle, get_pid, get_tid, + get_process, get_thread, + set_process, set_thread, + get_classname, get_style, get_extended_style, + get_text, set_text, + get_placement, set_placement, + get_screen_rect, get_client_rect, + screen_to_client, client_to_screen + + @group State: + is_valid, is_visible, is_enabled, is_maximized, is_minimized, is_child, + is_zoomed, is_iconic + + @group Navigation: + get_parent, get_children, get_root, get_tree, + get_child_at + + @group Instrumentation: + enable, disable, show, hide, maximize, minimize, restore, move, kill + + @group Low-level access: + send, post + + @type hWnd: int + @ivar hWnd: Window handle. + + @type dwProcessId: int + @ivar dwProcessId: Global ID of the process that owns this window. + + @type dwThreadId: int + @ivar dwThreadId: Global ID of the thread that owns this window. + + @type process: L{Process} + @ivar process: Process that owns this window. + Use the L{get_process} method instead. + + @type thread: L{Thread} + @ivar thread: Thread that owns this window. + Use the L{get_thread} method instead. + + @type classname: str + @ivar classname: Window class name. + + @type text: str + @ivar text: Window text (caption). + + @type placement: L{win32.WindowPlacement} + @ivar placement: Window placement in the desktop. + """ + + def __init__(self, hWnd = None, process = None, thread = None): + """ + @type hWnd: int or L{win32.HWND} + @param hWnd: Window handle. + + @type process: L{Process} + @param process: (Optional) Process that owns this window. + + @type thread: L{Thread} + @param thread: (Optional) Thread that owns this window. + """ + self.hWnd = hWnd + self.dwProcessId = None + self.dwThreadId = None + self.set_process(process) + self.set_thread(thread) + + @property + def _as_parameter_(self): + """ + Compatibility with ctypes. + Allows passing transparently a Window object to an API call. + """ + return self.get_handle() + + def get_handle(self): + """ + @rtype: int + @return: Window handle. + @raise ValueError: No window handle set. + """ + if self.hWnd is None: + raise ValueError("No window handle set!") + return self.hWnd + + def get_pid(self): + """ + @rtype: int + @return: Global ID of the process that owns this window. + """ + if self.dwProcessId is not None: + return self.dwProcessId + self.__get_pid_and_tid() + return self.dwProcessId + + def get_tid(self): + """ + @rtype: int + @return: Global ID of the thread that owns this window. + """ + if self.dwThreadId is not None: + return self.dwThreadId + self.__get_pid_and_tid() + return self.dwThreadId + + def __get_pid_and_tid(self): + "Internally used by get_pid() and get_tid()." + self.dwThreadId, self.dwProcessId = \ + win32.GetWindowThreadProcessId(self.get_handle()) + + def __load_Process_class(self): + global Process # delayed import + if Process is None: + from winappdbg.process import Process + + def __load_Thread_class(self): + global Thread # delayed import + if Thread is None: + from winappdbg.thread import Thread + + def get_process(self): + """ + @rtype: L{Process} + @return: Parent Process object. + """ + if self.__process is not None: + return self.__process + self.__load_Process_class() + self.__process = Process(self.get_pid()) + return self.__process + + def set_process(self, process = None): + """ + Manually set the parent process. Use with care! + + @type process: L{Process} + @param process: (Optional) Process object. Use C{None} to autodetect. + """ + if process is None: + self.__process = None + else: + self.__load_Process_class() + if not isinstance(process, Process): + msg = "Parent process must be a Process instance, " + msg += "got %s instead" % type(process) + raise TypeError(msg) + self.dwProcessId = process.get_pid() + self.__process = process + + def get_thread(self): + """ + @rtype: L{Thread} + @return: Parent Thread object. + """ + if self.__thread is not None: + return self.__thread + self.__load_Thread_class() + self.__thread = Thread(self.get_tid()) + return self.__thread + + def set_thread(self, thread = None): + """ + Manually set the thread process. Use with care! + + @type thread: L{Thread} + @param thread: (Optional) Thread object. Use C{None} to autodetect. + """ + if thread is None: + self.__thread = None + else: + self.__load_Thread_class() + if not isinstance(thread, Thread): + msg = "Parent thread must be a Thread instance, " + msg += "got %s instead" % type(thread) + raise TypeError(msg) + self.dwThreadId = thread.get_tid() + self.__thread = thread + + def __get_window(self, hWnd): + """ + User internally to get another Window from this one. + It'll try to copy the parent Process and Thread references if possible. + """ + window = Window(hWnd) + if window.get_pid() == self.get_pid(): + window.set_process( self.get_process() ) + if window.get_tid() == self.get_tid(): + window.set_thread( self.get_thread() ) + return window + +#------------------------------------------------------------------------------ + + def get_classname(self): + """ + @rtype: str + @return: Window class name. + + @raise WindowsError: An error occured while processing this request. + """ + return win32.GetClassName( self.get_handle() ) + + def get_style(self): + """ + @rtype: int + @return: Window style mask. + + @raise WindowsError: An error occured while processing this request. + """ + return win32.GetWindowLongPtr( self.get_handle(), win32.GWL_STYLE ) + + def get_extended_style(self): + """ + @rtype: int + @return: Window extended style mask. + + @raise WindowsError: An error occured while processing this request. + """ + return win32.GetWindowLongPtr( self.get_handle(), win32.GWL_EXSTYLE ) + + def get_text(self): + """ + @see: L{set_text} + @rtype: str + @return: Window text (caption) on success, C{None} on error. + """ + try: + return win32.GetWindowText( self.get_handle() ) + except WindowsError: + return None + + def set_text(self, text): + """ + Set the window text (caption). + + @see: L{get_text} + + @type text: str + @param text: New window text. + + @raise WindowsError: An error occured while processing this request. + """ + win32.SetWindowText( self.get_handle(), text ) + + def get_placement(self): + """ + Retrieve the window placement in the desktop. + + @see: L{set_placement} + + @rtype: L{win32.WindowPlacement} + @return: Window placement in the desktop. + + @raise WindowsError: An error occured while processing this request. + """ + return win32.GetWindowPlacement( self.get_handle() ) + + def set_placement(self, placement): + """ + Set the window placement in the desktop. + + @see: L{get_placement} + + @type placement: L{win32.WindowPlacement} + @param placement: Window placement in the desktop. + + @raise WindowsError: An error occured while processing this request. + """ + win32.SetWindowPlacement( self.get_handle(), placement ) + + def get_screen_rect(self): + """ + Get the window coordinates in the desktop. + + @rtype: L{win32.Rect} + @return: Rectangle occupied by the window in the desktop. + + @raise WindowsError: An error occured while processing this request. + """ + return win32.GetWindowRect( self.get_handle() ) + + def get_client_rect(self): + """ + Get the window's client area coordinates in the desktop. + + @rtype: L{win32.Rect} + @return: Rectangle occupied by the window's client area in the desktop. + + @raise WindowsError: An error occured while processing this request. + """ + cr = win32.GetClientRect( self.get_handle() ) + cr.left, cr.top = self.client_to_screen(cr.left, cr.top) + cr.right, cr.bottom = self.client_to_screen(cr.right, cr.bottom) + return cr + + # XXX TODO + # * properties x, y, width, height + # * properties left, top, right, bottom + + process = property(get_process, set_process, doc="") + thread = property(get_thread, set_thread, doc="") + classname = property(get_classname, doc="") + style = property(get_style, doc="") + exstyle = property(get_extended_style, doc="") + text = property(get_text, set_text, doc="") + placement = property(get_placement, set_placement, doc="") + +#------------------------------------------------------------------------------ + + def client_to_screen(self, x, y): + """ + Translates window client coordinates to screen coordinates. + + @note: This is a simplified interface to some of the functionality of + the L{win32.Point} class. + + @see: {win32.Point.client_to_screen} + + @type x: int + @param x: Horizontal coordinate. + @type y: int + @param y: Vertical coordinate. + + @rtype: tuple( int, int ) + @return: Translated coordinates in a tuple (x, y). + + @raise WindowsError: An error occured while processing this request. + """ + return tuple( win32.ClientToScreen( self.get_handle(), (x, y) ) ) + + def screen_to_client(self, x, y): + """ + Translates window screen coordinates to client coordinates. + + @note: This is a simplified interface to some of the functionality of + the L{win32.Point} class. + + @see: {win32.Point.screen_to_client} + + @type x: int + @param x: Horizontal coordinate. + @type y: int + @param y: Vertical coordinate. + + @rtype: tuple( int, int ) + @return: Translated coordinates in a tuple (x, y). + + @raise WindowsError: An error occured while processing this request. + """ + return tuple( win32.ScreenToClient( self.get_handle(), (x, y) ) ) + +#------------------------------------------------------------------------------ + + def get_parent(self): + """ + @see: L{get_children} + @rtype: L{Window} or None + @return: Parent window. Returns C{None} if the window has no parent. + @raise WindowsError: An error occured while processing this request. + """ + hWnd = win32.GetParent( self.get_handle() ) + if hWnd: + return self.__get_window(hWnd) + + def get_children(self): + """ + @see: L{get_parent} + @rtype: list( L{Window} ) + @return: List of child windows. + @raise WindowsError: An error occured while processing this request. + """ + return [ + self.__get_window(hWnd) \ + for hWnd in win32.EnumChildWindows( self.get_handle() ) + ] + + def get_tree(self): + """ + @see: L{get_root} + @rtype: dict( L{Window} S{->} dict( ... ) ) + @return: Dictionary of dictionaries forming a tree of child windows. + @raise WindowsError: An error occured while processing this request. + """ + subtree = dict() + for aWindow in self.get_children(): + subtree[ aWindow ] = aWindow.get_tree() + return subtree + + def get_root(self): + """ + @see: L{get_tree} + @rtype: L{Window} + @return: If this is a child window, return the top-level window it + belongs to. + If this window is already a top-level window, returns itself. + @raise WindowsError: An error occured while processing this request. + """ + hWnd = self.get_handle() + history = set() + hPrevWnd = hWnd + while hWnd and hWnd not in history: + history.add(hWnd) + hPrevWnd = hWnd + hWnd = win32.GetParent(hWnd) + if hWnd in history: + # See: https://docs.google.com/View?id=dfqd62nk_228h28szgz + return self + if hPrevWnd != self.get_handle(): + return self.__get_window(hPrevWnd) + return self + + def get_child_at(self, x, y, bAllowTransparency = True): + """ + Get the child window located at the given coordinates. If no such + window exists an exception is raised. + + @see: L{get_children} + + @type x: int + @param x: Horizontal coordinate. + + @type y: int + @param y: Vertical coordinate. + + @type bAllowTransparency: bool + @param bAllowTransparency: If C{True} transparent areas in windows are + ignored, returning the window behind them. If C{False} transparent + areas are treated just like any other area. + + @rtype: L{Window} + @return: Child window at the requested position, or C{None} if there + is no window at those coordinates. + """ + try: + if bAllowTransparency: + hWnd = win32.RealChildWindowFromPoint( self.get_handle(), (x, y) ) + else: + hWnd = win32.ChildWindowFromPoint( self.get_handle(), (x, y) ) + if hWnd: + return self.__get_window(hWnd) + except WindowsError: + pass + return None + +#------------------------------------------------------------------------------ + + def is_valid(self): + """ + @rtype: bool + @return: C{True} if the window handle is still valid. + """ + return win32.IsWindow( self.get_handle() ) + + def is_visible(self): + """ + @see: {show}, {hide} + @rtype: bool + @return: C{True} if the window is in a visible state. + """ + return win32.IsWindowVisible( self.get_handle() ) + + def is_enabled(self): + """ + @see: {enable}, {disable} + @rtype: bool + @return: C{True} if the window is in an enabled state. + """ + return win32.IsWindowEnabled( self.get_handle() ) + + def is_maximized(self): + """ + @see: L{maximize} + @rtype: bool + @return: C{True} if the window is maximized. + """ + return win32.IsZoomed( self.get_handle() ) + + def is_minimized(self): + """ + @see: L{minimize} + @rtype: bool + @return: C{True} if the window is minimized. + """ + return win32.IsIconic( self.get_handle() ) + + def is_child(self): + """ + @see: L{get_parent} + @rtype: bool + @return: C{True} if the window is a child window. + """ + return win32.IsChild( self.get_handle() ) + + is_zoomed = is_maximized + is_iconic = is_minimized + +#------------------------------------------------------------------------------ + + def enable(self): + """ + Enable the user input for the window. + + @see: L{disable} + + @raise WindowsError: An error occured while processing this request. + """ + win32.EnableWindow( self.get_handle(), True ) + + def disable(self): + """ + Disable the user input for the window. + + @see: L{enable} + + @raise WindowsError: An error occured while processing this request. + """ + win32.EnableWindow( self.get_handle(), False ) + + def show(self, bAsync = True): + """ + Make the window visible. + + @see: L{hide} + + @type bAsync: bool + @param bAsync: Perform the request asynchronously. + + @raise WindowsError: An error occured while processing this request. + """ + if bAsync: + win32.ShowWindowAsync( self.get_handle(), win32.SW_SHOW ) + else: + win32.ShowWindow( self.get_handle(), win32.SW_SHOW ) + + def hide(self, bAsync = True): + """ + Make the window invisible. + + @see: L{show} + + @type bAsync: bool + @param bAsync: Perform the request asynchronously. + + @raise WindowsError: An error occured while processing this request. + """ + if bAsync: + win32.ShowWindowAsync( self.get_handle(), win32.SW_HIDE ) + else: + win32.ShowWindow( self.get_handle(), win32.SW_HIDE ) + + def maximize(self, bAsync = True): + """ + Maximize the window. + + @see: L{minimize}, L{restore} + + @type bAsync: bool + @param bAsync: Perform the request asynchronously. + + @raise WindowsError: An error occured while processing this request. + """ + if bAsync: + win32.ShowWindowAsync( self.get_handle(), win32.SW_MAXIMIZE ) + else: + win32.ShowWindow( self.get_handle(), win32.SW_MAXIMIZE ) + + def minimize(self, bAsync = True): + """ + Minimize the window. + + @see: L{maximize}, L{restore} + + @type bAsync: bool + @param bAsync: Perform the request asynchronously. + + @raise WindowsError: An error occured while processing this request. + """ + if bAsync: + win32.ShowWindowAsync( self.get_handle(), win32.SW_MINIMIZE ) + else: + win32.ShowWindow( self.get_handle(), win32.SW_MINIMIZE ) + + def restore(self, bAsync = True): + """ + Unmaximize and unminimize the window. + + @see: L{maximize}, L{minimize} + + @type bAsync: bool + @param bAsync: Perform the request asynchronously. + + @raise WindowsError: An error occured while processing this request. + """ + if bAsync: + win32.ShowWindowAsync( self.get_handle(), win32.SW_RESTORE ) + else: + win32.ShowWindow( self.get_handle(), win32.SW_RESTORE ) + + def move(self, x = None, y = None, width = None, height = None, + bRepaint = True): + """ + Moves and/or resizes the window. + + @note: This is request is performed syncronously. + + @type x: int + @param x: (Optional) New horizontal coordinate. + + @type y: int + @param y: (Optional) New vertical coordinate. + + @type width: int + @param width: (Optional) Desired window width. + + @type height: int + @param height: (Optional) Desired window height. + + @type bRepaint: bool + @param bRepaint: + (Optional) C{True} if the window should be redrawn afterwards. + + @raise WindowsError: An error occured while processing this request. + """ + if None in (x, y, width, height): + rect = self.get_screen_rect() + if x is None: + x = rect.left + if y is None: + y = rect.top + if width is None: + width = rect.right - rect.left + if height is None: + height = rect.bottom - rect.top + win32.MoveWindow(self.get_handle(), x, y, width, height, bRepaint) + + def kill(self): + """ + Signals the program to quit. + + @note: This is an asyncronous request. + + @raise WindowsError: An error occured while processing this request. + """ + self.post(win32.WM_QUIT) + + def send(self, uMsg, wParam = None, lParam = None, dwTimeout = None): + """ + Send a low-level window message syncronically. + + @type uMsg: int + @param uMsg: Message code. + + @param wParam: + The type and meaning of this parameter depends on the message. + + @param lParam: + The type and meaning of this parameter depends on the message. + + @param dwTimeout: Optional timeout for the operation. + Use C{None} to wait indefinitely. + + @rtype: int + @return: The meaning of the return value depends on the window message. + Typically a value of C{0} means an error occured. You can get the + error code by calling L{win32.GetLastError}. + """ + if dwTimeout is None: + return win32.SendMessage(self.get_handle(), uMsg, wParam, lParam) + return win32.SendMessageTimeout( + self.get_handle(), uMsg, wParam, lParam, + win32.SMTO_ABORTIFHUNG | win32.SMTO_ERRORONEXIT, dwTimeout) + + def post(self, uMsg, wParam = None, lParam = None): + """ + Post a low-level window message asyncronically. + + @type uMsg: int + @param uMsg: Message code. + + @param wParam: + The type and meaning of this parameter depends on the message. + + @param lParam: + The type and meaning of this parameter depends on the message. + + @raise WindowsError: An error occured while sending the message. + """ + win32.PostMessage(self.get_handle(), uMsg, wParam, lParam) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/attach.cpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/attach.cpp new file mode 100644 index 0000000..005d447 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/attach.cpp @@ -0,0 +1,711 @@ +/* **************************************************************************** +* +* Copyright (c) Microsoft Corporation. +* +* This source code is subject to terms and conditions of the Apache License, Version 2.0. A +* copy of the license can be found in the License.html file at the root of this distribution. If +* you cannot locate the Apache License, Version 2.0, please send an email to +* vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound +* by the terms of the Apache License, Version 2.0. +* +* You must not remove this notice, or any other, from this software. +* +* Contributor: Fabio Zadrozny +* +* Based on PyDebugAttach.cpp from PVTS. Windows only. +* +* https://github.com/Microsoft/PTVS/blob/master/Python/Product/PyDebugAttach/PyDebugAttach.cpp +* +* Initially we did an attach completely based on shellcode which got the +* GIL called PyRun_SimpleString with the needed code and was done with it +* (so, none of this code was needed). +* Now, newer version of Python don't initialize threading by default, so, +* most of this code is done only to overcome this limitation (and as a plus, +* if there's no code running, we also pause the threads to make our code run). +* +* On Linux the approach is still the simpler one (using gdb), so, on newer +* versions of Python it may not work unless the user has some code running +* and threads are initialized. +* I.e.: +* +* The user may have to add the code below in the start of its script for +* a successful attach (if he doesn't already use threads). +* +* from threading import Thread +* Thread(target=str).start() +* +* -- this is the workaround for the fact that we can't get the gil +* if there aren't any threads (PyGILState_Ensure gives an error). +* ***************************************************************************/ + + +// Access to std::cout and std::endl +#include +#include +// DECLDIR will perform an export for us +#define DLL_EXPORT + +#include "attach.h" +#include "stdafx.h" + +#include "../common/python.h" +#include "../common/ref_utils.hpp" +#include "../common/py_utils.hpp" +#include "../common/py_settrace.hpp" + + +#pragma comment(lib, "kernel32.lib") +#pragma comment(lib, "user32.lib") +#pragma comment(lib, "advapi32.lib") +#pragma comment(lib, "psapi.lib") + +// _Always_ is not defined for all versions, so make it a no-op if missing. +#ifndef _Always_ +#define _Always_(x) x +#endif + + +typedef void (PyEval_Lock)(); // Acquire/Release lock +typedef void (PyThreadState_API)(PyThreadState *); // Acquire/Release lock +typedef PyObject* (Py_CompileString)(const char *str, const char *filename, int start); +typedef PyObject* (PyEval_EvalCode)(PyObject *co, PyObject *globals, PyObject *locals); +typedef PyObject* (PyDict_GetItemString)(PyObject *p, const char *key); +typedef PyObject* (PyEval_GetBuiltins)(); +typedef int (PyDict_SetItemString)(PyObject *dp, const char *key, PyObject *item); +typedef int (PyEval_ThreadsInitialized)(); +typedef int (Py_AddPendingCall)(int (*func)(void *), void*); +typedef PyObject* (PyString_FromString)(const char* s); +typedef void PyEval_SetTrace(Py_tracefunc func, PyObject *obj); +typedef PyObject* (PyErr_Print)(); +typedef PyObject* (PyObject_SetAttrString)(PyObject *o, const char *attr_name, PyObject* value); +typedef PyObject* (PyBool_FromLong)(long v); +typedef unsigned long (_PyEval_GetSwitchInterval)(void); +typedef void (_PyEval_SetSwitchInterval)(unsigned long microseconds); +typedef PyGILState_STATE PyGILState_EnsureFunc(void); +typedef void PyGILState_ReleaseFunc(PyGILState_STATE); +typedef PyThreadState *PyThreadState_NewFunc(PyInterpreterState *interp); + +typedef PyObject *PyList_New(Py_ssize_t len); +typedef int PyList_Append(PyObject *list, PyObject *item); + + + +std::wstring GetCurrentModuleFilename() { + HMODULE hModule = nullptr; + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)GetCurrentModuleFilename, &hModule) != 0) { + wchar_t filename[MAX_PATH]; + GetModuleFileName(hModule, filename, MAX_PATH); + return filename; + } + return std::wstring(); +} + + +struct InitializeThreadingInfo { + PyImport_ImportModule* pyImportMod; + PyEval_Lock* initThreads; + + std::mutex mutex; + HANDLE initedEvent; // Note: only access with mutex locked (and check if not already nullptr). + bool completed; // Note: only access with mutex locked +}; + + +int AttachCallback(void *voidInitializeThreadingInfo) { + // initialize us for threading, this will acquire the GIL if not already created, and is a nop if the GIL is created. + // This leaves us in the proper state when we return back to the runtime whether the GIL was created or not before + // we were called. + InitializeThreadingInfo* initializeThreadingInfo = reinterpret_cast(voidInitializeThreadingInfo); + initializeThreadingInfo->initThreads(); // Note: calling multiple times is ok. + initializeThreadingInfo->pyImportMod("threading"); + + initializeThreadingInfo->mutex.lock(); + if(initializeThreadingInfo->initedEvent != nullptr) { + SetEvent(initializeThreadingInfo->initedEvent); + } + initializeThreadingInfo->completed = true; + initializeThreadingInfo->mutex.unlock(); + return 0; +} + + +// create a custom heap for our unordered map. This is necessary because if we suspend a thread while in a heap function +// then we could deadlock here. We need to be VERY careful about what we do while the threads are suspended. +static HANDLE g_heap = 0; + +template +class PrivateHeapAllocator { +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef T value_type; + + template + struct rebind { + typedef PrivateHeapAllocator other; + }; + + explicit PrivateHeapAllocator() {} + + PrivateHeapAllocator(PrivateHeapAllocator const&) {} + + ~PrivateHeapAllocator() {} + + template + PrivateHeapAllocator(PrivateHeapAllocator const&) {} + + pointer allocate(size_type size, std::allocator::const_pointer hint = 0) { + UNREFERENCED_PARAMETER(hint); + + if (g_heap == nullptr) { + g_heap = HeapCreate(0, 0, 0); + } + auto mem = HeapAlloc(g_heap, 0, size * sizeof(T)); + return static_cast(mem); + } + + void deallocate(pointer p, size_type n) { + UNREFERENCED_PARAMETER(n); + + HeapFree(g_heap, 0, p); + } + + size_type max_size() const { + return (std::numeric_limits::max)() / sizeof(T); + } + + void construct(pointer p, const T& t) { + new(p) T(t); + } + + void destroy(pointer p) { + p->~T(); + } +}; + +typedef std::unordered_map, std::equal_to, PrivateHeapAllocator>> ThreadMap; + +void ResumeThreads(ThreadMap &suspendedThreads) { + for (auto start = suspendedThreads.begin(); start != suspendedThreads.end(); start++) { + ResumeThread((*start).second); + CloseHandle((*start).second); + } + suspendedThreads.clear(); +} + +// Suspends all threads ensuring that they are not currently in a call to Py_AddPendingCall. +void SuspendThreads(ThreadMap &suspendedThreads, Py_AddPendingCall* addPendingCall, PyEval_ThreadsInitialized* threadsInited) { + DWORD curThreadId = GetCurrentThreadId(); + DWORD curProcess = GetCurrentProcessId(); + // suspend all the threads in the process so we can do things safely... + bool suspended; + + do { + suspended = false; + HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); + if (h != INVALID_HANDLE_VALUE) { + + THREADENTRY32 te; + te.dwSize = sizeof(te); + if (Thread32First(h, &te)) { + do { + if (te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(te.th32OwnerProcessID) && te.th32OwnerProcessID == curProcess) { + + + if (te.th32ThreadID != curThreadId && suspendedThreads.find(te.th32ThreadID) == suspendedThreads.end()) { + auto hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, te.th32ThreadID); + if (hThread != nullptr) { + SuspendThread(hThread); + + bool addingPendingCall = false; + + CONTEXT context; + memset(&context, 0x00, sizeof(CONTEXT)); + context.ContextFlags = CONTEXT_ALL; + GetThreadContext(hThread, &context); + +#if defined(_X86_) + if (context.Eip >= *(reinterpret_cast(addPendingCall)) && context.Eip <= (*(reinterpret_cast(addPendingCall))) + 0x100) { + addingPendingCall = true; + } +#elif defined(_AMD64_) + if (context.Rip >= *(reinterpret_cast(addPendingCall)) && context.Rip <= *(reinterpret_cast(addPendingCall) + 0x100)) { + addingPendingCall = true; + } +#endif + + if (addingPendingCall) { + // we appear to be adding a pending call via this thread - wait for this to finish so we can add our own pending call... + ResumeThread(hThread); + SwitchToThread(); // yield to the resumed thread if it's on our CPU... + CloseHandle(hThread); + } else { + suspendedThreads[te.th32ThreadID] = hThread; + } + suspended = true; + } + } + } + + te.dwSize = sizeof(te); + } while (Thread32Next(h, &te) && !threadsInited()); + } + CloseHandle(h); + } + } while (suspended && !threadsInited()); +} + + + +// Checks to see if the specified module is likely a Python interpreter. +bool IsPythonModule(HMODULE module, bool &isDebug) { + wchar_t mod_name[MAX_PATH]; + isDebug = false; + if (GetModuleBaseName(GetCurrentProcess(), module, mod_name, MAX_PATH)) { + if (_wcsnicmp(mod_name, L"python", 6) == 0) { + if (wcslen(mod_name) >= 10 && _wcsnicmp(mod_name + 8, L"_d", 2) == 0) { + isDebug = true; + } + + // Check if the module has Py_IsInitialized. + DEFINE_PROC_NO_CHECK(isInit, Py_IsInitialized*, "Py_IsInitialized", 0); + DEFINE_PROC_NO_CHECK(gilEnsure, PyGILState_Ensure*, "PyGILState_Ensure", 51); + DEFINE_PROC_NO_CHECK(gilRelease, PyGILState_Release*, "PyGILState_Release", 51); + if (isInit == nullptr || gilEnsure == nullptr || gilRelease == nullptr) { + return false; + } + + + return true; + } + } + return false; +} + +extern "C" +{ + + /** + * The returned value signals the error that happened! + * + * Return codes: + * 0 = all OK. + * 1 = Py_IsInitialized not found + * 2 = Py_IsInitialized returned false + * 3 = Missing Python API + * 4 = Interpreter not initialized + * 5 = Python version unknown + * 6 = Connect timeout + **/ + int DoAttach(HMODULE module, bool isDebug, const char *command, bool showDebugInfo ) + { + auto isInit = reinterpret_cast(GetProcAddress(module, "Py_IsInitialized")); + + if (isInit == nullptr) { + if (showDebugInfo) { + std::cout << "Py_IsInitialized not found. " << std::endl << std::flush; + } + return 1; + } + if (!isInit()) { + if (showDebugInfo) { + std::cout << "Py_IsInitialized returned false. " << std::endl << std::flush; + } + return 2; + } + + auto version = GetPythonVersion(module); + + // found initialized Python runtime, gather and check the APIs we need for a successful attach... + DEFINE_PROC(addPendingCall, Py_AddPendingCall*, "Py_AddPendingCall", -100); + DEFINE_PROC(interpHead, PyInterpreterState_Head*, "PyInterpreterState_Head", -110); + DEFINE_PROC(gilEnsure, PyGILState_Ensure*, "PyGILState_Ensure", -120); + DEFINE_PROC(gilRelease, PyGILState_Release*, "PyGILState_Release", -130); + DEFINE_PROC(threadHead, PyInterpreterState_ThreadHead*, "PyInterpreterState_ThreadHead", -140); + DEFINE_PROC(initThreads, PyEval_Lock*, "PyEval_InitThreads", -150); + DEFINE_PROC(releaseLock, PyEval_Lock*, "PyEval_ReleaseLock", -160); + DEFINE_PROC(threadsInited, PyEval_ThreadsInitialized*, "PyEval_ThreadsInitialized", -170); + DEFINE_PROC(threadNext, PyThreadState_Next*, "PyThreadState_Next", -180); + DEFINE_PROC(pyImportMod, PyImport_ImportModule*, "PyImport_ImportModule", -190); + DEFINE_PROC(pyNone, PyObject*, "_Py_NoneStruct", -2000); + DEFINE_PROC(pyRun_SimpleString, PyRun_SimpleString*, "PyRun_SimpleString", -210); + + // Either _PyThreadState_Current or _PyThreadState_UncheckedGet are required + DEFINE_PROC_NO_CHECK(curPythonThread, PyThreadState**, "_PyThreadState_Current", -220); // optional + DEFINE_PROC_NO_CHECK(getPythonThread, _PyThreadState_UncheckedGet*, "_PyThreadState_UncheckedGet", -230); // optional + + if (curPythonThread == nullptr && getPythonThread == nullptr) { + // we're missing some APIs, we cannot attach. + PRINT("Error, missing Python threading API!!"); + return -240; + } + + // Either _Py_CheckInterval or _PyEval_[GS]etSwitchInterval are useful, but not required + DEFINE_PROC_NO_CHECK(intervalCheck, int*, "_Py_CheckInterval", -250); // optional + DEFINE_PROC_NO_CHECK(getSwitchInterval, _PyEval_GetSwitchInterval*, "_PyEval_GetSwitchInterval", -260); // optional + DEFINE_PROC_NO_CHECK(setSwitchInterval, _PyEval_SetSwitchInterval*, "_PyEval_SetSwitchInterval", -270); // optional + + auto head = interpHead(); + if (head == nullptr) { + // this interpreter is loaded but not initialized. + if (showDebugInfo) { + std::cout << "Interpreter not initialized! " << std::endl << std::flush; + } + return 4; + } + + // check that we're a supported version + if (version == PythonVersion_Unknown) { + if (showDebugInfo) { + std::cout << "Python version unknown! " << std::endl << std::flush; + } + return 5; + } else if (version == PythonVersion_25 || version == PythonVersion_26 || + version == PythonVersion_30 || version == PythonVersion_31 || version == PythonVersion_32) { + if (showDebugInfo) { + std::cout << "Python version unsupported! " << std::endl << std::flush; + } + return 5; + } + + + // We always try to initialize threading and import the threading module in the main thread in the code + // below... + // + // We need to initialize multiple threading support but we need to do so safely, so we call + // Py_AddPendingCall and have our callback then initialize multi threading. This is completely safe on 2.7 + // and up. Unfortunately that doesn't work if we're not actively running code on the main thread (blocked on a lock + // or reading input). + // + // Another option is to make sure no code is running - if there is no active thread then we can safely call + // PyEval_InitThreads and we're in business. But to know this is safe we need to first suspend all the other + // threads in the process and then inspect if any code is running (note that this is still not ideal because + // this thread will be the thread head for Python, but still better than not attach at all). + // + // Finally if code is running after we've suspended the threads then we can go ahead and do Py_AddPendingCall + // on down-level interpreters as long as we're sure no one else is making a call to Py_AddPendingCall at the same + // time. + // + // Therefore our strategy becomes: Make the Py_AddPendingCall on interpreters and wait for it. If it doesn't + // call after a timeout, suspend all threads - if a threads is in Py_AddPendingCall resume and try again. Once we've got all of the threads + // stopped and not in Py_AddPendingCall (which calls no functions its self, you can see this and it's size in the + // debugger) then see if we have a current thread. If not go ahead and initialize multiple threading (it's now safe, + // no Python code is running). + + InitializeThreadingInfo *initializeThreadingInfo = new InitializeThreadingInfo(); + initializeThreadingInfo->pyImportMod = pyImportMod; + initializeThreadingInfo->initThreads = initThreads; + initializeThreadingInfo->initedEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); + + // Add the call to initialize threading. + addPendingCall(&AttachCallback, initializeThreadingInfo); + + ::WaitForSingleObject(initializeThreadingInfo->initedEvent, 5000); + + // Whether this completed or not, release the event handle as we won't use it anymore. + initializeThreadingInfo->mutex.lock(); + CloseHandle(initializeThreadingInfo->initedEvent); + bool completed = initializeThreadingInfo->completed; + initializeThreadingInfo->initedEvent = nullptr; + initializeThreadingInfo->mutex.unlock(); + + if(completed) { + // Note that this structure will leak if addPendingCall did not complete in the timeout + // (we can't release now because it's possible that it'll still be called). + delete initializeThreadingInfo; + if (showDebugInfo) { + std::cout << "addPendingCall to initialize threads/import threading completed. " << std::endl << std::flush; + } + } else { + if (showDebugInfo) { + std::cout << "addPendingCall to initialize threads/import threading did NOT complete. " << std::endl << std::flush; + } + } + + if (threadsInited()) { + // Note that since Python 3.7, threads are *always* initialized! + if (showDebugInfo) { + std::cout << "Threads initialized! " << std::endl << std::flush; + } + + } else { + int saveIntervalCheck; + unsigned long saveLongIntervalCheck; + if (intervalCheck != nullptr) { + // not available on 3.2 + saveIntervalCheck = *intervalCheck; + *intervalCheck = -1; // lower the interval check so pending calls are processed faster + saveLongIntervalCheck = 0; // prevent compiler warning + } else if (getSwitchInterval != nullptr && setSwitchInterval != nullptr) { + saveLongIntervalCheck = getSwitchInterval(); + setSwitchInterval(0); + saveIntervalCheck = 0; // prevent compiler warning + } + else { + saveIntervalCheck = 0; // prevent compiler warning + saveLongIntervalCheck = 0; // prevent compiler warning + } + + // If threads weren't initialized in our pending call, instead of giving a timeout, try + // to initialize it in this thread. + for(int attempts = 0; !threadsInited() && attempts < 20; attempts++) { + if(attempts > 0){ + // If we haven't been able to do it in the first time, wait a bit before retrying. + Sleep(10); + } + + ThreadMap suspendedThreads; + std::cout << "SuspendThreads(suspendedThreads, addPendingCall, threadsInited);" << std::endl << std::flush; + SuspendThreads(suspendedThreads, addPendingCall, threadsInited); + + if(!threadsInited()){ // Check again with threads suspended. + if (showDebugInfo) { + std::cout << "ENTERED if (!threadsInited()) {" << std::endl << std::flush; + } + auto curPyThread = getPythonThread ? getPythonThread() : *curPythonThread; + + if (curPyThread == nullptr) { + if (showDebugInfo) { + std::cout << "ENTERED if (curPyThread == nullptr) {" << std::endl << std::flush; + } + // no threads are currently running, it is safe to initialize multi threading. + PyGILState_STATE gilState; + if (version >= PythonVersion_34) { + // in 3.4 due to http://bugs.python.org/issue20891, + // we need to create our thread state manually + // before we can call PyGILState_Ensure() before we + // can call PyEval_InitThreads(). + + // Don't require this function unless we need it. + auto threadNew = (PyThreadState_NewFunc*)GetProcAddress(module, "PyThreadState_New"); + if (threadNew != nullptr) { + threadNew(head); + } + } + + if (version >= PythonVersion_32) { + // in 3.2 due to the new GIL and later we can't call Py_InitThreads + // without a thread being initialized. + // So we use PyGilState_Ensure here to first + // initialize the current thread, and then we use + // Py_InitThreads to bring up multi-threading. + // Some context here: http://bugs.python.org/issue11329 + // http://pytools.codeplex.com/workitem/834 + gilState = gilEnsure(); + } + else { + gilState = PyGILState_LOCKED; // prevent compiler warning + } + + if (showDebugInfo) { + std::cout << "Called initThreads()" << std::endl << std::flush; + } + // Initialize threads in our secondary thread (this is NOT ideal because + // this thread will be the thread head), but is still better than not being + // able to attach if the main thread is not actually running any code. + initThreads(); + + if (version >= PythonVersion_32) { + // we will release the GIL here + gilRelease(gilState); + } else { + releaseLock(); + } + } + } + ResumeThreads(suspendedThreads); + } + + + if (intervalCheck != nullptr) { + *intervalCheck = saveIntervalCheck; + } else if (setSwitchInterval != nullptr) { + setSwitchInterval(saveLongIntervalCheck); + } + + } + + if (g_heap != nullptr) { + HeapDestroy(g_heap); + g_heap = nullptr; + } + + if (!threadsInited()) { + std::cout << "Unable to initialize threads in the given timeout! " << std::endl << std::flush; + return 8; + } + + GilHolder gilLock(gilEnsure, gilRelease); // acquire and hold the GIL until done... + + pyRun_SimpleString(command); + return 0; + + } + + + + + // ======================================== Code related to setting tracing to existing threads. + + struct ModuleInfo { + HMODULE module; + bool isDebug; + int errorGettingModule; // 0 means ok, negative values some error (should never be positive). + }; + + + ModuleInfo GetPythonModule() { + HANDLE hProcess = GetCurrentProcess(); + ModuleInfo moduleInfo; + moduleInfo.module = nullptr; + moduleInfo.isDebug = false; + moduleInfo.errorGettingModule = 0; + + DWORD modSize = sizeof(HMODULE) * 1024; + HMODULE* hMods = (HMODULE*)_malloca(modSize); + if (hMods == nullptr) { + std::cout << "hmods not allocated! " << std::endl << std::flush; + moduleInfo.errorGettingModule = -1; + return moduleInfo; + } + + DWORD modsNeeded; + while (!EnumProcessModules(hProcess, hMods, modSize, &modsNeeded)) { + // try again w/ more space... + _freea(hMods); + hMods = (HMODULE*)_malloca(modsNeeded); + if (hMods == nullptr) { + std::cout << "hmods not allocated (2)! " << std::endl << std::flush; + moduleInfo.errorGettingModule = -2; + return moduleInfo; + } + modSize = modsNeeded; + } + + for (size_t i = 0; i < modsNeeded / sizeof(HMODULE); i++) { + bool isDebug; + if (IsPythonModule(hMods[i], isDebug)) { + moduleInfo.isDebug = isDebug; + moduleInfo.module = hMods[i]; + return moduleInfo; + } + } + std::cout << "Unable to find python module. " << std::endl << std::flush; + moduleInfo.errorGettingModule = -3; + return moduleInfo; + } + + + /** + * This function is meant to be called to execute some arbitrary python code to be + * run. It'll initialize threads as needed and then run the code with pyRun_SimpleString. + * + * @param command: the python code to be run + * @param attachInfo: pointer to an int specifying whether we should show debug info (1) or not (0). + **/ + DECLDIR int AttachAndRunPythonCode(const char *command, int *attachInfo ) + { + + int SHOW_DEBUG_INFO = 1; + + bool showDebugInfo = (*attachInfo & SHOW_DEBUG_INFO) != 0; + + if (showDebugInfo) { + std::cout << "AttachAndRunPythonCode started (showing debug info). " << std::endl << std::flush; + } + + ModuleInfo moduleInfo = GetPythonModule(); + if (moduleInfo.errorGettingModule != 0) { + return moduleInfo.errorGettingModule; + } + HMODULE module = moduleInfo.module; + int attached = DoAttach(module, moduleInfo.isDebug, command, showDebugInfo); + + if (attached != 0 && showDebugInfo) { + std::cout << "Error when injecting code in target process. Error code (on windows): " << attached << std::endl << std::flush; + } + return attached; + } + + + DECLDIR int PrintDebugInfo() { + PRINT("Getting debug info..."); + ModuleInfo moduleInfo = GetPythonModule(); + if (moduleInfo.errorGettingModule != 0) { + PRINT("Error getting python module"); + return 0; + } + HMODULE module = moduleInfo.module; + + DEFINE_PROC(interpHead, PyInterpreterState_Head*, "PyInterpreterState_Head", 0); + DEFINE_PROC(threadHead, PyInterpreterState_ThreadHead*, "PyInterpreterState_ThreadHead", 0); + DEFINE_PROC(threadNext, PyThreadState_Next*, "PyThreadState_Next", 160); + DEFINE_PROC(gilEnsure, PyGILState_Ensure*, "PyGILState_Ensure", 0); + DEFINE_PROC(gilRelease, PyGILState_Release*, "PyGILState_Release", 0); + + auto head = interpHead(); + if (head == nullptr) { + // this interpreter is loaded but not initialized. + PRINT("Interpreter not initialized!"); + return 0; + } + + auto version = GetPythonVersion(module); + printf("Python version: %d\n", version); + + GilHolder gilLock(gilEnsure, gilRelease); // acquire and hold the GIL until done... + auto curThread = threadHead(head); + if (curThread == nullptr) { + PRINT("Thread head is NULL.") + return 0; + } + + for (auto curThread = threadHead(head); curThread != nullptr; curThread = threadNext(curThread)) { + printf("Found thread id: %d\n", GetPythonThreadId(version, curThread)); + } + + PRINT("Finished getting debug info.") + return 0; + } + + + /** + * This function may be called to set a tracing function to existing python threads. + **/ + DECLDIR int AttachDebuggerTracing(bool showDebugInfo, void* pSetTraceFunc, void* pTraceFunc, unsigned int threadId, void* pPyNone) + { + ModuleInfo moduleInfo = GetPythonModule(); + if (moduleInfo.errorGettingModule != 0) { + return moduleInfo.errorGettingModule; + } + HMODULE module = moduleInfo.module; + if (showDebugInfo) { + std::cout << "Setting sys trace for existing threads." << std::endl << std::flush; + } + int attached = 0; + PyObjectHolder traceFunc(moduleInfo.isDebug, reinterpret_cast(pTraceFunc), true); + PyObjectHolder setTraceFunc(moduleInfo.isDebug, reinterpret_cast(pSetTraceFunc), true); + PyObjectHolder pyNone(moduleInfo.isDebug, reinterpret_cast(pPyNone), true); + + int temp = InternalSetSysTraceFunc(module, moduleInfo.isDebug, showDebugInfo, &traceFunc, &setTraceFunc, threadId, &pyNone); + if (temp == 0) { + // we've successfully attached the debugger + return 0; + } else { + if (temp > attached) { + //I.e.: the higher the value the more significant it is. + attached = temp; + } + } + + if (showDebugInfo) { + std::cout << "Setting sys trace for existing threads failed with code: " << attached << "." << std::endl << std::flush; + } + return attached; + } + +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/attach.h b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/attach.h new file mode 100644 index 0000000..3a2b582 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/attach.h @@ -0,0 +1,57 @@ +/* **************************************************************************** + * + * Copyright (c) Brainwy software Ltda. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +#ifndef _ATTACH_DLL_H_ +#define _ATTACH_DLL_H_ + +#if defined DLL_EXPORT +#define DECLDIR __declspec(dllexport) +#else +#define DECLDIR __declspec(dllimport) +#endif + + +extern "C" +{ + DECLDIR int AttachAndRunPythonCode(const char *command, int *result ); + + /* + * Helper to print debug information from the current process + */ + DECLDIR int PrintDebugInfo(); + + /* + Could be used with ctypes (note that the threading should be initialized, so, + doing it in a thread as below is recommended): + + def check(): + + import ctypes + lib = ctypes.cdll.LoadLibrary(r'C:\...\attach_x86.dll') + print 'result', lib.AttachDebuggerTracing(0) + + t = threading.Thread(target=check) + t.start() + t.join() + */ + DECLDIR int AttachDebuggerTracing( + bool showDebugInfo, + void* pSetTraceFunc, // Actually PyObject*, but we don't want to include it here. + void* pTraceFunc, // Actually PyObject*, but we don't want to include it here. + unsigned int threadId, + void* pPyNone // Actually PyObject*, but we don't want to include it here. + ); +} + +#endif \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/compile_windows.bat b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/compile_windows.bat new file mode 100644 index 0000000..dbd9409 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/compile_windows.bat @@ -0,0 +1,17 @@ +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86 +cl -DUNICODE -D_UNICODE /EHsc /Zi /O1 /LD attach.cpp /link /DEBUG /OPT:REF /OPT:ICF /out:attach_x86.dll +copy attach_x86.dll ..\attach_x86.dll /Y +copy attach_x86.pdb ..\attach_x86.pdb /Y + + + +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 +cl -DUNICODE -D_UNICODE /EHsc /Zi /O1 /W3 /LD attach.cpp /link /DEBUG /OPT:REF /OPT:ICF /out:attach_amd64.dll +copy attach_amd64.dll ..\attach_amd64.dll /Y +copy attach_amd64.pdb ..\attach_amd64.pdb /Y + +del *.lib +del *.obj +del *.pdb +del *.dll +del *.exp \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.cpp b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.cpp new file mode 100644 index 0000000..4b80b54 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.cpp @@ -0,0 +1,22 @@ +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +// stdafx.cpp : source file that includes just the standard includes +// PyDebugAttach.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.h b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.h new file mode 100644 index 0000000..15274c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/stdafx.h @@ -0,0 +1,36 @@ +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/targetver.h b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/targetver.h new file mode 100644 index 0000000..acff541 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_attach_to_process/windows/targetver.h @@ -0,0 +1,22 @@ +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/pydevd_concurrency_logger.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/pydevd_concurrency_logger.py new file mode 100644 index 0000000..73a9bb5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/pydevd_concurrency_logger.py @@ -0,0 +1,339 @@ +import time + +from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding +from _pydev_imps._pydev_saved_modules import threading +from _pydevd_bundle import pydevd_xml +from _pydevd_bundle.pydevd_constants import GlobalDebuggerHolder +from _pydevd_bundle.pydevd_constants import get_thread_id, IS_PY3K +from _pydevd_bundle.pydevd_net_command import NetCommand +from pydevd_concurrency_analyser.pydevd_thread_wrappers import ObjectWrapper, wrap_attr +import pydevd_file_utils +from _pydev_bundle import pydev_log + +file_system_encoding = getfilesystemencoding() + +try: + from urllib import quote +except: + from urllib.parse import quote # @UnresolvedImport + +threadingCurrentThread = threading.currentThread + +DONT_TRACE_THREADING = ['threading.py', 'pydevd.py'] +INNER_METHODS = ['_stop'] +INNER_FILES = ['threading.py'] +THREAD_METHODS = ['start', '_stop', 'join'] +LOCK_METHODS = ['__init__', 'acquire', 'release', '__enter__', '__exit__'] +QUEUE_METHODS = ['put', 'get'] + +# return time since epoch in milliseconds +cur_time = lambda: int(round(time.time() * 1000000)) + +try: + import asyncio # @UnresolvedImport +except: + pass + + +def get_text_list_for_frame(frame): + # partial copy-paste from make_thread_suspend_str + curFrame = frame + cmdTextList = [] + try: + while curFrame: + # print cmdText + myId = str(id(curFrame)) + # print "id is ", myId + + if curFrame.f_code is None: + break # Iron Python sometimes does not have it! + + myName = curFrame.f_code.co_name # method name (if in method) or ? if global + if myName is None: + break # Iron Python sometimes does not have it! + + # print "name is ", myName + + filename = pydevd_file_utils.get_abs_path_real_path_and_base_from_frame(curFrame)[1] + + myFile = pydevd_file_utils.norm_file_to_client(filename) + + # print "file is ", myFile + # myFile = inspect.getsourcefile(curFrame) or inspect.getfile(frame) + + myLine = str(curFrame.f_lineno) + # print "line is ", myLine + + # the variables are all gotten 'on-demand' + # variables = pydevd_xml.frame_vars_to_xml(curFrame.f_locals) + + variables = '' + cmdTextList.append('' % (quote(myFile, '/>_= \t'), myLine)) + cmdTextList.append(variables) + cmdTextList.append("") + curFrame = curFrame.f_back + except : + pydev_log.exception() + + return cmdTextList + + +def send_message(event_class, time, name, thread_id, type, event, file, line, frame, lock_id=0, parent=None): + dbg = GlobalDebuggerHolder.global_dbg + if dbg is None: + return + cmdTextList = [''] + + cmdTextList.append('<' + event_class) + cmdTextList.append(' time="%s"' % pydevd_xml.make_valid_xml_value(str(time))) + cmdTextList.append(' name="%s"' % pydevd_xml.make_valid_xml_value(name)) + cmdTextList.append(' thread_id="%s"' % pydevd_xml.make_valid_xml_value(thread_id)) + cmdTextList.append(' type="%s"' % pydevd_xml.make_valid_xml_value(type)) + if type == "lock": + cmdTextList.append(' lock_id="%s"' % pydevd_xml.make_valid_xml_value(str(lock_id))) + if parent is not None: + cmdTextList.append(' parent="%s"' % pydevd_xml.make_valid_xml_value(parent)) + cmdTextList.append(' event="%s"' % pydevd_xml.make_valid_xml_value(event)) + cmdTextList.append(' file="%s"' % pydevd_xml.make_valid_xml_value(file)) + cmdTextList.append(' line="%s"' % pydevd_xml.make_valid_xml_value(str(line))) + cmdTextList.append('>') + + cmdTextList += get_text_list_for_frame(frame) + cmdTextList.append('') + + text = ''.join(cmdTextList) + if dbg.writer is not None: + dbg.writer.add_command(NetCommand(145, 0, text)) + + +def log_new_thread(global_debugger, t): + event_time = cur_time() - global_debugger.thread_analyser.start_time + send_message("threading_event", event_time, t.getName(), get_thread_id(t), "thread", + "start", "code_name", 0, None, parent=get_thread_id(t)) + + +class ThreadingLogger: + + def __init__(self): + self.start_time = cur_time() + + def set_start_time(self, time): + self.start_time = time + + def log_event(self, frame): + write_log = False + self_obj = None + if "self" in frame.f_locals: + self_obj = frame.f_locals["self"] + if isinstance(self_obj, threading.Thread) or self_obj.__class__ == ObjectWrapper: + write_log = True + if hasattr(frame, "f_back") and frame.f_back is not None: + back = frame.f_back + if hasattr(back, "f_back") and back.f_back is not None: + back = back.f_back + if "self" in back.f_locals: + if isinstance(back.f_locals["self"], threading.Thread): + write_log = True + try: + if write_log: + t = threadingCurrentThread() + back = frame.f_back + if not back: + return + _, name, back_base = pydevd_file_utils.get_abs_path_real_path_and_base_from_frame(back) + event_time = cur_time() - self.start_time + method_name = frame.f_code.co_name + + if isinstance(self_obj, threading.Thread): + if not hasattr(self_obj, "_pydev_run_patched"): + wrap_attr(self_obj, "run") + if (method_name in THREAD_METHODS) and (back_base not in DONT_TRACE_THREADING or \ + (method_name in INNER_METHODS and back_base in INNER_FILES)): + thread_id = get_thread_id(self_obj) + name = self_obj.getName() + real_method = frame.f_code.co_name + parent = None + if real_method == "_stop": + if back_base in INNER_FILES and \ + back.f_code.co_name == "_wait_for_tstate_lock": + back = back.f_back.f_back + real_method = "stop" + if hasattr(self_obj, "_pydev_join_called"): + parent = get_thread_id(t) + elif real_method == "join": + # join called in the current thread, not in self object + if not self_obj.is_alive(): + return + thread_id = get_thread_id(t) + name = t.getName() + self_obj._pydev_join_called = True + + if real_method == "start": + parent = get_thread_id(t) + send_message("threading_event", event_time, name, thread_id, "thread", + real_method, back.f_code.co_filename, back.f_lineno, back, parent=parent) + # print(event_time, self_obj.getName(), thread_id, "thread", + # real_method, back.f_code.co_filename, back.f_lineno) + + if method_name == "pydev_after_run_call": + if hasattr(frame, "f_back") and frame.f_back is not None: + back = frame.f_back + if hasattr(back, "f_back") and back.f_back is not None: + back = back.f_back + if "self" in back.f_locals: + if isinstance(back.f_locals["self"], threading.Thread): + my_self_obj = frame.f_back.f_back.f_locals["self"] + my_back = frame.f_back.f_back + my_thread_id = get_thread_id(my_self_obj) + send_massage = True + if IS_PY3K and hasattr(my_self_obj, "_pydev_join_called"): + send_massage = False + # we can't detect stop after join in Python 2 yet + if send_massage: + send_message("threading_event", event_time, "Thread", my_thread_id, "thread", + "stop", my_back.f_code.co_filename, my_back.f_lineno, my_back, parent=None) + + if self_obj.__class__ == ObjectWrapper: + if back_base in DONT_TRACE_THREADING: + # do not trace methods called from threading + return + back_back_base = pydevd_file_utils.get_abs_path_real_path_and_base_from_frame(back.f_back)[-1] + back = back.f_back + if back_back_base in DONT_TRACE_THREADING: + # back_back_base is the file, where the method was called froms + return + if method_name == "__init__": + send_message("threading_event", event_time, t.getName(), get_thread_id(t), "lock", + method_name, back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(frame.f_locals["self"]))) + if "attr" in frame.f_locals and \ + (frame.f_locals["attr"] in LOCK_METHODS or + frame.f_locals["attr"] in QUEUE_METHODS): + real_method = frame.f_locals["attr"] + if method_name == "call_begin": + real_method += "_begin" + elif method_name == "call_end": + real_method += "_end" + else: + return + if real_method == "release_end": + # do not log release end. Maybe use it later + return + send_message("threading_event", event_time, t.getName(), get_thread_id(t), "lock", + real_method, back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(self_obj))) + + if real_method in ("put_end", "get_end"): + # fake release for queue, cause we don't call it directly + send_message("threading_event", event_time, t.getName(), get_thread_id(t), "lock", + "release", back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(self_obj))) + # print(event_time, t.getName(), get_thread_id(t), "lock", + # real_method, back.f_code.co_filename, back.f_lineno) + + except Exception: + pydev_log.exception() + + +class NameManager: + + def __init__(self, name_prefix): + self.tasks = {} + self.last = 0 + self.prefix = name_prefix + + def get(self, id): + if id not in self.tasks: + self.last += 1 + self.tasks[id] = self.prefix + "-" + str(self.last) + return self.tasks[id] + + +class AsyncioLogger: + + def __init__(self): + self.task_mgr = NameManager("Task") + self.coro_mgr = NameManager("Coro") + self.start_time = cur_time() + + def get_task_id(self, frame): + while frame is not None: + if "self" in frame.f_locals: + self_obj = frame.f_locals["self"] + if isinstance(self_obj, asyncio.Task): + method_name = frame.f_code.co_name + if method_name == "_step": + return id(self_obj) + frame = frame.f_back + return None + + def log_event(self, frame): + event_time = cur_time() - self.start_time + + # Debug loop iterations + # if isinstance(self_obj, asyncio.base_events.BaseEventLoop): + # if method_name == "_run_once": + # print("Loop iteration") + + if not hasattr(frame, "f_back") or frame.f_back is None: + return + back = frame.f_back + + if "self" in frame.f_locals: + self_obj = frame.f_locals["self"] + if isinstance(self_obj, asyncio.Task): + method_name = frame.f_code.co_name + if method_name == "set_result": + task_id = id(self_obj) + task_name = self.task_mgr.get(str(task_id)) + send_message("asyncio_event", event_time, task_name, task_name, "thread", "stop", frame.f_code.co_filename, + frame.f_lineno, frame) + + method_name = back.f_code.co_name + if method_name == "__init__": + task_id = id(self_obj) + task_name = self.task_mgr.get(str(task_id)) + send_message("asyncio_event", event_time, task_name, task_name, "thread", "start", frame.f_code.co_filename, + frame.f_lineno, frame) + + method_name = frame.f_code.co_name + if isinstance(self_obj, asyncio.Lock): + if method_name in ("acquire", "release"): + task_id = self.get_task_id(frame) + task_name = self.task_mgr.get(str(task_id)) + + if method_name == "acquire": + if not self_obj._waiters and not self_obj.locked(): + send_message("asyncio_event", event_time, task_name, task_name, "lock", + method_name + "_begin", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + if self_obj.locked(): + method_name += "_begin" + else: + method_name += "_end" + elif method_name == "release": + method_name += "_end" + + send_message("asyncio_event", event_time, task_name, task_name, "lock", + method_name, frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + + if isinstance(self_obj, asyncio.Queue): + if method_name in ("put", "get", "_put", "_get"): + task_id = self.get_task_id(frame) + task_name = self.task_mgr.get(str(task_id)) + + if method_name == "put": + send_message("asyncio_event", event_time, task_name, task_name, "lock", + "acquire_begin", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + elif method_name == "_put": + send_message("asyncio_event", event_time, task_name, task_name, "lock", + "acquire_end", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + send_message("asyncio_event", event_time, task_name, task_name, "lock", + "release", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + elif method_name == "get": + back = frame.f_back + if back.f_code.co_name != "send": + send_message("asyncio_event", event_time, task_name, task_name, "lock", + "acquire_begin", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + else: + send_message("asyncio_event", event_time, task_name, task_name, "lock", + "acquire_end", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) + send_message("asyncio_event", event_time, task_name, task_name, "lock", + "release", frame.f_code.co_filename, frame.f_lineno, frame, lock_id=str(id(self_obj))) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/pydevd_thread_wrappers.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/pydevd_thread_wrappers.py new file mode 100644 index 0000000..435e287 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_concurrency_analyser/pydevd_thread_wrappers.py @@ -0,0 +1,82 @@ +from _pydev_imps._pydev_saved_modules import threading + + +def wrapper(fun): + def pydev_after_run_call(): + pass + + def inner(*args, **kwargs): + fun(*args, **kwargs) + pydev_after_run_call() + return inner + + +def wrap_attr(obj, attr): + t_save_start = getattr(obj, attr) + setattr(obj, attr, wrapper(t_save_start)) + obj._pydev_run_patched = True + + +class ObjectWrapper(object): + def __init__(self, obj): + self.wrapped_object = obj + try: + import functools + functools.update_wrapper(self, obj) + except: + pass + + def __getattr__(self, attr): + orig_attr = getattr(self.wrapped_object, attr) #.__getattribute__(attr) + if callable(orig_attr): + def patched_attr(*args, **kwargs): + self.call_begin(attr) + result = orig_attr(*args, **kwargs) + self.call_end(attr) + if result == self.wrapped_object: + return self + return result + return patched_attr + else: + return orig_attr + + def call_begin(self, attr): + pass + + def call_end(self, attr): + pass + + def __enter__(self): + self.call_begin("__enter__") + self.wrapped_object.__enter__() + self.call_end("__enter__") + + def __exit__(self, exc_type, exc_val, exc_tb): + self.call_begin("__exit__") + self.wrapped_object.__exit__(exc_type, exc_val, exc_tb) + + +def factory_wrapper(fun): + def inner(*args, **kwargs): + obj = fun(*args, **kwargs) + return ObjectWrapper(obj) + return inner + + +def wrap_threads(): + # TODO: add wrappers for thread and _thread + # import _thread as mod + # print("Thread imported") + # mod.start_new_thread = wrapper(mod.start_new_thread) + import threading + threading.Lock = factory_wrapper(threading.Lock) + threading.RLock = factory_wrapper(threading.RLock) + + # queue patching + try: + import queue # @UnresolvedImport + queue.Queue = factory_wrapper(queue.Queue) + except: + import Queue + Queue.Queue = factory_wrapper(Queue.Queue) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_file_utils.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_file_utils.py new file mode 100644 index 0000000..6a4d876 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_file_utils.py @@ -0,0 +1,746 @@ +r''' + This module provides utilities to get the absolute filenames so that we can be sure that: + - The case of a file will match the actual file in the filesystem (otherwise breakpoints won't be hit). + - Providing means for the user to make path conversions when doing a remote debugging session in + one machine and debugging in another. + + To do that, the PATHS_FROM_ECLIPSE_TO_PYTHON constant must be filled with the appropriate paths. + + @note: + in this context, the server is where your python process is running + and the client is where eclipse is running. + + E.g.: + If the server (your python process) has the structure + /user/projects/my_project/src/package/module1.py + + and the client has: + c:\my_project\src\package\module1.py + + the PATHS_FROM_ECLIPSE_TO_PYTHON would have to be: + PATHS_FROM_ECLIPSE_TO_PYTHON = [(r'c:\my_project\src', r'/user/projects/my_project/src')] + + alternatively, this can be set with an environment variable from the command line: + set PATHS_FROM_ECLIPSE_TO_PYTHON=[['c:\my_project\src','/user/projects/my_project/src']] + + @note: DEBUG_CLIENT_SERVER_TRANSLATION can be set to True to debug the result of those translations + + @note: the case of the paths is important! Note that this can be tricky to get right when one machine + uses a case-independent filesystem and the other uses a case-dependent filesystem (if the system being + debugged is case-independent, 'normcase()' should be used on the paths defined in PATHS_FROM_ECLIPSE_TO_PYTHON). + + @note: all the paths with breakpoints must be translated (otherwise they won't be found in the server) + + @note: to enable remote debugging in the target machine (pydev extensions in the eclipse installation) + import pydevd;pydevd.settrace(host, stdoutToServer, stderrToServer, port, suspend) + + see parameter docs on pydevd.py + + @note: for doing a remote debugging session, all the pydevd_ files must be on the server accessible + through the PYTHONPATH (and the PATHS_FROM_ECLIPSE_TO_PYTHON only needs to be set on the target + machine for the paths that'll actually have breakpoints). +''' + +from _pydev_bundle import pydev_log +from _pydevd_bundle.pydevd_constants import IS_PY2, IS_PY3K, DebugInfoHolder, IS_WINDOWS, IS_JYTHON +from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding +from _pydevd_bundle.pydevd_comm_constants import file_system_encoding, filesystem_encoding_is_utf8 +from _pydev_bundle.pydev_log import error_once + +import json +import os.path +import sys +import itertools +import ntpath +from functools import partial + +_nt_os_normcase = ntpath.normcase +basename = os.path.basename +exists = os.path.exists +join = os.path.join + +try: + FileNotFoundError +except NameError: + FileNotFoundError = IOError # noqa + +try: + rPath = os.path.realpath # @UndefinedVariable +except: + # jython does not support os.path.realpath + # realpath is a no-op on systems without islink support + rPath = os.path.abspath + +# defined as a list of tuples where the 1st element of the tuple is the path in the client machine +# and the 2nd element is the path in the server machine. +# see module docstring for more details. +try: + PATHS_FROM_ECLIPSE_TO_PYTHON = json.loads(os.environ.get('PATHS_FROM_ECLIPSE_TO_PYTHON', '[]')) +except Exception: + sys.stderr.write('Error loading PATHS_FROM_ECLIPSE_TO_PYTHON from environment variable.\n') + pydev_log.exception() + PATHS_FROM_ECLIPSE_TO_PYTHON = [] +else: + if not isinstance(PATHS_FROM_ECLIPSE_TO_PYTHON, list): + sys.stderr.write('Expected PATHS_FROM_ECLIPSE_TO_PYTHON loaded from environment variable to be a list.\n') + PATHS_FROM_ECLIPSE_TO_PYTHON = [] + else: + # Converting json lists to tuple + PATHS_FROM_ECLIPSE_TO_PYTHON = [tuple(x) for x in PATHS_FROM_ECLIPSE_TO_PYTHON] + +# example: +# PATHS_FROM_ECLIPSE_TO_PYTHON = [ +# (r'd:\temp\temp_workspace_2\test_python\src\yyy\yyy', +# r'd:\temp\temp_workspace_2\test_python\src\hhh\xxx') +# ] + +convert_to_long_pathname = lambda filename:filename +convert_to_short_pathname = lambda filename:filename +get_path_with_real_case = lambda filename:filename + +if sys.platform == 'win32': + try: + import ctypes + from ctypes.wintypes import MAX_PATH, LPCWSTR, LPWSTR, DWORD + + GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW # noqa + GetLongPathName.argtypes = [LPCWSTR, LPWSTR, DWORD] + GetLongPathName.restype = DWORD + + GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW # noqa + GetShortPathName.argtypes = [LPCWSTR, LPWSTR, DWORD] + GetShortPathName.restype = DWORD + + def _convert_to_long_pathname(filename): + buf = ctypes.create_unicode_buffer(MAX_PATH) + + if IS_PY2 and isinstance(filename, str): + filename = filename.decode(getfilesystemencoding()) + rv = GetLongPathName(filename, buf, MAX_PATH) + if rv != 0 and rv <= MAX_PATH: + filename = buf.value + + if IS_PY2: + filename = filename.encode(getfilesystemencoding()) + return filename + + def _convert_to_short_pathname(filename): + buf = ctypes.create_unicode_buffer(MAX_PATH) + + if IS_PY2 and isinstance(filename, str): + filename = filename.decode(getfilesystemencoding()) + rv = GetShortPathName(filename, buf, MAX_PATH) + if rv != 0 and rv <= MAX_PATH: + filename = buf.value + + if IS_PY2: + filename = filename.encode(getfilesystemencoding()) + return filename + + # Note that we have a cache for previous list dirs... the only case where this may be an + # issue is if the user actually changes the case of an existing file on windows while + # the debugger is executing (as this seems very unlikely and the cache can save a + # reasonable time -- especially on mapped drives -- it seems nice to have it). + _listdir_cache = {} + + def _resolve_listing(resolved, iter_parts, cache=_listdir_cache): + while True: # Note: while True to make iterative and not recursive + try: + resolve_lowercase = next(iter_parts) # must be lowercase already + except StopIteration: + return resolved + + resolved_lower = resolved.lower() + + resolved_joined = cache.get((resolved_lower, resolve_lowercase)) + if resolved_joined is None: + dir_contents = cache.get(resolved_lower) + if dir_contents is None: + dir_contents = cache[resolved_lower] = os.listdir(resolved) + + for filename in dir_contents: + if filename.lower() == resolve_lowercase: + resolved_joined = os.path.join(resolved, filename) + cache[(resolved_lower, resolve_lowercase)] = resolved_joined + break + else: + raise FileNotFoundError('Unable to find: %s in %s' % ( + resolve_lowercase, resolved)) + + resolved = resolved_joined + + def _get_path_with_real_case(filename): + # Note: this previously made: + # convert_to_long_pathname(convert_to_short_pathname(filename)) + # but this is no longer done because we can't rely on getting the shortname + # consistently (there are settings to disable it on Windows). + # So, using approach which resolves by listing the dir. + + if IS_PY2 and isinstance(filename, unicode): # noqa + filename = filename.encode(getfilesystemencoding()) + + if '~' in filename: + filename = convert_to_long_pathname(filename) + + if filename.startswith('<') or not os.path.exists(filename): + return filename # Not much we can do. + + drive, parts = os.path.splitdrive(os.path.normpath(filename)) + drive = drive.upper() + while parts.startswith(os.path.sep): + parts = parts[1:] + drive += os.path.sep + parts = parts.lower().split(os.path.sep) + + try: + return _resolve_listing(drive, iter(parts)) + except FileNotFoundError: + _listdir_cache.clear() + # Retry once after clearing the cache we have. + try: + return _resolve_listing(drive, iter(parts)) + except FileNotFoundError: + if os.path.exists(filename): + # This is really strange, ask the user to report as error. + sys.stderr.write('\npydev debugger: critical: unable to get real case for file. Details:\n' + 'filename: %s\ndrive: %s\nparts: %s\n' + '(please create a ticket in the tracker to address this).\n\n' % ( + filename, drive, parts)) + pydev_log.exception() + # Don't fail, just return the original file passed. + return filename + + # Check that it actually works + _get_path_with_real_case(__file__) + except: + # Something didn't quite work out, leave no-op conversions in place. + if DebugInfoHolder.DEBUG_TRACE_LEVEL > 2: + pydev_log.exception() + else: + convert_to_long_pathname = _convert_to_long_pathname + convert_to_short_pathname = _convert_to_short_pathname + get_path_with_real_case = _get_path_with_real_case + +elif IS_JYTHON and IS_WINDOWS: + + def get_path_with_real_case(filename): + from java.io import File # noqa + f = File(filename) + ret = f.getCanonicalPath() + if IS_PY2 and not isinstance(ret, str): + return ret.encode(getfilesystemencoding()) + return ret + +if IS_JYTHON: + + def _normcase_windows(filename): + return filename.lower() + +else: + + def _normcase_windows(filename): + # `normcase` doesn't lower case on Python 2 for non-English locale, so we should do it manually. + if '~' in filename: + filename = convert_to_long_pathname(filename) + + filename = _nt_os_normcase(filename) + return filename.lower() + + +def _normcase_linux(filename): + return filename # no-op + + +if IS_WINDOWS: + normcase = _normcase_windows + +else: + normcase = _normcase_linux + +_ide_os = 'WINDOWS' if IS_WINDOWS else 'UNIX' + +_normcase_from_client = normcase + +DEBUG_CLIENT_SERVER_TRANSLATION = os.environ.get('DEBUG_PYDEVD_PATHS_TRANSLATION', 'False').lower() in ('1', 'true') + + +def set_ide_os(os): + ''' + We need to set the IDE os because the host where the code is running may be + actually different from the client (and the point is that we want the proper + paths to translate from the client to the server). + + :param os: + 'UNIX' or 'WINDOWS' + ''' + global _ide_os + global _normcase_from_client + prev = _ide_os + if os == 'WIN': # Apparently PyCharm uses 'WIN' (https://github.com/fabioz/PyDev.Debugger/issues/116) + os = 'WINDOWS' + + assert os in ('WINDOWS', 'UNIX') + + if DEBUG_CLIENT_SERVER_TRANSLATION: + print('pydev debugger: client OS: %s' % (os,)) + + _normcase_from_client = normcase + if os == 'WINDOWS': + + # Client in Windows and server in Unix, we need to normalize the case. + if not IS_WINDOWS: + _normcase_from_client = _normcase_windows + + else: + # Client in Unix and server in Windows, we can't normalize the case. + if IS_WINDOWS: + _normcase_from_client = _normcase_linux + + if prev != os: + _ide_os = os + # We need to (re)setup how the client <-> server translation works to provide proper separators. + setup_client_server_paths(_last_client_server_paths_set) + + +# Caches filled as requested during the debug session. +NORM_PATHS_CONTAINER = {} +NORM_PATHS_AND_BASE_CONTAINER = {} + + +def _NormFile(filename): + _abs_path, real_path = _NormPaths(filename) + return real_path + + +def _AbsFile(filename): + abs_path, _real_path = _NormPaths(filename) + return abs_path + + +# Returns tuple of absolute path and real path for given filename +def _NormPaths(filename): + try: + return NORM_PATHS_CONTAINER[filename] + except KeyError: + if filename.__class__ != str: + raise AssertionError('Paths passed to _NormPaths must be str. Found: %s (%s)' % (filename, type(filename))) + abs_path = _NormPath(filename, os.path.abspath) + real_path = _NormPath(filename, rPath) + + # cache it for fast access later + NORM_PATHS_CONTAINER[filename] = abs_path, real_path + return abs_path, real_path + + +def _NormPath(filename, normpath): + if filename.startswith('<'): + # Not really a file, rather a synthetic name like or ; + # shouldn't be normalized. + return filename + + r = normpath(filename) + ind = r.find('.zip') + if ind == -1: + ind = r.find('.egg') + if ind != -1: + ind += 4 + zip_path = r[:ind] + inner_path = r[ind:] + if inner_path.startswith('!'): + # Note (fabioz): although I can replicate this by creating a file ending as + # .zip! or .egg!, I don't really know what's the real-world case for this + # (still kept as it was added by @jetbrains, but it should probably be reviewed + # later on). + # Note 2: it goes hand-in-hand with 'exists'. + inner_path = inner_path[1:] + zip_path = zip_path + '!' + + if inner_path.startswith('/') or inner_path.startswith('\\'): + inner_path = inner_path[1:] + if inner_path: + r = join(normcase(zip_path), inner_path) + return r + + r = normcase(r) + return r + + +_ZIP_SEARCH_CACHE = {} +_NOT_FOUND_SENTINEL = object() + + +def exists(file): + if os.path.exists(file): + return file + + ind = file.find('.zip') + if ind == -1: + ind = file.find('.egg') + + if ind != -1: + ind += 4 + zip_path = file[:ind] + inner_path = file[ind:] + if inner_path.startswith("!"): + # Note (fabioz): although I can replicate this by creating a file ending as + # .zip! or .egg!, I don't really know what's the real-world case for this + # (still kept as it was added by @jetbrains, but it should probably be reviewed + # later on). + # Note 2: it goes hand-in-hand with '_NormPath'. + inner_path = inner_path[1:] + zip_path = zip_path + '!' + + zip_file_obj = _ZIP_SEARCH_CACHE.get(zip_path, _NOT_FOUND_SENTINEL) + if zip_file_obj is None: + return False + elif zip_file_obj is _NOT_FOUND_SENTINEL: + try: + import zipfile + zip_file_obj = zipfile.ZipFile(zip_path, 'r') + _ZIP_SEARCH_CACHE[zip_path] = zip_file_obj + except: + _ZIP_SEARCH_CACHE[zip_path] = _NOT_FOUND_SENTINEL + return False + + try: + if inner_path.startswith('/') or inner_path.startswith('\\'): + inner_path = inner_path[1:] + + _info = zip_file_obj.getinfo(inner_path.replace('\\', '/')) + + return join(zip_path, inner_path) + except KeyError: + return None + return None + + +# Now, let's do a quick test to see if we're working with a version of python that has no problems +# related to the names generated... +try: + try: + code = rPath.func_code + except AttributeError: + code = rPath.__code__ + if not exists(_NormFile(code.co_filename)): + sys.stderr.write('-------------------------------------------------------------------------------\n') + sys.stderr.write('pydev debugger: CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)\n') + sys.stderr.write('pydev debugger: The debugger may still function, but it will work slower and may miss breakpoints.\n') + sys.stderr.write('pydev debugger: Related bug: http://bugs.python.org/issue1666807\n') + sys.stderr.write('-------------------------------------------------------------------------------\n') + sys.stderr.flush() + + NORM_SEARCH_CACHE = {} + + initial_norm_paths = _NormPaths + + def _NormPaths(filename): # Let's redefine _NormPaths to work with paths that may be incorrect + try: + return NORM_SEARCH_CACHE[filename] + except KeyError: + abs_path, real_path = initial_norm_paths(filename) + if not exists(real_path): + # We must actually go on and check if we can find it as if it was a relative path for some of the paths in the pythonpath + for path in sys.path: + abs_path, real_path = initial_norm_paths(join(path, filename)) + if exists(real_path): + break + else: + sys.stderr.write('pydev debugger: Unable to find real location for: %s\n' % (filename,)) + abs_path = filename + real_path = filename + + NORM_SEARCH_CACHE[filename] = abs_path, real_path + return abs_path, real_path + +except: + # Don't fail if there's something not correct here -- but at least print it to the user so that we can correct that + pydev_log.exception() + +# Note: as these functions may be rebound, users should always import +# pydevd_file_utils and then use: +# +# pydevd_file_utils.norm_file_to_client +# pydevd_file_utils.norm_file_to_server +# +# instead of importing any of those names to a given scope. + + +def _path_to_expected_str(filename): + if IS_PY2: + if not filesystem_encoding_is_utf8 and hasattr(filename, "decode"): + # filename_in_utf8 is a byte string encoded using the file system encoding + # convert it to utf8 + filename = filename.decode(file_system_encoding) + + if not isinstance(filename, bytes): + filename = filename.encode('utf-8') + + else: # py3 + if isinstance(filename, bytes): + filename = filename.decode(file_system_encoding) + + return filename + + +def _original_file_to_client(filename, cache={}): + try: + return cache[filename] + except KeyError: + translated = _path_to_expected_str(get_path_with_real_case(_AbsFile(filename))) + cache[filename] = translated + return cache[filename] + + +_original_file_to_server = _NormFile + +norm_file_to_client = _original_file_to_client +norm_file_to_server = _original_file_to_server + + +def _fix_path(path, sep): + if path.endswith('/') or path.endswith('\\'): + path = path[:-1] + + if sep != '/': + path = path.replace('/', sep) + return path + + +_last_client_server_paths_set = [] + +_source_reference_to_server_filename = {} +_client_filename_in_utf8_to_source_reference = {} +_next_source_reference = partial(next, itertools.count(1)) + + +def get_client_filename_source_reference(client_filename): + return _client_filename_in_utf8_to_source_reference.get(client_filename, 0) + + +def get_server_filename_from_source_reference(source_reference): + return _source_reference_to_server_filename.get(source_reference, '') + + +def setup_client_server_paths(paths): + '''paths is the same format as PATHS_FROM_ECLIPSE_TO_PYTHON''' + + global norm_file_to_client + global norm_file_to_server + global _last_client_server_paths_set + global _next_source_reference + + _last_client_server_paths_set = paths[:] + + _source_reference_to_server_filename.clear() + _client_filename_in_utf8_to_source_reference.clear() + _next_source_reference = partial(next, itertools.count(1)) + + # Work on the client and server slashes. + python_sep = '\\' if IS_WINDOWS else '/' + eclipse_sep = '\\' if _ide_os == 'WINDOWS' else '/' + + norm_filename_to_server_container = {} + norm_filename_to_client_container = {} + initial_paths = list(paths) + paths_from_eclipse_to_python = initial_paths[:] + + # Apply normcase to the existing paths to follow the os preferences. + + for i, (path0, path1) in enumerate(paths_from_eclipse_to_python[:]): + if IS_PY2: + if isinstance(path0, unicode): # noqa + path0 = path0.encode(sys.getfilesystemencoding()) + if isinstance(path1, unicode): # noqa + path1 = path1.encode(sys.getfilesystemencoding()) + + path0 = _fix_path(path0, eclipse_sep) + path1 = _fix_path(path1, python_sep) + initial_paths[i] = (path0, path1) + + paths_from_eclipse_to_python[i] = (_normcase_from_client(path0), normcase(path1)) + + if not paths_from_eclipse_to_python: + # no translation step needed (just inline the calls) + norm_file_to_client = _original_file_to_client + norm_file_to_server = _original_file_to_server + return + + # only setup translation functions if absolutely needed! + def _norm_file_to_server(filename, cache=norm_filename_to_server_container): + # Eclipse will send the passed filename to be translated to the python process + # So, this would be 'NormFileFromEclipseToPython' + try: + return cache[filename] + except KeyError: + if eclipse_sep != python_sep: + # Make sure that the separators are what we expect from the IDE. + filename = filename.replace(python_sep, eclipse_sep) + + # used to translate a path from the client to the debug server + translated = filename + translated_normalized = _normcase_from_client(filename) + for eclipse_prefix, server_prefix in paths_from_eclipse_to_python: + if translated_normalized.startswith(eclipse_prefix): + found_translation = True + if DEBUG_CLIENT_SERVER_TRANSLATION: + sys.stderr.write('pydev debugger: replacing to server: %s\n' % (filename,)) + translated = server_prefix + filename[len(eclipse_prefix):] + if DEBUG_CLIENT_SERVER_TRANSLATION: + sys.stderr.write('pydev debugger: sent to server: %s\n' % (translated,)) + break + else: + found_translation = False + + # Note that when going to the server, we do the replace first and only later do the norm file. + if eclipse_sep != python_sep: + translated = translated.replace(eclipse_sep, python_sep) + + if found_translation: + translated = _NormFile(translated) + else: + if not os.path.exists(translated): + if not translated.startswith('<'): + # This is a configuration error, so, write it always so + # that the user can fix it. + error_once('pydev debugger: unable to find translation for: "%s" in [%s] (please revise your path mappings).\n', + filename, ', '.join(['"%s"' % (x[0],) for x in paths_from_eclipse_to_python])) + else: + # It's possible that we had some round trip (say, we sent /usr/lib and received + # it back, so, having no translation is ok too). + translated = _NormFile(translated) + + cache[filename] = translated + return translated + + def _norm_file_to_client(filename, cache=norm_filename_to_client_container): + # The result of this method will be passed to eclipse + # So, this would be 'NormFileFromPythonToEclipse' + try: + return cache[filename] + except KeyError: + # used to translate a path from the debug server to the client + translated = _NormFile(filename) + + # After getting the real path, let's get it with the path with + # the real case and then obtain a new normalized copy, just in case + # the path is different now. + translated_proper_case = get_path_with_real_case(translated) + translated = _NormFile(translated_proper_case) + + path_mapping_applied = False + + if IS_WINDOWS: + if translated.lower() != translated_proper_case.lower(): + translated_proper_case = translated + if DEBUG_CLIENT_SERVER_TRANSLATION: + sys.stderr.write( + 'pydev debugger: _NormFile changed path (from: %s to %s)\n' % ( + translated_proper_case, translated)) + + for i, (eclipse_prefix, python_prefix) in enumerate(paths_from_eclipse_to_python): + if translated.startswith(python_prefix): + if DEBUG_CLIENT_SERVER_TRANSLATION: + sys.stderr.write('pydev debugger: replacing to client: %s\n' % (translated,)) + + # Note: use the non-normalized version. + eclipse_prefix = initial_paths[i][0] + translated = eclipse_prefix + translated_proper_case[len(python_prefix):] + if DEBUG_CLIENT_SERVER_TRANSLATION: + sys.stderr.write('pydev debugger: sent to client: %s\n' % (translated,)) + path_mapping_applied = True + break + else: + if DEBUG_CLIENT_SERVER_TRANSLATION: + sys.stderr.write('pydev debugger: to client: unable to find matching prefix for: %s in %s\n' % \ + (translated, [x[1] for x in paths_from_eclipse_to_python])) + translated = translated_proper_case + + if eclipse_sep != python_sep: + translated = translated.replace(python_sep, eclipse_sep) + + translated = _path_to_expected_str(translated) + + # The resulting path is not in the python process, so, we cannot do a _NormFile here, + # only at the beginning of this method. + cache[filename] = translated + + if translated not in _client_filename_in_utf8_to_source_reference: + if path_mapping_applied: + source_reference = 0 + else: + source_reference = _next_source_reference() + _client_filename_in_utf8_to_source_reference[translated] = source_reference + _source_reference_to_server_filename[source_reference] = filename + + return translated + + norm_file_to_server = _norm_file_to_server + norm_file_to_client = _norm_file_to_client + + +setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + + +# For given file f returns tuple of its absolute path, real path and base name +def get_abs_path_real_path_and_base_from_file(f): + try: + return NORM_PATHS_AND_BASE_CONTAINER[f] + except: + if _NormPaths is None: # Interpreter shutdown + return f + + if f is not None: + if f.endswith('.pyc'): + f = f[:-1] + elif f.endswith('$py.class'): + f = f[:-len('$py.class')] + '.py' + + abs_path, real_path = _NormPaths(f) + base = basename(real_path) + ret = abs_path, real_path, base + NORM_PATHS_AND_BASE_CONTAINER[f] = ret + return ret + + +def get_abs_path_real_path_and_base_from_frame(frame): + try: + return NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] + except: + # This one is just internal (so, does not need any kind of client-server translation) + f = frame.f_code.co_filename + if f is not None and f.startswith (('build/bdist.', 'build\\bdist.')): + # files from eggs in Python 2.7 have paths like build/bdist.linux-x86_64/egg/ + f = frame.f_globals['__file__'] + + if get_abs_path_real_path_and_base_from_file is None: # Interpreter shutdown + return f + + ret = get_abs_path_real_path_and_base_from_file(f) + # Also cache based on the frame.f_code.co_filename (if we had it inside build/bdist it can make a difference). + NORM_PATHS_AND_BASE_CONTAINER[frame.f_code.co_filename] = ret + return ret + + +def get_fullname(mod_name): + if IS_PY3K: + import pkgutil + else: + from _pydev_imps import _pydev_pkgutil_old as pkgutil + try: + loader = pkgutil.get_loader(mod_name) + except: + return None + if loader is not None: + for attr in ("get_filename", "_get_filename"): + meth = getattr(loader, attr, None) + if meth is not None: + return meth(mod_name) + return None + + +def get_package_dir(mod_name): + for path in sys.path: + mod_path = join(path, mod_name.replace('.', '/')) + if os.path.isdir(mod_path): + return mod_path + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/__init__.py new file mode 100644 index 0000000..afff0c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/__init__.py @@ -0,0 +1,5 @@ +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/django_debug.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/django_debug.py new file mode 100644 index 0000000..106e7f7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/django_debug.py @@ -0,0 +1,546 @@ +import inspect +import traceback + +from _pydev_bundle import pydev_log +from _pydevd_bundle.pydevd_breakpoints import LineBreakpoint +from _pydevd_bundle.pydevd_comm import CMD_SET_BREAK, CMD_ADD_EXCEPTION_BREAK +from _pydevd_bundle.pydevd_constants import STATE_SUSPEND, dict_iter_items, DJANGO_SUSPEND, IS_PY2 +from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, FCode, just_raised, ignore_exception_trace +from pydevd_file_utils import get_abs_path_real_path_and_base_from_file, normcase + +IS_DJANGO18 = False +IS_DJANGO19 = False +IS_DJANGO19_OR_HIGHER = False +try: + import django + version = django.VERSION + IS_DJANGO18 = version[0] == 1 and version[1] == 8 + IS_DJANGO19 = version[0] == 1 and version[1] == 9 + IS_DJANGO19_OR_HIGHER = ((version[0] == 1 and version[1] >= 9) or version[0] > 1) +except: + pass + + +class DjangoLineBreakpoint(LineBreakpoint): + + def __init__(self, file, line, condition, func_name, expression, hit_condition=None, is_logpoint=False): + self.file = file + LineBreakpoint.__init__(self, line, condition, func_name, expression, hit_condition=hit_condition, is_logpoint=is_logpoint) + + def is_triggered(self, template_frame_file, template_frame_line): + return self.file == template_frame_file and self.line == template_frame_line + + def __str__(self): + return "DjangoLineBreakpoint: %s-%d" % (self.file, self.line) + + +def add_line_breakpoint(plugin, pydb, type, file, line, condition, expression, func_name, hit_condition=None, is_logpoint=False): + if type == 'django-line': + breakpoint = DjangoLineBreakpoint(file, line, condition, func_name, expression, hit_condition=hit_condition, is_logpoint=is_logpoint) + if not hasattr(pydb, 'django_breakpoints'): + _init_plugin_breaks(pydb) + return breakpoint, pydb.django_breakpoints + return None + + +def add_exception_breakpoint(plugin, pydb, type, exception): + if type == 'django': + if not hasattr(pydb, 'django_exception_break'): + _init_plugin_breaks(pydb) + pydb.django_exception_break[exception] = True + return True + return False + + +def _init_plugin_breaks(pydb): + pydb.django_exception_break = {} + pydb.django_breakpoints = {} + + +def remove_exception_breakpoint(plugin, pydb, type, exception): + if type == 'django': + try: + del pydb.django_exception_break[exception] + return True + except: + pass + return False + + +def remove_all_exception_breakpoints(plugin, pydb): + if hasattr(pydb, 'django_exception_break'): + pydb.django_exception_break = {} + return True + return False + + +def get_breakpoints(plugin, pydb, type): + if type == 'django-line': + return pydb.django_breakpoints + return None + + +def _inherits(cls, *names): + if cls.__name__ in names: + return True + inherits_node = False + for base in inspect.getmro(cls): + if base.__name__ in names: + inherits_node = True + break + return inherits_node + + +def _is_django_render_call(frame, debug=False): + try: + name = frame.f_code.co_name + if name != 'render': + return False + + if 'self' not in frame.f_locals: + return False + + cls = frame.f_locals['self'].__class__ + + inherits_node = _inherits(cls, 'Node') + + if not inherits_node: + return False + + clsname = cls.__name__ + if IS_DJANGO19: + # in Django 1.9 we need to save the flag that there is included template + if clsname == 'IncludeNode': + if 'context' in frame.f_locals: + context = frame.f_locals['context'] + context._has_included_template = True + + return clsname != 'TextNode' and clsname != 'NodeList' + except: + pydev_log.exception() + return False + + +def _is_django_context_get_call(frame): + try: + if 'self' not in frame.f_locals: + return False + + cls = frame.f_locals['self'].__class__ + + return _inherits(cls, 'BaseContext') + except: + pydev_log.exception() + return False + + +def _is_django_resolve_call(frame): + try: + name = frame.f_code.co_name + if name != '_resolve_lookup': + return False + + if 'self' not in frame.f_locals: + return False + + cls = frame.f_locals['self'].__class__ + + clsname = cls.__name__ + return clsname == 'Variable' + except: + pydev_log.exception() + return False + + +def _is_django_suspended(thread): + return thread.additional_info.suspend_type == DJANGO_SUSPEND + + +def suspend_django(main_debugger, thread, frame, cmd=CMD_SET_BREAK): + if frame.f_lineno is None: + return None + + main_debugger.set_suspend(thread, cmd) + thread.additional_info.suspend_type = DJANGO_SUSPEND + + return frame + + +def _find_django_render_frame(frame): + while frame is not None and not _is_django_render_call(frame): + frame = frame.f_back + + return frame + +#======================================================================================================================= +# Django Frame +#======================================================================================================================= + + +def _read_file(filename): + # type: (str) -> str + if IS_PY2: + f = open(filename, 'r') + else: + f = open(filename, 'r', encoding='utf-8', errors='replace') + s = f.read() + f.close() + return s + + +def _offset_to_line_number(text, offset): + curLine = 1 + curOffset = 0 + while curOffset < offset: + if curOffset == len(text): + return -1 + c = text[curOffset] + if c == '\n': + curLine += 1 + elif c == '\r': + curLine += 1 + if curOffset < len(text) and text[curOffset + 1] == '\n': + curOffset += 1 + + curOffset += 1 + + return curLine + + +def _get_source_django_18_or_lower(frame): + # This method is usable only for the Django <= 1.8 + try: + node = frame.f_locals['self'] + if hasattr(node, 'source'): + return node.source + else: + if IS_DJANGO18: + # The debug setting was changed since Django 1.8 + pydev_log.error_once("WARNING: Template path is not available. Set the 'debug' option in the OPTIONS of a DjangoTemplates " + "backend.") + else: + # The debug setting for Django < 1.8 + pydev_log.error_once("WARNING: Template path is not available. Please set TEMPLATE_DEBUG=True in your settings.py to make " + "django template breakpoints working") + return None + + except: + pydev_log.exception() + return None + + +def _convert_to_str(s): + if IS_PY2: + if isinstance(s, unicode): + s = s.encode('utf-8') + return s + + +def _get_template_file_name(frame): + try: + if IS_DJANGO19: + # The Node source was removed since Django 1.9 + if 'context' in frame.f_locals: + context = frame.f_locals['context'] + if hasattr(context, '_has_included_template'): + # if there was included template we need to inspect the previous frames and find its name + back = frame.f_back + while back is not None and frame.f_code.co_name in ('render', '_render'): + locals = back.f_locals + if 'self' in locals: + self = locals['self'] + if self.__class__.__name__ == 'Template' and hasattr(self, 'origin') and \ + hasattr(self.origin, 'name'): + return normcase(_convert_to_str(self.origin.name)) + back = back.f_back + else: + if hasattr(context, 'template') and hasattr(context.template, 'origin') and \ + hasattr(context.template.origin, 'name'): + return normcase(_convert_to_str(context.template.origin.name)) + return None + elif IS_DJANGO19_OR_HIGHER: + # For Django 1.10 and later there is much simpler way to get template name + if 'self' in frame.f_locals: + self = frame.f_locals['self'] + if hasattr(self, 'origin') and hasattr(self.origin, 'name'): + return normcase(_convert_to_str(self.origin.name)) + return None + + source = _get_source_django_18_or_lower(frame) + if source is None: + pydev_log.debug("Source is None\n") + return None + fname = _convert_to_str(source[0].name) + + if fname == '': + pydev_log.debug("Source name is %s\n" % fname) + return None + else: + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(fname) + return abs_path_real_path_and_base[1] + except: + pydev_log.debug(traceback.format_exc()) + return None + + +def _get_template_line(frame): + if IS_DJANGO19_OR_HIGHER: + # The Node source was removed since Django 1.9 + self = frame.f_locals['self'] + if hasattr(self, 'token') and hasattr(self.token, 'lineno'): + return self.token.lineno + else: + return None + source = _get_source_django_18_or_lower(frame) + file_name = _get_template_file_name(frame) + try: + return _offset_to_line_number(_read_file(file_name), source[1][0]) + except: + return None + + +class DjangoTemplateFrame(object): + + IS_PLUGIN_FRAME = True + + def __init__(self, frame): + file_name = _get_template_file_name(frame) + self._back_context = frame.f_locals['context'] + self.f_code = FCode('Django Template', file_name) + self.f_lineno = _get_template_line(frame) + self.f_back = frame + self.f_globals = {} + self.f_locals = self._collect_context(self._back_context) + self.f_trace = None + + def _collect_context(self, context): + res = {} + try: + for d in context.dicts: + for k, v in d.items(): + res[k] = v + except AttributeError: + pass + return res + + def _change_variable(self, name, value): + for d in self._back_context.dicts: + for k, v in d.items(): + if k == name: + d[k] = value + + +class DjangoTemplateSyntaxErrorFrame(object): + + IS_PLUGIN_FRAME = True + + def __init__(self, frame, filename, lineno, f_locals): + self.f_code = FCode('Django TemplateSyntaxError', filename) + self.f_lineno = lineno + self.f_back = frame + self.f_globals = {} + self.f_locals = f_locals + self.f_trace = None + + +def change_variable(plugin, frame, attr, expression): + if isinstance(frame, DjangoTemplateFrame): + result = eval(expression, frame.f_globals, frame.f_locals) + frame._change_variable(attr, result) + return result + return False + + +def _is_django_variable_does_not_exist_exception_break_context(frame): + try: + name = frame.f_code.co_name + except: + name = None + return name in ('_resolve_lookup', 'find_template') + + +def _is_ignoring_failures(frame): + while frame is not None: + if frame.f_code.co_name == 'resolve': + ignore_failures = frame.f_locals.get('ignore_failures') + if ignore_failures: + return True + frame = frame.f_back + + return False + +#======================================================================================================================= +# Django Step Commands +#======================================================================================================================= + + +def can_skip(plugin, main_debugger, frame): + if main_debugger.django_breakpoints: + if _is_django_render_call(frame): + return False + + if main_debugger.django_exception_break: + module_name = frame.f_globals.get('__name__', '') + + if module_name == 'django.template.base': + # Exceptions raised at django.template.base must be checked. + return False + + return True + + +def has_exception_breaks(plugin): + if len(plugin.main_debugger.django_exception_break) > 0: + return True + return False + + +def has_line_breaks(plugin): + for file, breakpoints in dict_iter_items(plugin.main_debugger.django_breakpoints): + if len(breakpoints) > 0: + return True + return False + + +def cmd_step_into(plugin, main_debugger, frame, event, args, stop_info, stop): + info = args[2] + thread = args[3] + plugin_stop = False + if _is_django_suspended(thread): + stop_info['django_stop'] = event == 'call' and _is_django_render_call(frame) + plugin_stop = stop_info['django_stop'] + stop = stop and _is_django_resolve_call(frame.f_back) and not _is_django_context_get_call(frame) + if stop: + info.pydev_django_resolve_frame = True # we remember that we've go into python code from django rendering frame + return stop, plugin_stop + + +def cmd_step_over(plugin, main_debugger, frame, event, args, stop_info, stop): + info = args[2] + thread = args[3] + plugin_stop = False + if _is_django_suspended(thread): + stop_info['django_stop'] = event == 'call' and _is_django_render_call(frame) + plugin_stop = stop_info['django_stop'] + stop = False + return stop, plugin_stop + else: + if event == 'return' and info.pydev_django_resolve_frame and _is_django_resolve_call(frame.f_back): + # we return to Django suspend mode and should not stop before django rendering frame + info.pydev_step_stop = frame.f_back + info.pydev_django_resolve_frame = False + thread.additional_info.suspend_type = DJANGO_SUSPEND + stop = info.pydev_step_stop is frame and event in ('line', 'return') + return stop, plugin_stop + + +def stop(plugin, main_debugger, frame, event, args, stop_info, arg, step_cmd): + main_debugger = args[0] + thread = args[3] + if 'django_stop' in stop_info and stop_info['django_stop']: + frame = suspend_django(main_debugger, thread, DjangoTemplateFrame(frame), step_cmd) + if frame: + main_debugger.do_wait_suspend(thread, frame, event, arg) + return True + return False + + +def get_breakpoint(plugin, main_debugger, pydb_frame, frame, event, args): + main_debugger = args[0] + filename = args[1] + info = args[2] + flag = False + django_breakpoint = None + new_frame = None + type = 'django' + + if event == 'call' and info.pydev_state != STATE_SUSPEND and \ + main_debugger.django_breakpoints and _is_django_render_call(frame): + filename = _get_template_file_name(frame) + pydev_log.debug("Django is rendering a template: %s\n" % filename) + django_breakpoints_for_file = main_debugger.django_breakpoints.get(filename) + if django_breakpoints_for_file: + pydev_log.debug("Breakpoints for that file: %s\n" % django_breakpoints_for_file) + template_line = _get_template_line(frame) + pydev_log.debug("Tracing template line: %s\n" % str(template_line)) + + if template_line in django_breakpoints_for_file: + django_breakpoint = django_breakpoints_for_file[template_line] + flag = True + new_frame = DjangoTemplateFrame(frame) + return flag, django_breakpoint, new_frame, type + + +def suspend(plugin, main_debugger, thread, frame, bp_type): + if bp_type == 'django': + return suspend_django(main_debugger, thread, DjangoTemplateFrame(frame)) + return None + + +def _get_filename_from_origin_in_parent_frame_locals(frame, parent_frame_name): + filename = None + parent_frame = frame + while parent_frame.f_code.co_name != parent_frame_name: + parent_frame = parent_frame.f_back + + origin = None + if parent_frame is not None: + origin = parent_frame.f_locals.get('origin') + + if hasattr(origin, 'name') and origin.name is not None: + filename = normcase(_convert_to_str(origin.name)) + return filename + + +def exception_break(plugin, main_debugger, pydb_frame, frame, args, arg): + main_debugger = args[0] + thread = args[3] + exception, value, trace = arg + + if main_debugger.django_exception_break and exception is not None: + if exception.__name__ in ['VariableDoesNotExist', 'TemplateDoesNotExist', 'TemplateSyntaxError'] and \ + just_raised(trace) and not ignore_exception_trace(trace): + + if exception.__name__ == 'TemplateSyntaxError': + # In this case we don't actually have a regular render frame with the context + # (we didn't really get to that point). + token = getattr(value, 'token', None) + + if token is None: + # Django 1.7 does not have token in exception. Try to get it from locals. + token = frame.f_locals.get('token') + + lineno = getattr(token, 'lineno', None) + + filename = None + if lineno is not None: + filename = _get_filename_from_origin_in_parent_frame_locals(frame, 'get_template') + + if filename is None: + # Django 1.7 does not have origin in get_template. Try to get it from + # load_template. + filename = _get_filename_from_origin_in_parent_frame_locals(frame, 'load_template') + + if filename is not None and lineno is not None: + syntax_error_frame = DjangoTemplateSyntaxErrorFrame( + frame, filename, lineno, {'token': token, 'exception': exception}) + + suspend_frame = suspend_django( + main_debugger, thread, syntax_error_frame, CMD_ADD_EXCEPTION_BREAK) + return True, suspend_frame + + elif exception.__name__ == 'VariableDoesNotExist': + if _is_django_variable_does_not_exist_exception_break_context(frame): + if not getattr(exception, 'silent_variable_failure', False) and not _is_ignoring_failures(frame): + render_frame = _find_django_render_frame(frame) + if render_frame: + suspend_frame = suspend_django( + main_debugger, thread, DjangoTemplateFrame(render_frame), CMD_ADD_EXCEPTION_BREAK) + if suspend_frame: + add_exception_to_frame(suspend_frame, (exception, value, trace)) + thread.additional_info.pydev_message = 'VariableDoesNotExist' + suspend_frame.f_back = frame + frame = suspend_frame + return True, frame + + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/README.md b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/README.md new file mode 100644 index 0000000..030e303 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/README.md @@ -0,0 +1,30 @@ +Extensions allow extending the debugger without modifying the debugger code. This is implemented with explicit namespace +packages. + +To implement your own extension: + +1. Ensure that the root folder of your extension is in sys.path (add it to PYTHONPATH) +2. Ensure that your module follows the directory structure below +3. The ``__init__.py`` files inside the pydevd_plugin and extension folder must contain the preamble below, +and nothing else. +Preamble: +```python +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) +``` +4. Your plugin name inside the extensions folder must start with `"pydevd_plugin"` +5. Implement one or more of the abstract base classes defined in `_pydevd_bundle.pydevd_extension_api`. This can be done +by either inheriting from them or registering with the abstract base class. + +* Directory structure: +``` +|-- root_directory-> must be on python path +| |-- pydevd_plugins +| | |-- __init__.py -> must contain preamble +| | |-- extensions +| | | |-- __init__.py -> must contain preamble +| | | |-- pydevd_plugin_plugin_name.py +``` \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/__init__.py new file mode 100644 index 0000000..afff0c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/__init__.py @@ -0,0 +1,5 @@ +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/__init__.py new file mode 100644 index 0000000..afff0c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/__init__.py @@ -0,0 +1,5 @@ +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_helpers.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_helpers.py new file mode 100644 index 0000000..7c5a4fe --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_helpers.py @@ -0,0 +1,26 @@ +import sys + + +def find_cached_module(mod_name): + return sys.modules.get(mod_name, None) + +def find_mod_attr(mod_name, attr): + mod = find_cached_module(mod_name) + if mod is None: + return None + return getattr(mod, attr, None) + + +def find_class_name(val): + class_name = str(val.__class__) + if class_name.find('.') != -1: + class_name = class_name.split('.')[-1] + + elif class_name.find("'") != -1: #does not have '.' (could be something like ) + class_name = class_name[class_name.index("'") + 1:] + + if class_name.endswith("'>"): + class_name = class_name[:-2] + + return class_name + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugin_numpy_types.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugin_numpy_types.py new file mode 100644 index 0000000..0a4dc8e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugin_numpy_types.py @@ -0,0 +1,87 @@ +from _pydevd_bundle.pydevd_extension_api import TypeResolveProvider +from _pydevd_bundle.pydevd_resolver import defaultResolver, MAX_ITEMS_TO_HANDLE, TOO_LARGE_ATTR, TOO_LARGE_MSG +from .pydevd_helpers import find_mod_attr + + +# ======================================================================================================================= +# NdArrayResolver +# ======================================================================================================================= +class NdArrayResolver: pass + + +class NdArrayItemsContainer: pass + + +class NDArrayTypeResolveProvider(object): + def can_provide(self, type_object, type_name): + nd_array = find_mod_attr('numpy', 'ndarray') + return nd_array is not None and issubclass(type_object, nd_array) + + ''' + This resolves a numpy ndarray returning some metadata about the NDArray + ''' + + def is_numeric(self, obj): + if not hasattr(obj, 'dtype'): + return False + return obj.dtype.kind in 'biufc' + + def resolve(self, obj, attribute): + if attribute == '__internals__': + return defaultResolver.get_dictionary(obj) + if attribute == 'min': + if self.is_numeric(obj) and obj.size > 0: + return obj.min() + else: + return None + if attribute == 'max': + if self.is_numeric(obj) and obj.size > 0: + return obj.max() + else: + return None + if attribute == 'shape': + return obj.shape + if attribute == 'dtype': + return obj.dtype + if attribute == 'size': + return obj.size + if attribute.startswith('['): + container = NdArrayItemsContainer() + i = 0 + format_str = '%0' + str(int(len(str(len(obj))))) + 'd' + for item in obj: + setattr(container, format_str % i, item) + i += 1 + if i > MAX_ITEMS_TO_HANDLE: + setattr(container, TOO_LARGE_ATTR, TOO_LARGE_MSG) + break + return container + return None + + def get_dictionary(self, obj): + ret = dict() + ret['__internals__'] = defaultResolver.get_dictionary(obj) + if obj.size > 1024 * 1024: + ret['min'] = 'ndarray too big, calculating min would slow down debugging' + ret['max'] = 'ndarray too big, calculating max would slow down debugging' + elif obj.size == 0: + ret['min'] = 'array is empty' + ret['max'] = 'array is empty' + else: + if self.is_numeric(obj): + ret['min'] = obj.min() + ret['max'] = obj.max() + else: + ret['min'] = 'not a numeric object' + ret['max'] = 'not a numeric object' + ret['shape'] = obj.shape + ret['dtype'] = obj.dtype + ret['size'] = obj.size + ret['[0:%s] ' % (len(obj))] = list(obj[0:MAX_ITEMS_TO_HANDLE]) + return ret + + +import sys + +if not sys.platform.startswith("java"): + TypeResolveProvider.register(NDArrayTypeResolveProvider) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugins_django_form_str.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugins_django_form_str.py new file mode 100644 index 0000000..8d64095 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/extensions/types/pydevd_plugins_django_form_str.py @@ -0,0 +1,16 @@ +from _pydevd_bundle.pydevd_extension_api import StrPresentationProvider +from .pydevd_helpers import find_mod_attr, find_class_name + + +class DjangoFormStr(object): + def can_provide(self, type_object, type_name): + form_class = find_mod_attr('django.forms', 'Form') + return form_class is not None and issubclass(type_object, form_class) + + def get_str(self, val): + return '%s: %r' % (find_class_name(val), val) + +import sys + +if not sys.platform.startswith("java"): + StrPresentationProvider.register(DjangoFormStr) diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/jinja2_debug.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/jinja2_debug.py new file mode 100644 index 0000000..9c8d0a8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_plugins/jinja2_debug.py @@ -0,0 +1,467 @@ +from _pydevd_bundle.pydevd_breakpoints import LineBreakpoint +from _pydevd_bundle.pydevd_constants import STATE_SUSPEND, dict_iter_items, dict_keys, JINJA2_SUSPEND, \ + IS_PY2 +from _pydevd_bundle.pydevd_comm import CMD_SET_BREAK, CMD_ADD_EXCEPTION_BREAK +from pydevd_file_utils import get_abs_path_real_path_and_base_from_file +from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, FCode +from _pydev_bundle import pydev_log + + +class Jinja2LineBreakpoint(LineBreakpoint): + + def __init__(self, file, line, condition, func_name, expression, hit_condition=None, is_logpoint=False): + self.file = file + LineBreakpoint.__init__(self, line, condition, func_name, expression, hit_condition=hit_condition, is_logpoint=is_logpoint) + + def is_triggered(self, template_frame_file, template_frame_line): + return self.file == template_frame_file and self.line == template_frame_line + + def __str__(self): + return "Jinja2LineBreakpoint: %s-%d" % (self.file, self.line) + + +def add_line_breakpoint(plugin, pydb, type, file, line, condition, expression, func_name, hit_condition=None, is_logpoint=False): + result = None + if type == 'jinja2-line': + breakpoint = Jinja2LineBreakpoint(file, line, condition, func_name, expression, hit_condition=hit_condition, is_logpoint=is_logpoint) + if not hasattr(pydb, 'jinja2_breakpoints'): + _init_plugin_breaks(pydb) + result = breakpoint, pydb.jinja2_breakpoints + return result + return result + + +def add_exception_breakpoint(plugin, pydb, type, exception): + if type == 'jinja2': + if not hasattr(pydb, 'jinja2_exception_break'): + _init_plugin_breaks(pydb) + pydb.jinja2_exception_break[exception] = True + return True + return False + + +def _init_plugin_breaks(pydb): + pydb.jinja2_exception_break = {} + pydb.jinja2_breakpoints = {} + + +def remove_all_exception_breakpoints(plugin, pydb): + if hasattr(pydb, 'jinja2_exception_break'): + pydb.jinja2_exception_break = {} + return True + return False + + +def remove_exception_breakpoint(plugin, pydb, type, exception): + if type == 'jinja2': + try: + del pydb.jinja2_exception_break[exception] + return True + except: + pass + return False + + +def get_breakpoints(plugin, pydb, type): + if type == 'jinja2-line': + return pydb.jinja2_breakpoints + return None + + +def _is_jinja2_render_call(frame): + try: + name = frame.f_code.co_name + if "__jinja_template__" in frame.f_globals and name in ("root", "loop", "macro") or name.startswith("block_"): + return True + return False + except: + pydev_log.exception() + return False + + +def _suspend_jinja2(pydb, thread, frame, cmd=CMD_SET_BREAK, message=None): + frame = Jinja2TemplateFrame(frame) + + if frame.f_lineno is None: + return None + + pydb.set_suspend(thread, cmd) + + thread.additional_info.suspend_type = JINJA2_SUSPEND + if cmd == CMD_ADD_EXCEPTION_BREAK: + # send exception name as message + if message: + message = str(message) + thread.additional_info.pydev_message = message + + return frame + + +def _is_jinja2_suspended(thread): + return thread.additional_info.suspend_type == JINJA2_SUSPEND + + +def _is_jinja2_context_call(frame): + return "_Context__obj" in frame.f_locals + + +def _is_jinja2_internal_function(frame): + return 'self' in frame.f_locals and frame.f_locals['self'].__class__.__name__ in \ + ('LoopContext', 'TemplateReference', 'Macro', 'BlockReference') + + +def _find_jinja2_render_frame(frame): + while frame is not None and not _is_jinja2_render_call(frame): + frame = frame.f_back + + return frame + +#======================================================================================================================= +# Jinja2 Frame +#======================================================================================================================= + + +class Jinja2TemplateFrame(object): + + IS_PLUGIN_FRAME = True + + def __init__(self, frame): + file_name = _get_jinja2_template_filename(frame) + self.back_context = None + if 'context' in frame.f_locals: + # sometimes we don't have 'context', e.g. in macros + self.back_context = frame.f_locals['context'] + self.f_code = FCode('template', file_name) + self.f_lineno = _get_jinja2_template_line(frame) + self.f_back = frame + self.f_globals = {} + self.f_locals = self.collect_context(frame) + self.f_trace = None + + def _get_real_var_name(self, orig_name): + # replace leading number for local variables + parts = orig_name.split('_') + if len(parts) > 1 and parts[0].isdigit(): + return parts[1] + return orig_name + + def collect_context(self, frame): + res = {} + for k, v in frame.f_locals.items(): + if not k.startswith('l_'): + res[k] = v + elif v and not _is_missing(v): + res[self._get_real_var_name(k[2:])] = v + if self.back_context is not None: + for k, v in self.back_context.items(): + res[k] = v + return res + + def _change_variable(self, frame, name, value): + in_vars_or_parents = False + if 'context' in frame.f_locals: + if name in frame.f_locals['context'].parent: + self.back_context.parent[name] = value + in_vars_or_parents = True + if name in frame.f_locals['context'].vars: + self.back_context.vars[name] = value + in_vars_or_parents = True + + l_name = 'l_' + name + if l_name in frame.f_locals: + if in_vars_or_parents: + frame.f_locals[l_name] = self.back_context.resolve(name) + else: + frame.f_locals[l_name] = value + + +class Jinja2TemplateSyntaxErrorFrame(object): + + IS_PLUGIN_FRAME = True + + def __init__(self, frame, exception_cls_name, filename, lineno, f_locals): + self.f_code = FCode('Jinja2 %s' % (exception_cls_name,), filename) + self.f_lineno = lineno + self.f_back = frame + self.f_globals = {} + self.f_locals = f_locals + self.f_trace = None + + +def change_variable(plugin, frame, attr, expression): + if isinstance(frame, Jinja2TemplateFrame): + result = eval(expression, frame.f_globals, frame.f_locals) + frame._change_variable(frame.f_back, attr, result) + return result + return False + + +def _is_missing(item): + if item.__class__.__name__ == 'MissingType': + return True + return False + + +def _find_render_function_frame(frame): + # in order to hide internal rendering functions + old_frame = frame + try: + while not ('self' in frame.f_locals and frame.f_locals['self'].__class__.__name__ == 'Template' and \ + frame.f_code.co_name == 'render'): + frame = frame.f_back + if frame is None: + return old_frame + return frame + except: + return old_frame + + +def _get_jinja2_template_line(frame): + debug_info = None + if '__jinja_template__' in frame.f_globals: + _debug_info = frame.f_globals['__jinja_template__']._debug_info + if _debug_info != '': + # sometimes template contains only plain text + debug_info = frame.f_globals['__jinja_template__'].debug_info + + if debug_info is None: + return None + + lineno = frame.f_lineno + + for pair in debug_info: + if pair[1] == lineno: + return pair[0] + + return None + + +def _convert_to_str(s): + if IS_PY2: + if isinstance(s, unicode): + s = s.encode('utf-8', 'replace') + return s + + +def _get_jinja2_template_filename(frame): + if '__jinja_template__' in frame.f_globals: + fname = _convert_to_str(frame.f_globals['__jinja_template__'].filename) + abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_file(fname) + return abs_path_real_path_and_base[1] + return None + +#======================================================================================================================= +# Jinja2 Step Commands +#======================================================================================================================= + + +def has_exception_breaks(plugin): + if len(plugin.main_debugger.jinja2_exception_break) > 0: + return True + return False + + +def has_line_breaks(plugin): + for file, breakpoints in dict_iter_items(plugin.main_debugger.jinja2_breakpoints): + if len(breakpoints) > 0: + return True + return False + + +def can_skip(plugin, pydb, frame): + if pydb.jinja2_breakpoints and _is_jinja2_render_call(frame): + filename = _get_jinja2_template_filename(frame) + jinja2_breakpoints_for_file = pydb.jinja2_breakpoints.get(filename) + if jinja2_breakpoints_for_file: + return False + + if pydb.jinja2_exception_break: + name = frame.f_code.co_name + + if IS_PY2: + if name == 'fail': + module_name = frame.f_globals.get('__name__', '') + if module_name == 'jinja2.parser': + return False + else: + # errors in compile time + if name in ('template', 'top-level template code', '') or name.startswith('block '): + f_back = frame.f_back + module_name = '' + if f_back is not None: + module_name = f_back.f_globals.get('__name__', '') + if module_name.startswith('jinja2.'): + return False + + return True + + +def cmd_step_into(plugin, pydb, frame, event, args, stop_info, stop): + info = args[2] + thread = args[3] + plugin_stop = False + stop_info['jinja2_stop'] = False + if _is_jinja2_suspended(thread): + stop_info['jinja2_stop'] = event in ('call', 'line') and _is_jinja2_render_call(frame) + plugin_stop = stop_info['jinja2_stop'] + stop = False + if info.pydev_call_from_jinja2 is not None: + if _is_jinja2_internal_function(frame): + # if internal Jinja2 function was called, we sould continue debugging inside template + info.pydev_call_from_jinja2 = None + else: + # we go into python code from Jinja2 rendering frame + stop = True + + if event == 'call' and _is_jinja2_context_call(frame.f_back): + # we called function from context, the next step will be in function + info.pydev_call_from_jinja2 = 1 + + if event == 'return' and _is_jinja2_context_call(frame.f_back): + # we return from python code to Jinja2 rendering frame + info.pydev_step_stop = info.pydev_call_from_jinja2 + info.pydev_call_from_jinja2 = None + thread.additional_info.suspend_type = JINJA2_SUSPEND + stop = False + + # print "info.pydev_call_from_jinja2", info.pydev_call_from_jinja2, "stop_info", stop_info, \ + # "thread.additional_info.suspend_type", thread.additional_info.suspend_type + # print "event", event, "farme.locals", frame.f_locals + return stop, plugin_stop + + +def cmd_step_over(plugin, pydb, frame, event, args, stop_info, stop): + info = args[2] + thread = args[3] + plugin_stop = False + stop_info['jinja2_stop'] = False + if _is_jinja2_suspended(thread): + stop = False + + if info.pydev_call_inside_jinja2 is None: + if _is_jinja2_render_call(frame): + if event == 'call': + info.pydev_call_inside_jinja2 = frame.f_back + if event in ('line', 'return'): + info.pydev_call_inside_jinja2 = frame + else: + if event == 'line': + if _is_jinja2_render_call(frame) and info.pydev_call_inside_jinja2 is frame: + stop_info['jinja2_stop'] = True + plugin_stop = stop_info['jinja2_stop'] + if event == 'return': + if frame is info.pydev_call_inside_jinja2 and 'event' not in frame.f_back.f_locals: + info.pydev_call_inside_jinja2 = _find_jinja2_render_frame(frame.f_back) + return stop, plugin_stop + else: + if event == 'return' and _is_jinja2_context_call(frame.f_back): + # we return from python code to Jinja2 rendering frame + info.pydev_call_from_jinja2 = None + info.pydev_call_inside_jinja2 = _find_jinja2_render_frame(frame) + thread.additional_info.suspend_type = JINJA2_SUSPEND + stop = False + return stop, plugin_stop + # print "info.pydev_call_from_jinja2", info.pydev_call_from_jinja2, "stop", stop, "jinja_stop", jinja2_stop, \ + # "thread.additional_info.suspend_type", thread.additional_info.suspend_type + # print "event", event, "info.pydev_call_inside_jinja2", info.pydev_call_inside_jinja2 + # print "frame", frame, "frame.f_back", frame.f_back, "step_stop", info.pydev_step_stop + # print "is_context_call", _is_jinja2_context_call(frame) + # print "render", _is_jinja2_render_call(frame) + # print "-------------" + return stop, plugin_stop + + +def stop(plugin, pydb, frame, event, args, stop_info, arg, step_cmd): + pydb = args[0] + thread = args[3] + if 'jinja2_stop' in stop_info and stop_info['jinja2_stop']: + frame = _suspend_jinja2(pydb, thread, frame, step_cmd) + if frame: + pydb.do_wait_suspend(thread, frame, event, arg) + return True + return False + + +def get_breakpoint(plugin, pydb, pydb_frame, frame, event, args): + pydb = args[0] + filename = args[1] + info = args[2] + new_frame = None + jinja2_breakpoint = None + flag = False + type = 'jinja2' + if event == 'line' and info.pydev_state != STATE_SUSPEND and \ + pydb.jinja2_breakpoints and _is_jinja2_render_call(frame): + filename = _get_jinja2_template_filename(frame) + jinja2_breakpoints_for_file = pydb.jinja2_breakpoints.get(filename) + new_frame = Jinja2TemplateFrame(frame) + + if jinja2_breakpoints_for_file: + lineno = frame.f_lineno + template_lineno = _get_jinja2_template_line(frame) + if template_lineno is not None and template_lineno in jinja2_breakpoints_for_file: + jinja2_breakpoint = jinja2_breakpoints_for_file[template_lineno] + flag = True + new_frame = Jinja2TemplateFrame(frame) + + return flag, jinja2_breakpoint, new_frame, type + + +def suspend(plugin, pydb, thread, frame, bp_type): + if bp_type == 'jinja2': + return _suspend_jinja2(pydb, thread, frame) + return None + + +def exception_break(plugin, pydb, pydb_frame, frame, args, arg): + pydb = args[0] + thread = args[3] + exception, value, trace = arg + if pydb.jinja2_exception_break and exception is not None: + exception_type = dict_keys(pydb.jinja2_exception_break)[0] + if exception.__name__ in ('UndefinedError', 'TemplateNotFound', 'TemplatesNotFound'): + # errors in rendering + render_frame = _find_jinja2_render_frame(frame) + if render_frame: + suspend_frame = _suspend_jinja2(pydb, thread, render_frame, CMD_ADD_EXCEPTION_BREAK, message=exception_type) + if suspend_frame: + add_exception_to_frame(suspend_frame, (exception, value, trace)) + suspend_frame.f_back = frame + frame = suspend_frame + return True, frame + + elif exception.__name__ in ('TemplateSyntaxError', 'TemplateAssertionError'): + name = frame.f_code.co_name + + if IS_PY2: + if name == 'fail': + module_name = frame.f_globals.get('__name__', '') + if module_name == 'jinja2.parser': + filename = value.filename + lineno = value.lineno + + syntax_error_frame = Jinja2TemplateSyntaxErrorFrame( + frame, exception.__name__, filename, lineno, {'name': value.name, 'exception': value}) + + pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) + add_exception_to_frame(syntax_error_frame, (exception, value, trace)) + thread.additional_info.suspend_type = JINJA2_SUSPEND + thread.additional_info.pydev_message = str(exception_type) + return True, syntax_error_frame + + else: + # errors in compile time + if name in ('template', 'top-level template code', '') or name.startswith('block '): + + f_back = frame.f_back + if f_back is not None: + module_name = f_back.f_globals.get('__name__', '') + + if module_name.startswith('jinja2.'): + # Jinja2 translates exception info and creates fake frame on his own + pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK) + add_exception_to_frame(frame, (exception, value, trace)) + thread.additional_info.suspend_type = JINJA2_SUSPEND + thread.additional_info.pydev_message = str(exception_type) + return True, frame + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/pydevd_tracing.py b/adapter/python/ptvsd/_vendored/pydevd/pydevd_tracing.py new file mode 100644 index 0000000..d9da117 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pydevd_tracing.py @@ -0,0 +1,258 @@ + +from _pydevd_bundle.pydevd_constants import get_frame, IS_CPYTHON, IS_64BIT_PROCESS, IS_WINDOWS, \ + IS_LINUX, IS_MAC, IS_PY2, IS_PY37_OR_GREATER, DebugInfoHolder +from _pydev_imps._pydev_saved_modules import thread, threading +from _pydev_bundle import pydev_log, pydev_monkey +from os.path import os +try: + import ctypes +except ImportError: + ctypes = None + +try: + import cStringIO as StringIO # may not always be available @UnusedImport +except: + try: + import StringIO # @Reimport + except: + import io as StringIO + +import sys # @Reimport +import traceback + +_original_settrace = sys.settrace + + +class TracingFunctionHolder: + '''This class exists just to keep some variables (so that we don't keep them in the global namespace). + ''' + _original_tracing = None + _warn = True + _lock = thread.allocate_lock() + _traceback_limit = 1 + _warnings_shown = {} + + +def get_exception_traceback_str(): + exc_info = sys.exc_info() + s = StringIO.StringIO() + traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file=s) + return s.getvalue() + + +def _get_stack_str(frame): + + msg = '\nIf this is needed, please check: ' + \ + '\nhttp://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html' + \ + '\nto see how to restore the debug tracing back correctly.\n' + + if TracingFunctionHolder._traceback_limit: + s = StringIO.StringIO() + s.write('Call Location:\n') + traceback.print_stack(f=frame, limit=TracingFunctionHolder._traceback_limit, file=s) + msg = msg + s.getvalue() + + return msg + + +def _internal_set_trace(tracing_func): + if TracingFunctionHolder._warn: + frame = get_frame() + if frame is not None and frame.f_back is not None: + filename = frame.f_back.f_code.co_filename.lower() + if not filename.endswith('threading.py') and not filename.endswith('pydevd_tracing.py'): + + message = \ + '\nPYDEV DEBUGGER WARNING:' + \ + '\nsys.settrace() should not be used when the debugger is being used.' + \ + '\nThis may cause the debugger to stop working correctly.' + \ + '%s' % _get_stack_str(frame.f_back) + + if message not in TracingFunctionHolder._warnings_shown: + # only warn about each message once... + TracingFunctionHolder._warnings_shown[message] = 1 + sys.stderr.write('%s\n' % (message,)) + sys.stderr.flush() + + if TracingFunctionHolder._original_tracing: + TracingFunctionHolder._original_tracing(tracing_func) + + +def SetTrace(tracing_func): + if TracingFunctionHolder._original_tracing is None: + # This may happen before replace_sys_set_trace_func is called. + sys.settrace(tracing_func) + return + + try: + TracingFunctionHolder._lock.acquire() + TracingFunctionHolder._warn = False + _internal_set_trace(tracing_func) + TracingFunctionHolder._warn = True + finally: + TracingFunctionHolder._lock.release() + + +def replace_sys_set_trace_func(): + if TracingFunctionHolder._original_tracing is None: + TracingFunctionHolder._original_tracing = sys.settrace + sys.settrace = _internal_set_trace + + +def restore_sys_set_trace_func(): + if TracingFunctionHolder._original_tracing is not None: + sys.settrace = TracingFunctionHolder._original_tracing + TracingFunctionHolder._original_tracing = None + + +def load_python_helper_lib(): + if not IS_CPYTHON or ctypes is None or sys.version_info[:2] > (3, 7): + return None + + if IS_WINDOWS: + if IS_64BIT_PROCESS: + suffix = 'amd64' + else: + suffix = 'x86' + + filename = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process', 'attach_%s.dll' % (suffix,)) + + elif IS_LINUX: + if IS_64BIT_PROCESS: + suffix = 'amd64' + else: + suffix = 'x86' + + filename = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process', 'attach_linux_%s.so' % (suffix,)) + + elif IS_MAC: + if IS_64BIT_PROCESS: + suffix = 'x86_64.dylib' + else: + suffix = 'x86.dylib' + + filename = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process', 'attach_%s' % (suffix,)) + + else: + pydev_log.info('Unable to set trace to all threads in platform: %s', sys.platform) + return None + + if not os.path.exists(filename): + pydev_log.critical('Expected: %s to exist.', filename) + return None + + try: + # Load as pydll so that we don't release the gil. + lib = ctypes.pydll.LoadLibrary(filename) + return lib + except: + if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: + # Only show message if tracing is on (we don't have pre-compiled + # binaries for all architectures -- i.e.: ARM). + pydev_log.exception('Error loading: %s', filename) + return None + + +def set_trace_to_threads(tracing_func): + lib = load_python_helper_lib() + if lib is None: # This is the case if it's not CPython. + return -1 + + if hasattr(sys, 'getswitchinterval'): + get_interval, set_interval = sys.getswitchinterval, sys.setswitchinterval + else: + get_interval, set_interval = sys.getcheckinterval, sys.setcheckinterval + + prev_value = get_interval() + ret = 0 + try: + if not IS_PY37_OR_GREATER: + # Prevent going to any other thread... if we switch the thread during this operation we + # could potentially corrupt the interpreter. + # Note: on CPython 3.7 onwards this is not needed (we have a different implementation + # for setting the tracing for other threads in this case). + set_interval(2 ** 15) + + set_trace_func = TracingFunctionHolder._original_tracing or sys.settrace + + # Note: use sys._current_frames() keys to get the thread ids because it'll return + # thread ids created in C/C++ where there's user code running, unlike the APIs + # from the threading module which see only threads created through it (unless + # a call for threading.current_thread() was previously done in that thread, + # in which case a dummy thread would've been created for it). + thread_idents = set(sys._current_frames().keys()) + thread_idents = thread_idents.difference( + # Ignore pydevd threads. + set(t.ident for t in threading.enumerate() if getattr(t, 'pydev_do_not_trace', False)) + ) + + curr_ident = thread.get_ident() + curr_thread = threading._active.get(curr_ident) + + for thread_ident in thread_idents: + # If that thread is not available in the threading module we also need to create a + # dummy thread for it (otherwise it'll be invisible to the debugger). + if thread_ident not in threading._active: + + class _DummyThread(threading._DummyThread): + + def _set_ident(self): + # Note: Hack to set the thread ident that we want. + if IS_PY2: + self._Thread__ident = thread_ident + else: + self._ident = thread_ident + + t = _DummyThread() + # Reset to the base class (don't expose our own version of the class). + t.__class__ = threading._DummyThread + + with threading._active_limbo_lock: + # On Py2 it'll put in active getting the current indent, not using the + # ident that was set, so, we have to update it (should be harmless on Py3 + # so, do it always). + threading._active[thread_ident] = t + threading._active[curr_ident] = curr_thread + + if t.ident != thread_ident: + # Check if it actually worked. + pydev_log.critical('pydevd: creation of _DummyThread with fixed thread ident did not succeed.') + + # Some (ptvsd) tests failed because of this, so, leave it always disabled for now. + # show_debug_info = 1 if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1 else 0 + show_debug_info = 0 + + if IS_PY37_OR_GREATER: + # Hack to increase _Py_TracingPossible. + # See comments on py_settrace_37.hpp + proceed = thread.allocate_lock() + proceed.acquire() + + def dummy_trace_on_py37(frame, event, arg): + return dummy_trace_on_py37 + + def increase_tracing_count_on_py37(): + SetTrace(dummy_trace_on_py37) + proceed.release() + + start_new_thread = pydev_monkey.get_original_start_new_thread(thread) + start_new_thread(increase_tracing_count_on_py37, ()) + proceed.acquire() # Only proceed after the release() is done. + proceed = None + + result = lib.AttachDebuggerTracing( + ctypes.c_int(show_debug_info), + ctypes.py_object(set_trace_func), + ctypes.py_object(tracing_func), + ctypes.c_uint(thread_ident), + ctypes.py_object(None), + ) + if result != 0: + pydev_log.info('Unable to set tracing for existing threads. Result: %s', result) + ret = result + finally: + if not IS_PY37_OR_GREATER: + set_interval(prev_value) + + return ret + diff --git a/adapter/python/ptvsd/_vendored/pydevd/pytest.ini b/adapter/python/ptvsd/_vendored/pydevd/pytest.ini new file mode 100644 index 0000000..cd47002 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +norecursedirs=tests_runfiles/samples +addopts=-vv +testpaths=test_pydevd_reload tests tests_mainloop tests_python tests_runfiles \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/runfiles.py b/adapter/python/ptvsd/_vendored/pydevd/runfiles.py new file mode 100644 index 0000000..97efa02 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/runfiles.py @@ -0,0 +1,322 @@ +''' +Entry point module (keep at root): + +Used to run with tests with unittest/pytest/nose. +''' + + +import os + +try: + xrange +except: + xrange = range + +def main(): + import sys + + # Separate the nose params and the pydev params. + pydev_params = [] + other_test_framework_params = [] + found_other_test_framework_param = None + + NOSE_PARAMS = '--nose-params' + PY_TEST_PARAMS = '--py-test-params' + + for arg in sys.argv[1:]: + if not found_other_test_framework_param and arg != NOSE_PARAMS and arg != PY_TEST_PARAMS: + pydev_params.append(arg) + + else: + if not found_other_test_framework_param: + found_other_test_framework_param = arg + else: + other_test_framework_params.append(arg) + + try: + # Convert to the case stored in the filesystem + import win32api + def get_with_filesystem_case(f): + return win32api.GetLongPathName(win32api.GetShortPathName(f)) + except: + def get_with_filesystem_case(f): + return f + + # Here we'll run either with nose or with the pydev_runfiles. + from _pydev_runfiles import pydev_runfiles + from _pydev_runfiles import pydev_runfiles_xml_rpc + from _pydevd_bundle import pydevd_constants + from pydevd_file_utils import _NormFile + + DEBUG = 0 + if DEBUG: + sys.stdout.write('Received parameters: %s\n' % (sys.argv,)) + sys.stdout.write('Params for pydev: %s\n' % (pydev_params,)) + if found_other_test_framework_param: + sys.stdout.write('Params for test framework: %s, %s\n' % (found_other_test_framework_param, other_test_framework_params)) + + try: + configuration = pydev_runfiles.parse_cmdline([sys.argv[0]] + pydev_params) + except: + sys.stderr.write('Command line received: %s\n' % (sys.argv,)) + raise + pydev_runfiles_xml_rpc.initialize_server(configuration.port) # Note that if the port is None, a Null server will be initialized. + + NOSE_FRAMEWORK = "nose" + PY_TEST_FRAMEWORK = "py.test" + test_framework = None # Default (pydev) + try: + if found_other_test_framework_param: + if found_other_test_framework_param == NOSE_PARAMS: + test_framework = NOSE_FRAMEWORK + import nose + + elif found_other_test_framework_param == PY_TEST_PARAMS: + test_framework = PY_TEST_FRAMEWORK + import pytest + + else: + raise ImportError('Test framework: %s not supported.' % (found_other_test_framework_param,)) + + else: + raise ImportError() + + except ImportError: + if found_other_test_framework_param: + raise + + test_framework = None + + # Clear any exception that may be there so that clients don't see it. + # See: https://sourceforge.net/tracker/?func=detail&aid=3408057&group_id=85796&atid=577329 + if hasattr(sys, 'exc_clear'): + sys.exc_clear() + + if not test_framework: + + return pydev_runfiles.main(configuration) # Note: still doesn't return a proper value. + + else: + # We'll convert the parameters to what nose or py.test expects. + # The supported parameters are: + # runfiles.py --config-file|-t|--tests dirs|files --nose-params xxx yyy zzz + # (all after --nose-params should be passed directly to nose) + + # In java: + # --tests = Constants.ATTR_UNITTEST_TESTS + # --config-file = Constants.ATTR_UNITTEST_CONFIGURATION_FILE + + + # The only thing actually handled here are the tests that we want to run, which we'll + # handle and pass as what the test framework expects. + + py_test_accept_filter = {} + files_to_tests = configuration.files_to_tests + + if files_to_tests: + # Handling through the file contents (file where each line is a test) + files_or_dirs = [] + for file, tests in files_to_tests.items(): + if test_framework == NOSE_FRAMEWORK: + for test in tests: + files_or_dirs.append(file + ':' + test) + + elif test_framework == PY_TEST_FRAMEWORK: + file = _NormFile(file) + py_test_accept_filter[file] = tests + files_or_dirs.append(file) + + else: + raise AssertionError('Cannot handle test framework: %s at this point.' % (test_framework,)) + + else: + if configuration.tests: + # Tests passed (works together with the files_or_dirs) + files_or_dirs = [] + for file in configuration.files_or_dirs: + if test_framework == NOSE_FRAMEWORK: + for t in configuration.tests: + files_or_dirs.append(file + ':' + t) + + elif test_framework == PY_TEST_FRAMEWORK: + file = _NormFile(file) + py_test_accept_filter[file] = configuration.tests + files_or_dirs.append(file) + + else: + raise AssertionError('Cannot handle test framework: %s at this point.' % (test_framework,)) + else: + # Only files or dirs passed (let it do the test-loading based on those paths) + files_or_dirs = configuration.files_or_dirs + + argv = other_test_framework_params + files_or_dirs + + + if test_framework == NOSE_FRAMEWORK: + # Nose usage: http://somethingaboutorange.com/mrl/projects/nose/0.11.2/usage.html + # show_stdout_option = ['-s'] + # processes_option = ['--processes=2'] + argv.insert(0, sys.argv[0]) + if DEBUG: + sys.stdout.write('Final test framework args: %s\n' % (argv[1:],)) + + from _pydev_runfiles import pydev_runfiles_nose + PYDEV_NOSE_PLUGIN_SINGLETON = pydev_runfiles_nose.start_pydev_nose_plugin_singleton(configuration) + argv.append('--with-pydevplugin') + # Return 'not' because it will return 'success' (so, exit == 0 if success) + return not nose.run(argv=argv, addplugins=[PYDEV_NOSE_PLUGIN_SINGLETON]) + + elif test_framework == PY_TEST_FRAMEWORK: + + if '--coverage_output_dir' in pydev_params and '--coverage_include' in pydev_params: + coverage_output_dir = pydev_params[pydev_params.index('--coverage_output_dir') + 1] + coverage_include = pydev_params[pydev_params.index('--coverage_include') + 1] + try: + import pytest_cov + except ImportError: + sys.stderr.write('To do a coverage run with pytest the pytest-cov library is needed (i.e.: pip install pytest-cov).\n\n') + raise + + argv.insert(0, '--cov-append') + argv.insert(1, '--cov-report=') + argv.insert(2, '--cov=%s' % (coverage_include,)) + + import time + os.environ['COVERAGE_FILE'] = os.path.join(coverage_output_dir, '.coverage.%s' % (time.time(),)) + + if DEBUG: + sys.stdout.write('Final test framework args: %s\n' % (argv,)) + sys.stdout.write('py_test_accept_filter: %s\n' % (py_test_accept_filter,)) + + def dotted(p): + # Helper to convert path to have dots instead of slashes + return os.path.normpath(p).replace(os.sep, "/").replace('/', '.') + + curr_dir = os.path.realpath('.') + curr_dotted = dotted(curr_dir) + '.' + + # Overcome limitation on py.test: + # When searching conftest if we have a structure as: + # /my_package + # /my_package/conftest.py + # /my_package/tests + # /my_package/tests/test_my_package.py + # The test_my_package won't have access to the conftest contents from the + # test_my_package.py file unless the working dir is set to /my_package. + # + # See related issue (for which we work-around below): + # https://bitbucket.org/hpk42/pytest/issue/639/conftest-being-loaded-twice-giving + + for path in sys.path: + path_dotted = dotted(path) + if curr_dotted.startswith(path_dotted): + os.chdir(path) + break + + remove = [] + for i in xrange(len(argv)): + arg = argv[i] + # Workaround bug in py.test: if we pass the full path it ends up importing conftest + # more than once (so, always work with relative paths). + if os.path.isfile(arg) or os.path.isdir(arg): + + # Args must be passed with the proper case in the filesystem (otherwise + # python itself may not recognize it). + arg = get_with_filesystem_case(arg) + argv[i] = arg + + from os.path import relpath + try: + # May fail if on different drives + arg = relpath(arg) + except ValueError: + pass + else: + argv[i] = arg + elif '' in arg: + remove.append(i) + + for i in reversed(remove): + del argv[i] + + # To find our runfile helpers (i.e.: plugin)... + d = os.path.dirname(__file__) + if d not in sys.path: + sys.path.insert(0, d) + + import pickle, zlib, base64 + + # Update environment PYTHONPATH so that it finds our plugin if using xdist. + os.environ['PYTHONPATH'] = os.pathsep.join(sys.path) + + # Set what should be skipped in the plugin through an environment variable + s = base64.b64encode(zlib.compress(pickle.dumps(py_test_accept_filter))) + if pydevd_constants.IS_PY3K: + s = s.decode('ascii') # Must be str in py3. + os.environ['PYDEV_PYTEST_SKIP'] = s + + # Identifies the main pid (i.e.: if it's not the main pid it has to connect back to the + # main pid to give xml-rpc notifications). + os.environ['PYDEV_MAIN_PID'] = str(os.getpid()) + os.environ['PYDEV_PYTEST_SERVER'] = str(configuration.port) + + argv.append('-p') + argv.append('_pydev_runfiles.pydev_runfiles_pytest2') + return pytest.main(argv) + + else: + raise AssertionError('Cannot handle test framework: %s at this point.' % (test_framework,)) + + +if __name__ == '__main__': + try: + main() + finally: + try: + # The server is not a daemon thread, so, we have to ask for it to be killed! + from _pydev_runfiles import pydev_runfiles_xml_rpc + pydev_runfiles_xml_rpc.force_server_kill() + except: + pass # Ignore any errors here + + import sys + import threading + if hasattr(sys, '_current_frames') and hasattr(threading, 'enumerate'): + import time + import traceback + + class DumpThreads(threading.Thread): + def run(self): + time.sleep(10) + + thread_id_to_name = {} + try: + for t in threading.enumerate(): + thread_id_to_name[t.ident] = '%s (daemon: %s)' % (t.name, t.daemon) + except: + pass + + stack_trace = [ + '===============================================================================', + 'pydev pyunit runner: Threads still found running after tests finished', + '================================= Thread Dump ================================='] + + for thread_id, stack in sys._current_frames().items(): + stack_trace.append('\n-------------------------------------------------------------------------------') + stack_trace.append(" Thread %s" % thread_id_to_name.get(thread_id, thread_id)) + stack_trace.append('') + + if 'self' in stack.f_locals: + sys.stderr.write(str(stack.f_locals['self']) + '\n') + + for filename, lineno, name, line in traceback.extract_stack(stack): + stack_trace.append(' File "%s", line %d, in %s' % (filename, lineno, name)) + if line: + stack_trace.append(" %s" % (line.strip())) + stack_trace.append('\n=============================== END Thread Dump ===============================') + sys.stderr.write('\n'.join(stack_trace)) + + + dump_current_frames_thread = DumpThreads() + dump_current_frames_thread.setDaemon(True) # Daemon so that this thread doesn't halt it! + dump_current_frames_thread.start() diff --git a/adapter/python/ptvsd/_vendored/pydevd/setup.py b/adapter/python/ptvsd/_vendored/pydevd/setup.py new file mode 100644 index 0000000..6b1a0c5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/setup.py @@ -0,0 +1,141 @@ +r''' +Full setup, used to distribute the debugger backend to PyPi. + +Note that this is mostly so that users can do: + +pip install pydevd + +in a machine for doing remote-debugging, as a local installation with the IDE should have +everything already distributed. + +Reference on wheels: +https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/ +http://lucumr.pocoo.org/2014/1/27/python-on-wheels/ + +Another (no wheels): https://jamie.curle.io/blog/my-first-experience-adding-package-pypi/ + +See: + +build_tools\pydevd_release_process.txt + +for release process. +''' + +from setuptools import setup +from setuptools.dist import Distribution +from distutils.extension import Extension +import os + + +class BinaryDistribution(Distribution): + + def is_pure(self): + return False + + +data_files = [] + + +def accept_file(f): + f = f.lower() + for ext in '.py .dll .so .dylib .txt .cpp .h .bat .c .sh .md .txt'.split(): + if f.endswith(ext): + return True + + return f in ['readme', 'makefile'] + + +data_files.append(('pydevd_attach_to_process', [os.path.join('pydevd_attach_to_process', f) for f in os.listdir('pydevd_attach_to_process') if accept_file(f)])) +for root, dirs, files in os.walk("pydevd_attach_to_process"): + for d in dirs: + data_files.append((os.path.join(root, d), [os.path.join(root, d, f) for f in os.listdir(os.path.join(root, d)) if accept_file(f)])) + +import pydevd +version = pydevd.__version__ + +args = dict( + name='pydevd', + version=version, + description='PyDev.Debugger (used in PyDev, PyCharm and VSCode Python)', + author='Fabio Zadrozny and others', + url='https://github.com/fabioz/PyDev.Debugger/', + license='EPL (Eclipse Public License)', + packages=[ + '_pydev_bundle', + '_pydev_imps', + '_pydev_runfiles', + '_pydevd_bundle', + '_pydevd_bundle._debug_adapter', + '_pydevd_frame_eval', + 'pydev_ipython', + + # 'pydev_sitecustomize', -- Not actually a package (not added) + + 'pydevd_attach_to_process', + + 'pydevd_concurrency_analyser', + 'pydevd_plugins', + 'pydevd_plugins.extensions', + ], + py_modules=[ + # 'interpreterInfo', -- Not needed for debugger + # 'pycompletionserver', -- Not needed for debugger + 'pydev_app_engine_debug_startup', + # 'pydev_coverage', -- Not needed for debugger + # 'pydev_pysrc', -- Not needed for debugger + 'pydev_run_in_console', + 'pydevconsole', + 'pydevd_file_utils', + 'pydevd', + 'pydevd_tracing', + # 'runfiles', -- Not needed for debugger + 'setup_cython', # Distributed to clients. See: https://github.com/fabioz/PyDev.Debugger/issues/102 + # 'setup', -- Should not be included as a module + ], + classifiers=[ + 'Development Status :: 6 - Mature', + 'Environment :: Console', + 'Intended Audience :: Developers', + + 'License :: OSI Approved :: Eclipse Public License 1.0 (EPL-1.0)', + + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Topic :: Software Development :: Debuggers', + ], + entry_points={ + 'console_scripts':[ + 'pydevd = pydevd:main', + ], + }, + data_files=data_files, + keywords=['pydev', 'pydevd', 'pydev.debugger'], + include_package_data=True, + zip_safe=False, +) + +import sys +try: + args_with_binaries = args.copy() + args_with_binaries.update(dict( + distclass=BinaryDistribution, + ext_modules=[ + # In this setup, don't even try to compile with cython, just go with the .c file which should've + # been properly generated from a tested version. + Extension('_pydevd_bundle.pydevd_cython', ["_pydevd_bundle/pydevd_cython.c", ]) + ] + )) + setup(**args_with_binaries) +except: + # Compile failed: just setup without compiling cython deps. + setup(**args) + sys.stdout.write('Plain-python version of pydevd installed (cython speedups not available).\n') diff --git a/adapter/python/ptvsd/_vendored/pydevd/setup_cython.py b/adapter/python/ptvsd/_vendored/pydevd/setup_cython.py new file mode 100644 index 0000000..eeb18eb --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/setup_cython.py @@ -0,0 +1,125 @@ +''' +A simpler setup version just to compile the speedup module. + +It should be used as: + +python setup_cython build_ext --inplace + +Note: the .c file and other generated files are regenerated from +the .pyx file by running "python build_tools/build.py" +''' + +import os +import sys +from setuptools import setup + +os.chdir(os.path.dirname(os.path.abspath(__file__))) + +IS_PY36_OR_GREATER = sys.version_info > (3, 6) + + +def process_args(): + extension_folder = None + target_pydevd_name = None + target_frame_eval = None + force_cython = False + + for i, arg in enumerate(sys.argv[:]): + if arg == '--build-lib': + extension_folder = sys.argv[i + 1] + # It shouldn't be removed from sys.argv (among with --build-temp) because they're passed further to setup() + if arg.startswith('--target-pyd-name='): + sys.argv.remove(arg) + target_pydevd_name = arg[len('--target-pyd-name='):] + if arg.startswith('--target-pyd-frame-eval='): + sys.argv.remove(arg) + target_frame_eval = arg[len('--target-pyd-frame-eval='):] + if arg == '--force-cython': + sys.argv.remove(arg) + force_cython = True + + return extension_folder, target_pydevd_name, target_frame_eval, force_cython + + +def build_extension(dir_name, extension_name, target_pydevd_name, force_cython, extended=False, has_pxd=False): + pyx_file = os.path.join(os.path.dirname(__file__), dir_name, "%s.pyx" % (extension_name,)) + + if target_pydevd_name != extension_name: + # It MUST be there in this case! + # (otherwise we'll have unresolved externals because the .c file had another name initially). + import shutil + + # We must force cython in this case (but only in this case -- for the regular setup in the user machine, we + # should always compile the .c file). + force_cython = True + + new_pyx_file = os.path.join(os.path.dirname(__file__), dir_name, "%s.pyx" % (target_pydevd_name,)) + new_c_file = os.path.join(os.path.dirname(__file__), dir_name, "%s.c" % (target_pydevd_name,)) + shutil.copy(pyx_file, new_pyx_file) + pyx_file = new_pyx_file + if has_pxd: + pxd_file = os.path.join(os.path.dirname(__file__), dir_name, "%s.pxd" % (extension_name,)) + new_pxd_file = os.path.join(os.path.dirname(__file__), dir_name, "%s.pxd" % (target_pydevd_name,)) + shutil.copy(pxd_file, new_pxd_file) + assert os.path.exists(pyx_file) + + try: + if force_cython: + from Cython.Build import cythonize # @UnusedImport + ext_modules = cythonize([ + "%s/%s.pyx" % (dir_name, target_pydevd_name,), + ]) + else: + # Always compile the .c (and not the .pyx) file (which we should keep up-to-date by running build_tools/build.py). + from distutils.extension import Extension + ext_modules = [Extension("%s%s.%s" % (dir_name, "_ext" if extended else "", target_pydevd_name,), + [os.path.join(dir_name, "%s.c" % target_pydevd_name), ], + # uncomment to generate pdbs for visual studio. + # extra_compile_args=["-Zi", "/Od"], + # extra_link_args=["-debug"], + )] + + setup( + name='Cythonize', + ext_modules=ext_modules + ) + finally: + if target_pydevd_name != extension_name: + try: + os.remove(new_pyx_file) + except: + import traceback + traceback.print_exc() + try: + os.remove(new_c_file) + except: + import traceback + traceback.print_exc() + if has_pxd: + try: + os.remove(new_pxd_file) + except: + import traceback + traceback.print_exc() + + +extension_folder, target_pydevd_name, target_frame_eval, force_cython = process_args() + +extension_name = "pydevd_cython" +if target_pydevd_name is None: + target_pydevd_name = extension_name +build_extension("_pydevd_bundle", extension_name, target_pydevd_name, force_cython, extension_folder, True) + +if IS_PY36_OR_GREATER: + extension_name = "pydevd_frame_evaluator" + if target_frame_eval is None: + target_frame_eval = extension_name + build_extension("_pydevd_frame_eval", extension_name, target_frame_eval, force_cython, extension_folder, True) + +if extension_folder: + os.chdir(extension_folder) + for folder in [file for file in os.listdir(extension_folder) if + file != 'build' and os.path.isdir(os.path.join(extension_folder, file))]: + file = os.path.join(folder, "__init__.py") + if not os.path.exists(file): + open(file, 'a').close() diff --git a/adapter/python/ptvsd/_vendored/pydevd/stubs/_django_manager_body.py b/adapter/python/ptvsd/_vendored/pydevd/stubs/_django_manager_body.py new file mode 100644 index 0000000..2bf4706 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/stubs/_django_manager_body.py @@ -0,0 +1,414 @@ +# This is a dummy for code-completion purposes. + +def __unicode__(self): + """ + Return "app_label.model_label.manager_name". + """ + +def _copy_to_model(self, model): + """ + Makes a copy of the manager and assigns it to 'model', which should be + a child of the existing model (used when inheriting a manager from an + abstract base class). + """ + + +def _db(self): + """ + + """ + + +def _get_queryset_methods(cls, queryset_class): + """ + + """ + + +def _hints(self): + """ + dict() -> new empty dictionary + dict(mapping) -> new dictionary initialized from a mapping object's + (key, value) pairs + dict(iterable) -> new dictionary initialized as if via: + d = {} + for k, v in iterable: + d[k] = v + dict(**kwargs) -> new dictionary initialized with the name=value pairs + in the keyword argument list. For example: dict(one=1, two=2) + """ + + +def _inherited(self): + """ + + """ + + +def _insert(self, *args, **kwargs): + """ + Inserts a new record for the given model. This provides an interface to + the InsertQuery class and is how Model.save() is implemented. + """ + + +def _queryset_class(self): + """ + Represents a lazy database lookup for a set of objects. + """ + + +def _set_creation_counter(self): + """ + Sets the creation counter value for this instance and increments the + class-level copy. + """ + + +def _update(self, *args, **kwargs): + """ + A version of update that accepts field objects instead of field names. + Used primarily for model saving and not intended for use by general + code (it requires too much poking around at model internals to be + useful at that level). + """ + + +def aggregate(self, *args, **kwargs): + """ + Returns a dictionary containing the calculations (aggregation) + over the current queryset + + If args is present the expression is passed as a kwarg using + the Aggregate object's default alias. + """ + + +def all(self): + """ + @rtype: django.db.models.query.QuerySet + """ + + +def annotate(self, *args, **kwargs): + """ + Return a query set in which the returned objects have been annotated + with data aggregated from related fields. + """ + + +def bulk_create(self, *args, **kwargs): + """ + Inserts each of the instances into the database. This does *not* call + save() on each of the instances, does not send any pre/post save + signals, and does not set the primary key attribute if it is an + autoincrement field. + """ + + +def check(self, **kwargs): + """ + + """ + + +def complex_filter(self, *args, **kwargs): + """ + Returns a new QuerySet instance with filter_obj added to the filters. + + filter_obj can be a Q object (or anything with an add_to_query() + method) or a dictionary of keyword lookup arguments. + + This exists to support framework features such as 'limit_choices_to', + and usually it will be more natural to use other methods. + + @rtype: django.db.models.query.QuerySet + """ + + +def contribute_to_class(self, model, name): + """ + + """ + + +def count(self, *args, **kwargs): + """ + Performs a SELECT COUNT() and returns the number of records as an + integer. + + If the QuerySet is already fully cached this simply returns the length + of the cached results set to avoid multiple SELECT COUNT(*) calls. + """ + + +def create(self, *args, **kwargs): + """ + Creates a new object with the given kwargs, saving it to the database + and returning the created object. + """ + + +def creation_counter(self): + """ + + """ + + +def dates(self, *args, **kwargs): + """ + Returns a list of date objects representing all available dates for + the given field_name, scoped to 'kind'. + """ + + +def datetimes(self, *args, **kwargs): + """ + Returns a list of datetime objects representing all available + datetimes for the given field_name, scoped to 'kind'. + """ + + +def db(self): + """ + + """ + + +def db_manager(self, using=None, hints=None): + """ + + """ + + +def defer(self, *args, **kwargs): + """ + Defers the loading of data for certain fields until they are accessed. + The set of fields to defer is added to any existing set of deferred + fields. The only exception to this is if None is passed in as the only + parameter, in which case all deferrals are removed (None acts as a + reset option). + """ + + +def distinct(self, *args, **kwargs): + """ + Returns a new QuerySet instance that will select only distinct results. + + @rtype: django.db.models.query.QuerySet + """ + + +def earliest(self, *args, **kwargs): + """ + + """ + + +def exclude(self, *args, **kwargs): + """ + Returns a new QuerySet instance with NOT (args) ANDed to the existing + set. + + @rtype: django.db.models.query.QuerySet + """ + + +def exists(self, *args, **kwargs): + """ + + """ + + +def extra(self, *args, **kwargs): + """ + Adds extra SQL fragments to the query. + """ + + +def filter(self, *args, **kwargs): + """ + Returns a new QuerySet instance with the args ANDed to the existing + set. + + @rtype: django.db.models.query.QuerySet + """ + + +def first(self, *args, **kwargs): + """ + Returns the first object of a query, returns None if no match is found. + """ + + +def from_queryset(cls, queryset_class, class_name=None): + """ + + """ + + +def get(self, *args, **kwargs): + """ + Performs the query and returns a single object matching the given + keyword arguments. + """ + + +def get_or_create(self, *args, **kwargs): + """ + Looks up an object with the given kwargs, creating one if necessary. + Returns a tuple of (object, created), where created is a boolean + specifying whether an object was created. + """ + + +def get_queryset(self): + """ + Returns a new QuerySet object. Subclasses can override this method to + easily customize the behavior of the Manager. + + @rtype: django.db.models.query.QuerySet + """ + + +def in_bulk(self, *args, **kwargs): + """ + Returns a dictionary mapping each of the given IDs to the object with + that ID. + """ + + +def iterator(self, *args, **kwargs): + """ + An iterator over the results from applying this QuerySet to the + database. + """ + + +def last(self, *args, **kwargs): + """ + Returns the last object of a query, returns None if no match is found. + """ + + +def latest(self, *args, **kwargs): + """ + + """ + + +def model(self): + """ + MyModel(id) + """ + + +def none(self, *args, **kwargs): + """ + Returns an empty QuerySet. + + @rtype: django.db.models.query.QuerySet + """ + + +def only(self, *args, **kwargs): + """ + Essentially, the opposite of defer. Only the fields passed into this + method and that are not already specified as deferred are loaded + immediately when the queryset is evaluated. + """ + + +def order_by(self, *args, **kwargs): + """ + Returns a new QuerySet instance with the ordering changed. + + @rtype: django.db.models.query.QuerySet + """ + + +def prefetch_related(self, *args, **kwargs): + """ + Returns a new QuerySet instance that will prefetch the specified + Many-To-One and Many-To-Many related objects when the QuerySet is + evaluated. + + When prefetch_related() is called more than once, the list of lookups to + prefetch is appended to. If prefetch_related(None) is called, the list + is cleared. + + @rtype: django.db.models.query.QuerySet + """ + + +def raw(self, *args, **kwargs): + """ + + """ + + +def reverse(self, *args, **kwargs): + """ + Reverses the ordering of the QuerySet. + + @rtype: django.db.models.query.QuerySet + """ + + +def select_for_update(self, *args, **kwargs): + """ + Returns a new QuerySet instance that will select objects with a + FOR UPDATE lock. + + @rtype: django.db.models.query.QuerySet + """ + + +def select_related(self, *args, **kwargs): + """ + Returns a new QuerySet instance that will select related objects. + + If fields are specified, they must be ForeignKey fields and only those + related objects are included in the selection. + + If select_related(None) is called, the list is cleared. + + @rtype: django.db.models.query.QuerySet + """ + + +def update(self, *args, **kwargs): + """ + Updates all elements in the current QuerySet, setting all the given + fields to the appropriate values. + """ + + +def update_or_create(self, *args, **kwargs): + """ + Looks up an object with the given kwargs, updating one with defaults + if it exists, otherwise creates a new one. + Returns a tuple (object, created), where created is a boolean + specifying whether an object was created. + """ + + +def using(self, *args, **kwargs): + """ + Selects which database this QuerySet should execute its query against. + + @rtype: django.db.models.query.QuerySet + """ + + +def values(self, *args, **kwargs): + """ + + """ + + +def values_list(self, *args, **kwargs): + """ + + """ + diff --git a/adapter/python/ptvsd/_vendored/pydevd/stubs/_get_tips.py b/adapter/python/ptvsd/_vendored/pydevd/stubs/_get_tips.py new file mode 100644 index 0000000..b98e1c5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/stubs/_get_tips.py @@ -0,0 +1,280 @@ +import os.path +import inspect +import sys + +# completion types. +TYPE_IMPORT = '0' +TYPE_CLASS = '1' +TYPE_FUNCTION = '2' +TYPE_ATTR = '3' +TYPE_BUILTIN = '4' +TYPE_PARAM = '5' + +def _imp(name, log=None): + try: + return __import__(name) + except: + if '.' in name: + sub = name[0:name.rfind('.')] + + if log is not None: + log.AddContent('Unable to import', name, 'trying with', sub) + # log.AddContent('PYTHONPATH:') + # log.AddContent('\n'.join(sorted(sys.path))) + log.AddException() + + return _imp(sub, log) + else: + s = 'Unable to import module: %s - sys.path: %s' % (str(name), sys.path) + if log is not None: + log.AddContent(s) + log.AddException() + + raise ImportError(s) + + +IS_IPY = False +if sys.platform == 'cli': + IS_IPY = True + _old_imp = _imp + def _imp(name, log=None): + # We must add a reference in clr for .Net + import clr # @UnresolvedImport + initial_name = name + while '.' in name: + try: + clr.AddReference(name) + break # If it worked, that's OK. + except: + name = name[0:name.rfind('.')] + else: + try: + clr.AddReference(name) + except: + pass # That's OK (not dot net module). + + return _old_imp(initial_name, log) + + + +def GetFile(mod): + f = None + try: + f = inspect.getsourcefile(mod) or inspect.getfile(mod) + except: + if hasattr(mod, '__file__'): + f = mod.__file__ + if f.lower(f[-4:]) in ['.pyc', '.pyo']: + filename = f[:-4] + '.py' + if os.path.exists(filename): + f = filename + + return f + +def Find(name, log=None): + f = None + + mod = _imp(name, log) + parent = mod + foundAs = '' + + if inspect.ismodule(mod): + f = GetFile(mod) + + components = name.split('.') + + old_comp = None + for comp in components[1:]: + try: + # this happens in the following case: + # we have mx.DateTime.mxDateTime.mxDateTime.pyd + # but after importing it, mx.DateTime.mxDateTime shadows access to mxDateTime.pyd + mod = getattr(mod, comp) + except AttributeError: + if old_comp != comp: + raise + + if inspect.ismodule(mod): + f = GetFile(mod) + else: + if len(foundAs) > 0: + foundAs = foundAs + '.' + foundAs = foundAs + comp + + old_comp = comp + + return f, mod, parent, foundAs + + +def GenerateTip(data, log=None): + data = data.replace('\n', '') + if data.endswith('.'): + data = data.rstrip('.') + + f, mod, parent, foundAs = Find(data, log) + # print_ >> open('temp.txt', 'w'), f + tips = GenerateImportsTipForModule(mod) + return f, tips + + +def CheckChar(c): + if c == '-' or c == '.': + return '_' + return c + +def GenerateImportsTipForModule(obj_to_complete, dirComps=None, getattr=getattr, filter=lambda name:True): + ''' + @param obj_to_complete: the object from where we should get the completions + @param dirComps: if passed, we should not 'dir' the object and should just iterate those passed as a parameter + @param getattr: the way to get a given object from the obj_to_complete (used for the completer) + @param filter: a callable that receives the name and decides if it should be appended or not to the results + @return: list of tuples, so that each tuple represents a completion with: + name, doc, args, type (from the TYPE_* constants) + ''' + ret = [] + + if dirComps is None: + dirComps = dir(obj_to_complete) + if hasattr(obj_to_complete, '__dict__'): + dirComps.append('__dict__') + if hasattr(obj_to_complete, '__class__'): + dirComps.append('__class__') + + getCompleteInfo = True + + if len(dirComps) > 1000: + # ok, we don't want to let our users wait forever... + # no complete info for you... + + getCompleteInfo = False + + dontGetDocsOn = (float, int, str, tuple, list) + for d in dirComps: + + if d is None: + continue + + if not filter(d): + continue + + args = '' + + try: + obj = getattr(obj_to_complete, d) + except: # just ignore and get it without aditional info + ret.append((d, '', args, TYPE_BUILTIN)) + else: + + if getCompleteInfo: + retType = TYPE_BUILTIN + + # check if we have to get docs + getDoc = True + for class_ in dontGetDocsOn: + + if isinstance(obj, class_): + getDoc = False + break + + doc = '' + if getDoc: + # no need to get this info... too many constants are defined and + # makes things much slower (passing all that through sockets takes quite some time) + try: + doc = inspect.getdoc(obj) + if doc is None: + doc = '' + except: # may happen on jython when checking java classes (so, just ignore it) + doc = '' + + + if inspect.ismethod(obj) or inspect.isbuiltin(obj) or inspect.isfunction(obj) or inspect.isroutine(obj): + try: + args, vargs, kwargs, defaults = inspect.getargspec(obj) + except: + args, vargs, kwargs, defaults = (('self',), None, None, None) + if defaults is not None: + start_defaults_at = len(args) - len(defaults) + + + r = '' + for i, a in enumerate(args): + + if len(r) > 0: + r = r + ', ' + + r = r + str(a) + + if defaults is not None and i >= start_defaults_at: + default = defaults[i - start_defaults_at] + r += '=' +str(default) + + + others = '' + if vargs: + others += '*' + vargs + + if kwargs: + if others: + others+= ', ' + others += '**' + kwargs + + if others: + r+= ', ' + + + args = '(%s%s)' % (r, others) + retType = TYPE_FUNCTION + + elif inspect.isclass(obj): + retType = TYPE_CLASS + + elif inspect.ismodule(obj): + retType = TYPE_IMPORT + + else: + retType = TYPE_ATTR + + + # add token and doc to return - assure only strings. + ret.append((d, doc, args, retType)) + + + else: # getCompleteInfo == False + if inspect.ismethod(obj) or inspect.isbuiltin(obj) or inspect.isfunction(obj) or inspect.isroutine(obj): + retType = TYPE_FUNCTION + + elif inspect.isclass(obj): + retType = TYPE_CLASS + + elif inspect.ismodule(obj): + retType = TYPE_IMPORT + + else: + retType = TYPE_ATTR + # ok, no complete info, let's try to do this as fast and clean as possible + # so, no docs for this kind of information, only the signatures + ret.append((d, '', str(args), retType)) + + return ret + + + + +if __name__ == '__main__': + # To use when we have some object: i.e.: obj_to_complete=MyModel.objects + temp = ''' +def %(method_name)s%(args)s: + """ +%(doc)s + """ +''' + + for entry in GenerateImportsTipForModule(obj_to_complete): + import textwrap + doc = textwrap.dedent(entry[1]) + lines = [] + for line in doc.splitlines(): + lines.append(' ' + line) + doc = '\n'.join(lines) + print temp % dict(method_name=entry[0], args=entry[2] or '(self)', doc=doc) diff --git a/adapter/python/ptvsd/_vendored/pydevd/stubs/pycompletion.py b/adapter/python/ptvsd/_vendored/pydevd/stubs/pycompletion.py new file mode 100644 index 0000000..f9fb773 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/stubs/pycompletion.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +''' +@author Radim Kubacki +''' +from _pydev_bundle import _pydev_imports_tipper +import traceback +import StringIO +import sys +import urllib +import pycompletionserver + + +#======================================================================================================================= +# GetImports +#======================================================================================================================= +def GetImports(module_name): + try: + processor = pycompletionserver.Processor() + data = urllib.unquote_plus(module_name) + def_file, completions = _pydev_imports_tipper.GenerateTip(data) + return processor.formatCompletionMessage(def_file, completions) + except: + s = StringIO.StringIO() + exc_info = sys.exc_info() + + traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) + err = s.getvalue() + pycompletionserver.dbg('Received error: ' + str(err), pycompletionserver.ERROR) + raise + + +#======================================================================================================================= +# main +#======================================================================================================================= +if __name__ == '__main__': + mod_name = sys.argv[1] + + print(GetImports(mod_name)) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/test_pydevd_reload/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/test_pydevd_reload/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/test_pydevd_reload/test_pydevd_reload.py b/adapter/python/ptvsd/_vendored/pydevd/test_pydevd_reload/test_pydevd_reload.py new file mode 100644 index 0000000..38a1919 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/test_pydevd_reload/test_pydevd_reload.py @@ -0,0 +1,512 @@ +import os # @NoMove +import sys # @NoMove +import pytest + +from _pydevd_bundle import pydevd_reload +import tempfile +import unittest + + +SAMPLE_CODE = """ +class C: + def foo(self): + return 0 + + @classmethod + def bar(cls): + return (0, 0) + + @staticmethod + def stomp(): + return (0, 0, 0) + + def unchanged(self): + return 'unchanged' +""" + +from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_IRONPYTHON + +@pytest.mark.skipif(IS_JYTHON or IS_IRONPYTHON, reason='CPython related test') +class Test(unittest.TestCase): + + + def setUp(self): + unittest.TestCase.setUp(self) + self.tempdir = None + self.save_path = None + self.tempdir = tempfile.mkdtemp() + self.save_path = list(sys.path) + sys.path.append(self.tempdir) + try: + del sys.modules['x'] + except: + pass + + + def tearDown(self): + unittest.TestCase.tearDown(self) + sys.path = self.save_path + try: + del sys.modules['x'] + except: + pass + + def make_mod(self, name="x", repl=None, subst=None, sample=SAMPLE_CODE): + fn = os.path.join(self.tempdir, name + ".py") + f = open(fn, "w") + if repl is not None and subst is not None: + sample = sample.replace(repl, subst) + try: + f.write(sample) + finally: + f.close() + + + def test_pydevd_reload(self): + + self.make_mod() + import x # @UnresolvedImport + + C = x.C + COut = C + Cfoo = C.foo + Cbar = C.bar + Cstomp = C.stomp + + def check2(expected): + C = x.C + Cfoo = C.foo + Cbar = C.bar + Cstomp = C.stomp + b = C() + bfoo = b.foo + self.assertEqual(expected, b.foo()) + self.assertEqual(expected, bfoo()) + self.assertEqual(expected, Cfoo(b)) + + def check(expected): + b = COut() + bfoo = b.foo + self.assertEqual(expected, b.foo()) + self.assertEqual(expected, bfoo()) + self.assertEqual(expected, Cfoo(b)) + self.assertEqual((expected, expected), Cbar()) + self.assertEqual((expected, expected, expected), Cstomp()) + check2(expected) + + check(0) + + # modify mod and reload + count = 0 + while count < 1: + count += 1 + self.make_mod(repl="0", subst=str(count)) + pydevd_reload.xreload(x) + check(count) + + + def test_pydevd_reload2(self): + + self.make_mod() + import x # @UnresolvedImport + + c = x.C() + cfoo = c.foo + self.assertEqual(0, c.foo()) + self.assertEqual(0, cfoo()) + + self.make_mod(repl="0", subst='1') + pydevd_reload.xreload(x) + self.assertEqual(1, c.foo()) + self.assertEqual(1, cfoo()) + + def test_pydevd_reload3(self): + class F: + def m1(self): + return 1 + class G: + def m1(self): + return 2 + + self.assertEqual(F().m1(), 1) + pydevd_reload.Reload(None)._update(None, None, F, G) + self.assertEqual(F().m1(), 2) + + + def test_pydevd_reload4(self): + class F: + pass + F.m1 = lambda a:None + class G: + pass + G.m1 = lambda a:10 + + self.assertEqual(F().m1(), None) + pydevd_reload.Reload(None)._update(None, None, F, G) + self.assertEqual(F().m1(), 10) + + + + def test_if_code_obj_equals(self): + class F: + def m1(self): + return 1 + class G: + def m1(self): + return 1 + class H: + def m1(self): + return 2 + + if hasattr(F.m1, 'func_code'): + self.assertTrue(pydevd_reload.code_objects_equal(F.m1.func_code, G.m1.func_code)) + self.assertFalse(pydevd_reload.code_objects_equal(F.m1.func_code, H.m1.func_code)) + else: + self.assertTrue(pydevd_reload.code_objects_equal(F.m1.__code__, G.m1.__code__)) + self.assertFalse(pydevd_reload.code_objects_equal(F.m1.__code__, H.m1.__code__)) + + + + def test_metaclass(self): + + class Meta(type): + def __init__(cls, name, bases, attrs): + super(Meta, cls).__init__(name, bases, attrs) + + class F: + __metaclass__ = Meta + + def m1(self): + return 1 + + + class G: + __metaclass__ = Meta + + def m1(self): + return 2 + + self.assertEqual(F().m1(), 1) + pydevd_reload.Reload(None)._update(None, None, F, G) + self.assertEqual(F().m1(), 2) + + + + def test_change_hierarchy(self): + + class F(object): + + def m1(self): + return 1 + + + class B(object): + def super_call(self): + return 2 + + class G(B): + + def m1(self): + return self.super_call() + + self.assertEqual(F().m1(), 1) + old = pydevd_reload.notify_error + self._called = False + def on_error(*args): + self._called = True + try: + pydevd_reload.notify_error = on_error + pydevd_reload.Reload(None)._update(None, None, F, G) + self.assertTrue(self._called) + finally: + pydevd_reload.notify_error = old + + + def test_change_hierarchy_old_style(self): + + class F: + + def m1(self): + return 1 + + + class B: + def super_call(self): + return 2 + + class G(B): + + def m1(self): + return self.super_call() + + + self.assertEqual(F().m1(), 1) + old = pydevd_reload.notify_error + self._called = False + def on_error(*args): + self._called = True + try: + pydevd_reload.notify_error = on_error + pydevd_reload.Reload(None)._update(None, None, F, G) + self.assertTrue(self._called) + finally: + pydevd_reload.notify_error = old + + + def test_create_class(self): + SAMPLE_CODE1 = """ +class C: + def foo(self): + return 0 +""" + # Creating a new class and using it from old class + SAMPLE_CODE2 = """ +class B: + pass + +class C: + def foo(self): + return B +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.C().foo + self.assertEqual(foo(), 0) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo().__name__, 'B') + + def test_create_class2(self): + SAMPLE_CODE1 = """ +class C(object): + def foo(self): + return 0 +""" + # Creating a new class and using it from old class + SAMPLE_CODE2 = """ +class B(object): + pass + +class C(object): + def foo(self): + return B +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.C().foo + self.assertEqual(foo(), 0) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo().__name__, 'B') + + def test_parent_function(self): + SAMPLE_CODE1 = """ +class B(object): + def foo(self): + return 0 + +class C(B): + def call(self): + return self.foo() +""" + # Creating a new class and using it from old class + SAMPLE_CODE2 = """ +class B(object): + def foo(self): + return 0 + def bar(self): + return 'bar' + +class C(B): + def call(self): + return self.bar() +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + call = x.C().call + self.assertEqual(call(), 0) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(call(), 'bar') + + + def test_update_constant(self): + SAMPLE_CODE1 = """ +CONSTANT = 1 + +class B(object): + def foo(self): + return CONSTANT +""" + SAMPLE_CODE2 = """ +CONSTANT = 2 + +class B(object): + def foo(self): + return CONSTANT +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.B().foo + self.assertEqual(foo(), 1) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo(), 1) #Just making it explicit we don't reload constants. + + + def test_update_constant_with_custom_code(self): + SAMPLE_CODE1 = """ +CONSTANT = 1 + +class B(object): + def foo(self): + return CONSTANT +""" + SAMPLE_CODE2 = """ +CONSTANT = 2 + +def __xreload_old_new__(namespace, name, old, new): + if name == 'CONSTANT': + namespace[name] = new + +class B(object): + def foo(self): + return CONSTANT +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.B().foo + self.assertEqual(foo(), 1) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo(), 2) #Actually updated it now! + + + def test_reload_custom_code_after_changes(self): + SAMPLE_CODE1 = """ +CONSTANT = 1 + +class B(object): + def foo(self): + return CONSTANT +""" + SAMPLE_CODE2 = """ +CONSTANT = 1 + +def __xreload_after_reload_update__(namespace): + namespace['CONSTANT'] = 2 + +class B(object): + def foo(self): + return CONSTANT +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.B().foo + self.assertEqual(foo(), 1) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo(), 2) #Actually updated it now! + + + def test_reload_custom_code_after_changes_in_class(self): + SAMPLE_CODE1 = """ + +class B(object): + CONSTANT = 1 + + def foo(self): + return self.CONSTANT +""" + SAMPLE_CODE2 = """ + + +class B(object): + CONSTANT = 1 + + @classmethod + def __xreload_after_reload_update__(cls): + cls.CONSTANT = 2 + + def foo(self): + return self.CONSTANT +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.B().foo + self.assertEqual(foo(), 1) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo(), 2) #Actually updated it now! + + + def test_update_constant_with_custom_code2(self): + SAMPLE_CODE1 = """ + +class B(object): + CONSTANT = 1 + + def foo(self): + return self.CONSTANT +""" + SAMPLE_CODE2 = """ + + +class B(object): + + CONSTANT = 2 + + def __xreload_old_new__(cls, name, old, new): + if name == 'CONSTANT': + cls.CONSTANT = new + __xreload_old_new__ = classmethod(__xreload_old_new__) + + def foo(self): + return self.CONSTANT +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + foo = x.B().foo + self.assertEqual(foo(), 1) + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + self.assertEqual(foo(), 2) #Actually updated it now! + + + def test_update_with_slots(self): + SAMPLE_CODE1 = """ +class B(object): + + __slots__ = ['bar'] + +""" + SAMPLE_CODE2 = """ +class B(object): + + __slots__ = ['bar', 'foo'] + + def m1(self): + self.bar = 10 + return 1 + +""" + + self.make_mod(sample=SAMPLE_CODE1) + import x # @UnresolvedImport + B = x.B + self.make_mod(sample=SAMPLE_CODE2) + pydevd_reload.xreload(x) + b = B() + self.assertEqual(1, b.m1()) + self.assertEqual(10, b.bar) + self.assertRaises(Exception, setattr, b, 'foo', 20) #__slots__ can't be updated + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_check_pydevconsole.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_check_pydevconsole.py new file mode 100644 index 0000000..33d0256 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_check_pydevconsole.py @@ -0,0 +1,113 @@ +import threading +import unittest +import os +import pytest +import pydevconsole + +from _pydev_bundle.pydev_imports import xmlrpclib, SimpleXMLRPCServer +from _pydev_bundle.pydev_localhost import get_localhost + +try: + raw_input + raw_input_name = 'raw_input' +except NameError: + raw_input_name = 'input' + +try: + from IPython import core # @UnusedImport + has_ipython = True +except: + has_ipython = False + + +#======================================================================================================================= +# Test +#======================================================================================================================= +@pytest.mark.skipif(os.environ.get('TRAVIS') == 'true' or not has_ipython, reason='Too flaky on Travis (and requires IPython).') +class Test(unittest.TestCase): + + def start_client_thread(self, client_port): + class ClientThread(threading.Thread): + def __init__(self, client_port): + threading.Thread.__init__(self) + self.client_port = client_port + + def run(self): + class HandleRequestInput: + def RequestInput(self): + client_thread.requested_input = True + return 'RequestInput: OK' + + def NotifyFinished(self, *args, **kwargs): + client_thread.notified_finished += 1 + return 1 + + handle_request_input = HandleRequestInput() + + from _pydev_bundle import pydev_localhost + self.client_server = client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False) + client_server.register_function(handle_request_input.RequestInput) + client_server.register_function(handle_request_input.NotifyFinished) + client_server.serve_forever() + + def shutdown(self): + return + self.client_server.shutdown() + + client_thread = ClientThread(client_port) + client_thread.requested_input = False + client_thread.notified_finished = 0 + client_thread.setDaemon(True) + client_thread.start() + return client_thread + + + def get_free_addresses(self): + from _pydev_bundle.pydev_localhost import get_socket_names + socket_names = get_socket_names(2, close=True) + return [socket_name[1] for socket_name in socket_names] + + def test_server(self): + # Just making sure that the singleton is created in this thread. + from _pydev_bundle.pydev_ipython_console_011 import get_pydev_frontend + get_pydev_frontend(get_localhost(), 0) + + client_port, server_port = self.get_free_addresses() + class ServerThread(threading.Thread): + def __init__(self, client_port, server_port): + threading.Thread.__init__(self) + self.client_port = client_port + self.server_port = server_port + + def run(self): + from _pydev_bundle import pydev_localhost + print('Starting server with:', pydev_localhost.get_localhost(), self.server_port, self.client_port) + pydevconsole.start_server(pydev_localhost.get_localhost(), self.server_port, self.client_port) + server_thread = ServerThread(client_port, server_port) + server_thread.setDaemon(True) + server_thread.start() + + client_thread = self.start_client_thread(client_port) #@UnusedVariable + + try: + import time + time.sleep(.3) #let's give it some time to start the threads + + from _pydev_bundle import pydev_localhost + server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), server_port)) + server.execLine("import sys; print('Running with: %s %s' % (sys.executable or sys.platform, sys.version))") + server.execLine('class Foo:') + server.execLine(' pass') + server.execLine('') + server.execLine('foo = Foo()') + server.execLine('a = %s()' % raw_input_name) + initial = time.time() + while not client_thread.requested_input: + if time.time() - initial > 2: + raise AssertionError('Did not get the return asked before the timeout.') + time.sleep(.1) + frame_xml = server.getFrame() + self.assertTrue('RequestInput' in frame_xml, 'Did not fid RequestInput in:\n%s' % (frame_xml,)) + finally: + client_thread.shutdown() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_get_referrers.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_get_referrers.py new file mode 100644 index 0000000..c1b49db --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_get_referrers.py @@ -0,0 +1,125 @@ +import sys +import threading +import time +import unittest +import pytest +from _pydevd_bundle import pydevd_referrers +from _pydev_bundle.pydev_imports import StringIO +from tests_python.debugger_unittest import IS_PYPY + +try: + import gc + gc.get_referrers(unittest) + has_referrers = True +except NotImplementedError: + has_referrers = False + + +# Only do get referrers tests if it's actually available. +@pytest.mark.skipif(not has_referrers or IS_PYPY, reason='gc.get_referrers not implemented') +class Test(unittest.TestCase): + + def test_get_referrers1(self): + + container = [] + contained = [1, 2] + container.append(0) + container.append(contained) + + # Ok, we have the contained in this frame and inside the given list (which on turn is in this frame too). + # we should skip temporary references inside the get_referrer_info. + result = pydevd_referrers.get_referrer_info(contained) + assert 'list[1]' in result + pydevd_referrers.print_referrers(contained, stream=StringIO()) + + def test_get_referrers2(self): + + class MyClass(object): + + def __init__(self): + pass + + contained = [1, 2] + obj = MyClass() + obj.contained = contained + del contained + + # Ok, we have the contained in this frame and inside the given list (which on turn is in this frame too). + # we should skip temporary references inside the get_referrer_info. + result = pydevd_referrers.get_referrer_info(obj.contained) + assert 'found_as="contained"' in result + assert 'MyClass' in result + + def test_get_referrers3(self): + + class MyClass(object): + + def __init__(self): + pass + + contained = [1, 2] + obj = MyClass() + obj.contained = contained + del contained + + # Ok, we have the contained in this frame and inside the given list (which on turn is in this frame too). + # we should skip temporary references inside the get_referrer_info. + result = pydevd_referrers.get_referrer_info(obj.contained) + assert 'found_as="contained"' in result + assert 'MyClass' in result + + def test_get_referrers4(self): + + class MyClass(object): + + def __init__(self): + pass + + obj = MyClass() + obj.me = obj + + # Let's see if we detect the cycle... + result = pydevd_referrers.get_referrer_info(obj) + assert 'found_as="me"' in result # Cyclic ref + + def test_get_referrers5(self): + container = dict(a=[1]) + + # Let's see if we detect the cycle... + result = pydevd_referrers.get_referrer_info(container['a']) + assert 'test_get_referrers5' not in result # I.e.: NOT in the current method + assert 'found_as="a"' in result + assert 'dict' in result + assert str(id(container)) in result + + def test_get_referrers6(self): + import sys + container = dict(a=[1]) + + def should_appear(obj): + # Let's see if we detect the cycle... + return pydevd_referrers.get_referrer_info(obj) + + result = should_appear(container['a']) + if sys.version_info[:2] >= (3, 7): + # In Python 3.7 the frame is not appearing in gc.get_referrers. + assert 'should_appear' not in result + else: + assert 'should_appear' in result + + def test_get_referrers7(self): + + class MyThread(threading.Thread): + + def run(self): + # Note: we do that because if we do + self.frame = sys._getframe() + + t = MyThread() + t.start() + while not hasattr(t, 'frame'): + time.sleep(0.01) + + result = pydevd_referrers.get_referrer_info(t.frame) + assert 'MyThread' in result + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_jyserver.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_jyserver.py new file mode 100644 index 0000000..7e7a9f5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_jyserver.py @@ -0,0 +1,140 @@ +''' +@author Fabio Zadrozny +''' +import sys +import unittest +import socket +import urllib +import pytest +import pycompletionserver + + +IS_JYTHON = sys.platform.find('java') != -1 +DEBUG = 0 + +def dbg(s): + if DEBUG: + sys.stdout.write('TEST %s\n' % s) + +@pytest.mark.skipif(not IS_JYTHON, reason='Jython related test') +class TestJython(unittest.TestCase): + + def test_it(self): + dbg('ok') + + + def test_message(self): + t = pycompletionserver.CompletionServer(0) + t.exit_process_on_kill = False + + l = [] + l.append(('Def', 'description' , 'args')) + l.append(('Def1', 'description1', 'args1')) + l.append(('Def2', 'description2', 'args2')) + + msg = t.processor.format_completion_message('test_jyserver.py', l) + + self.assertEqual('@@COMPLETIONS(test_jyserver.py,(Def,description,args),(Def1,description1,args1),(Def2,description2,args2))END@@', msg) + + l = [] + l.append(('Def', 'desc,,r,,i()ption', '')) + l.append(('Def(1', 'descriptio(n1', '')) + l.append(('De,f)2', 'de,s,c,ription2', '')) + msg = t.processor.format_completion_message(None, l) + expected = '@@COMPLETIONS(None,(Def,desc%2C%2Cr%2C%2Ci%28%29ption, ),(Def%281,descriptio%28n1, ),(De%2Cf%292,de%2Cs%2Cc%2Cription2, ))END@@' + + self.assertEqual(expected, msg) + + + def test_completion_sockets_and_messages(self): + dbg('test_completion_sockets_and_messages') + t, socket = self.create_connections() + self.socket = socket + dbg('connections created') + + try: + #now that we have the connections all set up, check the code completion messages. + msg = urllib.quote_plus('math') + + toWrite = '@@IMPORTS:%sEND@@' % msg + dbg('writing' + str(toWrite)) + socket.send(toWrite) #math completions + completions = self.read_msg() + dbg(urllib.unquote_plus(completions)) + + start = '@@COMPLETIONS(' + self.assertTrue(completions.startswith(start), '%s DOESNT START WITH %s' % (completions, start)) + self.assertTrue(completions.find('@@COMPLETIONS') != -1) + self.assertTrue(completions.find('END@@') != -1) + + + msg = urllib.quote_plus('__builtin__.str') + toWrite = '@@IMPORTS:%sEND@@' % msg + dbg('writing' + str(toWrite)) + socket.send(toWrite) #math completions + completions = self.read_msg() + dbg(urllib.unquote_plus(completions)) + + start = '@@COMPLETIONS(' + self.assertTrue(completions.startswith(start), '%s DOESNT START WITH %s' % (completions, start)) + self.assertTrue(completions.find('@@COMPLETIONS') != -1) + self.assertTrue(completions.find('END@@') != -1) + + + + finally: + try: + self.send_kill_msg(socket) + + + while not t.ended: + pass #wait until it receives the message and quits. + + + socket.close() + except: + pass + + def get_free_port(self): + from _pydev_bundle.pydev_localhost import get_socket_name + return get_socket_name(close=True)[1] + + def create_connections(self): + ''' + Creates the connections needed for testing. + ''' + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server.bind((pycompletionserver.HOST, 0)) + server.listen(1) #socket to receive messages. + + from thread import start_new_thread + t = pycompletionserver.CompletionServer(server.getsockname()[1]) + t.exit_process_on_kill = False + + start_new_thread(t.run, ()) + + sock, _addr = server.accept() + + return t, sock + + def read_msg(self): + msg = '@@PROCESSING_END@@' + while msg.startswith('@@PROCESSING'): + msg = self.socket.recv(1024) + if msg.startswith('@@PROCESSING:'): + dbg('Status msg:' + str(msg)) + + while msg.find('END@@') == -1: + msg += self.socket.recv(1024) + + return msg + + def send_kill_msg(self, socket): + socket.send(pycompletionserver.MSG_KILL_SERVER) + + + + +# Run for jython in command line: +# c:\bin\jython2.7.0\bin\jython.exe -m py.test tests\test_jyserver.py diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_jysimpleTipper.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_jysimpleTipper.py new file mode 100644 index 0000000..a1790cf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_jysimpleTipper.py @@ -0,0 +1,242 @@ +import unittest +import os +import sys +import pytest + +# Note: ant.jar and junit.jar must be in the PYTHONPATH (see jython_test_deps) + +IS_JYTHON = False +if sys.platform.find('java') != -1: + IS_JYTHON = True + from _pydev_bundle._pydev_jy_imports_tipper import ismethod + from _pydev_bundle._pydev_jy_imports_tipper import isclass + from _pydev_bundle._pydev_jy_imports_tipper import dir_obj + from _pydev_bundle import _pydev_jy_imports_tipper + from java.lang.reflect import Method # @UnresolvedImport + from java.lang import System # @UnresolvedImport + from java.lang import String # @UnresolvedImport + from java.lang.System import arraycopy # @UnresolvedImport + from java.lang.System import out # @UnresolvedImport + import java.lang.String # @UnresolvedImport + import org.python.core.PyDictionary # @UnresolvedImport + +__DBG = 0 + + +def dbg(s): + if __DBG: + sys.stdout.write('%s\n' % (s,)) + + +@pytest.mark.skipif(not IS_JYTHON, reason='Jython related test') +class TestMod(unittest.TestCase): + + def assert_args(self, tok, args, tips): + for a in tips: + if tok == a[0]: + self.assertEqual(args, a[2]) + return + raise AssertionError('%s not in %s', tok, tips) + + def assert_in(self, tok, tips): + self.assertEqual(4, len(tips[0])) + for a in tips: + if tok == a[0]: + return a + s = '' + for a in tips: + s += str(a) + s += '\n' + raise AssertionError('%s not in %s' % (tok, s)) + + def test_imports1a(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('java.util.HashMap') + if f is None: + return # Not ok with java 9 + + assert f.endswith('rt.jar') + + def test_imports1c(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('java.lang.Class') + if f is None: + return # Not ok with java 9 + assert f.endswith('rt.jar') + + def test_imports1b(self): + try: + f, tip = _pydev_jy_imports_tipper.generate_tip('__builtin__.m') + self.fail('err') + except: + pass + + def test_imports1(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('junit.framework.TestCase') + assert f.endswith('junit.jar') + ret = self.assert_in('assertEquals', tip) +# self.assertEqual('', ret[2]) + + def test_imports2(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('junit.framework') + assert f.endswith('junit.jar') + ret = self.assert_in('TestCase', tip) + self.assertEqual('', ret[2]) + + def test_imports2a(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('org.apache.tools.ant') + assert f.endswith('ant.jar') + ret = self.assert_in('Task', tip) + self.assertEqual('', ret[2]) + + def test_imports3(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('os') + assert f.endswith('os.py') + ret = self.assert_in('path', tip) + self.assertEqual('', ret[2]) + + def test_tip_on_string(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('string') + self.assert_in('join', tip) + self.assert_in('uppercase', tip) + + def test_imports(self): + tip = _pydev_jy_imports_tipper.generate_tip('__builtin__')[1] + self.assert_in('tuple' , tip) + self.assert_in('RuntimeError' , tip) + self.assert_in('RuntimeWarning' , tip) + + def test_imports5(self): + f, tip = _pydev_jy_imports_tipper.generate_tip('java.lang') + if f is None: + return # Not ok with java 9 + assert f.endswith('rt.jar') + tup = self.assert_in('String' , tip) + self.assertEqual(str(_pydev_jy_imports_tipper.TYPE_CLASS), tup[3]) + + tip = _pydev_jy_imports_tipper.generate_tip('java')[1] + tup = self.assert_in('lang' , tip) + self.assertEqual(str(_pydev_jy_imports_tipper.TYPE_IMPORT), tup[3]) + + tip = _pydev_jy_imports_tipper.generate_tip('java.lang.String')[1] + tup = self.assert_in('indexOf' , tip) + self.assertEqual(str(_pydev_jy_imports_tipper.TYPE_FUNCTION), tup[3]) + + tip = _pydev_jy_imports_tipper.generate_tip('java.lang.String')[1] + tup = self.assert_in('charAt' , tip) + self.assertEqual(str(_pydev_jy_imports_tipper.TYPE_FUNCTION), tup[3]) + self.assertEqual('(int)', tup[2]) + + tup = self.assert_in('format' , tip) + self.assertEqual(str(_pydev_jy_imports_tipper.TYPE_FUNCTION), tup[3]) + self.assertEqual('(string, objectArray)', tup[2]) + self.assertTrue(tup[1].find('[Ljava.lang.Object;') == -1) + + tup = self.assert_in('getBytes', tip) + self.assertEqual(str(_pydev_jy_imports_tipper.TYPE_FUNCTION), tup[3]) + assert '[B' not in tup[1] + assert 'byte[]' in tup[1] + + f, tip = _pydev_jy_imports_tipper.generate_tip('__builtin__.str') + assert f is None or f.endswith('jython.jar') # Depends on jython version + self.assert_in('find' , tip) + + f, tip = _pydev_jy_imports_tipper.generate_tip('__builtin__.dict') + assert f is None or f.endswith('jython.jar') # Depends on jython version + self.assert_in('get' , tip) + + +@pytest.mark.skipif(not IS_JYTHON, reason='Jython related test') +class TestSearch(unittest.TestCase): + + def test_search_on_jython(self): + assert _pydev_jy_imports_tipper.search_definition('os')[0][0].split(os.sep)[-1] in ('javaos.py', 'os.py') + self.assertEqual(0, _pydev_jy_imports_tipper.search_definition('os')[0][1]) + + assert _pydev_jy_imports_tipper.search_definition('os.makedirs')[0][0].split(os.sep)[-1] in ('javaos.py', 'os.py') + self.assertNotEqual(0, _pydev_jy_imports_tipper.search_definition('os.makedirs')[0][1]) + + # print _pydev_jy_imports_tipper.search_definition('os.makedirs') + + +@pytest.mark.skipif(not IS_JYTHON, reason='Jython related test') +class TestCompl(unittest.TestCase): + + def test_getting_info_on_jython(self): + + dbg('\n\n--------------------------- java') + assert not ismethod(java)[0] + assert not isclass(java) + assert _pydev_jy_imports_tipper.ismodule(java) + + dbg('\n\n--------------------------- java.lang') + assert not ismethod(java.lang)[0] + assert not isclass(java.lang) + assert _pydev_jy_imports_tipper.ismodule(java.lang) + + dbg('\n\n--------------------------- Method') + assert not ismethod(Method)[0] + assert isclass(Method) + + dbg('\n\n--------------------------- System') + assert not ismethod(System)[0] + assert isclass(System) + + dbg('\n\n--------------------------- String') + assert not ismethod(System)[0] + assert isclass(String) + assert len(dir_obj(String)) > 10 + + dbg('\n\n--------------------------- arraycopy') + isMet = ismethod(arraycopy) + assert isMet[0] + assert isMet[1][0].basic_as_str() == "function:arraycopy args=['java.lang.Object', 'int', 'java.lang.Object', 'int', 'int'], varargs=None, kwargs=None, docs:None" + assert not isclass(arraycopy) + + dbg('\n\n--------------------------- out') + isMet = ismethod(out) + assert not isMet[0] + assert not isclass(out) + + dbg('\n\n--------------------------- out.println') + isMet = ismethod(out.println) # @UndefinedVariable + assert isMet[0] + assert len(isMet[1]) == 10 + self.assertEqual(isMet[1][0].basic_as_str(), "function:println args=[], varargs=None, kwargs=None, docs:None") + assert isMet[1][1].basic_as_str() == "function:println args=['long'], varargs=None, kwargs=None, docs:None" + assert not isclass(out.println) # @UndefinedVariable + + dbg('\n\n--------------------------- str') + isMet = ismethod(str) + # the code below should work, but is failing on jython 22a1 + # assert isMet[0] + # assert isMet[1][0].basic_as_str() == "function:str args=['org.python.core.PyObject'], varargs=None, kwargs=None, docs:None" + assert not isclass(str) + + def met1(): + a = 3 + return a + + dbg('\n\n--------------------------- met1') + isMet = ismethod(met1) + assert isMet[0] + assert isMet[1][0].basic_as_str() == "function:met1 args=[], varargs=None, kwargs=None, docs:None" + assert not isclass(met1) + + def met2(arg1, arg2, *vararg, **kwarg): + '''docmet2''' + + a = 1 + return a + + dbg('\n\n--------------------------- met2') + isMet = ismethod(met2) + assert isMet[0] + assert isMet[1][0].basic_as_str() == "function:met2 args=['arg1', 'arg2'], varargs=vararg, kwargs=kwarg, docs:docmet2" + assert not isclass(met2) + +# Run for jython in command line: + +# On Windows: +# c:/bin/jython2.7.0/bin/jython.exe -Dpython.path=jython_test_deps/ant.jar;jython_test_deps/junit.jar -m py.test tests/test_jysimpleTipper.py + +# On Linux (different path separator for jars) +# jython -Dpython.path=jython_test_deps/ant.jar:jython_test_deps/junit.jar -m py.test tests/test_jysimpleTipper.py diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_pydev_ipython_011.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_pydev_ipython_011.py new file mode 100644 index 0000000..17a4554 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_pydev_ipython_011.py @@ -0,0 +1,317 @@ +import sys +import unittest +import threading +import os +from _pydev_bundle.pydev_imports import SimpleXMLRPCServer +from _pydev_bundle.pydev_localhost import get_localhost +from _pydev_bundle.pydev_console_utils import StdIn +import socket +import time +from _pydevd_bundle import pydevd_io +import pytest + +try: + xrange +except: + xrange = range + +def eq_(a, b): + if a != b: + raise AssertionError('%s != %s' % (a, b)) + +try: + from IPython import core + has_ipython = True +except: + has_ipython = False + +@pytest.mark.skipif(not has_ipython, reason='IPython not available') +class TestBase(unittest.TestCase): + + + def setUp(self): + from _pydev_bundle.pydev_ipython_console_011 import get_pydev_frontend + + # PyDevFrontEnd depends on singleton in IPython, so you + # can't make multiple versions. So we reuse self.front_end for + # all the tests + self.front_end = get_pydev_frontend(get_localhost(), 0) + + from pydev_ipython.inputhook import set_return_control_callback + set_return_control_callback(lambda:True) + self.front_end.clear_buffer() + + def tearDown(self): + pass + + def add_exec(self, code, expected_more=False): + more = self.front_end.add_exec(code) + eq_(expected_more, more) + + def redirect_stdout(self): + from IPython.utils import io + + self.original_stdout = sys.stdout + sys.stdout = io.stdout = pydevd_io.IOBuf() + + def restore_stdout(self): + from IPython.utils import io + io.stdout = sys.stdout = self.original_stdout + + +@pytest.mark.skipif(not has_ipython, reason='IPython not available') +class TestPyDevFrontEnd(TestBase): + + def testAddExec_1(self): + self.add_exec('if True:', True) + + + def testAddExec_2(self): + #Change: 'more' must now be controlled in the client side after the initial 'True' returned. + self.add_exec('if True:\n testAddExec_a = 10\n', False) + assert 'testAddExec_a' in self.front_end.get_namespace() + + + def testAddExec_3(self): + assert 'testAddExec_x' not in self.front_end.get_namespace() + self.add_exec('if True:\n testAddExec_x = 10\n\n') + assert 'testAddExec_x' in self.front_end.get_namespace() + eq_(self.front_end.get_namespace()['testAddExec_x'], 10) + + + def test_get_namespace(self): + assert 'testGetNamespace_a' not in self.front_end.get_namespace() + self.add_exec('testGetNamespace_a = 10') + assert 'testGetNamespace_a' in self.front_end.get_namespace() + eq_(self.front_end.get_namespace()['testGetNamespace_a'], 10) + + + def test_complete(self): + unused_text, matches = self.front_end.complete('%') + assert len(matches) > 1, 'at least one magic should appear in completions' + + + def test_complete_does_not_do_python_matches(self): + # Test that IPython's completions do not do the things that + # PyDev's completions will handle + self.add_exec('testComplete_a = 5') + self.add_exec('testComplete_b = 10') + self.add_exec('testComplete_c = 15') + unused_text, matches = self.front_end.complete('testComplete_') + assert len(matches) == 0 + + + def testGetCompletions_1(self): + # Test the merged completions include the standard completions + self.add_exec('testComplete_a = 5') + self.add_exec('testComplete_b = 10') + self.add_exec('testComplete_c = 15') + res = self.front_end.getCompletions('testComplete_', 'testComplete_') + matches = [f[0] for f in res] + assert len(matches) == 3 + eq_(set(['testComplete_a', 'testComplete_b', 'testComplete_c']), set(matches)) + + + def testGetCompletions_2(self): + # Test that we get IPython completions in results + # we do this by checking kw completion which PyDev does + # not do by default + self.add_exec('def ccc(ABC=123): pass') + res = self.front_end.getCompletions('ccc(', '') + matches = [f[0] for f in res] + assert 'ABC=' in matches + + + def testGetCompletions_3(self): + # Test that magics return IPYTHON magic as type + res = self.front_end.getCompletions('%cd', '%cd') + assert len(res) == 1 + eq_(res[0][3], '12') # '12' == IToken.TYPE_IPYTHON_MAGIC + assert len(res[0][1]) > 100, 'docstring for %cd should be a reasonably long string' + +@pytest.mark.skipif(not has_ipython, reason='IPython not available') +class TestRunningCode(TestBase): + + def test_print(self): + self.redirect_stdout() + try: + self.add_exec('print("output")') + eq_(sys.stdout.getvalue(), 'output\n') + finally: + self.restore_stdout() + + + def testQuestionMark_1(self): + self.redirect_stdout() + try: + self.add_exec('?') + found = sys.stdout.getvalue() + if len(found) < 1000: + raise AssertionError('Expected IPython help to be big. Found: %s' % (found,)) + finally: + self.restore_stdout() + + + def testQuestionMark_2(self): + self.redirect_stdout() + try: + self.add_exec('int?') + found = sys.stdout.getvalue() + if 'Convert' not in found: + raise AssertionError('Expected to find "Convert" in %s' % (found,)) + finally: + self.restore_stdout() + + + + def test_gui(self): + try: + import Tkinter + except: + return + else: + from pydev_ipython.inputhook import get_inputhook + assert get_inputhook() is None + self.add_exec('%gui tk') + # we can't test the GUI works here because we aren't connected to XML-RPC so + # nowhere for hook to run + assert get_inputhook() is not None + self.add_exec('%gui none') + assert get_inputhook() is None + + + def test_history(self): + ''' Make sure commands are added to IPython's history ''' + self.redirect_stdout() + try: + self.add_exec('a=1') + self.add_exec('b=2') + _ih = self.front_end.get_namespace()['_ih'] + eq_(_ih[-1], 'b=2') + eq_(_ih[-2], 'a=1') + + self.add_exec('history') + hist = sys.stdout.getvalue().split('\n') + eq_(hist[-1], '') + eq_(hist[-2], 'history') + eq_(hist[-3], 'b=2') + eq_(hist[-4], 'a=1') + finally: + self.restore_stdout() + + + def test_edit(self): + ''' Make sure we can issue an edit command''' + if os.environ.get('TRAVIS') == 'true': + # This test is too flaky on travis. + return + + from _pydev_bundle.pydev_ipython_console_011 import get_pydev_frontend + + called_RequestInput = [False] + called_IPythonEditor = [False] + def start_client_thread(client_port): + class ClientThread(threading.Thread): + def __init__(self, client_port): + threading.Thread.__init__(self) + self.client_port = client_port + def run(self): + class HandleRequestInput: + def RequestInput(self): + called_RequestInput[0] = True + return '\n' + def IPythonEditor(self, name, line): + called_IPythonEditor[0] = (name, line) + return True + + handle_request_input = HandleRequestInput() + + from _pydev_bundle import pydev_localhost + self.client_server = client_server = SimpleXMLRPCServer( + (pydev_localhost.get_localhost(), self.client_port), logRequests=False) + client_server.register_function(handle_request_input.RequestInput) + client_server.register_function(handle_request_input.IPythonEditor) + client_server.serve_forever() + + def shutdown(self): + return + self.client_server.shutdown() + + client_thread = ClientThread(client_port) + client_thread.setDaemon(True) + client_thread.start() + return client_thread + + # PyDevFrontEnd depends on singleton in IPython, so you + # can't make multiple versions. So we reuse self.front_end for + # all the tests + s = socket.socket() + s.bind(('', 0)) + self.client_port = client_port = s.getsockname()[1] + s.close() + self.front_end = get_pydev_frontend(get_localhost(), client_port) + + client_thread = start_client_thread(self.client_port) + orig_stdin = sys.stdin + sys.stdin = StdIn(self, get_localhost(), self.client_port) + try: + filename = 'made_up_file.py' + self.add_exec('%edit ' + filename) + + for i in xrange(10): + if called_IPythonEditor[0] == (os.path.abspath(filename), '0'): + break + time.sleep(.1) + + if not called_IPythonEditor[0]: + # File "/home/travis/miniconda/lib/python3.3/site-packages/IPython/core/interactiveshell.py", line 2883, in run_code + # exec(code_obj, self.user_global_ns, self.user_ns) + # File "", line 1, in + # get_ipython().magic('edit made_up_file.py') + # File "/home/travis/miniconda/lib/python3.3/site-packages/IPython/core/interactiveshell.py", line 2205, in magic + # return self.run_line_magic(magic_name, magic_arg_s) + # File "/home/travis/miniconda/lib/python3.3/site-packages/IPython/core/interactiveshell.py", line 2126, in run_line_magic + # result = fn(*args,**kwargs) + # File "", line 2, in edit + # File "/home/travis/miniconda/lib/python3.3/site-packages/IPython/core/magic.py", line 193, in + # call = lambda f, *a, **k: f(*a, **k) + # File "/home/travis/miniconda/lib/python3.3/site-packages/IPython/core/magics/code.py", line 662, in edit + # self.shell.hooks.editor(filename,lineno) + # File "/home/travis/build/fabioz/PyDev.Debugger/pydev_ipython_console_011.py", line 70, in call_editor + # server.IPythonEditor(filename, str(line)) + # File "/home/travis/miniconda/lib/python3.3/xmlrpc/client.py", line 1090, in __call__ + # return self.__send(self.__name, args) + # File "/home/travis/miniconda/lib/python3.3/xmlrpc/client.py", line 1419, in __request + # verbose=self.__verbose + # File "/home/travis/miniconda/lib/python3.3/xmlrpc/client.py", line 1132, in request + # return self.single_request(host, handler, request_body, verbose) + # File "/home/travis/miniconda/lib/python3.3/xmlrpc/client.py", line 1143, in single_request + # http_conn = self.send_request(host, handler, request_body, verbose) + # File "/home/travis/miniconda/lib/python3.3/xmlrpc/client.py", line 1255, in send_request + # self.send_content(connection, request_body) + # File "/home/travis/miniconda/lib/python3.3/xmlrpc/client.py", line 1285, in send_content + # connection.endheaders(request_body) + # File "/home/travis/miniconda/lib/python3.3/http/client.py", line 1061, in endheaders + # self._send_output(message_body) + # File "/home/travis/miniconda/lib/python3.3/http/client.py", line 906, in _send_output + # self.send(msg) + # File "/home/travis/miniconda/lib/python3.3/http/client.py", line 844, in send + # self.connect() + # File "/home/travis/miniconda/lib/python3.3/http/client.py", line 822, in connect + # self.timeout, self.source_address) + # File "/home/travis/miniconda/lib/python3.3/socket.py", line 435, in create_connection + # raise err + # File "/home/travis/miniconda/lib/python3.3/socket.py", line 426, in create_connection + # sock.connect(sa) + # ConnectionRefusedError: [Errno 111] Connection refused + + # I.e.: just warn that the test failing, don't actually fail. + sys.stderr.write('Test failed: this test is brittle in travis because sometimes the connection is refused (as above) and we do not have a callback.\n') + return + + eq_(called_IPythonEditor[0], (os.path.abspath(filename), '0')) + assert called_RequestInput[0], "Make sure the 'wait' parameter has been respected" + finally: + sys.stdin = orig_stdin + client_thread.shutdown() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_pydevconsole.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_pydevconsole.py new file mode 100644 index 0000000..2569dbd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_pydevconsole.py @@ -0,0 +1,254 @@ +import threading +import unittest +import sys +import pydevconsole +from _pydev_bundle.pydev_imports import xmlrpclib, SimpleXMLRPCServer +from _pydevd_bundle import pydevd_io + +try: + raw_input + raw_input_name = 'raw_input' +except NameError: + raw_input_name = 'input' + + +#======================================================================================================================= +# Test +#======================================================================================================================= +class Test(unittest.TestCase): + + def test_console_hello(self): + self.original_stdout = sys.stdout + sys.stdout = pydevd_io.IOBuf() + try: + sys.stdout.encoding = sys.stdin.encoding + except AttributeError: + # In Python 3 encoding is not writable (whereas in Python 2 it doesn't exist). + pass + + try: + client_port, _server_port = self.get_free_addresses() + client_thread = self.start_client_thread(client_port) # @UnusedVariable + import time + time.sleep(.3) # let's give it some time to start the threads + + from _pydev_bundle import pydev_localhost + interpreter = pydevconsole.InterpreterInterface(pydev_localhost.get_localhost(), client_port, threading.currentThread()) + + (result,) = interpreter.hello("Hello pydevconsole") + self.assertEqual(result, "Hello eclipse") + finally: + sys.stdout = self.original_stdout + + def test_console_requests(self): + self.original_stdout = sys.stdout + sys.stdout = pydevd_io.IOBuf() + + try: + client_port, _server_port = self.get_free_addresses() + client_thread = self.start_client_thread(client_port) # @UnusedVariable + import time + time.sleep(.3) # let's give it some time to start the threads + + from _pydev_bundle import pydev_localhost + from _pydev_bundle.pydev_console_utils import CodeFragment + + interpreter = pydevconsole.InterpreterInterface(pydev_localhost.get_localhost(), client_port, threading.currentThread()) + sys.stdout = pydevd_io.IOBuf() + interpreter.add_exec(CodeFragment('class Foo:\n CONSTANT=1\n')) + interpreter.add_exec(CodeFragment('foo=Foo()')) + interpreter.add_exec(CodeFragment('foo.__doc__=None')) + interpreter.add_exec(CodeFragment('val = %s()' % (raw_input_name,))) + interpreter.add_exec(CodeFragment('50')) + interpreter.add_exec(CodeFragment('print (val)')) + found = sys.stdout.getvalue().split() + try: + self.assertEqual(['50', 'input_request'], found) + except: + try: + self.assertEqual(['input_request'], found) # IPython + except: + self.assertEqual([u'50', u'input_request'], found[1:]) # IPython 5.1 + self.assertTrue(found[0].startswith(u'Out')) + + comps = interpreter.getCompletions('foo.', 'foo.') + self.assertTrue( + ('CONSTANT', '', '', '3') in comps or ('CONSTANT', '', '', '4') in comps, \ + 'Found: %s' % comps + ) + + comps = interpreter.getCompletions('"".', '"".') + self.assertTrue( + ('__add__', 'x.__add__(y) <==> x+y', '', '3') in comps or + ('__add__', '', '', '4') in comps or + ('__add__', 'x.__add__(y) <==> x+y\r\nx.__add__(y) <==> x+y', '()', '2') in comps or + ('__add__', 'x.\n__add__(y) <==> x+yx.\n__add__(y) <==> x+y', '()', '2'), + 'Did not find __add__ in : %s' % (comps,) + ) + + completions = interpreter.getCompletions('', '') + for c in completions: + if c[0] == 'AssertionError': + break + else: + self.fail('Could not find AssertionError') + + completions = interpreter.getCompletions('Assert', 'Assert') + for c in completions: + if c[0] == 'RuntimeError': + self.fail('Did not expect to find RuntimeError there') + + self.assertTrue(('__doc__', None, '', '3') not in interpreter.getCompletions('foo.CO', 'foo.')) + + comps = interpreter.getCompletions('va', 'va') + self.assertTrue(('val', '', '', '3') in comps or ('val', '', '', '4') in comps) + + interpreter.add_exec(CodeFragment('s = "mystring"')) + + desc = interpreter.getDescription('val') + self.assertTrue(desc.find('str(object) -> string') >= 0 or + desc == "'input_request'" or + desc.find('str(string[, encoding[, errors]]) -> str') >= 0 or + desc.find('str(Char* value)') >= 0 or + desc.find('str(object=\'\') -> string') >= 0 or + desc.find('str(value: Char*)') >= 0 or + desc.find('str(object=\'\') -> str') >= 0 or + desc.find('The most base type') >= 0 # Jython 2.7 is providing this :P + , + 'Could not find what was needed in %s' % desc) + + desc = interpreter.getDescription('val.join') + self.assertTrue(desc.find('S.join(sequence) -> string') >= 0 or + desc.find('S.join(sequence) -> str') >= 0 or + desc.find('S.join(iterable) -> string') >= 0 or + desc == "" or + desc == "" or + desc.find('str join(str self, list sequence)') >= 0 or + desc.find('S.join(iterable) -> str') >= 0 or + desc.find('join(self: str, sequence: list) -> str') >= 0 or + desc.find('Concatenate any number of strings.') >= 0 or + desc.find('bound method str.join') >= 0, # PyPy + "Could not recognize: %s" % (desc,)) + finally: + sys.stdout = self.original_stdout + + def start_client_thread(self, client_port): + + class ClientThread(threading.Thread): + + def __init__(self, client_port): + threading.Thread.__init__(self) + self.client_port = client_port + + def run(self): + + class HandleRequestInput: + + def RequestInput(self): + client_thread.requested_input = True + return 'input_request' + + def NotifyFinished(self, *args, **kwargs): + client_thread.notified_finished += 1 + return 1 + + handle_request_input = HandleRequestInput() + + from _pydev_bundle import pydev_localhost + client_server = SimpleXMLRPCServer((pydev_localhost.get_localhost(), self.client_port), logRequests=False) + client_server.register_function(handle_request_input.RequestInput) + client_server.register_function(handle_request_input.NotifyFinished) + client_server.serve_forever() + + client_thread = ClientThread(client_port) + client_thread.requested_input = False + client_thread.notified_finished = 0 + client_thread.setDaemon(True) + client_thread.start() + return client_thread + + def start_debugger_server_thread(self, debugger_port, socket_code): + + class DebuggerServerThread(threading.Thread): + + def __init__(self, debugger_port, socket_code): + threading.Thread.__init__(self) + self.debugger_port = debugger_port + self.socket_code = socket_code + + def run(self): + import socket + s = socket.socket() + s.bind(('', debugger_port)) + s.listen(1) + socket, unused_addr = s.accept() + socket_code(socket) + + debugger_thread = DebuggerServerThread(debugger_port, socket_code) + debugger_thread.setDaemon(True) + debugger_thread.start() + return debugger_thread + + def get_free_addresses(self): + from _pydev_bundle.pydev_localhost import get_socket_names + socket_names = get_socket_names(2, True) + port0 = socket_names[0][1] + port1 = socket_names[1][1] + + assert port0 != port1 + assert port0 > 0 + assert port1 > 0 + + return port0, port1 + + def test_server(self): + self.original_stdout = sys.stdout + sys.stdout = pydevd_io.IOBuf() + try: + client_port, server_port = self.get_free_addresses() + + class ServerThread(threading.Thread): + + def __init__(self, client_port, server_port): + threading.Thread.__init__(self) + self.client_port = client_port + self.server_port = server_port + + def run(self): + from _pydev_bundle import pydev_localhost + pydevconsole.start_server(pydev_localhost.get_localhost(), self.server_port, self.client_port) + + server_thread = ServerThread(client_port, server_port) + server_thread.setDaemon(True) + server_thread.start() + + client_thread = self.start_client_thread(client_port) # @UnusedVariable + + import time + time.sleep(.3) # let's give it some time to start the threads + sys.stdout = pydevd_io.IOBuf() + + from _pydev_bundle import pydev_localhost + server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), server_port)) + server.execLine('class Foo:') + server.execLine(' pass') + server.execLine('') + server.execLine('foo = Foo()') + server.execLine('a = %s()' % (raw_input_name,)) + server.execLine('print (a)') + initial = time.time() + while not client_thread.requested_input: + if time.time() - initial > 2: + raise AssertionError('Did not get the return asked before the timeout.') + time.sleep(.1) + + found = sys.stdout.getvalue() + while ['input_request'] != found.split(): + found += sys.stdout.getvalue() + if time.time() - initial > 2: + break + time.sleep(.1) + self.assertEqual(['input_request'], found.split()) + finally: + sys.stdout = self.original_stdout + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_pyserver.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_pyserver.py new file mode 100644 index 0000000..d7d8610 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_pyserver.py @@ -0,0 +1,174 @@ +''' +@author Fabio Zadrozny +''' +import sys +import pytest +from _pydev_imps._pydev_saved_modules import thread + +start_new_thread = thread.start_new_thread + + +IS_PYTHON_3_ONWARDS = sys.version_info[0] >= 3 +IS_JYTHON = sys.platform.find('java') != -1 + +try: + import __builtin__ #@UnusedImport + BUILTIN_MOD = '__builtin__' +except ImportError: + BUILTIN_MOD = 'builtins' + + +if not IS_JYTHON: + import pycompletionserver + import socket + if not IS_PYTHON_3_ONWARDS: + from urllib import quote_plus, unquote_plus + def send(s, msg): + s.send(msg) + else: + from urllib.parse import quote_plus, unquote_plus #Python 3.0 + def send(s, msg): + s.send(bytearray(msg, 'utf-8')) + +import unittest + +@pytest.mark.skipif(IS_JYTHON, reason='Not applicable to Jython') +class TestCPython(unittest.TestCase): + + def test_message(self): + t = pycompletionserver.CompletionServer(0) + + l = [] + l.append(('Def', 'description' , 'args')) + l.append(('Def1', 'description1', 'args1')) + l.append(('Def2', 'description2', 'args2')) + + msg = t.processor.format_completion_message(None, l) + + self.assertEqual('@@COMPLETIONS(None,(Def,description,args),(Def1,description1,args1),(Def2,description2,args2))END@@', msg) + l = [] + l.append(('Def', 'desc,,r,,i()ption', '')) + l.append(('Def(1', 'descriptio(n1', '')) + l.append(('De,f)2', 'de,s,c,ription2', '')) + msg = t.processor.format_completion_message(None, l) + self.assertEqual('@@COMPLETIONS(None,(Def,desc%2C%2Cr%2C%2Ci%28%29ption, ),(Def%281,descriptio%28n1, ),(De%2Cf%292,de%2Cs%2Cc%2Cription2, ))END@@', msg) + + def create_connections(self): + ''' + Creates the connections needed for testing. + ''' + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server.bind((pycompletionserver.HOST, 0)) + server.listen(1) #socket to receive messages. + + t = pycompletionserver.CompletionServer(server.getsockname()[1]) + t.exit_process_on_kill = False + start_new_thread(t.run, ()) + + s, _addr = server.accept() + + return t, s + + + def read_msg(self): + finish = False + msg = '' + while finish == False: + m = self.socket.recv(1024 * 4) + if IS_PYTHON_3_ONWARDS: + m = m.decode('utf-8') + if m.startswith('@@PROCESSING'): + sys.stdout.write('Status msg: %s\n' % (msg,)) + else: + msg += m + + if msg.find('END@@') != -1: + finish = True + + return msg + + def test_completion_sockets_and_messages(self): + t, socket = self.create_connections() + self.socket = socket + + try: + #now that we have the connections all set up, check the code completion messages. + msg = quote_plus('math') + send(socket, '@@IMPORTS:%sEND@@' % msg) #math completions + completions = self.read_msg() + #print_ unquote_plus(completions) + + #math is a builtin and because of that, it starts with None as a file + start = '@@COMPLETIONS(None,(__doc__,' + start_2 = '@@COMPLETIONS(None,(__name__,' + if ('/math.so,' in completions or + '/math.cpython-33m.so,' in completions or + '/math.cpython-34m.so,' in completions or + 'math.cpython-35m' in completions or + 'math.cpython-36m' in completions or + 'math.cpython-37m' in completions + ): + return + self.assertTrue(completions.startswith(start) or completions.startswith(start_2), '%s DOESNT START WITH %s' % (completions, (start, start_2))) + + self.assertTrue('@@COMPLETIONS' in completions) + self.assertTrue('END@@' in completions) + + + #now, test i + msg = quote_plus('%s.list' % BUILTIN_MOD) + send(socket, "@@IMPORTS:%s\nEND@@" % msg) + found = self.read_msg() + self.assertTrue('sort' in found, 'Could not find sort in: %s' % (found,)) + + #now, test search + msg = quote_plus('inspect.ismodule') + send(socket, '@@SEARCH%sEND@@' % msg) #math completions + found = self.read_msg() + self.assertTrue('inspect.py' in found) + for i in range(33, 100): + if str(i) in found: + break + else: + self.fail('Could not find the ismodule line in %s' % (found,)) + + #now, test search + msg = quote_plus('inspect.CO_NEWLOCALS') + send(socket, '@@SEARCH%sEND@@' % msg) #math completions + found = self.read_msg() + self.assertTrue('inspect.py' in found) + self.assertTrue('CO_NEWLOCALS' in found) + + #now, test search + msg = quote_plus('inspect.BlockFinder.tokeneater') + send(socket, '@@SEARCH%sEND@@' % msg) + found = self.read_msg() + self.assertTrue('inspect.py' in found) +# self.assertTrue('CO_NEWLOCALS' in found) + + #reload modules test +# send(socket, '@@RELOAD_MODULES_END@@') +# ok = self.read_msg() +# self.assertEqual('@@MSG_OK_END@@' , ok) +# this test is not executed because it breaks our current enviroment. + + finally: + try: + sys.stdout.write('succedded...sending kill msg\n') + self.send_kill_msg(socket) + + +# while not hasattr(t, 'ended'): +# pass #wait until it receives the message and quits. + + + socket.close() + self.socket.close() + except: + pass + + def send_kill_msg(self, socket): + socket.send(pycompletionserver.MSG_KILL_SERVER) + + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests/test_simpleTipper.py b/adapter/python/ptvsd/_vendored/pydevd/tests/test_simpleTipper.py new file mode 100644 index 0000000..f3bc587 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests/test_simpleTipper.py @@ -0,0 +1,221 @@ +''' +@author Fabio Zadrozny +''' +from _pydev_bundle import _pydev_imports_tipper +import inspect +import pytest +import sys +import unittest + +try: + import __builtin__ # @UnusedImport + BUILTIN_MOD = '__builtin__' +except ImportError: + BUILTIN_MOD = 'builtins' + +IS_JYTHON = sys.platform.find('java') != -1 + +HAS_WX = False + + +@pytest.mark.skipif(IS_JYTHON, reason='CPython related test') +class TestCPython(unittest.TestCase): + + def p(self, t): + for a in t: + sys.stdout.write('%s\n' % (a,)) + + def test_imports3(self): + tip = _pydev_imports_tipper.generate_tip('os') + ret = self.assert_in('path', tip) + self.assertEqual('', ret[2]) + + def test_imports2(self): + try: + tip = _pydev_imports_tipper.generate_tip('OpenGL.GLUT') + self.assert_in('glutDisplayFunc', tip) + self.assert_in('glutInitDisplayMode', tip) + except ImportError: + pass + + def test_imports4(self): + try: + tip = _pydev_imports_tipper.generate_tip('mx.DateTime.mxDateTime.mxDateTime') + self.assert_in('now', tip) + except ImportError: + pass + + def test_imports5(self): + tip = _pydev_imports_tipper.generate_tip('%s.list' % BUILTIN_MOD) + s = self.assert_in('sort', tip) + self.check_args( + s, + '(cmp=None, key=None, reverse=False)', + '(self, object cmp, object key, bool reverse)', + '(self, cmp: object, key: object, reverse: bool)', + '(key=None, reverse=False)', + '(self, key=None, reverse=False)', + '(self, cmp, key, reverse)', + '(self, key, reverse)', + ) + + def test_imports2a(self): + tips = _pydev_imports_tipper.generate_tip('%s.RuntimeError' % BUILTIN_MOD) + self.assert_in('__doc__', tips) + + def test_imports2b(self): + try: + file + except: + pass + else: + tips = _pydev_imports_tipper.generate_tip('%s' % BUILTIN_MOD) + t = self.assert_in('file' , tips) + self.assertTrue('->' in t[1].strip() or 'file' in t[1]) + + def test_imports2c(self): + try: + file # file is not available on py 3 + except: + pass + else: + tips = _pydev_imports_tipper.generate_tip('%s.file' % BUILTIN_MOD) + t = self.assert_in('readlines' , tips) + self.assertTrue('->' in t[1] or 'sizehint' in t[1]) + + def test_imports(self): + ''' + You can print_ the results to check... + ''' + if HAS_WX: + tip = _pydev_imports_tipper.generate_tip('wxPython.wx') + self.assert_in('wxApp' , tip) + + tip = _pydev_imports_tipper.generate_tip('wxPython.wx.wxApp') + + try: + tip = _pydev_imports_tipper.generate_tip('qt') + self.assert_in('QWidget' , tip) + self.assert_in('QDialog' , tip) + + tip = _pydev_imports_tipper.generate_tip('qt.QWidget') + self.assert_in('rect' , tip) + self.assert_in('rect' , tip) + self.assert_in('AltButton' , tip) + + tip = _pydev_imports_tipper.generate_tip('qt.QWidget.AltButton') + self.assert_in('__xor__' , tip) + + tip = _pydev_imports_tipper.generate_tip('qt.QWidget.AltButton.__xor__') + self.assert_in('__class__' , tip) + except ImportError: + pass + + tip = _pydev_imports_tipper.generate_tip(BUILTIN_MOD) +# for t in tip[1]: +# print_ t + self.assert_in('object' , tip) + self.assert_in('tuple' , tip) + self.assert_in('list' , tip) + self.assert_in('RuntimeError' , tip) + self.assert_in('RuntimeWarning' , tip) + + # Remove cmp as it's not available on py 3 + # t = self.assert_in('cmp' , tip) + # self.check_args(t, '(x, y)', '(object x, object y)', '(x: object, y: object)') #args + + t = self.assert_in('isinstance' , tip) + self.check_args( + t, + '(object, class_or_type_or_tuple)', + '(object o, type typeinfo)', + '(o: object, typeinfo: type)', + '(obj, class_or_tuple)', + '(obj, klass_or_tuple)', + ) # args + + t = self.assert_in('compile' , tip) + self.check_args( + t, + '(source, filename, mode)', + '()', + '(o: object, name: str, val: object)', + '(source, filename, mode, flags, dont_inherit, optimize)', + '(source, filename, mode, flags, dont_inherit)', + ) # args + + t = self.assert_in('setattr' , tip) + self.check_args( + t, + '(object, name, value)', + '(object o, str name, object val)', + '(o: object, name: str, val: object)', + '(obj, name, value)', + '(object, name, val)', + ) # args + + try: + import compiler + compiler_module = 'compiler' + except ImportError: + try: + import ast + compiler_module = 'ast' + except ImportError: + compiler_module = None + + if compiler_module is not None: # Not available in iron python + tip = _pydev_imports_tipper.generate_tip(compiler_module) + if compiler_module == 'compiler': + self.assert_args('parse', '(buf, mode)', tip) + self.assert_args('walk', '(tree, visitor, walker, verbose)', tip) + self.assert_in('parseFile' , tip) + else: + self.assert_args('parse', '(source, filename, mode)', tip) + self.assert_args('walk', '(node)', tip) + self.assert_in('parse' , tip) + + def check_args(self, t, *expected): + for x in expected: + if x == t[2]: + return + self.fail('Found: %s. Expected: %s' % (t[2], expected)) + + def assert_args(self, tok, args, tips): + for a in tips[1]: + if tok == a[0]: + self.assertEqual(args, a[2]) + return + raise AssertionError('%s not in %s', tok, tips) + + def assert_in(self, tok, tips): + for a in tips[1]: + if tok == a[0]: + return a + raise AssertionError('%s not in %s' % (tok, tips)) + + def test_search(self): + s = _pydev_imports_tipper.search_definition('inspect.ismodule') + (f, line, col), foundAs = s + self.assertTrue(line > 0) + + def test_dot_net_libraries(self): + if sys.platform == 'cli': + tip = _pydev_imports_tipper.generate_tip('System.Drawing') + self.assert_in('Brushes' , tip) + + tip = _pydev_imports_tipper.generate_tip('System.Drawing.Brushes') + self.assert_in('Aqua' , tip) + + def test_inspect(self): + + class C(object): + + def metA(self, a, b): + pass + + obj = C.metA + if inspect.ismethod (obj): + pass +# print_ obj.im_func +# print_ inspect.getargspec(obj.im_func) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/README b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/README new file mode 100644 index 0000000..65e699b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/README @@ -0,0 +1,4 @@ +# Parts of IPython, files from: https://github.com/ipython/ipython/tree/rel-1.0.0/examples/lib +# The files in this folder are manual tests for main loop integration + +# These tests have been modified to work in the PyDev Console context diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-glut.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-glut.py new file mode 100644 index 0000000..34a16b4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-glut.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +"""Simple GLUT example to manually test event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for glut +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console +4) run: gl.glClearColor(1,1,1,1) +""" + +if __name__ == '__main__': + + #!/usr/bin/env python + import sys + import OpenGL.GL as gl + import OpenGL.GLUT as glut + + def close(): + glut.glutDestroyWindow(glut.glutGetWindow()) + + def display(): + gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) + glut.glutSwapBuffers() + + def resize(width,height): + gl.glViewport(0, 0, width, height+4) + gl.glMatrixMode(gl.GL_PROJECTION) + gl.glLoadIdentity() + gl.glOrtho(0, width, 0, height+4, -1, 1) + gl.glMatrixMode(gl.GL_MODELVIEW) + + if glut.glutGetWindow() > 0: + interactive = True + glut.glutInit(sys.argv) + glut.glutInitDisplayMode(glut.GLUT_DOUBLE | + glut.GLUT_RGBA | + glut.GLUT_DEPTH) + else: + interactive = False + + glut.glutCreateWindow('gui-glut') + glut.glutDisplayFunc(display) + glut.glutReshapeFunc(resize) + # This is necessary on osx to be able to close the window + # (else the close button is disabled) + if sys.platform == 'darwin' and not bool(glut.HAVE_FREEGLUT): + glut.glutWMCloseFunc(close) + gl.glClearColor(0,0,0,1) + + if not interactive: + glut.glutMainLoop() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-gtk.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-gtk.py new file mode 100644 index 0000000..6df5c78 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-gtk.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Simple GTK example to manually test event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for gtk +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console +""" + +if __name__ == '__main__': + import pygtk + pygtk.require('2.0') + import gtk + + + def hello_world(wigdet, data=None): + print("Hello World") + + def delete_event(widget, event, data=None): + return False + + def destroy(widget, data=None): + gtk.main_quit() + + window = gtk.Window(gtk.WINDOW_TOPLEVEL) + window.connect("delete_event", delete_event) + window.connect("destroy", destroy) + button = gtk.Button("Hello World") + button.connect("clicked", hello_world, None) + + window.add(button) + button.show() + window.show() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-gtk3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-gtk3.py new file mode 100644 index 0000000..6351d52 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-gtk3.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +"""Simple Gtk example to manually test event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for gtk3 +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console +""" + +if __name__ == '__main__': + from gi.repository import Gtk + + + def hello_world(wigdet, data=None): + print("Hello World") + + def delete_event(widget, event, data=None): + return False + + def destroy(widget, data=None): + Gtk.main_quit() + + window = Gtk.Window(Gtk.WindowType.TOPLEVEL) + window.connect("delete_event", delete_event) + window.connect("destroy", destroy) + button = Gtk.Button("Hello World") + button.connect("clicked", hello_world, None) + + window.add(button) + button.show() + window.show() + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-pyglet.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-pyglet.py new file mode 100644 index 0000000..70f1a7f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-pyglet.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +"""Simple pyglet example to manually test event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for pyglet +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console +""" + +if __name__ == '__main__': + import pyglet + + + window = pyglet.window.Window() + label = pyglet.text.Label('Hello, world', + font_name='Times New Roman', + font_size=36, + x=window.width//2, y=window.height//2, + anchor_x='center', anchor_y='center') + @window.event + def on_close(): + window.close() + + @window.event + def on_draw(): + window.clear() + label.draw() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-qt.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-qt.py new file mode 100644 index 0000000..30fc48d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-qt.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +"""Simple Qt4 example to manually test event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for qt +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console + +Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/ +""" + +if __name__ == '__main__': + import sys + from PyQt4 import QtGui, QtCore + + class SimpleWindow(QtGui.QWidget): + def __init__(self, parent=None): + QtGui.QWidget.__init__(self, parent) + + self.setGeometry(300, 300, 200, 80) + self.setWindowTitle('Hello World') + + quit = QtGui.QPushButton('Close', self) + quit.setGeometry(10, 10, 60, 35) + + self.connect(quit, QtCore.SIGNAL('clicked()'), + self, QtCore.SLOT('close()')) + + if __name__ == '__main__': + app = QtCore.QCoreApplication.instance() + if app is None: + app = QtGui.QApplication([]) + + sw = SimpleWindow() + sw.show() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-tk.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-tk.py new file mode 100644 index 0000000..4cef45f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-tk.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +"""Simple Tk example to manually test event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for tk +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console +""" + +if __name__ == '__main__': + + try: + from Tkinter import * + except: + # Python 3 + from tkinter import * + + class MyApp: + + def __init__(self, root): + frame = Frame(root) + frame.pack() + + self.button = Button(frame, text="Hello", command=self.hello_world) + self.button.pack(side=LEFT) + + def hello_world(self): + print("Hello World!") + + root = Tk() + + app = MyApp(root) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-wx.py b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-wx.py new file mode 100644 index 0000000..dfd35d8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_mainloop/gui-wx.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +""" +A Simple wx example to test PyDev's event loop integration. + +To run this: +1) Enable the PyDev GUI event loop integration for wx +2) do an execfile on this script +3) ensure you have a working GUI simultaneously with an + interactive console + +Ref: Modified from wxPython source code wxPython/samples/simple/simple.py +""" + +if __name__ == '__main__': + + import wx + + + class MyFrame(wx.Frame): + """ + This is MyFrame. It just shows a few controls on a wxPanel, + and has a simple menu. + """ + def __init__(self, parent, title): + wx.Frame.__init__(self, parent, -1, title, + pos=(150, 150), size=(350, 200)) + + # Create the menubar + menuBar = wx.MenuBar() + + # and a menu + menu = wx.Menu() + + # add an item to the menu, using \tKeyName automatically + # creates an accelerator, the third param is some help text + # that will show up in the statusbar + menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") + + # bind the menu event to an event handler + self.Bind(wx.EVT_MENU, self.on_time_to_close, id=wx.ID_EXIT) + + # and put the menu on the menubar + menuBar.Append(menu, "&File") + self.SetMenuBar(menuBar) + + self.CreateStatusBar() + + # Now create the Panel to put the other controls on. + panel = wx.Panel(self) + + # and a few controls + text = wx.StaticText(panel, -1, "Hello World!") + text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) + text.SetSize(text.GetBestSize()) + btn = wx.Button(panel, -1, "Close") + funbtn = wx.Button(panel, -1, "Just for fun...") + + # bind the button events to handlers + self.Bind(wx.EVT_BUTTON, self.on_time_to_close, btn) + self.Bind(wx.EVT_BUTTON, self.on_fun_button, funbtn) + + # Use a sizer to layout the controls, stacked vertically and with + # a 10 pixel border around each + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(text, 0, wx.ALL, 10) + sizer.Add(btn, 0, wx.ALL, 10) + sizer.Add(funbtn, 0, wx.ALL, 10) + panel.SetSizer(sizer) + panel.Layout() + + + def on_time_to_close(self, evt): + """Event handler for the button click.""" + print("See ya later!") + self.Close() + + def on_fun_button(self, evt): + """Event handler for the button click.""" + print("Having fun yet?") + + + class MyApp(wx.App): + def OnInit(self): + frame = MyFrame(None, "Simple wxPython App") + self.SetTopWindow(frame) + + print("Print statements go to this stdout window by default.") + + frame.Show(True) + return True + + + if __name__ == '__main__': + + app = wx.GetApp() + if app is None: + app = MyApp(redirect=False, clearSigInt=False) + else: + frame = MyFrame(None, "Simple wxPython App") + app.SetTopWindow(frame) + print("Print statements go to this stdout window by default.") + frame.Show(True) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/debug_constants.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/debug_constants.py new file mode 100644 index 0000000..83bc8f0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/debug_constants.py @@ -0,0 +1,43 @@ +import os +import sys +import platform + +TEST_CYTHON = os.getenv('PYDEVD_USE_CYTHON', None) == 'YES' +PYDEVD_TEST_VM = os.getenv('PYDEVD_TEST_VM', None) + +IS_PY3K = sys.version_info[0] >= 3 +IS_PY36_OR_GREATER = sys.version_info[0:2] >= (3, 6) +IS_CPYTHON = platform.python_implementation() == 'CPython' + +IS_PY2 = False +if sys.version_info[0] == 2: + IS_PY2 = True + +IS_PY26 = sys.version_info[:2] == (2, 6) +IS_PY27 = sys.version_info[:2] == (2, 7) +IS_PY34 = sys.version_info[:2] == (3, 4) +IS_PY36 = False +if sys.version_info[0] == 3 and sys.version_info[1] == 6: + IS_PY36 = True + +TEST_DJANGO = False +TEST_FLASK = False +TEST_CHERRYPY = False + +try: + import django + TEST_DJANGO = True +except: + pass + +try: + import flask + TEST_FLASK = True +except: + pass + +try: + import cherrypy + TEST_CHERRYPY = True +except: + pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/debugger_fixtures.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/debugger_fixtures.py new file mode 100644 index 0000000..a6d0a0e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/debugger_fixtures.py @@ -0,0 +1,512 @@ +# coding: utf-8 +from contextlib import contextmanager +import os +import threading + +import pytest + +from tests_python import debugger_unittest +from tests_python.debugger_unittest import (get_free_port, overrides, IS_CPYTHON, IS_JYTHON, IS_IRONPYTHON, + IS_PY3K, CMD_ADD_DJANGO_EXCEPTION_BREAK, CMD_REMOVE_DJANGO_EXCEPTION_BREAK, + CMD_ADD_EXCEPTION_BREAK, wait_for_condition, IS_PYPY) +from tests_python.debug_constants import IS_PY2 +from _pydevd_bundle.pydevd_comm_constants import file_system_encoding + +import sys +import time + + +def get_java_location(): + from java.lang import System # @UnresolvedImport + jre_dir = System.getProperty("java.home") + for f in [os.path.join(jre_dir, 'bin', 'java.exe'), os.path.join(jre_dir, 'bin', 'java')]: + if os.path.exists(f): + return f + raise RuntimeError('Unable to find java executable') + + +def get_jython_jar(): + from java.lang import ClassLoader # @UnresolvedImport + cl = ClassLoader.getSystemClassLoader() + paths = map(lambda url: url.getFile(), cl.getURLs()) + for p in paths: + if 'jython.jar' in p: + return p + raise RuntimeError('Unable to find jython.jar') + + +class _WriterThreadCaseMSwitch(debugger_unittest.AbstractWriterThread): + + TEST_FILE = 'tests_python.resources._debugger_case_m_switch' + IS_MODULE = True + + @overrides(debugger_unittest.AbstractWriterThread.get_environ) + def get_environ(self): + env = os.environ.copy() + curr_pythonpath = env.get('PYTHONPATH', '') + + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + curr_pythonpath += root_dirname + os.pathsep + env['PYTHONPATH'] = curr_pythonpath + return env + + @overrides(debugger_unittest.AbstractWriterThread.get_main_filename) + def get_main_filename(self): + return debugger_unittest._get_debugger_test_file('_debugger_case_m_switch.py') + + +class _WriterThreadCaseModuleWithEntryPoint(_WriterThreadCaseMSwitch): + + TEST_FILE = 'tests_python.resources._debugger_case_module_entry_point:main' + IS_MODULE = True + + @overrides(_WriterThreadCaseMSwitch.get_main_filename) + def get_main_filename(self): + return debugger_unittest._get_debugger_test_file('_debugger_case_module_entry_point.py') + + +class AbstractWriterThreadCaseFlask(debugger_unittest.AbstractWriterThread): + + FORCE_KILL_PROCESS_WHEN_FINISHED_OK = True + FLASK_FOLDER = None + + TEST_FILE = 'flask' + IS_MODULE = True + + def write_add_breakpoint_jinja2(self, line, func, template): + ''' + @param line: starts at 1 + ''' + assert self.FLASK_FOLDER is not None + breakpoint_id = self.next_breakpoint_id() + template_file = debugger_unittest._get_debugger_test_file(os.path.join(self.FLASK_FOLDER, 'templates', template)) + self.write("111\t%s\t%s\t%s\t%s\t%s\t%s\tNone\tNone" % (self.next_seq(), breakpoint_id, 'jinja2-line', template_file, line, func)) + self.log.append('write_add_breakpoint_jinja: %s line: %s func: %s' % (breakpoint_id, line, func)) + return breakpoint_id + + def write_add_exception_breakpoint_jinja2(self, exception='jinja2-Exception'): + self.write('%s\t%s\t%s\t%s\t%s\t%s' % (CMD_ADD_EXCEPTION_BREAK, self.next_seq(), exception, 2, 0, 0)) + + @overrides(debugger_unittest.AbstractWriterThread.get_environ) + def get_environ(self): + import platform + + env = os.environ.copy() + env['FLASK_APP'] = 'app.py' + env['FLASK_ENV'] = 'development' + env['FLASK_DEBUG'] = '0' + if platform.system() != 'Windows': + locale = 'en_US.utf8' if platform.system() == 'Linux' else 'en_US.UTF-8' + env.update({ + 'LC_ALL': locale, + 'LANG': locale, + }) + return env + + def get_cwd(self): + return debugger_unittest._get_debugger_test_file(self.FLASK_FOLDER) + + def get_command_line_args(self): + assert self.FLASK_FOLDER is not None + free_port = get_free_port() + self.flask_port = free_port + return [ + 'flask', + 'run', + '--no-debugger', + '--no-reload', + '--with-threads', + '--port', + str(free_port), + ] + + def _ignore_stderr_line(self, line): + if debugger_unittest.AbstractWriterThread._ignore_stderr_line(self, line): + return True + + if 'Running on http:' in line: + return True + + if 'GET / HTTP/' in line: + return True + + return False + + def create_request_thread(self, url=''): + return debugger_unittest.AbstractWriterThread.create_request_thread( + self, 'http://127.0.0.1:%s%s' % (self.flask_port, url)) + + +class AbstractWriterThreadCaseDjango(debugger_unittest.AbstractWriterThread): + + FORCE_KILL_PROCESS_WHEN_FINISHED_OK = True + DJANGO_FOLDER = None + + def _ignore_stderr_line(self, line): + if debugger_unittest.AbstractWriterThread._ignore_stderr_line(self, line): + return True + + if 'GET /my_app' in line: + return True + + return False + + def get_command_line_args(self): + assert self.DJANGO_FOLDER is not None + free_port = get_free_port() + self.django_port = free_port + return [ + debugger_unittest._get_debugger_test_file(os.path.join(self.DJANGO_FOLDER, 'manage.py')), + 'runserver', + '--noreload', + '--nothreading', + str(free_port), + ] + + def write_add_breakpoint_django(self, line, func, template): + ''' + @param line: starts at 1 + ''' + assert self.DJANGO_FOLDER is not None + breakpoint_id = self.next_breakpoint_id() + template_file = debugger_unittest._get_debugger_test_file(os.path.join(self.DJANGO_FOLDER, 'my_app', 'templates', 'my_app', template)) + self.write("111\t%s\t%s\t%s\t%s\t%s\t%s\tNone\tNone" % (self.next_seq(), breakpoint_id, 'django-line', template_file, line, func)) + self.log.append('write_add_django_breakpoint: %s line: %s func: %s' % (breakpoint_id, line, func)) + return breakpoint_id + + def write_add_exception_breakpoint_django(self, exception='Exception'): + self.write('%s\t%s\t%s' % (CMD_ADD_DJANGO_EXCEPTION_BREAK, self.next_seq(), exception)) + + def write_remove_exception_breakpoint_django(self, exception='Exception'): + self.write('%s\t%s\t%s' % (CMD_REMOVE_DJANGO_EXCEPTION_BREAK, self.next_seq(), exception)) + + def create_request_thread(self, url=''): + return debugger_unittest.AbstractWriterThread.create_request_thread( + self, 'http://127.0.0.1:%s/%s' % (self.django_port, url)) + + +class DebuggerRunnerSimple(debugger_unittest.DebuggerRunner): + + def get_command_line(self): + if IS_JYTHON: + if sys.executable is not None: + # i.e.: we're running with the provided jython.exe + return [sys.executable] + else: + + return [ + get_java_location(), + '-classpath', + get_jython_jar(), + 'org.python.util.jython' + ] + + if IS_CPYTHON or IS_PYPY: + return [sys.executable, '-u'] + + if IS_IRONPYTHON: + return [ + sys.executable, + '-X:Frames' + ] + + raise RuntimeError('Unable to provide command line') + + +class DebuggerRunnerRemote(debugger_unittest.DebuggerRunner): + + def get_command_line(self): + return [sys.executable, '-u'] + + def add_command_line_args(self, args): + writer = self.writer + + ret = args + [self.writer.TEST_FILE] + ret = writer.update_command_line_args(ret) # Provide a hook for the writer + return ret + + +@pytest.fixture +def case_setup(tmpdir): + + runner = DebuggerRunnerSimple() + + class WriterThread(debugger_unittest.AbstractWriterThread): + pass + + class CaseSetup(object): + + check_non_ascii = False + NON_ASCII_CHARS = u'áéíóú汉字' + + @contextmanager + def test_file( + self, + filename, + **kwargs + ): + import shutil + filename = debugger_unittest._get_debugger_test_file(filename) + if self.check_non_ascii: + basedir = str(tmpdir) + if isinstance(basedir, bytes): + basedir = basedir.decode('utf-8') + if isinstance(filename, bytes): + filename = filename.decode('utf-8') + + new_dir = os.path.join(basedir, self.NON_ASCII_CHARS) + os.makedirs(new_dir) + + new_filename = os.path.join(new_dir, self.NON_ASCII_CHARS + os.path.basename(filename)) + shutil.copyfile(filename, new_filename) + filename = new_filename + + if IS_PY2: + filename = filename.encode(file_system_encoding) + + WriterThread.TEST_FILE = filename + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + with runner.check_case(WriterThread) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_unhandled_exceptions(case_setup): + + original = case_setup.test_file + + def check_test_suceeded_msg(writer, stdout, stderr): + return 'TEST SUCEEDED' in ''.join(stderr) + + def additional_output_checks(writer, stdout, stderr): + # Don't call super as we have an expected exception + if 'ValueError: TEST SUCEEDED' not in stderr: + raise AssertionError('"ValueError: TEST SUCEEDED" not in stderr.\nstdout:\n%s\n\nstderr:\n%s' % ( + stdout, stderr)) + + def test_file(*args, **kwargs): + kwargs.setdefault('check_test_suceeded_msg', check_test_suceeded_msg) + kwargs.setdefault('additional_output_checks', additional_output_checks) + return original(*args, **kwargs) + + case_setup.test_file = test_file + + return case_setup + + +@pytest.fixture +def case_setup_remote(): + + runner = DebuggerRunnerRemote() + + class WriterThread(debugger_unittest.AbstractWriterThread): + pass + + class CaseSetup(object): + + @contextmanager + def test_file( + self, + filename, + wait_for_port=True, + **kwargs + ): + + def update_command_line_args(writer, args): + ret = debugger_unittest.AbstractWriterThread.update_command_line_args(writer, args) + wait_for_condition(lambda: hasattr(writer, 'port')) + ret.append(str(writer.port)) + return ret + + WriterThread.TEST_FILE = debugger_unittest._get_debugger_test_file(filename) + WriterThread.update_command_line_args = update_command_line_args + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + with runner.check_case(WriterThread, wait_for_port=wait_for_port) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_remote_attach_to(): + ''' + The difference from this to case_setup_remote is that this one will connect to a server + socket started by the debugger and case_setup_remote will create the server socket and wait + for a connection from the debugger. + ''' + + runner = DebuggerRunnerRemote() + + class WriterThread(debugger_unittest.AbstractWriterThread): + + @overrides(debugger_unittest.AbstractWriterThread.run) + def run(self): + # I.e.: don't start socket on start(), rather, the test should call + # start_socket_client() when needed. + pass + + class CaseSetup(object): + + @contextmanager + def test_file( + self, + filename, + port, + **kwargs + ): + + def update_command_line_args(writer, args): + ret = debugger_unittest.AbstractWriterThread.update_command_line_args(writer, args) + ret.append(str(port)) + return ret + + WriterThread.TEST_FILE = debugger_unittest._get_debugger_test_file(filename) + WriterThread.update_command_line_args = update_command_line_args + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + with runner.check_case(WriterThread, wait_for_port=False) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_multiprocessing(): + + runner = DebuggerRunnerSimple() + + class WriterThread(debugger_unittest.AbstractWriterThread): + pass + + class CaseSetup(object): + + @contextmanager + def test_file( + self, + filename, + **kwargs + ): + + def update_command_line_args(writer, args): + ret = debugger_unittest.AbstractWriterThread.update_command_line_args(writer, args) + ret.insert(ret.index('--qt-support'), '--multiprocess') + return ret + + WriterThread.update_command_line_args = update_command_line_args + WriterThread.TEST_FILE = debugger_unittest._get_debugger_test_file(filename) + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + with runner.check_case(WriterThread) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_m_switch(): + + runner = DebuggerRunnerSimple() + + class WriterThread(_WriterThreadCaseMSwitch): + pass + + class CaseSetup(object): + + @contextmanager + def test_file(self, **kwargs): + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + with runner.check_case(WriterThread) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_m_switch_entry_point(): + + runner = DebuggerRunnerSimple() + + class WriterThread(_WriterThreadCaseModuleWithEntryPoint): + pass + + class CaseSetup(object): + + @contextmanager + def test_file(self, **kwargs): + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + with runner.check_case(WriterThread) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_django(): + + runner = DebuggerRunnerSimple() + + class WriterThread(AbstractWriterThreadCaseDjango): + pass + + class CaseSetup(object): + + @contextmanager + def test_file(self, **kwargs): + import django + version = [int(x) for x in django.get_version().split('.')][:2] + if version == [1, 7]: + django_folder = 'my_django_proj_17' + elif version in ([2, 1], [2, 2]): + django_folder = 'my_django_proj_21' + else: + raise AssertionError('Can only check django 1.7, 2.1 and 2.2 right now. Found: %s' % (version,)) + + WriterThread.DJANGO_FOLDER = django_folder + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + with runner.check_case(WriterThread) as writer: + yield writer + + return CaseSetup() + + +@pytest.fixture +def case_setup_flask(): + + runner = DebuggerRunnerSimple() + + class WriterThread(AbstractWriterThreadCaseFlask): + pass + + class CaseSetup(object): + + @contextmanager + def test_file(self, **kwargs): + WriterThread.FLASK_FOLDER = 'flask1' + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + with runner.check_case(WriterThread) as writer: + yield writer + + return CaseSetup() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/debugger_unittest.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/debugger_unittest.py new file mode 100644 index 0000000..b95b799 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/debugger_unittest.py @@ -0,0 +1,1299 @@ +from collections import namedtuple +from contextlib import contextmanager +import json +try: + from urllib import quote, quote_plus, unquote_plus +except ImportError: + from urllib.parse import quote, quote_plus, unquote_plus # @UnresolvedImport + +import re +import socket +import subprocess +import threading +import time +import traceback +from tests_python.debug_constants import * + +from _pydev_bundle import pydev_localhost + +# Note: copied (don't import because we want it to be independent on the actual code because of backward compatibility). +CMD_RUN = 101 +CMD_LIST_THREADS = 102 +CMD_THREAD_CREATE = 103 +CMD_THREAD_KILL = 104 +CMD_THREAD_SUSPEND = 105 +CMD_THREAD_RUN = 106 +CMD_STEP_INTO = 107 +CMD_STEP_OVER = 108 +CMD_STEP_RETURN = 109 +CMD_GET_VARIABLE = 110 +CMD_SET_BREAK = 111 +CMD_REMOVE_BREAK = 112 +CMD_EVALUATE_EXPRESSION = 113 +CMD_GET_FRAME = 114 +CMD_EXEC_EXPRESSION = 115 +CMD_WRITE_TO_CONSOLE = 116 +CMD_CHANGE_VARIABLE = 117 +CMD_RUN_TO_LINE = 118 +CMD_RELOAD_CODE = 119 +CMD_GET_COMPLETIONS = 120 + +# Note: renumbered (conflicted on merge) +CMD_CONSOLE_EXEC = 121 +CMD_ADD_EXCEPTION_BREAK = 122 +CMD_REMOVE_EXCEPTION_BREAK = 123 +CMD_LOAD_SOURCE = 124 +CMD_ADD_DJANGO_EXCEPTION_BREAK = 125 +CMD_REMOVE_DJANGO_EXCEPTION_BREAK = 126 +CMD_SET_NEXT_STATEMENT = 127 +CMD_SMART_STEP_INTO = 128 +CMD_EXIT = 129 +CMD_SIGNATURE_CALL_TRACE = 130 + +CMD_SET_PY_EXCEPTION = 131 +CMD_GET_FILE_CONTENTS = 132 +CMD_SET_PROPERTY_TRACE = 133 +# Pydev debug console commands +CMD_EVALUATE_CONSOLE_EXPRESSION = 134 +CMD_RUN_CUSTOM_OPERATION = 135 +CMD_GET_BREAKPOINT_EXCEPTION = 136 +CMD_STEP_CAUGHT_EXCEPTION = 137 +CMD_SEND_CURR_EXCEPTION_TRACE = 138 +CMD_SEND_CURR_EXCEPTION_TRACE_PROCEEDED = 139 +CMD_IGNORE_THROWN_EXCEPTION_AT = 140 +CMD_ENABLE_DONT_TRACE = 141 +CMD_SHOW_CONSOLE = 142 + +CMD_GET_ARRAY = 143 +CMD_STEP_INTO_MY_CODE = 144 +CMD_GET_CONCURRENCY_EVENT = 145 +CMD_SHOW_RETURN_VALUES = 146 + +CMD_GET_THREAD_STACK = 152 +CMD_THREAD_DUMP_TO_STDERR = 153 # This is mostly for unit-tests to diagnose errors on ci. +CMD_STOP_ON_START = 154 +CMD_GET_EXCEPTION_DETAILS = 155 +CMD_PYDEVD_JSON_CONFIG = 156 + +CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION = 157 +CMD_THREAD_RESUME_SINGLE_NOTIFICATION = 158 + +CMD_STEP_OVER_MY_CODE = 159 +CMD_STEP_RETURN_MY_CODE = 160 + +CMD_REDIRECT_OUTPUT = 200 +CMD_GET_NEXT_STATEMENT_TARGETS = 201 +CMD_SET_PROJECT_ROOTS = 202 + +CMD_VERSION = 501 +CMD_RETURN = 502 +CMD_SET_PROTOCOL = 503 +CMD_ERROR = 901 + +REASON_CAUGHT_EXCEPTION = CMD_STEP_CAUGHT_EXCEPTION +REASON_UNCAUGHT_EXCEPTION = CMD_ADD_EXCEPTION_BREAK +REASON_STOP_ON_BREAKPOINT = CMD_SET_BREAK +REASON_THREAD_SUSPEND = CMD_THREAD_SUSPEND +REASON_STEP_INTO = CMD_STEP_INTO +REASON_STEP_INTO_MY_CODE = CMD_STEP_INTO_MY_CODE +REASON_STEP_RETURN = CMD_STEP_RETURN +REASON_STEP_RETURN_MY_CODE = CMD_STEP_RETURN_MY_CODE +REASON_STEP_OVER = CMD_STEP_OVER +REASON_STEP_OVER_MY_CODE = CMD_STEP_OVER_MY_CODE + +# Always True (because otherwise when we do have an error, it's hard to diagnose). +SHOW_WRITES_AND_READS = True +SHOW_OTHER_DEBUG_INFO = True +SHOW_STDOUT = True + +import platform + +IS_CPYTHON = platform.python_implementation() == 'CPython' +IS_IRONPYTHON = platform.python_implementation() == 'IronPython' +IS_JYTHON = platform.python_implementation() == 'Jython' +IS_PYPY = platform.python_implementation() == 'PyPy' +IS_APPVEYOR = os.environ.get('APPVEYOR', '') in ('True', 'true', '1') + +try: + from thread import start_new_thread +except ImportError: + from _thread import start_new_thread # @UnresolvedImport + +try: + xrange +except: + xrange = range + +Hit = namedtuple('Hit', 'thread_id, frame_id, line, suspend_type, name, file') + + +def overrides(method): + ''' + Helper to check that one method overrides another (redeclared in unit-tests to avoid importing pydevd). + ''' + + def wrapper(func): + if func.__name__ != method.__name__: + msg = "Wrong @override: %r expected, but overwriting %r." + msg = msg % (func.__name__, method.__name__) + raise AssertionError(msg) + + if func.__doc__ is None: + func.__doc__ = method.__doc__ + + return func + + return wrapper + + +TIMEOUT = 20 + + +class TimeoutError(RuntimeError): + pass + + +def wait_for_condition(condition, msg=None, timeout=TIMEOUT, sleep=.05): + curtime = time.time() + while True: + if condition(): + break + if time.time() - curtime > timeout: + error_msg = 'Condition not reached in %s seconds' % (timeout,) + if msg is not None: + error_msg += '\n' + if callable(msg): + error_msg += msg() + else: + error_msg += str(msg) + + raise TimeoutError(error_msg) + time.sleep(sleep) + + +#======================================================================================================================= +# ReaderThread +#======================================================================================================================= +class ReaderThread(threading.Thread): + + MESSAGES_TIMEOUT = 15 + + def __init__(self, sock): + threading.Thread.__init__(self) + self.name = 'Test Reader Thread' + try: + from queue import Queue + except ImportError: + from Queue import Queue + + self.setDaemon(True) + self._buffer = b'' + self.sock = sock + self._queue = Queue() + self._kill = False + self.accept_xml_messages = True + + def set_messages_timeout(self, timeout): + self.MESSAGES_TIMEOUT = timeout + + def get_next_message(self, context_message, timeout=None): + if timeout is None: + timeout = self.MESSAGES_TIMEOUT + try: + msg = self._queue.get(block=True, timeout=timeout) + except: + raise TimeoutError('No message was written in %s seconds. Error message:\n%s' % (timeout, context_message,)) + else: + frame = sys._getframe().f_back.f_back + frame_info = '' + while frame: + if not frame.f_code.co_name.startswith('test_'): + frame = frame.f_back + continue + + if frame.f_code.co_filename.endswith('debugger_unittest.py'): + frame = frame.f_back + continue + + stack_msg = ' -- File "%s", line %s, in %s\n' % (frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name) + if 'run' == frame.f_code.co_name: + frame_info = stack_msg # Ok, found the writer thread 'run' method (show only that). + break + frame_info += stack_msg + frame = frame.f_back + # Just print the first which is not debugger_unittest.py + break + + frame = None + sys.stdout.write('Message returned in get_next_message(): %s -- ctx: %s, asked at:\n%s\n' % (unquote_plus(unquote_plus(msg)), context_message, frame_info)) + + if not self.accept_xml_messages: + if ' size: + ret = self._buffer[:size] + self._buffer = self._buffer[size:] + return ret + + r = self.sock.recv(max(size - buffer_len, 1024)) + if not r: + return b'' + self._buffer += r + + def _read_line(self): + while True: + i = self._buffer.find(b'\n') + if i != -1: + i += 1 # Add the newline to the return + ret = self._buffer[:i] + self._buffer = self._buffer[i:] + return ret + else: + r = self.sock.recv(1024) + if not r: + return b'' + self._buffer += r + + def run(self): + try: + content_len = -1 + + while not self._kill: + line = self._read_line() + + if not line: + break + + if SHOW_WRITES_AND_READS: + show_line = line + if IS_PY3K: + show_line = line.decode('utf-8') + + print('%s Received %s' % (self.name, show_line,)) + + if line.startswith(b'Content-Length:'): + content_len = int(line.strip().split(b':', 1)[1]) + continue + + if content_len != -1: + # If we previously received a content length, read until a '\r\n'. + if line == b'\r\n': + json_contents = self._read(content_len) + content_len = -1 + + if len(json_contents) == 0: + self.handle_except() + return # Finished communication. + + msg = json_contents + if IS_PY3K: + msg = msg.decode('utf-8') + print('Test Reader Thread Received %s' % (msg,)) + self._queue.put(msg) + + continue + else: + # No content len, regular line-based protocol message (remove trailing new-line). + if line.endswith(b'\n\n'): + line = line[:-2] + + elif line.endswith(b'\n'): + line = line[:-1] + + elif line.endswith(b'\r'): + line = line[:-1] + + msg = line + if IS_PY3K: + msg = msg.decode('utf-8') + print('Test Reader Thread Received %s' % (msg,)) + self._queue.put(msg) + + except: + pass # ok, finished it + + def do_kill(self): + self._kill = True + if hasattr(self, 'sock'): + self.sock.close() + + +def read_process(stream, buffer, debug_stream, stream_name, finish): + while True: + line = stream.readline() + if not line: + break + + if IS_PY3K: + line = line.decode('utf-8', errors='replace') + + if SHOW_STDOUT: + debug_stream.write('%s: %s' % (stream_name, line,)) + buffer.append(line) + + if finish[0]: + return + + +def start_in_daemon_thread(target, args): + t0 = threading.Thread(target=target, args=args) + t0.setDaemon(True) + t0.start() + + +class DebuggerRunner(object): + + def get_command_line(self): + ''' + Returns the base command line (i.e.: ['python.exe', '-u']) + ''' + raise NotImplementedError + + def add_command_line_args(self, args): + writer = self.writer + port = int(writer.port) + + localhost = pydev_localhost.get_localhost() + ret = [ + writer.get_pydevd_file(), + '--DEBUG_RECORD_SOCKET_READS', + '--qt-support', + '--client', + localhost, + '--port', + str(port), + ] + + if writer.IS_MODULE: + ret += ['--module'] + + ret += ['--file'] + writer.get_command_line_args() + ret = writer.update_command_line_args(ret) # Provide a hook for the writer + return args + ret + + @contextmanager + def check_case(self, writer_class, wait_for_port=True): + if callable(writer_class): + writer = writer_class() + else: + writer = writer_class + try: + writer.start() + if wait_for_port: + wait_for_condition(lambda: hasattr(writer, 'port')) + self.writer = writer + + args = self.get_command_line() + + args = self.add_command_line_args(args) + + if SHOW_OTHER_DEBUG_INFO: + print('executing: %s' % (' '.join(args),)) + + with self.run_process(args, writer) as dct_with_stdout_stder: + try: + if wait_for_port: + wait_for_condition(lambda: writer.finished_initialization) + except TimeoutError: + sys.stderr.write('Timed out waiting for initialization\n') + sys.stderr.write('stdout:\n%s\n\nstderr:\n%s\n' % ( + ''.join(dct_with_stdout_stder['stdout']), + ''.join(dct_with_stdout_stder['stderr']), + )) + raise + finally: + writer.get_stdout = lambda: ''.join(dct_with_stdout_stder['stdout']) + writer.get_stderr = lambda: ''.join(dct_with_stdout_stder['stderr']) + + yield writer + finally: + writer.do_kill() + writer.log = [] + + stdout = dct_with_stdout_stder['stdout'] + stderr = dct_with_stdout_stder['stderr'] + writer.additional_output_checks(''.join(stdout), ''.join(stderr)) + + def create_process(self, args, writer): + process = subprocess.Popen( + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=writer.get_cwd() if writer is not None else '.', + env=writer.get_environ() if writer is not None else None, + ) + return process + + @contextmanager + def run_process(self, args, writer): + process = self.create_process(args, writer) + writer.process = process + stdout = [] + stderr = [] + finish = [False] + dct_with_stdout_stder = {} + + try: + start_in_daemon_thread(read_process, (process.stdout, stdout, sys.stdout, 'stdout', finish)) + start_in_daemon_thread(read_process, (process.stderr, stderr, sys.stderr, 'stderr', finish)) + + if SHOW_OTHER_DEBUG_INFO: + print('Both processes started') + + # polls can fail (because the process may finish and the thread still not -- so, we give it some more chances to + # finish successfully). + initial_time = time.time() + shown_intermediate = False + dumped_threads = False + + dct_with_stdout_stder['stdout'] = stdout + dct_with_stdout_stder['stderr'] = stderr + yield dct_with_stdout_stder + + if not writer.finished_ok: + self.fail_with_message( + "The thread that was doing the tests didn't finish successfully.", stdout, stderr, writer) + + while True: + if process.poll() is not None: + if writer.EXPECTED_RETURNCODE != 'any': + expected_returncode = writer.EXPECTED_RETURNCODE + if not isinstance(expected_returncode, (list, tuple)): + expected_returncode = (expected_returncode,) + + if process.returncode not in expected_returncode: + self.fail_with_message('Expected process.returncode to be %s. Found: %s' % ( + writer.EXPECTED_RETURNCODE, process.returncode), stdout, stderr, writer) + break + else: + if writer is not None: + if writer.FORCE_KILL_PROCESS_WHEN_FINISHED_OK: + process.kill() + continue + + if not shown_intermediate and (time.time() - initial_time > (TIMEOUT / 3.)): # 1/3 of timeout + print('Warning: writer thread exited and process still did not (%.2fs seconds elapsed).' % (time.time() - initial_time,)) + shown_intermediate = True + + if time.time() - initial_time > ((TIMEOUT / 3.) * 2.): # 2/3 of timeout + if not dumped_threads: + dumped_threads = True + # It still didn't finish. Ask for a thread dump + # (we'll be able to see it later on the test output stderr). + try: + writer.write_dump_threads() + except: + traceback.print_exc() + + if time.time() - initial_time > TIMEOUT: # timed out + process.kill() + time.sleep(.2) + self.fail_with_message( + "The other process should've exited but still didn't (%.2fs seconds timeout for process to exit)." % (time.time() - initial_time,), + stdout, stderr, writer + ) + time.sleep(.2) + + if writer is not None: + if not writer.FORCE_KILL_PROCESS_WHEN_FINISHED_OK: + if stdout is None: + self.fail_with_message( + "The other process may still be running -- and didn't give any output.", stdout, stderr, writer) + + check = 0 + while not writer.check_test_suceeded_msg(stdout, stderr): + check += 1 + if check == 50: + self.fail_with_message("TEST SUCEEDED not found.", stdout, stderr, writer) + time.sleep(.1) + + except TimeoutError: + writer.write_dump_threads() + time.sleep(.2) + raise + finally: + finish[0] = True + + def fail_with_message(self, msg, stdout, stderr, writerThread): + raise AssertionError(msg + + "\n\n===========================\nStdout: \n" + ''.join(stdout) + + "\n\n===========================\nStderr:" + ''.join(stderr) + + "\n\n===========================\nLog:\n" + '\n'.join(getattr(writerThread, 'log', []))) + + +#======================================================================================================================= +# AbstractWriterThread +#======================================================================================================================= +class AbstractWriterThread(threading.Thread): + + FORCE_KILL_PROCESS_WHEN_FINISHED_OK = False + IS_MODULE = False + TEST_FILE = None + EXPECTED_RETURNCODE = 0 + + def __init__(self, *args, **kwargs): + threading.Thread.__init__(self, *args, **kwargs) + self.process = None # Set after the process is created. + self.setDaemon(True) + self.finished_ok = False + self.finished_initialization = False + self._next_breakpoint_id = 0 + self.log = [] + + def run(self): + self.start_socket() + + def check_test_suceeded_msg(self, stdout, stderr): + return 'TEST SUCEEDED' in ''.join(stdout) + + def update_command_line_args(self, args): + return args + + def _ignore_stderr_line(self, line): + if line.startswith(( + 'debugger: ', + '>>', + '<<', + 'warning: Debugger speedups', + 'pydev debugger: New process is launching', + 'pydev debugger: To debug that process', + )): + return True + + for expected in ( + 'PyDev console: using IPython', + 'Attempting to work in a virtualenv. If you encounter problems, please', + ): + if expected in line: + return True + + if re.match(r'^(\d+)\t(\d)+', line): + return True + + if IS_JYTHON: + for expected in ( + 'org.python.netty.util.concurrent.DefaultPromise', + 'org.python.netty.util.concurrent.SingleThreadEventExecutor', + 'Failed to submit a listener notification task. Event loop shut down?', + 'java.util.concurrent.RejectedExecutionException', + 'An event executor terminated with non-empty task', + 'java.lang.UnsupportedOperationException', + "RuntimeWarning: Parent module '_pydevd_bundle' not found while handling absolute import", + 'from _pydevd_bundle.pydevd_additional_thread_info_regular import _current_frames', + 'from _pydevd_bundle.pydevd_additional_thread_info import _current_frames', + 'import org.python.core as PyCore #@UnresolvedImport', + 'from _pydevd_bundle.pydevd_additional_thread_info import set_additional_thread_info', + "RuntimeWarning: Parent module '_pydevd_bundle._debug_adapter' not found while handling absolute import", + 'import json', + + # Issues with Jython and Java 9. + 'WARNING: Illegal reflective access by org.python.core.PySystemState', + 'WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState', + 'WARNING: An illegal reflective access operation has occurred', + 'WARNING: Illegal reflective access by jnr.posix.JavaLibCHelper', + 'WARNING: Please consider reporting this to the maintainers of jnr.posix.JavaLibCHelper', + 'WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations', + 'WARNING: All illegal access operations will be denied in a future release', + ): + if expected in line: + return True + + if line.strip().startswith('at '): + return True + + if IS_PY26: + # Sometimes in the ci there's an unhandled exception which doesn't have a stack trace + # (apparently this happens when a daemon thread dies during process shutdown). + # This was only reproducible on the ci on Python 2.6, so, ignoring that output on Python 2.6 only. + for expected in ( + 'Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace'): + if expected in line: + return True + return False + + def additional_output_checks(self, stdout, stderr): + lines_with_error = [] + for line in stderr.splitlines(): + line = line.strip() + if not line: + continue + if not self._ignore_stderr_line(line): + lines_with_error.append(line) + + if lines_with_error: + raise AssertionError('Did not expect to have line(s) in stderr:\n\n%s\n\nFull stderr:\n\n%s' % ( + '\n'.join(lines_with_error), stderr)) + + def get_environ(self): + return None + + def get_pydevd_file(self): + dirname = os.path.dirname(__file__) + dirname = os.path.dirname(dirname) + return os.path.abspath(os.path.join(dirname, 'pydevd.py')) + + def get_pydevconsole_file(self): + dirname = os.path.dirname(__file__) + dirname = os.path.dirname(dirname) + return os.path.abspath(os.path.join(dirname, 'pydevconsole.py')) + + def get_line_index_with_content(self, line_content): + ''' + :return the line index which has the given content (1-based). + ''' + with open(self.TEST_FILE, 'r') as stream: + for i_line, line in enumerate(stream): + if line_content in line: + return i_line + 1 + raise AssertionError('Did not find: %s in %s' % (line_content, self.TEST_FILE)) + + def get_cwd(self): + return os.path.dirname(self.get_pydevd_file()) + + def get_command_line_args(self): + return [self.TEST_FILE] + + def do_kill(self): + if hasattr(self, 'server_socket'): + self.server_socket.close() + + if hasattr(self, 'reader_thread'): + # if it's not created, it's not there... + self.reader_thread.do_kill() + if hasattr(self, 'sock'): + self.sock.close() + + def write_with_content_len(self, msg): + self.log.append('write: %s' % (msg,)) + + if SHOW_WRITES_AND_READS: + print('Test Writer Thread Written %s' % (msg,)) + + if not hasattr(self, 'sock'): + print('%s.sock not available when sending: %s' % (self, msg)) + return + + if not isinstance(msg, bytes): + msg = msg.encode('utf-8') + + self.sock.sendall((u'Content-Length: %s\r\n\r\n' % len(msg)).encode('ascii')) + self.sock.sendall(msg) + + def write(self, s): + from _pydevd_bundle.pydevd_comm import ID_TO_MEANING + meaning = ID_TO_MEANING.get(re.search(r'\d+', s).group(), '') + if meaning: + meaning += ': ' + + self.log.append('write: %s%s' % (meaning, s,)) + + if SHOW_WRITES_AND_READS: + print('Test Writer Thread Written %s%s' % (meaning, s,)) + msg = s + '\n' + + if not hasattr(self, 'sock'): + print('%s.sock not available when sending: %s' % (self, msg)) + return + + if IS_PY3K: + msg = msg.encode('utf-8') + + self.sock.send(msg) + + def get_next_message(self, context_message, timeout=None): + return self.reader_thread.get_next_message(context_message, timeout=timeout) + + def start_socket(self, port=None): + assert not hasattr(self, 'port'), 'Socket already initialized.' + from _pydev_bundle.pydev_localhost import get_socket_name + if SHOW_WRITES_AND_READS: + print('start_socket') + + self._sequence = -1 + if port is None: + socket_name = get_socket_name(close=True) + else: + socket_name = (pydev_localhost.get_localhost(), port) + server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server_socket.bind(socket_name) + self.port = socket_name[1] + server_socket.listen(1) + if SHOW_WRITES_AND_READS: + print('Waiting in socket.accept()') + self.server_socket = server_socket + new_socket, addr = server_socket.accept() + if SHOW_WRITES_AND_READS: + print('Test Writer Thread Socket:', new_socket, addr) + + self._set_socket(new_socket) + + def _set_socket(self, new_socket): + curr_socket = getattr(self, 'sock', None) + if curr_socket: + try: + curr_socket.shutdown(socket.SHUT_WR) + except: + pass + try: + curr_socket.close() + except: + pass + + reader_thread = self.reader_thread = ReaderThread(new_socket) + self.sock = new_socket + reader_thread.start() + + # initial command is always the version + self.write_version() + self.log.append('start_socket') + self.finished_initialization = True + + def start_socket_client(self, host, port): + self._sequence = -1 + if SHOW_WRITES_AND_READS: + print("Connecting to %s:%s" % (host, port)) + + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + # Set TCP keepalive on an open socket. + # It activates after 1 second (TCP_KEEPIDLE,) of idleness, + # then sends a keepalive ping once every 3 seconds (TCP_KEEPINTVL), + # and closes the connection after 5 failed ping (TCP_KEEPCNT), or 15 seconds + try: + from socket import IPPROTO_TCP, SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT + s.setsockopt(socket.SOL_SOCKET, SO_KEEPALIVE, 1) + s.setsockopt(IPPROTO_TCP, TCP_KEEPIDLE, 1) + s.setsockopt(IPPROTO_TCP, TCP_KEEPINTVL, 3) + s.setsockopt(IPPROTO_TCP, TCP_KEEPCNT, 5) + except ImportError: + pass # May not be available everywhere. + + # 10 seconds default timeout + timeout = int(os.environ.get('PYDEVD_CONNECT_TIMEOUT', 10)) + s.settimeout(timeout) + for _i in range(6): + try: + s.connect((host, port)) + break + except: + time.sleep(.5) # We may have to wait a bit more and retry (especially on PyPy). + s.settimeout(None) # no timeout after connected + if SHOW_WRITES_AND_READS: + print("Connected.") + self._set_socket(s) + return s + + def next_breakpoint_id(self): + self._next_breakpoint_id += 1 + return self._next_breakpoint_id + + def next_seq(self): + self._sequence += 2 + return self._sequence + + def wait_for_new_thread(self): + # wait for hit breakpoint + last = '' + while not ' + splitted = last.split('"') + thread_id = splitted[3] + return thread_id + + def wait_for_output(self): + # Something as: + # + while True: + msg = self.get_next_message('wait_output') + if "' in last: + last = self.get_next_message('wait_for_get_next_statement_targets') + + matches = re.finditer(r"(([0-9]*)<\/line>)", last, re.IGNORECASE) + lines = [] + for _, match in enumerate(matches): + try: + lines.append(int(match.group(2))) + except ValueError: + pass + return set(lines) + + def wait_for_custom_operation(self, expected): + # wait for custom operation response, the response is double encoded + expected_encoded = quote(quote_plus(expected)) + last = '' + while not expected_encoded in last: + last = self.get_next_message('wait_for_custom_operation. Expected (encoded): %s' % (expected_encoded,)) + + return True + + def _is_var_in_last(self, expected, last): + if expected in last: + return True + + last = unquote_plus(last) + if expected in last: + return True + + # We actually quote 2 times on the backend... + last = unquote_plus(last) + if expected in last: + return True + + return False + + def wait_for_multiple_vars(self, expected_vars): + if not isinstance(expected_vars, (list, tuple)): + expected_vars = [expected_vars] + + all_found = [] + ignored = [] + + while True: + try: + last = self.get_next_message('wait_for_multiple_vars: %s' % (expected_vars,)) + except: + missing = [] + for v in expected_vars: + if v not in all_found: + missing.append(v) + raise ValueError('Not Found:\n%s\nNot found messages: %s\nFound messages: %s\nExpected messages: %s\nIgnored messages:\n%s' % ( + '\n'.join(str(x) for x in missing), len(missing), len(all_found), len(expected_vars), '\n'.join(str(x) for x in ignored))) + + was_message_used = False + new_expected = [] + for expected in expected_vars: + found_expected = False + if isinstance(expected, (tuple, list)): + for e in expected: + if self._is_var_in_last(e, last): + was_message_used = True + found_expected = True + all_found.append(expected) + break + else: + if self._is_var_in_last(expected, last): + was_message_used = True + found_expected = True + all_found.append(expected) + + if not found_expected: + new_expected.append(expected) + + expected_vars = new_expected + + if not expected_vars: + return True + + if not was_message_used: + ignored.append(last) + + wait_for_var = wait_for_multiple_vars + wait_for_vars = wait_for_multiple_vars + wait_for_evaluation = wait_for_multiple_vars + + def write_make_initial_run(self): + self.write("101\t%s\t" % self.next_seq()) + self.log.append('write_make_initial_run') + + def write_set_protocol(self, protocol): + self.write("%s\t%s\t%s" % (CMD_SET_PROTOCOL, self.next_seq(), protocol)) + + def write_version(self): + from _pydevd_bundle.pydevd_constants import IS_WINDOWS + self.write("%s\t%s\t1.0\t%s\tID" % (CMD_VERSION, self.next_seq(), 'WINDOWS' if IS_WINDOWS else 'UNIX')) + + def get_main_filename(self): + return self.TEST_FILE + + def write_show_return_vars(self, show=1): + self.write("%s\t%s\tCMD_SHOW_RETURN_VALUES\t%s" % (CMD_SHOW_RETURN_VALUES, self.next_seq(), show)) + + def write_add_breakpoint(self, line, func='None', filename=None, hit_condition=None, is_logpoint=False, suspend_policy=None, condition=None): + ''' + :param line: starts at 1 + :param func: if None, may hit in any context, empty string only top level, otherwise must be method name. + ''' + if filename is None: + filename = self.get_main_filename() + breakpoint_id = self.next_breakpoint_id() + if hit_condition is None and not is_logpoint and suspend_policy is None and condition is None: + # Format kept for backward compatibility tests + self.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\tNone\tNone" % ( + CMD_SET_BREAK, self.next_seq(), breakpoint_id, 'python-line', filename, line, func)) + else: + # Format: breakpoint_id, type, file, line, func_name, condition, expression, hit_condition, is_logpoint, suspend_policy + self.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\tNone\t%s\t%s\t%s" % ( + CMD_SET_BREAK, self.next_seq(), breakpoint_id, 'python-line', filename, line, func, condition, hit_condition, is_logpoint, suspend_policy)) + self.log.append('write_add_breakpoint: %s line: %s func: %s' % (breakpoint_id, line, func)) + return breakpoint_id + + def write_multi_threads_single_notification(self, multi_threads_single_notification): + self.write_json_config(dict( + multi_threads_single_notification=multi_threads_single_notification, + )) + + def write_suspend_on_breakpoint_exception(self, skip_suspend_on_breakpoint_exception, skip_print_breakpoint_exception): + self.write_json_config(dict( + skip_suspend_on_breakpoint_exception=skip_suspend_on_breakpoint_exception, + skip_print_breakpoint_exception=skip_print_breakpoint_exception + )) + + def write_json_config(self, config_dict): + self.write("%s\t%s\t%s" % (CMD_PYDEVD_JSON_CONFIG, self.next_seq(), + json.dumps(config_dict) + )) + + def write_stop_on_start(self, stop=True): + self.write("%s\t%s\t%s" % (CMD_STOP_ON_START, self.next_seq(), stop)) + + def write_dump_threads(self): + self.write("%s\t%s\t" % (CMD_THREAD_DUMP_TO_STDERR, self.next_seq())) + + def write_add_exception_breakpoint(self, exception): + self.write("%s\t%s\t%s" % (CMD_ADD_EXCEPTION_BREAK, self.next_seq(), exception)) + self.log.append('write_add_exception_breakpoint: %s' % (exception,)) + + def write_get_current_exception(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_GET_EXCEPTION_DETAILS, self.next_seq(), thread_id)) + + def write_set_py_exception_globals( + self, + break_on_uncaught, + break_on_caught, + skip_on_exceptions_thrown_in_same_context, + ignore_exceptions_thrown_in_lines_with_ignore_exception, + ignore_libraries, + exceptions=() + ): + # Only set the globals, others + self.write("131\t%s\t%s" % (self.next_seq(), '%s;%s;%s;%s;%s;%s' % ( + 'true' if break_on_uncaught else 'false', + 'true' if break_on_caught else 'false', + 'true' if skip_on_exceptions_thrown_in_same_context else 'false', + 'true' if ignore_exceptions_thrown_in_lines_with_ignore_exception else 'false', + 'true' if ignore_libraries else 'false', + ';'.join(exceptions) + ))) + self.log.append('write_set_py_exception_globals') + + def write_start_redirect(self): + self.write("%s\t%s\t%s" % (CMD_REDIRECT_OUTPUT, self.next_seq(), 'STDERR STDOUT')) + + def write_set_project_roots(self, project_roots): + self.write("%s\t%s\t%s" % (CMD_SET_PROJECT_ROOTS, self.next_seq(), '\t'.join(str(x) for x in project_roots))) + + def write_add_exception_breakpoint_with_policy( + self, exception, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries): + self.write("%s\t%s\t%s" % (CMD_ADD_EXCEPTION_BREAK, self.next_seq(), '\t'.join(str(x) for x in [ + exception, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries]))) + self.log.append('write_add_exception_breakpoint: %s' % (exception,)) + + def write_remove_exception_breakpoint(self, exception): + self.write('%s\t%s\t%s' % (CMD_REMOVE_EXCEPTION_BREAK, self.next_seq(), exception)) + + def write_remove_breakpoint(self, breakpoint_id): + self.write("%s\t%s\t%s\t%s\t%s" % ( + CMD_REMOVE_BREAK, self.next_seq(), 'python-line', self.get_main_filename(), breakpoint_id)) + + def write_change_variable(self, thread_id, frame_id, varname, value): + self.write("%s\t%s\t%s\t%s\t%s\t%s\t%s" % ( + CMD_CHANGE_VARIABLE, self.next_seq(), thread_id, frame_id, 'FRAME', varname, value)) + + def write_get_frame(self, thread_id, frame_id): + self.write("%s\t%s\t%s\t%s\tFRAME" % (CMD_GET_FRAME, self.next_seq(), thread_id, frame_id)) + self.log.append('write_get_frame') + + def write_get_variable(self, thread_id, frame_id, var_attrs): + self.write("%s\t%s\t%s\t%s\tFRAME\t%s" % (CMD_GET_VARIABLE, self.next_seq(), thread_id, frame_id, var_attrs)) + + def write_step_over(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_STEP_OVER, self.next_seq(), thread_id,)) + + def write_step_in(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_STEP_INTO, self.next_seq(), thread_id,)) + + def write_step_in_my_code(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_STEP_INTO_MY_CODE, self.next_seq(), thread_id,)) + + def write_step_return(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_STEP_RETURN, self.next_seq(), thread_id,)) + + def write_step_return_my_code(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_STEP_RETURN_MY_CODE, self.next_seq(), thread_id,)) + + def write_step_over_my_code(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_STEP_OVER_MY_CODE, self.next_seq(), thread_id,)) + + def write_suspend_thread(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_THREAD_SUSPEND, self.next_seq(), thread_id,)) + + def write_reload(self, module_name): + self.log.append('write_reload') + self.write("%s\t%s\t%s" % (CMD_RELOAD_CODE, self.next_seq(), module_name,)) + + def write_run_thread(self, thread_id): + self.log.append('write_run_thread') + self.write("%s\t%s\t%s" % (CMD_THREAD_RUN, self.next_seq(), thread_id,)) + + def write_get_thread_stack(self, thread_id): + self.log.append('write_get_thread_stack') + self.write("%s\t%s\t%s" % (CMD_GET_THREAD_STACK, self.next_seq(), thread_id,)) + + def write_load_source(self, filename): + self.log.append('write_load_source') + self.write("%s\t%s\t%s" % (CMD_LOAD_SOURCE, self.next_seq(), filename,)) + + def write_kill_thread(self, thread_id): + self.write("%s\t%s\t%s" % (CMD_THREAD_KILL, self.next_seq(), thread_id,)) + + def write_set_next_statement(self, thread_id, line, func_name): + self.write("%s\t%s\t%s\t%s\t%s" % (CMD_SET_NEXT_STATEMENT, self.next_seq(), thread_id, line, func_name,)) + + def write_debug_console_expression(self, locator): + self.write("%s\t%s\t%s" % (CMD_EVALUATE_CONSOLE_EXPRESSION, self.next_seq(), locator)) + + def write_custom_operation(self, locator, style, codeOrFile, operation_fn_name): + self.write("%s\t%s\t%s||%s\t%s\t%s" % ( + CMD_RUN_CUSTOM_OPERATION, self.next_seq(), locator, style, codeOrFile, operation_fn_name)) + + def write_evaluate_expression(self, locator, expression): + self.write("%s\t%s\t%s\t%s\t1" % (CMD_EVALUATE_EXPRESSION, self.next_seq(), locator, expression)) + + def write_enable_dont_trace(self, enable): + if enable: + enable = 'true' + else: + enable = 'false' + self.write("%s\t%s\t%s" % (CMD_ENABLE_DONT_TRACE, self.next_seq(), enable)) + + def write_get_next_statement_targets(self, thread_id, frame_id): + self.write("201\t%s\t%s\t%s" % (self.next_seq(), thread_id, frame_id)) + self.log.append('write_get_next_statement_targets') + + def write_list_threads(self): + seq = self.next_seq() + self.write("%s\t%s\t" % (CMD_LIST_THREADS, seq)) + return seq + + def wait_for_list_threads(self, seq): + return self.wait_for_message('502') + + def wait_for_get_thread_stack_message(self): + return self.wait_for_message(CMD_GET_THREAD_STACK) + + def wait_for_json_message(self, accept_message, unquote_msg=True, timeout=None): + last = self.wait_for_message(accept_message, unquote_msg, expect_xml=False, timeout=timeout) + json_msg = last.split('\t', 2)[-1] # We have something as: CMD\tSEQ\tJSON + if isinstance(json_msg, bytes): + json_msg = json_msg.decode('utf-8') + try: + return json.loads(json_msg) + except: + traceback.print_exc() + raise AssertionError('Unable to parse:\n%s\njson:\n%s' % (last, json_msg)) + + def wait_for_message(self, accept_message, unquote_msg=True, expect_xml=True, timeout=None): + if isinstance(accept_message, (str, int)): + msg_starts_with = '%s\t' % (accept_message,) + + def accept_message(msg): + return msg.startswith(msg_starts_with) + + import untangle + from io import StringIO + prev = None + while True: + last = self.get_next_message('wait_for_message', timeout=timeout) + if unquote_msg: + last = unquote_plus(unquote_plus(last)) + if accept_message(last): + if expect_xml: + # Extract xml and return untangled. + try: + xml = last[last.index(''):] + if isinstance(xml, bytes): + xml = xml.decode('utf-8') + xml = untangle.parse(StringIO(xml)) + except: + traceback.print_exc() + raise AssertionError('Unable to parse:\n%s\nxml:\n%s' % (last, xml)) + ret = xml.xml + ret.original_xml = last + return ret + else: + return last + if prev != last: + print('Ignored message: %r' % (last,)) + + prev = last + + def get_frame_names(self, thread_id): + self.write_get_thread_stack(thread_id) + msg = self.wait_for_message(CMD_GET_THREAD_STACK) + if msg.thread.frame: + frame_names = [frame['name'] for frame in msg.thread.frame] + return frame_names + return [msg.thread.frame['name']] + + def wait_for_thread_join(self, main_thread_id): + + def condition(): + return self.get_frame_names(main_thread_id) in ( + ['wait', 'join', ''], + ['_wait_for_tstate_lock', 'join', ''] + ) + + def msg(): + return 'Found stack: %s' % (self.get_frame_names(main_thread_id),) + + wait_for_condition(condition, msg, timeout=5, sleep=.5) + + def create_request_thread(self, full_url): + + class T(threading.Thread): + + def wait_for_contents(self): + for _ in range(10): + if hasattr(self, 'contents'): + break + time.sleep(.3) + else: + raise AssertionError('Unable to get contents from server. Url: %s' % (full_url,)) + return self.contents + + def run(self): + try: + from urllib.request import urlopen + except ImportError: + from urllib import urlopen + for _ in range(10): + try: + stream = urlopen(full_url) + contents = stream.read() + if IS_PY3K: + contents = contents.decode('utf-8') + self.contents = contents + break + except IOError: + continue + + t = T() + t.daemon = True + return t + + +def _get_debugger_test_file(filename): + try: + rPath = os.path.realpath # @UndefinedVariable + except: + # jython does not support os.path.realpath + # realpath is a no-op on systems without islink support + rPath = os.path.abspath + + ret = os.path.normcase(rPath(os.path.join(os.path.dirname(__file__), filename))) + if not os.path.exists(ret): + ret = os.path.join(os.path.dirname(__file__), 'resources', filename) + if not os.path.exists(ret): + raise AssertionError('Expected: %s to exist.' % (ret,)) + return ret + + +def get_free_port(): + from _pydev_bundle.pydev_localhost import get_socket_name + return get_socket_name(close=True)[1] diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/app.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/app.py new file mode 100644 index 0000000..2f4e4a2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/app.py @@ -0,0 +1,60 @@ +from flask import Flask +from flask import render_template + +app = Flask(__name__) + + +@app.route("/") +def home(): + content = 'Flask-Jinja-Test' + return render_template( + "hello.html", + title='Hello', + content=content + ) + + +@app.route("/handled") +def bad_route_handled(): + try: + raise ArithmeticError('Hello') + except Exception: + pass + return render_template( + "hello.html", + title='Hello', + content='Flask-Jinja-Test' + ) + + +@app.route("/unhandled") +def bad_route_unhandled(): + raise ArithmeticError('Hello') + return render_template( + "hello.html", + title='Hello', + content='Flask-Jinja-Test' + ) + + +@app.route("/bad_template") +def bad_template(): + return render_template( + "bad.html", + title='Bad', + content='Flask-Jinja-Test' + ) + + +@app.route("/exit") +def exit_app(): + from flask import request + func = request.environ.get('werkzeug.server.shutdown') + if func is None: + raise RuntimeError('No shutdown') + func() + return 'Done' + + +if __name__ == '__main__': + app.run() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/templates/bad.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/templates/bad.html new file mode 100644 index 0000000..5f552c6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/templates/bad.html @@ -0,0 +1,10 @@ + + + + + Test + + + {% doesnotexist %} + + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/templates/hello.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/templates/hello.html new file mode 100644 index 0000000..3784dad --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/flask1/templates/hello.html @@ -0,0 +1,10 @@ + + + + + {{ title }} + + + {{ content }} + + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/manage.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/manage.py new file mode 100644 index 0000000..c29c377 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_django_proj_17.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/admin.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/forms.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/forms.py new file mode 100644 index 0000000..fe03086 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/forms.py @@ -0,0 +1,4 @@ +from django import forms + +class NameForm(forms.Form): + your_name = forms.CharField(label='Your name', max_length=100) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/models.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/index.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/index.html new file mode 100644 index 0000000..5cad374 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/index.html @@ -0,0 +1,13 @@ +{% if entries %} +
    + {% for entry in entries %} +
  • + {{ entry.key }} + : + {{ entry.val }} +
  • + {% endfor %} +
+{% else %} +

No entries are available.

+{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/inherited.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/inherited.html new file mode 100644 index 0000000..0105431 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/inherited.html @@ -0,0 +1,5 @@ +{% if chat_mode %} + "chat_mode=True" +{% else %} + "chat_mode=False" +{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/inherits.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/inherits.html new file mode 100644 index 0000000..8c7b9ab --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/inherits.html @@ -0,0 +1,2 @@ +{% include 'my_app/inherited.html' with chat_mode=True %} +{% include 'my_app/inherited.html' with chat_mode=False %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/name.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/name.html new file mode 100644 index 0000000..d47a2e1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/name.html @@ -0,0 +1,7 @@ +
+ {% csrf_token %} + {{ form }} + It is {% now "jS F Y H:i" %} + +
+

End of form

\ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/no_var_error.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/no_var_error.html new file mode 100644 index 0000000..bdb84e5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/no_var_error.html @@ -0,0 +1,5 @@ +{% if pat.name %} + pat.name={{ pat.name }} +{% else %} + no_pat_name +{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/template_error.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/template_error.html new file mode 100644 index 0000000..4b2d703 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/template_error.html @@ -0,0 +1,13 @@ +{% if entries %} +
    + {% for entry in entries %} +
  • + {{ entry.key }} + : + {{ entry.invalid_attribute }} +
  • + {% endfor %} +
+{% else %} +

No entries are available.

+{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/template_error2.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/template_error2.html new file mode 100644 index 0000000..439f432 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/templates/my_app/template_error2.html @@ -0,0 +1,6 @@ + + + + {% doesnotexist %} + + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/tests.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/urls.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/urls.py new file mode 100644 index 0000000..849aaf6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.index, name='index'), + url(r'^name$', views.get_name, name='name'), + url(r'^template_error$', views.template_error, name='template_error'), + url(r'^template_error2$', views.template_error2, name='template_error2'), + url(r'^inherits$', views.inherits, name='inherits'), + url(r'^no_var_error$', views.no_var_error, name='no_var_error'), +] diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/views.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/views.py new file mode 100644 index 0000000..c15a994 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_app/views.py @@ -0,0 +1,73 @@ +from django.shortcuts import render + +# Create your views here. +from django.http import HttpResponse, HttpResponseRedirect +import sys +from .forms import NameForm + + +class Entry(object): + + def __init__(self, key, val): + self.key = key + self.val = val + + def __unicode__(self): + return u'%s:%s' % (self.key, self.val) + + def __str__(self): + return u'%s:%s' % (self.key, self.val) + + +def index(request): + context = { + 'entries': [Entry('v1', 'v1'), Entry('v2', 'v2')] + } + ret = render(request, 'my_app/index.html', context) + return ret + + +def get_name(request): + # if this is a POST request we need to process the form data + if request.method == 'POST': + # create a form instance and populate it with data from the request: + form = NameForm(request.POST) + # check whether it's valid: + if form.is_valid(): + # process the data in form.cleaned_data as required + # ... + # redirect to a new URL: + return HttpResponseRedirect('/thanks/') + + # if a GET (or any other method) we'll create a blank form + else: + form = NameForm(data={'your_name': 'unknown name'}) + + return render(request, 'my_app/name.html', {'form': form}) + + +def inherits(request): + context = {} + ret = render(request, 'my_app/inherits.html', context) + return ret + + +def template_error(request): + context = { + 'entries': [Entry('v1', 'v1'), Entry('v2', 'v2')] + } + + ret = render(request, 'my_app/template_error.html', context) + return ret + + +def template_error2(request): + context = {} + ret = render(request, 'my_app/template_error2.html', context) + return ret + + +def no_var_error(request): + context = {} + ret = render(request, 'my_app/no_var_error.html', context) + return ret diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/settings.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/settings.py new file mode 100644 index 0000000..ec3fb3b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/settings.py @@ -0,0 +1,86 @@ +""" +Django settings for my_django_proj_17 project. + +For more information on this file, see +https://docs.djangoproject.com/en/1.7/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.7/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '5_sue9bp&j=45#%_hcx3f34k!qnt$mxfd&7zq@7c7t@sn4_l)b' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +TEMPLATE_DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'my_app', +) + +MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) + +ROOT_URLCONF = 'my_django_proj_17.urls' + +WSGI_APPLICATION = 'my_django_proj_17.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.7/ref/settings/#databases + +# No database for our test. + +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +# } + +# Internationalization +# https://docs.djangoproject.com/en/1.7/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.7/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/urls.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/urls.py new file mode 100644 index 0000000..fc5c587 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import patterns, include, url +from django.contrib import admin + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'my_django_proj_17.views.home', name='home'), + # url(r'^blog/', include('blog.urls')), + + url(r'^admin/', include(admin.site.urls)), + url(r'^my_app/', include('my_app.urls')), +) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/wsgi.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/wsgi.py new file mode 100644 index 0000000..c410e8d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_17/my_django_proj_17/wsgi.py @@ -0,0 +1,14 @@ +""" +WSGI config for my_django_proj_17 project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ +""" + +import os +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_django_proj_17.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/manage.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/manage.py new file mode 100644 index 0000000..9692bd0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_django_proj_21.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/admin.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/apps.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/apps.py new file mode 100644 index 0000000..885dfa0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MyAppConfig(AppConfig): + name = 'my_app' diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/forms.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/forms.py new file mode 100644 index 0000000..fe03086 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/forms.py @@ -0,0 +1,4 @@ +from django import forms + +class NameForm(forms.Form): + your_name = forms.CharField(label='Your name', max_length=100) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/migrations/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/models.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/index.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/index.html new file mode 100644 index 0000000..5cad374 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/index.html @@ -0,0 +1,13 @@ +{% if entries %} +
    + {% for entry in entries %} +
  • + {{ entry.key }} + : + {{ entry.val }} +
  • + {% endfor %} +
+{% else %} +

No entries are available.

+{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/inherited.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/inherited.html new file mode 100644 index 0000000..0105431 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/inherited.html @@ -0,0 +1,5 @@ +{% if chat_mode %} + "chat_mode=True" +{% else %} + "chat_mode=False" +{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/inherits.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/inherits.html new file mode 100644 index 0000000..8c7b9ab --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/inherits.html @@ -0,0 +1,2 @@ +{% include 'my_app/inherited.html' with chat_mode=True %} +{% include 'my_app/inherited.html' with chat_mode=False %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/name.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/name.html new file mode 100644 index 0000000..d47a2e1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/name.html @@ -0,0 +1,7 @@ +
+ {% csrf_token %} + {{ form }} + It is {% now "jS F Y H:i" %} + +
+

End of form

\ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/no_var_error.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/no_var_error.html new file mode 100644 index 0000000..bdb84e5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/no_var_error.html @@ -0,0 +1,5 @@ +{% if pat.name %} + pat.name={{ pat.name }} +{% else %} + no_pat_name +{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/template_error.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/template_error.html new file mode 100644 index 0000000..4b2d703 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/template_error.html @@ -0,0 +1,13 @@ +{% if entries %} +
    + {% for entry in entries %} +
  • + {{ entry.key }} + : + {{ entry.invalid_attribute }} +
  • + {% endfor %} +
+{% else %} +

No entries are available.

+{% endif %} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/template_error2.html b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/template_error2.html new file mode 100644 index 0000000..439f432 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/templates/my_app/template_error2.html @@ -0,0 +1,6 @@ + + + + {% doesnotexist %} + + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/urls.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/urls.py new file mode 100644 index 0000000..ada7ec4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.index, name='index'), + url(r'^name$', views.get_name, name='name'), + url(r'^template_error2$', views.template_error2, name='template_error2'), + url(r'^template_error$', views.template_error, name='template_error'), + url(r'^inherits$', views.inherits, name='inherits'), + url(r'^no_var_error$', views.no_var_error, name='no_var_error'), +] diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/views.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/views.py new file mode 100644 index 0000000..db7872d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_app/views.py @@ -0,0 +1,80 @@ +from django.shortcuts import render + +# Create your views here. +from django.http import HttpResponse, HttpResponseRedirect +import sys +from .forms import NameForm + + +class Entry(object): + + def __init__(self, key, val): + self.key = key + self.val = val + + def __unicode__(self): + return u'%s:%s' % (self.key, self.val) + + def __str__(self): + return u'%s:%s' % (self.key, self.val) + + +def index(request): + import faulthandler + faulthandler.enable() + context = { + 'entries': [Entry('v1', 'v1'), Entry('v2', 'v2')] + } + ret = render(request, 'my_app/index.html', context) + return ret + + +def get_name(request): + import faulthandler + faulthandler.enable() + # if this is a POST request we need to process the form data + if request.method == 'POST': + # create a form instance and populate it with data from the request: + form = NameForm(request.POST) + # check whether it's valid: + if form.is_valid(): + # process the data in form.cleaned_data as required + # ... + # redirect to a new URL: + return HttpResponseRedirect('/thanks/') + + # if a GET (or any other method) we'll create a blank form + else: + form = NameForm(data={'your_name': 'unknown name'}) + + return render(request, 'my_app/name.html', {'form': form}) + + +def template_error(request): + import faulthandler + faulthandler.enable() + context = { + 'entries': [Entry('v1', 'v1'), Entry('v2', 'v2')] + } + ret = render(request, 'my_app/template_error.html', context) + return ret + + +def template_error2(request): + import faulthandler + faulthandler.enable() + context = {} + ret = render(request, 'my_app/template_error2.html', context) + return ret + + +def inherits(request): + context = {} + ret = render(request, 'my_app/inherits.html', context) + return ret + + +def no_var_error(request): + context = {} + ret = render(request, 'my_app/no_var_error.html', context) + return ret diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/settings.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/settings.py new file mode 100644 index 0000000..fe9ecc2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/settings.py @@ -0,0 +1,120 @@ +""" +Django settings for my_django_proj_21 project. + +Generated by 'django-admin startproject' using Django 2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'u1jqdxv=z@ue9)%onkenaqb*&4dzd2mmb98#j*8uq^fn#j67)p' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'my_app', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'my_django_proj_21.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'my_django_proj_21.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/ref/settings/#databases +# No database for our test. +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +# } + +# Password validation +# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/urls.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/urls.py new file mode 100644 index 0000000..f8173dc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/urls.py @@ -0,0 +1,23 @@ +"""my_django_proj_21 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path +from django.urls.conf import include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('my_app/', include('my_app.urls')), +] diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/wsgi.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/wsgi.py new file mode 100644 index 0000000..0018842 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_django_proj_21/my_django_proj_21/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for my_django_proj_21 project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_django_proj_21.settings') + +application = get_wsgi_application() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/__init__.py new file mode 100644 index 0000000..afff0c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/__init__.py @@ -0,0 +1,5 @@ +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/__init__.py new file mode 100644 index 0000000..afff0c0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/__init__.py @@ -0,0 +1,5 @@ +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/pydevd_plugin_test_events.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/pydevd_plugin_test_events.py new file mode 100644 index 0000000..71c1ef9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/pydevd_plugin_test_events.py @@ -0,0 +1,18 @@ +from _pydevd_bundle.pydevd_extension_api import DebuggerEventHandler +import os +import sys + + +class VerifyEvent(object): + def on_debugger_modules_loaded(self, **kwargs): + print ("INITIALIZE EVENT RECEIVED") + # check that some core modules are loaded before this callback is invoked + modules_loaded = all(mod in sys.modules for mod in ('pydevd_file_utils', '_pydevd_bundle.pydevd_constants')) + if modules_loaded: + print ("TEST SUCEEDED") # incorrect spelling on purpose + else: + print ("TEST FAILED") + + +if os.environ.get("VERIFY_EVENT_TEST"): + DebuggerEventHandler.register(VerifyEvent) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/pydevd_plugin_test_exttype.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/pydevd_plugin_test_exttype.py new file mode 100644 index 0000000..c3a7f78 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/my_extensions/pydevd_plugins/extensions/pydevd_plugin_test_exttype.py @@ -0,0 +1,20 @@ +from _pydevd_bundle.pydevd_extension_api import StrPresentationProvider, TypeResolveProvider + + +class RectResolver(TypeResolveProvider): + def get_dictionary(self, var): + return {'length': var.length, 'width': var.width, 'area': var.length * var.width} + + def resolve(self, var, attribute): + return getattr(var, attribute, None) if attribute != 'area' else var.length * var.width + + def can_provide(self, type_object, type_name): + return type_name.endswith('Rect') + + +class RectToString(StrPresentationProvider): + def get_str(self, val): + return "Rectangle[Length: %s, Width: %s , Area: %s]" % (val.length, val.width, val.length * val.width) + + def can_provide(self, type_object, type_name): + return type_name.endswith('Rect') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/performance_check.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/performance_check.py new file mode 100644 index 0000000..0e05a01 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/performance_check.py @@ -0,0 +1,243 @@ +from tests_python import debugger_unittest +import sys +import re +import os + +CHECK_BASELINE, CHECK_REGULAR, CHECK_CYTHON, CHECK_FRAME_EVAL = 'baseline', 'regular', 'cython', 'frame_eval' + +pytest_plugins = [ + str('tests_python.debugger_fixtures'), +] + +RUNS = 5 + + +class PerformanceWriterThread(debugger_unittest.AbstractWriterThread): + + CHECK = None + + debugger_unittest.AbstractWriterThread.get_environ # overrides + + def get_environ(self): + env = os.environ.copy() + if self.CHECK == CHECK_BASELINE: + env['PYTHONPATH'] = r'X:\PyDev.Debugger.baseline' + + elif self.CHECK == CHECK_CYTHON: + env['PYDEVD_USE_CYTHON'] = 'YES' + env['PYDEVD_USE_FRAME_EVAL'] = 'NO' + + elif self.CHECK == CHECK_FRAME_EVAL: + env['PYDEVD_USE_CYTHON'] = 'YES' + env['PYDEVD_USE_FRAME_EVAL'] = 'YES' + + elif self.CHECK == CHECK_REGULAR: + env['PYDEVD_USE_CYTHON'] = 'NO' + env['PYDEVD_USE_FRAME_EVAL'] = 'NO' + + else: + raise AssertionError("Don't know what to check.") + return env + + debugger_unittest.AbstractWriterThread.get_pydevd_file # overrides + + def get_pydevd_file(self): + if self.CHECK == CHECK_BASELINE: + return os.path.abspath(os.path.join(r'X:\PyDev.Debugger.baseline', 'pydevd.py')) + dirname = os.path.dirname(__file__) + dirname = os.path.dirname(dirname) + return os.path.abspath(os.path.join(dirname, 'pydevd.py')) + + +class CheckDebuggerPerformance(debugger_unittest.DebuggerRunner): + + def get_command_line(self): + return [sys.executable] + + def _get_time_from_result(self, stdout): + match = re.search(r'TotalTime>>((\d|\.)+)<<', stdout) + time_taken = match.group(1) + return float(time_taken) + + def obtain_results(self, benchmark_name, filename): + + class PerformanceCheck(PerformanceWriterThread): + TEST_FILE = debugger_unittest._get_debugger_test_file(filename) + BENCHMARK_NAME = benchmark_name + + writer_thread_class = PerformanceCheck + + runs = RUNS + all_times = [] + for _ in range(runs): + stdout_ref = [] + + def store_stdout(stdout, stderr): + stdout_ref.append(stdout) + + with self.check_case(writer_thread_class) as writer: + writer.additional_output_checks = store_stdout + yield writer + + assert len(stdout_ref) == 1 + all_times.append(self._get_time_from_result(stdout_ref[0])) + print('partial for: %s: %.3fs' % (writer_thread_class.BENCHMARK_NAME, all_times[-1])) + if len(all_times) > 3: + all_times.remove(min(all_times)) + all_times.remove(max(all_times)) + time_when_debugged = sum(all_times) / float(len(all_times)) + + args = self.get_command_line() + args.append(writer_thread_class.TEST_FILE) + # regular_time = self._get_time_from_result(self.run_process(args, writer_thread=None)) + # simple_trace_time = self._get_time_from_result(self.run_process(args+['--regular-trace'], writer_thread=None)) + + if 'SPEEDTIN_AUTHORIZATION_KEY' in os.environ: + + SPEEDTIN_AUTHORIZATION_KEY = os.environ['SPEEDTIN_AUTHORIZATION_KEY'] + + # sys.path.append(r'X:\speedtin\pyspeedtin') + import pyspeedtin # If the authorization key is there, pyspeedtin must be available + import pydevd + pydevd_cython_project_id, pydevd_pure_python_project_id = 6, 7 + if writer_thread_class.CHECK == CHECK_BASELINE: + project_ids = (pydevd_cython_project_id, pydevd_pure_python_project_id) + elif writer_thread_class.CHECK == CHECK_REGULAR: + project_ids = (pydevd_pure_python_project_id,) + elif writer_thread_class.CHECK == CHECK_CYTHON: + project_ids = (pydevd_cython_project_id,) + else: + raise AssertionError('Wrong check: %s' % (writer_thread_class.CHECK)) + for project_id in project_ids: + api = pyspeedtin.PySpeedTinApi(authorization_key=SPEEDTIN_AUTHORIZATION_KEY, project_id=project_id) + + benchmark_name = writer_thread_class.BENCHMARK_NAME + + if writer_thread_class.CHECK == CHECK_BASELINE: + version = '0.0.1_baseline' + return # No longer commit the baseline (it's immutable right now). + else: + version = pydevd.__version__, + + commit_id, branch, commit_date = api.git_commit_id_branch_and_date_from_path(pydevd.__file__) + api.add_benchmark(benchmark_name) + api.add_measurement( + benchmark_name, + value=time_when_debugged, + version=version, + released=False, + branch=branch, + commit_id=commit_id, + commit_date=commit_date, + ) + api.commit() + + self.performance_msg = '%s: %.3fs ' % (writer_thread_class.BENCHMARK_NAME, time_when_debugged) + + def method_calls_with_breakpoint(self): + for writer in self.obtain_results('method_calls_with_breakpoint', '_performance_1.py'): + writer.write_add_breakpoint(17, 'method') + writer.write_make_initial_run() + writer.finished_ok = True + + return self.performance_msg + + def method_calls_without_breakpoint(self): + for writer in self.obtain_results('method_calls_without_breakpoint', '_performance_1.py'): + writer.write_make_initial_run() + writer.finished_ok = True + + return self.performance_msg + + def method_calls_with_step_over(self): + for writer in self.obtain_results('method_calls_with_step_over', '_performance_1.py'): + writer.write_add_breakpoint(26, None) + + writer.write_make_initial_run() + hit = writer.wait_for_breakpoint_hit('111') + + writer.write_step_over(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('108') + + writer.write_run_thread(hit.thread_id) + writer.finished_ok = True + + return self.performance_msg + + def method_calls_with_exception_breakpoint(self): + for writer in self.obtain_results('method_calls_with_exception_breakpoint', '_performance_1.py'): + writer.write_add_exception_breakpoint('ValueError') + writer.write_make_initial_run() + writer.finished_ok = True + + return self.performance_msg + + def global_scope_1_with_breakpoint(self): + for writer in self.obtain_results('global_scope_1_with_breakpoint', '_performance_2.py'): + writer.write_add_breakpoint(writer.get_line_index_with_content('Breakpoint here'), None) + writer.write_make_initial_run() + writer.finished_ok = True + + return self.performance_msg + + def global_scope_2_with_breakpoint(self): + for writer in self.obtain_results('global_scope_2_with_breakpoint', '_performance_3.py'): + writer.write_add_breakpoint(17, None) + writer.write_make_initial_run() + writer.finished_ok = True + + return self.performance_msg + + +if __name__ == '__main__': + # Local times gotten (python 3.6) + # Checking: regular + # method_calls_with_breakpoint: 1.244s + # method_calls_without_breakpoint: 0.286s + # method_calls_with_step_over: 2.795s + # method_calls_with_exception_breakpoint: 0.272s + # global_scope_1_with_breakpoint: 4.212s + # global_scope_2_with_breakpoint: 3.256s + # Checking: cython + # method_calls_with_breakpoint: 0.639s + # method_calls_without_breakpoint: 0.188s + # method_calls_with_step_over: 1.387s + # method_calls_with_exception_breakpoint: 0.189s + # global_scope_1_with_breakpoint: 2.107s + # global_scope_2_with_breakpoint: 1.591s + # Checking: frame_eval + # method_calls_with_breakpoint: 0.182s + # method_calls_without_breakpoint: 0.175s + # method_calls_with_step_over: 0.211s + # method_calls_with_exception_breakpoint: 0.179s + # global_scope_1_with_breakpoint: 0.379s + # global_scope_2_with_breakpoint: 0.204s + + debugger_unittest.SHOW_WRITES_AND_READS = False + debugger_unittest.SHOW_OTHER_DEBUG_INFO = False + debugger_unittest.SHOW_STDOUT = False + + import time + start_time = time.time() + + msgs = [] + for check in ( + # CHECK_BASELINE, -- Checks against the version checked out at X:\PyDev.Debugger.baseline. + CHECK_REGULAR, + CHECK_CYTHON, + CHECK_FRAME_EVAL, + ): + PerformanceWriterThread.CHECK = check + msgs.append('Checking: %s' % (check,)) + check_debugger_performance = CheckDebuggerPerformance() + msgs.append(check_debugger_performance.method_calls_with_breakpoint()) + msgs.append(check_debugger_performance.method_calls_without_breakpoint()) + msgs.append(check_debugger_performance.method_calls_with_step_over()) + msgs.append(check_debugger_performance.method_calls_with_exception_breakpoint()) + msgs.append(check_debugger_performance.global_scope_1_with_breakpoint()) + msgs.append(check_debugger_performance.global_scope_2_with_breakpoint()) + + for msg in msgs: + print(msg) + + print('TotalTime for profile: %.2fs' % (time.time() - start_time,)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/regression_check.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/regression_check.py new file mode 100644 index 0000000..5dd35ef --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/regression_check.py @@ -0,0 +1,240 @@ +# Based on: https://github.com/ESSS/pytest-regressions (License: MIT) +# Created copy because we need Python 2.6 which is not available on pytest-regressions. +# Note: only used for testing. + +# encoding: UTF-8 +import difflib +import pytest +import sys +from functools import partial + +if sys.version_info[0] <= 2: + from pathlib2 import Path +else: + from pathlib import Path + +FORCE_REGEN = False + + +@pytest.fixture +def original_datadir(request): + # Method from: https://github.com/gabrielcnr/pytest-datadir + # License: MIT + import os.path + return Path(os.path.splitext(request.module.__file__)[0]) + + +@pytest.fixture +def datadir(original_datadir, tmpdir): + # Method from: https://github.com/gabrielcnr/pytest-datadir + # License: MIT + import shutil + result = Path(str(tmpdir.join(original_datadir.stem))) + if original_datadir.is_dir(): + shutil.copytree(str(original_datadir), str(result)) + else: + result.mkdir() + return result + + +@pytest.fixture +def data_regression(datadir, original_datadir, request): + return DataRegressionFixture(datadir, original_datadir, request) + + +def check_text_files(obtained_fn, expected_fn, fix_callback=lambda x: x, encoding=None): + """ + Compare two files contents. If the files differ, show the diff and write a nice HTML + diff file into the data directory. + :param Path obtained_fn: path to obtained file during current testing. + :param Path expected_fn: path to the expected file, obtained from previous testing. + :param str encoding: encoding used to open the files. + :param callable fix_callback: + A callback to "fix" the contents of the obtained (first) file. + This callback receives a list of strings (lines) and must also return a list of lines, + changed as needed. + The resulting lines will be used to compare with the contents of expected_fn. + """ + __tracebackhide__ = True + + obtained_fn = Path(obtained_fn) + expected_fn = Path(expected_fn) + obtained_lines = fix_callback(obtained_fn.read_text(encoding=encoding).splitlines()) + expected_lines = expected_fn.read_text(encoding=encoding).splitlines() + + if obtained_lines != expected_lines: + diff_lines = list(difflib.unified_diff(expected_lines, obtained_lines)) + if len(diff_lines) <= 500: + html_fn = obtained_fn.with_suffix(".diff.html") + try: + differ = difflib.HtmlDiff() + html_diff = differ.make_file( + fromlines=expected_lines, + fromdesc=expected_fn, + tolines=obtained_lines, + todesc=obtained_fn, + ) + except Exception as e: + html_fn = "(failed to generate html diff: %s)" % e + else: + html_fn.write_text(html_diff, encoding="UTF-8") + + diff = ["FILES DIFFER:", str(expected_fn), str(obtained_fn)] + diff += ["HTML DIFF: %s" % html_fn] + diff += diff_lines + raise AssertionError("\n".join(diff)) + else: + # difflib has exponential scaling and for thousands of lines it starts to take minutes to render + # the HTML diff. + msg = [ + "Files are different, but diff is too big (%s lines)" % (len(diff_lines),), + "- obtained: %s" % (obtained_fn,), + "- expected: %s" % (expected_fn,), + ] + raise AssertionError("\n".join(msg)) + + +def perform_regression_check( + datadir, + original_datadir, + request, + check_fn, + dump_fn, + extension, + basename=None, + fullpath=None, + obtained_filename=None, + dump_aux_fn=lambda filename: [], +): + """ + First run of this check will generate a expected file. Following attempts will always try to + match obtained files with that expected file. + :param Path datadir: Fixture embed_data. + :param Path original_datadir: Fixture embed_data. + :param SubRequest request: Pytest request object. + :param callable check_fn: A function that receives as arguments, respectively, absolute path to + obtained file and absolute path to expected file. It must assert if contents of file match. + Function can safely assume that obtained file is already dumped and only care about + comparison. + :param callable dump_fn: A function that receive an absolute file path as argument. Implementor + must dump file in this path. + :param callable dump_aux_fn: A function that receives the same file path as ``dump_fn``, but may + dump additional files to help diagnose this regression later (for example dumping image of + 3d views and plots to compare later). Must return the list of file names written (used to display). + :param six.text_type extension: Extension of files compared by this check. + :param six.text_type obtained_filename: complete path to use to write the obtained file. By + default will prepend `.obtained` before the file extension. + ..see: `data_regression.Check` for `basename` and `fullpath` arguments. + """ + import re + + assert not (basename and fullpath), "pass either basename or fullpath, but not both" + + __tracebackhide__ = True + + if basename is None: + basename = re.sub("[\W]", "_", request.node.name) + + if fullpath: + filename = source_filename = Path(fullpath) + else: + filename = datadir / (basename + extension) + source_filename = original_datadir / (basename + extension) + + def make_location_message(banner, filename, aux_files): + msg = [banner, "- %s" % (filename,)] + if aux_files: + msg.append("Auxiliary:") + msg += ["- %s" % (x,) for x in aux_files] + return "\n".join(msg) + + if not filename.is_file(): + source_filename.parent.mkdir(parents=True, exist_ok=True) + dump_fn(source_filename) + aux_created = dump_aux_fn(source_filename) + + msg = make_location_message( + "File not found in data directory, created:", source_filename, aux_created + ) + pytest.fail(msg) + else: + if obtained_filename is None: + if fullpath: + obtained_filename = (datadir / basename).with_suffix( + ".obtained" + extension + ) + else: + obtained_filename = filename.with_suffix(".obtained" + extension) + + dump_fn(obtained_filename) + + try: + check_fn(obtained_filename, filename) + except AssertionError: + if FORCE_REGEN: + dump_fn(source_filename) + aux_created = dump_aux_fn(source_filename) + msg = make_location_message( + "Files differ and FORCE_REGEN set, regenerating file at:", + source_filename, + aux_created, + ) + pytest.fail(msg) + else: + dump_aux_fn(obtained_filename) + raise + + +class DataRegressionFixture(object): + """ + Implementation of `data_regression` fixture. + """ + + def __init__(self, datadir, original_datadir, request): + """ + :type datadir: Path + :type original_datadir: Path + :type request: FixtureRequest + """ + self.request = request + self.datadir = datadir + self.original_datadir = original_datadir + + def check(self, data_dict, basename=None, fullpath=None): + """ + Checks the given dict against a previously recorded version, or generate a new file. + :param dict data_dict: any yaml serializable dict. + :param str basename: basename of the file to test/record. If not given the name + of the test is used. + Use either `basename` or `fullpath`. + :param str fullpath: complete path to use as a reference file. This option + will ignore ``datadir`` fixture when reading *expected* files but will still use it to + write *obtained* files. Useful if a reference file is located in the session data dir for example. + ``basename`` and ``fullpath`` are exclusive. + """ + __tracebackhide__ = True + + def dump(filename): + """Dump dict contents to the given filename""" + import json + + s = json.dumps(data_dict, sort_keys=True, indent=4) + if isinstance(s, bytes): + s = s.decode('utf-8') + + s = u'\n'.join([line.rstrip() for line in s.splitlines()]) + s = s.encode('utf-8') + + with filename.open("wb") as f: + f.write(s) + + perform_regression_check( + datadir=self.datadir, + original_datadir=self.original_datadir, + request=self.request, + check_fn=partial(check_text_files, encoding="UTF-8"), + dump_fn=dump, + extension=".json", + basename=basename, + fullpath=fullpath, + ) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resource_path_translation/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resource_path_translation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resource_path_translation/other.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resource_path_translation/other.py new file mode 100644 index 0000000..369a9b2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resource_path_translation/other.py @@ -0,0 +1,6 @@ + + +def call_me_back1(callback): + a = 'other' + callback() + return a diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_bytecode_many_names_example.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_bytecode_many_names_example.py new file mode 100644 index 0000000..6221725 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_bytecode_many_names_example.py @@ -0,0 +1,268 @@ + + +def foo(): + a0 = 1 + a1 = 1 + a2 = 1 + a3 = 1 + a4 = 1 + a5 = 1 + a6 = 1 + a7 = 1 + a8 = 1 + a9 = 1 + a10 = 1 + a11 = 1 + a12 = 1 + a13 = 1 + a14 = 1 + a15 = 1 + a16 = 1 + a17 = 1 + a18 = 1 + a19 = 1 + a20 = 1 + a21 = 1 + a22 = 1 + a23 = 1 + a24 = 1 + a25 = 1 + a26 = 1 + a27 = 1 + a28 = 1 + a29 = 1 + a30 = 1 + a31 = 1 + a32 = 1 + a33 = 1 + a34 = 1 + a35 = 1 + a36 = 1 + a37 = 1 + a38 = 1 + a39 = 1 + a40 = 1 + a41 = 1 + a42 = 1 + a43 = 1 + a44 = 1 + a45 = 1 + a46 = 1 + a47 = 1 + a48 = 1 + a49 = 1 + a50 = 1 + a51 = 1 + a52 = 1 + a53 = 1 + a54 = 1 + a55 = 1 + a56 = 1 + a57 = 1 + a58 = 1 + a59 = 1 + a60 = 1 + a61 = 1 + a62 = 1 + a63 = 1 + a64 = 1 + a65 = 1 + a66 = 1 + a67 = 1 + a68 = 1 + a69 = 1 + a70 = 1 + a71 = 1 + a72 = 1 + a73 = 1 + a74 = 1 + a75 = 1 + a76 = 1 + a77 = 1 + a78 = 1 + a79 = 1 + a80 = 1 + a81 = 1 + a82 = 1 + a83 = 1 + a84 = 1 + a85 = 1 + a86 = 1 + a87 = 1 + a88 = 1 + a89 = 1 + a90 = 1 + a91 = 1 + a92 = 1 + a93 = 1 + a94 = 1 + a95 = 1 + a96 = 1 + a97 = 1 + a98 = 1 + a99 = 1 + a100 = 1 + a101 = 1 + a102 = 1 + a103 = 1 + a104 = 1 + a105 = 1 + a106 = 1 + a107 = 1 + a108 = 1 + a109 = 1 + a110 = 1 + a111 = 1 + a112 = 1 + a113 = 1 + a114 = 1 + a115 = 1 + a116 = 1 + a117 = 1 + a118 = 1 + a119 = 1 + a120 = 1 + a121 = 1 + a122 = 1 + a123 = 1 + a124 = 1 + a125 = 1 + a126 = 1 + a127 = 1 + a128 = 1 + a129 = 1 + a130 = 1 + a131 = 1 + a132 = 1 + a133 = 1 + a134 = 1 + a135 = 1 + a136 = 1 + a137 = 1 + a138 = 1 + a139 = 1 + a140 = 1 + a141 = 1 + a142 = 1 + a143 = 1 + a144 = 1 + a145 = 1 + a146 = 1 + a147 = 1 + a148 = 1 + a149 = 1 + a150 = 1 + a151 = 1 + a152 = 1 + a153 = 1 + a154 = 1 + a155 = 1 + a156 = 1 + a157 = 1 + a158 = 1 + a159 = 1 + a160 = 1 + a161 = 1 + a162 = 1 + a163 = 1 + a164 = 1 + a165 = 1 + a166 = 1 + a167 = 1 + a168 = 1 + a169 = 1 + a170 = 1 + a171 = 1 + a172 = 1 + a173 = 1 + a174 = 1 + a175 = 1 + a176 = 1 + a177 = 1 + a178 = 1 + a179 = 1 + a180 = 1 + a181 = 1 + a182 = 1 + a183 = 1 + a184 = 1 + a185 = 1 + a186 = 1 + a187 = 1 + a188 = 1 + a189 = 1 + a190 = 1 + a191 = 1 + a192 = 1 + a193 = 1 + a194 = 1 + a195 = 1 + a196 = 1 + a197 = 1 + a198 = 1 + a199 = 1 + a200 = 1 + a201 = 1 + a202 = 1 + a203 = 1 + a204 = 1 + a205 = 1 + a206 = 1 + a207 = 1 + a208 = 1 + a209 = 1 + a210 = 1 + a211 = 1 + a212 = 1 + a213 = 1 + a214 = 1 + a215 = 1 + a216 = 1 + a217 = 1 + a218 = 1 + a219 = 1 + a220 = 1 + a221 = 1 + a222 = 1 + a223 = 1 + a224 = 1 + a225 = 1 + a226 = 1 + a227 = 1 + a228 = 1 + a229 = 1 + a230 = 1 + a231 = 1 + a232 = 1 + a233 = 1 + a234 = 1 + a235 = 1 + a236 = 1 + a237 = 1 + a238 = 1 + a239 = 1 + a240 = 1 + a241 = 1 + a242 = 1 + a243 = 1 + a244 = 1 + a245 = 1 + a246 = 1 + a247 = 1 + a248 = 1 + a249 = 1 + a250 = 1 + a251 = 1 + a252 = 1 + a253 = 1 + a254 = 1 + a255 = 1 + a256 = 1 + a257 = 1 + a258 = 1 + a259 = 1 + b = a1 + a2 + a260 = 1 + a261 = 1 + return b + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_bytecode_overflow_example.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_bytecode_overflow_example.py new file mode 100644 index 0000000..84f126d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_bytecode_overflow_example.py @@ -0,0 +1,98 @@ +import re + +en_lang_symbols = r'[^\w!@#$%\^-_+=|\}{][\"\';:?\/><.,&)(*\s`\u2019]' +en_words_basic = [] +en_words = [] + +TRACE_MESSAGE = "Trace called" + + +def tracing(): + print(TRACE_MESSAGE) + + +def call_tracing(): + tracing() + + +class Dummy: + non_en_words_limit = 3 + + @staticmethod + def fun(text): + words = tuple(w[0].lower() for w in re.finditer(r'[a-zA-Z]+', text)) + non_en_pass = [] + for i, word in enumerate(words): + non_en = [] + if not (word in en_words_basic + or (word.endswith('s') and word[:-1] in en_words_basic) + or (word.endswith('ed') and word[:-2] in en_words_basic) + or (word.endswith('ing') and word[:-3] in en_words_basic) + or word in en_words + or (word.endswith('s') and word[:-1] in en_words) + or (word.endswith('ed') and word[:-2] in en_words) + or (word.endswith('ing') and word[:-3] in en_words) + ): + + non_en.append(word) + non_en_pass.append(word) + for j in range(1, Dummy.non_en_words_limit): + if i + j >= len(words): + break + word = words[i + j] + + if (word in en_words_basic + or (word.endswith('s') and word[:-1] in en_words_basic) + or (word.endswith('ed') and word[:-2] in en_words_basic) + or (word.endswith('ing') and word[:-3] in en_words_basic) + or word in en_words + or (word.endswith('s') and word[:-1] in en_words) + or (word.endswith('ed') and word[:-2] in en_words) + or (word.endswith('ing') and word[:-3] in en_words) + ): + break + else: + non_en.append(word) + non_en_pass.append(word) + + +class DummyTracing: + non_en_words_limit = 3 + + @staticmethod + def fun(text): + words = tuple(w[0].lower() for w in re.finditer(r'[a-zA-Z]+', text)) + tracing() + non_en_pass = [] + for i, word in enumerate(words): + non_en = [] + if not (word in en_words_basic + or (word.endswith('s') and word[:-1] in en_words_basic) + or (word.endswith('ed') and word[:-2] in en_words_basic) + or (word.endswith('ing') and word[:-3] in en_words_basic) + or word in en_words + or (word.endswith('s') and word[:-1] in en_words) + or (word.endswith('ed') and word[:-2] in en_words) + or (word.endswith('ing') and word[:-3] in en_words) + ): + + non_en.append(word) + non_en_pass.append(word) + for j in range(1, Dummy.non_en_words_limit): + if i + j >= len(words): + break + word = words[i + j] + if (word in en_words_basic + or (word.endswith('s') and word[:-1] in en_words_basic) + or (word.endswith('ed') and word[:-2] in en_words_basic) + or (word.endswith('ing') and word[:-3] in en_words_basic) + or word in en_words + or (word.endswith('s') and word[:-1] in en_words) + or (word.endswith('ed') and word[:-2] in en_words) + or (word.endswith('ing') and word[:-3] in en_words) + ): + break + else: + non_en.append(word) + non_en_pass.append(word) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case1.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case1.py new file mode 100644 index 0000000..7ef8062 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case1.py @@ -0,0 +1,61 @@ +import sys +import weakref + +def set_up(): + observable = Observable() + observer = Observer() + observable.add_observer(observer) + return observable + + +class Observable(object): + def __init__(self): + self.observers = [] + + def add_observer(self, observer): + sys.stdout.write( 'observer %s\n' % (observer,)) + ref = weakref.ref(observer) + self.observers.append(ref) + sys.stdout.write('weakref: %s\n' % (ref(),)) + + def Notify(self): + for o in self.observers: + o = o() + + + try: + import gc + except ImportError: + o = None #some jython does not have gc, so, there's no sense testing this in it + else: + try: + gc.get_referrers(o) + except: + o = None #jython and ironpython do not have get_referrers + + if o is not None: + sys.stdout.write('still observing %s\n' % (o,)) + sys.stdout.write('number of referrers: %s\n' % len(gc.get_referrers(o))) + frame = gc.get_referrers(o)[0] + frame_referrers = gc.get_referrers(frame) + sys.stdout.write('frame referrer %s\n' % (frame_referrers,)) + referrers1 = gc.get_referrers(frame_referrers[1]) + sys.stdout.write('%s\n' % (referrers1,)) + sys.stderr.write('TEST FAILED: The observer should have died, even when running in debug\n') + else: + sys.stdout.write('TEST SUCEEDED: observer died\n') + + sys.stdout.flush() + sys.stderr.flush() + +class Observer(object): + pass + + +def main(): + observable = set_up() + observable.Notify() + + +if __name__ == '__main__': + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case13.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case13.py new file mode 100644 index 0000000..dbdbbd4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case13.py @@ -0,0 +1,43 @@ + +class TestProperty(object): + def __init__(self, name = "Default"): + self._x = None + self.name = name + + def get_name(self): + return self.__name + + + def set_name(self, value): + self.__name = value + + + def del_name(self): + del self.__name + name = property(get_name, set_name, del_name, "name's docstring") + + @property + def x(self): + return self._x + + @x.setter + def x(self, value): + self._x = value + + @x.deleter + def x(self): + del self._x + +def main(): + """ + """ + testObj = TestProperty() + testObj.x = 10 + val = testObj.x + + testObj.name = "Pydev" + debugType = testObj.name + print('TEST SUCEEDED!') + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case14.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case14.py new file mode 100644 index 0000000..2a5e181 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case14.py @@ -0,0 +1,29 @@ + +class Car(object): + """A car class""" + def __init__(self, model, make, color): + self.model = model + self.make = make + self.color = color + self.price = None + + def get_price(self): + return self.price + + def set_price(self, value): + self.price = value + +availableCars = [] +def main(): + global availableCars + + #Create a new car obj + carObj = Car("Maruti SX4", "2011", "Black") + carObj.set_price(950000) # Set price + # Add this to available cars + availableCars.append(carObj) + + print('TEST SUCEEDED') + +if __name__ == '__main__': + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case15.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case15.py new file mode 100644 index 0000000..2a5e181 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case15.py @@ -0,0 +1,29 @@ + +class Car(object): + """A car class""" + def __init__(self, model, make, color): + self.model = model + self.make = make + self.color = color + self.price = None + + def get_price(self): + return self.price + + def set_price(self, value): + self.price = value + +availableCars = [] +def main(): + global availableCars + + #Create a new car obj + carObj = Car("Maruti SX4", "2011", "Black") + carObj.set_price(950000) # Set price + # Add this to available cars + availableCars.append(carObj) + + print('TEST SUCEEDED') + +if __name__ == '__main__': + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case15_execfile.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case15_execfile.py new file mode 100644 index 0000000..7123209 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case15_execfile.py @@ -0,0 +1 @@ +f=lambda x: 'val=%s' % x diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case16.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case16.py new file mode 100644 index 0000000..5622813 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case16.py @@ -0,0 +1,12 @@ +# this test requires numpy to be installed +import numpy + +def main(): + smallarray = numpy.arange(100) * 1 + 1j + bigarray = numpy.arange(100000).reshape((10,10000)) # 100 thousand + hugearray = numpy.arange(10000000) # 10 million + + pass # location of breakpoint after all arrays defined + +main() +print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case17.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case17.py new file mode 100644 index 0000000..0177683 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case17.py @@ -0,0 +1,38 @@ +def get_here(): + a = 10 + +def foo(func): + return func + +def m1(): # @DontTrace + get_here() + +# @DontTrace +def m2(): + get_here() + +# @DontTrace +@foo +def m3(): + get_here() + +@foo +@foo +def m4(): # @DontTrace + get_here() + + +def main(): + + m1() + + m2() + + m3() + + m4() + +if __name__ == '__main__': + main() + + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case17a.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case17a.py new file mode 100644 index 0000000..fa3ea0e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case17a.py @@ -0,0 +1,15 @@ +def m1(): + _a = 'm1' + +def m2(): # @DontTrace + m1() + _a = 'm2' + +def m3(): + m2() + _a = 'm3' + +if __name__ == '__main__': + m3() + + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case18.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case18.py new file mode 100644 index 0000000..c221039 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case18.py @@ -0,0 +1,23 @@ +import sys + +def m2(a): + a = 10 + b = 20 #Break here and set a = 40 + c = 30 + + def function2(): + print(a) + + return a + + +def m1(a): + return m2(a) + + +if __name__ == '__main__': + found = m1(10) + if found == 40: + print('TEST SUCEEDED') + else: + raise AssertionError('Expected variable to be changed to 40. Found: %s' % (found,)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case19.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case19.py new file mode 100644 index 0000000..07ac951 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case19.py @@ -0,0 +1,10 @@ +class A: + + def __init__(self): + self.__var = 10 + +if __name__ == '__main__': + a = A() + print(a._A__var) + # Evaluate 'a.__var' should give a._A__var_ + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case2.py new file mode 100644 index 0000000..e47a5e2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case2.py @@ -0,0 +1,24 @@ + +def Call4(): + print('Start Call4') + print('End Call4') + +def Call3(): + print('Start Call3') + Call4() + print('End Call3') + +def Call2(): + print('Start Call2') + Call3() + print('End Call2 - a') + print('End Call2 - b') + +def Call1(): + print('Start Call1') + Call2() + print('End Call1') + +if __name__ == '__main__': + Call1() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case20.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case20.py new file mode 100644 index 0000000..e18e048 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case20.py @@ -0,0 +1,38 @@ +import pydevd +import threading + +original = pydevd.PyDB.notify_thread_created + +found = set() + +def new_notify_thread_created(self, thread_id, thread, *args, **kwargs): + found.add(thread) + return original(self, thread_id, thread, *args, **kwargs) + +pydevd.PyDB.notify_thread_created = new_notify_thread_created + +ok = [] +class MyThread(threading.Thread): + + def run(self): + if self not in found: + ok.append(False) + else: + ok.append(True) + +if __name__ == '__main__': + threads = [] + for i in range(15): + t = MyThread() + t.start() + threads.append(t) + + for t in threads: + t.join() + + assert len(ok) == len(threads) + assert all(ok), 'Expected all threads to be notified of their creation before starting to run. Found: %s' % (ok,) + + found.clear() + print('TEST SUCEEDED') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case3.py new file mode 100644 index 0000000..aa05032 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case3.py @@ -0,0 +1,8 @@ +import time +if __name__ == '__main__': + for i in range(15): + print('here') + time.sleep(.2) + + print('TEST SUCEEDED') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case4.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case4.py new file mode 100644 index 0000000..661d930 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case4.py @@ -0,0 +1,22 @@ +import time + + +class ProceedContainer: + proceed = False + + +def exit_while_loop(): + ProceedContainer.proceed = True + return 'ok' + + +def sleep(): + while not ProceedContainer.proceed: # The debugger should change the proceed to True to exit the loop. + time.sleep(.1) + + +if __name__ == '__main__': + sleep() + + print('TEST SUCEEDED') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case56.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case56.py new file mode 100644 index 0000000..e5de28d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case56.py @@ -0,0 +1,9 @@ +def Call2(): + print('Call2') + +def Call1(a): + print('Call1') + +if __name__ == '__main__': + Call1(Call2()) + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case89.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case89.py new file mode 100644 index 0000000..e22361d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case89.py @@ -0,0 +1,16 @@ +def Method1(): + print('m1') + +def Method2(): + print('m2 before') + Method1() + print('m2 after') + +def Method3(): + print('m3 before') + Method2() + print('m3 after') + +if __name__ == '__main__': + Method3() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_adjust_breakpoint.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_adjust_breakpoint.py new file mode 100644 index 0000000..0c26a8c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_adjust_breakpoint.py @@ -0,0 +1,10 @@ +def Call(): + b = True + while b: # expected + pass # requested + break + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_attach_to_pid_multiple_threads.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_attach_to_pid_multiple_threads.py new file mode 100644 index 0000000..92c0ba1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_attach_to_pid_multiple_threads.py @@ -0,0 +1,47 @@ + +import time +import sys +try: + import _thread +except: + import thread as _thread + +if __name__ == '__main__': + + lock = _thread.allocate_lock() + initialized = [False] + print('Main thread ident should be: %s' % (_thread.get_ident())) + + def new_thread_function(): + sys.secondary_id = _thread.get_ident() + print('Secondary thread ident should be: %s' % (_thread.get_ident())) + wait = True + + with lock: + initialized[0] = True + while wait: + time.sleep(.1) # break thread here + + _thread.start_new_thread(new_thread_function, ()) + + wait = True + + while not initialized[0]: + time.sleep(.1) + + with lock: # It'll be here until the secondary thread finishes (i.e.: releases the lock). + pass + + import threading # Note: only import after the attach. + curr_thread_ident = threading.current_thread().ident + if hasattr(threading, 'main_thread'): + main_thread_ident = threading.main_thread().ident + else: + # Python 2 does not have main_thread, but we can still get the reference. + main_thread_ident = threading._shutdown.im_self.ident + + if curr_thread_ident != main_thread_ident: + raise AssertionError('Expected current thread ident (%s) to be the main thread ident (%s)' % ( + curr_thread_ident, main_thread_ident)) + + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_attach_to_pid_simple.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_attach_to_pid_simple.py new file mode 100644 index 0000000..57f39d9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_attach_to_pid_simple.py @@ -0,0 +1,17 @@ +import time + +if __name__ == '__main__': + wait = True + + while wait: + time.sleep(1) # break here + + # Ok, if it got here things are looking good, let's just make + # sure that the threading module main thread has the correct ident. + import threading # Note: only import after the attach. + if hasattr(threading, 'main_thread'): + assert threading.current_thread().ident == threading.main_thread().ident + else: + # Python 2 does not have main_thread, but we can still get the reference. + assert threading.current_thread().ident == threading._shutdown.im_self.ident + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint.py new file mode 100644 index 0000000..745833f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint.py @@ -0,0 +1,7 @@ + +def break_in_method(): + breakpoint() # Builtin on Py3, but we provide a backport on Py2. + + +break_in_method() +print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint2.py new file mode 100644 index 0000000..9123ada --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint2.py @@ -0,0 +1,7 @@ +import sys +def break_in_method(): + sys.__breakpointhook__() # Builtin on Py3, but we provide a backport on Py2. + + +break_in_method() +print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_condition_exc.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_condition_exc.py new file mode 100644 index 0000000..acc2fd4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_condition_exc.py @@ -0,0 +1,8 @@ +def Call(): + for i in range(10): # break here + last_i = i + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_remote.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_remote.py new file mode 100644 index 0000000..12c24d0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_remote.py @@ -0,0 +1,15 @@ +if __name__ == '__main__': + import os + import sys + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + import pydevd + print('before pydevd.settrace') + breakpoint(port=port) + print('after pydevd.settrace') + print('TEST SUCEEDED!') + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_remote_no_import.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_remote_no_import.py new file mode 100644 index 0000000..ae1cdfd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_breakpoint_remote_no_import.py @@ -0,0 +1,14 @@ +if __name__ == '__main__': + import os + import sys + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + print('before pydevd.settrace') + breakpoint(port=port) # Set up through custom sitecustomize.py + print('after pydevd.settrace') + print('TEST SUCEEDED!') + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_change_breaks.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_change_breaks.py new file mode 100644 index 0000000..ce72f1a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_change_breaks.py @@ -0,0 +1,12 @@ + + +def method(): + _a = 1 # break 1 + _a = 2 + _a = 3 # break 2 + + +if __name__ == '__main__': + for i in range(2): + method() + print('TEST SUCEEDED') # break 3 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_check_tracer.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_check_tracer.py new file mode 100644 index 0000000..0fa373f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_check_tracer.py @@ -0,0 +1,116 @@ +import threading, atexit, sys +from collections import namedtuple +import os.path + +if sys.version_info[0] >= 3: + from _thread import start_new_thread +else: + from thread import start_new_thread + +FrameInfo = namedtuple('FrameInfo', 'filename, name, f_trace') + + +def _atexit(): + sys.stderr.flush() + sys.stdout.flush() + + +# Register the TEST SUCEEDED msg to the exit of the process. +atexit.register(_atexit) + + +def _iter_frame_info(frame): + while frame is not None: + yield FrameInfo( + os.path.basename(frame.f_code.co_filename), + frame.f_code.co_name, + frame.f_trace.__name__ if frame.f_trace is not None else "None" + ) + frame = frame.f_back + + +def check_frame_info(expected): + found = list(_iter_frame_info(sys._getframe().f_back)) + + def fail(): + raise AssertionError('Expected:\n%s\n\nFound:\n%s\n' % ( + '\n'.join(str(x) for x in expected), + '\n'.join(str(x) for x in found))) + + for found_info, expected_info in zip(found, expected): + if found_info.filename != expected_info.filename or found_info.name != expected_info.name: + fail() + + for f_trace in expected_info.f_trace.split('|'): + if f_trace == found_info.f_trace: + break + else: + fail() + + +def thread_func(): + if sys.version_info[0] >= 3: + check_frame_info([ + FrameInfo(filename='_debugger_case_check_tracer.py', name='thread_func', f_trace='trace_exception'), + FrameInfo(filename='threading.py', name='run', f_trace='None'), + FrameInfo(filename='threading.py', name='_bootstrap_inner', f_trace='trace_unhandled_exceptions'), + FrameInfo(filename='threading.py', name='_bootstrap', f_trace='None'), + FrameInfo(filename='pydev_monkey.py', name='__call__', f_trace='None') + ]) + else: + check_frame_info([ + FrameInfo(filename='_debugger_case_check_tracer.py', name='thread_func', f_trace='trace_exception'), + FrameInfo(filename='threading.py', name='run', f_trace='None'), + FrameInfo(filename='threading.py', name='__bootstrap_inner', f_trace='trace_unhandled_exceptions'), + FrameInfo(filename='threading.py', name='__bootstrap', f_trace='None'), + FrameInfo(filename='pydev_monkey.py', name='__call__', f_trace='None'), + ]) + + +th = threading.Thread(target=thread_func) +th.setDaemon(True) +th.start() + +event = threading.Event() + + +def thread_func2(): + try: + check_frame_info([ + FrameInfo(filename='_debugger_case_check_tracer.py', name='thread_func2', f_trace='trace_exception'), + FrameInfo(filename='pydev_monkey.py', name='__call__', f_trace='trace_unhandled_exceptions') + ]) + finally: + event.set() + + +start_new_thread(thread_func2, ()) + +event.wait() +th.join() + +# This is a bit tricky: although we waited on the event, there's a slight chance +# that we didn't get the notification because the thread could've stopped executing, +# so, sleep a bit so that the test does not become flaky. +import time +time.sleep(.3) + +if sys.version_info[0] >= 3: + check_frame_info([ + FrameInfo(filename='_debugger_case_check_tracer.py', name='', f_trace='trace_exception'), + FrameInfo(filename='_pydev_execfile.py', name='execfile', f_trace='None'), + FrameInfo(filename='pydevd.py', name='_exec', f_trace='trace_unhandled_exceptions'), + FrameInfo(filename='pydevd.py', name='run', f_trace='trace_dispatch|None'), + FrameInfo(filename='pydevd.py', name='main', f_trace='trace_dispatch|None'), + FrameInfo(filename='pydevd.py', name='', f_trace='trace_dispatch|None') + ]) +else: + check_frame_info([ + FrameInfo(filename='_debugger_case_check_tracer.py', name='', f_trace='trace_exception'), + FrameInfo(filename='pydevd.py', name='_exec', f_trace='trace_unhandled_exceptions'), + FrameInfo(filename='pydevd.py', name='run', f_trace='trace_dispatch|None'), + FrameInfo(filename='pydevd.py', name='main', f_trace='trace_dispatch|None'), + FrameInfo(filename='pydevd.py', name='', f_trace='trace_dispatch|None'), + ]) + +print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_completions.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_completions.py new file mode 100644 index 0000000..f570209 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_completions.py @@ -0,0 +1,23 @@ +def method1(): + yield + print('here') # Break here + + +if __name__ == '__main__': + # i.e.: make sure we create 2 frames with different frameIds. + it1 = iter(method1()) + it2 = iter(method1()) + + next(it1) # resume first + next(it2) # resume second + + try: + next(it1) # finish first + except StopIteration: + pass + try: + next(it2) # finish second + except StopIteration: + pass + + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_custom_frames.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_custom_frames.py new file mode 100644 index 0000000..af30327 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_custom_frames.py @@ -0,0 +1,23 @@ +import sys + +from _pydevd_bundle.pydevd_custom_frames import add_custom_frame +import threading + + +def call1(): + add_custom_frame(sys._getframe(), 'call1', threading.current_thread().ident) + + +def call2(): + add_custom_frame(sys._getframe(), 'call2', threading.current_thread().ident) + + +def call3(): + add_custom_frame(sys._getframe(), 'call3', threading.current_thread().ident) + + +if __name__ == '__main__': + call1() # break here + call2() + call3() + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_deep_stacks.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_deep_stacks.py new file mode 100644 index 0000000..8d06e16 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_deep_stacks.py @@ -0,0 +1,16 @@ +def method1(n): + if n <= 0: + return 0 # Break here + method2(n - 1) + + +def method2(n): + method1(n - 1) + + +if __name__ == '__main__': + try: + method1(100) + except: + pass # Don't let it print the exception (just deal with caught exceptions). + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_dont_trace.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_dont_trace.py new file mode 100644 index 0000000..5632d14 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_dont_trace.py @@ -0,0 +1,3 @@ +def call_me_back(callback): + if callable(callback): + callback() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_dont_trace_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_dont_trace_test.py new file mode 100644 index 0000000..0cb797e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_dont_trace_test.py @@ -0,0 +1,18 @@ +import sys +import os + +try: + from _debugger_case_dont_trace import call_me_back +except ImportError: + sys.path.append(os.path.dirname(__file__)) + from _debugger_case_dont_trace import call_me_back + + +def my_callback(): + print('trace me') # Break here + + +if __name__ == '__main__': + call_me_back(my_callback) + call_me_back(my_callback) + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_evaluate.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_evaluate.py new file mode 100644 index 0000000..ba01479 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_evaluate.py @@ -0,0 +1,8 @@ +def Call(): + var_1 = 5 + + var_all = 1 # Break here + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_event_ext.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_event_ext.py new file mode 100644 index 0000000..66b9ba6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_event_ext.py @@ -0,0 +1 @@ +# File empty. Output is in the extension itself \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_exceptions.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_exceptions.py new file mode 100644 index 0000000..f4a7be2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_exceptions.py @@ -0,0 +1,22 @@ +import sys + + +def method3(): + raise IndexError('foo') # raise indexerror line + + +def method2(): + return method3() # reraise on method2 + + +def method1(): + try: + method2() # handle on method1 + except: + pass # Ok, handled + assert '__exception__' not in sys._getframe().f_locals + + +if __name__ == '__main__': + method1() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_frame_eval.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_frame_eval.py new file mode 100644 index 0000000..945355f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_frame_eval.py @@ -0,0 +1,70 @@ +''' +Things this test checks: + +- frame.f_trace is None when there are only regular breakpoints. + +- The no-op tracing function is set by default (otherwise when set tracing functions have no effect). + +- When stepping in, frame.f_trace must be set by the frame eval. + +- When stepping over/return, the frame.f_trace must not be set on intermediate callers. + +TODO: + +- When frame.f_trace is set to the default tracing function, it'll become None again in frame + eval mode if not stepping (if breakpoints weren't changed). + +- The tracing function in the frames that deal with unhandled exceptions must be set when dealing + with unhandled exceptions. + +- The tracing function in the frames that deal with unhandled exceptions must NOT be set when + NOT dealing with unhandled exceptions. + +- If handled exceptions should be dealt with, the proper tracing should be set in frame.f_trace. +''' + +import sys +from _pydevd_frame_eval import pydevd_frame_tracing + + +def check_with_no_trace(): + if False: + print('break on check_with_trace') + frame = sys._getframe() + if frame.f_trace is not None: + raise AssertionError('Expected %s to be None' % (frame.f_trace,)) + + if sys.gettrace() is not pydevd_frame_tracing.dummy_tracing_holder.dummy_trace_func: + raise AssertionError('Expected %s to be dummy_trace_func' % (sys.gettrace(),)) + + +def check_step_in_then_step_return(): + frame = sys._getframe() + f_trace = frame.f_trace + if f_trace.__class__.__name__ != 'SafeCallWrapper': + raise AssertionError('Expected %s to be SafeCallWrapper' % (f_trace.__class__.__name__,)) + + check_with_no_trace() + + +def check_revert_to_dummy(): + check_with_no_trace() + + +if __name__ == '__main__': + # Check how frame eval works. + if sys.version_info[0:2] < (3, 6): + raise AssertionError('Only available for Python 3.6 onwards. Found: %s' % (sys.version_info[0:1],)) + + check_with_no_trace() # break on global (step over) + + check_step_in_then_step_return() + + import pydevd_tracing + import pydevd + + # This is what a remote attach would do (should revert to the frame eval mode). + pydevd_tracing.SetTrace(pydevd.get_global_debugger().trace_dispatch) + check_revert_to_dummy() + + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_generator_py2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_generator_py2.py new file mode 100644 index 0000000..956190c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_generator_py2.py @@ -0,0 +1,16 @@ +def generator2(): + for i in range(4): + yield i + + +def generator(): + a = 42 # break here + for x in generator2(): + yield x + + +sum = 0 +for i in generator(): + sum += i + +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_generator_py3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_generator_py3.py new file mode 100644 index 0000000..f8cf55a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_generator_py3.py @@ -0,0 +1,14 @@ +def generator2(): + yield from range(4) + + +def generator(): + a = 42 # break here + yield from generator2() + + +sum = 0 +for i in generator(): + sum += i + +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_get_next_statement_targets.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_get_next_statement_targets.py new file mode 100644 index 0000000..e258a95 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_get_next_statement_targets.py @@ -0,0 +1,26 @@ +def method(): + a = 1 + print('call %s' % (a,)) + + def method2(): + print('call %s' % (a,)) + + while a < 10: + a += 1 + print('call %s' % (a,)) + + try: + if a < 0: + print('call %s' % (a,)) + raise ValueError + else: + method2() + except ValueError: + pass + + print('call %s' % (a,)) + + +if __name__ == '__main__': + method() + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_get_thread_stack.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_get_thread_stack.py new file mode 100644 index 0000000..2ed3bc7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_get_thread_stack.py @@ -0,0 +1,21 @@ +import threading +event_set = False +inner_started = False + +def method(): + global inner_started + inner_started = True + while not event_set: + import time + time.sleep(.1) + +t = threading.Thread(target=method) +t.start() +while not inner_started: + import time + time.sleep(.1) + +print('break here') +event_set = True +t.join() +print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_gevent.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_gevent.py new file mode 100644 index 0000000..fd38429 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_gevent.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +from gevent import monkey, sleep, threading as gevent_threading +monkey.patch_all() +import threading + +called = [] + + +class MyGreenletThread(threading.Thread): + + def run(self): + for _i in range(5): + called.append(self.name) # break here + sleep() + +if __name__ == '__main__': + t1 = MyGreenletThread() + t1.name = 't1' + t2 = MyGreenletThread() + t2.name = 't2' + + if hasattr(gevent_threading, 'Thread'): + # Only available in newer versions of gevent. + assert isinstance(t1, gevent_threading.Thread) + assert isinstance(t2, gevent_threading.Thread) + + t1.start() + t2.start() + + for t1 in (t1, t2): + t1.join() + + # With gevent it's always the same (gevent coroutine support makes thread + # switching serial). + assert called == ['t1', 't1', 't2', 't1', 't2', 't1', 't2', 't1', 't2', 't2'] + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_import_imported.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_import_imported.py new file mode 100644 index 0000000..bc66192 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_import_imported.py @@ -0,0 +1,2 @@ +print('text 1') +print('text 2') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_import_main.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_import_main.py new file mode 100644 index 0000000..92e8676 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_import_main.py @@ -0,0 +1,3 @@ +import _debugger_case_import_imported # break here + +print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_lamda.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_lamda.py new file mode 100644 index 0000000..c039e4c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_lamda.py @@ -0,0 +1,5 @@ +call = lambda b:b # Break here will hit once at creation time and then at each call. +call(1) +call(2) + +print('TEST SUCEEDED') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_large_exception_stack.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_large_exception_stack.py new file mode 100644 index 0000000..7fa3704 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_large_exception_stack.py @@ -0,0 +1,16 @@ +def method1(n): + if n <= 0: + raise IndexError('foo') + method2(n - 1) + + +def method2(n): + method1(n - 1) + + +if __name__ == '__main__': + try: + method1(100) + except: + pass # Don't let it print the exception (just deal with caught exceptions). + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables.py new file mode 100644 index 0000000..47f8f16 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables.py @@ -0,0 +1,14 @@ + + +def Call(): + variable_for_test_1 = 10 # Break here + variable_for_test_2 = 20 + variable_for_test_3 = {'a':30, 'b':20} + locals()[u'\u16A0'] = u'\u16A1' # unicode variable (would be syntax error on py2). + + all_vars_set = True # Break 2 here + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables2.py new file mode 100644 index 0000000..988c97d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables2.py @@ -0,0 +1,12 @@ + + +def Call(): + variable_for_test_1 = ['a', 'b'] + variable_for_test_2 = set(['a']) + + all_vars_set = True # Break here + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables3.py new file mode 100644 index 0000000..7161353 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables3.py @@ -0,0 +1,82 @@ +class MyDictSubclass(dict): + + def __init__(self): + dict.__init__(self) + self.var1 = 10 + self['in_dct'] = 20 + + def __str__(self): + ret = [] + for key, val in sorted(self.items()): + ret.append('%s: %s' % (key, val)) + ret.append('self.var1: %s' % (self.var1,)) + return '{' + '; '.join(ret) + '}' + + __repr__ = __str__ + + +class MyListSubclass(list): + + def __init__(self): + list.__init__(self) + self.var1 = 11 + self.append('a') + self.append('b') + + def __str__(self): + ret = [] + for obj in self: + ret.append(repr(obj)) + ret.append('self.var1: %s' % (self.var1,)) + return '[' + ', '.join(ret) + ']' + + __repr__ = __str__ + + +class MySetSubclass(set): + + def __init__(self): + set.__init__(self) + self.var1 = 12 + self.add('a') + + def __str__(self): + ret = [] + for obj in sorted(self): + ret.append(repr(obj)) + ret.append('self.var1: %s' % (self.var1,)) + return 'set([' + ', '.join(ret) + '])' + + __repr__ = __str__ + + +class MyTupleSubclass(tuple): + + def __new__ (cls): + return super(MyTupleSubclass, cls).__new__(cls, tuple(['a', 1])) + + def __init__(self): + self.var1 = 13 + + def __str__(self): + ret = [] + for obj in self: + ret.append(repr(obj)) + ret.append('self.var1: %s' % (self.var1,)) + return 'tuple(' + ', '.join(ret) + ')' + + __repr__ = __str__ + + +def Call(): + variable_for_test_1 = MyListSubclass() + variable_for_test_2 = MySetSubclass() + variable_for_test_3 = MyDictSubclass() + variable_for_test_4 = MyTupleSubclass() + + all_vars_set = True # Break here + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables_hex.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables_hex.py new file mode 100644 index 0000000..07e2637 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_local_variables_hex.py @@ -0,0 +1,12 @@ +def Call(): + variables_for_test_1 = 100 + variables_for_test_2 = [1, 10, 100] + variables_for_test_3 = {10: 10, 100: 100, 1000: 1000} + variables_for_test_4 = {(1, 10, 100): (10000, 100000, 100000)} + + all_vars_set = True # Break here + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_m_switch.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_m_switch.py new file mode 100644 index 0000000..a5b3706 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_m_switch.py @@ -0,0 +1,3 @@ +from . import _debugger_case_m_switch_2 +print(_debugger_case_m_switch_2.ClassToBeImported) +print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_m_switch_2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_m_switch_2.py new file mode 100644 index 0000000..99c9f4c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_m_switch_2.py @@ -0,0 +1,2 @@ +class ClassToBeImported(object): + pass \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_matplotlib.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_matplotlib.py new file mode 100644 index 0000000..b973347 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_matplotlib.py @@ -0,0 +1,23 @@ +from concurrent.futures import ThreadPoolExecutor +import matplotlib +import matplotlib.pyplot as plt + +processed = [] + + +def double(nmbr): + doubled = nmbr * 2 # break here + processed.append(1) + return doubled + + +with ThreadPoolExecutor(max_workers=2) as pool: + futures = [] + + for number in range(3): + future = pool.submit(double, number) + futures.append(future) + +pool.shutdown() +assert len(processed) == 3 +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_module_entry_point.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_module_entry_point.py new file mode 100644 index 0000000..a69ce52 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_module_entry_point.py @@ -0,0 +1,2 @@ +def main(): + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multi_threads_stepping.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multi_threads_stepping.py new file mode 100644 index 0000000..be1eeb3 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multi_threads_stepping.py @@ -0,0 +1,55 @@ +''' +After breaking on the thread 1, thread 2 should pause waiting for the event1 to be set, +so, when we step return on thread 1, the program should finish if all threads are resumed +or should keep waiting for the thread 2 to run if only thread 1 is resumed. +''' + +import threading + +event0 = threading.Event() +event1 = threading.Event() +event2 = threading.Event() +event3 = threading.Event() + + +def _thread1(): + _event1_set = False + _event2_set = False + + while not event0.is_set(): + event0.wait(timeout=.001) + + event1.set() # Break thread 1 + _event1_set = True + + while not event2.is_set(): + event2.wait(timeout=.001) + _event2_set = True # Note: we can only get here if thread 2 is also released. + + event3.set() + + +def _thread2(): + event0.set() + + while not event1.is_set(): + event1.wait(timeout=.001) + + event2.set() + + while not event3.is_set(): + event3.wait(timeout=.001) + + +if __name__ == '__main__': + threads = [ + threading.Thread(target=_thread1, name='thread1'), + threading.Thread(target=_thread2, name='thread2'), + ] + for t in threads: + t.start() + + for t in threads: + t.join() + + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiple_threads.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiple_threads.py new file mode 100644 index 0000000..64296a8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiple_threads.py @@ -0,0 +1,32 @@ +import threading + + +class KeepInLoop(object): + keep_in_loop = True # Debugger should change to False to break. + + +def stop_loop(): + KeepInLoop.keep_in_loop = False + return 'stopped_loop' + + +def double_number(number): + while KeepInLoop.keep_in_loop: + doubled = number * 2 + print(doubled) + import time + time.sleep(.5) + return doubled + + +if __name__ == '__main__': + threads = [] + for num in range(2): + thread = threading.Thread(target=double_number, args=(num,)) + thread.start() + threads.append(thread) + + for thread in threads: + thread.join() + + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing.py new file mode 100644 index 0000000..9be273d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing.py @@ -0,0 +1,13 @@ +import multiprocessing +import sys + + +def run(name): + print("argument: ", name) # break 1 here + + +if __name__ == '__main__': + if sys.version_info[0] >= 3 and sys.platform != 'win32': + multiprocessing.set_start_method('fork') + multiprocessing.Process(target=run, args=("argument to run method",)).start() + print('TEST SUCEEDED!') # break 2 here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing_pool.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing_pool.py new file mode 100644 index 0000000..d83fb04 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing_pool.py @@ -0,0 +1,17 @@ +from __future__ import print_function +from multiprocessing import Pool +from time import sleep + + +def call(arg): + if arg == '2': + print("called") # break 1 here + + +if __name__ == '__main__': + pool = Pool(1) + pool.map(call, ['1', '2', '3']) + pool.close() + pool.join() + sleep(1) + print('TEST SUCEEDED!') # break 2 here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing_stopped_threads.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing_stopped_threads.py new file mode 100644 index 0000000..d43a29a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_multiprocessing_stopped_threads.py @@ -0,0 +1,30 @@ +import time +import multiprocessing +import threading +import sys +import os + +event = threading.Event() + + +class MyThread(threading.Thread): + + def run(self): + _a = 10 + _b = 20 # break in thread here + event.set() + _c = 20 + + +def run_in_multiprocess(): + _a = 30 + _b = 40 # break in process here + + +if __name__ == '__main__': + MyThread().start() + event.wait() + if sys.version_info[0] >= 3 and sys.platform != 'win32': + multiprocessing.set_start_method('fork') + multiprocessing.Process(target=run_in_multiprocess, args=()).start() + print('TEST SUCEEDED!') # break in main here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_namedtuple.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_namedtuple.py new file mode 100644 index 0000000..e871b0e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_namedtuple.py @@ -0,0 +1,6 @@ +from collections import namedtuple +MyTup = namedtuple('MyTup', 'a, b, c') +tup = MyTup(1, 2, 3) # break here +assert tup.a == 1 +assert tup.b == 2 +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_path_translation.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_path_translation.py new file mode 100644 index 0000000..3127821 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_path_translation.py @@ -0,0 +1,14 @@ +from tests_python.resource_path_translation import other + + +def call_this(): + print('break here') + + +def main(): + other.call_me_back1(call_this) + print('TEST SUCEEDED!') + + +if __name__ == '__main__': + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_pause_continue.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_pause_continue.py new file mode 100644 index 0000000..c37de64 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_pause_continue.py @@ -0,0 +1,13 @@ +import time +def Call(): + loop = True # Break here + + count = 0 + while(loop and (count < 200)): + time.sleep(0.1) + count += 1 # Pause here and change loop to False + + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_print.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_print.py new file mode 100644 index 0000000..e012ee8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_print.py @@ -0,0 +1 @@ +print('TEST SUCEEDED') # Break here should only hit once. \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_python_c.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_python_c.py new file mode 100644 index 0000000..21db960 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_python_c.py @@ -0,0 +1,21 @@ +import subprocess +import sys +import os +env = os.environ.copy() +pythonpath = env.get('PYTHONPATH', '') +env['PYTHONPATH'] = os.path.dirname(__file__) + + +def call(): + print("called") # break 1 here + + +if __name__ == '__main__': + p = subprocess.Popen( + [sys.executable, '-c', 'import _debugger_case_python_c;_debugger_case_python_c.call()'], + stdout=subprocess.PIPE, + env=env, + ) + stdout, stderr = p.communicate() + assert b'called' in stdout, 'Did not find b"called" in: %s' % (stdout,) + print('TEST SUCEEDED!') # break 2 here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread1.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread1.py new file mode 100644 index 0000000..b77a45b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread1.py @@ -0,0 +1,31 @@ +import time +import sys + +try: + try: + from PySide import QtCore # @UnresolvedImport + except: + from PySide2 import QtCore # @UnresolvedImport +except: + try: + from PyQt4 import QtCore + except: + from PyQt5 import QtCore + +# Subclassing QThread +# http://doc.qt.nokia.com/latest/qthread.html +class AThread(QtCore.QThread): + + def run(self): + count = 0 + while count < 5: + print("Increasing", count) # break here + sys.stdout.flush() + count += 1 + +app = QtCore.QCoreApplication([]) +thread = AThread() +thread.finished.connect(app.exit) +thread.start() +app.exec_() +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread2.py new file mode 100644 index 0000000..feddd72 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread2.py @@ -0,0 +1,40 @@ +import time +import sys + +try: + try: + from PySide import QtCore # @UnresolvedImport + except: + from PySide2 import QtCore # @UnresolvedImport +except: + try: + from PyQt4 import QtCore + except: + from PyQt5 import QtCore + +# Subclassing QObject and using moveToThread +# http://labs.qt.nokia.com/2007/07/05/qthreads-no-longer-abstract/ +class SomeObject(QtCore.QObject): + + try: + finished = QtCore.Signal() # @UndefinedVariable + except: + finished = QtCore.pyqtSignal() # @UndefinedVariable + + def long_running(self): + count = 0 + while count < 5: + print("Increasing") # break here + count += 1 + self.finished.emit() + +app = QtCore.QCoreApplication([]) +objThread = QtCore.QThread() +obj = SomeObject() +obj.moveToThread(objThread) +obj.finished.connect(objThread.quit) +objThread.started.connect(obj.long_running) +objThread.finished.connect(app.exit) +objThread.start() +app.exec_() +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread3.py new file mode 100644 index 0000000..5bc0470 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread3.py @@ -0,0 +1,35 @@ +import time +import sys + +try: + try: + from PySide import QtCore # @UnresolvedImport + except: + from PySide2 import QtCore # @UnresolvedImport +except: + try: + from PyQt4 import QtCore + except: + from PyQt5 import QtCore + +# Using a QRunnable +# http://doc.qt.nokia.com/latest/qthreadpool.html +# Note that a QRunnable isn't a subclass of QObject and therefore does +# not provide signals and slots. +class Runnable(QtCore.QRunnable): + + def run(self): + count = 0 + app = QtCore.QCoreApplication.instance() + while count < 5: + print("Increasing") # break here + count += 1 + app.quit() + + +app = QtCore.QCoreApplication([]) +runnable = Runnable() +QtCore.QThreadPool.globalInstance().start(runnable) +app.exec_() +QtCore.QThreadPool.globalInstance().waitForDone() +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread4.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread4.py new file mode 100644 index 0000000..f76da7a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_qthread4.py @@ -0,0 +1,41 @@ +try: + from PySide import QtCore +except: + try: + from PyQt4 import QtCore + except: + from PyQt5 import QtCore + +class TestObject(QtCore.QObject): + """ + Test class providing some non-argument signal + """ + + try: + testSignal = QtCore.Signal() # @UndefinedVariable + except: + testSignal = QtCore.pyqtSignal() # @UndefinedVariable + + +class TestThread(QtCore.QThread): + + def run(self): + QtCore.QThread.sleep(4) + print('Done sleeping') + +def on_start(): + print('On start called1') + print('On start called2') + +app = QtCore.QCoreApplication([]) +some_thread = TestThread() +some_object = TestObject() + +# connect QThread.started to the signal +some_thread.started.connect(some_object.testSignal) +some_object.testSignal.connect(on_start) +some_thread.finished.connect(app.quit) + +some_thread.start() +app.exec_() +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_quoting.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_quoting.py new file mode 100644 index 0000000..e9220ba --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_quoting.py @@ -0,0 +1,26 @@ +import subprocess +import sys + +args = [ + 'connect(\\"127 . 0.0.1\\")', + '"', + '', + '\\', + '\\"', + '""', +] + + +def main(): + retcode = subprocess.call([sys.executable, __file__] + args) + assert retcode == 0 + + +if __name__ == '__main__': + sys_args = sys.argv[1:] + if sys_args: + assert sys_args == args, 'Expected that %r == %r' % (sys_args, args) + print('break here') + print('TEST SUCEEDED!') + else: + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_redirect.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_redirect.py new file mode 100644 index 0000000..a920ccc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_redirect.py @@ -0,0 +1,24 @@ +# coding:utf-8 +if __name__ == '__main__': + import sys + for stream_name in ('stdout', 'stderr'): + stream = getattr(sys, stream_name) + if sys.version_info[0] == 2 and sys.version_info[1] == 6: + stream.write('text\n') + else: + stream.write(u'text\n') # Can't write unicode on py 2.6 + stream.write('binary or text\n') + stream.write('ação1\n') + + if sys.version_info[0] >= 3: + # sys.stdout.buffer is only available on py3. + stream.buffer.write(b'binary\n') + # Note: this will be giberish on the receiving side because when writing bytes + # we can't be sure what's the encoding and will treat it as utf-8 (i.e.: + # uses PYTHONIOENCODING). + stream.buffer.write('ação2\n'.encode(encoding='latin1')) + + # This will be ok + stream.buffer.write('ação3\n'.encode(encoding='utf-8')) + + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py new file mode 100644 index 0000000..f1aab4e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py @@ -0,0 +1,15 @@ +if __name__ == '__main__': + import os + import sys + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + import pydevd + print('before pydevd.settrace') + pydevd.settrace(port=port) + print('after pydevd.settrace') + print('TEST SUCEEDED!') + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_1.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_1.py new file mode 100644 index 0000000..3989430 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_1.py @@ -0,0 +1,28 @@ +if __name__ == '__main__': + import subprocess + import sys + import os + import _debugger_case_remote_2 + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + import pydevd + + print('before pydevd.settrace') + sys.stdout.flush() + pydevd.settrace(port=port, patch_multiprocessing=True) + print('after pydevd.settrace') + sys.stdout.flush() + f = _debugger_case_remote_2.__file__ + if f.endswith('.pyc'): + f = f[:-1] + elif f.endswith('$py.class'): + f = f[:-len('$py.class')] + '.py' + print('before call') + sys.stdout.flush() + subprocess.check_call([sys.executable, '-u', f]) + print('after call') + sys.stdout.flush() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_2.py new file mode 100644 index 0000000..d25bb77 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_2.py @@ -0,0 +1,11 @@ +if __name__ == '__main__': + print('Run as main: %s' % (__file__,)) + import sys + sys.stdout.flush() + import pydevd + # Just check that we're already connected + assert pydevd.GetGlobalDebugger() is not None + print('finish') + sys.stdout.flush() + print('TEST SUCEEDED!') + sys.stdout.flush() \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_threads.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_threads.py new file mode 100644 index 0000000..7192a19 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_threads.py @@ -0,0 +1,31 @@ +import threading +if __name__ == '__main__': + import os + import sys + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + def method(i): + import time + wait = True + while wait: + time.sleep(.1) # break here + + threads = [threading.Thread(target=method, args=(i,)) for i in range(2)] + for t in threads: + t.start() + + import pydevd + assert pydevd.get_global_debugger() is None + + print('before pydevd.settrace') + pydevd.settrace(port=port) + print('after pydevd.settrace') + + for t in threads: + t.join() + + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_unhandled_exceptions.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_unhandled_exceptions.py new file mode 100644 index 0000000..f0d9363 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_unhandled_exceptions.py @@ -0,0 +1,15 @@ +if __name__ == '__main__': + import os + import sys + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + import pydevd + print('before pydevd.settrace') + pydevd.settrace(port=port) + print('after pydevd.settrace') + raise ValueError('TEST SUCEEDED!') + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_unhandled_exceptions2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_unhandled_exceptions2.py new file mode 100644 index 0000000..9e7fd29 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remote_unhandled_exceptions2.py @@ -0,0 +1,21 @@ +if __name__ == '__main__': + import os + import sys + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + import pydevd + print('before pydevd.settrace') + pydevd.settrace(port=port) + print('after pydevd.settrace') + for i in range(2): + try: + raise ValueError('not finished') + except: + pass + + raise ValueError('TEST SUCEEDED!') + \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remove_breakpoint.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remove_breakpoint.py new file mode 100644 index 0000000..6681b42 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_remove_breakpoint.py @@ -0,0 +1,14 @@ + + +def check(): + import pydevd + py_db = pydevd.get_global_debugger() + assert len(py_db.api_received_breakpoints) == 1 + _a = 10 # break here + # should remove the breakpoints when stopped on the previous line + assert len(py_db.api_received_breakpoints) == 0 + + +if __name__ == '__main__': + check() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_return_value.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_return_value.py new file mode 100644 index 0000000..9f5cf50 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_return_value.py @@ -0,0 +1,12 @@ +def method1(): + return 1 + + +def method2(): + return 2 + + +if __name__ == '__main__': + method1() # break here + method2() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_scapy.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_scapy.py new file mode 100644 index 0000000..c2a51f6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_scapy.py @@ -0,0 +1,2 @@ +from scapy import all as scapy +print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_set_next_statement.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_set_next_statement.py new file mode 100644 index 0000000..dcbd1af --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_set_next_statement.py @@ -0,0 +1,10 @@ +def method(): + a = 1 # Step here + print('call %s' % (a,)) + a = 2 + print('call %s' % (a,)) + a = 3 # Break here + +if __name__ == '__main__': + method() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_settrace.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_settrace.py new file mode 100644 index 0000000..6090089 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_settrace.py @@ -0,0 +1,26 @@ +def ask_for_stop(use_back): + import pydevd + if use_back: + pydevd.settrace(stop_at_frame=sys._getframe().f_back) + else: + pydevd.settrace() + print('Will stop here if use_back==False.') + + +def outer_method(): + ask_for_stop(True) + print('will stop here.') + ask_for_stop(False) + + +if __name__ == '__main__': + import os + import sys + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + outer_method() + print('TEST SUCEEDED!') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_simple_calls.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_simple_calls.py new file mode 100644 index 0000000..323deda --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_simple_calls.py @@ -0,0 +1,18 @@ +def Method1(): + print('m1') + print('m1') + +def Method1a(): + print('m1a') + print('m1a') + +def Method2(): + print('m2 before') + Method1() + Method1a() + print('m2 after') + + +if __name__ == '__main__': + Method2() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_skip_breakpoint_in_exceptions.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_skip_breakpoint_in_exceptions.py new file mode 100644 index 0000000..fca9a9e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_skip_breakpoint_in_exceptions.py @@ -0,0 +1,8 @@ +if __name__ == '__main__': + for i in range(2): + print("one") + try: + raise AttributeError() # Breakpoint here + except: + pass + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_source_mapping.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_source_mapping.py new file mode 100644 index 0000000..d557148 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_source_mapping.py @@ -0,0 +1,31 @@ +def full_function(): + # Note that this function is not called, it's there just to make the mapping explicit. + a = 1 # map to cell1, line 2 + b = 2 # map to cell1, line 3 + + c = 3 # map to cell2, line 2 + d = 4 # map to cell2, line 3 + + +def create_code(): + cell1_code = compile(''' # line 1 +a = 1 # line 2 +b = 2 # line 3 +''', '', 'exec') + + cell2_code = compile('''# line 1 +c = 3 # line 2 +d = 4 # line 3 +''', '', 'exec') + + return {'cell1': cell1_code, 'cell2': cell2_code} + + +if __name__ == '__main__': + code = create_code() + exec(code['cell1']) + exec(code['cell1']) + + exec(code['cell2']) + exec(code['cell2']) + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_source_reference.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_source_reference.py new file mode 100644 index 0000000..84ba89b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_source_reference.py @@ -0,0 +1,32 @@ +def foo(): + return 1 # breakpoint + + +def main(): + import linecache + import time + + code = 'foo()' + + # Intermediate stack frame will have no source. + eval(code) + + co_filename = '' + co = compile(code, co_filename, 'exec') + + # Set up the source in linecache. Python doesn't have a public API for + # this, so we have to hack around it, similar to what IPython does. + linecache.cache[co_filename] = ( + len(code), + time.time(), + [line + '\n' for line in code.splitlines()], + co_filename, + ) + + # Intermediate stack frame will have source. + eval(co) + + +if __name__ == '__main__': + main() + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_stepping.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_stepping.py new file mode 100644 index 0000000..2abfbea --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_stepping.py @@ -0,0 +1,19 @@ +def step_over(): + print("don't step here") + +def step_into(): + print('step into') + +def step_out(): + print('step out') # Break here 1 + print("don't step here") + +def Call(): + step_over() # Break here 2 + step_into() + step_out() + print('stepped out') + +if __name__ == '__main__': + Call() + print('TEST SUCEEDED!') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_suspend_all.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_suspend_all.py new file mode 100644 index 0000000..f02ce7a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_suspend_all.py @@ -0,0 +1,33 @@ +import time +import threading + + +class ProceedContainer: + tid_to_proceed = { + 1: False, + 2: False, + } + + +def exit_while_loop(tid): + ProceedContainer.tid_to_proceed[tid] = True + return 'ok' + + +def thread_func(tid): + while not ProceedContainer.tid_to_proceed[tid]: # The debugger should change the proceed to True to exit the loop. + time.sleep(.1) + + +if __name__ == '__main__': + threads = [ + threading.Thread(target=thread_func, args=(1,)), + threading.Thread(target=thread_func, args=(2,)), + ] + for t in threads: + t.start() + + for t in threads: + t.join() + + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_suspend_policy.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_suspend_policy.py new file mode 100644 index 0000000..dfb5ed3 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_suspend_policy.py @@ -0,0 +1,29 @@ +import threading + +semaphore1 = threading.Semaphore(0) +proceed = False + + +def thread_target(): + semaphore1.release() + import time + + while True: + if proceed: + break + time.sleep(1 / 30.) + + +for i in range(2): + t = threading.Thread(target=thread_target) + t.start() + +semaphore1.acquire() # let first thread run +semaphore1.acquire() # let second thread run + +# At this point we know both other threads are already running. +print('break here') + +proceed = True + +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_sysexit.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_sysexit.py new file mode 100644 index 0000000..53738bd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_sysexit.py @@ -0,0 +1,9 @@ +import sys + + +def main(): + print('TEST SUCEEDED!') + sys.exit(1) + + +main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_sysexit_0.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_sysexit_0.py new file mode 100644 index 0000000..61f11c7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_sysexit_0.py @@ -0,0 +1,9 @@ +import sys + + +def main(): + print('TEST SUCEEDED!') + sys.exit(0) + + +main() # call_main_line diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_thread_creation_deadlock.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_thread_creation_deadlock.py new file mode 100644 index 0000000..b437d9c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_thread_creation_deadlock.py @@ -0,0 +1,26 @@ +from threading import Thread, Event + + +def create_thread(): + event = Event() + event_set = [False] + + def run_thread(): + event_set[0] = True + event.set() + + t = Thread(target=run_thread) + t.start() + + try: + event.wait(5) + + # note: not using `assert event.wait(5)` for py2.6 compatibility. + assert event_set[0] + print('TEST SUCEEDED!') + return 'create_thread:ok' + except: + import traceback;traceback.print_exc() + + +a = 10 # Add breakpoint here and evaluate create_thread() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_thread_started_exited.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_thread_started_exited.py new file mode 100644 index 0000000..7c89502 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_thread_started_exited.py @@ -0,0 +1,18 @@ +import threading + + +class MyThread(threading.Thread): + + def run(self): + pass + + +threads = [MyThread() for i in range(3)] + +for t in threads: + t.start() + +for t in threads: + t.join() + +print('TEST SUCEEDED!') # Break here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_trace_dispatch.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_trace_dispatch.py new file mode 100644 index 0000000..6a89f0d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_trace_dispatch.py @@ -0,0 +1,18 @@ +import sys + + +def method(): + a = 10 # add breakpoint + b = 20 + c = 30 + d = 40 + f_trace = sys._getframe().f_trace + if sys.version_info[:2] == (2,6) and f_trace.__name__ == 'NO_FTRACE': + print('TEST SUCEEDED') + elif f_trace is None: + print('TEST SUCEEDED') + else: + raise AssertionError('frame.f_trace is expected to be None at this point. Found: %s' % (f_trace,)) + + +method() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_tracing.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_tracing.py new file mode 100644 index 0000000..ab9dc89 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_tracing.py @@ -0,0 +1,14 @@ + +a = 1 +b = 2 +c = 3 + + +def foo(): + a = 1 + b = 2 + c = 3 + + +foo() +print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_type_ext.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_type_ext.py new file mode 100644 index 0000000..4a9b694 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_type_ext.py @@ -0,0 +1,8 @@ +class Rect(object): + def __init__(self, l, w): + super(Rect, self).__init__() + self.length = l + self.width = w +my_rect=Rect(5, 10) +print('TEST SUCEEDED!') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exception_get_stack.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exception_get_stack.py new file mode 100644 index 0000000..e013693 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exception_get_stack.py @@ -0,0 +1,12 @@ +from contextlib import contextmanager + + +@contextmanager +def something(): + yield + + +with something(): + raise ValueError('TEST SUCEEDED') # break line on unhandled exception + print('a') + print('b') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions.py new file mode 100644 index 0000000..57e17d6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions.py @@ -0,0 +1,47 @@ +import threading, atexit, sys +import time + +try: + from thread import start_new_thread +except: + from _thread import start_new_thread + + +def _atexit(): + print('TEST SUCEEDED') + sys.stderr.write('TEST SUCEEDED\n') + sys.stderr.flush() + sys.stdout.flush() + + +# Register the TEST SUCEEDED msg to the exit of the process. +atexit.register(_atexit) + + +def thread_func(): + raise Exception('in thread 1') + + +start_new_thread(thread_func, ()) + +# Wait for the first to be handled... otherwise, tests can become flaky if +# both stop at the same time only 1 notification may be given for both, whereas +# the test expects 2 notifications. +time.sleep(.5) + + +def thread_func2(n): + raise ValueError('in thread 2') + + +th = threading.Thread(target=lambda: thread_func2(1)) +th.setDaemon(True) +th.start() + +th.join() + +# This is a bit tricky: although we waited on the event, there's a slight chance +# that we didn't get the notification because the thread could've stopped executing, +# so, sleep a bit so that the test does not become flaky. +time.sleep(.5) +raise IndexError('in main') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_custom.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_custom.py new file mode 100644 index 0000000..a0b5f71 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_custom.py @@ -0,0 +1,53 @@ +import threading, atexit, sys +import time + +try: + from thread import start_new_thread +except: + from _thread import start_new_thread + + +class MyError(Exception): + + def __init__(self, msg): + return Exception.__init__(self) + + +def _atexit(): + print('TEST SUCEEDED') + sys.stderr.write('TEST SUCEEDED\n') + sys.stderr.flush() + sys.stdout.flush() + + +# Register the TEST SUCEEDED msg to the exit of the process. +atexit.register(_atexit) + + +def thread_func(): + raise MyError('in thread 1') + + +start_new_thread(thread_func, ()) + +# Wait for the first to be handled... otherwise, tests can become flaky if +# both stop at the same time only 1 notification may be given for both, whereas +# the test expects 2 notifications. +time.sleep(.5) + + +def thread_func2(n): + raise MyError('in thread 2') + + +th = threading.Thread(target=lambda: thread_func2(1)) +th.setDaemon(True) +th.start() + +th.join() + +# This is a bit tricky: although we waited on the event, there's a slight chance +# that we didn't get the notification because the thread could've stopped executing, +# so, sleep a bit so that the test does not become flaky. +time.sleep(.5) +raise MyError('in main') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_on_top_level.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_on_top_level.py new file mode 100644 index 0000000..8e2ce4a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_on_top_level.py @@ -0,0 +1 @@ +raise ValueError('TEST SUCEEDED') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_on_top_level2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_on_top_level2.py new file mode 100644 index 0000000..68b40cc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_unhandled_exceptions_on_top_level2.py @@ -0,0 +1,6 @@ +try: + raise ValueError('foobar') +except ValueError: + pass + +raise ValueError('TEST SUCEEDED') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_wait_for_attach.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_wait_for_attach.py new file mode 100644 index 0000000..c09922d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_wait_for_attach.py @@ -0,0 +1,50 @@ +if __name__ == '__main__': + import os + import sys + import time + port = int(sys.argv[1]) + root_dirname = os.path.dirname(os.path.dirname(__file__)) + + if root_dirname not in sys.path: + sys.path.append(root_dirname) + + import pydevd + try: + pydevd._wait_for_attach() # Cannot be called before _enable_attach. + except AssertionError: + pass + else: + raise AssertionError('Expected _wait_for_attach to raise exception.') + + assert sys.gettrace() is None + print('enable attach to port: %s' % (port,)) + pydevd._enable_attach(('127.0.0.1', port)) + pydevd._enable_attach(('127.0.0.1', port)) # no-op in practice + + try: + pydevd._enable_attach(('127.0.0.1', port + 15)) # different port: raise error. + except AssertionError: + pass + else: + raise AssertionError('Expected _enable_attach to raise exception (because it is already hearing in another port).') + + assert pydevd.get_global_debugger() is not None + assert sys.gettrace() is not None + + a = 10 # Break 1 + print('wait for attach') + pydevd._wait_for_attach() + print('finished wait for attach') + pydevd._wait_for_attach() # Should promptly return (already connected). + + a = 20 # Break 2 + + pydevd._wait_for_attach() # As we disconnected on the 2nd break, this one should wait until a new configurationDone. + + a = 20 # Break 3 + + while a == 20: # Pause 1 + # The debugger should disconnect/reconnect, pause and then change 'a' to another value. + time.sleep(1 / 20.) # Pause 2 + + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_zip_files.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_zip_files.py new file mode 100644 index 0000000..8445684 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_debugger_case_zip_files.py @@ -0,0 +1,17 @@ +from zipped import zipped_contents +try: + code = zipped_contents.call_in_zip.__code__ +except AttributeError: + code = zipped_contents.call_in_zip.func_code +assert 'myzip.zip' in code.co_filename +zipped_contents.call_in_zip() + +from zipped2 import zipped_contents2 +try: + code = zipped_contents2.call_in_zip2.__code__ +except AttributeError: + code = zipped_contents2.call_in_zip2.func_code +assert 'myzip2.egg!' in code.co_filename +zipped_contents2.call_in_zip2() + +print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_1.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_1.py new file mode 100644 index 0000000..8820d5a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_1.py @@ -0,0 +1,33 @@ +import time + +try: + xrange +except: + xrange = range + +def method2(): + i = 1 + +def method(): + + for i in xrange(200000): + method2() + + if False: + # Unreachable breakpoint here + pass + +def caller(): + start_time = time.time() + method() + print('TotalTime>>%s<<' % (time.time()-start_time,)) + +if __name__ == '__main__': + import sys + if '--regular-trace' in sys.argv: + def trace_dispatch(frame, event, arg): + return trace_dispatch + sys.settrace(trace_dispatch) + + caller() # Initial breakpoint for a step-over here + print('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_2.py new file mode 100644 index 0000000..90484cd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_2.py @@ -0,0 +1,28 @@ +import time +import sys +import itertools + +try: + xrange # @UndefinedVariable +except NameError: + xrange = range + +from itertools import groupby +count = itertools.count(0) +def next_val(): + return next(count) % 25 + +start_time = time.time() +letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + +# create an array of random strings of 40 characters each +l = sorted([''.join([letters[next_val()] for _ in range(40)]) for _ in xrange(10000)]) +# group by the first two characters +g = {k: list(v) for k, v in groupby(l, lambda x: x[:2])} + + +if False: + pass # Breakpoint here + +print('TotalTime>>%s<<' % (time.time()-start_time,)) +print('TEST SUCEEDED') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_3.py new file mode 100644 index 0000000..4ac1ece --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_performance_3.py @@ -0,0 +1,20 @@ +import time +start_time = time.time() + +try: + xrange # @UndefinedVariable +except NameError: + xrange = range + +# do some busy work in parallel +print("Started main task") +x = 0 +for i in xrange(1000000): + x += 1 +print("Completed main task") + +if False: + pass # Breakpoint here + +print('TotalTime>>%s<<' % (time.time()-start_time,)) +print('TEST SUCEEDED') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_cyrillic_encoding_py2.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_cyrillic_encoding_py2.py new file mode 100644 index 0000000..e56d5d0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_cyrillic_encoding_py2.py @@ -0,0 +1,8 @@ +# -*- coding: iso-8859-5 -*- + +# Ʋ³´µ¶ +class Dummy(object): + def Print(self): + print ('Ʋ³´µ¶') + +Dummy().Print() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_cyrillic_encoding_py3.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_cyrillic_encoding_py3.py new file mode 100644 index 0000000..f099c53 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_cyrillic_encoding_py3.py @@ -0,0 +1,8 @@ +# -*- coding: iso-8859-5 -*- + +# Ʋ³´µ¶ +class DummyƲ³´µ¶(object): + def Print(self): + print ('Ʋ³´µ¶') + +DummyƲ³´µ¶().Print() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_syntax_error.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_syntax_error.py new file mode 100644 index 0000000..6faf573 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydev_coverage_syntax_error.py @@ -0,0 +1,8 @@ +# -*- coding: iso-8859-5 -*- + +# Ʋ³´µ¶ +class Dummy(object): + def Print(self) + print ('Ʋ³´µ¶') + +Dummy().Print() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydevd_test_find_main_thread_id.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydevd_test_find_main_thread_id.py new file mode 100644 index 0000000..f78454f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/_pydevd_test_find_main_thread_id.py @@ -0,0 +1,159 @@ +# Note: this module should be self-contained to run tests (as it relies on `threading` not being +# imported and having no other threads running). + + +def wait_for_condition(condition, msg=None, timeout=5, sleep=.05): + import time + curtime = time.time() + while True: + if condition(): + break + if time.time() - curtime > timeout: + error_msg = 'Condition not reached in %s seconds' % (timeout,) + if msg is not None: + error_msg += '\n' + if callable(msg): + error_msg += msg() + else: + error_msg += str(msg) + + raise AssertionError('Timeout: %s' % (error_msg,)) + time.sleep(sleep) + + +def check_main_thread_id_simple(): + import attach_script + import sys + assert 'threading' not in sys.modules + try: + import thread + except ImportError: + import _thread as thread + + main_thread_id, log_msg = attach_script.get_main_thread_id(None) + assert main_thread_id == thread.get_ident(), 'Found: %s, Expected: %s' % (main_thread_id, thread.get_ident()) + assert not log_msg + assert 'threading' not in sys.modules + wait_for_condition(lambda: len(sys._current_frames()) == 1) + + +def check_main_thread_id_multiple_threads(): + import attach_script + import sys + import time + assert 'threading' not in sys.modules + try: + import thread + except ImportError: + import _thread as thread + + lock = thread.allocate_lock() + lock2 = thread.allocate_lock() + + def method(): + lock2.acquire() + with lock: + pass # Will only finish when lock is released. + + with lock: + thread.start_new_thread(method, ()) + while not lock2.locked(): + time.sleep(.1) + + wait_for_condition(lambda: len(sys._current_frames()) == 2) + + main_thread_id, log_msg = attach_script.get_main_thread_id(None) + assert main_thread_id == thread.get_ident(), 'Found: %s, Expected: %s' % (main_thread_id, thread.get_ident()) + assert not log_msg + assert 'threading' not in sys.modules + wait_for_condition(lambda: len(sys._current_frames()) == 1) + + +def check_fix_main_thread_id_multiple_threads(): + import attach_script + import sys + import time + assert 'threading' not in sys.modules + try: + import thread + except ImportError: + import _thread as thread + + lock = thread.allocate_lock() + lock2 = thread.allocate_lock() + + def method(): + lock2.acquire() + import threading # Note: imported on wrong thread + assert threading.current_thread().ident == thread.get_ident() + assert threading.current_thread() is attach_script.get_main_thread_instance(threading) + + attach_script.fix_main_thread_id() + + assert threading.current_thread().ident == thread.get_ident() + assert threading.current_thread() is not attach_script.get_main_thread_instance(threading) + + with lock: + pass # Will only finish when lock is released. + + with lock: + thread.start_new_thread(method, ()) + while not lock2.locked(): + time.sleep(.1) + + wait_for_condition(lambda: len(sys._current_frames()) == 2) + + main_thread_id, log_msg = attach_script.get_main_thread_id(None) + assert main_thread_id == thread.get_ident(), 'Found: %s, Expected: %s' % (main_thread_id, thread.get_ident()) + assert not log_msg + assert 'threading' in sys.modules + import threading + assert threading.current_thread().ident == main_thread_id + wait_for_condition(lambda: len(sys._current_frames()) == 1) + + +def check_win_threads(): + import sys + if sys.platform != 'win32': + return + + import attach_script + import time + assert 'threading' not in sys.modules + try: + import thread + except ImportError: + import _thread as thread + from ctypes import windll, WINFUNCTYPE, c_uint32, c_void_p, c_size_t + + ThreadProc = WINFUNCTYPE(c_uint32, c_void_p) + + lock = thread.allocate_lock() + lock2 = thread.allocate_lock() + + @ThreadProc + def method(_): + lock2.acquire() + with lock: + pass # Will only finish when lock is released. + return 0 + + with lock: + windll.kernel32.CreateThread(None, c_size_t(0), method, None, c_uint32(0), None) + while not lock2.locked(): + time.sleep(.1) + + wait_for_condition(lambda: len(sys._current_frames()) == 2) + + main_thread_id, log_msg = attach_script.get_main_thread_id(None) + assert main_thread_id == thread.get_ident(), 'Found: %s, Expected: %s' % (main_thread_id, thread.get_ident()) + assert not log_msg + assert 'threading' not in sys.modules + wait_for_condition(lambda: len(sys._current_frames()) == 1) + + +if __name__ == '__main__': + check_main_thread_id_simple() + check_main_thread_id_multiple_threads() + check_win_threads() + check_fix_main_thread_id_multiple_threads() # Important: must be the last test checked! diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch/foo/__main__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch/foo/__main__.py new file mode 100644 index 0000000..f29131e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch/foo/__main__.py @@ -0,0 +1,6 @@ +import sys +if '--as-module' in sys.argv: + from . import bar +else: + import bar +print('Worked') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch/foo/bar.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch/foo/bar.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/__main__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/__main__.py new file mode 100644 index 0000000..f29131e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/__main__.py @@ -0,0 +1,6 @@ +import sys +if '--as-module' in sys.argv: + from . import bar +else: + import bar +print('Worked') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/bar.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/launch_py2/foo/bar.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code.py new file mode 100644 index 0000000..8d0e8f7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code.py @@ -0,0 +1,15 @@ +if __name__ == '__main__': + import sys + import os + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + + from not_my_code import other + + def callback2(): + return 'my code2' + + def callback1(): + other.call_me_back2(callback2) # first step into my code + + other.call_me_back1(callback1) # break here + print('TEST SUCEEDED!') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code_exception.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code_exception.py new file mode 100644 index 0000000..7ec8013 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code_exception.py @@ -0,0 +1,14 @@ +if __name__ == '__main__': + import sys + import os + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + + from not_my_code import other + + def callback2(): + raise RuntimeError('TEST SUCEEDED!') + + def callback1(): + other.call_me_back2(callback2) + + other.call_me_back1(callback1) # break here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code_exception_on_other.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code_exception_on_other.py new file mode 100644 index 0000000..0d82dc9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/my_code/my_code_exception_on_other.py @@ -0,0 +1,14 @@ +if __name__ == '__main__': + import sys + import os + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + + from not_my_code import other + + def callback2(): + other.raise_exception() + + def callback1(): + other.call_me_back2(callback2) + + other.call_me_back1(callback1) # break here diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/not_my_code/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/not_my_code/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/not_my_code/other.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/not_my_code/other.py new file mode 100644 index 0000000..574575d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/resources/not_my_code/other.py @@ -0,0 +1,14 @@ +def call_me_back2(callback): + a = 'other' + callback() + return a + + +def call_me_back1(callback): + a = 'other' + callback() + return a + + +def raise_exception(): + raise RuntimeError('TEST SUCEEDED') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_additional_thread_info.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_additional_thread_info.py new file mode 100644 index 0000000..bb69c6b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_additional_thread_info.py @@ -0,0 +1,85 @@ +import sys +import os +from _pydev_bundle import pydev_monkey +sys.path.insert(0, os.path.split(os.path.split(__file__)[0])[0]) + +import unittest + +try: + import thread +except: + import _thread as thread # @UnresolvedImport + +try: + xrange +except: + xrange = range + +#======================================================================================================================= +# TestCase +#======================================================================================================================= +class TestCase(unittest.TestCase): + + def test_start_new_thread(self): + pydev_monkey.patch_thread_modules() + try: + found = {} + def function(a, b, *args, **kwargs): + found['a'] = a + found['b'] = b + found['args'] = args + found['kwargs'] = kwargs + thread.start_new_thread(function, (1,2,3,4), {'d':1, 'e':2}) + import time + for _i in xrange(20): + if len(found) == 4: + break + time.sleep(.1) + else: + raise AssertionError('Could not get to condition before 2 seconds') + + self.assertEqual({'a': 1, 'b': 2, 'args': (3, 4), 'kwargs': {'e': 2, 'd': 1}}, found) + finally: + pydev_monkey.undo_patch_thread_modules() + + + def test_start_new_thread2(self): + pydev_monkey.patch_thread_modules() + try: + found = {} + + class F(object): + start_new_thread = thread.start_new_thread + + def start_it(self): + try: + self.start_new_thread(self.function, (1,2,3,4), {'d':1, 'e':2}) + except: + import traceback;traceback.print_exc() + + def function(self, a, b, *args, **kwargs): + found['a'] = a + found['b'] = b + found['args'] = args + found['kwargs'] = kwargs + + f = F() + f.start_it() + import time + for _i in xrange(20): + if len(found) == 4: + break + time.sleep(.1) + else: + raise AssertionError('Could not get to condition before 2 seconds') + + self.assertEqual({'a': 1, 'b': 2, 'args': (3, 4), 'kwargs': {'e': 2, 'd': 1}}, found) + finally: + pydev_monkey.undo_patch_thread_modules() + + +#======================================================================================================================= +# main +#======================================================================================================================= +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_bytecode_modification.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_bytecode_modification.py new file mode 100644 index 0000000..aca6a6d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_bytecode_modification.py @@ -0,0 +1,592 @@ +import dis +import sys +import unittest +from io import StringIO +import pytest + +from _pydevd_frame_eval.pydevd_modify_bytecode import insert_code +from opcode import EXTENDED_ARG +from tests_python.debugger_unittest import IS_PYPY +from _pydevd_bundle.pydevd_constants import IS_PY37_OR_GREATER + +TRACE_MESSAGE = "Trace called" + + +def tracing(): + print(TRACE_MESSAGE) + + +def call_tracing(): + return tracing() + + +def bar(a, b): + return a + b + + +IS_PY36 = sys.version_info[0] == 3 and sys.version_info[1] >= 6 + + +@pytest.mark.skipif(not IS_PY36 or IS_PYPY, reason='Test requires Python 3.6 onwards') +class TestInsertCode(unittest.TestCase): + lines_separator = "---Line tested---" + + def check_insert_every_line(self, func_to_modify, func_to_insert, number_of_lines): + first_line = func_to_modify.__code__.co_firstlineno + 1 + last_line = first_line + number_of_lines + for i in range(first_line, last_line): + self.check_insert_to_line_with_exec(func_to_modify, func_to_insert, i) + print(self.lines_separator) + + def check_insert_to_line_with_exec(self, func_to_modify, func_to_insert, line_number): + code_orig = func_to_modify.__code__ + code_to_insert = func_to_insert.__code__ + success, result = insert_code(code_orig, code_to_insert, line_number) + exec(result) + output = sys.stdout.getvalue().strip().split(self.lines_separator)[-1] + self.assertTrue(TRACE_MESSAGE in output) + + def check_insert_to_line_by_symbols(self, func_to_modify, func_to_insert, line_number, code_for_check): + code_orig = func_to_modify.__code__ + code_to_insert = func_to_insert.__code__ + success, result = insert_code(code_orig, code_to_insert, line_number) + self.compare_bytes_sequence(list(result.co_code), list(code_for_check.co_code), len(code_to_insert.co_code)) + + def compare_bytes_sequence(self, code1, code2, inserted_code_size): + """ + Compare code after modification and the real code + Since we add POP_JUMP_IF_TRUE instruction, we can't compare modified code and the real code. That's why we + allow some inaccuracies while code comparison + :param code1: result code after modification + :param code2: a real code for checking + :param inserted_code_size: size of inserted code + """ + seq1 = [(offset, op, arg) for offset, op, arg in dis._unpack_opargs(code1)] + seq2 = [(offset, op, arg) for offset, op, arg in dis._unpack_opargs(code2)] + assert len(seq1) == len(seq2), "Bytes sequences have different lengths %s != %s" % (len(seq1), len(seq2)) + for i in range(len(seq1)): + of, op1, arg1 = seq1[i] + _, op2, arg2 = seq2[i] + if op1 != op2: + if op1 == 115 and op2 == 1: + # it's ok, because we added POP_JUMP_IF_TRUE manually, but it's POP_TOP in the real code + # inserted code - 2 (removed return instruction) - real code inserted + # Jump should be done to the beginning of inserted fragment + self.assertEqual(arg1, of - (inserted_code_size - 2)) + continue + elif op1 == EXTENDED_ARG and op2 == 12: + # we added a real UNARY_NOT to balance EXTENDED_ARG added by new jump instruction + # i.e. inserted code size was increased as well + inserted_code_size += 2 + continue + + self.assertEqual(op1, op2, "Different operators at offset {}".format(of)) + if arg1 != arg2: + if op1 in (100, 101, 106, 116): + # Sometimes indexes of variable names and consts may be different, when we insert them, it's ok + continue + else: + self.assertEqual(arg1, arg2, "Different arguments at offset {}".format(of)) + + def test_line(self): + + def foo(): + global global_loaded + global_loaded() + + def method(): + a = 10 + b = 20 + c = 20 + + success, result = insert_code(method.__code__, foo.__code__, method.__code__.co_firstlineno + 1) + assert success + assert list(result.co_lnotab) == [10, 1, 4, 1, 4, 1] + + success, result = insert_code(method.__code__, foo.__code__, method.__code__.co_firstlineno + 2) + assert success + assert list(result.co_lnotab) == [0, 1, 14, 1, 4, 1] + + success, result = insert_code(method.__code__, foo.__code__, method.__code__.co_firstlineno + 3) + assert success + assert list(result.co_lnotab) == [0, 1, 4, 1, 14, 1] + + def test_assignment(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + a = 1 + b = 2 + c = 3 + + self.check_insert_every_line(original, tracing, 3) + + finally: + sys.stdout = self.original_stdout + + def test_for_loop(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + n = 3 + sum = 0 + for i in range(n): + sum += i + return sum + + self.check_insert_every_line(original, tracing, 5) + + finally: + sys.stdout = self.original_stdout + + def test_if(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + if True: + a = 1 + else: + a = 0 + print(a) + + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 2) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 5) + + finally: + sys.stdout = self.original_stdout + + def test_else(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + if False: + a = 1 + else: + a = 0 + print(a) + + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 4) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 5) + + finally: + sys.stdout = self.original_stdout + + def test_for_else(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + sum = 0 + for i in range(3): + sum += i + else: + print(sum) + + def check_line_1(): + tracing() + sum = 0 + for i in range(3): + sum += i + else: + print(sum) + + def check_line_3(): + sum = 0 + for i in range(3): + tracing() + sum += i + else: + print(sum) + + def check_line_5(): + sum = 0 + for i in range(3): + sum += i + else: + tracing() + print(sum) + + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 1) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 3) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 5) + + sys.stdout = self.original_stdout + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 1, + check_line_1.__code__) + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 3, + check_line_3.__code__) + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 5, + check_line_5.__code__) + + finally: + sys.stdout = self.original_stdout + + def test_elif(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + a = 5 + b = 0 + if a < 0: + print("a < 0") + elif a < 3: + print("a < 3") + else: + print("a >= 3") + b = a + return b + + def check_line_1(): + tracing() + a = 5 + b = 0 + if a < 0: + print("a < 0") + elif a < 3: + print("a < 3") + else: + print("a >= 3") + b = a + return b + + def check_line_8(): + a = 5 + b = 0 + if a < 0: + print("a < 0") + elif a < 3: + print("a < 3") + else: + tracing() + print("a >= 3") + b = a + return b + + def check_line_9(): + a = 5 + b = 0 + if a < 0: + print("a < 0") + elif a < 3: + print("a < 3") + else: + print("a >= 3") + tracing() + b = a + return b + + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 1) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 2) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 8) + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 9) + + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 1, + check_line_1.__code__) + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 8, + check_line_8.__code__) + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 9, + check_line_9.__code__) + + finally: + sys.stdout = self.original_stdout + + def test_call_other_function(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def original(): + a = 1 + b = 3 + c = bar(a, b) + return c + + def check_line_3(): + a = 1 + b = 3 + tracing() + c = bar(a, b) + return c + + def check_line_4(): + a = 1 + b = 3 + c = bar(a, b) + tracing() + return c + + self.check_insert_every_line(original, tracing, 4) + sys.stdout = self.original_stdout + + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 3, + check_line_3.__code__) + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 4, + check_line_4.__code__) + + finally: + sys.stdout = self.original_stdout + + def test_class_method(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + class A(object): + + @staticmethod + def foo(): + print("i'm in foo") + + @staticmethod + def check_line_2(): + tracing() + print("i'm in foo") + + original = A.foo + self.check_insert_to_line_with_exec(original, tracing, original.__code__.co_firstlineno + 2) + + self.check_insert_to_line_by_symbols(original, call_tracing, original.__code__.co_firstlineno + 2, + A.check_line_2.__code__) + + finally: + sys.stdout = self.original_stdout + + def test_offset_overflow(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def foo(): + a = 1 + b = 2 # breakpoint + c = 3 + a1 = 1 if a > 1 else 2 + a2 = 1 if a > 1 else 2 + a3 = 1 if a > 1 else 2 + a4 = 1 if a > 1 else 2 + a5 = 1 if a > 1 else 2 + a6 = 1 if a > 1 else 2 + a7 = 1 if a > 1 else 2 + a8 = 1 if a > 1 else 2 + a9 = 1 if a > 1 else 2 + a10 = 1 if a > 1 else 2 + a11 = 1 if a > 1 else 2 + a12 = 1 if a > 1 else 2 + a13 = 1 if a > 1 else 2 + + for i in range(1): + if a > 0: + print("111") + # a = 1 + else: + print("222") + return b + + def check_line_2(): + a = 1 + tracing() + b = 2 + c = 3 + a1 = 1 if a > 1 else 2 + a2 = 1 if a > 1 else 2 + a3 = 1 if a > 1 else 2 + a4 = 1 if a > 1 else 2 + a5 = 1 if a > 1 else 2 + a6 = 1 if a > 1 else 2 + a7 = 1 if a > 1 else 2 + a8 = 1 if a > 1 else 2 + a9 = 1 if a > 1 else 2 + a10 = 1 if a > 1 else 2 + a11 = 1 if a > 1 else 2 + a12 = 1 if a > 1 else 2 + a13 = 1 if a > 1 else 2 + + for i in range(1): + if a > 0: + print("111") + # a = 1 + else: + print("222") + return b + + self.check_insert_to_line_with_exec(foo, tracing, foo.__code__.co_firstlineno + 2) + + self.check_insert_to_line_by_symbols(foo, call_tracing, foo.__code__.co_firstlineno + 2, + check_line_2.__code__) + + finally: + sys.stdout = self.original_stdout + + def test_long_lines(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def foo(): + a = 1 + b = 1 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + c = 1 if b > 1 else 2 if b > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + d = 1 if c > 1 else 2 if c > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + e = d + 1 + return e + + def check_line_2(): + a = 1 + tracing() + b = 1 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + c = 1 if b > 1 else 2 if b > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + d = 1 if c > 1 else 2 if c > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + e = d + 1 + return e + + self.check_insert_to_line_with_exec(foo, tracing, foo.__code__.co_firstlineno + 2) + sys.stdout = self.original_stdout + + self.check_insert_to_line_by_symbols(foo, call_tracing, foo.__code__.co_firstlineno + 2, + check_line_2.__code__) + + finally: + sys.stdout = self.original_stdout + + def test_many_names(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + from tests_python.resources._bytecode_many_names_example import foo + self.check_insert_to_line_with_exec(foo, tracing, foo.__code__.co_firstlineno + 2) + + finally: + sys.stdout = self.original_stdout + + @pytest.mark.skipif(IS_PY37_OR_GREATER, reason='It seems a new minor release of CPython 3.7 broke this (needs to be investigated).') + def test_extended_arg_overflow(self): + + from tests_python.resources._bytecode_overflow_example import Dummy, DummyTracing + self.check_insert_to_line_by_symbols(Dummy.fun, call_tracing, Dummy.fun.__code__.co_firstlineno + 3, + DummyTracing.fun.__code__) + + def test_double_extended_arg(self): + self.original_stdout = sys.stdout + sys.stdout = StringIO() + + try: + + def foo(): + a = 1 + b = 2 + if b > 0: + d = a + b + d += 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + a = a + 1 + return a + + def foo_check(): + a = 1 + b = 2 + tracing() + if b > 0: + d = a + b + d += 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + a = a + 1 + return a + + def foo_check_2(): + a = 1 + b = 2 + if b > 0: + d = a + b + d += 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + not tracing() # add 'not' to balance EXTENDED_ARG when jumping + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + b = b - 1 if a > 0 else b + 1 + a = a + 1 + return a + + self.check_insert_to_line_with_exec(foo, tracing, foo.__code__.co_firstlineno + 2) + sys.stdout = self.original_stdout + + self.check_insert_to_line_by_symbols(foo, call_tracing, foo.__code__.co_firstlineno + 3, + foo_check.__code__) + + self.check_insert_to_line_by_symbols(foo, call_tracing, foo.__code__.co_firstlineno + 21, + foo_check_2.__code__) + + finally: + sys.stdout = self.original_stdout diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info.py new file mode 100644 index 0000000..8ed413d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info.py @@ -0,0 +1,263 @@ +from io import StringIO +import os.path +import sys +import traceback + +from _pydevd_bundle.pydevd_collect_try_except_info import collect_try_except_info +from tests_python.debugger_unittest import IS_CPYTHON, IS_PYPY + + +def _method_call_with_error(): + try: + _method_reraise() + except: + raise + + +def _method_except_local(): + Foo = AssertionError + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except Foo as exc: + # DUP_TOP, LOAD_FAST (x), COMPARE_OP (exception match), POP_JUMP_IF_FALSE + pass + + +def _method_reraise(): + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except AssertionError as e: # POP_TOP + raise e + + +def _method_return_with_error(): + _method_call_with_error() + + +def _method_return_with_error2(): + try: + _method_call_with_error() + except: + return + + +def _method_simple_raise_any_except(): + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except: # POP_TOP + pass + + +def _method_simple_raise_any_except_return_on_raise(): + # Note how the tracing the debugger has is equal to the tracing from _method_simple_raise_any_except + # but this one resulted in an unhandled exception while the other one didn't. + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except: # POP_TOP + raise # RAISE_VARARGS + + +def _method_simple_raise_local_load(): + x = AssertionError + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except x as exc: + # DUP_TOP, LOAD_GLOBAL (NameError), LOAD_GLOBAL(AssertionError), BUILD_TUPLE, + # COMPARE_OP (exception match), POP_JUMP_IF_FALSE + pass + + +def _method_simple_raise_multi_except(): + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except (NameError, AssertionError) as exc: + # DUP_TOP, LOAD_FAST (x), COMPARE_OP (exception match), POP_JUMP_IF_FALSE + pass + + +def _method_simple_raise_unmatched_except(): + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except NameError: # DUP_TOP, LOAD_GLOBAL (NameError), COMPARE_OP (exception match), POP_JUMP_IF_FALSE + pass + + +def _method_try_except(): + try: # SETUP_EXCEPT (to except line) + try: # SETUP_EXCEPT (to except line) + raise AssertionError() + except: # POP_TOP + raise + except: # POP_TOP + return ( + 1, + 2 + ) + + +class _Tracer(object): + + def __init__(self, partial_info=False): + self.partial_info = partial_info + self.stream = StringIO() + self._in_print = False + + def tracer_printer(self, frame, event, arg): + if self._in_print: + return None + self._in_print = True + try: + if arg is not None: + if event == 'exception': + arg = arg[0].__name__ + elif arg is not None: + arg = str(arg) + if arg is None: + arg = '' + + if self.partial_info: + s = ' '.join(( + os.path.basename(frame.f_code.co_filename), + event.upper() if event != 'line' else event, + arg, + )) + else: + s = ' '.join(( + str(frame.f_lineno), + frame.f_code.co_name, + os.path.basename(frame.f_code.co_filename), + event.upper() if event != 'line' else event, + arg, + )) + self.writeln(s) + except: + traceback.print_exc() + self._in_print = False + return self.tracer_printer + + def writeln(self, s): + self.write(s) + self.write('\n') + + def write(self, s): + if isinstance(s, bytes): + s = s.decode('utf-8') + self.stream.write(s) + + def call(self, c): + sys.settrace(self.tracer_printer) + try: + c() + except: + pass + sys.settrace(None) + return self.stream.getvalue() + + +import pytest + + +@pytest.mark.skipif(not IS_CPYTHON, reason='CPython only test.') +def test_collect_try_except_info(data_regression): + method_to_info = {} + for key, method in sorted(dict(globals()).items()): + if key.startswith('_method'): + info = collect_try_except_info(method.__code__, use_func_first_line=True) + + if sys.version_info[:2] >= (3, 7): + for try_except_info in info: + # On 3.7 the last bytecode actually has a different start line. + if try_except_info.except_end_line == 8: + try_except_info.except_end_line = 9 + + method_to_info[key] = [str(x) for x in info] + + data_regression.check(method_to_info) + + +def test_collect_try_except_info2(): + + def method(): + try: + raise AssertionError + except: + _a = 10 + raise + finally: + _b = 20 + _c = 20 + + code = method.__code__ + lst = collect_try_except_info(code, use_func_first_line=True) + if IS_CPYTHON or IS_PYPY: + assert str(lst) == '[{try:1 except 3 end block 5 raises: 5}]' + else: + assert lst == [] + + +def _create_entry(instruction): + argval = instruction.argval + return dict( + opname=instruction.opname, + argval=argval, + starts_line=instruction.starts_line, + is_jump_target=instruction.is_jump_target, + ) + + +def debug_test_iter_bytecode(data_regression): + # Note: not run by default, only to help visualizing bytecode and comparing differences among versions. + import dis + + basename = 'test_iter_bytecode.py%s%s' % (sys.version_info[:2]) + method_to_info = {} + for key, method in sorted(dict(globals()).items()): + if key.startswith('_method'): + info = [] + + if sys.version_info[0] < 3: + from _pydevd_bundle.pydevd_collect_try_except_info import _iter_as_bytecode_as_instructions_py2 + iter_in = _iter_as_bytecode_as_instructions_py2(method.__code__) + else: + iter_in = dis.Bytecode(method) + + for instruction in iter_in: + info.append(_create_entry(instruction)) + + msg = [] + for d in info: + line = [] + for k, v in sorted(d.items()): + line.append(u'%s=%s' % (k, v)) + msg.append(u' '.join(line)) + if isinstance(key, bytes): + key = key.decode('utf-8') + method_to_info[key] = msg + + data_regression.check(method_to_info, basename=basename) + + +def debug_test_tracing_output(): # Note: not run by default, only to debug tracing. + from collections import defaultdict + output_to_method_names = defaultdict(list) + for key, val in sorted(dict(globals()).items()): + if key.startswith('_method'): + tracer = _Tracer(partial_info=False) + output_to_method_names[tracer.call(val)].append(val.__name__) + + # Notes: + # + # Seen as the same by the tracing (so, we inspect the bytecode to disambiguate). + # _method_simple_raise_any_except + # _method_simple_raise_any_except_return_on_raise + # _method_simple_raise_multi_except + # + # The return with an exception is always None + # + # It's not possible to disambiguate from a return None, pass or raise just with the tracing + # (only a raise with an exception is gotten by the debugger). + for output, method_names in sorted(output_to_method_names.items(), key=lambda x:(-len(x[1]), ''.join(x[1]))): + print('=' * 80) + print(' %s ' % (', '.join(method_names),)) + print('=' * 80) + print(output) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_collect_try_except_info.json b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_collect_try_except_info.json new file mode 100644 index 0000000..bb54b9a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_collect_try_except_info.json @@ -0,0 +1,34 @@ +{ + "_method_call_with_error": [ + "{try:1 except 3 end block 4 raises: 4}" + ], + "_method_except_local": [ + "{try:2 except 4 end block 6}" + ], + "_method_reraise": [ + "{try:1 except 3 end block 4}" + ], + "_method_return_with_error": [], + "_method_return_with_error2": [ + "{try:1 except 3 end block 4}" + ], + "_method_simple_raise_any_except": [ + "{try:1 except 3 end block 4}" + ], + "_method_simple_raise_any_except_return_on_raise": [ + "{try:3 except 5 end block 6 raises: 6}" + ], + "_method_simple_raise_local_load": [ + "{try:2 except 4 end block 7}" + ], + "_method_simple_raise_multi_except": [ + "{try:1 except 3 end block 5}" + ], + "_method_simple_raise_unmatched_except": [ + "{try:1 except 3 end block 4}" + ], + "_method_try_except": [ + "{try:2 except 4 end block 5 raises: 5}", + "{try:1 except 6 end block 9 raises: 5}" + ] +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py26.json b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py26.json new file mode 100644 index 0000000..7013d74 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py26.json @@ -0,0 +1,210 @@ +{ + "_method_call_with_error": [ + "argval=14 is_jump_target=False opname=SETUP_EXCEPT starts_line=11", + "argval=_method_reraise is_jump_target=False opname=LOAD_GLOBAL starts_line=12", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=13", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=14", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_except_local": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=18", + "argval=Foo is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=22 is_jump_target=False opname=SETUP_EXCEPT starts_line=19", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=20", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=21", + "argval=Foo is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=23", + "argval=None is_jump_target=True opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_reraise": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=27", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=28", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=29", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=e is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=e is_jump_target=False opname=LOAD_FAST starts_line=30", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error": [ + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=34", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error2": [ + "argval=14 is_jump_target=False opname=SETUP_EXCEPT starts_line=38", + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=39", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=22 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=40", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=41", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=45", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=46", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=23 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=47", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=23 is_jump_target=False opname=JUMP_FORWARD starts_line=48", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except_return_on_raise": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=54", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=55", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=56", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=57", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_local_load": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=61", + "argval=x is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=22 is_jump_target=False opname=SETUP_EXCEPT starts_line=62", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=63", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=64", + "argval=x is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=67", + "argval=None is_jump_target=True opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_multi_except": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=71", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=72", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=73", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=2 is_jump_target=False opname=BUILD_TUPLE starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=43 is_jump_target=False opname=JUMP_FORWARD starts_line=75", + "argval=None is_jump_target=True opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_unmatched_except": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=79", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=80", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=35 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=81", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=33 is_jump_target=False opname=JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=35 is_jump_target=False opname=JUMP_FORWARD starts_line=82", + "argval=None is_jump_target=True opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_try_except": [ + "argval=33 is_jump_target=False opname=SETUP_EXCEPT starts_line=86", + "argval=19 is_jump_target=False opname=SETUP_EXCEPT starts_line=87", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=88", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=29 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=89", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=90", + "argval=29 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=POP_BLOCK starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=91", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=(1, 2) is_jump_target=False opname=LOAD_CONST starts_line=94", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ] +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py27.json b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py27.json new file mode 100644 index 0000000..f4657b1 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py27.json @@ -0,0 +1,200 @@ +{ + "_method_call_with_error": [ + "argval=14 is_jump_target=False opname=SETUP_EXCEPT starts_line=11", + "argval=_method_reraise is_jump_target=False opname=LOAD_GLOBAL starts_line=12", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=13", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=14", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_except_local": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=18", + "argval=Foo is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=22 is_jump_target=False opname=SETUP_EXCEPT starts_line=19", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=20", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=21", + "argval=Foo is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=40 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=23", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_reraise": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=27", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=28", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=29", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=40 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=e is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=e is_jump_target=False opname=LOAD_FAST starts_line=30", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error": [ + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=34", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error2": [ + "argval=14 is_jump_target=False opname=SETUP_EXCEPT starts_line=38", + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=39", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=22 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=40", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=41", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=45", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=46", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=23 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=47", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=23 is_jump_target=False opname=JUMP_FORWARD starts_line=48", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except_return_on_raise": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=54", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=55", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=56", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=57", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_local_load": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=61", + "argval=x is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=22 is_jump_target=False opname=SETUP_EXCEPT starts_line=62", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=63", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=64", + "argval=x is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=40 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=67", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_multi_except": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=71", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=72", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=73", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=2 is_jump_target=False opname=BUILD_TUPLE starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=40 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=75", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_unmatched_except": [ + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=79", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=80", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=33 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=81", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=32 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=33 is_jump_target=False opname=JUMP_FORWARD starts_line=82", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_try_except": [ + "argval=33 is_jump_target=False opname=SETUP_EXCEPT starts_line=86", + "argval=19 is_jump_target=False opname=SETUP_EXCEPT starts_line=87", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=88", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=29 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=89", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=90", + "argval=29 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=POP_BLOCK starts_line=None", + "argval=41 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=91", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=(1, 2) is_jump_target=False opname=LOAD_CONST starts_line=94", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ] +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py36.json b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py36.json new file mode 100644 index 0000000..9e6aea6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py36.json @@ -0,0 +1,235 @@ +{ + "_method_call_with_error": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=11", + "argval=_method_reraise is_jump_target=False opname=LOAD_GLOBAL starts_line=12", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=13", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=14", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_except_local": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=18", + "argval=Foo is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=19", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=20", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=21", + "argval=Foo is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=38 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=23", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=exc is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_reraise": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=27", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=28", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=29", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=e is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=38 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=e is_jump_target=False opname=LOAD_FAST starts_line=30", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=e is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=e is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error": [ + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=34", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error2": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=38", + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=39", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=22 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=40", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=41", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=45", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=46", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=47", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=48", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except_return_on_raise": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=54", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=55", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=56", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=57", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_local_load": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=61", + "argval=x is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=62", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=63", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=64", + "argval=x is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=38 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=67", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=exc is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_multi_except": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=71", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=72", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=73", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=2 is_jump_target=False opname=BUILD_TUPLE starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=38 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=75", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=exc is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_unmatched_except": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=79", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=80", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=32 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=81", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=30 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=82", + "argval=32 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_try_except": [ + "argval=32 is_jump_target=False opname=SETUP_EXCEPT starts_line=86", + "argval=14 is_jump_target=False opname=SETUP_EXCEPT starts_line=87", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=88", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=28 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=89", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=90", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=28 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=POP_BLOCK starts_line=None", + "argval=42 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=91", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=(1, 2) is_jump_target=False opname=LOAD_CONST starts_line=94", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ] +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py37.json b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py37.json new file mode 100644 index 0000000..bef46a7 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_collect_try_except_info/test_iter_bytecode.py37.json @@ -0,0 +1,235 @@ +{ + "_method_call_with_error": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=11", + "argval=_method_reraise is_jump_target=False opname=LOAD_GLOBAL starts_line=12", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=13", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=14", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_except_local": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=18", + "argval=Foo is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=19", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=20", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=21", + "argval=Foo is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=36 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=23", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=exc is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_reraise": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=27", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=28", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=29", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=e is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=36 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=e is_jump_target=False opname=LOAD_FAST starts_line=30", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=e is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=e is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error": [ + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=34", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_return_with_error2": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=38", + "argval=_method_call_with_error is_jump_target=False opname=LOAD_GLOBAL starts_line=39", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=22 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=40", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=41", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=45", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=46", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=47", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=48", + "argval=24 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_any_except_return_on_raise": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=54", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=55", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=56", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=57", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=26 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_local_load": [ + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=61", + "argval=x is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=16 is_jump_target=False opname=SETUP_EXCEPT starts_line=62", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=63", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=64", + "argval=x is_jump_target=False opname=LOAD_FAST starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=36 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=67", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=exc is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_multi_except": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=71", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=72", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=73", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=2 is_jump_target=False opname=BUILD_TUPLE starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=48 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=36 is_jump_target=False opname=SETUP_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=75", + "argval=None is_jump_target=False opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=exc is_jump_target=False opname=STORE_FAST starts_line=None", + "argval=exc is_jump_target=False opname=DELETE_FAST starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=50 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_simple_raise_unmatched_except": [ + "argval=12 is_jump_target=False opname=SETUP_EXCEPT starts_line=79", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=80", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=32 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=DUP_TOP starts_line=81", + "argval=NameError is_jump_target=False opname=LOAD_GLOBAL starts_line=None", + "argval=exception match is_jump_target=False opname=COMPARE_OP starts_line=None", + "argval=30 is_jump_target=False opname=POP_JUMP_IF_FALSE starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=82", + "argval=32 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ], + "_method_try_except": [ + "argval=32 is_jump_target=False opname=SETUP_EXCEPT starts_line=86", + "argval=14 is_jump_target=False opname=SETUP_EXCEPT starts_line=87", + "argval=AssertionError is_jump_target=False opname=LOAD_GLOBAL starts_line=88", + "argval=0 is_jump_target=False opname=CALL_FUNCTION starts_line=None", + "argval=1 is_jump_target=False opname=RAISE_VARARGS starts_line=None", + "argval=None is_jump_target=False opname=POP_BLOCK starts_line=None", + "argval=28 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=89", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=0 is_jump_target=False opname=RAISE_VARARGS starts_line=90", + "argval=None is_jump_target=False opname=POP_EXCEPT starts_line=None", + "argval=28 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=False opname=END_FINALLY starts_line=None", + "argval=None is_jump_target=True opname=POP_BLOCK starts_line=None", + "argval=42 is_jump_target=False opname=JUMP_FORWARD starts_line=None", + "argval=None is_jump_target=True opname=POP_TOP starts_line=91", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=None is_jump_target=False opname=POP_TOP starts_line=None", + "argval=(1, 2) is_jump_target=False opname=LOAD_CONST starts_line=93", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None", + "argval=None is_jump_target=True opname=LOAD_CONST starts_line=None", + "argval=None is_jump_target=False opname=RETURN_VALUE starts_line=None" + ] +} \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_console.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_console.py new file mode 100644 index 0000000..dccd938 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_console.py @@ -0,0 +1,205 @@ +from contextlib import contextmanager + +import pytest + +from _pydev_bundle.pydev_override import overrides +from tests_python.debugger_fixtures import DebuggerRunnerSimple +from tests_python.debugger_unittest import AbstractWriterThread, SHOW_OTHER_DEBUG_INFO, \ + start_in_daemon_thread, wait_for_condition, IS_JYTHON +from _pydev_bundle.pydev_localhost import get_socket_names, get_socket_name +from _pydev_bundle.pydev_imports import xmlrpclib +from _pydev_bundle.pydev_imports import _queue as queue +from _pydev_bundle.pydev_imports import SimpleXMLRPCServer +import time +import socket +from tests_python.debug_constants import IS_PY2 + +if IS_PY2: + builtin_qualifier = "__builtin__" +else: + builtin_qualifier = "builtins" + + +@pytest.fixture +def console_setup(): + + server_queue = queue.Queue() + + def notify_finished(more): + server_queue.put(('notify_finished', more)) + return '' + + class ConsoleRunner(DebuggerRunnerSimple): + + @overrides(DebuggerRunnerSimple.add_command_line_args) + def add_command_line_args(self, args): + port, client_port = get_socket_names(2, close=True) + args.extend(( + writer.get_pydevconsole_file(), + str(port[1]), + str(client_port[1]) + )) + self.port = port + self.client_port = client_port + + server = SimpleXMLRPCServer(client_port) + server.register_function(notify_finished, "NotifyFinished") + start_in_daemon_thread(server.serve_forever, []) + + self.proxy = xmlrpclib.ServerProxy("http://%s:%s/" % port) + + return args + + class WriterThread(AbstractWriterThread): + + if IS_JYTHON: + EXPECTED_RETURNCODE = 'any' + + @overrides(AbstractWriterThread.additional_output_checks) + def additional_output_checks(self, stdout, stderr): + print('output found: %s - %s' % (stdout, stderr)) + + @overrides(AbstractWriterThread.write_dump_threads) + def write_dump_threads(self): + pass # no-op (may be called on timeout). + + def execute_line(self, command, more=False): + runner.proxy.execLine(command) + assert server_queue.get(timeout=5.) == ('notify_finished', more) + + def hello(self): + + def _hello(): + try: + msg = runner.proxy.hello('ignored') + if msg is not None: + if isinstance(msg, (list, tuple)): + msg = next(iter(msg)) + if msg.lower().startswith('hello'): + return True + except: + # That's ok, communication still not ready. + pass + + return False + + wait_for_condition(_hello) + + def close(self): + try: + runner.proxy.close() + except: + # Ignore any errors on close. + pass + + def connect_to_debugger(self, debugger_port): + runner.proxy.connectToDebugger(debugger_port) + + runner = ConsoleRunner() + writer = WriterThread() + + class CaseSetup(object): + + @contextmanager + def check_console( + self, + **kwargs + ): + for key, value in kwargs.items(): + assert hasattr(WriterThread, key) + setattr(WriterThread, key, value) + + self.writer = writer + + args = runner.get_command_line() + + args = runner.add_command_line_args(args) + + if SHOW_OTHER_DEBUG_INFO: + print('executing: %s' % (' '.join(args),)) + try: + with runner.run_process(args, writer) as dct_with_stdout_stder: + writer.get_stdout = lambda: ''.join(dct_with_stdout_stder['stdout']) + writer.get_stderr = lambda: ''.join(dct_with_stdout_stder['stderr']) + + # Make sure communication is setup. + writer.hello() + yield writer + finally: + writer.log = [] + + stdout = dct_with_stdout_stder['stdout'] + stderr = dct_with_stdout_stder['stderr'] + writer.additional_output_checks(''.join(stdout), ''.join(stderr)) + + return CaseSetup() + + +def test_console_simple(console_setup): + with console_setup.check_console() as writer: + writer.execute_line('a = 10') + writer.execute_line('print("TEST SUCEEDED")') + writer.close() + writer.finished_ok = True + + +def test_console_debugger_connected(console_setup): + + class _DebuggerWriterThread(AbstractWriterThread): + + FORCE_KILL_PROCESS_WHEN_FINISHED_OK = True + + def __init__(self): + AbstractWriterThread.__init__(self) + socket_name = get_socket_name(close=True) + server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server_socket.bind(socket_name) + server_socket.listen(1) + self.port = socket_name[1] + self.__server_socket = server_socket + + def run(self): + print('waiting for second process') + self.sock, addr = self.__server_socket.accept() + print('accepted second process') + + from tests_python.debugger_unittest import ReaderThread + self.reader_thread = ReaderThread(self.sock) + self.reader_thread.start() + + self._sequence = -1 + # initial command is always the version + self.write_version() + self.log.append('start_socket') + self.write_make_initial_run() + time.sleep(1) + + seq = self.write_list_threads() + msg = self.wait_for_list_threads(seq) + assert msg.thread['name'] == 'MainThread' + assert msg.thread['id'] == 'console_main' + + self.write_get_frame('console_main', '1') + self.wait_for_vars([ + [ + '') == '' + real_case = pydevd_file_utils.get_path_with_real_case(normalized) + assert isinstance(real_case, str) # bytes on py2, unicode on py3 + # Note test_dir itself cannot be compared with because pytest may + # have passed the case normalized. + assert real_case.endswith("Test_Convert_Utilities") + + if i == 2: + # Check that we have the expected paths in the cache. + assert pydevd_file_utils._listdir_cache[os.path.dirname(normalized).lower()] == ['Test_Convert_Utilities'] + assert pydevd_file_utils._listdir_cache[(os.path.dirname(normalized).lower(), 'Test_Convert_Utilities'.lower())] == real_case + + if IS_PY2: + # Test with unicode in python 2 too. + real_case = pydevd_file_utils.get_path_with_real_case(normalized.decode( + getfilesystemencoding())) + assert isinstance(real_case, str) # bytes on py2, unicode on py3 + # Note test_dir itself cannot be compared with because pytest may + # have passed the case normalized. + assert real_case.endswith("Test_Convert_Utilities") + + # Check that it works with a shortened path. + shortened = pydevd_file_utils.convert_to_short_pathname(normalized) + assert '~' in shortened + with_real_case = pydevd_file_utils.get_path_with_real_case(shortened) + assert with_real_case.endswith('Test_Convert_Utilities') + assert '~' not in with_real_case + + else: + # On other platforms, nothing should change + assert pydevd_file_utils.normcase(test_dir) == test_dir + assert pydevd_file_utils.get_path_with_real_case(test_dir) == test_dir + + +def test_source_reference(tmpdir): + import pydevd_file_utils + + pydevd_file_utils.set_ide_os('WINDOWS') + if IS_WINDOWS: + # Client and server are on windows. + pydevd_file_utils.setup_client_server_paths([('c:\\foo', 'c:\\bar')]) + + assert pydevd_file_utils.norm_file_to_client('c:\\bar\\my') == 'c:\\foo\\my' + assert pydevd_file_utils.get_client_filename_source_reference('c:\\foo\\my') == 0 + + assert pydevd_file_utils.norm_file_to_client('c:\\another\\my') == 'c:\\another\\my' + source_reference = pydevd_file_utils.get_client_filename_source_reference('c:\\another\\my') + assert source_reference != 0 + assert pydevd_file_utils.get_server_filename_from_source_reference(source_reference) == 'c:\\another\\my' + + else: + # Client on windows and server on unix + pydevd_file_utils.set_ide_os('WINDOWS') + + pydevd_file_utils.setup_client_server_paths([('c:\\foo', '/bar')]) + + assert pydevd_file_utils.norm_file_to_client('/bar/my') == 'c:\\foo\\my' + assert pydevd_file_utils.get_client_filename_source_reference('c:\\foo\\my') == 0 + + assert pydevd_file_utils.norm_file_to_client('/another/my') == '\\another\\my' + source_reference = pydevd_file_utils.get_client_filename_source_reference('\\another\\my') + assert source_reference != 0 + assert pydevd_file_utils.get_server_filename_from_source_reference(source_reference) == '/another/my' + + +def test_to_server_and_to_client(tmpdir): + try: + + def check(obtained, expected): + assert obtained == expected, '%s (%s) != %s (%s)' % (obtained, type(obtained), expected, type(expected)) + assert isinstance(obtained, str) # bytes on py2, unicode on py3 + assert isinstance(expected, str) # bytes on py2, unicode on py3 + + import pydevd_file_utils + if IS_WINDOWS: + # Check with made-up files + + pydevd_file_utils.setup_client_server_paths([('c:\\foo', 'c:\\bar'), ('c:\\foo2', 'c:\\bar2')]) + + stream = io.StringIO() + with log_context(0, stream=stream): + pydevd_file_utils.norm_file_to_server('y:\\only_exists_in_client_not_in_server') + assert r'pydev debugger: unable to find translation for: "y:\only_exists_in_client_not_in_server" in ["c:\foo", "c:\foo2"] (please revise your path mappings).' in stream.getvalue() + + # Client and server are on windows. + pydevd_file_utils.set_ide_os('WINDOWS') + for in_eclipse, in_python in ([ + ('c:\\foo', 'c:\\bar'), + ('c:/foo', 'c:\\bar'), + ('c:\\foo', 'c:/bar'), + ('c:\\foo', 'c:\\bar\\'), + ('c:/foo', 'c:\\bar\\'), + ('c:\\foo', 'c:/bar/'), + ('c:\\foo\\', 'c:\\bar'), + ('c:/foo/', 'c:\\bar'), + ('c:\\foo\\', 'c:/bar'), + + ]): + PATHS_FROM_ECLIPSE_TO_PYTHON = [ + (in_eclipse, in_python) + ] + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + check(pydevd_file_utils.norm_file_to_server('c:\\foo\\my'), 'c:\\bar\\my') + check(pydevd_file_utils.norm_file_to_server('c:/foo/my'), 'c:\\bar\\my') + check(pydevd_file_utils.norm_file_to_server('c:/foo/my/'), 'c:\\bar\\my') + check(pydevd_file_utils.norm_file_to_server('c:\\foo\\áéíóú'.upper()), 'c:\\bar\\áéíóú') + check(pydevd_file_utils.norm_file_to_client('c:\\bar\\my'), 'c:\\foo\\my') + + # Client on unix and server on windows + pydevd_file_utils.set_ide_os('UNIX') + for in_eclipse, in_python in ([ + ('/foo', 'c:\\bar'), + ('/foo', 'c:/bar'), + ('/foo', 'c:\\bar\\'), + ('/foo', 'c:/bar/'), + ('/foo/', 'c:\\bar'), + ('/foo/', 'c:\\bar\\'), + ]): + + PATHS_FROM_ECLIPSE_TO_PYTHON = [ + (in_eclipse, in_python) + ] + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + check(pydevd_file_utils.norm_file_to_server('/foo/my'), 'c:\\bar\\my') + check(pydevd_file_utils.norm_file_to_client('c:\\bar\\my'), '/foo/my') + check(pydevd_file_utils.norm_file_to_client('c:\\bar\\my\\'), '/foo/my') + check(pydevd_file_utils.norm_file_to_client('c:/bar/my'), '/foo/my') + check(pydevd_file_utils.norm_file_to_client('c:/bar/my/'), '/foo/my') + + # Test with 'real' files + # Client and server are on windows. + pydevd_file_utils.set_ide_os('WINDOWS') + + test_dir = str(tmpdir.mkdir("Foo")) + os.makedirs(os.path.join(test_dir, "Another")) + + in_eclipse = os.path.join(os.path.dirname(test_dir), 'Bar') + in_python = test_dir + PATHS_FROM_ECLIPSE_TO_PYTHON = [ + (in_eclipse, in_python) + ] + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + + assert pydevd_file_utils.norm_file_to_server(in_eclipse) == in_python.lower() + found_in_eclipse = pydevd_file_utils.norm_file_to_client(in_python) + assert found_in_eclipse.endswith('Bar') + + assert pydevd_file_utils.norm_file_to_server( + os.path.join(in_eclipse, 'another')) == os.path.join(in_python, 'another').lower() + found_in_eclipse = pydevd_file_utils.norm_file_to_client( + os.path.join(in_python, 'another')) + assert found_in_eclipse.endswith('Bar\\Another') + + # Client on unix and server on windows + pydevd_file_utils.set_ide_os('UNIX') + in_eclipse = '/foo' + in_python = test_dir + PATHS_FROM_ECLIPSE_TO_PYTHON = [ + (in_eclipse, in_python) + ] + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + assert pydevd_file_utils.norm_file_to_server('/foo').lower() == in_python.lower() + assert pydevd_file_utils.norm_file_to_client(in_python) == in_eclipse + + # Test without translation in place (still needs to fix case and separators) + pydevd_file_utils.set_ide_os('WINDOWS') + PATHS_FROM_ECLIPSE_TO_PYTHON = [] + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + assert pydevd_file_utils.norm_file_to_server(test_dir) == test_dir.lower() + assert pydevd_file_utils.norm_file_to_client(test_dir).endswith('\\Foo') + else: + # Client on windows and server on unix + pydevd_file_utils.set_ide_os('WINDOWS') + for in_eclipse, in_python in ([ + ('c:\\foo', '/báéíóúr'), + ('c:/foo', '/báéíóúr'), + ('c:/foo/', '/báéíóúr'), + ('c:/foo/', '/báéíóúr/'), + ('c:\\foo\\', '/báéíóúr/'), + ]): + + PATHS_FROM_ECLIPSE_TO_PYTHON = [ + (in_eclipse, in_python) + ] + + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + assert pydevd_file_utils.norm_file_to_server('c:\\foo\\my') == '/báéíóúr/my' + assert pydevd_file_utils.norm_file_to_server('C:\\foo\\my') == '/báéíóúr/my' + assert pydevd_file_utils.norm_file_to_server('C:\\foo\\MY') == '/báéíóúr/MY' + assert pydevd_file_utils.norm_file_to_server('C:\\foo\\MY\\') == '/báéíóúr/MY' + assert pydevd_file_utils.norm_file_to_server('c:\\foo\\my\\file.py') == '/báéíóúr/my/file.py' + assert pydevd_file_utils.norm_file_to_server('c:\\foo\\my\\other\\file.py') == '/báéíóúr/my/other/file.py' + assert pydevd_file_utils.norm_file_to_server('c:/foo/my') == '/báéíóúr/my' + assert pydevd_file_utils.norm_file_to_server('c:\\foo\\my\\') == '/báéíóúr/my' + assert pydevd_file_utils.norm_file_to_server('c:/foo/my/') == '/báéíóúr/my' + + assert pydevd_file_utils.norm_file_to_client('/báéíóúr/my') == 'c:\\foo\\my' + assert pydevd_file_utils.norm_file_to_client('/báéíóúr/my/') == 'c:\\foo\\my' + + # Files for which there's no translation have only their separators updated. + assert pydevd_file_utils.norm_file_to_client('/usr/bin/x.py') == '\\usr\\bin\\x.py' + assert pydevd_file_utils.norm_file_to_client('/usr/bin') == '\\usr\\bin' + assert pydevd_file_utils.norm_file_to_client('/usr/bin/') == '\\usr\\bin' + assert pydevd_file_utils.norm_file_to_server('\\usr\\bin') == '/usr/bin' + assert pydevd_file_utils.norm_file_to_server('\\usr\\bin\\') == '/usr/bin' + + # When we have a client file and there'd be no translation, and making it absolute would + # do something as '$cwd/$file_received' (i.e.: $cwd/c:/another in the case below), + # warn the user that it's not correct and the path that should be translated instead + # and don't make it absolute. + assert pydevd_file_utils.norm_file_to_server('c:\\another') == 'c:/another' + + # Client and server on unix + pydevd_file_utils.set_ide_os('UNIX') + in_eclipse = '/foo' + in_python = '/báéíóúr' + PATHS_FROM_ECLIPSE_TO_PYTHON = [ + (in_eclipse, in_python) + ] + pydevd_file_utils.setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) + assert pydevd_file_utils.norm_file_to_server('/foo/my') == '/báéíóúr/my' + assert pydevd_file_utils.norm_file_to_client('/báéíóúr/my') == '/foo/my' + finally: + pydevd_file_utils.setup_client_server_paths([]) + + +def test_zip_paths(tmpdir): + import pydevd_file_utils + import sys + import zipfile + + for i, zip_basename in enumerate(('MY1.zip', 'my2.egg!')): + zipfile_path = str(tmpdir.join(zip_basename)) + zip_file = zipfile.ZipFile(zipfile_path, 'w') + zip_file.writestr('zipped%s/__init__.py' % (i,), '') + zip_file.writestr('zipped%s/zipped_contents.py' % (i,), 'def call_in_zip():\n return 1') + zip_file.close() + + sys.path.append(zipfile_path) + try: + import importlib + except ImportError: + __import__('zipped%s' % (i,)) # Py2.6 does not have importlib + else: + importlib.import_module('zipped%s' % (i,)) # Check that it's importable. + + # Check that we can deal with the zip path. + assert pydevd_file_utils.exists(zipfile_path) + abspath, realpath, basename = pydevd_file_utils.get_abs_path_real_path_and_base_from_file(zipfile_path) + if IS_WINDOWS: + assert abspath == zipfile_path.lower() + assert basename == zip_basename.lower() + else: + assert abspath == zipfile_path + assert basename == zip_basename + + # Check that we can deal with zip contents. + for path in [ + zipfile_path + '/zipped%s/__init__.py' % (i,), + zipfile_path + '/zipped%s/zipped_contents.py' % (i,), + zipfile_path + '\\zipped%s\\__init__.py' % (i,), + zipfile_path + '\\zipped%s\\zipped_contents.py' % (i,), + ]: + assert pydevd_file_utils.exists(path), 'Expected exists to return True for path:\n%s' % (path,) + abspath, realpath, basename = pydevd_file_utils.get_abs_path_real_path_and_base_from_file(path) + assert pydevd_file_utils.exists(abspath), 'Expected exists to return True for path:\n%s' % (abspath,) + assert pydevd_file_utils.exists(realpath), 'Expected exists to return True for path:\n%s' % (realpath,) + + assert zipfile_path in pydevd_file_utils._ZIP_SEARCH_CACHE, '%s not in %s' % ( + zipfile_path, '\n'.join(sorted(pydevd_file_utils._ZIP_SEARCH_CACHE.keys()))) + + +def test_source_mapping(): + + from _pydevd_bundle.pydevd_source_mapping import SourceMapping, SourceMappingEntry + source_mapping = SourceMapping() + mapping = [ + SourceMappingEntry(line=3, end_line=6, runtime_line=5, runtime_source=''), + SourceMappingEntry(line=10, end_line=11, runtime_line=1, runtime_source=''), + ] + source_mapping.set_source_mapping('file1.py', mapping) + + # Map to server + assert source_mapping.map_to_server('file1.py', 1) == ('file1.py', 1, False) + assert source_mapping.map_to_server('file1.py', 2) == ('file1.py', 2, False) + + assert source_mapping.map_to_server('file1.py', 3) == ('', 5, True) + assert source_mapping.map_to_server('file1.py', 4) == ('', 6, True) + assert source_mapping.map_to_server('file1.py', 5) == ('', 7, True) + assert source_mapping.map_to_server('file1.py', 6) == ('', 8, True) + + assert source_mapping.map_to_server('file1.py', 7) == ('file1.py', 7, False) + + assert source_mapping.map_to_server('file1.py', 10) == ('', 1, True) + assert source_mapping.map_to_server('file1.py', 11) == ('', 2, True) + + assert source_mapping.map_to_server('file1.py', 12) == ('file1.py', 12, False) + + # Map to client + assert source_mapping.map_to_client('file1.py', 1) == ('file1.py', 1, False) + assert source_mapping.map_to_client('file1.py', 2) == ('file1.py', 2, False) + + assert source_mapping.map_to_client('', 5) == ('file1.py', 3, True) + assert source_mapping.map_to_client('', 6) == ('file1.py', 4, True) + assert source_mapping.map_to_client('', 7) == ('file1.py', 5, True) + assert source_mapping.map_to_client('', 8) == ('file1.py', 6, True) + + assert source_mapping.map_to_client('file1.py', 7) == ('file1.py', 7, False) + + assert source_mapping.map_to_client('', 1) == ('file1.py', 10, True) + assert source_mapping.map_to_client('', 2) == ('file1.py', 11, True) + + assert source_mapping.map_to_client('file1.py', 12) == ('file1.py', 12, False) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_debugger.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_debugger.py new file mode 100644 index 0000000..6725232 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_debugger.py @@ -0,0 +1,3430 @@ +# coding: utf-8 +''' + The idea is that we record the commands sent to the debugger and reproduce them from this script + (so, this works as the client, which spawns the debugger as a separate process and communicates + to it as if it was run from the outside) + + Note that it's a python script but it'll spawn a process to run as jython, ironpython and as python. +''' +import time + +import pytest + +from tests_python import debugger_unittest +from tests_python.debugger_unittest import (CMD_SET_PROPERTY_TRACE, REASON_CAUGHT_EXCEPTION, + REASON_UNCAUGHT_EXCEPTION, REASON_STOP_ON_BREAKPOINT, REASON_THREAD_SUSPEND, overrides, CMD_THREAD_CREATE, + CMD_GET_THREAD_STACK, REASON_STEP_INTO_MY_CODE, CMD_GET_EXCEPTION_DETAILS, IS_IRONPYTHON, IS_JYTHON, IS_CPYTHON, + IS_APPVEYOR, wait_for_condition, CMD_GET_FRAME, CMD_GET_BREAKPOINT_EXCEPTION, + CMD_THREAD_SUSPEND, CMD_STEP_OVER, REASON_STEP_OVER, CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION, + CMD_THREAD_RESUME_SINGLE_NOTIFICATION, REASON_STEP_RETURN, REASON_STEP_RETURN_MY_CODE, + REASON_STEP_OVER_MY_CODE, REASON_STEP_INTO, CMD_THREAD_KILL, IS_PYPY) +from _pydevd_bundle.pydevd_constants import IS_WINDOWS +from _pydevd_bundle.pydevd_comm_constants import CMD_RELOAD_CODE +import json +import pydevd_file_utils +import subprocess +import threading +try: + from urllib import unquote +except ImportError: + from urllib.parse import unquote + +from tests_python.debug_constants import * # noqa + +pytest_plugins = [ + str('tests_python.debugger_fixtures'), +] + +try: + xrange +except: + xrange = range + +if IS_PY2: + builtin_qualifier = "__builtin__" +else: + builtin_qualifier = "builtins" + + +@pytest.mark.skipif(not IS_CPYTHON, reason='Test needs gc.get_referrers/reference counting to really check anything.') +def test_case_referrers(case_setup): + with case_setup.test_file('_debugger_case1.py') as writer: + writer.log.append('writing add breakpoint') + writer.write_add_breakpoint(6, 'set_up') + + writer.log.append('making initial run') + writer.write_make_initial_run() + + writer.log.append('waiting for breakpoint hit') + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.log.append('get frame') + writer.write_get_frame(thread_id, frame_id) + + writer.log.append('step over') + writer.write_step_over(thread_id) + + writer.log.append('get frame') + writer.write_get_frame(thread_id, frame_id) + + writer.log.append('run thread') + writer.write_run_thread(thread_id) + + writer.log.append('asserting') + try: + assert 13 == writer._sequence, 'Expected 13. Had: %s' % writer._sequence + except: + writer.log.append('assert failed!') + raise + writer.log.append('asserted') + + writer.finished_ok = True + + +def test_case_2(case_setup): + with case_setup.test_file('_debugger_case2.py') as writer: + writer.write_add_breakpoint(3, 'Call4') # seq = 3 + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.write_get_frame(thread_id, frame_id) # Note: write get frame but not waiting for it to be gotten. + + writer.write_add_breakpoint(14, 'Call2') + + writer.write_run_thread(thread_id) + + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.write_get_frame(thread_id, frame_id) # Note: write get frame but not waiting for it to be gotten. + + writer.write_run_thread(thread_id) + + writer.log.append('Checking sequence. Found: %s' % (writer._sequence)) + assert 15 == writer._sequence, 'Expected 15. Had: %s' % writer._sequence + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.parametrize( + 'skip_suspend_on_breakpoint_exception, skip_print_breakpoint_exception', + ( + [['NameError'], []], + [['NameError'], ['NameError']], + [[], []], # Empty means it'll suspend/print in any exception + [[], ['NameError']], + [['ValueError'], ['Exception']], + [['Exception'], ['ValueError']], # ValueError will also suspend/print since we're dealing with a NameError + ) +) +def test_case_breakpoint_condition_exc(case_setup, skip_suspend_on_breakpoint_exception, skip_print_breakpoint_exception): + + msgs_in_stderr = ( + 'Error while evaluating expression: i > 5', + 'Traceback (most recent call last):', + 'File "", line 1, in ', + ) + + # It could be one or the other in PyPy depending on the version. + msgs_one_in_stderr = ( + "NameError: name 'i' is not defined", + "global name 'i' is not defined", + ) + + def _ignore_stderr_line(line): + if original_ignore_stderr_line(line): + return True + + for msg in msgs_in_stderr + msgs_one_in_stderr: + if msg in line: + return True + + return False + + def additional_output_checks(stdout, stderr): + original_additional_output_checks(stdout, stderr) + if skip_print_breakpoint_exception in ([], ['ValueError']): + for msg in msgs_in_stderr: + assert msg in stderr + + for msg in msgs_one_in_stderr: + if msg in stderr: + break + else: + raise AssertionError('Did not find any of: %s in stderr: %s' % ( + msgs_one_in_stderr, stderr)) + else: + for msg in msgs_in_stderr + msgs_one_in_stderr: + assert msg not in stderr + + with case_setup.test_file('_debugger_case_breakpoint_condition_exc.py') as writer: + + original_ignore_stderr_line = writer._ignore_stderr_line + writer._ignore_stderr_line = _ignore_stderr_line + + original_additional_output_checks = writer.additional_output_checks + writer.additional_output_checks = additional_output_checks + + writer.write_suspend_on_breakpoint_exception(skip_suspend_on_breakpoint_exception, skip_print_breakpoint_exception) + breakpoint_id = writer.write_add_breakpoint( + writer.get_line_index_with_content('break here'), 'Call', condition='i > 5') + + writer.write_make_initial_run() + + if skip_suspend_on_breakpoint_exception in ([], ['ValueError']): + writer.wait_for_message(CMD_GET_BREAKPOINT_EXCEPTION) + hit = writer.wait_for_breakpoint_hit() + writer.write_run_thread(hit.thread_id) + + if IS_JYTHON: + # Jython will break twice. + if skip_suspend_on_breakpoint_exception in ([], ['ValueError']): + writer.wait_for_message(CMD_GET_BREAKPOINT_EXCEPTION) + hit = writer.wait_for_breakpoint_hit() + writer.write_run_thread(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.write_get_frame(thread_id, frame_id) + msg = writer.wait_for_message(CMD_GET_FRAME) + name_to_value = {} + for var in msg.var: + name_to_value[var['name']] = var['value'] + assert name_to_value == {'i': 'int: 6', 'last_i': 'int: 6'} + + writer.write_remove_breakpoint(breakpoint_id) + + writer.write_run_thread(thread_id) + + writer.finished_ok = True + + +def test_case_remove_breakpoint(case_setup): + with case_setup.test_file('_debugger_case_remove_breakpoint.py') as writer: + breakpoint_id = writer.write_add_breakpoint(writer.get_line_index_with_content('break here')) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit() + writer.write_remove_breakpoint(breakpoint_id) + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_case_double_remove_breakpoint(case_setup): + + with case_setup.test_file('_debugger_case_remove_breakpoint.py') as writer: + breakpoint_id = writer.write_add_breakpoint(writer.get_line_index_with_content('break here')) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit() + writer.write_remove_breakpoint(breakpoint_id) + writer.write_remove_breakpoint(breakpoint_id) # Double-remove (just check that we don't have an error). + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_IRONPYTHON, reason='This test fails once in a while due to timing issues on IronPython, so, skipping it.') +def test_case_3(case_setup): + with case_setup.test_file('_debugger_case3.py') as writer: + writer.write_make_initial_run() + time.sleep(.5) + breakpoint_id = writer.write_add_breakpoint(4, '') + writer.write_add_breakpoint(5, 'FuncNotAvailable') # Check that it doesn't get hit in the global when a function is available + + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.write_get_frame(thread_id, frame_id) + + writer.write_run_thread(thread_id) + + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.write_get_frame(thread_id, frame_id) + + writer.write_remove_breakpoint(breakpoint_id) + + writer.write_run_thread(thread_id) + + assert 17 == writer._sequence, 'Expected 17. Had: %s' % writer._sequence + + writer.finished_ok = True + + +def test_case_suspend_thread(case_setup): + with case_setup.test_file('_debugger_case4.py') as writer: + writer.write_make_initial_run() + + thread_id = writer.wait_for_new_thread() + + writer.write_suspend_thread(thread_id) + + while True: + hit = writer.wait_for_breakpoint_hit((REASON_THREAD_SUSPEND, REASON_STOP_ON_BREAKPOINT)) + if hit.name == 'sleep': + break # Ok, broke on 'sleep'. + else: + # i.e.: if it doesn't hit on 'sleep', release and pause again. + writer.write_run_thread(thread_id) + time.sleep(.1) + writer.write_suspend_thread(thread_id) + + assert hit.thread_id == thread_id + + writer.write_evaluate_expression('%s\t%s\t%s' % (hit.thread_id, hit.frame_id, 'LOCAL'), 'exit_while_loop()') + writer.wait_for_evaluation([ + [ + '%0A
'.format(builtin_qualifier), + '%0A%0A
'.format(builtin_qualifier), + '%0A%0A', # jython + ] + ]) + + writer.write_run_thread(hit.thread_id) + + assert 17 == writer._sequence, 'Expected 17. Had: %s' % writer._sequence + + writer.finished_ok = True + + +def test_case_8(case_setup): + with case_setup.test_file('_debugger_case89.py') as writer: + writer.write_add_breakpoint(10, 'Method3') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111') + + writer.write_step_return(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit('109', line=15) + + writer.write_run_thread(hit.thread_id) + + assert 9 == writer._sequence, 'Expected 9. Had: %s' % writer._sequence + + writer.finished_ok = True + + +def test_case_9(case_setup): + with case_setup.test_file('_debugger_case89.py') as writer: + writer.write_add_breakpoint(10, 'Method3') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111') + + # Note: no active exception (should not give an error and should return no + # exception details as there's no exception). + writer.write_get_current_exception(hit.thread_id) + + msg = writer.wait_for_message(CMD_GET_EXCEPTION_DETAILS) + assert msg.thread['id'] == hit.thread_id + assert not hasattr(msg.thread, 'frames') # No frames should be found. + + writer.write_step_over(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit('108', line=11) + + writer.write_step_over(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit('108', line=12) + + writer.write_run_thread(hit.thread_id) + + assert 13 == writer._sequence, 'Expected 13. Had: %s' % writer._sequence + + writer.finished_ok = True + + +def test_case_10(case_setup): + with case_setup.test_file('_debugger_case_simple_calls.py') as writer: + writer.write_add_breakpoint(2, 'None') # None or Method should make hit. + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111') + + writer.write_step_return(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit('109', line=11) + + writer.write_step_over(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit('108', line=12) + + writer.write_run_thread(hit.thread_id) + + assert 11 == writer._sequence, 'Expected 11. Had: %s' % writer._sequence + + writer.finished_ok = True + + +def test_case_11(case_setup): + with case_setup.test_file('_debugger_case_simple_calls.py') as writer: + writer.write_add_breakpoint(2, 'Method1') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT, line=2) + assert hit.name == 'Method1' + + writer.write_step_over(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(REASON_STEP_OVER, line=3) + assert hit.name == 'Method1' + + writer.write_step_over(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(REASON_STEP_INTO, line=12) # Reverts to step in + assert hit.name == 'Method2' + + writer.write_step_over(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(REASON_STEP_OVER, line=13) + assert hit.name == 'Method2' + + writer.write_step_over(hit.thread_id) + hit = writer.wait_for_breakpoint_hit(REASON_STEP_INTO, line=18) # Reverts to step in + assert hit.name == '' + + # Finish with a step over + writer.write_step_over(hit.thread_id) + + if IS_JYTHON: + # Jython got to the exit functions (CPython does it builtin, + # so we have no traces from Python). + hit = writer.wait_for_breakpoint_hit(REASON_STEP_INTO) # Reverts to step in + assert hit.name == '_run_exitfuncs' + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_case_12(case_setup): + with case_setup.test_file('_debugger_case_simple_calls.py') as writer: + writer.write_add_breakpoint(2, '') # Should not be hit: setting empty function (not None) should only hit global. + writer.write_add_breakpoint(6, 'Method1a') + writer.write_add_breakpoint(11, 'Method2') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111', line=11) + + writer.write_step_return(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit('111', line=6) # not a return (it stopped in the other breakpoint) + + writer.write_run_thread(hit.thread_id) + + assert 13 == writer._sequence, 'Expected 13. Had: %s' % writer._sequence + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_IRONPYTHON, reason='Failing on IronPython (needs to be investigated).') +def test_case_13(case_setup): + with case_setup.test_file('_debugger_case13.py') as writer: + + def _ignore_stderr_line(line): + if original_ignore_stderr_line(line): + return True + + if IS_JYTHON: + for expected in ( + "RuntimeWarning: Parent module '_pydevd_bundle' not found while handling absolute import", + "import __builtin__"): + if expected in line: + return True + + return False + + original_ignore_stderr_line = writer._ignore_stderr_line + writer._ignore_stderr_line = _ignore_stderr_line + + writer.write_add_breakpoint(35, 'main') + writer.write("%s\t%s\t%s" % (CMD_SET_PROPERTY_TRACE, writer.next_seq(), "true;false;false;true")) + writer.write_make_initial_run() + hit = writer.wait_for_breakpoint_hit('111') + + writer.write_get_frame(hit.thread_id, hit.frame_id) + + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('107', line=25) + # Should go inside setter method + + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('107') + + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('107', line=21) + # Should go inside getter method + + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('107') + + # Disable property tracing + writer.write("%s\t%s\t%s" % (CMD_SET_PROPERTY_TRACE, writer.next_seq(), "true;true;true;true")) + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('107', line=39) + # Should Skip step into properties setter + + # Enable property tracing + writer.write("%s\t%s\t%s" % (CMD_SET_PROPERTY_TRACE, writer.next_seq(), "true;false;false;true")) + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit('107', line=8) + # Should go inside getter method + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_case_14(case_setup): + # Interactive Debug Console + with case_setup.test_file('_debugger_case14.py') as writer: + writer.write_add_breakpoint(22, 'main') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111') + assert hit.thread_id, '%s not valid.' % hit.thread_id + assert hit.frame_id, '%s not valid.' % hit.frame_id + + # Access some variable + writer.write_debug_console_expression("%s\t%s\tEVALUATE\tcarObj.color" % (hit.thread_id, hit.frame_id)) + writer.wait_for_var(['False', '%27Black%27']) + assert 7 == writer._sequence, 'Expected 9. Had: %s' % writer._sequence + + # Change some variable + writer.write_debug_console_expression("%s\t%s\tEVALUATE\tcarObj.color='Red'" % (hit.thread_id, hit.frame_id)) + writer.write_debug_console_expression("%s\t%s\tEVALUATE\tcarObj.color" % (hit.thread_id, hit.frame_id)) + writer.wait_for_var(['False', '%27Red%27']) + assert 11 == writer._sequence, 'Expected 13. Had: %s' % writer._sequence + + # Iterate some loop + writer.write_debug_console_expression("%s\t%s\tEVALUATE\tfor i in range(3):" % (hit.thread_id, hit.frame_id)) + writer.wait_for_var(['True']) + writer.write_debug_console_expression("%s\t%s\tEVALUATE\t print(i)" % (hit.thread_id, hit.frame_id)) + writer.wait_for_var(['True']) + writer.write_debug_console_expression("%s\t%s\tEVALUATE\t" % (hit.thread_id, hit.frame_id)) + writer.wait_for_var( + [ + 'False' ] + ) + assert 17 == writer._sequence, 'Expected 19. Had: %s' % writer._sequence + + writer.write_run_thread(hit.thread_id) + writer.finished_ok = True + + +def test_case_15(case_setup): + with case_setup.test_file('_debugger_case15.py') as writer: + writer.write_add_breakpoint(22, 'main') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT) + + # Access some variable + writer.write_custom_operation("%s\t%s\tEXPRESSION\tcarObj.color" % (hit.thread_id, hit.frame_id), "EXEC", "f=lambda x: 'val=%s' % x", "f") + writer.wait_for_custom_operation('val=Black') + assert 7 == writer._sequence, 'Expected 7. Had: %s' % writer._sequence + + writer.write_custom_operation("%s\t%s\tEXPRESSION\tcarObj.color" % (hit.thread_id, hit.frame_id), "EXECFILE", debugger_unittest._get_debugger_test_file('_debugger_case15_execfile.py'), "f") + writer.wait_for_custom_operation('val=Black') + assert 9 == writer._sequence, 'Expected 9. Had: %s' % writer._sequence + + writer.write_run_thread(hit.thread_id) + writer.finished_ok = True + + +def test_case_16(case_setup): + # numpy.ndarray resolver + try: + import numpy + except ImportError: + pytest.skip('numpy not available') + with case_setup.test_file('_debugger_case16.py') as writer: + writer.write_add_breakpoint(9, 'main') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT) + + # In this test we check that the three arrays of different shapes, sizes and types + # are all resolved properly as ndarrays. + + # First pass check is that we have all three expected variables defined + writer.write_get_frame(hit.thread_id, hit.frame_id) + writer.wait_for_multiple_vars(( + ( + '', + '' + ), + + ( + '', + '' + ), + + # Any of the ones below will do. + ( + '', + '' + ) + )) + + # For each variable, check each of the resolved (meta data) attributes... + writer.write_get_variable(hit.thread_id, hit.frame_id, 'smallarray') + writer.wait_for_multiple_vars(( + ''.format(builtin_qualifier), + ''.format(builtin_qualifier), + ''.format(builtin_qualifier), + ''.format(builtin_qualifier), + ], + [ + ''.format(builtin_qualifier), + ''.format(builtin_qualifier), + ''.format(builtin_qualifier), + ''.format(builtin_qualifier), + ], + '%0A'.format(builtin_qualifier,)) + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_case_19(case_setup): + # Check evaluate '__' attributes + with case_setup.test_file('_debugger_case19.py') as writer: + writer.write_add_breakpoint(8, None) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT, line=8) + + writer.write_evaluate_expression('%s\t%s\t%s' % (hit.thread_id, hit.frame_id, 'LOCAL'), 'a.__var') + writer.wait_for_evaluation([ + [ + 'Hello' in contents + assert 'Flask-Jinja-Test' in contents + + writer.finished_ok = True + + +@pytest.mark.skipif(not TEST_DJANGO, reason='No django available') +def test_case_django_a(case_setup_django): + + def get_environ(writer): + env = os.environ.copy() + env.update({ + 'PYDEVD_FILTER_LIBRARIES': '1', # Global setting for in project or not + }) + return env + + with case_setup_django.test_file(EXPECTED_RETURNCODE='any', get_environ=get_environ) as writer: + writer.write_add_breakpoint_django(5, None, 'index.html') + writer.write_make_initial_run() + + t = writer.create_request_thread('my_app') + time.sleep(5) # Give django some time to get to startup before requesting the page + t.start() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT, line=5) + writer.write_get_variable(hit.thread_id, hit.frame_id, 'entry') + writer.wait_for_vars([ + '
  • v1:v1
  • v2:v2
  • ' % (contents,)) + + writer.finished_ok = True + + +@pytest.mark.skipif(not TEST_DJANGO, reason='No django available') +def test_case_django_b(case_setup_django): + with case_setup_django.test_file(EXPECTED_RETURNCODE='any') as writer: + writer.write_add_breakpoint_django(4, None, 'name.html') + writer.write_add_exception_breakpoint_django() + writer.write_remove_exception_breakpoint_django() + writer.write_make_initial_run() + + t = writer.create_request_thread('my_app/name') + time.sleep(5) # Give django some time to get to startup before requesting the page + t.start() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT, line=4) + + writer.write_get_frame(hit.thread_id, hit.frame_id) + writer.wait_for_var('' + thread_id3 = hit.thread_id + + # Requesting the stack in an unhandled exception should provide the stack of the exception, + # not the current location of the program. + writer.write_get_thread_stack(thread_id3) + msg = writer.wait_for_message(CMD_GET_THREAD_STACK) + assert len(msg.thread.frame) == 0 # In main thread (must have no back frames). + assert msg.thread.frame['name'] == '' + check(hit, 'IndexError', 'in main') + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Failing on Jython -- needs to be investigated).') +def test_unhandled_exceptions_in_top_level1(case_setup_unhandled_exceptions): + + with case_setup_unhandled_exceptions.test_file( + '_debugger_case_unhandled_exceptions_on_top_level.py', + EXPECTED_RETURNCODE=1, + ) as writer: + + writer.write_add_exception_breakpoint_with_policy('Exception', "0", "1", "0") + writer.write_make_initial_run() + + # Will stop in main thread + hit = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Failing on Jython -- needs to be investigated).') +def test_unhandled_exceptions_in_top_level2(case_setup_unhandled_exceptions): + # Note: expecting unhandled exception to be printed to stderr. + + def get_environ(writer): + env = os.environ.copy() + curr_pythonpath = env.get('PYTHONPATH', '') + + pydevd_dirname = os.path.dirname(writer.get_pydevd_file()) + + curr_pythonpath = pydevd_dirname + os.pathsep + curr_pythonpath + env['PYTHONPATH'] = curr_pythonpath + return env + + def update_command_line_args(writer, args): + # Start pydevd with '-m' to see how it deal with being called with + # runpy at the start. + assert args[0].endswith('pydevd.py') + args = ['-m', 'pydevd'] + args[1:] + return args + + with case_setup_unhandled_exceptions.test_file( + '_debugger_case_unhandled_exceptions_on_top_level.py', + get_environ=get_environ, + update_command_line_args=update_command_line_args, + EXPECTED_RETURNCODE='any', + ) as writer: + + writer.write_add_exception_breakpoint_with_policy('Exception', "0", "1", "0") + writer.write_make_initial_run() + + # Should stop (only once) in the main thread. + hit = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Failing on Jython -- needs to be investigated).') +def test_unhandled_exceptions_in_top_level3(case_setup_unhandled_exceptions): + + with case_setup_unhandled_exceptions.test_file( + '_debugger_case_unhandled_exceptions_on_top_level.py', + EXPECTED_RETURNCODE=1 + ) as writer: + + # Handled and unhandled + writer.write_add_exception_breakpoint_with_policy('Exception', "1", "1", "0") + writer.write_make_initial_run() + + # Will stop in main thread twice: once one we find that the exception is being + # thrown and another in postmortem mode when we discover it's uncaught. + hit = writer.wait_for_breakpoint_hit(REASON_CAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Failing on Jython -- needs to be investigated).') +def test_unhandled_exceptions_in_top_level4(case_setup_unhandled_exceptions): + + # Note: expecting unhandled exception to be printed to stderr. + with case_setup_unhandled_exceptions.test_file( + '_debugger_case_unhandled_exceptions_on_top_level2.py', + EXPECTED_RETURNCODE=1, + ) as writer: + + # Handled and unhandled + writer.write_add_exception_breakpoint_with_policy('Exception', "1", "1", "0") + writer.write_make_initial_run() + + # We have an exception thrown and handled and another which is thrown and is then unhandled. + hit = writer.wait_for_breakpoint_hit(REASON_CAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(REASON_CAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION) + writer.write_run_thread(hit.thread_id) + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.skipif(not IS_CPYTHON, reason='Only for Python.') +def test_case_set_next_statement(case_setup): + + with case_setup.test_file('_debugger_case_set_next_statement.py') as writer: + breakpoint_id = writer.write_add_breakpoint(6, None) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT, line=6) # Stop in line a=3 (before setting it) + + writer.write_evaluate_expression('%s\t%s\t%s' % (hit.thread_id, hit.frame_id, 'LOCAL'), 'a') + writer.wait_for_evaluation('' + assert msg.thread.frame['line'] == str(writer.get_line_index_with_content('break line on unhandled exception')) + + writer.write_run_thread(hit.thread_id) + + writer.log.append('Marking finished ok.') + writer.finished_ok = True + + +@pytest.mark.skipif(not IS_CPYTHON, reason='Only for Python.') +def test_case_get_next_statement_targets(case_setup): + with case_setup.test_file('_debugger_case_get_next_statement_targets.py') as writer: + breakpoint_id = writer.write_add_breakpoint(21, None) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT, line=21) + + writer.write_get_next_statement_targets(hit.thread_id, hit.frame_id) + targets = writer.wait_for_get_next_statement_targets() + expected = set((2, 3, 5, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 21)) + assert targets == expected, 'Expected targets to be %s, was: %s' % (expected, targets) + + writer.write_remove_breakpoint(breakpoint_id) + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_IRONPYTHON or IS_JYTHON, reason='Failing on IronPython and Jython (needs to be investigated).') +def test_case_type_ext(case_setup): + # Custom type presentation extensions + + def get_environ(self): + env = os.environ.copy() + + python_path = env.get("PYTHONPATH", "") + ext_base = debugger_unittest._get_debugger_test_file('my_extensions') + env['PYTHONPATH'] = ext_base + os.pathsep + python_path if python_path else ext_base + return env + + with case_setup.test_file('_debugger_case_type_ext.py', get_environ=get_environ) as writer: + writer.get_environ = get_environ + + writer.write_add_breakpoint(7, None) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111') + writer.write_get_frame(hit.thread_id, hit.frame_id) + assert writer.wait_for_var([ + [ + r'', + r''.format(builtin_qualifier)) + writer.write_run_thread(hit.thread_id) + writer.finished_ok = True + + +@pytest.mark.skipif(IS_IRONPYTHON or IS_JYTHON, reason='Failing on IronPython and Jython (needs to be investigated).') +def test_case_event_ext(case_setup): + + def get_environ(self): + env = os.environ.copy() + + python_path = env.get("PYTHONPATH", "") + ext_base = debugger_unittest._get_debugger_test_file('my_extensions') + env['PYTHONPATH'] = ext_base + os.pathsep + python_path if python_path else ext_base + env["VERIFY_EVENT_TEST"] = "1" + return env + + # Test initialize event for extensions + with case_setup.test_file('_debugger_case_event_ext.py', get_environ=get_environ) as writer: + + original_additional_output_checks = writer.additional_output_checks + + @overrides(writer.additional_output_checks) + def additional_output_checks(stdout, stderr): + original_additional_output_checks(stdout, stderr) + if 'INITIALIZE EVENT RECEIVED' not in stdout: + raise AssertionError('No initialize event received') + + writer.additional_output_checks = additional_output_checks + + writer.write_make_initial_run() + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Jython does not seem to be creating thread started inside tracing (investigate).') +def test_case_writer_creation_deadlock(case_setup): + # check case where there was a deadlock evaluating expressions + with case_setup.test_file('_debugger_case_thread_creation_deadlock.py') as writer: + writer.write_add_breakpoint(26, None) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit('111') + + assert hit.line == 26, 'Expected return to be in line 26, was: %s' % (hit.line,) + + writer.write_evaluate_expression('%s\t%s\t%s' % (hit.thread_id, hit.frame_id, 'LOCAL'), 'create_thread()') + writer.wait_for_evaluation('= 3: + expected.extend(( + 'binary\n', + 'ação2\n'.encode(encoding='latin1').decode('utf-8', 'replace'), + 'ação3\n', + )) + + new_expected = [(x, 'stdout') for x in expected] + new_expected.extend([(x, 'stderr') for x in expected]) + + writer.write_start_redirect() + + writer.write_make_initial_run() + msgs = [] + ignored = [] + while len(msgs) < len(new_expected): + try: + msg = writer.wait_for_output() + except AssertionError: + for msg in msgs: + sys.stderr.write('Found: %s\n' % (msg,)) + for msg in new_expected: + sys.stderr.write('Expected: %s\n' % (msg,)) + for msg in ignored: + sys.stderr.write('Ignored: %s\n' % (msg,)) + raise + if msg not in new_expected: + ignored.append(msg) + continue + msgs.append(msg) + + if msgs != new_expected: + print(msgs) + print(new_expected) + assert msgs == new_expected + writer.finished_ok = True + + +def _path_equals(path1, path2): + path1 = pydevd_file_utils.normcase(path1) + path2 = pydevd_file_utils.normcase(path2) + return path1 == path2 + + +@pytest.mark.parametrize('mixed_case', [True, False] if sys.platform == 'win32' else [False]) +def test_path_translation(case_setup, mixed_case): + + def get_file_in_client(writer): + # Instead of using: test_python/_debugger_case_path_translation.py + # we'll set the breakpoints at foo/_debugger_case_path_translation.py + file_in_client = os.path.dirname(os.path.dirname(writer.TEST_FILE)) + return os.path.join(os.path.dirname(file_in_client), 'foo', '_debugger_case_path_translation.py') + + def get_environ(writer): + import json + env = os.environ.copy() + + env["PYTHONIOENCODING"] = 'utf-8' + + assert writer.TEST_FILE.endswith('_debugger_case_path_translation.py') + file_in_client = get_file_in_client(writer) + if mixed_case: + new_file_in_client = ''.join([file_in_client[i].upper() if i % 2 == 0 else file_in_client[i].lower() for i in range(len(file_in_client))]) + assert _path_equals(file_in_client, new_file_in_client) + env["PATHS_FROM_ECLIPSE_TO_PYTHON"] = json.dumps([ + ( + os.path.dirname(file_in_client), + os.path.dirname(writer.TEST_FILE) + ) + ]) + return env + + with case_setup.test_file('_debugger_case_path_translation.py', get_environ=get_environ) as writer: + from tests_python.debugger_unittest import CMD_LOAD_SOURCE + writer.write_start_redirect() + + file_in_client = get_file_in_client(writer) + assert 'tests_python' not in file_in_client + writer.write_add_breakpoint( + writer.get_line_index_with_content('break here'), 'call_this', filename=file_in_client) + writer.write_make_initial_run() + + xml = writer.wait_for_message(lambda msg:'stop_reason="111"' in msg) + assert xml.thread.frame[0]['file'] == file_in_client + thread_id = xml.thread['id'] + + # Request a file that exists + files_to_match = [file_in_client] + if IS_WINDOWS: + files_to_match.append(file_in_client.upper()) + for f in files_to_match: + writer.write_load_source(f) + writer.wait_for_message( + lambda msg: + '%s\t' % CMD_LOAD_SOURCE in msg and \ + "def main():" in msg and \ + "print('break here')" in msg and \ + "print('TEST SUCEEDED!')" in msg + , expect_xml=False) + + # Request a file that does not exist + writer.write_load_source(file_in_client + 'not_existent.py') + writer.wait_for_message( + lambda msg:'901\t' in msg and ('FileNotFoundError' in msg or 'IOError' in msg), + expect_xml=False) + + writer.write_run_thread(thread_id) + + writer.finished_ok = True + + +def test_evaluate_errors(case_setup): + with case_setup.test_file('_debugger_case_local_variables.py') as writer: + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here'), 'Call') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit() + thread_id = hit.thread_id + frame_id = hit.frame_id + + writer.write_evaluate_expression('%s\t%s\t%s' % (thread_id, frame_id, 'LOCAL'), 'name_error') + writer.wait_for_evaluation('' + else: + assert len(msg.thread.frame) > 1 # Stopped in threading (must have back frames). + assert msg.thread.frame[0]['name'] == 'method' + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_case_dump_threads_to_stderr(case_setup): + + from tests_python.debugger_unittest import wait_for_condition + + def additional_output_checks(writer, stdout, stderr): + assert is_stderr_ok(stderr), make_error_msg(stderr) + + def make_error_msg(stderr): + return 'Did not find thread dump in stderr. stderr:\n%s' % (stderr,) + + def is_stderr_ok(stderr): + return 'Thread Dump' in stderr and 'Thread pydevd.CommandThread (daemon: True, pydevd thread: True)' in stderr + + with case_setup.test_file( + '_debugger_case_get_thread_stack.py', additional_output_checks=additional_output_checks) as writer: + writer.write_add_breakpoint(12, None) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT) + + writer.write_dump_threads() + wait_for_condition( + lambda: is_stderr_ok(writer.get_stderr()), + lambda: make_error_msg(writer.get_stderr()) + ) + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_stop_on_start_regular(case_setup): + + with case_setup.test_file('_debugger_case_simple_calls.py') as writer: + writer.write_stop_on_start() + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STEP_INTO_MY_CODE, file='_debugger_case_simple_calls.py', line=1) + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def _get_breakpoint_cases(): + if sys.version_info >= (3, 7): + # Just check breakpoint() + return ('_debugger_case_breakpoint.py',) + else: + # Check breakpoint() and sys.__breakpointhook__ replacement. + return ('_debugger_case_breakpoint.py', '_debugger_case_breakpoint2.py') + + +@pytest.mark.parametrize("filename", _get_breakpoint_cases()) +def test_py_37_breakpoint(case_setup, filename): + with case_setup.test_file(filename) as writer: + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(file=filename, line=3) + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def _get_generator_cases(): + if IS_PY2: + return ('_debugger_case_generator_py2.py',) + else: + # On py3 we should check both versions. + return ( + '_debugger_case_generator_py2.py', + '_debugger_case_generator_py3.py', + ) + + +@pytest.mark.parametrize("filename", _get_generator_cases()) +def test_generator_cases(case_setup, filename): + with case_setup.test_file(filename) as writer: + writer.write_add_breakpoint(writer.get_line_index_with_content('break here')) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit() + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_stop_on_start_m_switch(case_setup_m_switch): + + with case_setup_m_switch.test_file() as writer: + writer.write_stop_on_start() + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STEP_INTO_MY_CODE, file='_debugger_case_m_switch.py', line=1) + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_stop_on_start_entry_point(case_setup_m_switch_entry_point): + + with case_setup_m_switch_entry_point.test_file() as writer: + writer.write_stop_on_start() + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(REASON_STEP_INTO_MY_CODE, file='_debugger_case_module_entry_point.py', line=1) + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Not working properly on Jython (needs investigation).') +def test_debug_zip_files(case_setup, tmpdir): + + def get_environ(writer): + env = os.environ.copy() + curr_pythonpath = env.get('PYTHONPATH', '') + + curr_pythonpath = str(tmpdir.join('myzip.zip')) + os.pathsep + curr_pythonpath + curr_pythonpath = str(tmpdir.join('myzip2.egg!')) + os.pathsep + curr_pythonpath + env['PYTHONPATH'] = curr_pythonpath + + env["IDE_PROJECT_ROOTS"] = str(tmpdir.join('myzip.zip')) + return env + + import zipfile + zip_file = zipfile.ZipFile( + str(tmpdir.join('myzip.zip')), 'w') + zip_file.writestr('zipped/__init__.py', '') + zip_file.writestr('zipped/zipped_contents.py', 'def call_in_zip():\n return 1') + zip_file.close() + + zip_file = zipfile.ZipFile( + str(tmpdir.join('myzip2.egg!')), 'w') + zip_file.writestr('zipped2/__init__.py', '') + zip_file.writestr('zipped2/zipped_contents2.py', 'def call_in_zip2():\n return 1') + zip_file.close() + + with case_setup.test_file('_debugger_case_zip_files.py', get_environ=get_environ) as writer: + writer.write_add_breakpoint( + 2, + 'None', + filename=os.path.join(str(tmpdir.join('myzip.zip')), 'zipped', 'zipped_contents.py') + ) + + writer.write_add_breakpoint( + 2, + 'None', + filename=os.path.join(str(tmpdir.join('myzip2.egg!')), 'zipped2', 'zipped_contents2.py') + ) + + writer.write_make_initial_run() + hit = writer.wait_for_breakpoint_hit() + assert hit.name == 'call_in_zip' + writer.write_run_thread(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit() + assert hit.name == 'call_in_zip2' + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +@pytest.mark.skipif(not IS_CPYTHON, reason='CPython only test.') +@pytest.mark.parametrize('file_to_check', [ + '_debugger_case_multiprocessing.py', + '_debugger_case_python_c.py', + '_debugger_case_multiprocessing_pool.py' +]) +def test_multiprocessing_simple(case_setup_multiprocessing, file_to_check): + import threading + from tests_python.debugger_unittest import AbstractWriterThread + with case_setup_multiprocessing.test_file(file_to_check) as writer: + break1_line = writer.get_line_index_with_content('break 1 here') + break2_line = writer.get_line_index_with_content('break 2 here') + + writer.write_add_breakpoint(break1_line) + writer.write_add_breakpoint(break2_line) + + server_socket = writer.server_socket + + class SecondaryProcessWriterThread(AbstractWriterThread): + + TEST_FILE = writer.get_main_filename() + _sequence = -1 + + class SecondaryProcessThreadCommunication(threading.Thread): + + def run(self): + from tests_python.debugger_unittest import ReaderThread + expected_connections = 1 + if sys.platform != 'win32' and IS_PY2 and file_to_check == '_debugger_case_python_c.py': + # Note: on linux on Python 2 CPython subprocess.call will actually + # create a fork first (at which point it'll connect) and then, later on it'll + # call the main (as if it was a clean process as if PyDB wasn't created + # the first time -- the debugger will still work, but it'll do an additional + # connection). + expected_connections = 2 + + for _ in range(expected_connections): + server_socket.listen(1) + self.server_socket = server_socket + new_sock, addr = server_socket.accept() + + reader_thread = ReaderThread(new_sock) + reader_thread.name = ' *** Multiprocess Reader Thread' + reader_thread.start() + + writer2 = SecondaryProcessWriterThread() + + writer2.reader_thread = reader_thread + writer2.sock = new_sock + + writer2.write_version() + writer2.write_add_breakpoint(break1_line) + writer2.write_add_breakpoint(break2_line) + writer2.write_make_initial_run() + + hit = writer2.wait_for_breakpoint_hit() + writer2.write_run_thread(hit.thread_id) + + secondary_process_thread_communication = SecondaryProcessThreadCommunication() + secondary_process_thread_communication.start() + writer.write_make_initial_run() + hit2 = writer.wait_for_breakpoint_hit() + secondary_process_thread_communication.join(10) + if secondary_process_thread_communication.is_alive(): + raise AssertionError('The SecondaryProcessThreadCommunication did not finish') + writer.write_run_thread(hit2.thread_id) + writer.finished_ok = True + + +@pytest.mark.skipif(not IS_CPYTHON, reason='CPython only test.') +def test_multiprocessing_with_stopped_breakpoints(case_setup_multiprocessing): + import threading + from tests_python.debugger_unittest import AbstractWriterThread + with case_setup_multiprocessing.test_file('_debugger_case_multiprocessing_stopped_threads.py') as writer: + break_main_line = writer.get_line_index_with_content('break in main here') + break_thread_line = writer.get_line_index_with_content('break in thread here') + break_process_line = writer.get_line_index_with_content('break in process here') + + writer.write_add_breakpoint(break_main_line) + writer.write_add_breakpoint(break_thread_line) + writer.write_add_breakpoint(break_process_line) + + server_socket = writer.server_socket + + class SecondaryProcessWriterThread(AbstractWriterThread): + + TEST_FILE = writer.get_main_filename() + _sequence = -1 + + class SecondaryProcessThreadCommunication(threading.Thread): + + def run(self): + from tests_python.debugger_unittest import ReaderThread + server_socket.listen(1) + self.server_socket = server_socket + new_sock, addr = server_socket.accept() + + reader_thread = ReaderThread(new_sock) + reader_thread.name = ' *** Multiprocess Reader Thread' + reader_thread.start() + + writer2 = SecondaryProcessWriterThread() + + writer2.reader_thread = reader_thread + writer2.sock = new_sock + + writer2.write_version() + writer2.write_add_breakpoint(break_main_line) + writer2.write_add_breakpoint(break_thread_line) + writer2.write_add_breakpoint(break_process_line) + writer2.write_make_initial_run() + hit = writer2.wait_for_breakpoint_hit() + writer2.write_run_thread(hit.thread_id) + + secondary_process_thread_communication = SecondaryProcessThreadCommunication() + secondary_process_thread_communication.start() + writer.write_make_initial_run() + hit2 = writer.wait_for_breakpoint_hit() # Breaks in thread. + writer.write_step_over(hit2.thread_id) + + hit2 = writer.wait_for_breakpoint_hit(REASON_STEP_OVER) # line == event.set() + + # paused on breakpoint, will start process and pause on main thread + # in the main process too. + writer.write_step_over(hit2.thread_id) + + # Note: ignore the step over hit (go only for the breakpoint hit). + main_hit = writer.wait_for_breakpoint_hit(REASON_STOP_ON_BREAKPOINT) + + secondary_process_thread_communication.join(10) + if secondary_process_thread_communication.is_alive(): + raise AssertionError('The SecondaryProcessThreadCommunication did not finish') + + writer.write_run_thread(hit2.thread_id) + writer.write_run_thread(main_hit.thread_id) + + writer.finished_ok = True + + +@pytest.mark.skipif(not IS_CPYTHON, reason='CPython only test.') +def test_subprocess_quoted_args(case_setup_multiprocessing): + import threading + from tests_python.debugger_unittest import AbstractWriterThread + with case_setup_multiprocessing.test_file('_debugger_case_quoting.py') as writer: + break_subprocess_line = writer.get_line_index_with_content('break here') + + writer.write_add_breakpoint(break_subprocess_line) + + server_socket = writer.server_socket + + class SecondaryProcessWriterThread(AbstractWriterThread): + + TEST_FILE = writer.get_main_filename() + _sequence = -1 + + class SecondaryProcessThreadCommunication(threading.Thread): + + def run(self): + from tests_python.debugger_unittest import ReaderThread + # Note: on linux on Python 2 because on Python 2 CPython subprocess.call will actually + # create a fork first (at which point it'll connect) and then, later on it'll + # call the main (as if it was a clean process as if PyDB wasn't created + # the first time -- the debugger will still work, but it'll do an additional + # connection. + + expected_connections = 1 + if sys.platform != 'win32' and IS_PY2: + expected_connections = 2 + + for _ in range(expected_connections): + server_socket.listen(1) + self.server_socket = server_socket + new_sock, addr = server_socket.accept() + + reader_thread = ReaderThread(new_sock) + reader_thread.name = ' *** Multiprocess Reader Thread' + reader_thread.start() + + writer2 = SecondaryProcessWriterThread() + + writer2.reader_thread = reader_thread + writer2.sock = new_sock + + writer2.write_version() + writer2.write_add_breakpoint(break_subprocess_line) + writer2.write_make_initial_run() + hit = writer2.wait_for_breakpoint_hit() + writer2.write_run_thread(hit.thread_id) + + secondary_process_thread_communication = SecondaryProcessThreadCommunication() + secondary_process_thread_communication.start() + writer.write_make_initial_run() + + secondary_process_thread_communication.join(10) + if secondary_process_thread_communication.is_alive(): + raise AssertionError('The SecondaryProcessThreadCommunication did not finish') + + writer.finished_ok = True + + +def _attach_to_writer_pid(writer): + import pydevd + assert writer.process is not None + + def attach(): + attach_pydevd_file = os.path.join(os.path.dirname(pydevd.__file__), 'pydevd_attach_to_process', 'attach_pydevd.py') + subprocess.call([sys.executable, attach_pydevd_file, '--pid', str(writer.process.pid), '--port', str(writer.port)]) + + threading.Thread(target=attach).start() + + wait_for_condition(lambda: writer.finished_initialization) + + +@pytest.mark.skipif(not IS_CPYTHON, reason='CPython only test.') +def test_attach_to_pid_no_threads(case_setup_remote): + with case_setup_remote.test_file('_debugger_case_attach_to_pid_simple.py', wait_for_port=False) as writer: + time.sleep(1) # Give it some time to initialize to get to the while loop. + _attach_to_writer_pid(writer) + + bp_line = writer.get_line_index_with_content('break here') + writer.write_add_breakpoint(bp_line) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(line=bp_line) + + writer.write_change_variable(hit.thread_id, hit.frame_id, 'wait', 'False') + writer.wait_for_var('', line=break_line) + + writer.write_step_over(hit.thread_id) + hit = writer.wait_for_breakpoint_hit(REASON_STEP_OVER, name='', line=break_line + 1) + writer.write_get_frame(hit.thread_id, hit.frame_id) + writer.wait_for_vars([ + [ + '' + + if IS_JYTHON: + # Jython may get to exit functions, so, just resume the thread. + writer.write_run_thread(hit.thread_id) + + else: + stop_reason = do_step() + + if step_method != 'step_return': + stop_reason = do_step() + if step_method == 'step_over': + stop_reason = REASON_STEP_OVER + + hit = writer.wait_for_breakpoint_hit(reason=stop_reason) + assert hit.name == '' + + writer.write_step_over(hit.thread_id) + + writer.finished_ok = True + + +def test_step_over_my_code_global_setting_and_explicit_include(case_setup): + + def get_environ(writer): + env = os.environ.copy() + env.update({ + 'PYDEVD_FILTER_LIBRARIES': '1', # Global setting for in project or not + # specify as json (force include). + 'PYDEVD_FILTERS': json.dumps({'**/other.py': False}) + }) + return env + + with case_setup.test_file('my_code/my_code.py', get_environ=get_environ) as writer: + writer.write_set_project_roots([debugger_unittest._get_debugger_test_file('my_code')]) + writer.write_add_breakpoint(writer.get_line_index_with_content('break here')) + writer.write_make_initial_run() + hit = writer.wait_for_breakpoint_hit() + + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit(reason=REASON_STEP_INTO) + + # Although we filtered out non-project files, other.py is explicitly included. + assert hit.name == 'call_me_back1' + + writer.write_run_thread(hit.thread_id) + writer.finished_ok = True + + +def test_namedtuple(case_setup): + ''' + Check that we don't step into in the namedtuple constructor. + ''' + with case_setup.test_file('_debugger_case_namedtuple.py') as writer: + line = writer.get_line_index_with_content('break here') + writer.write_add_breakpoint(line) + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit() + + expected_line = line + + for _ in range(2): + expected_line += 1 + writer.write_step_in(hit.thread_id) + hit = writer.wait_for_breakpoint_hit( + reason=REASON_STEP_INTO, file='_debugger_case_namedtuple.py', line=expected_line) + + writer.write_run_thread(hit.thread_id) + writer.finished_ok = True + + +def test_matplotlib_activation(case_setup): + try: + import matplotlib + except ImportError: + return + + def get_environ(writer): + env = os.environ.copy() + env.update({ + 'IPYTHONENABLE': 'True', + }) + return env + + with case_setup.test_file('_debugger_case_matplotlib.py', get_environ=get_environ) as writer: + writer.write_add_breakpoint(writer.get_line_index_with_content('break here')) + writer.write_make_initial_run() + for _ in range(3): + hit = writer.wait_for_breakpoint_hit() + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + +# Jython needs some vars to be set locally. +# set JAVA_HOME=c:\bin\jdk1.8.0_172 +# set PATH=%PATH%;C:\bin\jython2.7.0\bin +# set PATH=%PATH%;%JAVA_HOME%\bin +# c:\bin\jython2.7.0\bin\jython.exe -m py.test tests_python + + +if __name__ == '__main__': + pytest.main(['-k', 'test_unhandled_exceptions_in_top_level2']) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py new file mode 100644 index 0000000..4b3ad4e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py @@ -0,0 +1,2737 @@ +# coding: utf-8 +import pytest + +from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema +from _pydevd_bundle._debug_adapter.pydevd_base_schema import from_json +from tests_python.debugger_unittest import IS_JYTHON, IS_APPVEYOR, overrides, wait_for_condition, \ + get_free_port +from _pydevd_bundle._debug_adapter.pydevd_schema import (ThreadEvent, ModuleEvent, OutputEvent, + ExceptionOptions, Response, StoppedEvent, ContinuedEvent, ProcessEvent) +from tests_python import debugger_unittest +import json +from collections import namedtuple +from _pydevd_bundle.pydevd_constants import (int_types, IS_64BIT_PROCESS, + PY_VERSION_STR, PY_IMPL_VERSION_STR, PY_IMPL_NAME) +from tests_python.debug_constants import * # noqa +import time +from os.path import normcase +from _pydev_bundle.pydev_localhost import get_socket_name +from _pydevd_bundle.pydevd_comm_constants import file_system_encoding +from tests_python.debug_constants import TEST_CHERRYPY + +pytest_plugins = [ + str('tests_python.debugger_fixtures'), +] + +_JsonHit = namedtuple('_JsonHit', 'thread_id, frame_id, stack_trace_response') + +pytestmark = pytest.mark.skipif(IS_JYTHON, reason='Single notification is not OK in Jython (investigate).') + +# Note: in reality must be < int32, but as it's created sequentially this should be +# a reasonable number for tests. +MAX_EXPECTED_ID = 10000 + + +class _MessageWithMark(object): + + def __init__(self, msg): + self.msg = msg + self.marked = False + + +class JsonFacade(object): + + def __init__(self, writer): + self.writer = writer + writer.reader_thread.accept_xml_messages = False + writer.write_set_protocol('http_json') + writer.write_multi_threads_single_notification(True) + self._all_json_messages_found = [] + self._sent_launch_or_attach = False + + def mark_messages(self, expected_class, accept_message=lambda obj:True): + ret = [] + for message_with_mark in self._all_json_messages_found: + if not message_with_mark.marked: + if isinstance(message_with_mark.msg, expected_class): + if accept_message(message_with_mark.msg): + message_with_mark.marked = True + ret.append(message_with_mark.msg) + return ret + + def wait_for_json_message(self, expected_class, accept_message=lambda obj:True): + + def accept_json_message(msg): + if msg.startswith('{'): + decoded_msg = from_json(msg) + + self._all_json_messages_found.append(_MessageWithMark(decoded_msg)) + + if isinstance(decoded_msg, expected_class): + if accept_message(decoded_msg): + return True + return False + + msg = self.writer.wait_for_message(accept_json_message, unquote_msg=False, expect_xml=False) + return from_json(msg) + + def wait_for_response(self, request): + response_class = pydevd_base_schema.get_response_class(request) + + def accept_message(response): + if isinstance(request, dict): + if response.request_seq == request['seq']: + return True + else: + if response.request_seq == request.seq: + return True + return False + + return self.wait_for_json_message((response_class, Response), accept_message) + + def write_request(self, request): + seq = self.writer.next_seq() + if isinstance(request, dict): + request['seq'] = seq + self.writer.write_with_content_len(json.dumps(request)) + else: + request.seq = seq + self.writer.write_with_content_len(request.to_json()) + return request + + def write_make_initial_run(self): + if not self._sent_launch_or_attach: + self.write_launch() + + configuration_done_request = self.write_request(pydevd_schema.ConfigurationDoneRequest()) + return self.wait_for_response(configuration_done_request) + + def write_list_threads(self): + return self.wait_for_response(self.write_request(pydevd_schema.ThreadsRequest())) + + def wait_for_thread_stopped(self, reason='breakpoint', line=None, file=None, name=None): + ''' + :param file: + utf-8 bytes encoded file or unicode + ''' + stopped_event = self.wait_for_json_message(StoppedEvent) + assert stopped_event.body.reason == reason + json_hit = self.get_stack_as_json_hit(stopped_event.body.threadId) + if file is not None: + path = json_hit.stack_trace_response.body.stackFrames[0]['source']['path'] + if IS_PY2: + if isinstance(file, bytes): + file = file.decode('utf-8') + if isinstance(path, bytes): + path = path.decode('utf-8') + + assert path.endswith(file) + if name is not None: + assert json_hit.stack_trace_response.body.stackFrames[0]['name'] == name + if line is not None: + found_line = json_hit.stack_trace_response.body.stackFrames[0]['line'] + if not isinstance(line, (tuple, list)): + line = [line] + assert found_line in line, 'Expect to break at line: %s. Found: %s' % (line, found_line) + return json_hit + + def write_set_breakpoints( + self, + lines, + filename=None, + line_to_info=None, + success=True, + verified=True, + send_launch_if_needed=True, + expected_lines_in_response=None, + ): + ''' + Adds a breakpoint. + ''' + if send_launch_if_needed and not self._sent_launch_or_attach: + self.write_launch() + + if isinstance(lines, int): + lines = [lines] + + if line_to_info is None: + line_to_info = {} + + if filename is None: + filename = self.writer.get_main_filename() + + if isinstance(filename, bytes): + filename = filename.decode(file_system_encoding) # file is in the filesystem encoding but protocol needs it in utf-8 + filename = filename.encode('utf-8') + + source = pydevd_schema.Source(path=filename) + breakpoints = [] + for line in lines: + condition = None + hit_condition = None + log_message = None + + if line in line_to_info: + line_info = line_to_info.get(line) + condition = line_info.get('condition') + hit_condition = line_info.get('hit_condition') + log_message = line_info.get('log_message') + + breakpoints.append(pydevd_schema.SourceBreakpoint( + line, condition=condition, hitCondition=hit_condition, logMessage=log_message).to_dict()) + + arguments = pydevd_schema.SetBreakpointsArguments(source, breakpoints) + request = pydevd_schema.SetBreakpointsRequest(arguments) + + # : :type response: SetBreakpointsResponse + response = self.wait_for_response(self.write_request(request)) + body = response.body + + assert response.success == success + + if success: + # : :type body: SetBreakpointsResponseBody + assert len(body.breakpoints) == len(lines) + lines_in_response = [b['line'] for b in body.breakpoints] + + if expected_lines_in_response is None: + expected_lines_in_response = lines + assert set(lines_in_response) == set(expected_lines_in_response) + + for b in body.breakpoints: + assert b['verified'] == verified + return response + + def write_set_exception_breakpoints(self, filters=None, exception_options=None): + ''' + :param list(str) filters: + A list with 'raised' or 'uncaught' entries. + + :param list(ExceptionOptions) exception_options: + + ''' + filters = filters or [] + assert set(filters).issubset(set(('raised', 'uncaught'))) + + exception_options = exception_options or [] + exception_options = [exception_option.to_dict() for exception_option in exception_options] + + arguments = pydevd_schema.SetExceptionBreakpointsArguments(filters, exception_options) + request = pydevd_schema.SetExceptionBreakpointsRequest(arguments) + # : :type response: SetExceptionBreakpointsResponse + response = self.wait_for_response(self.write_request(request)) + assert response.success + + def _write_launch_or_attach(self, command, **arguments): + assert not self._sent_launch_or_attach + self._sent_launch_or_attach = True + arguments['noDebug'] = False + request = {'type': 'request', 'command': command, 'arguments': arguments, 'seq':-1} + self.wait_for_response(self.write_request(request)) + + def write_launch(self, **arguments): + return self._write_launch_or_attach('launch', **arguments) + + def write_attach(self, **arguments): + return self._write_launch_or_attach('attach', **arguments) + + def write_disconnect(self, wait_for_response=True): + assert self._sent_launch_or_attach + self._sent_launch_or_attach = False + arguments = pydevd_schema.DisconnectArguments(terminateDebuggee=False) + request = pydevd_schema.DisconnectRequest(arguments) + self.write_request(request) + if wait_for_response: + self.wait_for_response(request) + + def get_stack_as_json_hit(self, thread_id): + stack_trace_request = self.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=thread_id))) + + # : :type stack_trace_response: StackTraceResponse + # : :type stack_trace_response_body: StackTraceResponseBody + # : :type stack_frame: StackFrame + stack_trace_response = self.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + assert len(stack_trace_response_body.stackFrames) > 0 + + for stack_frame in stack_trace_response_body.stackFrames: + assert stack_frame['id'] < MAX_EXPECTED_ID + + stack_frame = next(iter(stack_trace_response_body.stackFrames)) + + return _JsonHit( + thread_id=thread_id, frame_id=stack_frame['id'], stack_trace_response=stack_trace_response) + + def get_variables_response(self, variables_reference, fmt=None, success=True): + assert variables_reference < MAX_EXPECTED_ID + variables_request = self.write_request( + pydevd_schema.VariablesRequest(pydevd_schema.VariablesArguments(variables_reference, format=fmt))) + variables_response = self.wait_for_response(variables_request) + assert variables_response.success == success + return variables_response + + def filter_return_variables(self, variables): + ret = [] + for variable in variables: + if variable['name'].startswith('(return)'): + ret.append(variable) + return ret + + def pop_variables_reference(self, lst): + ''' + Modifies dicts in-place to remove the variablesReference and returns those (in the same order + in which they were received). + ''' + references = [] + for dct in lst: + reference = dct.pop('variablesReference', None) + if reference is not None: + assert isinstance(reference, int_types) + assert reference < MAX_EXPECTED_ID + references.append(reference) + return references + + def write_continue(self, wait_for_response=True): + continue_request = self.write_request( + pydevd_schema.ContinueRequest(pydevd_schema.ContinueArguments('*'))) + + if wait_for_response: + # The continued event is received before the response. + assert self.wait_for_json_message(ContinuedEvent).body.allThreadsContinued + + continue_response = self.wait_for_response(continue_request) + assert continue_response.body.allThreadsContinued + + def write_pause(self): + pause_request = self.write_request( + pydevd_schema.PauseRequest(pydevd_schema.PauseArguments('*'))) + pause_response = self.wait_for_response(pause_request) + assert pause_response.success + + def write_step_in(self, thread_id): + arguments = pydevd_schema.StepInArguments(threadId=thread_id) + self.wait_for_response(self.write_request(pydevd_schema.StepInRequest(arguments))) + + def write_step_next(self, thread_id, wait_for_response=True): + next_request = self.write_request( + pydevd_schema.NextRequest(pydevd_schema.NextArguments(thread_id))) + if wait_for_response: + self.wait_for_response(next_request) + + def write_step_out(self, thread_id, wait_for_response=True): + stepout_request = self.write_request( + pydevd_schema.StepOutRequest(pydevd_schema.StepOutArguments(thread_id))) + if wait_for_response: + self.wait_for_response(stepout_request) + + def write_set_variable(self, frame_variables_reference, name, value, success=True): + set_variable_request = self.write_request( + pydevd_schema.SetVariableRequest(pydevd_schema.SetVariableArguments( + frame_variables_reference, name, value, + ))) + set_variable_response = self.wait_for_response(set_variable_request) + assert set_variable_response.success == success + return set_variable_response + + def get_name_to_scope(self, frame_id): + scopes_request = self.write_request(pydevd_schema.ScopesRequest( + pydevd_schema.ScopesArguments(frame_id))) + + scopes_response = self.wait_for_response(scopes_request) + + scopes = scopes_response.body.scopes + name_to_scopes = dict((scope['name'], pydevd_schema.Scope(**scope)) for scope in scopes) + + assert len(scopes) == 1 + assert sorted(name_to_scopes.keys()) == ['Locals'] + assert not name_to_scopes['Locals'].expensive + + return name_to_scopes + + def get_name_to_var(self, variables_reference): + variables_response = self.get_variables_response(variables_reference) + return dict((variable['name'], pydevd_schema.Variable(**variable)) for variable in variables_response.body.variables) + + def get_locals_name_to_var(self, frame_id): + name_to_scope = self.get_name_to_scope(frame_id) + + return self.get_name_to_var(name_to_scope['Locals'].variablesReference) + + def get_local_var(self, frame_id, var_name): + ret = self.get_locals_name_to_var(frame_id)[var_name] + assert ret.name == var_name + return ret + + def get_var(self, variables_reference, var_name=None, index=None): + if var_name is not None: + return self.get_name_to_var(variables_reference)[var_name] + else: + assert index is not None, 'Either var_name or index must be passed.' + variables_response = self.get_variables_response(variables_reference) + return pydevd_schema.Variable(**variables_response.body.variables[index]) + + def write_set_debugger_property(self, dont_trace_start_patterns, dont_trace_end_patterns): + dbg_request = self.write_request( + pydevd_schema.SetDebuggerPropertyRequest(pydevd_schema.SetDebuggerPropertyArguments( + dontTraceStartPatterns=dont_trace_start_patterns, + dontTraceEndPatterns=dont_trace_end_patterns))) + response = self.wait_for_response(dbg_request) + assert response.success + return response + + def write_set_pydevd_source_map(self, source, pydevd_source_maps, success=True): + dbg_request = self.write_request( + pydevd_schema.SetPydevdSourceMapRequest(pydevd_schema.SetPydevdSourceMapArguments( + source=source, + pydevdSourceMaps=pydevd_source_maps, + ))) + response = self.wait_for_response(dbg_request) + assert response.success == success + return response + + +def test_case_json_logpoints(case_setup): + with case_setup.test_file('_debugger_case_change_breaks.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + break_2 = writer.get_line_index_with_content('break 2') + break_3 = writer.get_line_index_with_content('break 3') + json_facade.write_set_breakpoints( + [break_2, break_3], + line_to_info={ + break_2: {'log_message': 'var {repr("_a")} is {_a}'} + }) + json_facade.write_make_initial_run() + + # Should only print, not stop on logpoints. + messages = [] + while True: + output_event = json_facade.wait_for_json_message(OutputEvent) + msg = output_event.body.output + ctx = output_event.body.category + + if ctx == 'stdout': + msg = msg.strip() + if msg == "var '_a' is 2": + messages.append(msg) + + if len(messages) == 2: + break + + # Just one hit at the end (break 3). + json_facade.wait_for_thread_stopped(line=break_3) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_process_event(case_setup): + with case_setup.test_file('_debugger_case_change_breaks.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + assert len(json_facade.mark_messages(ProcessEvent)) == 1 + json_facade.write_make_initial_run() + writer.finished_ok = True + + +def test_case_json_change_breaks(case_setup): + with case_setup.test_file('_debugger_case_change_breaks.py') as writer: + json_facade = JsonFacade(writer) + + break1_line = writer.get_line_index_with_content('break 1') + # Note: we can only write breakpoints after the launch is received. + json_facade.write_set_breakpoints(break1_line, success=False, send_launch_if_needed=False) + + json_facade.write_launch() + json_facade.write_set_breakpoints(break1_line) + json_facade.write_make_initial_run() + + json_facade.wait_for_thread_stopped(line=break1_line) + json_facade.write_set_breakpoints([]) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_handled_exception_breaks(case_setup): + with case_setup.test_file('_debugger_case_exceptions.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + json_facade.write_set_exception_breakpoints(['raised']) + json_facade.write_make_initial_run() + + json_facade.wait_for_thread_stopped( + reason='exception', line=writer.get_line_index_with_content('raise indexerror line')) + json_facade.write_continue() + + json_facade.wait_for_thread_stopped( + reason='exception', line=writer.get_line_index_with_content('reraise on method2')) + + # Clear so that the last one is not hit. + json_facade.write_set_exception_breakpoints([]) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.parametrize('target_file', [ + '_debugger_case_unhandled_exceptions.py', + '_debugger_case_unhandled_exceptions_custom.py' + ]) +def test_case_unhandled_exception(case_setup, target_file): + + def check_test_suceeded_msg(writer, stdout, stderr): + # Don't call super (we have an unhandled exception in the stack trace). + return 'TEST SUCEEDED' in ''.join(stdout) and 'TEST SUCEEDED' in ''.join(stderr) + + def additional_output_checks(writer, stdout, stderr): + if 'raise MyError' not in stderr and 'raise Exception' not in stderr: + raise AssertionError('Expected test to have an unhandled exception.\nstdout:\n%s\n\nstderr:\n%s' % ( + stdout, stderr)) + + with case_setup.test_file( + target_file, + check_test_suceeded_msg=check_test_suceeded_msg, + additional_output_checks=additional_output_checks, + EXPECTED_RETURNCODE=1, + ) as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + json_facade.write_set_exception_breakpoints(['uncaught']) + json_facade.write_make_initial_run() + + line_in_thread1 = writer.get_line_index_with_content('in thread 1') + line_in_thread2 = writer.get_line_index_with_content('in thread 2') + line_in_main = writer.get_line_index_with_content('in main') + json_facade.wait_for_thread_stopped( + reason='exception', line=(line_in_thread1, line_in_thread2), file=target_file) + json_facade.write_continue() + + json_facade.wait_for_thread_stopped( + reason='exception', line=(line_in_thread1, line_in_thread2), file=target_file) + json_facade.write_continue() + + json_facade.wait_for_thread_stopped( + reason='exception', line=line_in_main, file=target_file) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_sys_exit_unhandled_exception(case_setup): + + with case_setup.test_file('_debugger_case_sysexit.py', EXPECTED_RETURNCODE=1) as writer: + json_facade = JsonFacade(writer) + json_facade.write_set_exception_breakpoints(['uncaught']) + json_facade.write_make_initial_run() + + break_line = writer.get_line_index_with_content('sys.exit(1)') + json_facade.wait_for_thread_stopped( + reason='exception', line=break_line) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.parametrize('break_on_system_exit_zero', [True, False]) +def test_case_sys_exit_0_unhandled_exception(case_setup, break_on_system_exit_zero): + + with case_setup.test_file('_debugger_case_sysexit_0.py', EXPECTED_RETURNCODE=0) as writer: + json_facade = JsonFacade(writer) + json_facade.write_launch( + debugOptions=['BreakOnSystemExitZero'] if break_on_system_exit_zero else [], + ) + json_facade.write_set_exception_breakpoints(['uncaught']) + json_facade.write_make_initial_run() + + break_line = writer.get_line_index_with_content('sys.exit(0)') + if break_on_system_exit_zero: + json_facade.wait_for_thread_stopped( + reason='exception', line=break_line) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.parametrize('break_on_system_exit_zero', [True, False]) +def test_case_sys_exit_0_handled_exception(case_setup, break_on_system_exit_zero): + + with case_setup.test_file('_debugger_case_sysexit_0.py', EXPECTED_RETURNCODE=0) as writer: + json_facade = JsonFacade(writer) + json_facade.write_launch( + debugOptions=['BreakOnSystemExitZero'] if break_on_system_exit_zero else [], + ) + json_facade.write_set_exception_breakpoints(['raised']) + json_facade.write_make_initial_run() + + break_line = writer.get_line_index_with_content('sys.exit(0)') + break_main_line = writer.get_line_index_with_content('call_main_line') + if break_on_system_exit_zero: + json_facade.wait_for_thread_stopped( + reason='exception', line=break_line) + json_facade.write_continue() + + json_facade.wait_for_thread_stopped( + reason='exception', line=break_main_line) + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_handled_exception_breaks_by_type(case_setup): + with case_setup.test_file('_debugger_case_exceptions.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + json_facade.write_set_exception_breakpoints(exception_options=[ + ExceptionOptions(breakMode='always', path=[ + {'names': ['Python Exceptions']}, + {'names': ['IndexError']}, + ]) + ]) + json_facade.write_make_initial_run() + + json_facade.wait_for_thread_stopped( + reason='exception', line=writer.get_line_index_with_content('raise indexerror line')) + + # Deal only with RuntimeErorr now. + json_facade.write_set_exception_breakpoints(exception_options=[ + ExceptionOptions(breakMode='always', path=[ + {'names': ['Python Exceptions']}, + {'names': ['RuntimeError']}, + ]) + ]) + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_json_protocol(case_setup): + with case_setup.test_file('_debugger_case_print.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + break_line = writer.get_line_index_with_content('Break here') + json_facade.write_set_breakpoints(break_line) + json_facade.write_make_initial_run() + + json_facade.wait_for_json_message(ThreadEvent, lambda event: event.body.reason == 'started') + + json_facade.wait_for_thread_stopped(line=break_line) + + # : :type response: ThreadsResponse + response = json_facade.write_list_threads() + assert len(response.body.threads) == 1 + assert next(iter(response.body.threads))['name'] == 'MainThread' + + # Removes breakpoints and proceeds running. + json_facade.write_disconnect(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_started_exited_threads_protocol(case_setup): + with case_setup.test_file('_debugger_case_thread_started_exited.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + break_line = writer.get_line_index_with_content('Break here') + json_facade.write_set_breakpoints(break_line) + + json_facade.write_make_initial_run() + + _stopped_event = json_facade.wait_for_json_message(StoppedEvent) + started_events = json_facade.mark_messages(ThreadEvent, lambda x: x.body.reason == 'started') + exited_events = json_facade.mark_messages(ThreadEvent, lambda x: x.body.reason == 'exited') + assert len(started_events) == 4 + assert len(exited_events) == 3 # Main is still running. + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_case_path_translation_not_skipped(case_setup): + import site + sys_folder = None + if hasattr(site, 'getusersitepackages'): + sys_folder = site.getusersitepackages() + + if not sys_folder and hasattr(site, 'getsitepackages'): + sys_folder = site.getsitepackages() + + if not sys_folder: + sys_folder = sys.prefix + + if isinstance(sys_folder, (list, tuple)): + sys_folder = next(iter(sys_folder)) + + with case_setup.test_file('my_code/my_code.py') as writer: + json_facade = JsonFacade(writer) + + # We need to set up path mapping to enable source references. + my_code = debugger_unittest._get_debugger_test_file('my_code') + + json_facade.write_launch( + debugOptions=['DebugStdLib'], + pathMappings=[{ + 'localRoot': sys_folder, + 'remoteRoot': my_code, + }] + ) + + bp_line = writer.get_line_index_with_content('break here') + json_facade.write_set_breakpoints( + bp_line, + filename=os.path.join(sys_folder, 'my_code.py'), + ) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped(line=bp_line) + + assert json_hit.stack_trace_response.body.stackFrames[-1]['source']['path'] == \ + os.path.join(sys_folder, 'my_code.py') + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.parametrize("custom_setup", [ + 'set_exclude_launch_module_full', + 'set_exclude_launch_module_prefix', + 'set_exclude_launch_path_match_filename', + 'set_exclude_launch_path_match_folder', + 'set_just_my_code', + 'set_just_my_code_and_include', +]) +def test_case_skipping_filters(case_setup, custom_setup): + with case_setup.test_file('my_code/my_code.py') as writer: + json_facade = JsonFacade(writer) + + expect_just_my_code = False + if custom_setup == 'set_exclude_launch_path_match_filename': + json_facade.write_launch( + debugOptions=['DebugStdLib'], + rules=[ + {'path': '**/other.py', 'include':False}, + ] + ) + + elif custom_setup == 'set_exclude_launch_path_match_folder': + not_my_code_dir = debugger_unittest._get_debugger_test_file('not_my_code') + json_facade.write_launch( + debugOptions=['DebugStdLib'], + rules=[ + {'path': not_my_code_dir, 'include':False}, + ] + ) + + other_filename = os.path.join(not_my_code_dir, 'other.py') + response = json_facade.write_set_breakpoints(1, filename=other_filename, verified=False) + assert response.body.breakpoints == [ + {'verified': False, 'message': 'Breakpoint in file excluded by filters.', 'source': {'path': other_filename}, 'line': 1}] + # Note: there's actually a use-case where we'd hit that breakpoint even if it was excluded + # by filters, so, we must actually clear it afterwards (the use-case is that when we're + # stepping into the context with the breakpoint we wouldn't skip it). + json_facade.write_set_breakpoints([], filename=other_filename) + + other_filename = os.path.join(not_my_code_dir, 'file_that_does_not_exist.py') + response = json_facade.write_set_breakpoints(1, filename=other_filename, verified=False) + assert response.body.breakpoints == [ + {'verified': False, 'message': 'Breakpoint in file that does not exist.', 'source': {'path': other_filename}, 'line': 1}] + + elif custom_setup == 'set_exclude_launch_module_full': + json_facade.write_launch( + debugOptions=['DebugStdLib'], + rules=[ + {'module': 'not_my_code.other', 'include':False}, + ] + ) + + elif custom_setup == 'set_exclude_launch_module_prefix': + json_facade.write_launch( + debugOptions=['DebugStdLib'], + rules=[ + {'module': 'not_my_code', 'include':False}, + ] + ) + + elif custom_setup == 'set_just_my_code': + expect_just_my_code = True + writer.write_set_project_roots([debugger_unittest._get_debugger_test_file('my_code')]) + json_facade.write_launch(debugOptions=[]) + + not_my_code_dir = debugger_unittest._get_debugger_test_file('not_my_code') + other_filename = os.path.join(not_my_code_dir, 'other.py') + response = json_facade.write_set_breakpoints( + 33, filename=other_filename, verified=False, expected_lines_in_response=[14]) + assert response.body.breakpoints == [{ + 'verified': False, + 'message': 'Breakpoint in file excluded by filters.\nNote: may be excluded because of "justMyCode" option (default == true).', + 'source': {'path': other_filename}, + 'line': 14 + }] + elif custom_setup == 'set_just_my_code_and_include': + expect_just_my_code = True + # I.e.: nothing in my_code (add it with rule). + writer.write_set_project_roots([debugger_unittest._get_debugger_test_file('launch')]) + json_facade.write_launch( + debugOptions=[], + rules=[ + {'module': '__main__', 'include':True}, + ] + ) + + else: + raise AssertionError('Unhandled: %s' % (custom_setup,)) + + break_line = writer.get_line_index_with_content('break here') + json_facade.write_set_breakpoints(break_line) + json_facade.write_make_initial_run() + + json_facade.wait_for_json_message(ThreadEvent, lambda event: event.body.reason == 'started') + + json_hit = json_facade.wait_for_thread_stopped(line=break_line) + + json_facade.write_step_in(json_hit.thread_id) + + json_hit = json_facade.wait_for_thread_stopped('step', name='callback1') + + messages = json_facade.mark_messages( + OutputEvent, lambda output_event: 'Frame skipped from debugging during step-in.' in output_event.body.output) + assert len(messages) == 1 + found_just_my_code = 'Note: may have been skipped because of \"justMyCode\" option (default == true)' in next(iter(messages)).body.output + + assert found_just_my_code == expect_just_my_code + + json_facade.write_step_in(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='callback2') + + json_facade.write_step_next(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='callback1') + + json_facade.write_step_next(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='') + + json_facade.write_step_next(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='') + + json_facade.write_step_next(json_hit.thread_id) + + if IS_JYTHON: + json_facade.write_continue(wait_for_response=False) + else: + json_facade.write_step_next(json_hit.thread_id, wait_for_response=False) + + # Check that it's sent only once. + assert len(json_facade.mark_messages( + OutputEvent, lambda output_event: 'Frame skipped from debugging during step-in.' in output_event.body.output)) == 0 + + writer.finished_ok = True + + +def test_case_completions_json(case_setup): + with case_setup.test_file('_debugger_case_completions.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + first_hit = None + for i in range(2): + json_hit = json_facade.wait_for_thread_stopped() + + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + if i == 0: + first_hit = json_hit + + completions_arguments = pydevd_schema.CompletionsArguments( + 'dict.', 6, frameId=json_hit.frame_id, line=0) + completions_request = json_facade.write_request( + pydevd_schema.CompletionsRequest(completions_arguments)) + + response = json_facade.wait_for_response(completions_request) + assert response.success + labels = [x['label'] for x in response.body.targets] + assert set(labels).issuperset(set(['__contains__', 'items', 'keys', 'values'])) + + completions_arguments = pydevd_schema.CompletionsArguments( + 'dict.item', 10, frameId=json_hit.frame_id) + completions_request = json_facade.write_request( + pydevd_schema.CompletionsRequest(completions_arguments)) + + response = json_facade.wait_for_response(completions_request) + assert response.success + if IS_JYTHON: + assert response.body.targets == [ + {'start': 5, 'length': 4, 'type': 'keyword', 'label': 'items'}] + else: + assert response.body.targets == [ + {'start': 5, 'length': 4, 'type': 'function', 'label': 'items'}] + + if i == 1: + # Check with a previously existing frameId. + assert first_hit.frame_id != json_hit.frame_id + completions_arguments = pydevd_schema.CompletionsArguments( + 'dict.item', 10, frameId=first_hit.frame_id) + completions_request = json_facade.write_request( + pydevd_schema.CompletionsRequest(completions_arguments)) + + response = json_facade.wait_for_response(completions_request) + assert not response.success + assert response.message == 'Thread to get completions seems to have resumed already.' + + # Check with a never frameId which never existed. + completions_arguments = pydevd_schema.CompletionsArguments( + 'dict.item', 10, frameId=99999) + completions_request = json_facade.write_request( + pydevd_schema.CompletionsRequest(completions_arguments)) + + response = json_facade.wait_for_response(completions_request) + assert not response.success + assert response.message.startswith('Wrong ID sent from the client:') + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_modules(case_setup): + with case_setup.test_file('_debugger_case_local_variables.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break 2 here')) + json_facade.write_make_initial_run() + + stopped_event = json_facade.wait_for_json_message(StoppedEvent) + thread_id = stopped_event.body.threadId + + json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=thread_id))) + + json_facade.wait_for_json_message(ModuleEvent) + + # : :type response: ModulesResponse + # : :type modules_response_body: ModulesResponseBody + response = json_facade.wait_for_response(json_facade.write_request( + pydevd_schema.ModulesRequest(pydevd_schema.ModulesArguments()))) + modules_response_body = response.body + assert len(modules_response_body.modules) == 1 + module = next(iter(modules_response_body.modules)) + assert module['name'] == '__main__' + assert module['path'].endswith('_debugger_case_local_variables.py') + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Putting unicode on frame vars does not work on Jython.') +def test_stack_and_variables_dict(case_setup): + with case_setup.test_file('_debugger_case_local_variables.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break 2 here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + + variables_response = json_facade.get_variables_response(json_hit.frame_id) + + variables_references = json_facade.pop_variables_reference(variables_response.body.variables) + dict_variable_reference = variables_references[2] + assert isinstance(dict_variable_reference, int_types) + # : :type variables_response: VariablesResponse + + if IS_PY2: + print(repr(variables_response.body.variables[-1])) + expected_unicode = { + u'name': u'\u16a0', + u'value': u"u'\\u16a1'", + u'type': u'unicode', + u'presentationHint': {u'attributes': [u'rawString']}, + u'evaluateName': u'\u16a0', + } + else: + expected_unicode = { + 'name': u'\u16A0', + 'value': "'\u16a1'", + 'type': 'str', + 'presentationHint': {'attributes': ['rawString']}, + 'evaluateName': u'\u16A0', + } + assert variables_response.body.variables == [ + {'name': 'variable_for_test_1', 'value': '10', 'type': 'int', 'evaluateName': 'variable_for_test_1'}, + {'name': 'variable_for_test_2', 'value': '20', 'type': 'int', 'evaluateName': 'variable_for_test_2'}, + {'name': 'variable_for_test_3', 'value': "{'a': 30, 'b': 20}", 'type': 'dict', 'evaluateName': 'variable_for_test_3'}, + expected_unicode + ] + + variables_response = json_facade.get_variables_response(dict_variable_reference) + assert variables_response.body.variables == [ + {'name': "'a'", 'value': '30', 'type': 'int', 'evaluateName': "variable_for_test_3['a']", 'variablesReference': 0 }, + {'name': "'b'", 'value': '20', 'type': 'int', 'evaluateName': "variable_for_test_3['b']", 'variablesReference': 0}, + {'name': '__len__', 'value': '2', 'type': 'int', 'evaluateName': 'len(variable_for_test_3)', 'variablesReference': 0, 'presentationHint': {'attributes': ['readOnly']}} + ] + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +def test_return_value(case_setup): + with case_setup.test_file('_debugger_case_return_value.py') as writer: + json_facade = JsonFacade(writer) + + break_line = writer.get_line_index_with_content('break here') + json_facade.write_launch(debugOptions=['ShowReturnValue']) + json_facade.write_set_breakpoints(break_line) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_facade.write_step_next(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='', line=break_line + 1) + + variables_response = json_facade.get_variables_response(json_hit.frame_id) + return_variables = json_facade.filter_return_variables(variables_response.body.variables) + assert return_variables == [{ + 'name': '(return) method1', + 'value': '1', + 'type': 'int', + 'evaluateName': "__pydevd_ret_val_dict['method1']", + 'presentationHint': {'attributes': ['readOnly']}, + 'variablesReference': 0, + }] + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +def test_stack_and_variables_set_and_list(case_setup): + with case_setup.test_file('_debugger_case_local_variables2.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + variables_response = json_facade.get_variables_response(json_hit.frame_id) + + variables_references = json_facade.pop_variables_reference(variables_response.body.variables) + if IS_PY2: + expected_set = "set(['a'])" + else: + expected_set = "{'a'}" + assert variables_response.body.variables == [ + {'type': 'list', 'evaluateName': 'variable_for_test_1', 'name': 'variable_for_test_1', 'value': "['a', 'b']"}, + {'type': 'set', 'evaluateName': 'variable_for_test_2', 'name': 'variable_for_test_2', 'value': expected_set} + ] + + variables_response = json_facade.get_variables_response(variables_references[0]) + assert variables_response.body.variables == [{ + u'name': u'0', + u'type': u'str', + u'value': u"'a'", + u'presentationHint': {u'attributes': [u'rawString']}, + u'evaluateName': u'variable_for_test_1[0]', + u'variablesReference': 0, + }, + { + u'name': u'1', + u'type': u'str', + u'value': u"'b'", + u'presentationHint': {u'attributes': [u'rawString']}, + u'evaluateName': u'variable_for_test_1[1]', + u'variablesReference': 0, + }, + { + u'name': u'__len__', + u'type': u'int', + u'value': u'2', + u'evaluateName': u'len(variable_for_test_1)', + u'variablesReference': 0, + u'presentationHint': {'attributes': ['readOnly']}, + }] + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Putting unicode on frame vars does not work on Jython.') +def test_evaluate_unicode(case_setup): + from _pydevd_bundle._debug_adapter.pydevd_schema import EvaluateRequest + from _pydevd_bundle._debug_adapter.pydevd_schema import EvaluateArguments + with case_setup.test_file('_debugger_case_local_variables.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break 2 here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + + evaluate_response = json_facade.wait_for_response( + json_facade.write_request(EvaluateRequest(EvaluateArguments(u'\u16A0', json_hit.frame_id)))) + + evaluate_response_body = evaluate_response.body.to_dict() + + if IS_PY2: + # The error can be referenced. + variables_reference = json_facade.pop_variables_reference([evaluate_response_body]) + + assert evaluate_response_body == { + 'result': u"SyntaxError('invalid syntax', ('', 1, 1, '\\xe1\\x9a\\xa0'))", + 'type': u'SyntaxError', + 'presentationHint': {}, + } + + assert len(variables_reference) == 1 + reference = variables_reference[0] + assert reference > 0 + variables_response = json_facade.get_variables_response(reference) + child_variables = variables_response.to_dict()['body']['variables'] + assert len(child_variables) == 1 + assert json_facade.pop_variables_reference(child_variables)[0] > 0 + assert child_variables == [{ + u'type': u'SyntaxError', + u'evaluateName': u'\u16a0.result', + u'name': u'result', + u'value': u"SyntaxError('invalid syntax', ('', 1, 1, '\\xe1\\x9a\\xa0'))" + }] + + else: + assert evaluate_response_body == { + 'result': "'\u16a1'", + 'type': 'str', + 'variablesReference': 0, + 'presentationHint': {'attributes': ['rawString']}, + } + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +def test_evaluate_variable_references(case_setup): + from _pydevd_bundle._debug_adapter.pydevd_schema import EvaluateRequest + from _pydevd_bundle._debug_adapter.pydevd_schema import EvaluateArguments + with case_setup.test_file('_debugger_case_local_variables2.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + + evaluate_response = json_facade.wait_for_response( + json_facade.write_request(EvaluateRequest(EvaluateArguments('variable_for_test_2', json_hit.frame_id)))) + + evaluate_response_body = evaluate_response.body.to_dict() + + variables_reference = json_facade.pop_variables_reference([evaluate_response_body]) + + assert evaluate_response_body == { + 'type': 'set', + 'result': "set(['a'])" if IS_PY2 else "{'a'}", + 'presentationHint': {}, + } + assert len(variables_reference) == 1 + reference = variables_reference[0] + assert reference > 0 + variables_response = json_facade.get_variables_response(reference) + child_variables = variables_response.to_dict()['body']['variables'] + + # The name for a reference in a set is the id() of the variable and can change at each run. + del child_variables[0]['name'] + + assert child_variables == [ + { + 'type': 'str', + 'value': "'a'", + 'presentationHint': {'attributes': ['rawString']}, + 'variablesReference': 0, + }, + { + 'name': '__len__', + 'type': 'int', + 'value': '1', + 'presentationHint': {'attributes': ['readOnly']}, + 'evaluateName': 'len(variable_for_test_2)', + 'variablesReference': 0, + } + ] + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +def test_set_expression(case_setup): + from _pydevd_bundle._debug_adapter.pydevd_schema import SetExpressionRequest + from _pydevd_bundle._debug_adapter.pydevd_schema import SetExpressionArguments + with case_setup.test_file('_debugger_case_local_variables2.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + + set_expression_response = json_facade.wait_for_response( + json_facade.write_request(SetExpressionRequest( + SetExpressionArguments('bb', '20', frameId=json_hit.frame_id)))) + assert set_expression_response.to_dict()['body'] == { + 'value': '20', 'type': 'int', 'presentationHint': {}, 'variablesReference': 0} + + variables_response = json_facade.get_variables_response(json_hit.frame_id) + assert {'name': 'bb', 'value': '20', 'type': 'int', 'evaluateName': 'bb', 'variablesReference': 0} in \ + variables_response.to_dict()['body']['variables'] + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +def test_set_expression_failures(case_setup): + from _pydevd_bundle._debug_adapter.pydevd_schema import SetExpressionRequest + from _pydevd_bundle._debug_adapter.pydevd_schema import SetExpressionArguments + + with case_setup.test_file('_debugger_case_local_variables2.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + + set_expression_response = json_facade.wait_for_response( + json_facade.write_request(SetExpressionRequest( + SetExpressionArguments('frame_not_there', '10', frameId=0)))) + assert not set_expression_response.success + assert set_expression_response.message == 'Unable to find thread to set expression.' + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_get_variable_errors(case_setup): + with case_setup.test_file('_debugger_case_completions.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + # First, try with wrong id. + response = json_facade.get_variables_response(9999, success=False) + assert response.message == 'Wrong ID sent from the client: 9999' + + first_hit = None + for i in range(2): + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + if i == 0: + first_hit = json_hit + + if i == 1: + # Now, check with a previously existing frameId. + response = json_facade.get_variables_response(first_hit.frame_id, success=False) + assert response.message == 'Unable to find thread to evaluate variable reference.' + + json_facade.write_continue(wait_for_response=i == 0) + if i == 0: + json_hit = json_facade.wait_for_thread_stopped() + + writer.finished_ok = True + + +def test_set_variable_failure(case_setup): + with case_setup.test_file('_debugger_case_local_variables2.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_facade.wait_for_thread_stopped() + + # Wrong frame + set_variable_response = json_facade.write_set_variable(0, 'invalid_reference', 'invalid_reference', success=False) + assert not set_variable_response.success + assert set_variable_response.message == 'Unable to find thread to evaluate variable reference.' + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def _check_list(json_facade, json_hit): + + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_1') + assert variable.value == "['a', 'b', self.var1: 11]" + + var0 = json_facade.get_var(variable.variablesReference, '0') + + json_facade.write_set_variable(variable.variablesReference, var0.name, '1') + + # Check that it was actually changed. + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_1') + assert variable.value == "[1, 'b', self.var1: 11]" + + var1 = json_facade.get_var(variable.variablesReference, 'var1') + + json_facade.write_set_variable(variable.variablesReference, var1.name, '2') + + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_1') + assert variable.value == "[1, 'b', self.var1: 2]" + + +def _check_tuple(json_facade, json_hit): + + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_4') + assert variable.value == "tuple('a', 1, self.var1: 13)" + + var0 = json_facade.get_var(variable.variablesReference, '0') + + response = json_facade.write_set_variable(variable.variablesReference, var0.name, '1', success=False) + assert response.message.startswith("Unable to change: ") + + var1 = json_facade.get_var(variable.variablesReference, 'var1') + json_facade.write_set_variable(variable.variablesReference, var1.name, '2') + + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_4') + assert variable.value == "tuple('a', 1, self.var1: 2)" + + +def _check_dict_subclass(json_facade, json_hit): + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_3') + assert variable.value == "{in_dct: 20; self.var1: 10}" + + var1 = json_facade.get_var(variable.variablesReference, 'var1') + + json_facade.write_set_variable(variable.variablesReference, var1.name, '2') + + # Check that it was actually changed. + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_3') + assert variable.value == "{in_dct: 20; self.var1: 2}" + + var_in_dct = json_facade.get_var(variable.variablesReference, "'in_dct'") + + json_facade.write_set_variable(variable.variablesReference, var_in_dct.name, '5') + + # Check that it was actually changed. + variable = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_3') + assert variable.value == "{in_dct: 5; self.var1: 2}" + + +def _check_set(json_facade, json_hit): + set_var = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_2') + + assert set_var.value == "set(['a', self.var1: 12])" + + var_in_set = json_facade.get_var(set_var.variablesReference, index=1) + assert var_in_set.name != 'var1' + + set_variables_response = json_facade.write_set_variable(set_var.variablesReference, var_in_set.name, '1') + assert set_variables_response.body.type == "int" + assert set_variables_response.body.value == "1" + + # Check that it was actually changed (which for a set means removing the existing entry + # and adding a new one). + set_var = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_2') + assert set_var.value == "set([1, self.var1: 12])" + + # Check that it can be changed again. + var_in_set = json_facade.get_var(set_var.variablesReference, index=1) + + # Check that adding a mutable object to the set does not work. + response = json_facade.write_set_variable(set_var.variablesReference, var_in_set.name, '[22]', success=False) + assert response.message.startswith('Unable to change: ') + + # Check that it's still the same (the existing entry was not removed). + assert json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_2').value == "set([1, self.var1: 12])" + + set_variables_response = json_facade.write_set_variable(set_var.variablesReference, var_in_set.name, '(22,)') + assert set_variables_response.body.type == "tuple" + assert set_variables_response.body.value == "(22,)" + + # Check that the tuple created can be accessed and is correct in the response. + var_in_tuple_in_set = json_facade.get_var(set_variables_response.body.variablesReference, '0') + assert var_in_tuple_in_set.name == '0' + assert var_in_tuple_in_set.value == '22' + + # Check that we can change the variable in the instance. + var1 = json_facade.get_var(set_var.variablesReference, 'var1') + + json_facade.write_set_variable(set_var.variablesReference, var1.name, '2') + + # Check that it was actually changed. + set_var = json_facade.get_local_var(json_hit.frame_id, 'variable_for_test_2') + assert set_var.value == "set([(22,), self.var1: 2])" + + +@pytest.mark.parametrize('_check_func', [ + _check_tuple, + _check_set, + _check_list, + _check_dict_subclass, +]) +def test_set_variable_multiple_cases(case_setup, _check_func): + with case_setup.test_file('_debugger_case_local_variables3.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + _check_func(json_facade, json_hit) + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Putting unicode on frame vars does not work on Jython.') +def test_stack_and_variables(case_setup): + + with case_setup.test_file('_debugger_case_local_variables.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + # : :type stack_trace_response: StackTraceResponse + # : :type stack_trace_response_body: StackTraceResponseBody + # : :type stack_frame: StackFrame + + # Check stack trace format. + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments( + threadId=json_hit.thread_id, + format={'module': True, 'line': True} + ))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + stack_frame = next(iter(stack_trace_response_body.stackFrames)) + assert stack_frame['name'] == '__main__.Call : 4' + + # Regular stack trace request (no format). + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + stack_trace_response = json_hit.stack_trace_response + stack_trace_response_body = stack_trace_response.body + assert len(stack_trace_response_body.stackFrames) == 2 + stack_frame = next(iter(stack_trace_response_body.stackFrames)) + assert stack_frame['name'] == 'Call' + assert stack_frame['source']['path'].endswith('_debugger_case_local_variables.py') + + name_to_scope = json_facade.get_name_to_scope(stack_frame['id']) + scope = name_to_scope['Locals'] + frame_variables_reference = scope.variablesReference + assert isinstance(frame_variables_reference, int) + + variables_response = json_facade.get_variables_response(frame_variables_reference) + # : :type variables_response: VariablesResponse + assert len(variables_response.body.variables) == 0 # No variables expected here + + json_facade.write_step_next(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step') + + variables_response = json_facade.get_variables_response(frame_variables_reference) + # : :type variables_response: VariablesResponse + assert variables_response.body.variables == [{ + 'name': 'variable_for_test_1', + 'value': '10', + 'type': 'int', + 'evaluateName': 'variable_for_test_1', + 'variablesReference': 0, + }] + + # Same thing with hex format + variables_response = json_facade.get_variables_response(frame_variables_reference, fmt={'hex': True}) + # : :type variables_response: VariablesResponse + assert variables_response.body.variables == [{ + 'name': 'variable_for_test_1', + 'value': '0xa', + 'type': 'int', + 'evaluateName': 'variable_for_test_1', + 'variablesReference': 0, + }] + + # Note: besides the scope/stack/variables we can also have references when: + # - setting variable + # * If the variable was changed to a container, the new reference should be returned. + # - evaluate expression + # * Currently ptvsd returns a None value in on_setExpression, so, skip this for now. + # - output + # * Currently not handled by ptvsd, so, skip for now. + + # Reference is for parent (in this case the frame). + # We'll change `variable_for_test_1` from 10 to [1]. + set_variable_response = json_facade.write_set_variable( + frame_variables_reference, 'variable_for_test_1', '[1]') + set_variable_response_as_dict = set_variable_response.to_dict()['body'] + if not IS_JYTHON: + # Not properly changing var on Jython. + assert isinstance(set_variable_response_as_dict.pop('variablesReference'), int) + assert set_variable_response_as_dict == {'value': "[1]", 'type': 'list'} + + variables_response = json_facade.get_variables_response(frame_variables_reference) + # : :type variables_response: VariablesResponse + variables = variables_response.body.variables + assert len(variables) == 1 + var_as_dict = next(iter(variables)) + if not IS_JYTHON: + # Not properly changing var on Jython. + assert isinstance(var_as_dict.pop('variablesReference'), int) + assert var_as_dict == { + 'name': 'variable_for_test_1', + 'value': "[1]", + 'type': 'list', + 'evaluateName': 'variable_for_test_1', + } + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_hex_variables(case_setup): + with case_setup.test_file('_debugger_case_local_variables_hex.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + # : :type stack_trace_response: StackTraceResponse + # : :type stack_trace_response_body: StackTraceResponseBody + # : :type stack_frame: StackFrame + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=json_hit.thread_id))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + assert len(stack_trace_response_body.stackFrames) == 2 + stack_frame = next(iter(stack_trace_response_body.stackFrames)) + assert stack_frame['name'] == 'Call' + assert stack_frame['source']['path'].endswith('_debugger_case_local_variables_hex.py') + + name_to_scope = json_facade.get_name_to_scope(stack_frame['id']) + + scope = name_to_scope['Locals'] + frame_variables_reference = scope.variablesReference + assert isinstance(frame_variables_reference, int) + + fmt = {'hex': True} + variables_request = json_facade.write_request( + pydevd_schema.VariablesRequest(pydevd_schema.VariablesArguments(frame_variables_reference, format=fmt))) + variables_response = json_facade.wait_for_response(variables_request) + + # : :type variables_response: VariablesResponse + variable_for_test_1, variable_for_test_2, variable_for_test_3, variable_for_test_4 = sorted(list( + v for v in variables_response.body.variables if v['name'].startswith('variables_for_test') + ), key=lambda v: v['name']) + assert variable_for_test_1 == { + 'name': 'variables_for_test_1', + 'value': "0x64", + 'type': 'int', + 'evaluateName': 'variables_for_test_1', + 'variablesReference': 0, + } + + assert isinstance(variable_for_test_2.pop('variablesReference'), int) + assert variable_for_test_2 == { + 'name': 'variables_for_test_2', + 'value': "[0x1, 0xa, 0x64]", + 'type': 'list', + 'evaluateName': 'variables_for_test_2' + } + + assert isinstance(variable_for_test_3.pop('variablesReference'), int) + assert variable_for_test_3 == { + 'name': 'variables_for_test_3', + 'value': '{0xa: 0xa, 0x64: 0x64, 0x3e8: 0x3e8}', + 'type': 'dict', + 'evaluateName': 'variables_for_test_3' + } + + assert isinstance(variable_for_test_4.pop('variablesReference'), int) + assert variable_for_test_4 == { + 'name': 'variables_for_test_4', + 'value': '{(0x1, 0xa, 0x64): (0x2710, 0x186a0, 0x186a0)}', + 'type': 'dict', + 'evaluateName': 'variables_for_test_4' + } + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_stopped_event(case_setup): + with case_setup.test_file('_debugger_case_print.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + assert json_hit.thread_id + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Not Jython compatible (fails on set variable).') +def test_pause_and_continue(case_setup): + with case_setup.test_file('_debugger_case_pause_continue.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_facade.wait_for_thread_stopped() + + json_facade.write_continue() + + json_facade.write_pause() + + json_hit = json_facade.wait_for_thread_stopped(reason="pause") + + stack_frame = next(iter(json_hit.stack_trace_response.body.stackFrames)) + + name_to_scope = json_facade.get_name_to_scope(stack_frame['id']) + frame_variables_reference = name_to_scope['Locals'].variablesReference + + set_variable_response = json_facade.write_set_variable(frame_variables_reference, 'loop', 'False') + set_variable_response_as_dict = set_variable_response.to_dict()['body'] + assert set_variable_response_as_dict == {'value': "False", 'type': 'bool', 'variablesReference': 0} + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.parametrize('stepping_resumes_all_threads', [False, True]) +def test_step_out_multi_threads(case_setup, stepping_resumes_all_threads): + with case_setup.test_file('_debugger_case_multi_threads_stepping.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch(steppingResumesAllThreads=stepping_resumes_all_threads) + json_facade.write_set_breakpoints([ + writer.get_line_index_with_content('Break thread 1'), + ]) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + response = json_facade.write_list_threads() + assert len(response.body.threads) == 3 + + thread_name_to_id = dict((t['name'], t['id']) for t in response.body.threads) + assert json_hit.thread_id == thread_name_to_id['thread1'] + + if stepping_resumes_all_threads: + # If we're stepping with multiple threads, we'll exit here. + json_facade.write_step_out(thread_name_to_id['thread1'], wait_for_response=False) + else: + json_facade.write_step_out(thread_name_to_id['thread1']) + + # Timeout is expected... make it shorter. + writer.reader_thread.set_messages_timeout(2) + try: + json_hit = json_facade.wait_for_thread_stopped('step') + raise AssertionError('Expected timeout!') + except debugger_unittest.TimeoutError: + pass + + json_facade.write_step_out(thread_name_to_id['thread2']) + json_facade.write_step_next(thread_name_to_id['MainThread']) + json_hit = json_facade.wait_for_thread_stopped('step') + assert json_hit.thread_id == thread_name_to_id['MainThread'] + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.parametrize('stepping_resumes_all_threads', [True, False]) +@pytest.mark.parametrize('step_mode', ['step_next', 'step_in']) +def test_step_next_step_in_multi_threads(case_setup, stepping_resumes_all_threads, step_mode): + with case_setup.test_file('_debugger_case_multi_threads_stepping.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch(steppingResumesAllThreads=stepping_resumes_all_threads) + json_facade.write_set_breakpoints([ + writer.get_line_index_with_content('Break thread 1'), + ]) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + response = json_facade.write_list_threads() + assert len(response.body.threads) == 3 + + thread_name_to_id = dict((t['name'], t['id']) for t in response.body.threads) + assert json_hit.thread_id == thread_name_to_id['thread1'] + + for _i in range(20): + if step_mode == 'step_next': + json_facade.write_step_next(thread_name_to_id['thread1']) + + elif step_mode == 'step_in': + json_facade.write_step_in(thread_name_to_id['thread1']) + + else: + raise AssertionError('Unexpected step_mode: %s' % (step_mode,)) + + json_hit = json_facade.wait_for_thread_stopped('step') + assert json_hit.thread_id == thread_name_to_id['thread1'] + local_var = json_facade.get_local_var(json_hit.frame_id, '_event2_set') + + # We're stepping in a single thread which depends on events being set in + # another thread, so, we can only get here if the other thread was also released. + if local_var.value == 'True': + if stepping_resumes_all_threads: + break + else: + raise AssertionError('Did not expect _event2_set to be set when not resuming other threads on step.') + + time.sleep(.01) + else: + if stepping_resumes_all_threads: + raise AssertionError('Expected _event2_set to be set already.') + else: + # That's correct, we should never reach the condition where _event2_set is set if + # we're not resuming other threads on step. + pass + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_stepping(case_setup): + with case_setup.test_file('_debugger_case_stepping.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch(debugOptions=['DebugStdLib']) + json_facade.write_set_breakpoints([ + writer.get_line_index_with_content('Break here 1'), + writer.get_line_index_with_content('Break here 2') + ]) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + # Test Step-Over or 'next' + stack_trace_response = json_hit.stack_trace_response + stack_frame = next(iter(stack_trace_response.body.stackFrames)) + before_step_over_line = stack_frame['line'] + + json_facade.write_step_next(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', line=before_step_over_line + 1) + + # Test step into or 'stepIn' + json_facade.write_step_in(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='step_into') + + # Test step return or 'stepOut' + json_facade.write_continue() + json_hit = json_facade.wait_for_thread_stopped(name='step_out') + + json_facade.write_step_out(json_hit.thread_id) + json_hit = json_facade.wait_for_thread_stopped('step', name='Call') + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_evaluate(case_setup): + with case_setup.test_file('_debugger_case_evaluate.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=json_hit.thread_id))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_frame = next(iter(stack_trace_response.body.stackFrames)) + stack_frame_id = stack_frame['id'] + + # Test evaluate request that results in 'eval' + eval_request = json_facade.write_request( + pydevd_schema.EvaluateRequest(pydevd_schema.EvaluateArguments('var_1', frameId=stack_frame_id, context='repl'))) + eval_response = json_facade.wait_for_response(eval_request) + assert eval_response.body.result == '5' + assert eval_response.body.type == 'int' + + # Test evaluate request that results in 'exec' + exec_request = json_facade.write_request( + pydevd_schema.EvaluateRequest(pydevd_schema.EvaluateArguments('var_1 = 6', frameId=stack_frame_id, context='repl'))) + exec_response = json_facade.wait_for_response(exec_request) + assert exec_response.body.result == '' + + # Test evaluate request that results in 'exec' but fails + exec_request = json_facade.write_request( + pydevd_schema.EvaluateRequest(pydevd_schema.EvaluateArguments('var_1 = "abc"/6', frameId=stack_frame_id, context='repl'))) + exec_response = json_facade.wait_for_response(exec_request) + assert exec_response.success == False + assert exec_response.body.result.find('TypeError') > -1 + assert exec_response.message.find('TypeError') > -1 + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_evaluate_failures(case_setup): + with case_setup.test_file('_debugger_case_completions.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + # First, try with wrong id. + exec_request = json_facade.write_request( + pydevd_schema.EvaluateRequest(pydevd_schema.EvaluateArguments('a = 10', frameId=9999, context='repl'))) + exec_response = json_facade.wait_for_response(exec_request) + assert exec_response.success == False + assert exec_response.message == 'Wrong ID sent from the client: 9999' + + first_hit = None + for i in range(2): + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + if i == 0: + first_hit = json_hit + + if i == 1: + # Now, check with a previously existing frameId. + exec_request = json_facade.write_request( + pydevd_schema.EvaluateRequest(pydevd_schema.EvaluateArguments('a = 10', frameId=first_hit.frame_id, context='repl'))) + exec_response = json_facade.wait_for_response(exec_request) + assert exec_response.success == False + assert exec_response.message == 'Unable to find thread for evaluation.' + + json_facade.write_continue(wait_for_response=i == 0) + if i == 0: + json_hit = json_facade.wait_for_thread_stopped() + + writer.finished_ok = True + + +@pytest.mark.parametrize('max_frames', ['default', 'all', 10]) # -1 = default, 0 = all, 10 = 10 frames +def test_exception_details(case_setup, max_frames): + with case_setup.test_file('_debugger_case_large_exception_stack.py') as writer: + json_facade = JsonFacade(writer) + + if max_frames == 'all': + json_facade.write_launch(maxExceptionStackFrames=0) + # trace back compresses repeated text + min_expected_lines = 100 + max_expected_lines = 220 + elif max_frames == 'default': + json_facade.write_launch() + # default is all frames + # trace back compresses repeated text + min_expected_lines = 100 + max_expected_lines = 220 + else: + json_facade.write_launch(maxExceptionStackFrames=max_frames) + min_expected_lines = 10 + max_expected_lines = 21 + + json_facade.write_set_exception_breakpoints(['raised']) + + json_facade.write_make_initial_run() + json_hit = json_facade.wait_for_thread_stopped('exception') + + exc_info_request = json_facade.write_request( + pydevd_schema.ExceptionInfoRequest(pydevd_schema.ExceptionInfoArguments(json_hit.thread_id))) + exc_info_response = json_facade.wait_for_response(exc_info_request) + body = exc_info_response.body + assert body.exceptionId.endswith('IndexError') + assert body.description == 'foo' + assert normcase(body.details.kwargs['source']) == normcase(writer.TEST_FILE) + stack_line_count = len(body.details.stackTrace.split('\n')) + assert min_expected_lines <= stack_line_count <= max_expected_lines + + json_facade.write_set_exception_breakpoints([]) # Don't stop on reraises. + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_stack_levels(case_setup): + with case_setup.test_file('_debugger_case_deep_stacks.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + json_hit = json_facade.wait_for_thread_stopped() + + # get full stack + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=json_hit.thread_id))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + full_stack_frames = stack_trace_response.body.stackFrames + total_frames = stack_trace_response.body.totalFrames + + startFrame = 0 + levels = 20 + received_frames = [] + while startFrame < total_frames: + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments( + threadId=json_hit.thread_id, + startFrame=startFrame, + levels=20))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + received_frames += stack_trace_response.body.stackFrames + startFrame += levels + + assert full_stack_frames == received_frames + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_breakpoint_adjustment(case_setup): + with case_setup.test_file('_debugger_case_adjust_breakpoint.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch() + + bp_requested = writer.get_line_index_with_content('requested') + bp_expected = writer.get_line_index_with_content('expected') + + set_bp_request = json_facade.write_request( + pydevd_schema.SetBreakpointsRequest(pydevd_schema.SetBreakpointsArguments( + source=pydevd_schema.Source(path=writer.TEST_FILE, sourceReference=0), + breakpoints=[pydevd_schema.SourceBreakpoint(bp_requested).to_dict()])) + ) + set_bp_response = json_facade.wait_for_response(set_bp_request) + assert set_bp_response.success + assert set_bp_response.body.breakpoints[0]['line'] == bp_expected + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=json_hit.thread_id))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_frame = next(iter(stack_trace_response.body.stackFrames)) + assert stack_frame['line'] == bp_expected + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='No goto on Jython.') +def test_goto(case_setup): + with case_setup.test_file('_debugger_case_set_next_statement.py') as writer: + json_facade = JsonFacade(writer) + + break_line = writer.get_line_index_with_content('Break here') + step_line = writer.get_line_index_with_content('Step here') + json_facade.write_set_breakpoints(break_line) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=json_hit.thread_id))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_frame = next(iter(stack_trace_response.body.stackFrames)) + assert stack_frame['line'] == break_line + + goto_targets_request = json_facade.write_request( + pydevd_schema.GotoTargetsRequest(pydevd_schema.GotoTargetsArguments( + source=pydevd_schema.Source(path=writer.TEST_FILE, sourceReference=0), + line=step_line))) + goto_targets_response = json_facade.wait_for_response(goto_targets_request) + target_id = goto_targets_response.body.targets[0]['id'] + + goto_request = json_facade.write_request( + pydevd_schema.GotoRequest(pydevd_schema.GotoArguments( + threadId=json_hit.thread_id, + targetId=12345))) + goto_response = json_facade.wait_for_response(goto_request) + assert not goto_response.success + + goto_request = json_facade.write_request( + pydevd_schema.GotoRequest(pydevd_schema.GotoArguments( + threadId=json_hit.thread_id, + targetId=target_id))) + goto_response = json_facade.wait_for_response(goto_request) + + json_hit = json_facade.wait_for_thread_stopped('goto') + + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments(threadId=json_hit.thread_id))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_frame = next(iter(stack_trace_response.body.stackFrames)) + assert stack_frame['line'] == step_line + + json_facade.write_continue() + + # we hit the breakpoint again. Since we moved back + json_facade.wait_for_thread_stopped() + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def _collect_stack_frames_ending_with(json_hit, end_with_pattern): + stack_trace_response = json_hit.stack_trace_response + dont_trace_frames = list(frame for frame in stack_trace_response.body.stackFrames + if frame['source']['path'].endswith(end_with_pattern)) + return dont_trace_frames + + +def _check_dont_trace_filtered_out(json_hit): + assert _collect_stack_frames_ending_with(json_hit, 'dont_trace.py') == [] + + +def _check_dont_trace_not_filtered_out(json_hit): + assert len(_collect_stack_frames_ending_with(json_hit, 'dont_trace.py')) == 1 + + +@pytest.mark.parametrize('dbg_property', [ + 'dont_trace', + 'trace', + 'change_pattern', + 'dont_trace_after_start' +]) +def test_set_debugger_property(case_setup, dbg_property): + + kwargs = {} + + with case_setup.test_file('_debugger_case_dont_trace_test.py', **kwargs) as writer: + json_facade = JsonFacade(writer) + + json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here')) + + if dbg_property in ('dont_trace', 'change_pattern', 'dont_trace_after_start'): + json_facade.write_set_debugger_property([], ['dont_trace.py']) + + if dbg_property == 'change_pattern': + json_facade.write_set_debugger_property([], ['something_else.py']) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + if dbg_property in ('dont_trace', 'dont_trace_after_start'): + _check_dont_trace_filtered_out(json_hit) + + elif dbg_property in ('change_pattern', 'trace'): + _check_dont_trace_not_filtered_out(json_hit) + + else: + raise AssertionError('Unexpected: %s' % (dbg_property,)) + + if dbg_property == 'dont_trace_after_start': + json_facade.write_set_debugger_property([], ['something_else.py']) + + json_facade.write_continue() + json_hit = json_facade.wait_for_thread_stopped() + + if dbg_property in ('dont_trace',): + _check_dont_trace_filtered_out(json_hit) + + elif dbg_property in ('change_pattern', 'trace', 'dont_trace_after_start'): + _check_dont_trace_not_filtered_out(json_hit) + + else: + raise AssertionError('Unexpected: %s' % (dbg_property,)) + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +def test_source_mapping_errors(case_setup): + from _pydevd_bundle._debug_adapter.pydevd_schema import Source + from _pydevd_bundle._debug_adapter.pydevd_schema import PydevdSourceMap + + with case_setup.test_file('_debugger_case_source_mapping.py') as writer: + json_facade = JsonFacade(writer) + + map_to_cell_1_line2 = writer.get_line_index_with_content('map to cell1, line 2') + map_to_cell_2_line2 = writer.get_line_index_with_content('map to cell2, line 2') + + cell1_map = PydevdSourceMap(map_to_cell_1_line2, map_to_cell_1_line2 + 1, Source(path=''), 2) + cell2_map = PydevdSourceMap(map_to_cell_2_line2, map_to_cell_2_line2 + 1, Source(path=''), 2) + pydevd_source_maps = [ + cell1_map, cell2_map + ] + + json_facade.write_set_pydevd_source_map( + Source(path=writer.TEST_FILE), + pydevd_source_maps=pydevd_source_maps, + ) + # This will fail because file mappings must be 1:N, not M:N (i.e.: if there's a mapping from file1.py to , + # there can be no other mapping from any other file to ). + # This is a limitation to make it easier to remove existing breakpoints when new breakpoints are + # set to a file (so, any file matching that breakpoint can be removed instead of needing to check + # which lines are corresponding to that file). + json_facade.write_set_pydevd_source_map( + Source(path=os.path.join(os.path.dirname(writer.TEST_FILE), 'foo.py')), + pydevd_source_maps=pydevd_source_maps, + success=False, + ) + json_facade.write_make_initial_run() + + writer.finished_ok = True + + +def test_source_mapping(case_setup): + from _pydevd_bundle._debug_adapter.pydevd_schema import Source + from _pydevd_bundle._debug_adapter.pydevd_schema import PydevdSourceMap + + case_setup.check_non_ascii = True + + with case_setup.test_file('_debugger_case_source_mapping.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch( + debugOptions=['DebugStdLib'], + ) + + map_to_cell_1_line2 = writer.get_line_index_with_content('map to cell1, line 2') + map_to_cell_2_line2 = writer.get_line_index_with_content('map to cell2, line 2') + + cell1_map = PydevdSourceMap(map_to_cell_1_line2, map_to_cell_1_line2 + 1, Source(path=''), 2) + cell2_map = PydevdSourceMap(map_to_cell_2_line2, map_to_cell_2_line2 + 1, Source(path=''), 2) + pydevd_source_maps = [ + cell1_map, cell2_map, cell2_map, # The one repeated should be ignored. + ] + + # Set breakpoints before setting the source map (check that we reapply them). + json_facade.write_set_breakpoints(map_to_cell_1_line2) + + test_file = writer.TEST_FILE + if isinstance(test_file, bytes): + # file is in the filesystem encoding (needed for launch) but protocol needs it in utf-8 + test_file = test_file.decode(file_system_encoding) + test_file = test_file.encode('utf-8') + + json_facade.write_set_pydevd_source_map( + Source(path=test_file), + pydevd_source_maps=pydevd_source_maps, + ) + + json_facade.write_make_initial_run() + + json_facade.wait_for_thread_stopped(line=map_to_cell_1_line2, file=os.path.basename(test_file)) + # Check that we no longer stop at the cell1 breakpoint (its mapping should be removed when + # the new one is added and we should only stop at cell2). + json_facade.write_set_breakpoints(map_to_cell_2_line2) + json_facade.write_continue() + + json_facade.wait_for_thread_stopped(line=map_to_cell_2_line2, file=os.path.basename(test_file)) + json_facade.write_set_breakpoints([]) # Clears breakpoints + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.skipif(not TEST_CHERRYPY, reason='No CherryPy available') +def test_process_autoreload_cherrypy(case_setup_multiprocessing, tmpdir): + ''' + CherryPy does an os.execv(...) which will kill the running process and replace + it with a new process when a reload takes place, so, it mostly works as + a new process connection (everything is the same except that the + existing process is stopped). + ''' + port = get_free_port() + # We write a temp file because we'll change it to autoreload later on. + f = tmpdir.join('_debugger_case_cherrypy.py') + + tmplt = ''' +import cherrypy +cherrypy.config.update({ + 'engine.autoreload.on': True, + 'checker.on': False, + 'server.socket_port': %(port)s, +}) +class HelloWorld(object): + + @cherrypy.expose + def index(self): + print('TEST SUCEEDED') + return "Hello World %(str)s!" # break here + @cherrypy.expose('/exit') + def exit(self): + cherrypy.engine.exit() + +cherrypy.quickstart(HelloWorld()) +''' + + f.write(tmplt % dict(port=port, str='INITIAL')) + + file_to_check = str(f) + + def get_environ(writer): + env = os.environ.copy() + + env["PYTHONIOENCODING"] = 'utf-8' + env["PYTHONPATH"] = str(tmpdir) + return env + + import threading + from tests_python.debugger_unittest import AbstractWriterThread + with case_setup_multiprocessing.test_file(file_to_check, get_environ=get_environ) as writer: + + original_ignore_stderr_line = writer._ignore_stderr_line + + @overrides(writer._ignore_stderr_line) + def _ignore_stderr_line(line): + if original_ignore_stderr_line(line): + return True + return 'ENGINE ' in line or 'CherryPy Checker' in line or 'has an empty config' in line + + writer._ignore_stderr_line = _ignore_stderr_line + + json_facade = JsonFacade(writer) + json_facade.write_launch(debugOptions=['DebugStdLib']) + + break1_line = writer.get_line_index_with_content('break here') + json_facade.write_set_breakpoints(break1_line) + + server_socket = writer.server_socket + + class SecondaryProcessWriterThread(AbstractWriterThread): + + TEST_FILE = writer.get_main_filename() + _sequence = -1 + + class SecondaryProcessThreadCommunication(threading.Thread): + + def run(self): + from tests_python.debugger_unittest import ReaderThread + expected_connections = 1 + for _ in range(expected_connections): + server_socket.listen(1) + self.server_socket = server_socket + new_sock, addr = server_socket.accept() + + reader_thread = ReaderThread(new_sock) + reader_thread.name = ' *** Multiprocess Reader Thread' + reader_thread.start() + + writer2 = SecondaryProcessWriterThread() + + writer2.reader_thread = reader_thread + writer2.sock = new_sock + + writer2.write_version() + writer2.write_add_breakpoint(break1_line) + writer2.write_make_initial_run() + + # Give it some time to startup + time.sleep(2) + t = writer.create_request_thread('http://127.0.0.1:%s/' % (port,)) + t.start() + + hit = writer2.wait_for_breakpoint_hit() + writer2.write_run_thread(hit.thread_id) + + contents = t.wait_for_contents() + assert 'Hello World NEW!' in contents + + t = writer.create_request_thread('http://127.0.0.1:%s/exit' % (port,)) + t.start() + + secondary_process_thread_communication = SecondaryProcessThreadCommunication() + secondary_process_thread_communication.start() + json_facade.write_make_initial_run() + + # Give it some time to startup + time.sleep(2) + + t = writer.create_request_thread('http://127.0.0.1:%s/' % (port,)) + t.start() + json_facade.wait_for_thread_stopped() + json_facade.write_continue() + + contents = t.wait_for_contents() + assert 'Hello World INITIAL!' in contents + + # Sleep a bit more to make sure that the initial timestamp was gotten in the + # CherryPy background thread. + time.sleep(2) + f.write(tmplt % dict(port=port, str='NEW')) + + secondary_process_thread_communication.join(10) + if secondary_process_thread_communication.is_alive(): + raise AssertionError('The SecondaryProcessThreadCommunication did not finish') + writer.finished_ok = True + + +def test_wait_for_attach(case_setup_remote_attach_to): + host_port = get_socket_name(close=True) + + def check_thread_events(json_facade): + json_facade.write_list_threads() + # Check that we have the started thread event (whenever we reconnect). + started_events = json_facade.mark_messages(ThreadEvent, lambda x: x.body.reason == 'started') + assert len(started_events) == 1 + + def check_process_event(json_facade, start_method): + if start_method == 'attach': + json_facade.write_attach() + + elif start_method == 'launch': + json_facade.write_launch() + + else: + raise AssertionError('Unexpected: %s' % (start_method,)) + + process_events = json_facade.mark_messages(ProcessEvent) + assert len(process_events) == 1 + assert next(iter(process_events)).body.startMethod == start_method + + with case_setup_remote_attach_to.test_file('_debugger_case_wait_for_attach.py', host_port[1]) as writer: + time.sleep(.5) # Give some time for it to pass the first breakpoint and wait in 'wait_for_attach'. + writer.start_socket_client(*host_port) + + json_facade = JsonFacade(writer) + check_thread_events(json_facade) + + break1_line = writer.get_line_index_with_content('Break 1') + break2_line = writer.get_line_index_with_content('Break 2') + break3_line = writer.get_line_index_with_content('Break 3') + + pause1_line = writer.get_line_index_with_content('Pause 1') + pause2_line = writer.get_line_index_with_content('Pause 2') + + check_process_event(json_facade, start_method='launch') + json_facade.write_set_breakpoints([break1_line, break2_line, break3_line]) + json_facade.write_make_initial_run() + json_facade.wait_for_thread_stopped(line=break2_line) + + # Upon disconnect, all threads should be running again. + json_facade.write_disconnect() + + # Connect back (socket should remain open). + writer.start_socket_client(*host_port) + json_facade = JsonFacade(writer) + check_thread_events(json_facade) + check_process_event(json_facade, start_method='attach') + json_facade.write_set_breakpoints([break1_line, break2_line, break3_line]) + json_facade.write_make_initial_run() + json_facade.wait_for_thread_stopped(line=break3_line) + + # Upon disconnect, all threads should be running again. + json_facade.write_disconnect() + + # Connect back (socket should remain open). + writer.start_socket_client(*host_port) + json_facade = JsonFacade(writer) + check_thread_events(json_facade) + check_process_event(json_facade, start_method='attach') + json_facade.write_make_initial_run() + + # Connect back without a disconnect (auto-disconnects previous and connects new client). + writer.start_socket_client(*host_port) + json_facade = JsonFacade(writer) + check_thread_events(json_facade) + check_process_event(json_facade, start_method='attach') + json_facade.write_make_initial_run() + + json_facade.write_pause() + json_hit = json_facade.wait_for_thread_stopped(reason='pause', line=[pause1_line, pause2_line]) + + # Change value of 'a' for test to finish. + json_facade.write_set_variable(json_hit.frame_id, 'a', '10') + + json_facade.write_disconnect(wait_for_response=False) + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Flaky on Jython.') +def test_path_translation_and_source_reference(case_setup): + + translated_dir_not_ascii = u'áéíóú汉字' + + if IS_PY2: + translated_dir_not_ascii = translated_dir_not_ascii.encode(file_system_encoding) + + def get_file_in_client(writer): + # Instead of using: test_python/_debugger_case_path_translation.py + # we'll set the breakpoints at foo/_debugger_case_path_translation.py + file_in_client = os.path.dirname(os.path.dirname(writer.TEST_FILE)) + return os.path.join(os.path.dirname(file_in_client), translated_dir_not_ascii, '_debugger_case_path_translation.py') + + def get_environ(writer): + env = os.environ.copy() + + env["PYTHONIOENCODING"] = 'utf-8' + return env + + with case_setup.test_file('_debugger_case_path_translation.py', get_environ=get_environ) as writer: + file_in_client = get_file_in_client(writer) + assert 'tests_python' not in file_in_client + assert translated_dir_not_ascii in file_in_client + + json_facade = JsonFacade(writer) + + bp_line = writer.get_line_index_with_content('break here') + assert writer.TEST_FILE.endswith('_debugger_case_path_translation.py') + local_root = os.path.dirname(get_file_in_client(writer)) + if IS_PY2: + local_root = local_root.decode(file_system_encoding).encode('utf-8') + json_facade.write_launch(pathMappings=[{ + 'localRoot': local_root, + 'remoteRoot': os.path.dirname(writer.TEST_FILE), + }]) + json_facade.write_set_breakpoints(bp_line, filename=file_in_client) + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + + # : :type stack_trace_response: StackTraceResponse + # : :type stack_trace_response_body: StackTraceResponseBody + # : :type stack_frame: StackFrame + + # Check stack trace format. + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments( + threadId=json_hit.thread_id, + format={'module': True, 'line': True} + ))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + stack_frame = stack_trace_response_body.stackFrames[0] + assert stack_frame['name'] == '__main__.call_this : %s' % (bp_line,) + + path = stack_frame['source']['path'] + file_in_client_unicode = file_in_client + if IS_PY2: + if isinstance(path, bytes): + path = path.decode('utf-8') + if isinstance(file_in_client_unicode, bytes): + file_in_client_unicode = file_in_client_unicode.decode(file_system_encoding) + + assert path == file_in_client_unicode + source_reference = stack_frame['source']['sourceReference'] + assert source_reference == 0 # When it's translated the source reference must be == 0 + + stack_frame_not_path_translated = stack_trace_response_body.stackFrames[1] + assert stack_frame_not_path_translated['name'].startswith( + 'tests_python.resource_path_translation.other.call_me_back1 :') + + assert stack_frame_not_path_translated['source']['path'].endswith('other.py') + source_reference = stack_frame_not_path_translated['source']['sourceReference'] + assert source_reference != 0 # Not translated + + response = json_facade.wait_for_response(json_facade.write_request( + pydevd_schema.SourceRequest(pydevd_schema.SourceArguments(source_reference)))) + assert "def call_me_back1(callback):" in response.body.content + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_JYTHON, reason='Flaky on Jython.') +def test_source_reference_no_file(case_setup, tmpdir): + + with case_setup.test_file('_debugger_case_source_reference.py') as writer: + json_facade = JsonFacade(writer) + + json_facade.write_launch( + debugOptions=['DebugStdLib'], + pathMappings=[{ + 'localRoot': os.path.dirname(writer.TEST_FILE), + 'remoteRoot': os.path.dirname(writer.TEST_FILE), + }]) + + writer.write_add_breakpoint(writer.get_line_index_with_content('breakpoint')) + json_facade.write_make_initial_run() + + # First hit is for breakpoint reached via a stack frame that doesn't have source. + + json_hit = json_facade.wait_for_thread_stopped() + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments( + threadId=json_hit.thread_id, + format={'module': True, 'line': True} + ))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + stack_frame = stack_trace_response_body.stackFrames[1] + assert stack_frame['source']['path'] == '' + source_reference = stack_frame['source']['sourceReference'] + assert source_reference != 0 + + response = json_facade.wait_for_response(json_facade.write_request( + pydevd_schema.SourceRequest(pydevd_schema.SourceArguments(source_reference)))) + assert not response.success + + json_facade.write_continue() + + # First hit is for breakpoint reached via a stack frame that doesn't have source + # on disk, but which can be retrieved via linecache. + + json_hit = json_facade.wait_for_thread_stopped() + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments( + threadId=json_hit.thread_id, + format={'module': True, 'line': True} + ))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + stack_frame = stack_trace_response_body.stackFrames[1] + print(stack_frame['source']['path']) + assert stack_frame['source']['path'] == '' + source_reference = stack_frame['source']['sourceReference'] + assert source_reference != 0 + + response = json_facade.wait_for_response(json_facade.write_request( + pydevd_schema.SourceRequest(pydevd_schema.SourceArguments(source_reference)))) + assert response.success + assert response.body.content == 'foo()\n' + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +@pytest.mark.skipif(not TEST_DJANGO, reason='No django available') +@pytest.mark.parametrize("jmc", [False, True]) +def test_case_django_no_attribute_exception_breakpoint(case_setup_django, jmc): + django_version = [int(x) for x in django.get_version().split('.')][:2] + + if django_version < [2, 1]: + pytest.skip('Template exceptions only supporting Django 2.1 onwards.') + + with case_setup_django.test_file(EXPECTED_RETURNCODE='any') as writer: + json_facade = JsonFacade(writer) + + if jmc: + writer.write_set_project_roots([debugger_unittest._get_debugger_test_file('my_code')]) + json_facade.write_launch(debugOptions=['Django']) + json_facade.write_set_exception_breakpoints(['raised']) + else: + json_facade.write_launch(debugOptions=['DebugStdLib', 'Django']) + # Don't set to all 'raised' because we'd stop on standard library exceptions here + # (which is not something we want). + json_facade.write_set_exception_breakpoints(exception_options=[ + ExceptionOptions(breakMode='always', path=[ + {'names': ['Python Exceptions']}, + {'names': ['AssertionError']}, + ]) + ]) + + writer.write_make_initial_run() + + t = writer.create_request_thread('my_app/template_error') + time.sleep(5) # Give django some time to get to startup before requesting the page + t.start() + + json_hit = json_facade.wait_for_thread_stopped('exception', line=7, file='template_error.html') + + stack_trace_request = json_facade.write_request( + pydevd_schema.StackTraceRequest(pydevd_schema.StackTraceArguments( + threadId=json_hit.thread_id, + format={'module': True, 'line': True} + ))) + stack_trace_response = json_facade.wait_for_response(stack_trace_request) + stack_trace_response_body = stack_trace_response.body + stack_frame = next(iter(stack_trace_response_body.stackFrames)) + assert stack_frame['source']['path'].endswith('template_error.html') + + json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) + variables_response = json_facade.get_variables_response(json_hit.frame_id) + entries = [x for x in variables_response.to_dict()['body']['variables'] if x['name'] == 'entry'] + assert len(entries) == 1 + variables_response = json_facade.get_variables_response(entries[0]['variablesReference']) + assert variables_response.to_dict()['body']['variables'] == [ + {'name': 'key', 'value': "'v1'", 'type': 'str', 'evaluateName': 'entry.key', 'presentationHint': {'attributes': ['rawString']}, 'variablesReference': 0}, + {'name': 'val', 'value': "'v1'", 'type': 'str', 'evaluateName': 'entry.val', 'presentationHint': {'attributes': ['rawString']}, 'variablesReference': 0} + ] + + json_facade.write_continue(wait_for_response=False) + writer.finished_ok = True + + +@pytest.mark.skipif(not TEST_FLASK, reason='No flask available') +@pytest.mark.parametrize("jmc", [False, True]) +def test_case_flask_exceptions(case_setup_flask, jmc): + with case_setup_flask.test_file(EXPECTED_RETURNCODE='any') as writer: + json_facade = JsonFacade(writer) + + if jmc: + writer.write_set_project_roots([debugger_unittest._get_debugger_test_file('my_code')]) + json_facade.write_launch(debugOptions=['Jinja']) + json_facade.write_set_exception_breakpoints(['raised']) + else: + json_facade.write_launch(debugOptions=['DebugStdLib', 'Jinja']) + # Don't set to all 'raised' because we'd stop on standard library exceptions here + # (which is not something we want). + json_facade.write_set_exception_breakpoints(exception_options=[ + ExceptionOptions(breakMode='always', path=[ + {'names': ['Python Exceptions']}, + {'names': ['IndexError']}, + ]) + ]) + json_facade.write_make_initial_run() + + t = writer.create_request_thread('/bad_template') + time.sleep(2) # Give flask some time to get to startup before requesting the page + t.start() + + json_facade.wait_for_thread_stopped('exception', line=8, file='bad.html') + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +@pytest.mark.skipif(IS_APPVEYOR or IS_JYTHON, reason='Flaky on appveyor / Jython encoding issues (needs investigation).') +def test_redirect_output(case_setup): + + def get_environ(writer): + env = os.environ.copy() + + env["PYTHONIOENCODING"] = 'utf-8' + return env + + with case_setup.test_file('_debugger_case_redirect.py', get_environ=get_environ) as writer: + original_ignore_stderr_line = writer._ignore_stderr_line + + json_facade = JsonFacade(writer) + + @overrides(writer._ignore_stderr_line) + def _ignore_stderr_line(line): + if original_ignore_stderr_line(line): + return True + return line.startswith(( + 'text', + 'binary', + 'a' + )) + + writer._ignore_stderr_line = _ignore_stderr_line + + # Note: writes to stdout and stderr are now synchronous (so, the order + # must always be consistent and there's a message for each write). + expected = [ + 'text\n', + 'binary or text\n', + 'ação1\n', + ] + + if sys.version_info[0] >= 3: + expected.extend(( + 'binary\n', + 'ação2\n'.encode(encoding='latin1').decode('utf-8', 'replace'), + 'ação3\n', + )) + + new_expected = [(x, 'stdout') for x in expected] + new_expected.extend([(x, 'stderr') for x in expected]) + + writer.write_start_redirect() + + writer.write_make_initial_run() + msgs = [] + ignored = [] + while len(msgs) < len(new_expected): + try: + output_event = json_facade.wait_for_json_message(OutputEvent) + output = output_event.body.output + category = output_event.body.category + if IS_PY2: + if isinstance(output, unicode): + output = output.encode('utf-8') + if isinstance(category, unicode): + category = category.encode('utf-8') + msg = (output, category) + except Exception: + for msg in msgs: + sys.stderr.write('Found: %s\n' % (msg,)) + for msg in new_expected: + sys.stderr.write('Expected: %s\n' % (msg,)) + for msg in ignored: + sys.stderr.write('Ignored: %s\n' % (msg,)) + raise + if msg not in new_expected: + ignored.append(msg) + continue + msgs.append(msg) + + if msgs != new_expected: + print(msgs) + print(new_expected) + assert msgs == new_expected + writer.finished_ok = True + + +def test_pydevd_systeminfo(case_setup): + with case_setup.test_file('_debugger_case_print.py') as writer: + json_facade = JsonFacade(writer) + + writer.write_add_breakpoint(writer.get_line_index_with_content('Break here')) + + json_facade.write_make_initial_run() + + json_hit = json_facade.wait_for_thread_stopped() + assert json_hit.thread_id + + info_request = json_facade.write_request( + pydevd_schema.PydevdSystemInfoRequest( + pydevd_schema.PydevdSystemInfoArguments() + ) + ) + info_response = json_facade.wait_for_response(info_request) + body = info_response.to_dict()['body'] + + assert body['python']['version'] == PY_VERSION_STR + assert body['python']['implementation']['name'] == PY_IMPL_NAME + assert body['python']['implementation']['version'] == PY_IMPL_VERSION_STR + assert 'description' in body['python']['implementation'] + + assert body['platform'] == {'name': sys.platform} + + assert 'pid' in body['process'] + assert body['process']['executable'] == sys.executable + assert body['process']['bitness'] == 64 if IS_64BIT_PROCESS else 32 + + json_facade.write_continue(wait_for_response=False) + + writer.finished_ok = True + + +if __name__ == '__main__': + pytest.main(['-k', 'test_case_skipping_filters', '-s']) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_dump_threads.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_dump_threads.py new file mode 100644 index 0000000..c077433 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_dump_threads.py @@ -0,0 +1,11 @@ +def test_dump_threads(): + import pydevd + try: + from StringIO import StringIO + except: + from io import StringIO + stream = StringIO() + pydevd.dump_threads(stream=stream) + contents = stream.getvalue() + assert 'Thread MainThread (daemon: False, pydevd thread: False)' in contents + assert 'test_dump_threads' in contents diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_extract_token.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_extract_token.py new file mode 100644 index 0000000..9f5509a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_extract_token.py @@ -0,0 +1,54 @@ +# coding: utf-8 +from __future__ import unicode_literals +from _pydev_bundle._pydev_completer import (isidentifier, extract_token_and_qualifier, + TokenAndQualifier) +from _pydevd_bundle.pydevd_constants import IS_PY2 + + +def test_isidentifier(): + assert isidentifier('abc') + assert not isidentifier('<') + assert not isidentifier('') + if IS_PY2: + # Py3 accepts unicode identifiers + assert not isidentifier('áéíóú') + else: + assert isidentifier('áéíóú') + + +def test_extract_token_and_qualifier(): + + assert extract_token_and_qualifier('tok', 0, 0) == TokenAndQualifier('', '') + assert extract_token_and_qualifier('tok', 0, 1) == TokenAndQualifier('', 't') + assert extract_token_and_qualifier('tok', 0, 2) == TokenAndQualifier('', 'to') + assert extract_token_and_qualifier('tok', 0, 3) == TokenAndQualifier('', 'tok') + assert extract_token_and_qualifier('tok', 0, 4) == TokenAndQualifier('', 'tok') + + assert extract_token_and_qualifier('tok.qual', 0, 0) == TokenAndQualifier('', '') + assert extract_token_and_qualifier('tok.qual', 0, 1) == TokenAndQualifier('', 't') + assert extract_token_and_qualifier('tok.qual', 0, 2) == TokenAndQualifier('', 'to') + assert extract_token_and_qualifier('tok.qual', 0, 3) == TokenAndQualifier('', 'tok') + + assert extract_token_and_qualifier('tok.qual', 0, 4) == TokenAndQualifier('tok', '') + assert extract_token_and_qualifier('tok.qual', 0, 5) == TokenAndQualifier('tok', 'q') + assert extract_token_and_qualifier('tok.qual', 0, 6) == TokenAndQualifier('tok', 'qu') + assert extract_token_and_qualifier('tok.qual', 0, 7) == TokenAndQualifier('tok', 'qua') + assert extract_token_and_qualifier('tok.qual', 0, 8) == TokenAndQualifier('tok', 'qual') + + # out of range (column) + assert extract_token_and_qualifier('tok.qual.qual2', 0, 100) == TokenAndQualifier('tok.qual', 'qual2') + + assert extract_token_and_qualifier('t' + + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + + +def test_frame_eval_change_breakpoints(case_setup_force_frame_eval): + with case_setup_force_frame_eval.test_file('_debugger_case_change_breaks.py') as writer: + break1_line = writer.get_line_index_with_content('break 1') + break2_line = writer.get_line_index_with_content('break 2') + + break2_id = writer.write_add_breakpoint(break2_line, 'None') + writer.write_make_initial_run() + + hit = writer.wait_for_breakpoint_hit(line=break2_line) + assert hit.suspend_type == "frame_eval" + + writer.write_remove_breakpoint(break2_id) + writer.write_add_breakpoint(break1_line, 'None') + writer.write_run_thread(hit.thread_id) + + hit = writer.wait_for_breakpoint_hit(line=break1_line) + writer.write_run_thread(hit.thread_id) + + writer.finished_ok = True + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_frame_evaluator.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_frame_evaluator.py new file mode 100644 index 0000000..5bfb9cc --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_frame_evaluator.py @@ -0,0 +1,76 @@ +import sys +import threading +import pytest +from tests_python.debugger_unittest import IS_PY36_OR_GREATER, IS_CPYTHON +from tests_python.debug_constants import TEST_CYTHON + +pytestmark = pytest.mark.skipif(not IS_PY36_OR_GREATER or not IS_CPYTHON or not TEST_CYTHON, reason='Requires CPython >= 3.6') + + +def get_foo_frame(): + frame = sys._getframe() + return frame + + +class CheckClass(object): + + def collect_info(self): + from _pydevd_frame_eval import pydevd_frame_evaluator + thread_info = pydevd_frame_evaluator.get_thread_info_py() + self.thread_info = thread_info + + +@pytest.mark.parametrize('_times', range(2)) +def test_thread_info(_times): + obj = CheckClass() + obj.collect_info() + assert obj.thread_info.additional_info is not None + assert not obj.thread_info.is_pydevd_thread + thread_info = obj.thread_info + obj.collect_info() + assert obj.thread_info is thread_info + + obj = CheckClass() + t = threading.Thread(target=obj.collect_info) + t.is_pydev_daemon_thread = True + t.start() + t.join() + + assert obj.thread_info.additional_info is None + assert obj.thread_info.is_pydevd_thread + + +def method(): + return sys._getframe() + + +@pytest.fixture +def _custom_global_dbg(): + from _pydevd_bundle.pydevd_constants import GlobalDebuggerHolder + from pydevd import PyDB + curr = GlobalDebuggerHolder.global_dbg + PyDB() # Will make itself current + yield + GlobalDebuggerHolder.global_dbg = curr + + +@pytest.mark.parametrize('_times', range(2)) +def test_func_code_info(_times, _custom_global_dbg): + from _pydevd_frame_eval import pydevd_frame_evaluator + # Must be called before get_func_code_info_py to initialize the _code_extra_index. + pydevd_frame_evaluator.get_thread_info_py() + + func_info = pydevd_frame_evaluator.get_func_code_info_py(method(), method.__code__) + assert func_info.co_filename is method.__code__.co_filename + func_info2 = pydevd_frame_evaluator.get_func_code_info_py(method(), method.__code__) + assert func_info is func_info2 + + some_func = eval('lambda:sys._getframe()') + func_info3 = pydevd_frame_evaluator.get_func_code_info_py(some_func(), some_func.__code__) + del some_func + del func_info3 + + some_func = eval('lambda:sys._getframe()') + pydevd_frame_evaluator.get_func_code_info_py(some_func(), some_func.__code__) + func_info = pydevd_frame_evaluator.get_func_code_info_py(some_func(), some_func.__code__) + assert pydevd_frame_evaluator.get_func_code_info_py(some_func(), some_func.__code__) is func_info diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_null.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_null.py new file mode 100644 index 0000000..f09da7b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_null.py @@ -0,0 +1,8 @@ +def test_null(): + from _pydevd_bundle.pydevd_constants import Null + null = Null() + assert not null + assert len(null) == 0 + + with null as n: + n.write('foo') \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_process_command_line.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_process_command_line.py new file mode 100644 index 0000000..8932630 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_process_command_line.py @@ -0,0 +1,28 @@ +import unittest + +class Test(unittest.TestCase): + + def testProcessCommandLine(self): + from _pydevd_bundle.pydevd_command_line_handling import process_command_line, setup_to_argv + setup = process_command_line(['pydevd.py', '--port', '1', '--save-threading']) + assert setup['save-threading'] + assert setup['port'] == 1 + assert not setup['qt-support'] + + argv = setup_to_argv(setup) + assert argv[0].endswith('pydevd.py') or argv[0].endswith('pydevd$py.class'), 'Expected: %s to end with pydevd.py' % (argv[0],) + argv = argv[1:] + assert argv == ['--port', '1', '--save-threading'] + + def testProcessCommandLine2(self): + from _pydevd_bundle.pydevd_command_line_handling import process_command_line, setup_to_argv + setup = process_command_line(['pydevd.py', '--port', '1', '--qt-support=auto']) + assert setup['qt-support'] == 'auto' + + setup = process_command_line(['pydevd.py', '--port', '1', '--qt-support']) + assert setup['qt-support'] == 'auto' + + setup = process_command_line(['pydevd.py', '--port', '1', '--qt-support=pyqt4']) + assert setup['qt-support'] == 'pyqt4' + + self.assertRaises(ValueError, process_command_line, ['pydevd.py', '--port', '1', '--qt-support=wrong']) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydev_monkey.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydev_monkey.py new file mode 100644 index 0000000..aa51224 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydev_monkey.py @@ -0,0 +1,175 @@ +import os +import sys +import unittest + +try: + from _pydev_bundle import pydev_monkey +except: + sys.path.append(os.path.dirname(os.path.dirname(__file__))) + from _pydev_bundle import pydev_monkey +from pydevd import SetupHolder +from _pydev_bundle.pydev_monkey import pydev_src_dir + + +class TestCase(unittest.TestCase): + + def test_monkey(self): + original = SetupHolder.setup + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'} + check = '''C:\\bin\\python.exe -u -c connect(\\"127.0.0.1\\")''' + debug_command = ( + 'import sys; ' + 'sys.path.append(r\'%s\'); ' + "import pydevd; pydevd.settrace(host='127.0.0.1', port=0, suspend=False, " + 'trace_only_current_thread=False, patch_multiprocessing=True); ' + '' + "from pydevd import SetupHolder; " + "SetupHolder.setup = %s; " + '' + 'connect("127.0.0.1")') % (pydev_src_dir, SetupHolder.setup) + if sys.platform == "win32": + debug_command = debug_command.replace('"', '\\"') + debug_command = '"%s"' % debug_command + + self.assertEqual( + 'C:\\bin\\python.exe -u -c %s' % debug_command, + pydev_monkey.patch_arg_str_win(check)) + finally: + SetupHolder.setup = original + + def test_str_to_args_windows(self): + self.assertEqual(['a', 'b'], pydev_monkey.str_to_args_windows('a "b"')) + + def test_monkey_patch_args_indc(self): + original = SetupHolder.setup + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'} + check = ['C:\\bin\\python.exe', '-u', '-c', 'connect("127.0.0.1")'] + debug_command = ( + 'import sys; sys.path.append(r\'%s\'); import pydevd; ' + 'pydevd.settrace(host=\'127.0.0.1\', port=0, suspend=False, trace_only_current_thread=False, patch_multiprocessing=True); ' + '' + "from pydevd import SetupHolder; " + "SetupHolder.setup = %s; " + '' + 'connect("127.0.0.1")') % (pydev_src_dir, SetupHolder.setup) + if sys.platform == "win32": + debug_command = debug_command.replace('"', '\\"') + debug_command = '"%s"' % debug_command + res = pydev_monkey.patch_args(check) + self.assertEqual(res, [ + 'C:\\bin\\python.exe', + '-u', + '-c', + debug_command + ]) + finally: + SetupHolder.setup = original + + def test_monkey_patch_args_module(self): + original = SetupHolder.setup + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0', 'multiprocess': True} + check = ['C:\\bin\\python.exe', '-m', 'test'] + from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file + self.assertEqual(pydev_monkey.patch_args(check), [ + 'C:\\bin\\python.exe', + get_pydevd_file(), + '--module', + '--port', + '0', + '--client', + '127.0.0.1', + '--multiprocess', + '--file', + 'test', + ]) + finally: + SetupHolder.setup = original + + def test_monkey_patch_args_no_indc(self): + original = SetupHolder.setup + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'} + check = ['C:\\bin\\python.exe', 'connect(\\"127.0.0.1\\")', 'with spaces'] + from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file + self.assertEqual(pydev_monkey.patch_args(check), [ + 'C:\\bin\\python.exe', + get_pydevd_file(), + '--port', + '0', + '--client', + '127.0.0.1', + '--file', + '"connect(\\\\\\"127.0.0.1\\\\\\")"' if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")', + '"with spaces"' if sys.platform == 'win32' else 'with spaces', + ]) + finally: + SetupHolder.setup = original + + def test_monkey_patch_args_no_indc_with_pydevd(self): + original = SetupHolder.setup + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'} + check = ['C:\\bin\\python.exe', 'pydevd.py', 'connect(\\"127.0.0.1\\")', 'bar'] + + self.assertEqual(pydev_monkey.patch_args(check), [ + 'C:\\bin\\python.exe', 'pydevd.py', 'connect(\\"127.0.0.1\\")', 'bar']) + finally: + SetupHolder.setup = original + + def test_monkey_patch_args_no_indc_without_pydevd(self): + original = SetupHolder.setup + from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'} + check = ['C:\\bin\\python.exe', 'target.py', 'connect(\\"127.0.0.1\\")', 'bar'] + self.assertEqual(pydev_monkey.patch_args(check), [ + 'C:\\bin\\python.exe', + get_pydevd_file(), + '--port', + '0', + '--client', + '127.0.0.1', + '--file', + 'target.py', + '"connect(\\\\\\"127.0.0.1\\\\\\")"' if sys.platform == 'win32' else 'connect(\\"127.0.0.1\\")', + 'bar', + ]) + finally: + SetupHolder.setup = original + + def test_monkey_patch_c_program_arg(self): + original = SetupHolder.setup + from _pydevd_bundle.pydevd_command_line_handling import get_pydevd_file + + try: + SetupHolder.setup = {'client': '127.0.0.1', 'port': '0'} + check = ['C:\\bin\\python.exe', '-u', 'target.py', '-c', '-another_arg'] + + self.assertEqual(pydev_monkey.patch_args(check), [ + 'C:\\bin\\python.exe', + '-u', + get_pydevd_file(), + '--port', + '0', + '--client', + '127.0.0.1', + '--file', + 'target.py', + '-c', + '-another_arg' + ]) + finally: + SetupHolder.setup = original + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevcoverage.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevcoverage.py new file mode 100644 index 0000000..353027d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevcoverage.py @@ -0,0 +1,68 @@ +import os +import re +import sys +import subprocess +import tempfile +import unittest + + +#======================================================================================================================= +# Test +#======================================================================================================================= +class Test(unittest.TestCase): + """ + Unittest for pydev_coverage.py. + TODO: + - 'combine' in arguments + - no 'combine' and no 'pydev-analyze' in arguments + """ + + def setUp(self): + unittest.TestCase.setUp(self) + project_path = os.path.dirname(os.path.dirname(__file__)) + self._resources_path = os.path.join(project_path, "tests_python", "resources") + self._coverage_file = os.path.join(project_path, "pydev_coverage.py") + + def _do_analyze(self, files): + invalid_files = [] + + p = subprocess.Popen([sys.executable, self._coverage_file, "--pydev-analyze"], + stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + __, stderrdata = p.communicate("|".join(files).encode()) + + if stderrdata: + match = re.search("Invalid files not passed to coverage: (.*?)$", + stderrdata.decode(), re.M) # @UndefinedVariable + if match: + invalid_files = [f.strip() for f in match.group(1).split(",")] + return invalid_files + + def test_pydev_analyze_ok(self): + ref_valid_files = [__file__, + os.path.join(self._resources_path, "_debugger_case18.py")] + ref_invalid_files = [] + + invalid_files = self._do_analyze(ref_valid_files) + + self.assertEqual(ref_invalid_files, invalid_files) + + def test_pydev_analyse_non_standard_encoding(self): + ref_valid_files = [os.path.join(self._resources_path, + "_pydev_coverage_cyrillic_encoding_py%i.py" + % sys.version_info[0])] + ref_invalid_files = [] + + invalid_files = self._do_analyze(ref_valid_files + ref_invalid_files) + + self.assertEqual(ref_invalid_files, invalid_files) + + def test_pydev_analyse_invalid_files(self): + with tempfile.NamedTemporaryFile(suffix=".pyx") as pyx_file: + ref_valid_files = [] + ref_invalid_files = [os.path.join(self._resources_path, + "_pydev_coverage_syntax_error.py"), + pyx_file.name] + + invalid_files = self._do_analyze(ref_valid_files + ref_invalid_files) + + self.assertEqual(ref_invalid_files, invalid_files) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevd_filtering.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevd_filtering.py new file mode 100644 index 0000000..2b5ee5f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevd_filtering.py @@ -0,0 +1,189 @@ + + +def test_in_project_roots(tmpdir): + from _pydevd_bundle.pydevd_filtering import FilesFiltering + files_filtering = FilesFiltering() + + import os.path + import sys + assert files_filtering._get_library_roots() == [ + os.path.normcase(x) for x in files_filtering._get_default_library_roots()] + + site_packages = tmpdir.mkdir('site-packages') + project_dir = tmpdir.mkdir('project') + + project_dir_inside_site_packages = str(site_packages.mkdir('project')) + site_packages_inside_project_dir = str(project_dir.mkdir('site-packages')) + + # Convert from pytest paths to str. + site_packages = str(site_packages) + project_dir = str(project_dir) + tmpdir = str(tmpdir) + + # Test permutations of project dir inside site packages and vice-versa. + files_filtering.set_project_roots([project_dir, project_dir_inside_site_packages]) + files_filtering.set_library_roots([site_packages, site_packages_inside_project_dir]) + + check = [ + (tmpdir, False), + (site_packages, False), + (site_packages_inside_project_dir, False), + (project_dir, True), + (project_dir_inside_site_packages, True), + ] + for (check_path, find) in check[:]: + check.append((os.path.join(check_path, 'a.py'), find)) + + for check_path, find in check: + assert files_filtering.in_project_roots(check_path) == find + + files_filtering.set_project_roots([]) + files_filtering.set_library_roots([site_packages, site_packages_inside_project_dir]) + + # If the IDE did not set the project roots, consider anything not in the site + # packages as being in a project root (i.e.: we can calculate default values for + # site-packages but not for project roots). + check = [ + (tmpdir, True), + (site_packages, False), + (site_packages_inside_project_dir, False), + (project_dir, True), + (project_dir_inside_site_packages, False), + ('', True), + ('', False), + ] + + for check_path, find in check: + assert files_filtering.in_project_roots(check_path) == find + + sys.path.append(str(site_packages)) + try: + default_library_roots = files_filtering._get_default_library_roots() + assert len(set(default_library_roots)) == len(default_library_roots), \ + 'Duplicated library roots found in: %s' % (default_library_roots,) + + assert str(site_packages) in default_library_roots + for path in sys.path: + if os.path.exists(path) and path.endswith('site-packages'): + assert path in default_library_roots + finally: + sys.path.remove(str(site_packages)) + + +def test_filtering(tmpdir): + from _pydevd_bundle.pydevd_filtering import FilesFiltering + from _pydevd_bundle.pydevd_filtering import ExcludeFilter + files_filtering = FilesFiltering() + + site_packages = tmpdir.mkdir('site-packages') + project_dir = tmpdir.mkdir('project') + + project_dir_inside_site_packages = str(site_packages.mkdir('project')) + site_packages_inside_project_dir = str(project_dir.mkdir('site-packages')) + + files_filtering.set_exclude_filters([ + ExcludeFilter('**/project*', True, True), + ExcludeFilter('**/bar*', False, True), + ]) + assert files_filtering.exclude_by_filter('/foo/project', None) is True + assert files_filtering.exclude_by_filter('/foo/unmatched', None) is None + assert files_filtering.exclude_by_filter('/foo/bar', None) is False + + +def test_glob_matching(): + from _pydevd_bundle.pydevd_filtering import glob_matches_path + + # Linux + for sep, altsep in (('\\', '/'), ('/', None)): + + def build(path): + if sep == '/': + return path + else: + return ('c:' + path).replace('/', '\\') + + assert glob_matches_path(build('/a'), r'*', sep, altsep) + + assert not glob_matches_path(build('/a/b/c/some.py'), '/a/**/c/so?.py', sep, altsep) + + assert glob_matches_path('/a/b/c', '/a/b/*') + assert not glob_matches_path('/a/b', '/*') + assert glob_matches_path('/a/b', '/*/b') + assert glob_matches_path('/a/b', '**/*') + assert not glob_matches_path('/a/b', '**/a') + + assert glob_matches_path(build('/a/b/c/d'), '**/d', sep, altsep) + assert not glob_matches_path(build('/a/b/c/d'), '**/c', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '**/c/d', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '**/b/c/d', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '/*/b/*/d', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '**/c/*', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '/a/**/c/*', sep, altsep) + + assert glob_matches_path(build('/a/b/c/d.py'), '/a/**/c/*', sep, altsep) + assert glob_matches_path(build('/a/b/c/d.py'), '/a/**/c/*.py', sep, altsep) + assert glob_matches_path(build('/a/b/c/some.py'), '/a/**/c/so*.py', sep, altsep) + assert glob_matches_path(build('/a/b/c/some.py'), '/a/**/c/som?.py', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '/**', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), '/**/d', sep, altsep) + assert glob_matches_path(build('/a/b/c/d.py'), '/**/*.py', sep, altsep) + assert glob_matches_path(build('/a/b/c/d.py'), '**/c/*.py', sep, altsep) + + # Expected not to match. + assert not glob_matches_path(build('/a/b/c/d'), '/**/d.py', sep, altsep) + assert not glob_matches_path(build('/a/b/c/d.pyx'), '/a/**/c/*.py', sep, altsep) + assert not glob_matches_path(build('/a/b/c/d'), '/*/d', sep, altsep) + + if sep == '/': + assert not glob_matches_path(build('/a/b/c/d'), r'**\d', sep, altsep) # Match with \ doesn't work on linux... + assert not glob_matches_path(build('/a/b/c/d'), r'c:\**\d', sep, altsep) # Match with drive doesn't work on linux... + else: + # Works in Windows. + assert glob_matches_path(build('/a/b/c/d'), r'**\d', sep, altsep) + assert glob_matches_path(build('/a/b/c/d'), r'c:\**\d', sep, altsep) + + # Corner cases + assert not glob_matches_path(build('/'), r'', sep, altsep) + assert glob_matches_path(build(''), r'', sep, altsep) + assert not glob_matches_path(build(''), r'**', sep, altsep) + assert glob_matches_path(build('/'), r'**', sep, altsep) + assert glob_matches_path(build('/'), r'*', sep, altsep) + + +def test_rules_to_exclude_filter(tmpdir): + from _pydevd_bundle.pydevd_process_net_command_json import _convert_rules_to_exclude_filters + from _pydevd_bundle.pydevd_filtering import ExcludeFilter + from random import shuffle + dira = tmpdir.mkdir('a') + dirb = dira.mkdir('b') + fileb = dirb.join('fileb.py') + fileb2 = dirb.join('fileb2.py') + with fileb.open('w') as stream: + stream.write('') + + def filename_to_server(filename): + return filename + + def on_error(msg): + raise AssertionError(msg) + + rules = [ + {'path': str(dira), 'include': False}, + {'path': str(dirb), 'include': True}, + {'path': str(fileb), 'include': True}, + {'path': str(fileb2), 'include': True}, + {'path': '**/foo/*.py', 'include': True}, + {'module': 'bar', 'include': False}, + {'module': 'bar.foo', 'include': True}, + ] + shuffle(rules) + exclude_filters = _convert_rules_to_exclude_filters(rules, filename_to_server, on_error) + assert exclude_filters == [ + ExcludeFilter(name=str(fileb2), exclude=False, is_path=True), + ExcludeFilter(name=str(fileb), exclude=False, is_path=True), + ExcludeFilter(name=str(dirb) + '/**', exclude=False, is_path=True), + ExcludeFilter(name=str(dira) + '/**', exclude=True, is_path=True), + ExcludeFilter(name='**/foo/*.py', exclude=False, is_path=True), + ExcludeFilter(name='bar.foo', exclude=False, is_path=False), + ExcludeFilter(name='bar', exclude=True, is_path=False), + ] diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevd_io.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevd_io.py new file mode 100644 index 0000000..116e60b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_pydevd_io.py @@ -0,0 +1,120 @@ +from _pydevd_bundle.pydevd_io import IORedirector +from _pydevd_bundle.pydevd_net_command_factory_xml import NetCommandFactory +import pytest + + +def test_io_redirector(): + + class MyRedirection1(object): + encoding = 'foo' + + class MyRedirection2(object): + pass + + my_redirector = IORedirector(MyRedirection1(), MyRedirection2(), wrap_buffer=True) + none_redirector = IORedirector(None, None, wrap_buffer=True) + + assert my_redirector.encoding == 'foo' + with pytest.raises(AttributeError): + none_redirector.encoding + + # Check that we don't fail creating the IORedirector if the original + # doesn't have a 'buffer'. + for redirector in ( + my_redirector, + none_redirector, + ): + redirector.write('test') + redirector.flush() + + assert not redirector.isatty() + + +class _DummyWriter(object): + + __slots__ = ['commands', 'command_meanings'] + + def __init__(self): + self.commands = [] + self.command_meanings = [] + + def add_command(self, cmd): + from _pydevd_bundle.pydevd_comm import ID_TO_MEANING + meaning = ID_TO_MEANING[str(cmd.id)] + self.command_meanings.append(meaning) + self.commands.append(cmd) + + +class _DummyPyDb(object): + + def __init__(self): + self.cmd_factory = NetCommandFactory() + self.writer = _DummyWriter() + + +def test_patch_stdin(): + from pydevd import _internal_patch_stdin + + py_db = _DummyPyDb() + + class _Stub(object): + pass + + actions = [] + + class OriginalStdin(object): + + def readline(self): + # On a readline we keep the patched version. + assert sys_mod.stdin is not original_stdin + actions.append('readline') + return 'read' + + def getpass_stub(*args, **kwargs): + # On getpass we need to revert to the original version. + actions.append('getpass') + assert sys_mod.stdin is original_stdin + return 'pass' + + sys_mod = _Stub() + original_stdin = sys_mod.stdin = OriginalStdin() + + getpass_mod = _Stub() + getpass_mod.getpass = getpass_stub + + _internal_patch_stdin(py_db, sys_mod, getpass_mod) + + assert sys_mod.stdin.readline() == 'read' + + assert py_db.writer.command_meanings == ['CMD_INPUT_REQUESTED', 'CMD_INPUT_REQUESTED'] + del py_db.writer.command_meanings[:] + assert actions == ['readline'] + del actions[:] + + assert getpass_mod.getpass() == 'pass' + assert py_db.writer.command_meanings == ['CMD_INPUT_REQUESTED', 'CMD_INPUT_REQUESTED'] + del py_db.writer.command_meanings[:] + + +def test_debug_console(): + from _pydev_bundle.pydev_console_utils import DebugConsoleStdIn + + class OriginalStdin(object): + + def readline(self): + return 'read' + + original_stdin = OriginalStdin() + + py_db = _DummyPyDb() + debug_console_std_in = DebugConsoleStdIn(py_db, original_stdin) + assert debug_console_std_in.readline() == 'read' + + assert py_db.writer.command_meanings == ['CMD_INPUT_REQUESTED', 'CMD_INPUT_REQUESTED'] + del py_db.writer.command_meanings[:] + + with debug_console_std_in.notify_input_requested(): + with debug_console_std_in.notify_input_requested(): + pass + assert py_db.writer.command_meanings == ['CMD_INPUT_REQUESTED', 'CMD_INPUT_REQUESTED'] + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_resolvers.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_resolvers.py new file mode 100644 index 0000000..72a91a2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_resolvers.py @@ -0,0 +1,298 @@ +from tests_python.debug_constants import IS_PY2 + + +def check_len_entry(len_entry, first_2_params): + assert len_entry[:2] == first_2_params + assert callable(len_entry[2]) + assert len_entry[2]('check') == 'len(check)' + + +def test_dict_resolver(): + from _pydevd_bundle.pydevd_resolver import DictResolver + dict_resolver = DictResolver() + dct = {(1, 2): 2, u'22': 22} + contents_debug_adapter_protocol = dict_resolver.get_contents_debug_adapter_protocol(dct) + len_entry = contents_debug_adapter_protocol.pop(-1) + check_len_entry(len_entry, ('__len__', 2)) + if IS_PY2: + assert contents_debug_adapter_protocol == [ + ('(1, 2)', 2, '[(1, 2)]'), (u"u'22'", 22, u"[u'22']")] + else: + assert contents_debug_adapter_protocol == [ + ("'22'", 22, "['22']"), ('(1, 2)', 2, '[(1, 2)]')] + + +def test_dict_resolver_hex(): + from _pydevd_bundle.pydevd_resolver import DictResolver + dict_resolver = DictResolver() + dct = {(1, 10, 100): (10000, 100000, 100000)} + contents_debug_adapter_protocol = dict_resolver.get_contents_debug_adapter_protocol(dct, fmt={'hex': True}) + len_entry = contents_debug_adapter_protocol.pop(-1) + check_len_entry(len_entry, ('__len__', 1)) + assert contents_debug_adapter_protocol == [ + ('(0x1, 0xa, 0x64)', (10000, 100000, 100000), '[(1, 10, 100)]'), ] + + +def test_object_resolver_simple(): + from _pydevd_bundle.pydevd_resolver import DefaultResolver + default_resolver = DefaultResolver() + + class MyObject(object): + + def __init__(self): + self.a = 10 + self.b = 20 + + obj = MyObject() + dictionary = default_resolver.get_dictionary(obj) + assert dictionary == {'a': 10, 'b': 20} + + contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj) + assert contents_debug_adapter_protocol == [('a', 10, '.a'), ('b', 20, '.b')] + + +def test_object_resolver_error(): + from _pydevd_bundle.pydevd_resolver import DefaultResolver + default_resolver = DefaultResolver() + + class MyObject(object): + + def __init__(self): + self.a = 10 + + def __dir__(self): + return ['a', 'b'] + + def __getattribute__(self, attr_name): + if attr_name == 'b': + raise RuntimeError('unavailable') + return object.__getattribute__(self, attr_name) + + obj = MyObject() + dictionary = default_resolver.get_dictionary(obj) + b_value = dictionary.pop('b') + assert dictionary == {'a': 10} + assert "raise RuntimeError('unavailable')" in b_value + + contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj) + b_value = contents_debug_adapter_protocol.pop(-1) + assert contents_debug_adapter_protocol == [('a', 10, '.a')] + assert b_value[0] == 'b' + assert "raise RuntimeError('unavailable')" in b_value[1] + assert b_value[2] == '.b' + + +def test_object_resolver__dict__non_strings(): + from _pydevd_bundle.pydevd_resolver import DefaultResolver + default_resolver = DefaultResolver() + + class MyObject(object): + + def __init__(self): + self.__dict__[(1, 2)] = (3, 4) + + obj = MyObject() + dictionary = default_resolver.get_dictionary(obj) + if IS_PY2: + assert 'attribute name must be string' in dictionary.pop('(1, 2)') + assert dictionary == {} + else: + assert dictionary == {'(1, 2)': (3, 4)} + + contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj) + if IS_PY2: + assert len(contents_debug_adapter_protocol) == 1 + entry = contents_debug_adapter_protocol[0] + assert entry[0] == '(1, 2)' + assert 'attribute name must be string' in entry[1] + assert entry[2] == '.(1, 2)' + else: + assert contents_debug_adapter_protocol == [('(1, 2)', (3, 4), '.__dict__[(1, 2)]')] + + +def test_django_forms_resolver(): + from _pydevd_bundle.pydevd_resolver import DjangoFormResolver + django_form_resolver = DjangoFormResolver() + + class MyObject(object): + + def __init__(self): + self.__dict__[(1, 2)] = (3, 4) + self.__dict__['errors'] = 'foo' + + obj = MyObject() + + dictionary = django_form_resolver.get_dictionary(obj) + if IS_PY2: + assert 'attribute name must be string' in dictionary.pop('(1, 2)') + assert dictionary == {'errors': None} + else: + assert dictionary == {'(1, 2)': (3, 4), 'errors': None} + + obj._errors = 'bar' + dictionary = django_form_resolver.get_dictionary(obj) + if IS_PY2: + assert 'attribute name must be string' in dictionary.pop('(1, 2)') + assert dictionary == {'errors': 'bar', '_errors': 'bar'} + else: + assert dictionary == {'(1, 2)': (3, 4), 'errors': 'bar', '_errors': 'bar'} + + +def test_tuple_resolver(): + from _pydevd_bundle.pydevd_resolver import TupleResolver + tuple_resolver = TupleResolver() + fmt = {'hex': True} + lst = tuple(range(11)) + contents_debug_adapter_protocol = tuple_resolver.get_contents_debug_adapter_protocol(lst) + len_entry = contents_debug_adapter_protocol.pop(-1) + assert contents_debug_adapter_protocol == [ + ('00', 0, '[0]'), + ('01', 1, '[1]'), + ('02', 2, '[2]'), + ('03', 3, '[3]'), + ('04', 4, '[4]'), + ('05', 5, '[5]'), + ('06', 6, '[6]'), + ('07', 7, '[7]'), + ('08', 8, '[8]'), + ('09', 9, '[9]'), + ('10', 10, '[10]'), + ] + check_len_entry(len_entry, ('__len__', 11)) + + assert tuple_resolver.get_dictionary(lst) == { + '00': 0, + '01': 1, + '02': 2, + '03': 3, + '04': 4, + '05': 5, + '06': 6, + '07': 7, + '08': 8, + '09': 9, + '10': 10, + '__len__': 11 + } + + lst = tuple(range(17)) + contents_debug_adapter_protocol = tuple_resolver.get_contents_debug_adapter_protocol(lst, fmt=fmt) + len_entry = contents_debug_adapter_protocol.pop(-1) + assert contents_debug_adapter_protocol == [ + ('0x00', 0, '[0]'), + ('0x01', 1, '[1]'), + ('0x02', 2, '[2]'), + ('0x03', 3, '[3]'), + ('0x04', 4, '[4]'), + ('0x05', 5, '[5]'), + ('0x06', 6, '[6]'), + ('0x07', 7, '[7]'), + ('0x08', 8, '[8]'), + ('0x09', 9, '[9]'), + ('0x0a', 10, '[10]'), + ('0x0b', 11, '[11]'), + ('0x0c', 12, '[12]'), + ('0x0d', 13, '[13]'), + ('0x0e', 14, '[14]'), + ('0x0f', 15, '[15]'), + ('0x10', 16, '[16]'), + ] + check_len_entry(len_entry, ('__len__', 17)) + + assert tuple_resolver.get_dictionary(lst, fmt=fmt) == { + '0x00': 0, + '0x01': 1, + '0x02': 2, + '0x03': 3, + '0x04': 4, + '0x05': 5, + '0x06': 6, + '0x07': 7, + '0x08': 8, + '0x09': 9, + '0x0a': 10, + '0x0b': 11, + '0x0c': 12, + '0x0d': 13, + '0x0e': 14, + '0x0f': 15, + '0x10': 16, + '__len__': 17 + } + + lst = tuple(range(10)) + contents_debug_adapter_protocol = tuple_resolver.get_contents_debug_adapter_protocol(lst) + len_entry = contents_debug_adapter_protocol.pop(-1) + assert contents_debug_adapter_protocol == [ + ('0', 0, '[0]'), + ('1', 1, '[1]'), + ('2', 2, '[2]'), + ('3', 3, '[3]'), + ('4', 4, '[4]'), + ('5', 5, '[5]'), + ('6', 6, '[6]'), + ('7', 7, '[7]'), + ('8', 8, '[8]'), + ('9', 9, '[9]'), + ] + check_len_entry(len_entry, ('__len__', 10)) + + assert tuple_resolver.get_dictionary(lst) == { + '0': 0, + '1': 1, + '2': 2, + '3': 3, + '4': 4, + '5': 5, + '6': 6, + '7': 7, + '8': 8, + '9': 9, + '__len__': 10 + } + + contents_debug_adapter_protocol = tuple_resolver.get_contents_debug_adapter_protocol(lst, fmt=fmt) + len_entry = contents_debug_adapter_protocol.pop(-1) + assert contents_debug_adapter_protocol == [ + ('0x0', 0, '[0]'), + ('0x1', 1, '[1]'), + ('0x2', 2, '[2]'), + ('0x3', 3, '[3]'), + ('0x4', 4, '[4]'), + ('0x5', 5, '[5]'), + ('0x6', 6, '[6]'), + ('0x7', 7, '[7]'), + ('0x8', 8, '[8]'), + ('0x9', 9, '[9]'), + ] + check_len_entry(len_entry, ('__len__', 10)) + + assert tuple_resolver.get_dictionary(lst, fmt=fmt) == { + '0x0': 0, + '0x1': 1, + '0x2': 2, + '0x3': 3, + '0x4': 4, + '0x5': 5, + '0x6': 6, + '0x7': 7, + '0x8': 8, + '0x9': 9, + '__len__': 10 + } + + +def test_tuple_resolver_mixed(): + from _pydevd_bundle.pydevd_resolver import TupleResolver + tuple_resolver = TupleResolver() + + class CustomTuple(tuple): + pass + + my_tuple = CustomTuple([1, 2]) + my_tuple.some_value = 10 + contents_debug_adapter_protocol = tuple_resolver.get_contents_debug_adapter_protocol(my_tuple) + len_entry = contents_debug_adapter_protocol.pop(-1) + check_len_entry(len_entry, ('__len__', 2)) + assert contents_debug_adapter_protocol == [ + ('some_value', 10, '.some_value'), ('0', 1, '[0]'), ('1', 2, '[1]'), ] diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_run.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_run.py new file mode 100644 index 0000000..1f646b5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_run.py @@ -0,0 +1,104 @@ +pytest_plugins = [ + str('_pytest.pytester'), +] + + +def _run_and_check(testdir, path, check_for='Worked'): + result = testdir.runpython(path) + result.stdout.fnmatch_lines([ + check_for + ]) + +def test_run(testdir): + from tests_python import debugger_unittest + import sys + import os + + if debugger_unittest.IS_PY3K: + foo_dir = debugger_unittest._get_debugger_test_file(os.path.join('resources', 'launch', 'foo')) + foo_module = 'tests_python.resources.launch.foo' + else: + foo_dir = debugger_unittest._get_debugger_test_file(os.path.join('resources', 'launch_py2', 'foo')) + foo_module = 'tests_python.resources.launch_py2.foo' + + pydevd_dir = os.path.dirname(os.path.dirname(__file__)) + assert os.path.exists(os.path.join(pydevd_dir, 'pydevd.py')) + + _run_and_check(testdir, testdir.makepyfile(''' +import sys +sys.path.append(%(pydevd_dir)r) +import pydevd +py_db = pydevd.PyDB() +py_db.ready_to_run = True +py_db.run(%(foo_dir)r) +''' % locals())) + + _run_and_check(testdir, testdir.makepyfile(''' +import sys +sys.path.append(%(pydevd_dir)r) +import pydevd +py_db = pydevd.PyDB() +py_db.run(%(foo_dir)r, set_trace=False) +''' % locals())) + + if sys.version_info[0:2] == (2, 6): + # Not valid for Python 2.6 + return + + _run_and_check(testdir, testdir.makepyfile(''' +import sys +sys.path.append(%(pydevd_dir)r) +sys.argv.append('--as-module') +import pydevd +py_db = pydevd.PyDB() +py_db.ready_to_run = True +py_db.run(%(foo_module)r, is_module=True) +''' % locals())) + + _run_and_check(testdir, testdir.makepyfile(''' +import sys +sys.argv.append('--as-module') +sys.path.append(%(pydevd_dir)r) +import pydevd +py_db = pydevd.PyDB() +py_db.run(%(foo_module)r, is_module=True, set_trace=False) +''' % locals())) + + +def test_run_on_local_module_without_adding_to_pythonpath(testdir): + import sys + import os + + pydevd_dir = os.path.dirname(os.path.dirname(__file__)) + assert os.path.exists(os.path.join(pydevd_dir, 'pydevd.py')) + + foo_module = 'local_foo' + with open(os.path.join(os.getcwd(), 'local_foo.py'), 'w') as stream: + stream.write('print("WorkedLocalFoo")') + + _run_and_check(testdir, testdir.makepyfile(''' +import sys +import os +sys.path.append(%(pydevd_dir)r) +sys.argv.append('--as-module') +cwd = os.path.abspath(os.getcwd()) +while cwd in sys.path: + sys.path.remove(cwd) +import pydevd +py_db = pydevd.PyDB() +py_db.ready_to_run = True +py_db.run(%(foo_module)r, is_module=True) +''' % locals()), check_for='WorkedLocalFoo') + + _run_and_check(testdir, testdir.makepyfile(''' +import sys +import os +sys.argv.append('--as-module') +sys.path.append(%(pydevd_dir)r) +cwd = os.path.abspath(os.getcwd()) +while cwd in sys.path: + sys.path.remove(cwd) +import pydevd +py_db = pydevd.PyDB() +py_db.run(%(foo_module)r, is_module=True, set_trace=False) +''' % locals()), check_for='WorkedLocalFoo') diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_safe_repr.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_safe_repr.py new file mode 100644 index 0000000..918ba33 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_safe_repr.py @@ -0,0 +1,716 @@ +# coding: utf-8 +import collections +import sys +import re +import pytest +from _pydevd_bundle.pydevd_safe_repr import SafeRepr +import json +from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_PY2 + +try: + import numpy as np +except ImportError: + np = None + +PY_VER = sys.version_info[0] +assert PY_VER <= 3 # Fix the code when Python 4 comes around. +PY3K = PY_VER == 3 + +if PY3K: + unicode = str + xrange = range + + +class SafeReprTestBase(object): + + saferepr = SafeRepr() + + def assert_saferepr(self, value, expected): + safe = self.saferepr(value) + + assert safe == expected + return safe + + def assert_unchanged(self, value, expected): + actual = repr(value) + + safe = self.assert_saferepr(value, expected) + assert safe == actual + + def assert_shortened(self, value, expected): + actual = repr(value) + + safe = self.assert_saferepr(value, expected) + assert safe != actual + + def assert_saferepr_regex(self, s, r): + safe = self.saferepr(s) + + assert re.search(r, safe) is not None + return safe + + def assert_unchanged_regex(self, value, expected): + actual = repr(value) + + safe = self.assert_saferepr_regex(value, expected) + assert safe == actual + + def assert_shortened_regex(self, value, expected): + actual = repr(value) + + safe = self.assert_saferepr_regex(value, expected) + assert safe != actual + + +class TestSafeRepr(SafeReprTestBase): + + def test_collection_types(self): + colltypes = [t for t, _, _, _ in SafeRepr.collection_types] + + assert colltypes == [ + tuple, + list, + frozenset, + set, + collections.deque, + ] + + def test_largest_repr(self): + # Find the largest possible repr and ensure it is below our arbitrary + # limit (8KB). + coll = '-' * (SafeRepr.maxstring_outer * 2) + for limit in reversed(SafeRepr.maxcollection[1:]): + coll = [coll] * (limit * 2) + dcoll = {} + for i in range(SafeRepr.maxcollection[0]): + dcoll[str(i) * SafeRepr.maxstring_outer] = coll + text = self.saferepr(dcoll) + # try: + # text_repr = repr(dcoll) + # except MemoryError: + # print('Memory error raised while creating repr of test data') + # text_repr = '' + # print('len(SafeRepr()(dcoll)) = ' + str(len(text)) + + # ', len(repr(coll)) = ' + str(len(text_repr))) + + assert len(text) < 8192 + + +class TestStrings(SafeReprTestBase): + + def test_str_small(self): + value = 'A' * 5 + + self.assert_unchanged(value, "'AAAAA'") + self.assert_unchanged([value], "['AAAAA']") + + def test_str_large(self): + value = 'A' * (SafeRepr.maxstring_outer + 10) + + self.assert_shortened(value, + "'" + 'A' * 43689 + "..." + 'A' * 21844 + "'") + self.assert_shortened([value], "['AAAAAAAAAAAAAAAAAAA...AAAAAAAAA']") + + def test_str_largest_unchanged(self): + value = 'A' * (SafeRepr.maxstring_outer - 2) + + self.assert_unchanged(value, "'" + 'A' * 65534 + "'") + + def test_str_smallest_changed(self): + value = 'A' * (SafeRepr.maxstring_outer - 1) + + self.assert_shortened(value, + "'" + 'A' * 43689 + "..." + 'A' * 21844 + "'") + + def test_str_list_largest_unchanged(self): + value = 'A' * (SafeRepr.maxstring_inner - 2) + + self.assert_unchanged([value], "['" + 'A' * 28 + "']") + + def test_str_list_smallest_changed(self): + value = 'A' * (SafeRepr.maxstring_inner - 1) + + self.assert_shortened([value], "['AAAAAAAAAAAAAAAAAAA...AAAAAAAAA']") + + @pytest.mark.skipif(sys.version_info > (3, 0), reason='Py2 specific test') + def test_unicode_small(self): + value = u'A' * 5 + + self.assert_unchanged(value, "u'AAAAA'") + self.assert_unchanged([value], "[u'AAAAA']") + + @pytest.mark.skipif(sys.version_info > (3, 0), reason='Py2 specific test') + def test_unicode_large(self): + value = u'A' * (SafeRepr.maxstring_outer + 10) + + self.assert_shortened(value, + "u'" + 'A' * 43688 + "..." + 'A' * 21844 + "'") + self.assert_shortened([value], "[u'AAAAAAAAAAAAAAAAAA...AAAAAAAAA']") + + @pytest.mark.skipif(sys.version_info < (3, 0), reason='Py3 specific test') + def test_bytes_small(self): + value = b'A' * 5 + + self.assert_unchanged(value, "b'AAAAA'") + self.assert_unchanged([value], "[b'AAAAA']") + + @pytest.mark.skipif(sys.version_info < (3, 0), reason='Py3 specific test') + def test_bytes_large(self): + value = b'A' * (SafeRepr.maxstring_outer + 10) + + self.assert_shortened(value, + "b'" + 'A' * 43688 + "..." + 'A' * 21844 + "'") + self.assert_shortened([value], "[b'AAAAAAAAAAAAAAAAAA...AAAAAAAAA']") + + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_bytearray_small(self): + # raise NotImplementedError + # + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_bytearray_large(self): + # raise NotImplementedError + + +class RawValueTests(SafeReprTestBase): + + def setUp(self): + super(RawValueTests, self).setUp() + self.saferepr.raw_value = True + + def test_unicode_raw(self): + value = u'A\u2000' * 10000 + self.assert_saferepr(value, value) + + def test_bytes_raw(self): + value = b'A' * 10000 + self.assert_saferepr(value, value.decode('ascii')) + + def test_bytearray_raw(self): + value = bytearray(b'A' * 5) + self.assert_saferepr(value, value.decode('ascii')) + +# class TestNumbers(SafeReprTestBase): +# +# @pytest.mark.skip(reason='not written') # TODO: finish! +# def test_int(self): +# raise NotImplementedError +# +# @pytest.mark.skip(reason='not written') # TODO: finish! +# def test_float(self): +# raise NotImplementedError +# +# @pytest.mark.skip(reason='not written') # TODO: finish! +# def test_complex(self): +# raise NotImplementedError + + +class ContainerBase(object): + + CLASS = None + LEFT = None + RIGHT = None + + @property + def info(self): + try: + return self._info + except AttributeError: + for info in SafeRepr.collection_types: + ctype, _, _, _ = info + if self.CLASS is ctype: + type(self)._info = info + return info + else: + raise TypeError('unsupported') + + def _combine(self, items, prefix, suffix, large): + contents = ', '.join(str(item) for item in items) + if large: + contents += ', ...' + return prefix + contents + suffix + + def combine(self, items, large=False): + if self.LEFT is None: + pytest.skip('unsupported') + return self._combine(items, self.LEFT, self.RIGHT, large=large) + + def combine_nested(self, depth, items, large=False): + _, _prefix, _suffix, comma = self.info + prefix = _prefix * (depth + 1) + if comma: + suffix = _suffix + ("," + _suffix) * depth + else: + suffix = _suffix * (depth + 1) + # print("ctype = " + ctype.__name__ + ", maxcollection[" + + # str(i) + "] == " + str(SafeRepr.maxcollection[i])) + return self._combine(items, prefix, suffix, large=large) + + def test_large_flat(self): + c1 = self.CLASS(range(SafeRepr.maxcollection[0] * 2)) + items = range(SafeRepr.maxcollection[0] - 1) + c1_expect = self.combine(items, large=True) + + self.assert_shortened(c1, c1_expect) + + def test_large_nested(self): + c1 = self.CLASS(range(SafeRepr.maxcollection[0] * 2)) + c1_items = range(SafeRepr.maxcollection[1] - 1) + c1_expect = self.combine(c1_items, large=True) + + c2 = self.CLASS(c1 for _ in range(SafeRepr.maxcollection[0] * 2)) + items = (c1_expect for _ in range(SafeRepr.maxcollection[0] - 1)) + c2_expect = self.combine(items, large=True) + + self.assert_shortened(c2, c2_expect) + + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_empty(self): + # raise NotImplementedError + # + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_subclass(self): + # raise NotImplementedError + + def test_boundary(self): + items1 = range(SafeRepr.maxcollection[0] - 1) + items2 = range(SafeRepr.maxcollection[0]) + items3 = range(SafeRepr.maxcollection[0] + 1) + c1 = self.CLASS(items1) + c2 = self.CLASS(items2) + c3 = self.CLASS(items3) + expected1 = self.combine(items1) + expected2 = self.combine(items2[:-1], large=True) + expected3 = self.combine(items3[:-2], large=True) + + self.assert_unchanged(c1, expected1) + self.assert_shortened(c2, expected2) + self.assert_shortened(c3, expected3) + + def test_nested(self): + ctype = self.CLASS + for i in range(1, len(SafeRepr.maxcollection)): + items1 = range(SafeRepr.maxcollection[i] - 1) + items2 = range(SafeRepr.maxcollection[i]) + items3 = range(SafeRepr.maxcollection[i] + 1) + c1 = self.CLASS(items1) + c2 = self.CLASS(items2) + c3 = self.CLASS(items3) + for _j in range(i): + c1, c2, c3 = ctype((c1,)), ctype((c2,)), ctype((c3,)) + expected1 = self.combine_nested(i, items1) + expected2 = self.combine_nested(i, items2[:-1], large=True) + expected3 = self.combine_nested(i, items3[:-2], large=True) + + self.assert_unchanged(c1, expected1) + self.assert_shortened(c2, expected2) + self.assert_shortened(c3, expected3) + + +class TestTuples(ContainerBase, SafeReprTestBase): + + CLASS = tuple + LEFT = '(' + RIGHT = ')' + + +class TestLists(ContainerBase, SafeReprTestBase): + + CLASS = list + LEFT = '[' + RIGHT = ']' + + def test_directly_recursive(self): + value = [1, 2] + value.append(value) + + self.assert_unchanged(value, '[1, 2, [...]]') + + def test_indirectly_recursive(self): + value = [1, 2] + value.append([value]) + + self.assert_unchanged(value, '[1, 2, [[...]]]') + + +class TestFrozensets(ContainerBase, SafeReprTestBase): + + CLASS = frozenset + + +class TestSets(ContainerBase, SafeReprTestBase): + + CLASS = set + if PY_VER != 2: + LEFT = '{' + RIGHT = '}' + + def test_nested(self): + pytest.skip('unsupported') + + def test_large_nested(self): + pytest.skip('unsupported') + + +class TestDicts(SafeReprTestBase): + + def test_large_key(self): + value = { + 'a' * SafeRepr.maxstring_inner * 3: '', + } + + self.assert_shortened_regex(value, r"{'a+\.\.\.a+': ''}") + + def test_large_value(self): + value = { + '': 'a' * SafeRepr.maxstring_inner * 2, + } + + self.assert_shortened_regex(value, r"{'': 'a+\.\.\.a+'}") + + def test_large_both(self): + value = {} + key = 'a' * SafeRepr.maxstring_inner * 2 + value[key] = key + + self.assert_shortened_regex(value, r"{'a+\.\.\.a+': 'a+\.\.\.a+'}") + + def test_nested_value(self): + d1 = {} + d1_key = 'a' * SafeRepr.maxstring_inner * 2 + d1[d1_key] = d1_key + d2 = {d1_key: d1} + d3 = {d1_key: d2} + + self.assert_shortened_regex(d2, r"{'a+\.\.\.a+': {'a+\.\.\.a+': 'a+\.\.\.a+'}}") # noqa + if len(SafeRepr.maxcollection) == 2: + self.assert_shortened_regex(d3, r"{'a+\.\.\.a+': {'a+\.\.\.a+': {\.\.\.}}}") # noqa + else: + self.assert_shortened_regex(d3, r"{'a+\.\.\.a+': {'a+\.\.\.a+': {'a+\.\.\.a+': 'a+\.\.\.a+'}}}") # noqa + + def test_empty(self): + # Ensure empty dicts work + self.assert_unchanged({}, '{}') + + def test_sorted(self): + # Ensure dict keys are sorted + d1 = {} + d1['c'] = None + d1['b'] = None + d1['a'] = None + self.assert_saferepr(d1, "{'a': None, 'b': None, 'c': None}") + + @pytest.mark.skipif(sys.version_info < (3, 0), reason='Py3 specific test') + def test_unsortable_keys(self): + # Ensure dicts with unsortable keys do not crash + d1 = {} + for _ in range(100): + d1[object()] = None + with pytest.raises(TypeError): + list(sorted(d1)) + self.saferepr(d1) + + def test_directly_recursive(self): + value = {1: None} + value[2] = value + + self.assert_unchanged(value, '{1: None, 2: {...}}') + + def test_indirectly_recursive(self): + value = {1: None} + value[2] = {3: value} + + self.assert_unchanged(value, '{1: None, 2: {3: {...}}}') + + +class TestOtherPythonTypes(SafeReprTestBase): + # not critical to test: + # singletons + # + # + # + # memoryview + # classmethod + # staticmethod + # property + # enumerate + # reversed + # object + # type + # super + + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_file(self): + # raise NotImplementedError + + def test_range_small(self): + range_name = xrange.__name__ + value = xrange(1, 42) + + self.assert_unchanged(value, '%s(1, 42)' % (range_name,)) + + @pytest.mark.skipif(sys.version_info < (3, 0), reason='Py3 specific test') + def test_range_large_stop_only(self): + range_name = xrange.__name__ + stop = SafeRepr.maxcollection[0] + value = xrange(stop) + + self.assert_unchanged(value, + '%s(0, %s)' % (range_name, stop)) + + def test_range_large_with_start(self): + range_name = xrange.__name__ + stop = SafeRepr.maxcollection[0] + 1 + value = xrange(1, stop) + + self.assert_unchanged(value, + '%s(1, %s)' % (range_name, stop)) + + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_named_struct(self): + # # e.g. sys.version_info + # raise NotImplementedError + # + # @pytest.mark.skip(reason='not written') # TODO: finish! + # def test_namedtuple(self): + # raise NotImplementedError + # + # @pytest.mark.skip(reason='not written') # TODO: finish! + # @pytest.mark.skipif(sys.version_info < (3, 0), reason='Py3 specific test') + # def test_SimpleNamespace(self): + # raise NotImplementedError + + +class TestUserDefinedObjects(SafeReprTestBase): + + def test_broken_repr(self): + + class TestClass(object): + + def __repr__(self): + raise NameError + + value = TestClass() + + with pytest.raises(NameError): + repr(TestClass()) + self.assert_saferepr(value, object.__repr__(value)) + + def test_large(self): + + class TestClass(object): + + def __repr__(self): + return '<' + 'A' * SafeRepr.maxother_outer * 2 + '>' + + value = TestClass() + + self.assert_shortened_regex(value, r'\') + + def test_inherit_repr(self): + + class TestClass(dict): + pass + + value_dict = TestClass() + + class TestClass2(list): + pass + + value_list = TestClass2() + + self.assert_unchanged(value_dict, '{}') + self.assert_unchanged(value_list, '[]') + + def test_custom_repr(self): + + class TestClass(dict): + + def __repr__(self): + return 'MyRepr' + + value1 = TestClass() + + class TestClass2(list): + + def __repr__(self): + return 'MyRepr' + + value2 = TestClass2() + + self.assert_unchanged(value1, 'MyRepr') + self.assert_unchanged(value2, 'MyRepr') + + def test_custom_repr_many_items(self): + + class TestClass(list): + + def __init__(self, it=()): + list.__init__(self, it) + + def __repr__(self): + return 'MyRepr' + + value1 = TestClass(xrange(0, 15)) + value2 = TestClass(xrange(0, 16)) + value3 = TestClass([TestClass(xrange(0, 10))]) + value4 = TestClass([TestClass(xrange(0, 11))]) + + self.assert_unchanged(value1, 'MyRepr') + self.assert_shortened(value2, '') + self.assert_unchanged(value3, 'MyRepr') + self.assert_shortened(value4, '') + + def test_custom_repr_large_item(self): + + class TestClass(list): + + def __init__(self, it=()): + list.__init__(self, it) + + def __repr__(self): + return 'MyRepr' + + value1 = TestClass(['a' * (SafeRepr.maxcollection[1] + 1)]) + value2 = TestClass(['a' * (SafeRepr.maxstring_inner + 1)]) + + self.assert_unchanged(value1, 'MyRepr') + self.assert_shortened(value2, '') + + +@pytest.mark.skipif(np is None, reason='could not import numpy') +class TestNumpy(SafeReprTestBase): + # numpy types should all use their native reprs, even arrays + # exceeding limits. + + def test_int32(self): + value = np.int32(123) + + self.assert_unchanged(value, repr(value)) + + def test_float32(self): + value = np.float32(123.456) + + self.assert_unchanged(value, repr(value)) + + def test_zeros(self): + value = np.zeros(SafeRepr.maxcollection[0] + 1) + + self.assert_unchanged(value, repr(value)) + + +@pytest.mark.parametrize('params', [ + # In python 2, unicode slicing may or may not work well depending on whether it's a ucs-2 or + # ucs-4 build (so, we have to strip the high-surrogate if it's ucs-2 and the number of chars + # will be different). + + {'maxother_outer': 20, 'input': u"😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄F😄FF😄F", 'output': (u"😄😄😄😄😄😄...FF😄F", u"😄😄😄😄😄😄😄😄😄😄😄😄😄...F😄FF😄F")}, + + {'maxother_outer': 20, 'input': u"😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄FFFFFFFF", 'output': (u"😄😄😄😄😄😄...FFFFFF", u"😄😄😄😄😄😄😄😄😄😄😄😄😄...FFFFFF")}, + {'maxother_outer': 20, 'input': u"ðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒFFFFFFFF", 'output': (u"ðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒ...FFFFFF", u"ðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒ...FFFFFF")}, + {'maxother_outer': 10, 'input': u"😄😄😄😄😄😄😄😄😄FFFFFFFF", 'output': (u"😄😄😄...FFF", u"😄😄😄😄😄😄...FFF")}, + {'maxother_outer': 10, 'input': u"ðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒFFFFFFFF", 'output': (u"ðŸŒðŸŒðŸŒ...FFF", u"ðŸŒðŸŒðŸŒðŸŒðŸŒðŸŒ...FFF")}, + + # Regular unicode + {'maxother_outer': 20, 'input': u"ωωωωωωωωωωωωωωωωωωωωωωωFFFFFFFF", 'output': u"ωωωωωωωωωωωωω...FFFFFF"}, + {'maxother_outer': 20, 'input': u"������������FFFFFFFF", 'output': u"������������F...FFFFFF"}, + {'maxother_outer': 10, 'input': u"������������FFFFFFFF", 'output': u"������...FFF"}, + + # Note that we actually get the repr() in this case as we can't decode it with any of the available encodings. + {'maxother_outer': 10, 'input': b'\xed\xbd\xbf\xff\xfe\xfa\xfd' * 10, 'output': b"'\\xed\\...fd'"}, + {'maxother_outer': 20, 'input': b'\xed\xbd\xbf\xff\xfe\xfa\xfd' * 10, 'output': b"'\\xed\\xbd\\xbf...a\\xfd'"}, + # Check that we use repr() even if it fits the maxother_outer limit. + {'maxother_outer': 100, 'input': b'\xed\xbd\xbf\xff\xfe\xfa\xfd', 'output': "'\\xed\\xbd\\xbf\\xff\\xfe\\xfa\\xfd'"}, + + # Note that with latin1 encoding we can actually decode the string but when encoding back to utf-8 we have garbage + # (couldn't find a good approach to know what to do here as we've actually been able to decode it as + # latin-1 because it's a very permissive encoding). + { + 'maxother_outer': 10, + 'sys_stdout_encoding': 'latin1', + 'input': b'\xed\xbd\xbf\xff\xfe\xfa\xfd' * 10, + 'output': b'\xc3\xad\xc2\xbd\xc2\xbf\xc3\xbf\xc3\xbe\xc3\xba...\xc3\xbe\xc3\xba\xc3\xbd' + }, +]) +@pytest.mark.skipif(not IS_PY2, reason='Py2 specific test.') +def test_py2_bytes_slicing(params): + safe_repr = SafeRepr() + safe_repr.locale_preferred_encoding = 'ascii' + safe_repr.sys_stdout_encoding = params.get('sys_stdout_encoding', 'ascii') + + safe_repr.maxother_outer = params['maxother_outer'] + + # This is the encoding that we expect back (because json needs to be able to encode it + # later on, so, the return from SafeRepr must always be utf-8 regardless of the input). + encoding = 'utf-8' + + class MyObj(object): + + def __repr__(self): + ret = params['input'] + if isinstance(ret, unicode): + ret = ret.encode(encoding) + return ret + + expected_output = params['output'] + computed = safe_repr(MyObj()) + + expect_unicode = False + if isinstance(expected_output, unicode): + expect_unicode = True + if isinstance(expected_output, tuple) and isinstance(expected_output[0], unicode): + expect_unicode = True + + if expect_unicode: + computed = computed.decode(encoding) + if isinstance(expected_output, tuple): + assert computed in expected_output + else: + assert computed == expected_output + else: + assert repr(computed) == repr(expected_output) + + # Check that we can json-encode the return. + assert json.dumps(computed) + + +@pytest.mark.parametrize('params', [ + {'maxother_outer': 20, 'input': "😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄FFFFFFFF", 'output': '😄😄😄😄😄😄😄😄😄😄😄😄😄...FFFFFF'}, + {'maxother_outer': 10, 'input': "😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄FFFFFFFF", 'output': '😄😄😄😄😄😄...FFF'}, + {'maxother_outer': 10, 'input': u"������������FFFFFFFF", 'output': u"������...FFF"}, + + # Because we can't return bytes, byte-related tests aren't needed (and str works as it should). +]) +@pytest.mark.skipif(IS_PY2, reason='Py3 specific test') +def test_py3_str_slicing(params): + # Note: much simpler in python because __repr__ is required to return str + # (which is actually unicode). + safe_repr = SafeRepr() + safe_repr.locale_preferred_encoding = 'ascii' + safe_repr.sys_stdout_encoding = params.get('sys_stdout_encoding', 'ascii') + + safe_repr.maxother_outer = params['maxother_outer'] + + class MyObj(object): + + def __repr__(self): + return params['input'] + + expected_output = params['output'] + computed = safe_repr(MyObj()) + assert repr(computed) == repr(expected_output) + + # Check that we can json-encode the return. + assert json.dumps(computed) + + +def test_raw(): + safe_repr = SafeRepr() + safe_repr.raw_value = True + obj = b'\xed\xbd\xbf\xff\xfe\xfa\xfd' + raw_value_repr = safe_repr(obj) + assert isinstance(raw_value_repr, str) # bytes on py2, str on py3 + if IS_PY2: + assert raw_value_repr == obj.decode('latin1').encode('utf-8') + else: + assert raw_value_repr == obj.decode('latin1') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_save_locals.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_save_locals.py new file mode 100644 index 0000000..ed4bd2c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_save_locals.py @@ -0,0 +1,101 @@ +import inspect +import sys +import unittest + +from _pydevd_bundle.pydevd_save_locals import save_locals +from _pydevd_bundle.pydevd_constants import IS_JYTHON, IS_IRONPYTHON +import pytest + + +def use_save_locals(name, value): + """ + Attempt to set the local of the given name to value, using locals_to_fast. + """ + frame = inspect.currentframe().f_back + locals_dict = frame.f_locals + locals_dict[name] = value + + save_locals(frame) + + +def check_method(fn): + """ + A harness for testing methods that attempt to modify the values of locals on the stack. + """ + x = 1 + + # The method 'fn' should attempt to set x = 2 in the current frame. + fn('x', 2) + + return x + + + +@pytest.mark.skipif(IS_JYTHON or IS_IRONPYTHON, reason='CPython/pypy only') +class TestSetLocals(unittest.TestCase): + """ + Test setting locals in one function from another function using several approaches. + """ + + def test_set_locals_using_save_locals(self): + x = check_method(use_save_locals) + self.assertEqual(x, 2) # Expected to succeed + + + def test_frame_simple_change(self): + frame = sys._getframe() + a = 20 + frame.f_locals['a'] = 50 + save_locals(frame) + self.assertEqual(50, a) + + + def test_frame_co_freevars(self): + + outer_var = 20 + + def func(): + frame = sys._getframe() + frame.f_locals['outer_var'] = 50 + save_locals(frame) + self.assertEqual(50, outer_var) + + func() + + def test_frame_co_cellvars(self): + + def check_co_vars(a): + frame = sys._getframe() + def function2(): + print(a) + + assert 'a' in frame.f_code.co_cellvars + frame = sys._getframe() + frame.f_locals['a'] = 50 + save_locals(frame) + self.assertEqual(50, a) + + check_co_vars(1) + + + def test_frame_change_in_inner_frame(self): + def change(f): + self.assertTrue(f is not sys._getframe()) + f.f_locals['a']= 50 + save_locals(f) + + + frame = sys._getframe() + a = 20 + change(frame) + self.assertEqual(50, a) + + +if __name__ == '__main__': + suite = unittest.TestSuite() +# suite.addTest(TestSetLocals('test_set_locals_using_dict')) +# #suite.addTest(Test('testCase10a')) +# unittest.TextTestRunner(verbosity=3).run(suite) + + suite = unittest.makeSuite(TestSetLocals) + unittest.TextTestRunner(verbosity=3).run(suite) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_schema.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_schema.py new file mode 100644 index 0000000..5470076 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_schema.py @@ -0,0 +1,142 @@ +from _pydevd_bundle._debug_adapter.pydevd_schema import InitializeRequest, \ + InitializeRequestArguments, InitializeResponse, Capabilities +from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema +from _pydevd_bundle._debug_adapter.pydevd_schema import ThreadsResponse + + +def test_schema(): + + json_msg = ''' +{ + "arguments": { + "adapterID": "pydevd", + "clientID": "vscode", + "clientName": "Visual Studio Code", + "columnsStartAt1": true, + "linesStartAt1": true, + "locale": "en-us", + "pathFormat": "path", + "supportsRunInTerminalRequest": true, + "supportsVariablePaging": true, + "supportsVariableType": true + }, + "command": "initialize", + "seq": 1, + "type": "request" +}''' + + initialize_request = pydevd_base_schema.from_json(json_msg) + assert initialize_request.__class__ == InitializeRequest + assert initialize_request.arguments.__class__ == InitializeRequestArguments + assert initialize_request.arguments.adapterID == 'pydevd' + assert initialize_request.command == 'initialize' + assert initialize_request.type == 'request' + assert initialize_request.seq == 1 + + response = pydevd_base_schema.build_response(initialize_request) + assert response.__class__ == InitializeResponse + assert response.seq == -1 # Must be set before sending + assert response.command == 'initialize' + assert response.type == 'response' + assert response.body.__class__ == Capabilities + + assert response.to_dict() == { + "seq":-1, + "type": "response", + "request_seq": 1, + "success": True, + "command": "initialize", + "body": {} + } + + capabilities = response.body # : :type capabilities: Capabilities + capabilities.supportsCompletionsRequest = True + assert response.to_dict() == { + "seq":-1, + "type": "response", + "request_seq": 1, + "success": True, + "command": "initialize", + "body": {'supportsCompletionsRequest':True} + } + + initialize_event = pydevd_schema.InitializedEvent() + assert initialize_event.to_dict() == { + "seq":-1, + "type": "event", + "event": "initialized" + } + + +def test_schema_translation_frame(): + pydevd_base_schema.BaseSchema.initialize_ids_translation() + stack_trace_arguments = pydevd_schema.StackTraceArguments(threadId=1) + stack_trace_request = pydevd_schema.StackTraceRequest(stack_trace_arguments) + + stackFrames = [ + pydevd_schema.StackFrame(id=2 ** 45, name='foo', line=1, column=1).to_dict(), + pydevd_schema.StackFrame(id=2 ** 46, name='bar', line=1, column=1).to_dict(), + ] + body = pydevd_schema.StackTraceResponseBody(stackFrames) + stack_trace_response = pydevd_base_schema.build_response(stack_trace_request, kwargs=dict(body=body)) + as_dict = stack_trace_response.to_dict(update_ids_to_dap=True) + assert as_dict == { + 'type': 'response', + 'request_seq':-1, + 'success': True, + 'command': 'stackTrace', + 'body': {'stackFrames': [ + {'id': 1, 'name': 'foo', 'line': 1, 'column': 1, 'source': {}}, + {'id': 2, 'name': 'bar', 'line': 1, 'column': 1, 'source': {}}, + ]}, + 'seq':-1} + + reconstructed = pydevd_base_schema.from_dict(as_dict, update_ids_from_dap=True) + assert reconstructed.to_dict() == { + 'type': 'response', + 'request_seq':-1, + 'success': True, + 'command': 'stackTrace', + 'body': {'stackFrames': [ + {'id': 2 ** 45, 'name': 'foo', 'line': 1, 'column': 1, 'source': {}}, + {'id': 2 ** 46, 'name': 'bar', 'line': 1, 'column': 1, 'source': {}} + ]}, + 'seq':-1 + } + + +def test_schema_translation_thread(): + from _pydevd_bundle._debug_adapter.pydevd_schema import ThreadsRequest + pydevd_base_schema.BaseSchema.initialize_ids_translation() + + threads = [ + pydevd_schema.Thread(id=2 ** 45, name='foo').to_dict(), + pydevd_schema.Thread(id=2 ** 46, name='bar').to_dict(), + ] + body = pydevd_schema.ThreadsResponseBody(threads) + threads_request = ThreadsRequest() + threads_response = pydevd_base_schema.build_response(threads_request, kwargs=dict(body=body)) + as_dict = threads_response.to_dict(update_ids_to_dap=True) + assert as_dict == { + 'type': 'response', + 'request_seq':-1, + 'success': True, + 'command': 'threads', + 'body': {'threads': [ + {'id': 1, 'name': 'foo'}, + {'id': 2, 'name': 'bar'}, + ]}, + 'seq':-1} + + reconstructed = pydevd_base_schema.from_dict(as_dict, update_ids_from_dap=True) + assert reconstructed.to_dict() == { + 'type': 'response', + 'request_seq':-1, + 'success': True, + 'command': 'threads', + 'body': {'threads': [ + {'id': 2 ** 45, 'name': 'foo'}, + {'id': 2 ** 46, 'name': 'bar'} + ]}, + 'seq':-1 + } diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_suspended_frames_manager.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_suspended_frames_manager.py new file mode 100644 index 0000000..0b15f67 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_suspended_frames_manager.py @@ -0,0 +1,133 @@ +import sys +from _pydevd_bundle.pydevd_constants import int_types +from _pydevd_bundle.pydevd_resolver import MAX_ITEMS_TO_HANDLE, TOO_LARGE_ATTR + + +def get_frame(): + var1 = 1 + var2 = [var1] + var3 = {33: [var1]} + return sys._getframe() + + +def check_vars_dict_expected(as_dict, expected): + assert as_dict == expected + + +def test_suspended_frames_manager(): + from _pydevd_bundle.pydevd_suspended_frames import SuspendedFramesManager + suspended_frames_manager = SuspendedFramesManager() + py_db = None + with suspended_frames_manager.track_frames(py_db) as tracker: + # : :type tracker: _FramesTracker + thread_id = 'thread1' + frame = get_frame() + tracker.track(thread_id, frame, frame_id_to_lineno={}) + + assert suspended_frames_manager.get_thread_id_for_variable_reference(id(frame)) == thread_id + + variable = suspended_frames_manager.get_variable(id(frame)) + + # Should be properly sorted. + assert ['var1', 'var2', 'var3'] == [x.get_name()for x in variable.get_children_variables()] + + as_dict = dict((x.get_name(), x.get_var_data()) for x in variable.get_children_variables()) + var_reference = as_dict['var2'].pop('variablesReference') + assert isinstance(var_reference, int_types) # The variable reference is always a new int. + assert isinstance(as_dict['var3'].pop('variablesReference'), int_types) # The variable reference is always a new int. + + check_vars_dict_expected(as_dict, { + 'var1': {'name': 'var1', 'value': '1', 'type': 'int', 'evaluateName': 'var1', 'variablesReference': 0}, + 'var2': {'name': 'var2', 'value': '[1]', 'type': 'list', 'evaluateName': 'var2'}, + 'var3': {'name': 'var3', 'value': '{33: [1]}', 'type': 'dict', 'evaluateName': 'var3'} + }) + + # Now, same thing with a different format. + as_dict = dict((x.get_name(), x.get_var_data(fmt={'hex': True})) for x in variable.get_children_variables()) + var_reference = as_dict['var2'].pop('variablesReference') + assert isinstance(var_reference, int_types) # The variable reference is always a new int. + assert isinstance(as_dict['var3'].pop('variablesReference'), int_types) # The variable reference is always a new int. + + check_vars_dict_expected(as_dict, { + 'var1': {'name': 'var1', 'value': '0x1', 'type': 'int', 'evaluateName': 'var1', 'variablesReference': 0}, + 'var2': {'name': 'var2', 'value': '[0x1]', 'type': 'list', 'evaluateName': 'var2'}, + 'var3': {'name': 'var3', 'value': '{0x21: [0x1]}', 'type': 'dict', 'evaluateName': 'var3'} + }) + + var2 = dict((x.get_name(), x) for x in variable.get_children_variables())['var2'] + children_vars = var2.get_children_variables() + as_dict = (dict([x.get_name(), x.get_var_data()] for x in children_vars)) + assert as_dict == { + '0': {'name': '0', 'value': '1', 'type': 'int', 'evaluateName': 'var2[0]', 'variablesReference': 0 }, + '__len__': {'name': '__len__', 'value': '1', 'type': 'int', 'evaluateName': 'len(var2)', 'variablesReference': 0, 'presentationHint': {'attributes': ['readOnly']}, }, + } + + var3 = dict((x.get_name(), x) for x in variable.get_children_variables())['var3'] + children_vars = var3.get_children_variables() + as_dict = (dict([x.get_name(), x.get_var_data()] for x in children_vars)) + assert isinstance(as_dict['33'].pop('variablesReference'), int_types) # The variable reference is always a new int. + + check_vars_dict_expected(as_dict, { + '33': {'name': '33', 'value': "[1]", 'type': 'list', 'evaluateName': 'var3[33]'}, + '__len__': {'name': '__len__', 'value': '1', 'type': 'int', 'evaluateName': 'len(var3)', 'variablesReference': 0, 'presentationHint': {'attributes': ['readOnly']}, } + }) + + +_NUMBER_OF_ITEMS_TO_CREATE = MAX_ITEMS_TO_HANDLE + 300 + + +def get_dict_large_frame(): + obj = {} + for idx in range(_NUMBER_OF_ITEMS_TO_CREATE): + obj[idx] = (1) + return sys._getframe() + + +def get_set_large_frame(): + obj = set() + for idx in range(_NUMBER_OF_ITEMS_TO_CREATE): + obj.add(idx) + return sys._getframe() + + +def get_tuple_large_frame(): + obj = tuple(range(_NUMBER_OF_ITEMS_TO_CREATE)) + return sys._getframe() + + +def test_get_child_variables(): + from _pydevd_bundle.pydevd_suspended_frames import SuspendedFramesManager + suspended_frames_manager = SuspendedFramesManager() + py_db = None + for frame in ( + get_dict_large_frame(), + get_set_large_frame(), + get_tuple_large_frame(), + ): + with suspended_frames_manager.track_frames(py_db) as tracker: + # : :type tracker: _FramesTracker + thread_id = 'thread1' + tracker.track(thread_id, frame, frame_id_to_lineno={}) + + assert suspended_frames_manager.get_thread_id_for_variable_reference(id(frame)) == thread_id + + variable = suspended_frames_manager.get_variable(id(frame)) + + children_variables = variable.get_child_variable_named('obj').get_children_variables() + assert len(children_variables) < _NUMBER_OF_ITEMS_TO_CREATE + + found_too_large = False + found_len = False + for x in children_variables: + if x.name == TOO_LARGE_ATTR: + var_data = x.get_var_data() + assert 'readOnly' in var_data['presentationHint']['attributes'] + found_too_large = True + elif x.name == '__len__': + found_len = True + + if not found_too_large: + raise AssertionError('Expected to find variable named: %s' % (TOO_LARGE_ATTR,)) + if not found_len: + raise AssertionError('Expected to find variable named: __len__') + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_tracing_gotchas.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_tracing_gotchas.py new file mode 100644 index 0000000..b120db8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_tracing_gotchas.py @@ -0,0 +1,102 @@ +import pytest +import sys +from tests_python.test_debugger import IS_PY26, IS_PY34 +from _pydevd_bundle.pydevd_constants import NO_FTRACE +from tests_python.debugger_unittest import IS_JYTHON + + +class Tracer(object): + + def __init__(self): + self.call_calls = 0 + self.line_calls = 0 + + def trace_func(self, frame, event, arg): + if event == 'call': + self.call_calls += 1 + return self.on_call() + + elif event == 'line': + self.line_calls += 1 + # Should disable tracing when None is returned (but doesn't). + return self.on_line(frame, event, arg) + + else: + return self.trace_func + + def on_call(self): + return self.trace_func + + def on_line(self, frame, event, arg): + return None + + +class TracerSettingNone(Tracer): + + def on_line(self, frame, event, arg): + frame.f_trace = NO_FTRACE + return NO_FTRACE + + +class TracerChangeToOtherTracing(Tracer): + + def on_line(self, frame, event, arg): + return self._no_trace + + def _no_trace(self, frame, event, arg): + return self._no_trace + + +class TracerDisableOnCall(Tracer): + + def on_call(self): + return None + + +def test_tracing_gotchas(): + ''' + Summary of the gotchas tested: + + If 'call' is used, a None return value is used for the tracing. Afterwards the return may or may + not be ignored depending on the Python version. + + Also, on Python 2.6, the trace function may not be set to None as it'll give an error + afterwards (it needs to be set to an empty tracing function). + + All of the versions seem to work when the return value is a new callable though. + + Note: according to: https://docs.python.org/3/library/sys.html#sys.settrace the behavior + does not follow the spec (but we have to work with it nonetheless). + + Note: Jython seems to do what's written in the docs. + ''' + + def method(): + _a = 1 + _b = 1 + _c = 1 + _d = 1 + + for tracer, line_events in ( + (Tracer(), 1 if IS_JYTHON else 4), + (TracerSettingNone(), 1), + (TracerChangeToOtherTracing(), 1), + (TracerDisableOnCall(), 0), + ): + curr_trace_func = sys.gettrace() + try: + sys.settrace(tracer.trace_func) + + method() + + if tracer.call_calls != 1: + pytest.fail('Expected a single call event. Found: %s' % (tracer.call_calls)) + + if tracer.line_calls != line_events: + pytest.fail('Expected %s line events. Found: %s. Tracer: %s' % (line_events, tracer.line_calls, tracer)) + finally: + sys.settrace(curr_trace_func) + + +if __name__ == '__main__': + pytest.main(['-k', 'test_tracing_gotchas']) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_tracing_on_top_level.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_tracing_on_top_level.py new file mode 100644 index 0000000..a16cd7b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_tracing_on_top_level.py @@ -0,0 +1,484 @@ +from pydevd import PyDB +import pytest +from tests_python.debugger_unittest import IS_CPYTHON +import threading + +DEBUG = False + + +class DummyTopLevelFrame(object): + + __slots__ = ['f_code', 'f_back', 'f_lineno', 'f_trace'] + + def __init__(self, method): + self.f_code = method.__code__ + self.f_back = None + self.f_lineno = method.__code__.co_firstlineno + + +class DummyWriter(object): + + __slots__ = ['commands', 'command_meanings'] + + def __init__(self): + self.commands = [] + self.command_meanings = [] + + def add_command(self, cmd): + from _pydevd_bundle.pydevd_comm import ID_TO_MEANING + meaning = ID_TO_MEANING[str(cmd.id)] + if DEBUG: + print(meaning) + self.command_meanings.append(meaning) + if DEBUG: + print(cmd._as_bytes.decode('utf-8')) + self.commands.append(cmd) + + +class DummyPyDb(PyDB): + + def __init__(self): + PyDB.__init__(self, set_as_global=False) + + def do_wait_suspend( + self, thread, frame, event, arg, *args, **kwargs): + from _pydevd_bundle.pydevd_constants import STATE_RUN + info = thread.additional_info + info.pydev_original_step_cmd = -1 + info.pydev_step_cmd = -1 + info.pydev_step_stop = None + info.pydev_state = STATE_RUN + + return PyDB.do_wait_suspend(self, thread, frame, event, arg, *args, **kwargs) + + +class _TraceTopLevel(object): + + def __init__(self): + self.py_db = DummyPyDb() + self.py_db.writer = DummyWriter() + + def set_target_func(self, target_func): + self.frame = DummyTopLevelFrame(target_func) + self.target_func = target_func + + def get_exception_arg(self): + import sys + try: + raise AssertionError() + except: + arg = sys.exc_info() + return arg + + def create_add_exception_breakpoint_with_policy( + self, exception, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries): + return '\t'.join(str(x) for x in [ + exception, notify_on_handled_exceptions, notify_on_unhandled_exceptions, ignore_libraries]) + + def add_unhandled_exception_breakpoint(self): + from _pydevd_bundle.pydevd_process_net_command import process_net_command + from tests_python.debugger_unittest import CMD_ADD_EXCEPTION_BREAK + for exc_name in ('AssertionError', 'RuntimeError'): + process_net_command( + self.py_db, + CMD_ADD_EXCEPTION_BREAK, + 1, + self.create_add_exception_breakpoint_with_policy(exc_name, '0', '1', '0'), + ) + + def assert_last_commands(self, *commands): + assert self.py_db.writer.command_meanings[-len(commands):] == list(commands) + + def assert_no_commands(self, *commands): + for command in commands: + assert command not in self.py_db.writer.command_meanings + + def trace_dispatch(self, event, arg): + from _pydevd_bundle import pydevd_trace_dispatch_regular + + self.new_trace_func = pydevd_trace_dispatch_regular.trace_dispatch(self.py_db, self.frame, event, arg) + return self.new_trace_func + + def call_trace_dispatch(self, line): + self.frame.f_lineno = line + return self.trace_dispatch('call', None) + + def exception_trace_dispatch(self, line, arg): + self.frame.f_lineno = line + self.new_trace_func = self.new_trace_func(self.frame, 'exception', arg) + + def return_trace_dispatch(self, line): + self.frame.f_lineno = line + self.new_trace_func = self.new_trace_func(self.frame, 'return', None) + + def assert_paused(self): + self.assert_last_commands('CMD_THREAD_SUSPEND', 'CMD_THREAD_RUN') + + def assert_not_paused(self): + self.assert_no_commands('CMD_THREAD_SUSPEND', 'CMD_THREAD_RUN') + + +@pytest.yield_fixture +def trace_top_level(): + # Note: we trace with a dummy frame with no f_back to simulate the issue in a remote attach. + yield _TraceTopLevel() + threading.current_thread().additional_info = None + + +@pytest.fixture +def trace_top_level_unhandled(trace_top_level): + trace_top_level.add_unhandled_exception_breakpoint() + return trace_top_level + + +_expected_functions_to_test = 0 + + +def mark_handled(func): + global _expected_functions_to_test + _expected_functions_to_test += 1 + func.__handled__ = True + return func + + +def mark_unhandled(func): + global _expected_functions_to_test + _expected_functions_to_test += 1 + func.__handled__ = False + return func + + +#------------------------------------------------------------------------------------------- Handled +@mark_handled +def raise_handled_exception(): + try: + raise AssertionError() + except: + pass + + +@mark_handled +def raise_handled_exception2(): + try: + raise AssertionError() + except AssertionError: + pass + + +@mark_handled +def raise_handled_exception3(): + try: + try: + raise AssertionError() + except RuntimeError: + pass + except AssertionError: + pass + + +@mark_handled +def raise_handled_exception3a(): + try: + try: + raise AssertionError() + except AssertionError: + pass + except RuntimeError: + pass + + +@mark_handled +def raise_handled_exception4(): + try: + try: + raise AssertionError() + except RuntimeError: + pass + except ( + RuntimeError, + AssertionError): + pass + + +@mark_handled +def raise_handled(): + try: + try: + raise AssertionError() + except RuntimeError: + pass + except ( + RuntimeError, + AssertionError): + pass + + +@mark_handled +def raise_handled2(): + try: + raise AssertionError() + except ( + RuntimeError, + AssertionError): + pass + + try: + raise RuntimeError() + except ( + RuntimeError, + AssertionError): + pass + + +@mark_handled +def raise_handled9(): + for i in range(2): + try: + raise AssertionError() + except AssertionError: + if i == 1: + try: + raise + except: + pass + + +@mark_handled +def raise_handled10(): + for i in range(2): + try: + raise AssertionError() + except AssertionError: + if i == 1: + try: + raise + except: + pass + + _foo = 10 + +#----------------------------------------------------------------------------------------- Unhandled + + +@mark_unhandled +def raise_unhandled_exception(): + raise AssertionError() + + +@mark_unhandled +def raise_unhandled_exception_not_in_except_clause(): + try: + raise AssertionError() + except RuntimeError: + pass + + +@mark_unhandled +def raise_unhandled(): + try: + try: + raise AssertionError() + except RuntimeError: + pass + except ( + RuntimeError, + AssertionError): + raise + + +@mark_unhandled +def raise_unhandled2(): + try: + raise AssertionError() + except AssertionError: + pass + + raise AssertionError() + + +@mark_unhandled +def raise_unhandled3(): + try: + raise AssertionError() + except AssertionError: + raise AssertionError() + + +@mark_unhandled +def raise_unhandled4(): + try: + raise AssertionError() + finally: + _a = 10 + + +@mark_unhandled +def raise_unhandled5(): + try: + raise AssertionError() + finally: + raise RuntimeError() + + +@mark_unhandled +def raise_unhandled6(): + try: + raise AssertionError() + finally: + raise RuntimeError( + 'in another' + 'line' + ) + + +@mark_unhandled +def raise_unhandled7(): + try: + raise AssertionError() + except AssertionError: + try: + raise AssertionError() + except RuntimeError: + pass + + +@mark_unhandled +def raise_unhandled8(): + for i in range(2): + + def get_exc_to_treat(): + if i == 0: + return AssertionError + return RuntimeError + + try: + raise AssertionError() + except get_exc_to_treat(): + pass + + +@mark_unhandled +def raise_unhandled9(): + for i in range(2): + + def get_exc_to_treat(): + if i == 0: + return AssertionError + return RuntimeError + + try: + raise AssertionError() + except get_exc_to_treat(): + try: + raise + except: + pass + + +@mark_unhandled +def raise_unhandled10(): + for i in range(2): + try: + raise AssertionError() + except AssertionError: + if i == 1: + try: + raise + except RuntimeError: + pass + + +@mark_unhandled +def raise_unhandled11(): + try: + raise_unhandled10() + finally: + if True: + pass + + +@mark_unhandled +def raise_unhandled12(): + try: + raise AssertionError() + except: + pass + try: + raise AssertionError() + finally: + if True: + pass + + +@mark_unhandled +def reraise_handled_exception(): + try: + raise AssertionError() # Should be considered unhandled (because it's reraised). + except: + raise + + +def _collect_events(func): + collected = [] + + def events_collector(frame, event, arg): + if frame.f_code.co_name == func.__name__: + collected.append((event, frame.f_lineno, arg)) + return events_collector + + import sys + sys.settrace(events_collector) + try: + func() + except: + import traceback;traceback.print_exc() + finally: + sys.settrace(None) + return collected + + +def _replay_events(collected, trace_top_level_unhandled): + for event, lineno, arg in collected: + if event == 'call': + # Notify only unhandled + new_trace_func = trace_top_level_unhandled.call_trace_dispatch(lineno) + # Check that it's dealing with the top-level event. + if hasattr(new_trace_func, 'get_method_object'): + new_trace_func = new_trace_func.get_method_object() + assert new_trace_func.__name__ == 'trace_dispatch_and_unhandled_exceptions' + elif event == 'exception': + trace_top_level_unhandled.exception_trace_dispatch(lineno, arg) + + elif event == 'return': + trace_top_level_unhandled.return_trace_dispatch(lineno) + + elif event == 'line': + pass + + else: + raise AssertionError('Unexpected: %s' % (event,)) + + +def _collect_target_functions(): +# return [raise_unhandled10] + ret = [] + for _key, method in sorted(dict(globals()).items()): + if hasattr(method, '__handled__'): + ret.append(method) + + assert len(ret) == _expected_functions_to_test + return ret + + +@pytest.mark.skipif(not IS_CPYTHON, reason='try..except info only available on CPython') +@pytest.mark.parametrize("func", _collect_target_functions()) +def test_tracing_on_top_level_unhandled(trace_top_level_unhandled, func): + trace_top_level_unhandled.set_target_func(func) + + collected_events = _collect_events(func) + _replay_events(collected_events, trace_top_level_unhandled) + + if func.__handled__: + trace_top_level_unhandled.assert_not_paused() # handled exception + else: + trace_top_level_unhandled.assert_paused() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_utilities.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_utilities.py new file mode 100644 index 0000000..559eb9c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/test_utilities.py @@ -0,0 +1,281 @@ +import threading + +from _pydevd_bundle.pydevd_comm import pydevd_find_thread_by_id +from _pydevd_bundle.pydevd_utils import convert_dap_log_message_to_expression +from tests_python.debug_constants import IS_PY26, IS_PY3K +import sys +from _pydevd_bundle.pydevd_constants import IS_CPYTHON +import pytest + + +def test_is_main_thread(): + from _pydevd_bundle.pydevd_utils import is_current_thread_main_thread + if not is_current_thread_main_thread(): + error_msg = 'Current thread does not seem to be a main thread. Details:\n' + current_thread = threading.current_thread() + error_msg += 'Current thread: %s\n' % (current_thread,) + + if hasattr(threading, 'main_thread'): + error_msg += 'Main thread found: %s\n' % (threading.main_thread(),) + else: + error_msg += 'Current main thread not instance of: %s (%s)' % ( + threading._MainThread, current_thread.__class__.__mro__,) + + raise AssertionError(error_msg) + + class NonMainThread(threading.Thread): + + def run(self): + self.is_main_thread = is_current_thread_main_thread() + + non_main_thread = NonMainThread() + non_main_thread.start() + non_main_thread.join() + assert not non_main_thread.is_main_thread + + +def test_find_thread(): + from _pydevd_bundle.pydevd_constants import get_current_thread_id + assert pydevd_find_thread_by_id('123') is None + + assert pydevd_find_thread_by_id( + get_current_thread_id(threading.current_thread())) is threading.current_thread() + + +def check_dap_log_message(log_message, expected, evaluated, eval_locals=None): + ret = convert_dap_log_message_to_expression(log_message) + assert ret == expected + assert (eval(ret, eval_locals)) == evaluated + return ret + + +def test_convert_dap_log_message_to_expression(): + assert check_dap_log_message( + 'a', + "'a'", + 'a', + ) + assert check_dap_log_message( + 'a {a}', + "'a %s' % (a,)", + 'a value', + {'a': 'value'} + ) + assert check_dap_log_message( + 'a {1}', + "'a %s' % (1,)", + 'a 1' + ) + assert check_dap_log_message( + 'a { }', + "'a '", + 'a ' + ) + assert check_dap_log_message( + 'a {1} {2}', + "'a %s %s' % (1, 2,)", + 'a 1 2', + ) + assert check_dap_log_message( + 'a {{22:22}} {2}', + "'a %s %s' % ({22:22}, 2,)", + 'a {22: 22} 2' + ) + assert check_dap_log_message( + 'a {(22,33)}} {2}', + "'a %s} %s' % ((22,33), 2,)", + 'a (22, 33)} 2' + ) + + if not IS_PY26: + # Note: set literal not valid for Python 2.6. + assert check_dap_log_message( + 'a {{1: {1}}}', + "'a %s' % ({1: {1}},)", + 'a {1: {1}}' if IS_PY3K else 'a {1: set([1])}', + ) + + # Error condition. + assert check_dap_log_message( + 'a {{22:22} {2}', + "'Unbalanced braces in: a {{22:22} {2}'", + 'Unbalanced braces in: a {{22:22} {2}' + ) + + +def test_pydevd_log(): + from _pydev_bundle import pydev_log + try: + import StringIO as io + except: + import io + from _pydev_bundle.pydev_log import log_context + + stream = io.StringIO() + with log_context(0, stream=stream): + pydev_log.critical('always') + pydev_log.info('never') + + assert stream.getvalue() == 'always\n' + + stream = io.StringIO() + with log_context(1, stream=stream): + pydev_log.critical('always') + pydev_log.info('this too') + + assert stream.getvalue() == 'always\nthis too\n' + + stream = io.StringIO() + with log_context(0, stream=stream): + pydev_log.critical('always %s', 1) + + assert stream.getvalue() == 'always 1\n' + + stream = io.StringIO() + with log_context(0, stream=stream): + pydev_log.critical('always %s %s', 1, 2) + + assert stream.getvalue() == 'always 1 2\n' + + stream = io.StringIO() + with log_context(0, stream=stream): + pydev_log.critical('always %s %s', 1) + + # Even if there's an error in the formatting, don't fail, just print the message and args. + assert stream.getvalue() == 'always %s %s - (1,)\n' + + stream = io.StringIO() + with log_context(0, stream=stream): + try: + raise RuntimeError() + except: + pydev_log.exception('foo') + + assert 'foo\n' in stream.getvalue() + assert 'raise RuntimeError()' in stream.getvalue() + + stream = io.StringIO() + with log_context(0, stream=stream): + pydev_log.error_once('always %s %s', 1) + + # Even if there's an error in the formatting, don't fail, just print the message and args. + assert stream.getvalue() == 'always %s %s - (1,)\n' + + +def _check_tracing_other_threads(): + import pydevd_tracing + import time + from tests_python.debugger_unittest import wait_for_condition + try: + import _thread + except ImportError: + import thread as _thread + + def method(): + while True: + trace_func = sys.gettrace() + if trace_func: + threading.current_thread().trace_func = trace_func + break + time.sleep(.01) + + def dummy_thread_method(): + threads.append(threading.current_thread()) + method() + + threads = [] + threads.append(threading.Thread(target=method)) + threads[-1].start() + _thread.start_new_thread(dummy_thread_method, ()) + + wait_for_condition(lambda: len(threads) == 2, msg=lambda:'Found threads: %s' % (threads,)) + + def tracing_func(frame, event, args): + return tracing_func + + assert pydevd_tracing.set_trace_to_threads(tracing_func) == 0 + + def check_threads_tracing_func(): + for t in threads: + if getattr(t, 'trace_func', None) != tracing_func: + return False + return True + + wait_for_condition(check_threads_tracing_func) + + assert tracing_func == sys.gettrace() + + +def _build_launch_env(): + import os + import pydevd + + environ = os.environ.copy() + cwd = os.path.abspath(os.path.dirname(__file__)) + assert os.path.isdir(cwd) + + resources_dir = os.path.join(os.path.dirname(pydevd.__file__), 'tests_python', 'resources') + assert os.path.isdir(resources_dir) + + attach_to_process_dir = os.path.join(os.path.dirname(pydevd.__file__), 'pydevd_attach_to_process') + assert os.path.isdir(attach_to_process_dir) + + pydevd_dir = os.path.dirname(pydevd.__file__) + assert os.path.isdir(pydevd_dir) + + environ['PYTHONPATH'] = ( + cwd + os.pathsep + + resources_dir + os.pathsep + + attach_to_process_dir + os.pathsep + + pydevd_dir + os.pathsep + + environ.get('PYTHONPATH', '') + ) + return cwd, environ + + +def _check_in_separate_process(method_name, module_name='test_utilities'): + import subprocess + cwd, environ = _build_launch_env() + + subprocess.check_call( + [sys.executable, '-c', 'import %(module_name)s;%(module_name)s.%(method_name)s()' % dict( + method_name=method_name, module_name=module_name)], + env=environ, + cwd=cwd + ) + + +@pytest.mark.skipif(not IS_CPYTHON, reason='Functionality to trace other threads requires CPython.') +def test_tracing_other_threads(): + # Note: run this test in a separate process so that it doesn't mess with any current tracing + # in our current process. + _check_in_separate_process('_check_tracing_other_threads') + + +@pytest.mark.skipif(not IS_CPYTHON, reason='Functionality to trace other threads requires CPython.') +def test_find_main_thread_id(): + # Note: run the checks below in a separate process because they rely heavily on what's available + # in the env (such as threads or having threading imported). + _check_in_separate_process('check_main_thread_id_simple', '_pydevd_test_find_main_thread_id') + _check_in_separate_process('check_main_thread_id_multiple_threads', '_pydevd_test_find_main_thread_id') + _check_in_separate_process('check_win_threads', '_pydevd_test_find_main_thread_id') + _check_in_separate_process('check_fix_main_thread_id_multiple_threads', '_pydevd_test_find_main_thread_id') + + import subprocess + import os + import pydevd + cwd, environ = _build_launch_env() + + subprocess.check_call( + [sys.executable, '-m', '_pydevd_test_find_main_thread_id'], + env=environ, + cwd=cwd + ) + + resources_dir = os.path.join(os.path.dirname(pydevd.__file__), 'tests_python', 'resources') + + subprocess.check_call( + [sys.executable, os.path.join(resources_dir, '_pydevd_test_find_main_thread_id.py') ], + env=environ, + cwd=cwd + ) diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_python/tests_single_notification.py b/adapter/python/ptvsd/_vendored/pydevd/tests_python/tests_single_notification.py new file mode 100644 index 0000000..c1946fb --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_python/tests_single_notification.py @@ -0,0 +1,278 @@ +from functools import partial +import itertools +from pydevd import AbstractSingleNotificationBehavior +import time + +import pytest + +from _pydevd_bundle.pydevd_comm import run_as_pydevd_daemon_thread +from tests_python.debugger_unittest import CMD_THREAD_SUSPEND, CMD_STEP_OVER, CMD_SET_BREAK +from _pydev_bundle.pydev_override import overrides + +STATE_RUN = 1 +STATE_SUSPEND = 2 + + +class _ThreadInfo(object): + + next_thread_id = partial(next, itertools.count()) + + def __init__(self): + self.state = STATE_RUN + self.thread_id = self.next_thread_id() + + +class _CustomSingleNotificationBehavior(AbstractSingleNotificationBehavior): + + NOTIFY_OF_PAUSE_TIMEOUT = .01 + + __slots__ = AbstractSingleNotificationBehavior.__slots__ + ['notification_queue'] + + def __init__(self): + try: + from queue import Queue + except ImportError: + from Queue import Queue + super(_CustomSingleNotificationBehavior, self).__init__() + self.notification_queue = Queue() + + @overrides(AbstractSingleNotificationBehavior.send_resume_notification) + def send_resume_notification(self, *args, **kwargs): + # print('put resume', threading.current_thread()) + self.notification_queue.put('resume') + + @overrides(AbstractSingleNotificationBehavior.send_suspend_notification) + def send_suspend_notification(self, *args, **kwargs): + # print('put suspend', threading.current_thread()) + self.notification_queue.put('suspend') + + def do_wait_suspend(self, thread_info, stop_reason): + with self.notify_thread_suspended(thread_info.thread_id, stop_reason=stop_reason): + while thread_info.state == STATE_SUSPEND: + time.sleep(.1) + + +@pytest.fixture( + name='single_notification_behavior', +# params=range(50) # uncomment to run the tests many times. +) +def _single_notification_behavior(): + single_notification_behavior = _CustomSingleNotificationBehavior() + return single_notification_behavior + + +@pytest.fixture(name='notification_queue') +def _notification_queue(single_notification_behavior): + return single_notification_behavior.notification_queue + + +def wait_for_notification(notification_queue, msg): + __tracebackhide__ = True + try: + from Queue import Empty + except ImportError: + from queue import Empty + try: + found = notification_queue.get(timeout=2) + assert found == msg + except Empty: + raise AssertionError('Timed out while waiting for %s notification.' % (msg,)) + + +def join_thread(t): + __tracebackhide__ = True + t.join(2) + assert not t.is_alive(), 'Thread still alive after timeout.s' + + +def test_single_notification_1(single_notification_behavior, notification_queue): + ''' + 1. Resume before pausing 2nd thread + + - user pauses all (2) threads + - break first -> send notification + - user presses continue all before second is paused + - 2nd should not pause nor send notification + - resume all notification should be sent + ''' + thread_info1 = _ThreadInfo() + thread_info2 = _ThreadInfo() + + # pause all = set_suspend both + single_notification_behavior.increment_suspend_time() + single_notification_behavior.on_pause() + thread_info1.state = STATE_SUSPEND + thread_info2.state = STATE_SUSPEND + + t = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) + thread_info1.state = STATE_RUN + # Set 2 to run before it starts (should not send additional message). + thread_info2.state = STATE_RUN + t.join() + + assert notification_queue.qsize() == 2 + assert notification_queue.get() == 'suspend' + assert notification_queue.get() == 'resume' + assert notification_queue.qsize() == 0 + + # Run thread 2 only now (no additional notification). + t = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) + t.join() + + assert notification_queue.qsize() == 0 + + +def test_single_notification_2(single_notification_behavior, notification_queue): + ''' + 2. Pausing all then stepping + + - user pauses all (2) threads + - break first -> send notification + - break second (no notification) + - user steps in second + - suspend in second -> send resume/pause notification on step + ''' + thread_info1 = _ThreadInfo() + thread_info2 = _ThreadInfo() + + # pause all = set_suspend both + single_notification_behavior.increment_suspend_time() + single_notification_behavior.on_pause() + thread_info1.state = STATE_SUSPEND + thread_info2.state = STATE_SUSPEND + + # Leave both in break mode + t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) + wait_for_notification(notification_queue, 'suspend') + + t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info2, CMD_THREAD_SUSPEND) + + # Step would actually be set state to STEP, which would result in resuming + # and then stopping again as if it was a SUSPEND (which calls a set_supend again with + # the step mode). + thread_info2.state = STATE_RUN + join_thread(t2) + wait_for_notification(notification_queue, 'resume') + + single_notification_behavior.increment_suspend_time() + thread_info2.state = STATE_SUSPEND + t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info2, CMD_STEP_OVER) + wait_for_notification(notification_queue, 'suspend') + + thread_info1.state = STATE_RUN + thread_info2.state = STATE_RUN + # First does a resume notification, the other remains quiet. + wait_for_notification(notification_queue, 'resume') + + join_thread(t2) + join_thread(t1) + assert notification_queue.qsize() == 0 + + +def test_single_notification_3(single_notification_behavior, notification_queue): + ''' + 3. Deadlocked thread + + - user adds breakpoint in thread.join() -- just before threads becomes deadlocked + - breakpoint hits -> send notification + - pauses 2nd thread (no notification) + - user steps over thead.join() -> never completes + - user presses pause + - second thread is already stopped + - send notification regarding 2nd thread (still stopped). + - leave both threads running: no suspend should be shown as there are no stopped threads + - when thread is paused, show suspend notification + ''' + + # i.e.: stopping at breakpoint + thread_info1 = _ThreadInfo() + single_notification_behavior.increment_suspend_time() + thread_info1.state = STATE_SUSPEND + t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_SET_BREAK) + + # i.e.: stop because of breakpoint + thread_info2 = _ThreadInfo() + thread_info2.state = STATE_SUSPEND + t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info2, CMD_SET_BREAK) + + wait_for_notification(notification_queue, 'suspend') + + # i.e.: step over (thread 2 is still suspended and this one never completes) + thread_info1.state = STATE_RUN + wait_for_notification(notification_queue, 'resume') + + join_thread(t1) + + # On pause we should notify that the thread 2 is suspended (after timeout if no other thread suspends first). + single_notification_behavior.increment_suspend_time() + single_notification_behavior.on_pause() + thread_info1.state = STATE_SUSPEND + thread_info2.state = STATE_SUSPEND + wait_for_notification(notification_queue, 'suspend') + + thread_info2.state = STATE_RUN + wait_for_notification(notification_queue, 'resume') + + join_thread(t2) + assert notification_queue.qsize() == 0 + assert not single_notification_behavior._suspended_thread_ids + + # Now, no threads are running and pause is pressed + # (maybe we could do a thread dump in this case as this + # means nothing is stopped after pause is requested and + # the timeout elapses). + single_notification_behavior.increment_suspend_time() + single_notification_behavior.on_pause() + thread_info1.state = STATE_SUSPEND + thread_info2.state = STATE_SUSPEND + + time.sleep(single_notification_behavior.NOTIFY_OF_PAUSE_TIMEOUT * 2) + assert notification_queue.qsize() == 0 + + t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) + wait_for_notification(notification_queue, 'suspend') + thread_info1.state = STATE_RUN + wait_for_notification(notification_queue, 'resume') + join_thread(t1) + assert notification_queue.qsize() == 0 + + +def test_single_notification_4(single_notification_behavior, notification_queue): + ''' + 4. Delayed stop + + - user presses pause + - stops first (2nd keeps running) + - user steps on first + - 2nd hits before first ends step (should not send any notification) + - when step finishes send notification + ''' + thread_info1 = _ThreadInfo() + thread_info2 = _ThreadInfo() + + single_notification_behavior.increment_suspend_time() + single_notification_behavior.on_pause() + thread_info1.state = STATE_SUSPEND + thread_info2.state = STATE_SUSPEND + + t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) + wait_for_notification(notification_queue, 'suspend') + thread_info1.state = STATE_RUN + wait_for_notification(notification_queue, 'resume') + join_thread(t1) + + t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) + time.sleep(.1) + assert notification_queue.qsize() == 0 + + single_notification_behavior.increment_suspend_time() + thread_info1.state = STATE_SUSPEND + t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_STEP_OVER) + wait_for_notification(notification_queue, 'suspend') + thread_info2.state = STATE_RUN + thread_info1.state = STATE_RUN + join_thread(t1) + join_thread(t2) + wait_for_notification(notification_queue, 'resume') + assert notification_queue.qsize() == 0 + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/not_in_default_pythonpath.txt b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/not_in_default_pythonpath.txt new file mode 100644 index 0000000..29cdc5b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/not_in_default_pythonpath.txt @@ -0,0 +1 @@ +(no __init__.py file) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/.cvsignore b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/.cvsignore new file mode 100644 index 0000000..d1c8995 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/.cvsignore @@ -0,0 +1,2 @@ +*.class +*.pyc diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/.cvsignore b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/.cvsignore new file mode 100644 index 0000000..d1c8995 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/.cvsignore @@ -0,0 +1,2 @@ +*.class +*.pyc diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/__init__.py @@ -0,0 +1 @@ + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/.cvsignore b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/.cvsignore new file mode 100644 index 0000000..d1c8995 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/.cvsignore @@ -0,0 +1,2 @@ +*.class +*.pyc diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/__init__.py @@ -0,0 +1 @@ + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/deep_nest_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/deep_nest_test.py new file mode 100644 index 0000000..7b1972b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/deep_nest_test.py @@ -0,0 +1,22 @@ +import unittest + +class SampleTest(unittest.TestCase): + + def setUp(self): + return + + def tearDown(self): + return + + def test_non_unique_name(self): + pass + + def test_asdf2(self): + pass + + def test_i_am_a_unique_test_name(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/non_test_file.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/non_test_file.py new file mode 100644 index 0000000..470c650 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested2/non_test_file.py @@ -0,0 +1,3 @@ + +""" i am a python file with no tests """ +pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/.cvsignore b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/.cvsignore new file mode 100644 index 0000000..d1c8995 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/.cvsignore @@ -0,0 +1,2 @@ +*.class +*.pyc diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/__init__.py @@ -0,0 +1 @@ + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/junk.txt b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/junk.txt new file mode 100644 index 0000000..14dd4dd --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/junk.txt @@ -0,0 +1 @@ +im a junk file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/non_test_file.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/non_test_file.py new file mode 100644 index 0000000..470c650 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/nested3/non_test_file.py @@ -0,0 +1,3 @@ + +""" i am a python file with no tests """ +pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/non_test_file.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/non_test_file.py new file mode 100644 index 0000000..470c650 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/non_test_file.py @@ -0,0 +1,3 @@ + +""" i am a python file with no tests """ +pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/simple4_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/simple4_test.py new file mode 100644 index 0000000..ba5d45f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/nested_dir/simple4_test.py @@ -0,0 +1,16 @@ +import unittest + +class NestedSampleTest(unittest.TestCase): + + def setUp(self): + return + + def tearDown(self): + return + + def test_non_unique_name(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/non_test_file.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/non_test_file.py new file mode 100644 index 0000000..470c650 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/non_test_file.py @@ -0,0 +1,3 @@ + +""" i am a python file with no tests """ +pass diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/not_in_default_pythonpath.txt b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/not_in_default_pythonpath.txt new file mode 100644 index 0000000..29cdc5b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/not_in_default_pythonpath.txt @@ -0,0 +1 @@ +(no __init__.py file) \ No newline at end of file diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple2_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple2_test.py new file mode 100644 index 0000000..d46468e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple2_test.py @@ -0,0 +1,16 @@ +import unittest + +class YetAnotherSampleTest(unittest.TestCase): + + def setUp(self): + return + + def tearDown(self): + return + + def test_abc(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple3_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple3_test.py new file mode 100644 index 0000000..da1ccbf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple3_test.py @@ -0,0 +1,16 @@ +import unittest + +class StillYetAnotherSampleTest(unittest.TestCase): + + def setUp(self): + return + + def tearDown(self): + return + + def test_non_unique_name(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simpleClass_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simpleClass_test.py new file mode 100644 index 0000000..3a9c900 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simpleClass_test.py @@ -0,0 +1,14 @@ +import unittest + +class SetUpClassTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + raise ValueError("This is an INTENTIONAL value error in setUpClass.") + + def test_blank(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simpleModule_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simpleModule_test.py new file mode 100644 index 0000000..fdde67e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simpleModule_test.py @@ -0,0 +1,16 @@ +import unittest + +def setUpModule(): + raise ValueError("This is an INTENTIONAL value error in setUpModule.") + +class SetUpModuleTest(unittest.TestCase): + + def setUp(cls): + pass + + def test_blank(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple_test.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple_test.py new file mode 100644 index 0000000..619df7c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/samples/simple_test.py @@ -0,0 +1,45 @@ +import unittest + +class SampleTest(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_xxxxxx1(self): + self.fail('Fail test 2') + def test_xxxxxx2(self): + pass + def test_xxxxxx3(self): + pass + def test_xxxxxx4(self): + pass + def test_non_unique_name(self): + print('non unique name ran') + + +class AnotherSampleTest(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def test_1(self): + pass + def test_2(self): + """ im a doc string""" + pass + def todo_not_tested(self): + ''' + Not there by default! + ''' + + +if __name__ == '__main__': +# suite = unittest.makeSuite(SampleTest, 'test') +# runner = unittest.TextTestRunner( verbosity=3 ) +# runner.run(suite) + unittest.main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_pydevd_property.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_pydevd_property.py new file mode 100644 index 0000000..aa1d010 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_pydevd_property.py @@ -0,0 +1,124 @@ +''' +Created on Aug 22, 2011 + +@author: hussain.bohra +@author: fabioz +''' + +import os +import sys +import unittest + +#======================================================================================================================= +# Test +#======================================================================================================================= +class Test(unittest.TestCase): + """Test cases to validate custom property implementation in pydevd + """ + + def setUp(self, nused=None): + self.tempdir = os.path.join(os.path.dirname(os.path.dirname(__file__))) + sys.path.insert(0, self.tempdir) + from _pydevd_bundle import pydevd_traceproperty + self.old = pydevd_traceproperty.replace_builtin_property() + + + def tearDown(self, unused=None): + from _pydevd_bundle import pydevd_traceproperty + pydevd_traceproperty.replace_builtin_property(self.old) + sys.path.remove(self.tempdir) + + + def test_property(self): + """Test case to validate custom property + """ + + from _pydevd_bundle import pydevd_traceproperty + class TestProperty(object): + + def __init__(self): + self._get = 0 + self._set = 0 + self._del = 0 + + def get_name(self): + self._get += 1 + return self.__name + + def set_name(self, value): + self._set += 1 + self.__name = value + + def del_name(self): + self._del += 1 + del self.__name + name = property(get_name, set_name, del_name, "name's docstring") + self.assertEqual(name.__class__, pydevd_traceproperty.DebugProperty) + + testObj = TestProperty() + self._check(testObj) + + + def test_property2(self): + """Test case to validate custom property + """ + + class TestProperty(object): + + def __init__(self): + self._get = 0 + self._set = 0 + self._del = 0 + + def name(self): + self._get += 1 + return self.__name + name = property(name) + + def set_name(self, value): + self._set += 1 + self.__name = value + name.setter(set_name) + + def del_name(self): + self._del += 1 + del self.__name + name.deleter(del_name) + + testObj = TestProperty() + self._check(testObj) + + + def test_property3(self): + """Test case to validate custom property + """ + + class TestProperty(object): + + def __init__(self): + self._name = 'foo' + + def name(self): + return self._name + name = property(name) + + testObj = TestProperty() + self.assertRaises(AttributeError, setattr, testObj, 'name', 'bar') + self.assertRaises(AttributeError, delattr, testObj, 'name') + + + def _check(self, testObj): + testObj.name = "Custom" + self.assertEqual(1, testObj._set) + + self.assertEqual(testObj.name, "Custom") + self.assertEqual(1, testObj._get) + + self.assertTrue(hasattr(testObj, 'name')) + del testObj.name + self.assertEqual(1, testObj._del) + + self.assertTrue(not hasattr(testObj, 'name')) + testObj.name = "Custom2" + self.assertEqual(testObj.name, "Custom2") + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_pydevdio.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_pydevdio.py new file mode 100644 index 0000000..3d0b007 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_pydevdio.py @@ -0,0 +1,36 @@ +import sys +import os + + +import unittest + +class Test(unittest.TestCase): + + def test_it(self): + #make it as if we were executing from the directory above this one (so that we can use jycompletionserver + #without the need for it being in the pythonpath) + #(twice the dirname to get the previous level from this file.) + import test_pydevdio #@UnresolvedImport - importing itself + ADD_TO_PYTHONPATH = os.path.join(os.path.dirname(os.path.dirname(test_pydevdio.__file__))) + sys.path.insert(0, ADD_TO_PYTHONPATH) + + try: + from _pydevd_bundle import pydevd_io + original = sys.stdout + + try: + sys.stdout = pydevd_io.IOBuf() + print('foo') + print('bar') + + self.assertEqual('foo\nbar\n', sys.stdout.getvalue()) #@UndefinedVariable + + print('ww') + print('xx') + self.assertEqual('ww\nxx\n', sys.stdout.getvalue()) #@UndefinedVariable + finally: + sys.stdout = original + finally: + #remove it to leave it ok for other tests + sys.path.remove(ADD_TO_PYTHONPATH) + diff --git a/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_runfiles.py b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_runfiles.py new file mode 100644 index 0000000..b2c0e93 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/tests_runfiles/test_runfiles.py @@ -0,0 +1,449 @@ +import os.path +import sys +from tests_python.test_debugger import IS_PY26 + +IS_JYTHON = sys.platform.find('java') != -1 + +try: + this_file_name = __file__ +except NameError: + # stupid jython. plain old __file__ isnt working for some reason + import test_runfiles #@UnresolvedImport - importing the module itself + this_file_name = test_runfiles.__file__ + + +desired_runfiles_path = os.path.normpath(os.path.dirname(this_file_name) + "/..") +sys.path.insert(0, desired_runfiles_path) + +from _pydev_runfiles import pydev_runfiles_unittest +from _pydev_runfiles import pydev_runfiles_xml_rpc +from _pydevd_bundle import pydevd_io + +#remove existing pydev_runfiles from modules (if any), so that we can be sure we have the correct version +if 'pydev_runfiles' in sys.modules: + del sys.modules['pydev_runfiles'] +if '_pydev_runfiles.pydev_runfiles' in sys.modules: + del sys.modules['_pydev_runfiles.pydev_runfiles'] + + +from _pydev_runfiles import pydev_runfiles +import unittest +import tempfile +import re + +try: + set +except: + from sets import Set as set + +#this is an early test because it requires the sys.path changed +orig_syspath = sys.path +a_file = pydev_runfiles.__file__ +pydev_runfiles.PydevTestRunner(pydev_runfiles.Configuration(files_or_dirs=[a_file])) +file_dir = os.path.dirname(os.path.dirname(a_file)) +assert file_dir in sys.path +sys.path = orig_syspath[:] + +#remove it so that we leave it ok for other tests +sys.path.remove(desired_runfiles_path) + +class RunfilesTest(unittest.TestCase): + + def _setup_scenario( + self, + path, + include_tests=None, + tests=None, + files_to_tests=None, + exclude_files=None, + exclude_tests=None, + include_files=None, + ): + self.MyTestRunner = pydev_runfiles.PydevTestRunner( + pydev_runfiles.Configuration( + files_or_dirs=path, + include_tests=include_tests, + verbosity=1, + tests=tests, + files_to_tests=files_to_tests, + exclude_files=exclude_files, + exclude_tests=exclude_tests, + include_files=include_files, + ) + ) + self.files = self.MyTestRunner.find_import_files() + self.modules = self.MyTestRunner.find_modules_from_files(self.files) + self.all_tests = self.MyTestRunner.find_tests_from_modules(self.modules) + self.filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + + def setUp(self): + self.file_dir = [os.path.abspath(os.path.join(desired_runfiles_path, 'tests_runfiles/samples'))] + self._setup_scenario(self.file_dir, None) + + + def test_suite_used(self): + for suite in self.all_tests + self.filtered_tests: + self.assertTrue(isinstance(suite, pydev_runfiles_unittest.PydevTestSuite)) + + def test_parse_cmdline(self): + sys.argv = "pydev_runfiles.py ./".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual([sys.argv[1]], configuration.files_or_dirs) + self.assertEqual(2, configuration.verbosity) # default value + self.assertEqual(None, configuration.include_tests) # default value + + sys.argv = "pydev_runfiles.py ../images c:/temp".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual(sys.argv[1:3], configuration.files_or_dirs) + self.assertEqual(2, configuration.verbosity) + + sys.argv = "pydev_runfiles.py --verbosity 3 ../junk c:/asdf ".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual(sys.argv[3:], configuration.files_or_dirs) + self.assertEqual(int(sys.argv[2]), configuration.verbosity) + + sys.argv = "pydev_runfiles.py --include_tests test_def ./".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual([sys.argv[-1]], configuration.files_or_dirs) + self.assertEqual([sys.argv[2]], configuration.include_tests) + + sys.argv = "pydev_runfiles.py --include_tests Abc.test_def,Mod.test_abc c:/junk/".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual([sys.argv[-1]], configuration.files_or_dirs) + self.assertEqual(sys.argv[2].split(','), configuration.include_tests) + + sys.argv = ('C:\\eclipse-SDK-3.2-win32\\eclipse\\plugins\\org.python.pydev.debug_1.2.2\\pysrc\\pydev_runfiles.py ' + + '--verbosity 1 ' + + 'C:\\workspace_eclipse\\fronttpa\\tests\\gui_tests\\calendar_popup_control_test.py ').split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual([sys.argv[-1]], configuration.files_or_dirs) + self.assertEqual(1, configuration.verbosity) + + sys.argv = "pydev_runfiles.py --verbosity 1 --include_tests Mod.test_abc c:/junk/ ./".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual(sys.argv[5:], configuration.files_or_dirs) + self.assertEqual(int(sys.argv[2]), configuration.verbosity) + self.assertEqual([sys.argv[4]], configuration.include_tests) + + sys.argv = "pydev_runfiles.py --exclude_files=*.txt,a*.py".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual(['*.txt', 'a*.py'], configuration.exclude_files) + + sys.argv = "pydev_runfiles.py --exclude_tests=*__todo,test*bar".split() + configuration = pydev_runfiles.parse_cmdline() + self.assertEqual(['*__todo', 'test*bar'], configuration.exclude_tests) + + + def test___adjust_python_path_works_for_directories(self): + orig_syspath = sys.path + tempdir = tempfile.gettempdir() + pydev_runfiles.PydevTestRunner(pydev_runfiles.Configuration(files_or_dirs=[tempdir])) + self.assertEqual(1, tempdir in sys.path) + sys.path = orig_syspath[:] + + + def test___is_valid_py_file(self): + isvalid = self.MyTestRunner._PydevTestRunner__is_valid_py_file + self.assertEqual(1, isvalid("test.py")) + self.assertEqual(0, isvalid("asdf.pyc")) + self.assertEqual(0, isvalid("__init__.py")) + self.assertEqual(0, isvalid("__init__.pyc")) + self.assertEqual(1, isvalid("asdf asdf.pyw")) + + def test___unixify(self): + unixify = self.MyTestRunner._PydevTestRunner__unixify + self.assertEqual("c:/temp/junk/asdf.py", unixify("c:SEPtempSEPjunkSEPasdf.py".replace('SEP', os.sep))) + + def test___importify(self): + importify = self.MyTestRunner._PydevTestRunner__importify + self.assertEqual("temp.junk.asdf", importify("temp/junk/asdf.py")) + self.assertEqual("asdf", importify("asdf.py")) + self.assertEqual("abc.def.hgi", importify("abc/def/hgi")) + + def test_finding_a_file_from_file_system(self): + test_file = "simple_test.py" + self.MyTestRunner.files_or_dirs = [self.file_dir[0] + test_file] + files = self.MyTestRunner.find_import_files() + self.assertEqual(1, len(files)) + self.assertEqual(files[0], self.file_dir[0] + test_file) + + def test_finding_files_in_dir_from_file_system(self): + self.assertEqual(1, len(self.files) > 0) + for import_file in self.files: + self.assertEqual(-1, import_file.find(".pyc")) + self.assertEqual(-1, import_file.find("__init__.py")) + self.assertEqual(-1, import_file.find("\\")) + self.assertEqual(-1, import_file.find(".txt")) + + def test___get_module_from_str(self): + my_importer = self.MyTestRunner._PydevTestRunner__get_module_from_str + my_os_path = my_importer("os.path", True, 'unused') + from os import path + import os.path as path2 + self.assertEqual(path, my_os_path) + self.assertEqual(path2, my_os_path) + self.assertNotEqual(__import__("os.path"), my_os_path) + self.assertNotEqual(__import__("os"), my_os_path) + + def test_finding_modules_from_import_strings(self): + self.assertEqual(1, len(self.modules) > 0) + + def test_finding_tests_when_no_filter(self): + # unittest.py will create a TestCase with 0 tests in it + # since it just imports what is given + self.assertEqual(1, len(self.all_tests) > 0) + files_with_tests = [1 for t in self.all_tests if len(t._tests) > 0] + self.assertNotEqual(len(self.files), len(files_with_tests)) + + def count_suite(self, tests=None): + total = 0 + for t in tests: + total += t.countTestCases() + return total + + def test_runfile_imports(self): + from _pydev_runfiles import pydev_runfiles_coverage + from _pydev_runfiles import pydev_runfiles_parallel_client + from _pydev_runfiles import pydev_runfiles_parallel + import pytest + if IS_PY26: + with pytest.raises(AssertionError) as e: + from _pydev_runfiles import pydev_runfiles_pytest2 + assert 'Please upgrade pytest' in str(e) + else: + from _pydev_runfiles import pydev_runfiles_pytest2 + from _pydev_runfiles import pydev_runfiles_unittest + from _pydev_runfiles import pydev_runfiles_xml_rpc + from _pydev_runfiles import pydev_runfiles + + def test___match(self): + matcher = self.MyTestRunner._PydevTestRunner__match + self.assertEqual(1, matcher(None, "aname")) + self.assertEqual(1, matcher([".*"], "aname")) + self.assertEqual(0, matcher(["^x$"], "aname")) + self.assertEqual(0, matcher(["abc"], "aname")) + self.assertEqual(1, matcher(["abc", "123"], "123")) + + def test_finding_tests_from_modules_with_bad_filter_returns_0_tests(self): + self._setup_scenario(self.file_dir, ["NO_TESTS_ARE_SURE_TO_HAVE_THIS_NAME"]) + self.assertEqual(0, self.count_suite(self.all_tests)) + + def test_finding_test_with_unique_name_returns_1_test(self): + self._setup_scenario(self.file_dir, include_tests=["test_i_am_a_unique_test_name"]) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(1, self.count_suite(filtered_tests)) + + def test_finding_test_with_non_unique_name(self): + self._setup_scenario(self.file_dir, include_tests=["test_non_unique_name"]) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(1, self.count_suite(filtered_tests) > 2) + + def test_finding_tests_with_regex_filters(self): + self._setup_scenario(self.file_dir, include_tests=["test_non*"]) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(1, self.count_suite(filtered_tests) > 2) + + self._setup_scenario(self.file_dir, ["^$"]) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(0, self.count_suite(filtered_tests)) + + self._setup_scenario(self.file_dir, None, exclude_tests=["*"]) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(0, self.count_suite(filtered_tests)) + + def test_matching_tests(self): + self._setup_scenario(self.file_dir, None, ['StillYetAnotherSampleTest']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(1, self.count_suite(filtered_tests)) + + self._setup_scenario(self.file_dir, None, ['SampleTest.test_xxxxxx1']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(1, self.count_suite(filtered_tests)) + + self._setup_scenario(self.file_dir, None, ['SampleTest']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(8, self.count_suite(filtered_tests)) + + self._setup_scenario(self.file_dir, None, ['AnotherSampleTest.todo_not_tested']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(1, self.count_suite(filtered_tests)) + + self._setup_scenario(self.file_dir, None, ['StillYetAnotherSampleTest', 'SampleTest.test_xxxxxx1']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(2, self.count_suite(filtered_tests)) + + self._setup_scenario(self.file_dir, None, exclude_tests=['*']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(self.count_suite(filtered_tests), 0) + + + self._setup_scenario(self.file_dir, None, exclude_tests=['*a*']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(self.count_suite(filtered_tests), 6) + + self.assertEqual( + set(self.MyTestRunner.list_test_names(filtered_tests)), + set(['test_1', 'test_2', 'test_xxxxxx1', 'test_xxxxxx2', 'test_xxxxxx3', 'test_xxxxxx4']) + ) + + self._setup_scenario(self.file_dir, None, exclude_tests=['*a*', '*x*']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + self.assertEqual(self.count_suite(filtered_tests), 2) + + self.assertEqual( + set(self.MyTestRunner.list_test_names(filtered_tests)), + set(['test_1', 'test_2']) + ) + + self._setup_scenario(self.file_dir, None, exclude_files=['simple_test.py']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + names = self.MyTestRunner.list_test_names(filtered_tests) + self.assertTrue('test_xxxxxx1' not in names, 'Found: %s' % (names,)) + + self.assertEqual( + set(['test_abc', 'test_non_unique_name', 'test_non_unique_name', 'test_asdf2', 'test_i_am_a_unique_test_name', 'test_non_unique_name', 'test_blank']), + set(names) + ) + + self._setup_scenario(self.file_dir, None, include_files=['simple3_test.py']) + filtered_tests = self.MyTestRunner.filter_tests(self.all_tests) + names = self.MyTestRunner.list_test_names(filtered_tests) + self.assertTrue('test_xxxxxx1' not in names, 'Found: %s' % (names,)) + + self.assertEqual( + set(['test_non_unique_name']), + set(names) + ) + + def test_xml_rpc_communication(self): + import sys + sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'samples')) + notifications = [] + class Server: + + def __init__(self, notifications): + self.notifications = notifications + + def notifyConnected(self): + #This method is called at the very start (in runfiles.py), and we do not check this here + raise AssertionError('Should not be called from the run tests.') + + + def notifyTestsCollected(self, number_of_tests): + self.notifications.append(('notifyTestsCollected', number_of_tests)) + + + def notifyStartTest(self, file, test): + pass + + def notifyTest(self, cond, captured_output, error_contents, file, test, time): + try: + #I.e.: when marked as Binary in xml-rpc + captured_output = captured_output.data + except: + pass + try: + #I.e.: when marked as Binary in xml-rpc + error_contents = error_contents.data + except: + pass + if error_contents: + error_contents = error_contents.splitlines()[-1].strip() + self.notifications.append(('notifyTest', cond, captured_output.strip(), error_contents, file, test)) + + def notifyTestRunFinished(self, total_time): + self.notifications.append(('notifyTestRunFinished',)) + + server = Server(notifications) + pydev_runfiles_xml_rpc.set_server(server) + simple_test = os.path.join(self.file_dir[0], 'simple_test.py') + simple_test2 = os.path.join(self.file_dir[0], 'simple2_test.py') + simpleClass_test = os.path.join(self.file_dir[0], 'simpleClass_test.py') + simpleModule_test = os.path.join(self.file_dir[0], 'simpleModule_test.py') + + files_to_tests = {} + files_to_tests.setdefault(simple_test , []).append('SampleTest.test_xxxxxx1') + files_to_tests.setdefault(simple_test , []).append('SampleTest.test_xxxxxx2') + files_to_tests.setdefault(simple_test , []).append('SampleTest.test_non_unique_name') + files_to_tests.setdefault(simple_test2, []).append('YetAnotherSampleTest.test_abc') + files_to_tests.setdefault(simpleClass_test, []).append('SetUpClassTest.test_blank') + files_to_tests.setdefault(simpleModule_test, []).append('SetUpModuleTest.test_blank') + + self._setup_scenario(None, files_to_tests=files_to_tests) + self.MyTestRunner.verbosity = 2 + + buf = pydevd_io.start_redirect(keep_original_redirection=False) + try: + self.MyTestRunner.run_tests() + self.assertEqual(8, len(notifications)) + if sys.version_info[:2] <= (2, 6): + # The setUpClass is not supported in Python 2.6 (thus we have no collection error). + expected = [ + ('notifyTest', 'fail', '', 'AssertionError: Fail test 2', simple_test, 'SampleTest.test_xxxxxx1'), + ('notifyTest', 'ok', '', '', simple_test2, 'YetAnotherSampleTest.test_abc'), + ('notifyTest', 'ok', '', '', simpleClass_test, 'SetUpClassTest.test_blank'), + ('notifyTest', 'ok', '', '', simpleModule_test, 'SetUpModuleTest.test_blank'), + ('notifyTest', 'ok', '', '', simple_test, 'SampleTest.test_xxxxxx2'), + ('notifyTest', 'ok', 'non unique name ran', '', simple_test, 'SampleTest.test_non_unique_name'), + ('notifyTestRunFinished',), + ('notifyTestsCollected', 6) + ] + else: + expected = [ + ('notifyTestsCollected', 6), + ('notifyTest', 'ok', 'non unique name ran', '', simple_test, 'SampleTest.test_non_unique_name'), + ('notifyTest', 'fail', '', 'AssertionError: Fail test 2', simple_test, 'SampleTest.test_xxxxxx1'), + ('notifyTest', 'ok', '', '', simple_test, 'SampleTest.test_xxxxxx2'), + ('notifyTest', 'ok', '', '', simple_test2, 'YetAnotherSampleTest.test_abc'), + ] + + if not IS_JYTHON: + if 'samples.simpleClass_test' in str(notifications): + expected.append(('notifyTest', 'error', '', 'ValueError: This is an INTENTIONAL value error in setUpClass.', + simpleClass_test.replace('/', os.path.sep), 'samples.simpleClass_test.SetUpClassTest ')) + expected.append(('notifyTest', 'error', '', 'ValueError: This is an INTENTIONAL value error in setUpModule.', + simpleModule_test.replace('/', os.path.sep), 'samples.simpleModule_test ')) + else: + expected.append(('notifyTest', 'error', '', 'ValueError: This is an INTENTIONAL value error in setUpClass.', + simpleClass_test.replace('/', os.path.sep), 'simpleClass_test.SetUpClassTest ')) + expected.append(('notifyTest', 'error', '', 'ValueError: This is an INTENTIONAL value error in setUpModule.', + simpleModule_test.replace('/', os.path.sep), 'simpleModule_test ')) + else: + expected.append(('notifyTest', 'ok', '', '', simpleClass_test, 'SetUpClassTest.test_blank')) + expected.append(('notifyTest', 'ok', '', '', simpleModule_test, 'SetUpModuleTest.test_blank')) + + expected.append(('notifyTestRunFinished',)) + + expected.sort() + new_notifications = [] + for notification in expected: + try: + if len(notification) == 6: + # Some are binary on Py3. + new_notifications.append(( + notification[0], + notification[1], + notification[2].encode('latin1'), + notification[3].encode('latin1'), + notification[4], + notification[5], + )) + else: + new_notifications.append(notification) + except: + raise + expected = new_notifications + + notifications.sort() + if not IS_JYTHON: + self.assertEqual( + expected, + notifications + ) + finally: + pydevd_io.end_redirect() + b = buf.getvalue() + if sys.version_info[:2] > (2, 6): + self.assertTrue(b.find('Ran 4 tests in ') != -1, 'Found: ' + b) + else: + self.assertTrue(b.find('Ran 6 tests in ') != -1, 'Found: ' + b) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/__init__.py new file mode 100644 index 0000000..3063d1e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/__init__.py @@ -0,0 +1,28 @@ +"""__init__.py. + +Defines the isort module to include the SortImports utility class as well as any defined settings. + +Copyright (C) 2013 Timothy Edmund Crosley + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +""" + +from __future__ import absolute_import, division, print_function, unicode_literals + +from . import settings +from .isort import SortImports + +__version__ = "4.2.15" diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/__main__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/__main__.py new file mode 100644 index 0000000..94b1d05 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/__main__.py @@ -0,0 +1,3 @@ +from isort.main import main + +main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/hooks.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/hooks.py new file mode 100644 index 0000000..15b6d40 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/hooks.py @@ -0,0 +1,82 @@ +"""isort.py. + +Defines a git hook to allow pre-commit warnings and errors about import order. + +usage: + exit_code = git_hook(strict=True) + +Copyright (C) 2015 Helen Sherwood-Taylor + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +""" +import subprocess + +from isort import SortImports + + +def get_output(command): + """ + Run a command and return raw output + + :param str command: the command to run + :returns: the stdout output of the command + """ + return subprocess.check_output(command.split()) + + +def get_lines(command): + """ + Run a command and return lines of output + + :param str command: the command to run + :returns: list of whitespace-stripped lines output by command + """ + stdout = get_output(command) + return [line.strip().decode('utf-8') for line in stdout.splitlines()] + + +def git_hook(strict=False): + """ + Git pre-commit hook to check staged files for isort errors + + :param bool strict - if True, return number of errors on exit, + causing the hook to fail. If False, return zero so it will + just act as a warning. + + :return number of errors if in strict mode, 0 otherwise. + """ + + # Get list of files modified and staged + diff_cmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD" + files_modified = get_lines(diff_cmd) + + errors = 0 + for filename in files_modified: + if filename.endswith('.py'): + # Get the staged contents of the file + staged_cmd = "git show :%s" % filename + staged_contents = get_output(staged_cmd) + + sort = SortImports( + file_path=filename, + file_contents=staged_contents.decode(), + check=True + ) + + if sort.incorrectly_sorted: + errors += 1 + + return errors if strict else 0 diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/isort.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/isort.py new file mode 100644 index 0000000..cecd5af --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/isort.py @@ -0,0 +1,969 @@ +"""isort.py. + +Exposes a simple library to sort through imports within Python code + +usage: + SortImports(file_name) +or: + sorted = SortImports(file_contents=file_contents).output + +Copyright (C) 2013 Timothy Edmund Crosley + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +""" +from __future__ import absolute_import, division, print_function, unicode_literals + +import copy +import io +import itertools +import os +import re +import sys +from collections import namedtuple +from datetime import datetime +from difflib import unified_diff +from fnmatch import fnmatch +from glob import glob + +from . import settings +from .natural import nsorted +from .pie_slice import OrderedDict, OrderedSet, input, itemsview + +KNOWN_SECTION_MAPPING = { + 'STDLIB': 'STANDARD_LIBRARY', + 'FUTURE': 'FUTURE_LIBRARY', + 'FIRSTPARTY': 'FIRST_PARTY', + 'THIRDPARTY': 'THIRD_PARTY', +} + + +class SortImports(object): + incorrectly_sorted = False + skipped = False + + def __init__(self, file_path=None, file_contents=None, write_to_stdout=False, check=False, + show_diff=False, settings_path=None, ask_to_apply=False, **setting_overrides): + if not settings_path and file_path: + settings_path = os.path.dirname(os.path.abspath(file_path)) + settings_path = settings_path or os.getcwd() + + self.config = settings.from_path(settings_path).copy() + for key, value in itemsview(setting_overrides): + access_key = key.replace('not_', '').lower() + # The sections config needs to retain order and can't be converted to a set. + if access_key != 'sections' and type(self.config.get(access_key)) in (list, tuple): + if key.startswith('not_'): + self.config[access_key] = list(set(self.config[access_key]).difference(value)) + else: + self.config[access_key] = list(set(self.config[access_key]).union(value)) + else: + self.config[key] = value + + if self.config['force_alphabetical_sort']: + self.config.update({'force_alphabetical_sort_within_sections': True, + 'no_sections': True, + 'lines_between_types': 1, + 'from_first': True}) + + indent = str(self.config['indent']) + if indent.isdigit(): + indent = " " * int(indent) + else: + indent = indent.strip("'").strip('"') + if indent.lower() == "tab": + indent = "\t" + self.config['indent'] = indent + + self.place_imports = {} + self.import_placements = {} + self.remove_imports = [self._format_simplified(removal) for removal in self.config['remove_imports']] + self.add_imports = [self._format_natural(addition) for addition in self.config['add_imports']] + self._section_comments = ["# " + value for key, value in itemsview(self.config) if + key.startswith('import_heading') and value] + + self.file_encoding = 'utf-8' + file_name = file_path + self.file_path = file_path or "" + if file_path: + file_path = os.path.abspath(file_path) + if settings.should_skip(file_path, self.config): + self.skipped = True + if self.config['verbose']: + print("WARNING: {0} was skipped as it's listed in 'skip' setting" + " or matches a glob in 'skip_glob' setting".format(file_path)) + file_contents = None + elif not file_contents: + self.file_path = file_path + self.file_encoding = coding_check(file_path) + with io.open(file_path, encoding=self.file_encoding) as file_to_import_sort: + file_contents = file_to_import_sort.read() + + if file_contents is None or ("isort:" + "skip_file") in file_contents: + return + + self.in_lines = file_contents.split("\n") + self.original_length = len(self.in_lines) + if (self.original_length > 1 or self.in_lines[:1] not in ([], [""])) or self.config['force_adds']: + for add_import in self.add_imports: + self.in_lines.append(add_import) + self.number_of_lines = len(self.in_lines) + + self.out_lines = [] + self.comments = {'from': {}, 'straight': {}, 'nested': {}, 'above': {'straight': {}, 'from': {}}} + self.imports = OrderedDict() + self.as_map = {} + + section_names = self.config['sections'] + self.sections = namedtuple('Sections', section_names)(*[name for name in section_names]) + for section in itertools.chain(self.sections, self.config['forced_separate']): + self.imports[section] = {'straight': OrderedSet(), 'from': OrderedDict()} + + self.known_patterns = [] + for placement in reversed(self.sections): + known_placement = KNOWN_SECTION_MAPPING.get(placement, placement) + config_key = 'known_{0}'.format(known_placement.lower()) + known_patterns = self.config.get(config_key, []) + for known_pattern in known_patterns: + self.known_patterns.append((re.compile('^' + known_pattern.replace('*', '.*').replace('?', '.?') + '$'), + placement)) + + self.index = 0 + self.import_index = -1 + self._first_comment_index_start = -1 + self._first_comment_index_end = -1 + self._parse() + if self.import_index != -1: + self._add_formatted_imports() + + self.length_change = len(self.out_lines) - self.original_length + while self.out_lines and self.out_lines[-1].strip() == "": + self.out_lines.pop(-1) + self.out_lines.append("") + + self.output = "\n".join(self.out_lines) + if self.config['atomic']: + try: + compile(self._strip_top_comments(self.out_lines), self.file_path, 'exec', 0, 1) + except SyntaxError: + self.output = file_contents + self.incorrectly_sorted = True + try: + compile(self._strip_top_comments(self.in_lines), self.file_path, 'exec', 0, 1) + print("ERROR: {0} isort would have introduced syntax errors, please report to the project!". \ + format(self.file_path)) + except SyntaxError: + print("ERROR: {0} File contains syntax errors.".format(self.file_path)) + + return + if check: + check_output = self.output + check_against = file_contents + if self.config['ignore_whitespace']: + check_output = check_output.replace("\n", "").replace(" ", "") + check_against = check_against.replace("\n", "").replace(" ", "") + + if check_output == check_against: + if self.config['verbose']: + print("SUCCESS: {0} Everything Looks Good!".format(self.file_path)) + return + + print("ERROR: {0} Imports are incorrectly sorted.".format(self.file_path)) + self.incorrectly_sorted = True + if show_diff or self.config['show_diff']: + self._show_diff(file_contents) + elif write_to_stdout: + sys.stdout.write(self.output) + elif file_name and not check: + if ask_to_apply: + if self.output == file_contents: + return + self._show_diff(file_contents) + answer = None + while answer not in ('yes', 'y', 'no', 'n', 'quit', 'q'): + answer = input("Apply suggested changes to '{0}' [y/n/q]?".format(self.file_path)).lower() + if answer in ('no', 'n'): + return + if answer in ('quit', 'q'): + sys.exit(1) + with io.open(self.file_path, encoding=self.file_encoding, mode='w') as output_file: + output_file.write(self.output) + + def _show_diff(self, file_contents): + for line in unified_diff( + file_contents.splitlines(1), + self.output.splitlines(1), + fromfile=self.file_path + ':before', + tofile=self.file_path + ':after', + fromfiledate=str(datetime.fromtimestamp(os.path.getmtime(self.file_path)) + if self.file_path else datetime.now()), + tofiledate=str(datetime.now()) + ): + sys.stdout.write(line) + + @staticmethod + def _strip_top_comments(lines): + """Strips # comments that exist at the top of the given lines""" + lines = copy.copy(lines) + while lines and lines[0].startswith("#"): + lines = lines[1:] + return "\n".join(lines) + + def place_module(self, module_name): + """Tries to determine if a module is a python std import, third party import, or project code: + + if it can't determine - it assumes it is project code + + """ + for forced_separate in self.config['forced_separate']: + # Ensure all forced_separate patterns will match to end of string + path_glob = forced_separate + if not forced_separate.endswith('*'): + path_glob = '%s*' % forced_separate + + if fnmatch(module_name, path_glob) or fnmatch(module_name, '.' + path_glob): + return forced_separate + + if module_name.startswith("."): + return self.sections.LOCALFOLDER + + # Try to find most specific placement instruction match (if any) + parts = module_name.split('.') + module_names_to_check = ['.'.join(parts[:first_k]) for first_k in range(len(parts), 0, -1)] + for module_name_to_check in module_names_to_check: + for pattern, placement in self.known_patterns: + if pattern.match(module_name_to_check): + return placement + + # Use a copy of sys.path to avoid any unintended modifications + # to it - e.g. `+=` used below will change paths in place and + # if not copied, consequently sys.path, which will grow unbounded + # with duplicates on every call to this method. + paths = list(sys.path) + virtual_env = self.config.get('virtual_env') or os.environ.get('VIRTUAL_ENV') + virtual_env_src = False + if virtual_env: + paths += [path for path in glob('{0}/lib/python*/site-packages'.format(virtual_env)) + if path not in paths] + paths += [path for path in glob('{0}/src/*'.format(virtual_env)) if os.path.isdir(path)] + virtual_env_src = '{0}/src/'.format(virtual_env) + + # handle case-insensitive paths on windows + stdlib_lib_prefix = os.path.normcase(get_stdlib_path()) + + for prefix in paths: + module_path = "/".join((prefix, module_name.replace(".", "/"))) + package_path = "/".join((prefix, module_name.split(".")[0])) + is_module = (exists_case_sensitive(module_path + ".py") or + exists_case_sensitive(module_path + ".so")) + is_package = exists_case_sensitive(package_path) and os.path.isdir(package_path) + if is_module or is_package: + if ('site-packages' in prefix or 'dist-packages' in prefix or + (virtual_env and virtual_env_src in prefix)): + return self.sections.THIRDPARTY + elif os.path.normcase(prefix).startswith(stdlib_lib_prefix): + return self.sections.STDLIB + else: + return self.config['default_section'] + + return self.config['default_section'] + + def _get_line(self): + """Returns the current line from the file while incrementing the index.""" + line = self.in_lines[self.index] + self.index += 1 + return line + + @staticmethod + def _import_type(line): + """If the current line is an import line it will return its type (from or straight)""" + if "isort:skip" in line: + return + elif line.startswith('import '): + return "straight" + elif line.startswith('from '): + return "from" + + def _at_end(self): + """returns True if we are at the end of the file.""" + return self.index == self.number_of_lines + + @staticmethod + def _module_key(module_name, config, sub_imports=False, ignore_case=False): + prefix = "" + if ignore_case: + module_name = str(module_name).lower() + else: + module_name = str(module_name) + + if sub_imports and config['order_by_type']: + if module_name.isupper() and len(module_name) > 1: + prefix = "A" + elif module_name[0:1].isupper(): + prefix = "B" + else: + prefix = "C" + module_name = module_name.lower() + return "{0}{1}{2}".format(module_name in config['force_to_top'] and "A" or "B", prefix, + config['length_sort'] and (str(len(module_name)) + ":" + module_name) or module_name) + + def _add_comments(self, comments, original_string=""): + """ + Returns a string with comments added + """ + return comments and "{0} # {1}".format(self._strip_comments(original_string)[0], + "; ".join(comments)) or original_string + + def _wrap(self, line): + """ + Returns an import wrapped to the specified line-length, if possible. + """ + wrap_mode = self.config['multi_line_output'] + if len(line) > self.config['line_length'] and wrap_mode != settings.WrapModes.NOQA: + for splitter in ("import", ".", "as"): + exp = r"\b" + re.escape(splitter) + r"\b" + if re.search(exp, line) and not line.strip().startswith(splitter): + line_parts = re.split(exp, line) + next_line = [] + while (len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']) and line_parts: + next_line.append(line_parts.pop()) + line = splitter.join(line_parts) + if not line: + line = next_line.pop() + + cont_line = self._wrap(self.config['indent'] + splitter.join(next_line).lstrip()) + if self.config['use_parentheses']: + output = "{0}{1} (\n{2}{3}{4})".format( + line, splitter, cont_line, + "," if self.config['include_trailing_comma'] else "", + "\n" if wrap_mode in ( + settings.WrapModes.VERTICAL_HANGING_INDENT, + settings.WrapModes.VERTICAL_GRID_GROUPED, + ) else "") + lines = output.split('\n') + if ' #' in lines[-1] and lines[-1].endswith(')'): + line, comment = lines[-1].split(' #', 1) + lines[-1] = line + ') #' + comment[:-1] + return '\n'.join(lines) + return "{0}{1} \\\n{2}".format(line, splitter, cont_line) + elif len(line) > self.config['line_length'] and wrap_mode == settings.WrapModes.NOQA: + if "# NOQA" not in line: + return "{0} # NOQA".format(line) + + return line + + def _add_straight_imports(self, straight_modules, section, section_output): + for module in straight_modules: + if module in self.remove_imports: + continue + + if module in self.as_map: + import_definition = "import {0} as {1}".format(module, self.as_map[module]) + else: + import_definition = "import {0}".format(module) + + comments_above = self.comments['above']['straight'].pop(module, None) + if comments_above: + section_output.extend(comments_above) + section_output.append(self._add_comments(self.comments['straight'].get(module), import_definition)) + + def _add_from_imports(self, from_modules, section, section_output, ignore_case): + for module in from_modules: + if module in self.remove_imports: + continue + + import_start = "from {0} import ".format(module) + from_imports = self.imports[section]['from'][module] + from_imports = nsorted(from_imports, key=lambda key: self._module_key(key, self.config, True, ignore_case)) + if self.remove_imports: + from_imports = [line for line in from_imports if not "{0}.{1}".format(module, line) in + self.remove_imports] + + for from_import in copy.copy(from_imports): + submodule = module + "." + from_import + import_as = self.as_map.get(submodule, False) + if import_as: + import_definition = "{0} as {1}".format(from_import, import_as) + if self.config['combine_as_imports'] and not ("*" in from_imports and + self.config['combine_star']): + from_imports[from_imports.index(from_import)] = import_definition + else: + import_statement = import_start + import_definition + force_grid_wrap = self.config['force_grid_wrap'] + comments = self.comments['straight'].get(submodule) + import_statement = self._add_comments(comments, self._wrap(import_statement)) + from_imports.remove(from_import) + section_output.append(import_statement) + + + if from_imports: + comments = self.comments['from'].pop(module, ()) + if "*" in from_imports and self.config['combine_star']: + import_statement = self._wrap(self._add_comments(comments, "{0}*".format(import_start))) + elif self.config['force_single_line']: + import_statements = [] + for from_import in from_imports: + single_import_line = self._add_comments(comments, import_start + from_import) + comment = self.comments['nested'].get(module, {}).pop(from_import, None) + if comment: + single_import_line += "{0} {1}".format(comments and ";" or " #", comment) + import_statements.append(self._wrap(single_import_line)) + comments = None + import_statement = "\n".join(import_statements) + else: + star_import = False + if "*" in from_imports: + section_output.append(self._add_comments(comments, "{0}*".format(import_start))) + from_imports.remove('*') + star_import = True + comments = None + + for from_import in copy.copy(from_imports): + comment = self.comments['nested'].get(module, {}).pop(from_import, None) + if comment: + single_import_line = self._add_comments(comments, import_start + from_import) + single_import_line += "{0} {1}".format(comments and ";" or " #", comment) + above_comments = self.comments['above']['from'].pop(module, None) + if above_comments: + section_output.extend(above_comments) + section_output.append(self._wrap(single_import_line)) + from_imports.remove(from_import) + comments = None + + if star_import: + import_statement = import_start + (", ").join(from_imports) + else: + import_statement = self._add_comments(comments, import_start + (", ").join(from_imports)) + if not from_imports: + import_statement = "" + + do_multiline_reformat = False + + force_grid_wrap = self.config['force_grid_wrap'] + if force_grid_wrap and len(from_imports) >= force_grid_wrap: + do_multiline_reformat = True + + if len(import_statement) > self.config['line_length'] and len(from_imports) > 1: + do_multiline_reformat = True + + # If line too long AND have imports AND we are NOT using GRID or VERTICAL wrap modes + if (len(import_statement) > self.config['line_length'] and len(from_imports) > 0 and + self.config['multi_line_output'] not in (1, 0)): + do_multiline_reformat = True + + if do_multiline_reformat: + import_statement = self._multi_line_reformat(import_start, from_imports, comments) + if not do_multiline_reformat and len(import_statement) > self.config['line_length']: + import_statement = self._wrap(import_statement) + + if import_statement: + above_comments = self.comments['above']['from'].pop(module, None) + if above_comments: + section_output.extend(above_comments) + section_output.append(import_statement) + + def _multi_line_reformat(self, import_start, from_imports, comments): + output_mode = settings.WrapModes._fields[self.config['multi_line_output']].lower() + formatter = getattr(self, "_output_" + output_mode, self._output_grid) + dynamic_indent = " " * (len(import_start) + 1) + indent = self.config['indent'] + line_length = self.config['wrap_length'] or self.config['line_length'] + import_statement = formatter(import_start, copy.copy(from_imports), + dynamic_indent, indent, line_length, comments) + if self.config['balanced_wrapping']: + lines = import_statement.split("\n") + line_count = len(lines) + if len(lines) > 1: + minimum_length = min([len(line) for line in lines[:-1]]) + else: + minimum_length = 0 + new_import_statement = import_statement + while (len(lines[-1]) < minimum_length and + len(lines) == line_count and line_length > 10): + import_statement = new_import_statement + line_length -= 1 + new_import_statement = formatter(import_start, copy.copy(from_imports), + dynamic_indent, indent, line_length, comments) + lines = new_import_statement.split("\n") + if import_statement.count('\n') == 0: + return self._wrap(import_statement) + return import_statement + + def _add_formatted_imports(self): + """Adds the imports back to the file. + + (at the index of the first import) sorted alphabetically and split between groups + + """ + sort_ignore_case = self.config['force_alphabetical_sort_within_sections'] + sections = itertools.chain(self.sections, self.config['forced_separate']) + + if self.config['no_sections']: + self.imports['no_sections'] = {'straight': [], 'from': {}} + for section in sections: + self.imports['no_sections']['straight'].extend(self.imports[section].get('straight', [])) + self.imports['no_sections']['from'].update(self.imports[section].get('from', {})) + sections = ('no_sections', ) + + output = [] + for section in sections: + straight_modules = self.imports[section]['straight'] + straight_modules = nsorted(straight_modules, key=lambda key: self._module_key(key, self.config)) + from_modules = self.imports[section]['from'] + from_modules = nsorted(from_modules, key=lambda key: self._module_key(key, self.config)) + + section_output = [] + if self.config['from_first']: + self._add_from_imports(from_modules, section, section_output, sort_ignore_case) + if self.config['lines_between_types'] and from_modules and straight_modules: + section_output.extend([''] * self.config['lines_between_types']) + self._add_straight_imports(straight_modules, section, section_output) + else: + self._add_straight_imports(straight_modules, section, section_output) + if self.config['lines_between_types'] and from_modules and straight_modules: + section_output.extend([''] * self.config['lines_between_types']) + self._add_from_imports(from_modules, section, section_output, sort_ignore_case) + + if self.config['force_sort_within_sections']: + def by_module(line): + section = 'B' + if line.startswith('#'): + return 'AA' + + line = re.sub('^from ', '', line) + line = re.sub('^import ', '', line) + if line.split(' ')[0] in self.config['force_to_top']: + section = 'A' + if not self.config['order_by_type']: + line = line.lower() + return '{0}{1}'.format(section, line) + section_output = nsorted(section_output, key=by_module) + + if section_output: + section_name = section + if section_name in self.place_imports: + self.place_imports[section_name] = section_output + continue + + section_title = self.config.get('import_heading_' + str(section_name).lower(), '') + if section_title: + section_comment = "# {0}".format(section_title) + if not section_comment in self.out_lines[0:1] and not section_comment in self.in_lines[0:1]: + section_output.insert(0, section_comment) + output += section_output + ([''] * self.config['lines_between_sections']) + + while [character.strip() for character in output[-1:]] == [""]: + output.pop() + + output_at = 0 + if self.import_index < self.original_length: + output_at = self.import_index + elif self._first_comment_index_end != -1 and self._first_comment_index_start <= 2: + output_at = self._first_comment_index_end + self.out_lines[output_at:0] = output + + imports_tail = output_at + len(output) + while [character.strip() for character in self.out_lines[imports_tail: imports_tail + 1]] == [""]: + self.out_lines.pop(imports_tail) + + if len(self.out_lines) > imports_tail: + next_construct = "" + self._in_quote = False + tail = self.out_lines[imports_tail:] + for index, line in enumerate(tail): + if not self._skip_line(line) and line.strip(): + if line.strip().startswith("#") and len(tail) > (index + 1) and tail[index + 1].strip(): + continue + next_construct = line + break + + if self.config['lines_after_imports'] != -1: + self.out_lines[imports_tail:0] = ["" for line in range(self.config['lines_after_imports'])] + elif next_construct.startswith("def") or next_construct.startswith("class") or \ + next_construct.startswith("@") or next_construct.startswith("async def"): + self.out_lines[imports_tail:0] = ["", ""] + else: + self.out_lines[imports_tail:0] = [""] + + if self.place_imports: + new_out_lines = [] + for index, line in enumerate(self.out_lines): + new_out_lines.append(line) + if line in self.import_placements: + new_out_lines.extend(self.place_imports[self.import_placements[line]]) + if len(self.out_lines) <= index or self.out_lines[index + 1].strip() != "": + new_out_lines.append("") + self.out_lines = new_out_lines + + def _output_grid(self, statement, imports, white_space, indent, line_length, comments): + statement += "(" + imports.pop(0) + while imports: + next_import = imports.pop(0) + next_statement = self._add_comments(comments, statement + ", " + next_import) + if len(next_statement.split("\n")[-1]) + 1 > line_length: + lines = ['{0}{1}'.format(white_space, next_import.split(" ")[0])] + for part in next_import.split(" ")[1:]: + new_line = '{0} {1}'.format(lines[-1], part) + if len(new_line) + 1 > line_length: + lines.append('{0}{1}'.format(white_space, part)) + else: + lines[-1] = new_line + next_import = '\n'.join(lines) + statement = (self._add_comments(comments, "{0},".format(statement)) + + "\n{0}".format(next_import)) + comments = None + else: + statement += ", " + next_import + return statement + ("," if self.config['include_trailing_comma'] else "") + ")" + + def _output_vertical(self, statement, imports, white_space, indent, line_length, comments): + first_import = self._add_comments(comments, imports.pop(0) + ",") + "\n" + white_space + return "{0}({1}{2}{3})".format( + statement, + first_import, + (",\n" + white_space).join(imports), + "," if self.config['include_trailing_comma'] else "", + ) + + def _output_hanging_indent(self, statement, imports, white_space, indent, line_length, comments): + statement += imports.pop(0) + while imports: + next_import = imports.pop(0) + next_statement = self._add_comments(comments, statement + ", " + next_import) + if len(next_statement.split("\n")[-1]) + 3 > line_length: + next_statement = (self._add_comments(comments, "{0}, \\".format(statement)) + + "\n{0}{1}".format(indent, next_import)) + comments = None + statement = next_statement + return statement + + def _output_vertical_hanging_indent(self, statement, imports, white_space, indent, line_length, comments): + return "{0}({1}\n{2}{3}{4}\n)".format( + statement, + self._add_comments(comments), + indent, + (",\n" + indent).join(imports), + "," if self.config['include_trailing_comma'] else "", + ) + + def _output_vertical_grid_common(self, statement, imports, white_space, indent, line_length, comments): + statement += self._add_comments(comments, "(") + "\n" + indent + imports.pop(0) + while imports: + next_import = imports.pop(0) + next_statement = "{0}, {1}".format(statement, next_import) + if len(next_statement.split("\n")[-1]) + 1 > line_length: + next_statement = "{0},\n{1}{2}".format(statement, indent, next_import) + statement = next_statement + if self.config['include_trailing_comma']: + statement += ',' + return statement + + def _output_vertical_grid(self, statement, imports, white_space, indent, line_length, comments): + return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments) + ")" + + def _output_vertical_grid_grouped(self, statement, imports, white_space, indent, line_length, comments): + return self._output_vertical_grid_common(statement, imports, white_space, indent, line_length, comments) + "\n)" + + def _output_noqa(self, statement, imports, white_space, indent, line_length, comments): + retval = '{0}{1}'.format(statement, ', '.join(imports)) + comment_str = ' '.join(comments) + if comments: + if len(retval) + 4 + len(comment_str) <= line_length: + return '{0} # {1}'.format(retval, comment_str) + else: + if len(retval) <= line_length: + return retval + if comments: + if "NOQA" in comments: + return '{0} # {1}'.format(retval, comment_str) + else: + return '{0} # NOQA {1}'.format(retval, comment_str) + else: + return '{0} # NOQA'.format(retval) + + @staticmethod + def _strip_comments(line, comments=None): + """Removes comments from import line.""" + if comments is None: + comments = [] + + new_comments = False + comment_start = line.find("#") + if comment_start != -1: + comments.append(line[comment_start + 1:].strip()) + new_comments = True + line = line[:comment_start] + + return line, comments, new_comments + + @staticmethod + def _format_simplified(import_line): + import_line = import_line.strip() + if import_line.startswith("from "): + import_line = import_line.replace("from ", "") + import_line = import_line.replace(" import ", ".") + elif import_line.startswith("import "): + import_line = import_line.replace("import ", "") + + return import_line + + @staticmethod + def _format_natural(import_line): + import_line = import_line.strip() + if not import_line.startswith("from ") and not import_line.startswith("import "): + if not "." in import_line: + return "import {0}".format(import_line) + parts = import_line.split(".") + end = parts.pop(-1) + return "from {0} import {1}".format(".".join(parts), end) + + return import_line + + def _skip_line(self, line): + skip_line = self._in_quote + if self.index == 1 and line.startswith("#"): + self._in_top_comment = True + return True + elif self._in_top_comment: + if not line.startswith("#"): + self._in_top_comment = False + self._first_comment_index_end = self.index - 1 + + if '"' in line or "'" in line: + index = 0 + if self._first_comment_index_start == -1 and (line.startswith('"') or line.startswith("'")): + self._first_comment_index_start = self.index + while index < len(line): + if line[index] == "\\": + index += 1 + elif self._in_quote: + if line[index:index + len(self._in_quote)] == self._in_quote: + self._in_quote = False + if self._first_comment_index_end < self._first_comment_index_start: + self._first_comment_index_end = self.index + elif line[index] in ("'", '"'): + long_quote = line[index:index + 3] + if long_quote in ('"""', "'''"): + self._in_quote = long_quote + index += 2 + else: + self._in_quote = line[index] + elif line[index] == "#": + break + index += 1 + + return skip_line or self._in_quote or self._in_top_comment + + def _strip_syntax(self, import_string): + import_string = import_string.replace("_import", "[[i]]") + for remove_syntax in ['\\', '(', ')', ',']: + import_string = import_string.replace(remove_syntax, " ") + import_list = import_string.split() + for key in ('from', 'import'): + if key in import_list: + import_list.remove(key) + import_string = ' '.join(import_list) + import_string = import_string.replace("[[i]]", "_import") + return import_string.replace("{ ", "{|").replace(" }", "|}") + + def _parse(self): + """Parses a python file taking out and categorizing imports.""" + self._in_quote = False + self._in_top_comment = False + while not self._at_end(): + line = self._get_line() + statement_index = self.index + skip_line = self._skip_line(line) + + if line in self._section_comments and not skip_line: + if self.import_index == -1: + self.import_index = self.index - 1 + continue + + if "isort:imports-" in line and line.startswith("#"): + section = line.split("isort:imports-")[-1].split()[0].upper() + self.place_imports[section] = [] + self.import_placements[line] = section + + if ";" in line: + for part in (part.strip() for part in line.split(";")): + if part and not part.startswith("from ") and not part.startswith("import "): + skip_line = True + + import_type = self._import_type(line) + if not import_type or skip_line: + self.out_lines.append(line) + continue + + for line in (line.strip() for line in line.split(";")): + import_type = self._import_type(line) + if not import_type: + self.out_lines.append(line) + continue + + line = line.replace("\t", " ").replace('import*', 'import *') + if self.import_index == -1: + self.import_index = self.index - 1 + + nested_comments = {} + import_string, comments, new_comments = self._strip_comments(line) + stripped_line = [part for part in self._strip_syntax(import_string).strip().split(" ") if part] + + if import_type == "from" and len(stripped_line) == 2 and stripped_line[1] != "*" and new_comments: + nested_comments[stripped_line[-1]] = comments[0] + + if "(" in line.split("#")[0] and not self._at_end(): + while not line.strip().endswith(")") and not self._at_end(): + line, comments, new_comments = self._strip_comments(self._get_line(), comments) + stripped_line = self._strip_syntax(line).strip() + if import_type == "from" and stripped_line and not " " in stripped_line and new_comments: + nested_comments[stripped_line] = comments[-1] + import_string += "\n" + line + else: + while line.strip().endswith("\\"): + line, comments, new_comments = self._strip_comments(self._get_line(), comments) + stripped_line = self._strip_syntax(line).strip() + if import_type == "from" and stripped_line and not " " in stripped_line and new_comments: + nested_comments[stripped_line] = comments[-1] + if import_string.strip().endswith(" import") or line.strip().startswith("import "): + import_string += "\n" + line + else: + import_string = import_string.rstrip().rstrip("\\") + " " + line.lstrip() + + if import_type == "from": + import_string = import_string.replace("import(", "import (") + parts = import_string.split(" import ") + from_import = parts[0].split(" ") + import_string = " import ".join([from_import[0] + " " + "".join(from_import[1:])] + parts[1:]) + + imports = [item.replace("{|", "{ ").replace("|}", " }") for item in + self._strip_syntax(import_string).split()] + if "as" in imports and (imports.index('as') + 1) < len(imports): + while "as" in imports: + index = imports.index('as') + if import_type == "from": + module = imports[0] + "." + imports[index - 1] + self.as_map[module] = imports[index + 1] + else: + module = imports[index - 1] + self.as_map[module] = imports[index + 1] + if not self.config['combine_as_imports']: + self.comments['straight'][module] = comments + comments = [] + del imports[index:index + 2] + if import_type == "from": + import_from = imports.pop(0) + placed_module = self.place_module(import_from) + if placed_module == '': + print( + "WARNING: could not place module {0} of line {1} --" + " Do you need to define a default section?".format(import_from, line) + ) + root = self.imports[placed_module][import_type] + for import_name in imports: + associated_comment = nested_comments.get(import_name) + if associated_comment: + self.comments['nested'].setdefault(import_from, {})[import_name] = associated_comment + comments.pop(comments.index(associated_comment)) + if comments: + self.comments['from'].setdefault(import_from, []).extend(comments) + + if len(self.out_lines) > max(self.import_index, self._first_comment_index_end + 1, 1) - 1: + last = self.out_lines and self.out_lines[-1].rstrip() or "" + while (last.startswith("#") and not last.endswith('"""') and not last.endswith("'''") and not + 'isort:imports-' in last): + self.comments['above']['from'].setdefault(import_from, []).insert(0, self.out_lines.pop(-1)) + if len(self.out_lines) > max(self.import_index - 1, self._first_comment_index_end + 1, 1) - 1: + last = self.out_lines[-1].rstrip() + else: + last = "" + if statement_index - 1 == self.import_index: + self.import_index -= len(self.comments['above']['from'].get(import_from, [])) + + if root.get(import_from, False): + root[import_from].update(imports) + else: + root[import_from] = OrderedSet(imports) + else: + for module in imports: + if comments: + self.comments['straight'][module] = comments + comments = None + + if len(self.out_lines) > max(self.import_index, self._first_comment_index_end + 1, 1) - 1: + + last = self.out_lines and self.out_lines[-1].rstrip() or "" + while (last.startswith("#") and not last.endswith('"""') and not last.endswith("'''") and + not 'isort:imports-' in last): + self.comments['above']['straight'].setdefault(module, []).insert(0, + self.out_lines.pop(-1)) + if len(self.out_lines) > 0: + last = self.out_lines[-1].rstrip() + else: + last = "" + if self.index - 1 == self.import_index: + self.import_index -= len(self.comments['above']['straight'].get(module, [])) + placed_module = self.place_module(module) + if placed_module == '': + print( + "WARNING: could not place module {0} of line {1} --" + " Do you need to define a default section?".format(import_from, line) + ) + self.imports[placed_module][import_type].add(module) + + +def coding_check(fname, default='utf-8'): + + # see https://www.python.org/dev/peps/pep-0263/ + pattern = re.compile(br'coding[:=]\s*([-\w.]+)') + + coding = default + with io.open(fname, 'rb') as f: + for line_number, line in enumerate(f, 1): + groups = re.findall(pattern, line) + if groups: + coding = groups[0].decode('ascii') + break + if line_number > 2: + break + + return coding + + +def get_stdlib_path(): + """Returns the path to the standard lib for the current path installation. + + This function can be dropped and "sysconfig.get_paths()" used directly once Python 2.6 support is dropped. + """ + if sys.version_info >= (2, 7): + import sysconfig + return sysconfig.get_paths()['stdlib'] + else: + return os.path.join(sys.prefix, 'lib') + + +def exists_case_sensitive(path): + """ + Returns if the given path exists and also matches the case on Windows. + + When finding files that can be imported, it is important for the cases to match because while + file os.path.exists("module.py") and os.path.exists("MODULE.py") both return True on Windows, Python + can only import using the case of the real file. + """ + result = os.path.exists(path) + if sys.platform.startswith('win') and result: + directory, basename = os.path.split(path) + result = basename in os.listdir(directory) + return result diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/main.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/main.py new file mode 100644 index 0000000..eae7afa --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/main.py @@ -0,0 +1,296 @@ +#! /usr/bin/env python +''' Tool for sorting imports alphabetically, and automatically separated into sections. + +Copyright (C) 2013 Timothy Edmund Crosley + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +''' +from __future__ import absolute_import, division, print_function, unicode_literals + +import argparse +import glob +import os +import sys + +import setuptools + +from isort import SortImports, __version__ +from isort.settings import DEFAULT_SECTIONS, default, from_path, should_skip + +from .pie_slice import itemsview + + +INTRO = r""" +/#######################################################################\ + + `sMMy` + .yyyy- ` + ##soos## ./o. + ` ``..-..` ``...`.`` ` ```` ``-ssso``` + .s:-y- .+osssssso/. ./ossss+:so+:` :+o-`/osso:+sssssssso/ + .s::y- osss+.``.`` -ssss+-.`-ossso` ssssso/::..::+ssss:::. + .s::y- /ssss+//:-.` `ssss+ `ssss+ sssso` :ssss` + .s::y- `-/+oossssso/ `ssss/ sssso ssss/ :ssss` + .y-/y- ````:ssss` ossso. :ssss: ssss/ :ssss. + `/so:` `-//::/osss+ `+ssss+-/ossso: /sso- `osssso/. + \/ `-/oooo++/- .:/++:/++/-` .. `://++/. + + + isort your Python imports for you so you don't have to + + VERSION {0} + +\########################################################################/ +""".format(__version__) + + +def iter_source_code(paths, config, skipped): + """Iterate over all Python source files defined in paths.""" + for path in paths: + if os.path.isdir(path): + if should_skip(path, config, os.getcwd()): + skipped.append(path) + continue + + for dirpath, dirnames, filenames in os.walk(path, topdown=True): + for dirname in list(dirnames): + if should_skip(dirname, config, dirpath): + skipped.append(dirname) + dirnames.remove(dirname) + for filename in filenames: + if filename.endswith('.py'): + if should_skip(filename, config, dirpath): + skipped.append(filename) + else: + yield os.path.join(dirpath, filename) + else: + yield path + + +class ISortCommand(setuptools.Command): + """The :class:`ISortCommand` class is used by setuptools to perform + imports checks on registered modules. + """ + + description = "Run isort on modules registered in setuptools" + user_options = [] + + def initialize_options(self): + default_settings = default.copy() + for (key, value) in itemsview(default_settings): + setattr(self, key, value) + + def finalize_options(self): + "Get options from config files." + self.arguments = {} + computed_settings = from_path(os.getcwd()) + for (key, value) in itemsview(computed_settings): + self.arguments[key] = value + + def distribution_files(self): + """Find distribution packages.""" + # This is verbatim from flake8 + if self.distribution.packages: + package_dirs = self.distribution.package_dir or {} + for package in self.distribution.packages: + pkg_dir = package + if package in package_dirs: + pkg_dir = package_dirs[package] + elif '' in package_dirs: + pkg_dir = package_dirs[''] + os.path.sep + pkg_dir + yield pkg_dir.replace('.', os.path.sep) + + if self.distribution.py_modules: + for filename in self.distribution.py_modules: + yield "%s.py" % filename + # Don't miss the setup.py file itself + yield "setup.py" + + def run(self): + arguments = self.arguments + wrong_sorted_files = False + arguments['check'] = True + for path in self.distribution_files(): + for python_file in glob.iglob(os.path.join(path, '*.py')): + try: + incorrectly_sorted = SortImports(python_file, **arguments).incorrectly_sorted + if incorrectly_sorted: + wrong_sorted_files = True + except IOError as e: + print("WARNING: Unable to parse file {0} due to {1}".format(python_file, e)) + if wrong_sorted_files: + exit(1) + + +def create_parser(): + parser = argparse.ArgumentParser(description='Sort Python import definitions alphabetically ' + 'within logical sections.') + parser.add_argument('files', nargs='*', help='One or more Python source files that need their imports sorted.') + parser.add_argument('-y', '--apply', dest='apply', action='store_true', + help='Tells isort to apply changes recursively without asking') + parser.add_argument('-l', '--lines', help='[Deprecated] The max length of an import line (used for wrapping ' + 'long imports).', + dest='line_length', type=int) + parser.add_argument('-w', '--line-width', help='The max length of an import line (used for wrapping long imports).', + dest='line_length', type=int) + parser.add_argument('-s', '--skip', help='Files that sort imports should skip over. If you want to skip multiple ' + 'files you should specify twice: --skip file1 --skip file2.', dest='skip', action='append') + parser.add_argument('-ns', '--dont-skip', help='Files that sort imports should never skip over.', + dest='not_skip', action='append') + parser.add_argument('-sg', '--skip-glob', help='Files that sort imports should skip over.', dest='skip_glob', + action='append') + parser.add_argument('-t', '--top', help='Force specific imports to the top of their appropriate section.', + dest='force_to_top', action='append') + parser.add_argument('-f', '--future', dest='known_future_library', action='append', + help='Force sortImports to recognize a module as part of the future compatibility libraries.') + parser.add_argument('-b', '--builtin', dest='known_standard_library', action='append', + help='Force sortImports to recognize a module as part of the python standard library.') + parser.add_argument('-o', '--thirdparty', dest='known_third_party', action='append', + help='Force sortImports to recognize a module as being part of a third party library.') + parser.add_argument('-p', '--project', dest='known_first_party', action='append', + help='Force sortImports to recognize a module as being part of the current python project.') + parser.add_argument('--virtual-env', dest='virtual_env', + help='Virtual environment to use for determining whether a package is third-party') + parser.add_argument('-m', '--multi-line', dest='multi_line_output', type=int, choices=[0, 1, 2, 3, 4, 5], + help='Multi line output (0-grid, 1-vertical, 2-hanging, 3-vert-hanging, 4-vert-grid, ' + '5-vert-grid-grouped).') + parser.add_argument('-i', '--indent', help='String to place for indents defaults to " " (4 spaces).', + dest='indent', type=str) + parser.add_argument('-a', '--add-import', dest='add_imports', action='append', + help='Adds the specified import line to all files, ' + 'automatically determining correct placement.') + parser.add_argument('-af', '--force-adds', dest='force_adds', action='store_true', + help='Forces import adds even if the original file is empty.') + parser.add_argument('-r', '--remove-import', dest='remove_imports', action='append', + help='Removes the specified import from all files.') + parser.add_argument('-ls', '--length-sort', help='Sort imports by their string length.', + dest='length_sort', action='store_true') + parser.add_argument('-d', '--stdout', help='Force resulting output to stdout, instead of in-place.', + dest='write_to_stdout', action='store_true') + parser.add_argument('-c', '--check-only', action='store_true', dest="check", + help='Checks the file for unsorted / unformatted imports and prints them to the ' + 'command line without modifying the file.') + parser.add_argument('-ws', '--ignore-whitespace', action='store_true', dest="ignore_whitespace", + help='Tells isort to ignore whitespace differences when --check-only is being used.') + parser.add_argument('-sl', '--force-single-line-imports', dest='force_single_line', action='store_true', + help='Forces all from imports to appear on their own line') + parser.add_argument('-ds', '--no-sections', help='Put all imports into the same section bucket', dest='no_sections', + action='store_true') + parser.add_argument('-sd', '--section-default', dest='default_section', + help='Sets the default section for imports (by default FIRSTPARTY) options: ' + + str(DEFAULT_SECTIONS)) + parser.add_argument('-df', '--diff', dest='show_diff', action='store_true', + help="Prints a diff of all the changes isort would make to a file, instead of " + "changing it in place") + parser.add_argument('-e', '--balanced', dest='balanced_wrapping', action='store_true', + help='Balances wrapping to produce the most consistent line length possible') + parser.add_argument('-rc', '--recursive', dest='recursive', action='store_true', + help='Recursively look for Python files of which to sort imports') + parser.add_argument('-ot', '--order-by-type', dest='order_by_type', + action='store_true', help='Order imports by type in addition to alphabetically') + parser.add_argument('-dt', '--dont-order-by-type', dest='dont_order_by_type', + action='store_true', help='Only order imports alphabetically, do not attempt type ordering') + parser.add_argument('-ac', '--atomic', dest='atomic', action='store_true', + help="Ensures the output doesn't save if the resulting file contains syntax errors.") + parser.add_argument('-cs', '--combine-star', dest='combine_star', action='store_true', + help="Ensures that if a star import is present, nothing else is imported from that namespace.") + parser.add_argument('-ca', '--combine-as', dest='combine_as_imports', action='store_true', + help="Combines as imports on the same line.") + parser.add_argument('-tc', '--trailing-comma', dest='include_trailing_comma', action='store_true', + help='Includes a trailing comma on multi line imports that include parentheses.') + parser.add_argument('-v', '--version', action='store_true', dest='show_version') + parser.add_argument('-vb', '--verbose', action='store_true', dest="verbose", + help='Shows verbose output, such as when files are skipped or when a check is successful.') + parser.add_argument('-q', '--quiet', action='store_true', dest="quiet", + help='Shows extra quiet output, only errors are outputted.') + parser.add_argument('-sp', '--settings-path', dest="settings_path", + help='Explicitly set the settings path instead of auto determining based on file location.') + parser.add_argument('-ff', '--from-first', dest='from_first', + help="Switches the typical ordering preference, showing from imports first then straight ones.") + parser.add_argument('-wl', '--wrap-length', dest='wrap_length', + help="Specifies how long lines that are wrapped should be, if not set line_length is used.") + parser.add_argument('-fgw', '--force-grid-wrap', nargs='?', const=2, type=int, dest="force_grid_wrap", + help='Force number of from imports (defaults to 2) to be grid wrapped regardless of line ' + 'length') + parser.add_argument('-fass', '--force-alphabetical-sort-within-sections', action='store_true', + dest="force_alphabetical_sort", help='Force all imports to be sorted alphabetically within a ' + 'section') + parser.add_argument('-fas', '--force-alphabetical-sort', action='store_true', dest="force_alphabetical_sort", + help='Force all imports to be sorted as a single section') + parser.add_argument('-fss', '--force-sort-within-sections', action='store_true', dest="force_sort_within_sections", + help='Force imports to be sorted by module, independent of import_type') + parser.add_argument('-lbt', '--lines-between-types', dest='lines_between_types', type=int) + parser.add_argument('-up', '--use-parentheses', dest='use_parentheses', action='store_true', + help='Use parenthesis for line continuation on lenght limit instead of slashes.') + + arguments = dict((key, value) for (key, value) in itemsview(vars(parser.parse_args())) if value) + if 'dont_order_by_type' in arguments: + arguments['order_by_type'] = False + return arguments + + +def main(): + arguments = create_parser() + if arguments.get('show_version'): + print(INTRO) + return + + if 'settings_path' in arguments: + sp = arguments['settings_path'] + arguments['settings_path'] = os.path.abspath(sp) if os.path.isdir(sp) else os.path.dirname(os.path.abspath(sp)) + + file_names = arguments.pop('files', []) + if file_names == ['-']: + SortImports(file_contents=sys.stdin.read(), write_to_stdout=True, **arguments) + else: + if not file_names: + file_names = ['.'] + arguments['recursive'] = True + if not arguments.get('apply', False): + arguments['ask_to_apply'] = True + config = from_path(os.path.abspath(file_names[0]) or os.getcwd()).copy() + config.update(arguments) + wrong_sorted_files = False + skipped = [] + if arguments.get('recursive', False): + file_names = iter_source_code(file_names, config, skipped) + num_skipped = 0 + if config['verbose'] or config.get('show_logo', False): + print(INTRO) + for file_name in file_names: + try: + sort_attempt = SortImports(file_name, **arguments) + incorrectly_sorted = sort_attempt.incorrectly_sorted + if arguments.get('check', False) and incorrectly_sorted: + wrong_sorted_files = True + if sort_attempt.skipped: + num_skipped += 1 + except IOError as e: + print("WARNING: Unable to parse file {0} due to {1}".format(file_name, e)) + if wrong_sorted_files: + exit(1) + + num_skipped += len(skipped) + if num_skipped and not arguments.get('quiet', False): + if config['verbose']: + for was_skipped in skipped: + print("WARNING: {0} was skipped as it's listed in 'skip' setting" + " or matches a glob in 'skip_glob' setting".format(was_skipped)) + print("Skipped {0} files".format(num_skipped)) + + +if __name__ == "__main__": + main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/natural.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/natural.py new file mode 100644 index 0000000..aac8c4a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/natural.py @@ -0,0 +1,47 @@ +"""isort/natural.py. + +Enables sorting strings that contain numbers naturally + +usage: + natural.nsorted(list) + +Copyright (C) 2013 Timothy Edmund Crosley + +Implementation originally from @HappyLeapSecond stack overflow user in response to: + http://stackoverflow.com/questions/5967500/how-to-correctly-sort-a-string-with-a-number-inside + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +""" +import re + + +def _atoi(text): + return int(text) if text.isdigit() else text + + +def _natural_keys(text): + return [_atoi(c) for c in re.split(r'(\d+)', text)] + + +def nsorted(to_sort, key=None): + """Returns a naturally sorted list""" + if key is None: + key_callback = _natural_keys + else: + def key_callback(item): + return _natural_keys(key(item)) + + return sorted(to_sort, key=key_callback) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/pie_slice.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/pie_slice.py new file mode 100644 index 0000000..131f325 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/pie_slice.py @@ -0,0 +1,594 @@ +"""pie_slice/overrides.py. + +Overrides Python syntax to conform to the Python3 version as much as possible using a '*' import + +Copyright (C) 2013 Timothy Edmund Crosley + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +""" +from __future__ import absolute_import + +import abc +import collections +import functools +import sys +from numbers import Integral + +__version__ = "1.1.0" + +PY2 = sys.version_info[0] == 2 +PY3 = sys.version_info[0] == 3 +VERSION = sys.version_info + +native_dict = dict +native_round = round +native_filter = filter +native_map = map +native_zip = zip +native_range = range +native_str = str +native_chr = chr +native_input = input +native_next = next +native_object = object + +common = ['native_dict', 'native_round', 'native_filter', 'native_map', 'native_range', 'native_str', 'native_chr', + 'native_input', 'PY2', 'PY3', 'u', 'itemsview', 'valuesview', 'keysview', 'execute', 'integer_types', + 'native_next', 'native_object', 'with_metaclass', 'OrderedDict', 'lru_cache'] + + +def with_metaclass(meta, *bases): + """Enables use of meta classes across Python Versions. taken from jinja2/_compat.py. + + Use it like this:: + + class BaseForm(object): + pass + + class FormType(type): + pass + + class Form(with_metaclass(FormType, BaseForm)): + pass + + """ + class metaclass(meta): + __call__ = type.__call__ + __init__ = type.__init__ + + def __new__(cls, name, this_bases, d): + if this_bases is None: + return type.__new__(cls, name, (), d) + return meta(name, bases, d) + return metaclass('temporary_class', None, {}) + + +def unmodified_isinstance(*bases): + """When called in the form + + MyOverrideClass(unmodified_isinstance(BuiltInClass)) + + it allows calls against passed in built in instances to pass even if there not a subclass + + """ + class UnmodifiedIsInstance(type): + if sys.version_info[0] == 2 and sys.version_info[1] <= 6: + + @classmethod + def __instancecheck__(cls, instance): + if cls.__name__ in (str(base.__name__) for base in bases): + return isinstance(instance, bases) + + subclass = getattr(instance, '__class__', None) + subtype = type(instance) + instance_type = getattr(abc, '_InstanceType', None) + if not instance_type: + class test_object: + pass + instance_type = type(test_object) + if subtype is instance_type: + subtype = subclass + if subtype is subclass or subclass is None: + return cls.__subclasscheck__(subtype) + return (cls.__subclasscheck__(subclass) or cls.__subclasscheck__(subtype)) + else: + @classmethod + def __instancecheck__(cls, instance): + if cls.__name__ in (str(base.__name__) for base in bases): + return isinstance(instance, bases) + + return type.__instancecheck__(cls, instance) + + return with_metaclass(UnmodifiedIsInstance, *bases) + + +if PY3: + import urllib + import builtins + from urllib import parse + + input = input + integer_types = (int, ) + + def u(string): + return string + + def itemsview(collection): + return collection.items() + + def valuesview(collection): + return collection.values() + + def keysview(collection): + return collection.keys() + + urllib.quote = parse.quote + urllib.quote_plus = parse.quote_plus + urllib.unquote = parse.unquote + urllib.unquote_plus = parse.unquote_plus + urllib.urlencode = parse.urlencode + execute = getattr(builtins, 'exec') + if VERSION[1] < 2: + def callable(entity): + return hasattr(entity, '__call__') + common.append('callable') + + __all__ = common + ['urllib'] +else: + from itertools import ifilter as filter + from itertools import imap as map + from itertools import izip as zip + from decimal import Decimal, ROUND_HALF_EVEN + + import codecs + str = unicode + chr = unichr + input = raw_input + range = xrange + integer_types = (int, long) + + import sys + stdout = sys.stdout + stderr = sys.stderr +# reload(sys) +# sys.stdout = stdout +# sys.stderr = stderr +# sys.setdefaultencoding('utf-8') + + def _create_not_allowed(name): + def _not_allow(*args, **kwargs): + raise NameError("name '{0}' is not defined".format(name)) + _not_allow.__name__ = name + return _not_allow + + for removed in ('apply', 'cmp', 'coerce', 'execfile', 'raw_input', 'unpacks'): + globals()[removed] = _create_not_allowed(removed) + + def u(s): + if isinstance(s, unicode): + return s + else: + return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") + + def execute(_code_, _globs_=None, _locs_=None): + """Execute code in a namespace.""" + if _globs_ is None: + frame = sys._getframe(1) + _globs_ = frame.f_globals + if _locs_ is None: + _locs_ = frame.f_locals + del frame + elif _locs_ is None: + _locs_ = _globs_ + exec("""exec _code_ in _globs_, _locs_""") + + class _dict_view_base(object): + __slots__ = ('_dictionary', ) + + def __init__(self, dictionary): + self._dictionary = dictionary + + def __repr__(self): + return "{0}({1})".format(self.__class__.__name__, str(list(self.__iter__()))) + + def __unicode__(self): + return str(self.__repr__()) + + def __str__(self): + return str(self.__unicode__()) + + class dict_keys(_dict_view_base): + __slots__ = () + + def __iter__(self): + return self._dictionary.iterkeys() + + class dict_values(_dict_view_base): + __slots__ = () + + def __iter__(self): + return self._dictionary.itervalues() + + class dict_items(_dict_view_base): + __slots__ = () + + def __iter__(self): + return self._dictionary.iteritems() + + def itemsview(collection): + return dict_items(collection) + + def valuesview(collection): + return dict_values(collection) + + def keysview(collection): + return dict_keys(collection) + + class dict(unmodified_isinstance(native_dict)): + def has_key(self, *args, **kwargs): + return AttributeError("'dict' object has no attribute 'has_key'") + + def items(self): + return dict_items(self) + + def keys(self): + return dict_keys(self) + + def values(self): + return dict_values(self) + + def round(number, ndigits=None): + return_int = False + if ndigits is None: + return_int = True + ndigits = 0 + if hasattr(number, '__round__'): + return number.__round__(ndigits) + + if ndigits < 0: + raise NotImplementedError('negative ndigits not supported yet') + exponent = Decimal('10') ** (-ndigits) + d = Decimal.from_float(number).quantize(exponent, + rounding=ROUND_HALF_EVEN) + if return_int: + return int(d) + else: + return float(d) + + def next(iterator): + try: + iterator.__next__() + except Exception: + native_next(iterator) + + class FixStr(type): + def __new__(cls, name, bases, dct): + if '__str__' in dct: + dct['__unicode__'] = dct['__str__'] + dct['__str__'] = lambda self: self.__unicode__().encode('utf-8') + return type.__new__(cls, name, bases, dct) + + if sys.version_info[1] <= 6: + def __instancecheck__(cls, instance): + if cls.__name__ == "object": + return isinstance(instance, native_object) + + subclass = getattr(instance, '__class__', None) + subtype = type(instance) + instance_type = getattr(abc, '_InstanceType', None) + if not instance_type: + class test_object: + pass + instance_type = type(test_object) + if subtype is instance_type: + subtype = subclass + if subtype is subclass or subclass is None: + return cls.__subclasscheck__(subtype) + return (cls.__subclasscheck__(subclass) or cls.__subclasscheck__(subtype)) + else: + def __instancecheck__(cls, instance): + if cls.__name__ == "object": + return isinstance(instance, native_object) + return type.__instancecheck__(cls, instance) + + class object(with_metaclass(FixStr, object)): + pass + + __all__ = common + ['round', 'dict', 'apply', 'cmp', 'coerce', 'execfile', 'raw_input', 'unpacks', 'str', 'chr', + 'input', 'range', 'filter', 'map', 'zip', 'object'] + +if sys.version_info[0] == 2 and sys.version_info[1] < 7: + # OrderedDict + # Copyright (c) 2009 Raymond Hettinger + # + # Permission is hereby granted, free of charge, to any person + # obtaining a copy of this software and associated documentation files + # (the "Software"), to deal in the Software without restriction, + # including without limitation the rights to use, copy, modify, merge, + # publish, distribute, sublicense, and/or sell copies of the Software, + # and to permit persons to whom the Software is furnished to do so, + # subject to the following conditions: + # + # The above copyright notice and this permission notice shall be + # included in all copies or substantial portions of the Software. + # + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + # OTHER DEALINGS IN THE SOFTWARE. + + from UserDict import DictMixin + + class OrderedDict(dict, DictMixin): + + def __init__(self, *args, **kwds): + if len(args) > 1: + raise TypeError('expected at most 1 arguments, got %d' % len(args)) + try: + self.__end + except AttributeError: + self.clear() + self.update(*args, **kwds) + + def clear(self): + self.__end = end = [] + end += [None, end, end] # sentinel node for doubly linked list + self.__map = {} # key --> [key, prev, next] + dict.clear(self) + + def __setitem__(self, key, value): + if key not in self: + end = self.__end + curr = end[1] + curr[2] = end[1] = self.__map[key] = [key, curr, end] + dict.__setitem__(self, key, value) + + def __delitem__(self, key): + dict.__delitem__(self, key) + key, prev, next = self.__map.pop(key) + prev[2] = next + next[1] = prev + + def __iter__(self): + end = self.__end + curr = end[2] + while curr is not end: + yield curr[0] + curr = curr[2] + + def __reversed__(self): + end = self.__end + curr = end[1] + while curr is not end: + yield curr[0] + curr = curr[1] + + def popitem(self, last=True): + if not self: + raise KeyError('dictionary is empty') + if last: + key = reversed(self).next() + else: + key = iter(self).next() + value = self.pop(key) + return key, value + + def __reduce__(self): + items = [[k, self[k]] for k in self] + tmp = self.__map, self.__end + del self.__map, self.__end + inst_dict = vars(self).copy() + self.__map, self.__end = tmp + if inst_dict: + return (self.__class__, (items,), inst_dict) + return self.__class__, (items,) + + def keys(self): + return list(self) + + setdefault = DictMixin.setdefault + update = DictMixin.update + pop = DictMixin.pop + values = DictMixin.values + items = DictMixin.items + iterkeys = DictMixin.iterkeys + itervalues = DictMixin.itervalues + iteritems = DictMixin.iteritems + + def __repr__(self): + if not self: + return '%s()' % (self.__class__.__name__,) + return '%s(%r)' % (self.__class__.__name__, self.items()) + + def copy(self): + return self.__class__(self) + + @classmethod + def fromkeys(cls, iterable, value=None): + d = cls() + for key in iterable: + d[key] = value + return d + + def __eq__(self, other): + if isinstance(other, OrderedDict): + if len(self) != len(other): + return False + for p, q in zip(self.items(), other.items()): + if p != q: + return False + return True + return dict.__eq__(self, other) + + def __ne__(self, other): + return not self == other +else: + from collections import OrderedDict + + +if sys.version_info < (3, 2): + try: + from threading import Lock + except ImportError: + from dummy_threading import Lock + + from functools import wraps + + def lru_cache(maxsize=100): + """Least-recently-used cache decorator. + Taking from: https://github.com/MiCHiLU/python-functools32/blob/master/functools32/functools32.py + with slight modifications. + If *maxsize* is set to None, the LRU features are disabled and the cache + can grow without bound. + Arguments to the cached function must be hashable. + View the cache statistics named tuple (hits, misses, maxsize, currsize) with + f.cache_info(). Clear the cache and statistics with f.cache_clear(). + Access the underlying function with f.__wrapped__. + See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used + + """ + def decorating_function(user_function, tuple=tuple, sorted=sorted, len=len, KeyError=KeyError): + hits, misses = [0], [0] + kwd_mark = (object(),) # separates positional and keyword args + lock = Lock() + + if maxsize is None: + CACHE = dict() + + @wraps(user_function) + def wrapper(*args, **kwds): + key = args + if kwds: + key += kwd_mark + tuple(sorted(kwds.items())) + try: + result = CACHE[key] + hits[0] += 1 + return result + except KeyError: + pass + result = user_function(*args, **kwds) + CACHE[key] = result + misses[0] += 1 + return result + else: + CACHE = OrderedDict() + + @wraps(user_function) + def wrapper(*args, **kwds): + key = args + if kwds: + key += kwd_mark + tuple(sorted(kwds.items())) + with lock: + cached = CACHE.get(key, None) + if cached: + del CACHE[key] + CACHE[key] = cached + hits[0] += 1 + return cached + result = user_function(*args, **kwds) + with lock: + CACHE[key] = result # record recent use of this key + misses[0] += 1 + while len(CACHE) > maxsize: + CACHE.popitem(last=False) + return result + + def cache_info(): + """Report CACHE statistics.""" + with lock: + return _CacheInfo(hits[0], misses[0], maxsize, len(CACHE)) + + def cache_clear(): + """Clear the CACHE and CACHE statistics.""" + with lock: + CACHE.clear() + hits[0] = misses[0] = 0 + + wrapper.cache_info = cache_info + wrapper.cache_clear = cache_clear + return wrapper + + return decorating_function + +else: + from functools import lru_cache + + +class OrderedSet(collections.MutableSet): + + def __init__(self, iterable=None): + self.end = end = [] + end += [None, end, end] + self.map = {} + if iterable is not None: + self |= iterable + + def __len__(self): + return len(self.map) + + def __contains__(self, key): + return key in self.map + + def add(self, key): + if key not in self.map: + end = self.end + curr = end[1] + curr[2] = end[1] = self.map[key] = [key, curr, end] + + def discard(self, key): + if key in self.map: + key, prev, next = self.map.pop(key) + prev[2] = next + next[1] = prev + + def __iter__(self): + end = self.end + curr = end[2] + while curr is not end: + yield curr[0] + curr = curr[2] + + def __reversed__(self): + end = self.end + curr = end[1] + while curr is not end: + yield curr[0] + curr = curr[1] + + def pop(self, last=True): + if not self: + raise KeyError('set is empty') + key = self.end[1][0] if last else self.end[2][0] + self.discard(key) + return key + + def __repr__(self): + if not self: + return '%s()' % (self.__class__.__name__,) + return '%s(%r)' % (self.__class__.__name__, list(self)) + + def __eq__(self, other): + if isinstance(other, OrderedSet): + return len(self) == len(other) and list(self) == list(other) + return set(self) == set(other) + + def update(self, other): + for item in other: + self.add(item) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/pylama_isort.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/pylama_isort.py new file mode 100644 index 0000000..6fa235f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/pylama_isort.py @@ -0,0 +1,29 @@ +import os +import sys + +from pylama.lint import Linter as BaseLinter + +from .isort import SortImports + + +class Linter(BaseLinter): + + def allow(self, path): + """Determine if this path should be linted.""" + return path.endswith('.py') + + def run(self, path, **meta): + """Lint the file. Return an array of error dicts if appropriate.""" + with open(os.devnull, 'w') as devnull: + # Suppress isort messages + sys.stdout = devnull + + if SortImports(path, check=True).incorrectly_sorted: + return [{ + 'lnum': 0, + 'col': 0, + 'text': 'Incorrectly sorted imports.', + 'type': 'ISORT' + }] + else: + return [] diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/settings.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/settings.py new file mode 100644 index 0000000..15cdb21 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/isort_container/isort/settings.py @@ -0,0 +1,256 @@ +"""isort/settings.py. + +Defines how the default settings for isort should be loaded + +(First from the default setting dictionary at the top of the file, then overridden by any settings + in ~/.isort.cfg if there are any) + +Copyright (C) 2013 Timothy Edmund Crosley + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +""" +from __future__ import absolute_import, division, print_function, unicode_literals + +import fnmatch +import os +import posixpath +from collections import namedtuple + +from .pie_slice import itemsview, lru_cache, native_str + +try: + import configparser +except ImportError: + import ConfigParser as configparser + +MAX_CONFIG_SEARCH_DEPTH = 25 # The number of parent directories isort will look for a config file within +DEFAULT_SECTIONS = ('FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER') + +WrapModes = ('GRID', 'VERTICAL', 'HANGING_INDENT', 'VERTICAL_HANGING_INDENT', 'VERTICAL_GRID', 'VERTICAL_GRID_GROUPED', 'NOQA') +WrapModes = namedtuple('WrapModes', WrapModes)(*range(len(WrapModes))) + +# Note that none of these lists must be complete as they are simply fallbacks for when included auto-detection fails. +default = {'force_to_top': [], + 'skip': ['__init__.py', ], + 'skip_glob': [], + 'line_length': 79, + 'wrap_length': 0, + 'sections': DEFAULT_SECTIONS, + 'no_sections': False, + 'known_future_library': ['__future__'], + 'known_standard_library': ['AL', 'BaseHTTPServer', 'Bastion', 'CGIHTTPServer', 'Carbon', 'ColorPicker', + 'ConfigParser', 'Cookie', 'DEVICE', 'DocXMLRPCServer', 'EasyDialogs', 'FL', + 'FrameWork', 'GL', 'HTMLParser', 'MacOS', 'MimeWriter', 'MiniAEFrame', 'Nav', + 'PixMapWrapper', 'Queue', 'SUNAUDIODEV', 'ScrolledText', 'SimpleHTTPServer', + 'SimpleXMLRPCServer', 'SocketServer', 'StringIO', 'Tix', 'Tkinter', 'UserDict', + 'UserList', 'UserString', 'W', '__builtin__', 'abc', 'aepack', 'aetools', + 'aetypes', 'aifc', 'al', 'anydbm', 'applesingle', 'argparse', 'array', 'ast', + 'asynchat', 'asyncio', 'asyncore', 'atexit', 'audioop', 'autoGIL', 'base64', + 'bdb', 'binascii', 'binhex', 'bisect', 'bsddb', 'buildtools', 'builtins', + 'bz2', 'cPickle', 'cProfile', 'cStringIO', 'calendar', 'cd', 'cfmfile', 'cgi', + 'cgitb', 'chunk', 'cmath', 'cmd', 'code', 'codecs', 'codeop', 'collections', + 'colorsys', 'commands', 'compileall', 'compiler', 'concurrent', 'configparser', + 'contextlib', 'cookielib', 'copy', 'copy_reg', 'copyreg', 'crypt', 'csv', + 'ctypes', 'curses', 'datetime', 'dbhash', 'dbm', 'decimal', 'difflib', + 'dircache', 'dis', 'distutils', 'dl', 'doctest', 'dumbdbm', 'dummy_thread', + 'dummy_threading', 'email', 'encodings', 'ensurepip', 'enum', 'errno', + 'exceptions', 'faulthandler', 'fcntl', 'filecmp', 'fileinput', 'findertools', + 'fl', 'flp', 'fm', 'fnmatch', 'formatter', 'fpectl', 'fpformat', 'fractions', + 'ftplib', 'functools', 'future_builtins', 'gc', 'gdbm', 'gensuitemodule', + 'getopt', 'getpass', 'gettext', 'gl', 'glob', 'grp', 'gzip', 'hashlib', + 'heapq', 'hmac', 'hotshot', 'html', 'htmlentitydefs', 'htmllib', 'http', + 'httplib', 'ic', 'icopen', 'imageop', 'imaplib', 'imgfile', 'imghdr', 'imp', + 'importlib', 'imputil', 'inspect', 'io', 'ipaddress', 'itertools', 'jpeg', + 'json', 'keyword', 'lib2to3', 'linecache', 'locale', 'logging', 'lzma', + 'macerrors', 'macostools', 'macpath', 'macresource', 'mailbox', 'mailcap', + 'marshal', 'math', 'md5', 'mhlib', 'mimetools', 'mimetypes', 'mimify', 'mmap', + 'modulefinder', 'msilib', 'msvcrt', 'multifile', 'multiprocessing', 'mutex', + 'netrc', 'new', 'nis', 'nntplib', 'numbers', 'operator', 'optparse', 'os', + 'ossaudiodev', 'parser', 'pathlib', 'pdb', 'pickle', 'pickletools', 'pipes', + 'pkgutil', 'platform', 'plistlib', 'popen2', 'poplib', 'posix', 'posixfile', + 'pprint', 'profile', 'pstats', 'pty', 'pwd', 'py_compile', 'pyclbr', 'pydoc', + 'queue', 'quopri', 'random', 're', 'readline', 'reprlib', 'resource', 'rexec', + 'rfc822', 'rlcompleter', 'robotparser', 'runpy', 'sched', 'secrets', 'select', + 'selectors', 'sets', 'sgmllib', 'sha', 'shelve', 'shlex', 'shutil', 'signal', + 'site', 'sitecustomize', 'smtpd', 'smtplib', 'sndhdr', 'socket', 'socketserver', + 'spwd', 'sqlite3', 'ssl', 'stat', 'statistics', 'statvfs', 'string', 'stringprep', + 'struct', 'subprocess', 'sunau', 'sunaudiodev', 'symbol', 'symtable', 'sys', + 'sysconfig', 'syslog', 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'termios', + 'test', 'textwrap', 'this', 'thread', 'threading', 'time', 'timeit', 'tkinter', + 'token', 'tokenize', 'trace', 'traceback', 'tracemalloc', 'ttk', 'tty', 'turtle', + 'turtledemo', 'types', 'typing', 'unicodedata', 'unittest', 'urllib', 'urllib2', + 'urlparse', 'user', 'usercustomize', 'uu', 'uuid', 'venv', 'videoreader', + 'warnings', 'wave', 'weakref', 'webbrowser', 'whichdb', 'winreg', 'winsound', + 'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'xmlrpclib', 'zipapp', 'zipfile', + 'zipimport', 'zlib'], + 'known_third_party': ['google.appengine.api'], + 'known_first_party': [], + 'multi_line_output': WrapModes.GRID, + 'forced_separate': [], + 'indent': ' ' * 4, + 'length_sort': False, + 'add_imports': [], + 'remove_imports': [], + 'force_single_line': False, + 'default_section': 'FIRSTPARTY', + 'import_heading_future': '', + 'import_heading_stdlib': '', + 'import_heading_thirdparty': '', + 'import_heading_firstparty': '', + 'import_heading_localfolder': '', + 'balanced_wrapping': False, + 'use_parentheses': False, + 'order_by_type': True, + 'atomic': False, + 'lines_after_imports': -1, + 'lines_between_sections': 1, + 'lines_between_types': 0, + 'combine_as_imports': False, + 'combine_star': False, + 'include_trailing_comma': False, + 'from_first': False, + 'verbose': False, + 'quiet': False, + 'force_adds': False, + 'force_alphabetical_sort_within_sections': False, + 'force_alphabetical_sort': False, + 'force_grid_wrap': 0, + 'force_sort_within_sections': False, + 'show_diff': False, + 'ignore_whitespace': False} + + +@lru_cache() +def from_path(path): + computed_settings = default.copy() + _update_settings_with_config(path, '.editorconfig', '~/.editorconfig', ('*', '*.py', '**.py'), computed_settings) + _update_settings_with_config(path, '.isort.cfg', '~/.isort.cfg', ('settings', 'isort'), computed_settings) + _update_settings_with_config(path, 'setup.cfg', None, ('isort', ), computed_settings) + _update_settings_with_config(path, 'tox.ini', None, ('isort', ), computed_settings) + return computed_settings + + +def _update_settings_with_config(path, name, default, sections, computed_settings): + editor_config_file = default and os.path.expanduser(default) + tries = 0 + current_directory = path + while current_directory and tries < MAX_CONFIG_SEARCH_DEPTH: + potential_path = os.path.join(current_directory, native_str(name)) + if os.path.exists(potential_path): + editor_config_file = potential_path + break + + new_directory = os.path.split(current_directory)[0] + if current_directory == new_directory: + break + current_directory = new_directory + tries += 1 + + if editor_config_file and os.path.exists(editor_config_file): + _update_with_config_file(editor_config_file, sections, computed_settings) + + +def _update_with_config_file(file_path, sections, computed_settings): + settings = _get_config_data(file_path, sections).copy() + if not settings: + return + + if file_path.endswith('.editorconfig'): + indent_style = settings.pop('indent_style', '').strip() + indent_size = settings.pop('indent_size', '').strip() + if indent_style == 'space': + computed_settings['indent'] = ' ' * (indent_size and int(indent_size) or 4) + elif indent_style == 'tab': + computed_settings['indent'] = '\t' * (indent_size and int(indent_size) or 1) + + max_line_length = settings.pop('max_line_length', '').strip() + if max_line_length: + computed_settings['line_length'] = float('inf') if max_line_length == 'off' else int(max_line_length) + + for key, value in itemsview(settings): + access_key = key.replace('not_', '').lower() + existing_value_type = type(default.get(access_key, '')) + if existing_value_type in (list, tuple): + # sections has fixed order values; no adding or substraction from any set + if access_key == 'sections': + computed_settings[access_key] = tuple(_as_list(value)) + else: + existing_data = set(computed_settings.get(access_key, default.get(access_key))) + if key.startswith('not_'): + computed_settings[access_key] = list(existing_data.difference(_as_list(value))) + else: + computed_settings[access_key] = list(existing_data.union(_as_list(value))) + elif existing_value_type == bool and value.lower().strip() == 'false': + computed_settings[access_key] = False + elif key.startswith('known_'): + computed_settings[access_key] = list(_as_list(value)) + elif key == 'force_grid_wrap': + try: + result = existing_value_type(value) + except ValueError: + # backwards compat + result = default.get(access_key) if value.lower().strip() == 'false' else 2 + computed_settings[access_key] = result + else: + computed_settings[access_key] = existing_value_type(value) + + +def _as_list(value): + return filter(bool, [item.strip() for item in value.replace('\n', ',').split(',')]) + + +@lru_cache() +def _get_config_data(file_path, sections): + with open(file_path, 'rU') as config_file: + if file_path.endswith('.editorconfig'): + line = '\n' + last_position = config_file.tell() + while line: + line = config_file.readline() + if '[' in line: + config_file.seek(last_position) + break + last_position = config_file.tell() + + config = configparser.SafeConfigParser() + config.readfp(config_file) + settings = dict() + for section in sections: + if config.has_section(section): + settings.update(dict(config.items(section))) + + return settings + + return {} + + +def should_skip(filename, config, path='/'): + """Returns True if the file should be skipped based on the passed in settings.""" + for skip_path in config['skip']: + if posixpath.abspath(posixpath.join(path, filename)) == posixpath.abspath(skip_path.replace('\\', '/')): + return True + + position = os.path.split(filename) + while position[1]: + if position[1] in config['skip']: + return True + position = os.path.split(position[0]) + + for glob in config['skip_glob']: + if fnmatch.fnmatch(filename, glob): + return True + + return False diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/autopep8.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/autopep8.py new file mode 100644 index 0000000..7b66d30 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/autopep8.py @@ -0,0 +1,3827 @@ +#!/usr/bin/env python + +# Copyright (C) 2010-2011 Hideo Hattori +# Copyright (C) 2011-2013 Hideo Hattori, Steven Myint +# Copyright (C) 2013-2016 Hideo Hattori, Steven Myint, Bill Wendling +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +"""Automatically formats Python code to conform to the PEP 8 style guide. + +Fixes that only need be done once can be added by adding a function of the form +"fix_(source)" to this module. They should return the fixed source code. +These fixes are picked up by apply_global_fixes(). + +Fixes that depend on pycodestyle should be added as methods to FixPEP8. See the +class documentation for more information. + +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import codecs +import collections +import copy +import difflib +import fnmatch +import inspect +import io +import keyword +import locale +import os +import re +import signal +import sys +import textwrap +import token +import tokenize + +import pycodestyle + +def check_lib2to3(): + try: + import lib2to3 + except ImportError: + sys.path.append(os.path.join(os.path.dirname(__file__), 'lib2to3')) + import lib2to3 + + + +try: + unicode +except NameError: + unicode = str + + +__version__ = '1.3' + + +CR = '\r' +LF = '\n' +CRLF = '\r\n' + + +PYTHON_SHEBANG_REGEX = re.compile(r'^#!.*\bpython[23]?\b\s*$') +LAMBDA_REGEX = re.compile(r'([\w.]+)\s=\slambda\s*([\(\)\w,\s.]*):') +COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+([^][)(}{]+)\s+(in|is)\s') +BARE_EXCEPT_REGEX = re.compile(r'except\s*:') +STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)\s.*\):') + + +# For generating line shortening candidates. +SHORTEN_OPERATOR_GROUPS = frozenset([ + frozenset([',']), + frozenset(['%']), + frozenset([',', '(', '[', '{']), + frozenset(['%', '(', '[', '{']), + frozenset([',', '(', '[', '{', '%', '+', '-', '*', '/', '//']), + frozenset(['%', '+', '-', '*', '/', '//']), +]) + + +DEFAULT_IGNORE = 'E24,W503' +DEFAULT_INDENT_SIZE = 4 + + +# W602 is handled separately due to the need to avoid "with_traceback". +CODE_TO_2TO3 = { + 'E231': ['ws_comma'], + 'E721': ['idioms'], + 'W601': ['has_key'], + 'W603': ['ne'], + 'W604': ['repr'], + 'W690': ['apply', + 'except', + 'exitfunc', + 'numliterals', + 'operator', + 'paren', + 'reduce', + 'renames', + 'standarderror', + 'sys_exc', + 'throw', + 'tuple_params', + 'xreadlines']} + + +if sys.platform == 'win32': # pragma: no cover + DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') +else: + DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or + os.path.expanduser('~/.config'), 'pep8') +PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8') + + +MAX_PYTHON_FILE_DETECTION_BYTES = 1024 + + +def open_with_encoding(filename, + encoding=None, mode='r', limit_byte_check=-1): + """Return opened file with a specific encoding.""" + if not encoding: + encoding = detect_encoding(filename, limit_byte_check=limit_byte_check) + + return io.open(filename, mode=mode, encoding=encoding, + newline='') # Preserve line endings + + +def detect_encoding(filename, limit_byte_check=-1): + """Return file encoding.""" + try: + with open(filename, 'rb') as input_file: + from lib2to3.pgen2 import tokenize as lib2to3_tokenize + encoding = lib2to3_tokenize.detect_encoding(input_file.readline)[0] + + with open_with_encoding(filename, encoding) as test_file: + test_file.read(limit_byte_check) + + return encoding + except (LookupError, SyntaxError, UnicodeDecodeError): + return 'latin-1' + + +def readlines_from_file(filename): + """Return contents of file.""" + with open_with_encoding(filename) as input_file: + return input_file.readlines() + + +def extended_blank_lines(logical_line, + blank_lines, + blank_before, + indent_level, + previous_logical): + """Check for missing blank lines after class declaration.""" + if previous_logical.startswith('def '): + if blank_lines and pycodestyle.DOCSTRING_REGEX.match(logical_line): + yield (0, 'E303 too many blank lines ({0})'.format(blank_lines)) + elif pycodestyle.DOCSTRING_REGEX.match(previous_logical): + # Missing blank line between class docstring and method declaration. + if ( + indent_level and + not blank_lines and + not blank_before and + logical_line.startswith(('def ')) and + '(self' in logical_line + ): + yield (0, 'E301 expected 1 blank line, found 0') + + +pycodestyle.register_check(extended_blank_lines) + + +def continued_indentation(logical_line, tokens, indent_level, indent_char, + noqa): + """Override pycodestyle's function to provide indentation information.""" + first_row = tokens[0][2][0] + nrows = 1 + tokens[-1][2][0] - first_row + if noqa or nrows == 1: + return + + # indent_next tells us whether the next block is indented. Assuming + # that it is indented by 4 spaces, then we should not allow 4-space + # indents on the final continuation line. In turn, some other + # indents are allowed to have an extra 4 spaces. + indent_next = logical_line.endswith(':') + + row = depth = 0 + valid_hangs = ( + (DEFAULT_INDENT_SIZE,) + if indent_char != '\t' else (DEFAULT_INDENT_SIZE, + 2 * DEFAULT_INDENT_SIZE) + ) + + # Remember how many brackets were opened on each line. + parens = [0] * nrows + + # Relative indents of physical lines. + rel_indent = [0] * nrows + + # For each depth, collect a list of opening rows. + open_rows = [[0]] + # For each depth, memorize the hanging indentation. + hangs = [None] + + # Visual indents. + indent_chances = {} + last_indent = tokens[0][2] + indent = [last_indent[1]] + + last_token_multiline = None + line = None + last_line = '' + last_line_begins_with_multiline = False + for token_type, text, start, end, line in tokens: + + newline = row < start[0] - first_row + if newline: + row = start[0] - first_row + newline = (not last_token_multiline and + token_type not in (tokenize.NL, tokenize.NEWLINE)) + last_line_begins_with_multiline = last_token_multiline + + if newline: + # This is the beginning of a continuation line. + last_indent = start + + # Record the initial indent. + rel_indent[row] = pycodestyle.expand_indent(line) - indent_level + + # Identify closing bracket. + close_bracket = (token_type == tokenize.OP and text in ']})') + + # Is the indent relative to an opening bracket line? + for open_row in reversed(open_rows[depth]): + hang = rel_indent[row] - rel_indent[open_row] + hanging_indent = hang in valid_hangs + if hanging_indent: + break + if hangs[depth]: + hanging_indent = (hang == hangs[depth]) + + visual_indent = (not close_bracket and hang > 0 and + indent_chances.get(start[1])) + + if close_bracket and indent[depth]: + # Closing bracket for visual indent. + if start[1] != indent[depth]: + yield (start, 'E124 {0}'.format(indent[depth])) + elif close_bracket and not hang: + pass + elif indent[depth] and start[1] < indent[depth]: + # Visual indent is broken. + yield (start, 'E128 {0}'.format(indent[depth])) + elif (hanging_indent or + (indent_next and + rel_indent[row] == 2 * DEFAULT_INDENT_SIZE)): + # Hanging indent is verified. + if close_bracket: + yield (start, 'E123 {0}'.format(indent_level + + rel_indent[open_row])) + hangs[depth] = hang + elif visual_indent is True: + # Visual indent is verified. + indent[depth] = start[1] + elif visual_indent in (text, unicode): + # Ignore token lined up with matching one from a previous line. + pass + else: + one_indented = (indent_level + rel_indent[open_row] + + DEFAULT_INDENT_SIZE) + # Indent is broken. + if hang <= 0: + error = ('E122', one_indented) + elif indent[depth]: + error = ('E127', indent[depth]) + elif not close_bracket and hangs[depth]: + error = ('E131', one_indented) + elif hang > DEFAULT_INDENT_SIZE: + error = ('E126', one_indented) + else: + hangs[depth] = hang + error = ('E121', one_indented) + + yield (start, '{0} {1}'.format(*error)) + + # Look for visual indenting. + if ( + parens[row] and + token_type not in (tokenize.NL, tokenize.COMMENT) and + not indent[depth] + ): + indent[depth] = start[1] + indent_chances[start[1]] = True + # Deal with implicit string concatenation. + elif (token_type in (tokenize.STRING, tokenize.COMMENT) or + text in ('u', 'ur', 'b', 'br')): + indent_chances[start[1]] = unicode + # Special case for the "if" statement because len("if (") is equal to + # 4. + elif not indent_chances and not row and not depth and text == 'if': + indent_chances[end[1] + 1] = True + elif text == ':' and line[end[1]:].isspace(): + open_rows[depth].append(row) + + # Keep track of bracket depth. + if token_type == tokenize.OP: + if text in '([{': + depth += 1 + indent.append(0) + hangs.append(None) + if len(open_rows) == depth: + open_rows.append([]) + open_rows[depth].append(row) + parens[row] += 1 + elif text in ')]}' and depth > 0: + # Parent indents should not be more than this one. + prev_indent = indent.pop() or last_indent[1] + hangs.pop() + for d in range(depth): + if indent[d] > prev_indent: + indent[d] = 0 + for ind in list(indent_chances): + if ind >= prev_indent: + del indent_chances[ind] + del open_rows[depth + 1:] + depth -= 1 + if depth: + indent_chances[indent[depth]] = True + for idx in range(row, -1, -1): + if parens[idx]: + parens[idx] -= 1 + break + assert len(indent) == depth + 1 + if ( + start[1] not in indent_chances and + # This is for purposes of speeding up E121 (GitHub #90). + not last_line.rstrip().endswith(',') + ): + # Allow to line up tokens. + indent_chances[start[1]] = text + + last_token_multiline = (start[0] != end[0]) + if last_token_multiline: + rel_indent[end[0] - first_row] = rel_indent[row] + + last_line = line + + if ( + indent_next and + not last_line_begins_with_multiline and + pycodestyle.expand_indent(line) == indent_level + DEFAULT_INDENT_SIZE + ): + pos = (start[0], indent[0] + 4) + desired_indent = indent_level + 2 * DEFAULT_INDENT_SIZE + if visual_indent: + yield (pos, 'E129 {0}'.format(desired_indent)) + else: + yield (pos, 'E125 {0}'.format(desired_indent)) + + +del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation] +pycodestyle.register_check(continued_indentation) + + +class FixPEP8(object): + + """Fix invalid code. + + Fixer methods are prefixed "fix_". The _fix_source() method looks for these + automatically. + + The fixer method can take either one or two arguments (in addition to + self). The first argument is "result", which is the error information from + pycodestyle. The second argument, "logical", is required only for + logical-line fixes. + + The fixer method can return the list of modified lines or None. An empty + list would mean that no changes were made. None would mean that only the + line reported in the pycodestyle error was modified. Note that the modified + line numbers that are returned are indexed at 1. This typically would + correspond with the line number reported in the pycodestyle error + information. + + [fixed method list] + - e111,e114,e115,e116 + - e121,e122,e123,e124,e125,e126,e127,e128,e129 + - e201,e202,e203 + - e211 + - e221,e222,e223,e224,e225 + - e231 + - e251 + - e261,e262 + - e271,e272,e273,e274 + - e301,e302,e303,e304,e306 + - e401 + - e502 + - e701,e702,e703,e704 + - e711,e712,e713,e714 + - e722 + - e731 + - w291 + - w503 + + """ + + def __init__(self, filename, + options, + contents=None, + long_line_ignore_cache=None): + self.filename = filename + if contents is None: + self.source = readlines_from_file(filename) + else: + sio = io.StringIO(contents) + self.source = sio.readlines() + self.options = options + self.indent_word = _get_indentword(''.join(self.source)) + + self.long_line_ignore_cache = ( + set() if long_line_ignore_cache is None + else long_line_ignore_cache) + + # Many fixers are the same even though pycodestyle categorizes them + # differently. + self.fix_e115 = self.fix_e112 + self.fix_e116 = self.fix_e113 + self.fix_e121 = self._fix_reindent + self.fix_e122 = self._fix_reindent + self.fix_e123 = self._fix_reindent + self.fix_e124 = self._fix_reindent + self.fix_e126 = self._fix_reindent + self.fix_e127 = self._fix_reindent + self.fix_e128 = self._fix_reindent + self.fix_e129 = self._fix_reindent + self.fix_e202 = self.fix_e201 + self.fix_e203 = self.fix_e201 + self.fix_e211 = self.fix_e201 + self.fix_e221 = self.fix_e271 + self.fix_e222 = self.fix_e271 + self.fix_e223 = self.fix_e271 + self.fix_e226 = self.fix_e225 + self.fix_e227 = self.fix_e225 + self.fix_e228 = self.fix_e225 + self.fix_e241 = self.fix_e271 + self.fix_e242 = self.fix_e224 + self.fix_e261 = self.fix_e262 + self.fix_e272 = self.fix_e271 + self.fix_e273 = self.fix_e271 + self.fix_e274 = self.fix_e271 + self.fix_e306 = self.fix_e301 + self.fix_e501 = ( + self.fix_long_line_logically if + options and (options.aggressive >= 2 or options.experimental) else + self.fix_long_line_physically) + self.fix_e703 = self.fix_e702 + self.fix_w293 = self.fix_w291 + + def _fix_source(self, results): + try: + (logical_start, logical_end) = _find_logical(self.source) + logical_support = True + except (SyntaxError, tokenize.TokenError): # pragma: no cover + logical_support = False + + completed_lines = set() + for result in sorted(results, key=_priority_key): + if result['line'] in completed_lines: + continue + + fixed_methodname = 'fix_' + result['id'].lower() + if hasattr(self, fixed_methodname): + fix = getattr(self, fixed_methodname) + + line_index = result['line'] - 1 + original_line = self.source[line_index] + + is_logical_fix = len(_get_parameters(fix)) > 2 + if is_logical_fix: + logical = None + if logical_support: + logical = _get_logical(self.source, + result, + logical_start, + logical_end) + if logical and set(range( + logical[0][0] + 1, + logical[1][0] + 1)).intersection( + completed_lines): + continue + + modified_lines = fix(result, logical) + else: + modified_lines = fix(result) + + if modified_lines is None: + # Force logical fixes to report what they modified. + assert not is_logical_fix + + if self.source[line_index] == original_line: + modified_lines = [] + + if modified_lines: + completed_lines.update(modified_lines) + elif modified_lines == []: # Empty list means no fix + if self.options.verbose >= 2: + print( + '---> Not fixing {error} on line {line}'.format( + error=result['id'], line=result['line']), + file=sys.stderr) + else: # We assume one-line fix when None. + completed_lines.add(result['line']) + else: + if self.options.verbose >= 3: + print( + "---> '{0}' is not defined.".format(fixed_methodname), + file=sys.stderr) + + info = result['info'].strip() + print('---> {0}:{1}:{2}:{3}'.format(self.filename, + result['line'], + result['column'], + info), + file=sys.stderr) + + def fix(self): + """Return a version of the source code with PEP 8 violations fixed.""" + pep8_options = { + 'ignore': self.options.ignore, + 'select': self.options.select, + 'max_line_length': self.options.max_line_length, + } + results = _execute_pep8(pep8_options, self.source) + + if self.options.verbose: + progress = {} + for r in results: + if r['id'] not in progress: + progress[r['id']] = set() + progress[r['id']].add(r['line']) + print('---> {n} issue(s) to fix {progress}'.format( + n=len(results), progress=progress), file=sys.stderr) + + if self.options.line_range: + start, end = self.options.line_range + results = [r for r in results + if start <= r['line'] <= end] + + self._fix_source(filter_results(source=''.join(self.source), + results=results, + aggressive=self.options.aggressive)) + + if self.options.line_range: + # If number of lines has changed then change line_range. + count = sum(sline.count('\n') + for sline in self.source[start - 1:end]) + self.options.line_range[1] = start + count - 1 + + return ''.join(self.source) + + def _fix_reindent(self, result): + """Fix a badly indented line. + + This is done by adding or removing from its initial indent only. + + """ + num_indent_spaces = int(result['info'].split()[1]) + line_index = result['line'] - 1 + target = self.source[line_index] + + self.source[line_index] = ' ' * num_indent_spaces + target.lstrip() + + def fix_e112(self, result): + """Fix under-indented comments.""" + line_index = result['line'] - 1 + target = self.source[line_index] + + if not target.lstrip().startswith('#'): + # Don't screw with invalid syntax. + return [] + + self.source[line_index] = self.indent_word + target + + def fix_e113(self, result): + """Fix over-indented comments.""" + line_index = result['line'] - 1 + target = self.source[line_index] + + indent = _get_indentation(target) + stripped = target.lstrip() + + if not stripped.startswith('#'): + # Don't screw with invalid syntax. + return [] + + self.source[line_index] = indent[1:] + stripped + + def fix_e125(self, result): + """Fix indentation undistinguish from the next logical line.""" + num_indent_spaces = int(result['info'].split()[1]) + line_index = result['line'] - 1 + target = self.source[line_index] + + spaces_to_add = num_indent_spaces - len(_get_indentation(target)) + indent = len(_get_indentation(target)) + modified_lines = [] + + while len(_get_indentation(self.source[line_index])) >= indent: + self.source[line_index] = (' ' * spaces_to_add + + self.source[line_index]) + modified_lines.append(1 + line_index) # Line indexed at 1. + line_index -= 1 + + return modified_lines + + def fix_e131(self, result): + """Fix indentation undistinguish from the next logical line.""" + num_indent_spaces = int(result['info'].split()[1]) + line_index = result['line'] - 1 + target = self.source[line_index] + + spaces_to_add = num_indent_spaces - len(_get_indentation(target)) + + if spaces_to_add >= 0: + self.source[line_index] = (' ' * spaces_to_add + + self.source[line_index]) + else: + offset = abs(spaces_to_add) + self.source[line_index] = self.source[line_index][offset:] + + def fix_e201(self, result): + """Remove extraneous whitespace.""" + line_index = result['line'] - 1 + target = self.source[line_index] + offset = result['column'] - 1 + + fixed = fix_whitespace(target, + offset=offset, + replacement='') + + self.source[line_index] = fixed + + def fix_e224(self, result): + """Remove extraneous whitespace around operator.""" + target = self.source[result['line'] - 1] + offset = result['column'] - 1 + fixed = target[:offset] + target[offset:].replace('\t', ' ') + self.source[result['line'] - 1] = fixed + + def fix_e225(self, result): + """Fix missing whitespace around operator.""" + target = self.source[result['line'] - 1] + offset = result['column'] - 1 + fixed = target[:offset] + ' ' + target[offset:] + + # Only proceed if non-whitespace characters match. + # And make sure we don't break the indentation. + if ( + fixed.replace(' ', '') == target.replace(' ', '') and + _get_indentation(fixed) == _get_indentation(target) + ): + self.source[result['line'] - 1] = fixed + else: + return [] + + def fix_e231(self, result): + """Add missing whitespace.""" + line_index = result['line'] - 1 + target = self.source[line_index] + offset = result['column'] + fixed = target[:offset].rstrip() + ' ' + target[offset:].lstrip() + self.source[line_index] = fixed + + def fix_e251(self, result): + """Remove whitespace around parameter '=' sign.""" + line_index = result['line'] - 1 + target = self.source[line_index] + + # This is necessary since pycodestyle sometimes reports columns that + # goes past the end of the physical line. This happens in cases like, + # foo(bar\n=None) + c = min(result['column'] - 1, + len(target) - 1) + + if target[c].strip(): + fixed = target + else: + fixed = target[:c].rstrip() + target[c:].lstrip() + + # There could be an escaped newline + # + # def foo(a=\ + # 1) + if fixed.endswith(('=\\\n', '=\\\r\n', '=\\\r')): + self.source[line_index] = fixed.rstrip('\n\r \t\\') + self.source[line_index + 1] = self.source[line_index + 1].lstrip() + return [line_index + 1, line_index + 2] # Line indexed at 1 + + self.source[result['line'] - 1] = fixed + + def fix_e262(self, result): + """Fix spacing after comment hash.""" + target = self.source[result['line'] - 1] + offset = result['column'] + + code = target[:offset].rstrip(' \t#') + comment = target[offset:].lstrip(' \t#') + + fixed = code + (' # ' + comment if comment.strip() else '\n') + + self.source[result['line'] - 1] = fixed + + def fix_e271(self, result): + """Fix extraneous whitespace around keywords.""" + line_index = result['line'] - 1 + target = self.source[line_index] + offset = result['column'] - 1 + + fixed = fix_whitespace(target, + offset=offset, + replacement=' ') + + if fixed == target: + return [] + else: + self.source[line_index] = fixed + + def fix_e301(self, result): + """Add missing blank line.""" + cr = '\n' + self.source[result['line'] - 1] = cr + self.source[result['line'] - 1] + + def fix_e302(self, result): + """Add missing 2 blank lines.""" + add_linenum = 2 - int(result['info'].split()[-1]) + cr = '\n' * add_linenum + self.source[result['line'] - 1] = cr + self.source[result['line'] - 1] + + def fix_e303(self, result): + """Remove extra blank lines.""" + delete_linenum = int(result['info'].split('(')[1].split(')')[0]) - 2 + delete_linenum = max(1, delete_linenum) + + # We need to count because pycodestyle reports an offset line number if + # there are comments. + cnt = 0 + line = result['line'] - 2 + modified_lines = [] + while cnt < delete_linenum and line >= 0: + if not self.source[line].strip(): + self.source[line] = '' + modified_lines.append(1 + line) # Line indexed at 1 + cnt += 1 + line -= 1 + + return modified_lines + + def fix_e304(self, result): + """Remove blank line following function decorator.""" + line = result['line'] - 2 + if not self.source[line].strip(): + self.source[line] = '' + + def fix_e305(self, result): + """Add missing 2 blank lines after end of function or class.""" + cr = '\n' + # check comment line + offset = result['line'] - 2 + while True: + if offset < 0: + break + line = self.source[offset].lstrip() + if len(line) == 0: + break + if line[0] != '#': + break + offset -= 1 + offset += 1 + self.source[offset] = cr + self.source[offset] + + def fix_e401(self, result): + """Put imports on separate lines.""" + line_index = result['line'] - 1 + target = self.source[line_index] + offset = result['column'] - 1 + + if not target.lstrip().startswith('import'): + return [] + + indentation = re.split(pattern=r'\bimport\b', + string=target, maxsplit=1)[0] + fixed = (target[:offset].rstrip('\t ,') + '\n' + + indentation + 'import ' + target[offset:].lstrip('\t ,')) + self.source[line_index] = fixed + + def fix_long_line_logically(self, result, logical): + """Try to make lines fit within --max-line-length characters.""" + if ( + not logical or + len(logical[2]) == 1 or + self.source[result['line'] - 1].lstrip().startswith('#') + ): + return self.fix_long_line_physically(result) + + start_line_index = logical[0][0] + end_line_index = logical[1][0] + logical_lines = logical[2] + + previous_line = get_item(self.source, start_line_index - 1, default='') + next_line = get_item(self.source, end_line_index + 1, default='') + + single_line = join_logical_line(''.join(logical_lines)) + + try: + fixed = self.fix_long_line( + target=single_line, + previous_line=previous_line, + next_line=next_line, + original=''.join(logical_lines)) + except (SyntaxError, tokenize.TokenError): + return self.fix_long_line_physically(result) + + if fixed: + for line_index in range(start_line_index, end_line_index + 1): + self.source[line_index] = '' + self.source[start_line_index] = fixed + return range(start_line_index + 1, end_line_index + 1) + else: + return [] + + def fix_long_line_physically(self, result): + """Try to make lines fit within --max-line-length characters.""" + line_index = result['line'] - 1 + target = self.source[line_index] + + previous_line = get_item(self.source, line_index - 1, default='') + next_line = get_item(self.source, line_index + 1, default='') + + try: + fixed = self.fix_long_line( + target=target, + previous_line=previous_line, + next_line=next_line, + original=target) + except (SyntaxError, tokenize.TokenError): + return [] + + if fixed: + self.source[line_index] = fixed + return [line_index + 1] + else: + return [] + + def fix_long_line(self, target, previous_line, + next_line, original): + cache_entry = (target, previous_line, next_line) + if cache_entry in self.long_line_ignore_cache: + return [] + + if target.lstrip().startswith('#'): + # Wrap commented lines. + return shorten_comment( + line=target, + max_line_length=self.options.max_line_length, + last_comment=not next_line.lstrip().startswith('#')) + + fixed = get_fixed_long_line( + target=target, + previous_line=previous_line, + original=original, + indent_word=self.indent_word, + max_line_length=self.options.max_line_length, + aggressive=self.options.aggressive, + experimental=self.options.experimental, + verbose=self.options.verbose) + if fixed and not code_almost_equal(original, fixed): + return fixed + else: + self.long_line_ignore_cache.add(cache_entry) + return None + + def fix_e502(self, result): + """Remove extraneous escape of newline.""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) + self.source[line_index] = target.rstrip('\n\r \t\\') + '\n' + + def fix_e701(self, result): + """Put colon-separated compound statement on separate lines.""" + line_index = result['line'] - 1 + target = self.source[line_index] + c = result['column'] + + fixed_source = (target[:c] + '\n' + + _get_indentation(target) + self.indent_word + + target[c:].lstrip('\n\r \t\\')) + self.source[result['line'] - 1] = fixed_source + return [result['line'], result['line'] + 1] + + def fix_e702(self, result, logical): + """Put semicolon-separated compound statement on separate lines.""" + if not logical: + return [] # pragma: no cover + logical_lines = logical[2] + + line_index = result['line'] - 1 + target = self.source[line_index] + + if target.rstrip().endswith('\\'): + # Normalize '1; \\\n2' into '1; 2'. + self.source[line_index] = target.rstrip('\n \r\t\\') + self.source[line_index + 1] = self.source[line_index + 1].lstrip() + return [line_index + 1, line_index + 2] + + if target.rstrip().endswith(';'): + self.source[line_index] = target.rstrip('\n \r\t;') + '\n' + return [line_index + 1] + + offset = result['column'] - 1 + first = target[:offset].rstrip(';').rstrip() + second = (_get_indentation(logical_lines[0]) + + target[offset:].lstrip(';').lstrip()) + + # Find inline comment. + inline_comment = None + if target[offset:].lstrip(';').lstrip()[:2] == '# ': + inline_comment = target[offset:].lstrip(';') + + if inline_comment: + self.source[line_index] = first + inline_comment + else: + self.source[line_index] = first + '\n' + second + return [line_index + 1] + + def fix_e704(self, result): + """Fix multiple statements on one line def""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) + match = STARTSWITH_DEF_REGEX.match(target) + if match: + self.source[line_index] = '{0}\n{1}{2}'.format( + match.group(0), + _get_indentation(target) + self.indent_word, + target[match.end(0):].lstrip()) + + def fix_e711(self, result): + """Fix comparison with None.""" + (line_index, offset, target) = get_index_offset_contents(result, + self.source) + + right_offset = offset + 2 + if right_offset >= len(target): + return [] + + left = target[:offset].rstrip() + center = target[offset:right_offset] + right = target[right_offset:].lstrip() + + if not right.startswith('None'): + return [] + + if center.strip() == '==': + new_center = 'is' + elif center.strip() == '!=': + new_center = 'is not' + else: + return [] + + self.source[line_index] = ' '.join([left, new_center, right]) + + def fix_e712(self, result): + """Fix (trivial case of) comparison with boolean.""" + (line_index, offset, target) = get_index_offset_contents(result, + self.source) + + # Handle very easy "not" special cases. + if re.match(r'^\s*if [\w.]+ == False:$', target): + self.source[line_index] = re.sub(r'if ([\w.]+) == False:', + r'if not \1:', target, count=1) + elif re.match(r'^\s*if [\w.]+ != True:$', target): + self.source[line_index] = re.sub(r'if ([\w.]+) != True:', + r'if not \1:', target, count=1) + else: + right_offset = offset + 2 + if right_offset >= len(target): + return [] + + left = target[:offset].rstrip() + center = target[offset:right_offset] + right = target[right_offset:].lstrip() + + # Handle simple cases only. + new_right = None + if center.strip() == '==': + if re.match(r'\bTrue\b', right): + new_right = re.sub(r'\bTrue\b *', '', right, count=1) + elif center.strip() == '!=': + if re.match(r'\bFalse\b', right): + new_right = re.sub(r'\bFalse\b *', '', right, count=1) + + if new_right is None: + return [] + + if new_right[0].isalnum(): + new_right = ' ' + new_right + + self.source[line_index] = left + new_right + + def fix_e713(self, result): + """Fix (trivial case of) non-membership check.""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) + + match = COMPARE_NEGATIVE_REGEX.search(target) + if match: + if match.group(3) == 'in': + pos_start = match.start(1) + self.source[line_index] = '{0}{1} {2} {3} {4}'.format( + target[:pos_start], match.group(2), match.group(1), + match.group(3), target[match.end():]) + + def fix_e714(self, result): + """Fix object identity should be 'is not' case.""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) + + match = COMPARE_NEGATIVE_REGEX.search(target) + if match: + if match.group(3) == 'is': + pos_start = match.start(1) + self.source[line_index] = '{0}{1} {2} {3} {4}'.format( + target[:pos_start], match.group(2), match.group(3), + match.group(1), target[match.end():]) + + def fix_e722(self, result): + """fix bare except""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) + if BARE_EXCEPT_REGEX.search(target): + self.source[line_index] = '{0}{1}'.format( + target[:result['column'] - 1], "except Exception:") + + def fix_e731(self, result): + """Fix do not assign a lambda expression check.""" + (line_index, _, target) = get_index_offset_contents(result, + self.source) + match = LAMBDA_REGEX.search(target) + if match: + end = match.end() + self.source[line_index] = '{0}def {1}({2}): return {3}'.format( + target[:match.start(0)], match.group(1), match.group(2), + target[end:].lstrip()) + + def fix_w291(self, result): + """Remove trailing whitespace.""" + fixed_line = self.source[result['line'] - 1].rstrip() + self.source[result['line'] - 1] = fixed_line + '\n' + + def fix_w391(self, _): + """Remove trailing blank lines.""" + blank_count = 0 + for line in reversed(self.source): + line = line.rstrip() + if line: + break + else: + blank_count += 1 + + original_length = len(self.source) + self.source = self.source[:original_length - blank_count] + return range(1, 1 + original_length) + + def fix_w503(self, result): + (line_index, _, target) = get_index_offset_contents(result, + self.source) + one_string_token = target.split()[0] + try: + ts = generate_tokens(one_string_token) + except tokenize.TokenError: + return + if not _is_binary_operator(ts[0][0], one_string_token): + return + i = target.index(one_string_token) + self.source[line_index] = '{0}{1}'.format( + target[:i], target[i + len(one_string_token):]) + nl = find_newline(self.source[line_index - 1:line_index]) + before_line = self.source[line_index - 1] + bl = before_line.index(nl) + self.source[line_index - 1] = '{0} {1}{2}'.format( + before_line[:bl], one_string_token, + before_line[bl:]) + + +def get_index_offset_contents(result, source): + """Return (line_index, column_offset, line_contents).""" + line_index = result['line'] - 1 + return (line_index, + result['column'] - 1, + source[line_index]) + + +def get_fixed_long_line(target, previous_line, original, + indent_word=' ', max_line_length=79, + aggressive=False, experimental=False, verbose=False): + """Break up long line and return result. + + Do this by generating multiple reformatted candidates and then + ranking the candidates to heuristically select the best option. + + """ + indent = _get_indentation(target) + source = target[len(indent):] + assert source.lstrip() == source + + # Check for partial multiline. + tokens = list(generate_tokens(source)) + + candidates = shorten_line( + tokens, source, indent, + indent_word, + max_line_length, + aggressive=aggressive, + experimental=experimental, + previous_line=previous_line) + + # Also sort alphabetically as a tie breaker (for determinism). + candidates = sorted( + sorted(set(candidates).union([target, original])), + key=lambda x: line_shortening_rank( + x, + indent_word, + max_line_length, + experimental=experimental)) + + if verbose >= 4: + print(('-' * 79 + '\n').join([''] + candidates + ['']), + file=wrap_output(sys.stderr, 'utf-8')) + + if candidates: + best_candidate = candidates[0] + # Don't allow things to get longer. + if longest_line_length(best_candidate) > longest_line_length(original): + return None + else: + return best_candidate + + +def longest_line_length(code): + """Return length of longest line.""" + return max(len(line) for line in code.splitlines()) + + +def join_logical_line(logical_line): + """Return single line based on logical line input.""" + indentation = _get_indentation(logical_line) + + return indentation + untokenize_without_newlines( + generate_tokens(logical_line.lstrip())) + '\n' + + +def untokenize_without_newlines(tokens): + """Return source code based on tokens.""" + text = '' + last_row = 0 + last_column = -1 + + for t in tokens: + token_string = t[1] + (start_row, start_column) = t[2] + (end_row, end_column) = t[3] + + if start_row > last_row: + last_column = 0 + if ( + (start_column > last_column or token_string == '\n') and + not text.endswith(' ') + ): + text += ' ' + + if token_string != '\n': + text += token_string + + last_row = end_row + last_column = end_column + + return text.rstrip() + + +def _find_logical(source_lines): + # Make a variable which is the index of all the starts of lines. + logical_start = [] + logical_end = [] + last_newline = True + parens = 0 + for t in generate_tokens(''.join(source_lines)): + if t[0] in [tokenize.COMMENT, tokenize.DEDENT, + tokenize.INDENT, tokenize.NL, + tokenize.ENDMARKER]: + continue + if not parens and t[0] in [tokenize.NEWLINE, tokenize.SEMI]: + last_newline = True + logical_end.append((t[3][0] - 1, t[2][1])) + continue + if last_newline and not parens: + logical_start.append((t[2][0] - 1, t[2][1])) + last_newline = False + if t[0] == tokenize.OP: + if t[1] in '([{': + parens += 1 + elif t[1] in '}])': + parens -= 1 + return (logical_start, logical_end) + + +def _get_logical(source_lines, result, logical_start, logical_end): + """Return the logical line corresponding to the result. + + Assumes input is already E702-clean. + + """ + row = result['line'] - 1 + col = result['column'] - 1 + ls = None + le = None + for i in range(0, len(logical_start), 1): + assert logical_end + x = logical_end[i] + if x[0] > row or (x[0] == row and x[1] > col): + le = x + ls = logical_start[i] + break + if ls is None: + return None + original = source_lines[ls[0]:le[0] + 1] + return ls, le, original + + +def get_item(items, index, default=None): + if 0 <= index < len(items): + return items[index] + else: + return default + + +def reindent(source, indent_size): + """Reindent all lines.""" + reindenter = Reindenter(source) + return reindenter.run(indent_size) + + +def code_almost_equal(a, b): + """Return True if code is similar. + + Ignore whitespace when comparing specific line. + + """ + split_a = split_and_strip_non_empty_lines(a) + split_b = split_and_strip_non_empty_lines(b) + + if len(split_a) != len(split_b): + return False + + for (index, _) in enumerate(split_a): + if ''.join(split_a[index].split()) != ''.join(split_b[index].split()): + return False + + return True + + +def split_and_strip_non_empty_lines(text): + """Return lines split by newline. + + Ignore empty lines. + + """ + return [line.strip() for line in text.splitlines() if line.strip()] + + +def fix_e265(source, aggressive=False): # pylint: disable=unused-argument + """Format block comments.""" + if '#' not in source: + # Optimization. + return source + + ignored_line_numbers = multiline_string_lines( + source, + include_docstrings=True) | set(commented_out_code_lines(source)) + + fixed_lines = [] + sio = io.StringIO(source) + for (line_number, line) in enumerate(sio.readlines(), start=1): + if ( + line.lstrip().startswith('#') and + line_number not in ignored_line_numbers and + not pycodestyle.noqa(line) + ): + indentation = _get_indentation(line) + line = line.lstrip() + + # Normalize beginning if not a shebang. + if len(line) > 1: + pos = next((index for index, c in enumerate(line) + if c != '#')) + if ( + # Leave multiple spaces like '# ' alone. + (line[:pos].count('#') > 1 or line[1].isalnum()) and + # Leave stylistic outlined blocks alone. + not line.rstrip().endswith('#') + ): + line = '# ' + line.lstrip('# \t') + + fixed_lines.append(indentation + line) + else: + fixed_lines.append(line) + + return ''.join(fixed_lines) + + +def refactor(source, fixer_names, ignore=None, filename=''): + """Return refactored code using lib2to3. + + Skip if ignore string is produced in the refactored code. + + """ + check_lib2to3() + from lib2to3 import pgen2 + try: + new_text = refactor_with_2to3(source, + fixer_names=fixer_names, + filename=filename) + except (pgen2.parse.ParseError, + SyntaxError, + UnicodeDecodeError, + UnicodeEncodeError): + return source + + if ignore: + if ignore in new_text and ignore not in source: + return source + + return new_text + + +def code_to_2to3(select, ignore): + fixes = set() + for code, fix in CODE_TO_2TO3.items(): + if code_match(code, select=select, ignore=ignore): + fixes |= set(fix) + return fixes + + +def fix_2to3(source, + aggressive=True, select=None, ignore=None, filename=''): + """Fix various deprecated code (via lib2to3).""" + if not aggressive: + return source + + select = select or [] + ignore = ignore or [] + + return refactor(source, + code_to_2to3(select=select, + ignore=ignore), + filename=filename) + + +def fix_w602(source, aggressive=True): + """Fix deprecated form of raising exception.""" + if not aggressive: + return source + + return refactor(source, ['raise'], + ignore='with_traceback') + + +def find_newline(source): + """Return type of newline used in source. + + Input is a list of lines. + + """ + assert not isinstance(source, unicode) + + counter = collections.defaultdict(int) + for line in source: + if line.endswith(CRLF): + counter[CRLF] += 1 + elif line.endswith(CR): + counter[CR] += 1 + elif line.endswith(LF): + counter[LF] += 1 + + return (sorted(counter, key=counter.get, reverse=True) or [LF])[0] + + +def _get_indentword(source): + """Return indentation type.""" + indent_word = ' ' # Default in case source has no indentation + try: + for t in generate_tokens(source): + if t[0] == token.INDENT: + indent_word = t[1] + break + except (SyntaxError, tokenize.TokenError): + pass + return indent_word + + +def _get_indentation(line): + """Return leading whitespace.""" + if line.strip(): + non_whitespace_index = len(line) - len(line.lstrip()) + return line[:non_whitespace_index] + else: + return '' + + +def get_diff_text(old, new, filename): + """Return text of unified diff between old and new.""" + newline = '\n' + diff = difflib.unified_diff( + old, new, + 'original/' + filename, + 'fixed/' + filename, + lineterm=newline) + + text = '' + for line in diff: + text += line + + # Work around missing newline (http://bugs.python.org/issue2142). + if text and not line.endswith(newline): + text += newline + r'\ No newline at end of file' + newline + + return text + + +def _priority_key(pep8_result): + """Key for sorting PEP8 results. + + Global fixes should be done first. This is important for things like + indentation. + + """ + priority = [ + # Fix multiline colon-based before semicolon based. + 'e701', + # Break multiline statements early. + 'e702', + # Things that make lines longer. + 'e225', 'e231', + # Remove extraneous whitespace before breaking lines. + 'e201', + # Shorten whitespace in comment before resorting to wrapping. + 'e262' + ] + middle_index = 10000 + lowest_priority = [ + # We need to shorten lines last since the logical fixer can get in a + # loop, which causes us to exit early. + 'e501' + ] + key = pep8_result['id'].lower() + try: + return priority.index(key) + except ValueError: + try: + return middle_index + lowest_priority.index(key) + 1 + except ValueError: + return middle_index + + +def shorten_line(tokens, source, indentation, indent_word, max_line_length, + aggressive=False, experimental=False, previous_line=''): + """Separate line at OPERATOR. + + Multiple candidates will be yielded. + + """ + for candidate in _shorten_line(tokens=tokens, + source=source, + indentation=indentation, + indent_word=indent_word, + aggressive=aggressive, + previous_line=previous_line): + yield candidate + + if aggressive: + for key_token_strings in SHORTEN_OPERATOR_GROUPS: + shortened = _shorten_line_at_tokens( + tokens=tokens, + source=source, + indentation=indentation, + indent_word=indent_word, + key_token_strings=key_token_strings, + aggressive=aggressive) + + if shortened is not None and shortened != source: + yield shortened + + if experimental: + for shortened in _shorten_line_at_tokens_new( + tokens=tokens, + source=source, + indentation=indentation, + max_line_length=max_line_length): + + yield shortened + + +def _shorten_line(tokens, source, indentation, indent_word, + aggressive=False, previous_line=''): + """Separate line at OPERATOR. + + The input is expected to be free of newlines except for inside multiline + strings and at the end. + + Multiple candidates will be yielded. + + """ + for (token_type, + token_string, + start_offset, + end_offset) in token_offsets(tokens): + + if ( + token_type == tokenize.COMMENT and + not is_probably_part_of_multiline(previous_line) and + not is_probably_part_of_multiline(source) and + not source[start_offset + 1:].strip().lower().startswith( + ('noqa', 'pragma:', 'pylint:')) + ): + # Move inline comments to previous line. + first = source[:start_offset] + second = source[start_offset:] + yield (indentation + second.strip() + '\n' + + indentation + first.strip() + '\n') + elif token_type == token.OP and token_string != '=': + # Don't break on '=' after keyword as this violates PEP 8. + + assert token_type != token.INDENT + + first = source[:end_offset] + + second_indent = indentation + if first.rstrip().endswith('('): + second_indent += indent_word + elif '(' in first: + second_indent += ' ' * (1 + first.find('(')) + else: + second_indent += indent_word + + second = (second_indent + source[end_offset:].lstrip()) + if ( + not second.strip() or + second.lstrip().startswith('#') + ): + continue + + # Do not begin a line with a comma + if second.lstrip().startswith(','): + continue + # Do end a line with a dot + if first.rstrip().endswith('.'): + continue + if token_string in '+-*/': + fixed = first + ' \\' + '\n' + second + else: + fixed = first + '\n' + second + + # Only fix if syntax is okay. + if check_syntax(normalize_multiline(fixed) + if aggressive else fixed): + yield indentation + fixed + + +def _is_binary_operator(token_type, text): + return ((token_type == tokenize.OP or text in ['and', 'or']) and + text not in '()[]{},:.;@=%~') + + +# A convenient way to handle tokens. +Token = collections.namedtuple('Token', ['token_type', 'token_string', + 'spos', 'epos', 'line']) + + +class ReformattedLines(object): + + """The reflowed lines of atoms. + + Each part of the line is represented as an "atom." They can be moved + around when need be to get the optimal formatting. + + """ + + ########################################################################### + # Private Classes + + class _Indent(object): + + """Represent an indentation in the atom stream.""" + + def __init__(self, indent_amt): + self._indent_amt = indent_amt + + def emit(self): + return ' ' * self._indent_amt + + @property + def size(self): + return self._indent_amt + + class _Space(object): + + """Represent a space in the atom stream.""" + + def emit(self): + return ' ' + + @property + def size(self): + return 1 + + class _LineBreak(object): + + """Represent a line break in the atom stream.""" + + def emit(self): + return '\n' + + @property + def size(self): + return 0 + + def __init__(self, max_line_length): + self._max_line_length = max_line_length + self._lines = [] + self._bracket_depth = 0 + self._prev_item = None + self._prev_prev_item = None + + def __repr__(self): + return self.emit() + + ########################################################################### + # Public Methods + + def add(self, obj, indent_amt, break_after_open_bracket): + if isinstance(obj, Atom): + self._add_item(obj, indent_amt) + return + + self._add_container(obj, indent_amt, break_after_open_bracket) + + def add_comment(self, item): + num_spaces = 2 + if len(self._lines) > 1: + if isinstance(self._lines[-1], self._Space): + num_spaces -= 1 + if len(self._lines) > 2: + if isinstance(self._lines[-2], self._Space): + num_spaces -= 1 + + while num_spaces > 0: + self._lines.append(self._Space()) + num_spaces -= 1 + self._lines.append(item) + + def add_indent(self, indent_amt): + self._lines.append(self._Indent(indent_amt)) + + def add_line_break(self, indent): + self._lines.append(self._LineBreak()) + self.add_indent(len(indent)) + + def add_line_break_at(self, index, indent_amt): + self._lines.insert(index, self._LineBreak()) + self._lines.insert(index + 1, self._Indent(indent_amt)) + + def add_space_if_needed(self, curr_text, equal=False): + if ( + not self._lines or isinstance( + self._lines[-1], (self._LineBreak, self._Indent, self._Space)) + ): + return + + prev_text = unicode(self._prev_item) + prev_prev_text = ( + unicode(self._prev_prev_item) if self._prev_prev_item else '') + + if ( + # The previous item was a keyword or identifier and the current + # item isn't an operator that doesn't require a space. + ((self._prev_item.is_keyword or self._prev_item.is_string or + self._prev_item.is_name or self._prev_item.is_number) and + (curr_text[0] not in '([{.,:}])' or + (curr_text[0] == '=' and equal))) or + + # Don't place spaces around a '.', unless it's in an 'import' + # statement. + ((prev_prev_text != 'from' and prev_text[-1] != '.' and + curr_text != 'import') and + + # Don't place a space before a colon. + curr_text[0] != ':' and + + # Don't split up ending brackets by spaces. + ((prev_text[-1] in '}])' and curr_text[0] not in '.,}])') or + + # Put a space after a colon or comma. + prev_text[-1] in ':,' or + + # Put space around '=' if asked to. + (equal and prev_text == '=') or + + # Put spaces around non-unary arithmetic operators. + ((self._prev_prev_item and + (prev_text not in '+-' and + (self._prev_prev_item.is_name or + self._prev_prev_item.is_number or + self._prev_prev_item.is_string)) and + prev_text in ('+', '-', '%', '*', '/', '//', '**', 'in'))))) + ): + self._lines.append(self._Space()) + + def previous_item(self): + """Return the previous non-whitespace item.""" + return self._prev_item + + def fits_on_current_line(self, item_extent): + return self.current_size() + item_extent <= self._max_line_length + + def current_size(self): + """The size of the current line minus the indentation.""" + size = 0 + for item in reversed(self._lines): + size += item.size + if isinstance(item, self._LineBreak): + break + + return size + + def line_empty(self): + return (self._lines and + isinstance(self._lines[-1], + (self._LineBreak, self._Indent))) + + def emit(self): + string = '' + for item in self._lines: + if isinstance(item, self._LineBreak): + string = string.rstrip() + string += item.emit() + + return string.rstrip() + '\n' + + ########################################################################### + # Private Methods + + def _add_item(self, item, indent_amt): + """Add an item to the line. + + Reflow the line to get the best formatting after the item is + inserted. The bracket depth indicates if the item is being + inserted inside of a container or not. + + """ + if self._prev_item and self._prev_item.is_string and item.is_string: + # Place consecutive string literals on separate lines. + self._lines.append(self._LineBreak()) + self._lines.append(self._Indent(indent_amt)) + + item_text = unicode(item) + if self._lines and self._bracket_depth: + # Adding the item into a container. + self._prevent_default_initializer_splitting(item, indent_amt) + + if item_text in '.,)]}': + self._split_after_delimiter(item, indent_amt) + + elif self._lines and not self.line_empty(): + # Adding the item outside of a container. + if self.fits_on_current_line(len(item_text)): + self._enforce_space(item) + + else: + # Line break for the new item. + self._lines.append(self._LineBreak()) + self._lines.append(self._Indent(indent_amt)) + + self._lines.append(item) + self._prev_item, self._prev_prev_item = item, self._prev_item + + if item_text in '([{': + self._bracket_depth += 1 + + elif item_text in '}])': + self._bracket_depth -= 1 + assert self._bracket_depth >= 0 + + def _add_container(self, container, indent_amt, break_after_open_bracket): + actual_indent = indent_amt + 1 + + if ( + unicode(self._prev_item) != '=' and + not self.line_empty() and + not self.fits_on_current_line( + container.size + self._bracket_depth + 2) + ): + + if unicode(container)[0] == '(' and self._prev_item.is_name: + # Don't split before the opening bracket of a call. + break_after_open_bracket = True + actual_indent = indent_amt + 4 + elif ( + break_after_open_bracket or + unicode(self._prev_item) not in '([{' + ): + # If the container doesn't fit on the current line and the + # current line isn't empty, place the container on the next + # line. + self._lines.append(self._LineBreak()) + self._lines.append(self._Indent(indent_amt)) + break_after_open_bracket = False + else: + actual_indent = self.current_size() + 1 + break_after_open_bracket = False + + if isinstance(container, (ListComprehension, IfExpression)): + actual_indent = indent_amt + + # Increase the continued indentation only if recursing on a + # container. + container.reflow(self, ' ' * actual_indent, + break_after_open_bracket=break_after_open_bracket) + + def _prevent_default_initializer_splitting(self, item, indent_amt): + """Prevent splitting between a default initializer. + + When there is a default initializer, it's best to keep it all on + the same line. It's nicer and more readable, even if it goes + over the maximum allowable line length. This goes back along the + current line to determine if we have a default initializer, and, + if so, to remove extraneous whitespaces and add a line + break/indent before it if needed. + + """ + if unicode(item) == '=': + # This is the assignment in the initializer. Just remove spaces for + # now. + self._delete_whitespace() + return + + if (not self._prev_item or not self._prev_prev_item or + unicode(self._prev_item) != '='): + return + + self._delete_whitespace() + prev_prev_index = self._lines.index(self._prev_prev_item) + + if ( + isinstance(self._lines[prev_prev_index - 1], self._Indent) or + self.fits_on_current_line(item.size + 1) + ): + # The default initializer is already the only item on this line. + # Don't insert a newline here. + return + + # Replace the space with a newline/indent combo. + if isinstance(self._lines[prev_prev_index - 1], self._Space): + del self._lines[prev_prev_index - 1] + + self.add_line_break_at(self._lines.index(self._prev_prev_item), + indent_amt) + + def _split_after_delimiter(self, item, indent_amt): + """Split the line only after a delimiter.""" + self._delete_whitespace() + + if self.fits_on_current_line(item.size): + return + + last_space = None + for item in reversed(self._lines): + if ( + last_space and + (not isinstance(item, Atom) or not item.is_colon) + ): + break + else: + last_space = None + if isinstance(item, self._Space): + last_space = item + if isinstance(item, (self._LineBreak, self._Indent)): + return + + if not last_space: + return + + self.add_line_break_at(self._lines.index(last_space), indent_amt) + + def _enforce_space(self, item): + """Enforce a space in certain situations. + + There are cases where we will want a space where normally we + wouldn't put one. This just enforces the addition of a space. + + """ + if isinstance(self._lines[-1], + (self._Space, self._LineBreak, self._Indent)): + return + + if not self._prev_item: + return + + item_text = unicode(item) + prev_text = unicode(self._prev_item) + + # Prefer a space around a '.' in an import statement, and between the + # 'import' and '('. + if ( + (item_text == '.' and prev_text == 'from') or + (item_text == 'import' and prev_text == '.') or + (item_text == '(' and prev_text == 'import') + ): + self._lines.append(self._Space()) + + def _delete_whitespace(self): + """Delete all whitespace from the end of the line.""" + while isinstance(self._lines[-1], (self._Space, self._LineBreak, + self._Indent)): + del self._lines[-1] + + +class Atom(object): + + """The smallest unbreakable unit that can be reflowed.""" + + def __init__(self, atom): + self._atom = atom + + def __repr__(self): + return self._atom.token_string + + def __len__(self): + return self.size + + def reflow( + self, reflowed_lines, continued_indent, extent, + break_after_open_bracket=False, + is_list_comp_or_if_expr=False, + next_is_dot=False + ): + if self._atom.token_type == tokenize.COMMENT: + reflowed_lines.add_comment(self) + return + + total_size = extent if extent else self.size + + if self._atom.token_string not in ',:([{}])': + # Some atoms will need an extra 1-sized space token after them. + total_size += 1 + + prev_item = reflowed_lines.previous_item() + if ( + not is_list_comp_or_if_expr and + not reflowed_lines.fits_on_current_line(total_size) and + not (next_is_dot and + reflowed_lines.fits_on_current_line(self.size + 1)) and + not reflowed_lines.line_empty() and + not self.is_colon and + not (prev_item and prev_item.is_name and + unicode(self) == '(') + ): + # Start a new line if there is already something on the line and + # adding this atom would make it go over the max line length. + reflowed_lines.add_line_break(continued_indent) + else: + reflowed_lines.add_space_if_needed(unicode(self)) + + reflowed_lines.add(self, len(continued_indent), + break_after_open_bracket) + + def emit(self): + return self.__repr__() + + @property + def is_keyword(self): + return keyword.iskeyword(self._atom.token_string) + + @property + def is_string(self): + return self._atom.token_type == tokenize.STRING + + @property + def is_name(self): + return self._atom.token_type == tokenize.NAME + + @property + def is_number(self): + return self._atom.token_type == tokenize.NUMBER + + @property + def is_comma(self): + return self._atom.token_string == ',' + + @property + def is_colon(self): + return self._atom.token_string == ':' + + @property + def size(self): + return len(self._atom.token_string) + + +class Container(object): + + """Base class for all container types.""" + + def __init__(self, items): + self._items = items + + def __repr__(self): + string = '' + last_was_keyword = False + + for item in self._items: + if item.is_comma: + string += ', ' + elif item.is_colon: + string += ': ' + else: + item_string = unicode(item) + if ( + string and + (last_was_keyword or + (not string.endswith(tuple('([{,.:}]) ')) and + not item_string.startswith(tuple('([{,.:}])')))) + ): + string += ' ' + string += item_string + + last_was_keyword = item.is_keyword + return string + + def __iter__(self): + for element in self._items: + yield element + + def __getitem__(self, idx): + return self._items[idx] + + def reflow(self, reflowed_lines, continued_indent, + break_after_open_bracket=False): + last_was_container = False + for (index, item) in enumerate(self._items): + next_item = get_item(self._items, index + 1) + + if isinstance(item, Atom): + is_list_comp_or_if_expr = ( + isinstance(self, (ListComprehension, IfExpression))) + item.reflow(reflowed_lines, continued_indent, + self._get_extent(index), + is_list_comp_or_if_expr=is_list_comp_or_if_expr, + next_is_dot=(next_item and + unicode(next_item) == '.')) + if last_was_container and item.is_comma: + reflowed_lines.add_line_break(continued_indent) + last_was_container = False + else: # isinstance(item, Container) + reflowed_lines.add(item, len(continued_indent), + break_after_open_bracket) + last_was_container = not isinstance(item, (ListComprehension, + IfExpression)) + + if ( + break_after_open_bracket and index == 0 and + # Prefer to keep empty containers together instead of + # separating them. + unicode(item) == self.open_bracket and + (not next_item or unicode(next_item) != self.close_bracket) and + (len(self._items) != 3 or not isinstance(next_item, Atom)) + ): + reflowed_lines.add_line_break(continued_indent) + break_after_open_bracket = False + else: + next_next_item = get_item(self._items, index + 2) + if ( + unicode(item) not in ['.', '%', 'in'] and + next_item and not isinstance(next_item, Container) and + unicode(next_item) != ':' and + next_next_item and (not isinstance(next_next_item, Atom) or + unicode(next_item) == 'not') and + not reflowed_lines.line_empty() and + not reflowed_lines.fits_on_current_line( + self._get_extent(index + 1) + 2) + ): + reflowed_lines.add_line_break(continued_indent) + + def _get_extent(self, index): + """The extent of the full element. + + E.g., the length of a function call or keyword. + + """ + extent = 0 + prev_item = get_item(self._items, index - 1) + seen_dot = prev_item and unicode(prev_item) == '.' + while index < len(self._items): + item = get_item(self._items, index) + index += 1 + + if isinstance(item, (ListComprehension, IfExpression)): + break + + if isinstance(item, Container): + if prev_item and prev_item.is_name: + if seen_dot: + extent += 1 + else: + extent += item.size + + prev_item = item + continue + elif (unicode(item) not in ['.', '=', ':', 'not'] and + not item.is_name and not item.is_string): + break + + if unicode(item) == '.': + seen_dot = True + + extent += item.size + prev_item = item + + return extent + + @property + def is_string(self): + return False + + @property + def size(self): + return len(self.__repr__()) + + @property + def is_keyword(self): + return False + + @property + def is_name(self): + return False + + @property + def is_comma(self): + return False + + @property + def is_colon(self): + return False + + @property + def open_bracket(self): + return None + + @property + def close_bracket(self): + return None + + +class Tuple(Container): + + """A high-level representation of a tuple.""" + + @property + def open_bracket(self): + return '(' + + @property + def close_bracket(self): + return ')' + + +class List(Container): + + """A high-level representation of a list.""" + + @property + def open_bracket(self): + return '[' + + @property + def close_bracket(self): + return ']' + + +class DictOrSet(Container): + + """A high-level representation of a dictionary or set.""" + + @property + def open_bracket(self): + return '{' + + @property + def close_bracket(self): + return '}' + + +class ListComprehension(Container): + + """A high-level representation of a list comprehension.""" + + @property + def size(self): + length = 0 + for item in self._items: + if isinstance(item, IfExpression): + break + length += item.size + return length + + +class IfExpression(Container): + + """A high-level representation of an if-expression.""" + + +def _parse_container(tokens, index, for_or_if=None): + """Parse a high-level container, such as a list, tuple, etc.""" + + # Store the opening bracket. + items = [Atom(Token(*tokens[index]))] + index += 1 + + num_tokens = len(tokens) + while index < num_tokens: + tok = Token(*tokens[index]) + + if tok.token_string in ',)]}': + # First check if we're at the end of a list comprehension or + # if-expression. Don't add the ending token as part of the list + # comprehension or if-expression, because they aren't part of those + # constructs. + if for_or_if == 'for': + return (ListComprehension(items), index - 1) + + elif for_or_if == 'if': + return (IfExpression(items), index - 1) + + # We've reached the end of a container. + items.append(Atom(tok)) + + # If not, then we are at the end of a container. + if tok.token_string == ')': + # The end of a tuple. + return (Tuple(items), index) + + elif tok.token_string == ']': + # The end of a list. + return (List(items), index) + + elif tok.token_string == '}': + # The end of a dictionary or set. + return (DictOrSet(items), index) + + elif tok.token_string in '([{': + # A sub-container is being defined. + (container, index) = _parse_container(tokens, index) + items.append(container) + + elif tok.token_string == 'for': + (container, index) = _parse_container(tokens, index, 'for') + items.append(container) + + elif tok.token_string == 'if': + (container, index) = _parse_container(tokens, index, 'if') + items.append(container) + + else: + items.append(Atom(tok)) + + index += 1 + + return (None, None) + + +def _parse_tokens(tokens): + """Parse the tokens. + + This converts the tokens into a form where we can manipulate them + more easily. + + """ + + index = 0 + parsed_tokens = [] + + num_tokens = len(tokens) + while index < num_tokens: + tok = Token(*tokens[index]) + + assert tok.token_type != token.INDENT + if tok.token_type == tokenize.NEWLINE: + # There's only one newline and it's at the end. + break + + if tok.token_string in '([{': + (container, index) = _parse_container(tokens, index) + if not container: + return None + parsed_tokens.append(container) + else: + parsed_tokens.append(Atom(tok)) + + index += 1 + + return parsed_tokens + + +def _reflow_lines(parsed_tokens, indentation, max_line_length, + start_on_prefix_line): + """Reflow the lines so that it looks nice.""" + + if unicode(parsed_tokens[0]) == 'def': + # A function definition gets indented a bit more. + continued_indent = indentation + ' ' * 2 * DEFAULT_INDENT_SIZE + else: + continued_indent = indentation + ' ' * DEFAULT_INDENT_SIZE + + break_after_open_bracket = not start_on_prefix_line + + lines = ReformattedLines(max_line_length) + lines.add_indent(len(indentation.lstrip('\r\n'))) + + if not start_on_prefix_line: + # If splitting after the opening bracket will cause the first element + # to be aligned weirdly, don't try it. + first_token = get_item(parsed_tokens, 0) + second_token = get_item(parsed_tokens, 1) + + if ( + first_token and second_token and + unicode(second_token)[0] == '(' and + len(indentation) + len(first_token) + 1 == len(continued_indent) + ): + return None + + for item in parsed_tokens: + lines.add_space_if_needed(unicode(item), equal=True) + + save_continued_indent = continued_indent + if start_on_prefix_line and isinstance(item, Container): + start_on_prefix_line = False + continued_indent = ' ' * (lines.current_size() + 1) + + item.reflow(lines, continued_indent, break_after_open_bracket) + continued_indent = save_continued_indent + + return lines.emit() + + +def _shorten_line_at_tokens_new(tokens, source, indentation, + max_line_length): + """Shorten the line taking its length into account. + + The input is expected to be free of newlines except for inside + multiline strings and at the end. + + """ + # Yield the original source so to see if it's a better choice than the + # shortened candidate lines we generate here. + yield indentation + source + + parsed_tokens = _parse_tokens(tokens) + + if parsed_tokens: + # Perform two reflows. The first one starts on the same line as the + # prefix. The second starts on the line after the prefix. + fixed = _reflow_lines(parsed_tokens, indentation, max_line_length, + start_on_prefix_line=True) + if fixed and check_syntax(normalize_multiline(fixed.lstrip())): + yield fixed + + fixed = _reflow_lines(parsed_tokens, indentation, max_line_length, + start_on_prefix_line=False) + if fixed and check_syntax(normalize_multiline(fixed.lstrip())): + yield fixed + + +def _shorten_line_at_tokens(tokens, source, indentation, indent_word, + key_token_strings, aggressive): + """Separate line by breaking at tokens in key_token_strings. + + The input is expected to be free of newlines except for inside + multiline strings and at the end. + + """ + offsets = [] + for (index, _t) in enumerate(token_offsets(tokens)): + (token_type, + token_string, + start_offset, + end_offset) = _t + + assert token_type != token.INDENT + + if token_string in key_token_strings: + # Do not break in containers with zero or one items. + unwanted_next_token = { + '(': ')', + '[': ']', + '{': '}'}.get(token_string) + if unwanted_next_token: + if ( + get_item(tokens, + index + 1, + default=[None, None])[1] == unwanted_next_token or + get_item(tokens, + index + 2, + default=[None, None])[1] == unwanted_next_token + ): + continue + + if ( + index > 2 and token_string == '(' and + tokens[index - 1][1] in ',(%[' + ): + # Don't split after a tuple start, or before a tuple start if + # the tuple is in a list. + continue + + if end_offset < len(source) - 1: + # Don't split right before newline. + offsets.append(end_offset) + else: + # Break at adjacent strings. These were probably meant to be on + # separate lines in the first place. + previous_token = get_item(tokens, index - 1) + if ( + token_type == tokenize.STRING and + previous_token and previous_token[0] == tokenize.STRING + ): + offsets.append(start_offset) + + current_indent = None + fixed = None + for line in split_at_offsets(source, offsets): + if fixed: + fixed += '\n' + current_indent + line + + for symbol in '([{': + if line.endswith(symbol): + current_indent += indent_word + else: + # First line. + fixed = line + assert not current_indent + current_indent = indent_word + + assert fixed is not None + + if check_syntax(normalize_multiline(fixed) + if aggressive > 1 else fixed): + return indentation + fixed + else: + return None + + +def token_offsets(tokens): + """Yield tokens and offsets.""" + end_offset = 0 + previous_end_row = 0 + previous_end_column = 0 + for t in tokens: + token_type = t[0] + token_string = t[1] + (start_row, start_column) = t[2] + (end_row, end_column) = t[3] + + # Account for the whitespace between tokens. + end_offset += start_column + if previous_end_row == start_row: + end_offset -= previous_end_column + + # Record the start offset of the token. + start_offset = end_offset + + # Account for the length of the token itself. + end_offset += len(token_string) + + yield (token_type, + token_string, + start_offset, + end_offset) + + previous_end_row = end_row + previous_end_column = end_column + + +def normalize_multiline(line): + """Normalize multiline-related code that will cause syntax error. + + This is for purposes of checking syntax. + + """ + if line.startswith('def ') and line.rstrip().endswith(':'): + return line + ' pass' + elif line.startswith('return '): + return 'def _(): ' + line + elif line.startswith('@'): + return line + 'def _(): pass' + elif line.startswith('class '): + return line + ' pass' + elif line.startswith(('if ', 'elif ', 'for ', 'while ')): + return line + ' pass' + else: + return line + + +def fix_whitespace(line, offset, replacement): + """Replace whitespace at offset and return fixed line.""" + # Replace escaped newlines too + left = line[:offset].rstrip('\n\r \t\\') + right = line[offset:].lstrip('\n\r \t\\') + if right.startswith('#'): + return line + else: + return left + replacement + right + + +def _execute_pep8(pep8_options, source): + """Execute pycodestyle via python method calls.""" + class QuietReport(pycodestyle.BaseReport): + + """Version of checker that does not print.""" + + def __init__(self, options): + super(QuietReport, self).__init__(options) + self.__full_error_results = [] + + def error(self, line_number, offset, text, check): + """Collect errors.""" + code = super(QuietReport, self).error(line_number, + offset, + text, + check) + if code: + self.__full_error_results.append( + {'id': code, + 'line': line_number, + 'column': offset + 1, + 'info': text}) + + def full_error_results(self): + """Return error results in detail. + + Results are in the form of a list of dictionaries. Each + dictionary contains 'id', 'line', 'column', and 'info'. + + """ + return self.__full_error_results + + checker = pycodestyle.Checker('', lines=source, reporter=QuietReport, + **pep8_options) + checker.check_all() + return checker.report.full_error_results() + + +def _remove_leading_and_normalize(line): + return line.lstrip().rstrip(CR + LF) + '\n' + + +class Reindenter(object): + + """Reindents badly-indented code to uniformly use four-space indentation. + + Released to the public domain, by Tim Peters, 03 October 2000. + + """ + + def __init__(self, input_text): + sio = io.StringIO(input_text) + source_lines = sio.readlines() + + self.string_content_line_numbers = multiline_string_lines(input_text) + + # File lines, rstripped & tab-expanded. Dummy at start is so + # that we can use tokenize's 1-based line numbering easily. + # Note that a line is all-blank iff it is a newline. + self.lines = [] + for line_number, line in enumerate(source_lines, start=1): + # Do not modify if inside a multiline string. + if line_number in self.string_content_line_numbers: + self.lines.append(line) + else: + # Only expand leading tabs. + self.lines.append(_get_indentation(line).expandtabs() + + _remove_leading_and_normalize(line)) + + self.lines.insert(0, None) + self.index = 1 # index into self.lines of next line + self.input_text = input_text + + def run(self, indent_size=DEFAULT_INDENT_SIZE): + """Fix indentation and return modified line numbers. + + Line numbers are indexed at 1. + + """ + if indent_size < 1: + return self.input_text + + try: + stats = _reindent_stats(tokenize.generate_tokens(self.getline)) + except (SyntaxError, tokenize.TokenError): + return self.input_text + # Remove trailing empty lines. + lines = self.lines + # Sentinel. + stats.append((len(lines), 0)) + # Map count of leading spaces to # we want. + have2want = {} + # Program after transformation. + after = [] + # Copy over initial empty lines -- there's nothing to do until + # we see a line with *something* on it. + i = stats[0][0] + after.extend(lines[1:i]) + for i in range(len(stats) - 1): + thisstmt, thislevel = stats[i] + nextstmt = stats[i + 1][0] + have = _leading_space_count(lines[thisstmt]) + want = thislevel * indent_size + if want < 0: + # A comment line. + if have: + # An indented comment line. If we saw the same + # indentation before, reuse what it most recently + # mapped to. + want = have2want.get(have, -1) + if want < 0: + # Then it probably belongs to the next real stmt. + for j in range(i + 1, len(stats) - 1): + jline, jlevel = stats[j] + if jlevel >= 0: + if have == _leading_space_count(lines[jline]): + want = jlevel * indent_size + break + if want < 0: # Maybe it's a hanging + # comment like this one, + # in which case we should shift it like its base + # line got shifted. + for j in range(i - 1, -1, -1): + jline, jlevel = stats[j] + if jlevel >= 0: + want = (have + _leading_space_count( + after[jline - 1]) - + _leading_space_count(lines[jline])) + break + if want < 0: + # Still no luck -- leave it alone. + want = have + else: + want = 0 + assert want >= 0 + have2want[have] = want + diff = want - have + if diff == 0 or have == 0: + after.extend(lines[thisstmt:nextstmt]) + else: + for line_number, line in enumerate(lines[thisstmt:nextstmt], + start=thisstmt): + if line_number in self.string_content_line_numbers: + after.append(line) + elif diff > 0: + if line == '\n': + after.append(line) + else: + after.append(' ' * diff + line) + else: + remove = min(_leading_space_count(line), -diff) + after.append(line[remove:]) + + return ''.join(after) + + def getline(self): + """Line-getter for tokenize.""" + if self.index >= len(self.lines): + line = '' + else: + line = self.lines[self.index] + self.index += 1 + return line + + +def _reindent_stats(tokens): + """Return list of (lineno, indentlevel) pairs. + + One for each stmt and comment line. indentlevel is -1 for comment + lines, as a signal that tokenize doesn't know what to do about them; + indeed, they're our headache! + + """ + find_stmt = 1 # Next token begins a fresh stmt? + level = 0 # Current indent level. + stats = [] + + for t in tokens: + token_type = t[0] + sline = t[2][0] + line = t[4] + + if token_type == tokenize.NEWLINE: + # A program statement, or ENDMARKER, will eventually follow, + # after some (possibly empty) run of tokens of the form + # (NL | COMMENT)* (INDENT | DEDENT+)? + find_stmt = 1 + + elif token_type == tokenize.INDENT: + find_stmt = 1 + level += 1 + + elif token_type == tokenize.DEDENT: + find_stmt = 1 + level -= 1 + + elif token_type == tokenize.COMMENT: + if find_stmt: + stats.append((sline, -1)) + # But we're still looking for a new stmt, so leave + # find_stmt alone. + + elif token_type == tokenize.NL: + pass + + elif find_stmt: + # This is the first "real token" following a NEWLINE, so it + # must be the first token of the next program statement, or an + # ENDMARKER. + find_stmt = 0 + if line: # Not endmarker. + stats.append((sline, level)) + + return stats + + +def _leading_space_count(line): + """Return number of leading spaces in line.""" + i = 0 + while i < len(line) and line[i] == ' ': + i += 1 + return i + + +def refactor_with_2to3(source_text, fixer_names, filename=''): + """Use lib2to3 to refactor the source. + + Return the refactored source code. + + """ + from lib2to3.refactor import RefactoringTool + fixers = ['lib2to3.fixes.fix_' + name for name in fixer_names] + tool = RefactoringTool(fixer_names=fixers, explicit=fixers) + + from lib2to3.pgen2 import tokenize as lib2to3_tokenize + try: + # The name parameter is necessary particularly for the "import" fixer. + return unicode(tool.refactor_string(source_text, name=filename)) + except lib2to3_tokenize.TokenError: + return source_text + + +def check_syntax(code): + """Return True if syntax is okay.""" + try: + return compile(code, '', 'exec') + except (SyntaxError, TypeError, UnicodeDecodeError): + return False + + +def filter_results(source, results, aggressive): + """Filter out spurious reports from pycodestyle. + + If aggressive is True, we allow possibly unsafe fixes (E711, E712). + + """ + non_docstring_string_line_numbers = multiline_string_lines( + source, include_docstrings=False) + all_string_line_numbers = multiline_string_lines( + source, include_docstrings=True) + + commented_out_code_line_numbers = commented_out_code_lines(source) + + has_e901 = any(result['id'].lower() == 'e901' for result in results) + + for r in results: + issue_id = r['id'].lower() + + if r['line'] in non_docstring_string_line_numbers: + if issue_id.startswith(('e1', 'e501', 'w191')): + continue + + if r['line'] in all_string_line_numbers: + if issue_id in ['e501']: + continue + + # We must offset by 1 for lines that contain the trailing contents of + # multiline strings. + if not aggressive and (r['line'] + 1) in all_string_line_numbers: + # Do not modify multiline strings in non-aggressive mode. Remove + # trailing whitespace could break doctests. + if issue_id.startswith(('w29', 'w39')): + continue + + if aggressive <= 0: + if issue_id.startswith(('e711', 'e72', 'w6')): + continue + + if aggressive <= 1: + if issue_id.startswith(('e712', 'e713', 'e714', 'w5')): + continue + + if aggressive <= 2: + if issue_id.startswith(('e704', 'w5')): + continue + + if r['line'] in commented_out_code_line_numbers: + if issue_id.startswith(('e26', 'e501')): + continue + + # Do not touch indentation if there is a token error caused by + # incomplete multi-line statement. Otherwise, we risk screwing up the + # indentation. + if has_e901: + if issue_id.startswith(('e1', 'e7')): + continue + + yield r + + +def multiline_string_lines(source, include_docstrings=False): + """Return line numbers that are within multiline strings. + + The line numbers are indexed at 1. + + Docstrings are ignored. + + """ + line_numbers = set() + previous_token_type = '' + try: + for t in generate_tokens(source): + token_type = t[0] + start_row = t[2][0] + end_row = t[3][0] + + if token_type == tokenize.STRING and start_row != end_row: + if ( + include_docstrings or + previous_token_type != tokenize.INDENT + ): + # We increment by one since we want the contents of the + # string. + line_numbers |= set(range(1 + start_row, 1 + end_row)) + + previous_token_type = token_type + except (SyntaxError, tokenize.TokenError): + pass + + return line_numbers + + +def commented_out_code_lines(source): + """Return line numbers of comments that are likely code. + + Commented-out code is bad practice, but modifying it just adds even + more clutter. + + """ + line_numbers = [] + try: + for t in generate_tokens(source): + token_type = t[0] + token_string = t[1] + start_row = t[2][0] + line = t[4] + + # Ignore inline comments. + if not line.lstrip().startswith('#'): + continue + + if token_type == tokenize.COMMENT: + stripped_line = token_string.lstrip('#').strip() + if ( + ' ' in stripped_line and + '#' not in stripped_line and + check_syntax(stripped_line) + ): + line_numbers.append(start_row) + except (SyntaxError, tokenize.TokenError): + pass + + return line_numbers + + +def shorten_comment(line, max_line_length, last_comment=False): + """Return trimmed or split long comment line. + + If there are no comments immediately following it, do a text wrap. + Doing this wrapping on all comments in general would lead to jagged + comment text. + + """ + assert len(line) > max_line_length + line = line.rstrip() + + # PEP 8 recommends 72 characters for comment text. + indentation = _get_indentation(line) + '# ' + max_line_length = min(max_line_length, + len(indentation) + 72) + + MIN_CHARACTER_REPEAT = 5 + if ( + len(line) - len(line.rstrip(line[-1])) >= MIN_CHARACTER_REPEAT and + not line[-1].isalnum() + ): + # Trim comments that end with things like --------- + return line[:max_line_length] + '\n' + elif last_comment and re.match(r'\s*#+\s*\w+', line): + split_lines = textwrap.wrap(line.lstrip(' \t#'), + initial_indent=indentation, + subsequent_indent=indentation, + width=max_line_length, + break_long_words=False, + break_on_hyphens=False) + return '\n'.join(split_lines) + '\n' + else: + return line + '\n' + + +def normalize_line_endings(lines, newline): + """Return fixed line endings. + + All lines will be modified to use the most common line ending. + + """ + return [line.rstrip('\n\r') + newline for line in lines] + + +def mutual_startswith(a, b): + return b.startswith(a) or a.startswith(b) + + +def code_match(code, select, ignore): + if ignore: + assert not isinstance(ignore, unicode) + for ignored_code in [c.strip() for c in ignore]: + if mutual_startswith(code.lower(), ignored_code.lower()): + return False + + if select: + assert not isinstance(select, unicode) + for selected_code in [c.strip() for c in select]: + if mutual_startswith(code.lower(), selected_code.lower()): + return True + return False + + return True + + +def fix_code(source, options=None, encoding=None, apply_config=False): + """Return fixed source code. + + "encoding" will be used to decode "source" if it is a byte string. + + """ + options = _get_options(options, apply_config) + + if not isinstance(source, unicode): + source = source.decode(encoding or get_encoding()) + + sio = io.StringIO(source) + return fix_lines(sio.readlines(), options=options) + + +def _get_options(raw_options, apply_config): + """Return parsed options.""" + if not raw_options: + return parse_args([''], apply_config=apply_config) + + if isinstance(raw_options, dict): + options = parse_args([''], apply_config=apply_config) + for name, value in raw_options.items(): + if not hasattr(options, name): + raise ValueError("No such option '{}'".format(name)) + + # Check for very basic type errors. + expected_type = type(getattr(options, name)) + if not isinstance(expected_type, (str, unicode)): + if isinstance(value, (str, unicode)): + raise ValueError( + "Option '{}' should not be a string".format(name)) + setattr(options, name, value) + else: + options = raw_options + + return options + + +def fix_lines(source_lines, options, filename=''): + """Return fixed source code.""" + # Transform everything to line feed. Then change them back to original + # before returning fixed source code. + original_newline = find_newline(source_lines) + tmp_source = ''.join(normalize_line_endings(source_lines, '\n')) + + # Keep a history to break out of cycles. + previous_hashes = set() + + if options.line_range: + # Disable "apply_local_fixes()" for now due to issue #175. + fixed_source = tmp_source + else: + # Apply global fixes only once (for efficiency). + fixed_source = apply_global_fixes(tmp_source, + options, + filename=filename) + + passes = 0 + long_line_ignore_cache = set() + while hash(fixed_source) not in previous_hashes: + if options.pep8_passes >= 0 and passes > options.pep8_passes: + break + passes += 1 + + previous_hashes.add(hash(fixed_source)) + + tmp_source = copy.copy(fixed_source) + + fix = FixPEP8( + filename, + options, + contents=tmp_source, + long_line_ignore_cache=long_line_ignore_cache) + + fixed_source = fix.fix() + + sio = io.StringIO(fixed_source) + return ''.join(normalize_line_endings(sio.readlines(), original_newline)) + + +def fix_file(filename, options=None, output=None, apply_config=False): + if not options: + options = parse_args([filename], apply_config=apply_config) + + original_source = readlines_from_file(filename) + + fixed_source = original_source + + if options.in_place or output: + encoding = detect_encoding(filename) + + if output: + output = LineEndingWrapper(wrap_output(output, encoding=encoding)) + + fixed_source = fix_lines(fixed_source, options, filename=filename) + + if options.diff: + new = io.StringIO(fixed_source) + new = new.readlines() + diff = get_diff_text(original_source, new, filename) + if output: + output.write(diff) + output.flush() + else: + return diff + elif options.in_place: + fp = open_with_encoding(filename, encoding=encoding, mode='w') + fp.write(fixed_source) + fp.close() + else: + if output: + output.write(fixed_source) + output.flush() + else: + return fixed_source + + +def global_fixes(): + """Yield multiple (code, function) tuples.""" + for function in list(globals().values()): + if inspect.isfunction(function): + arguments = _get_parameters(function) + if arguments[:1] != ['source']: + continue + + code = extract_code_from_function(function) + if code: + yield (code, function) + + +def _get_parameters(function): + # pylint: disable=deprecated-method + if sys.version_info >= (3, 3): + # We need to match "getargspec()", which includes "self" as the first + # value for methods. + # https://bugs.python.org/issue17481#msg209469 + if inspect.ismethod(function): + function = function.__func__ + + return list(inspect.signature(function).parameters) + else: + return inspect.getargspec(function)[0] + + +def apply_global_fixes(source, options, where='global', filename=''): + """Run global fixes on source code. + + These are fixes that only need be done once (unlike those in + FixPEP8, which are dependent on pycodestyle). + + """ + if any(code_match(code, select=options.select, ignore=options.ignore) + for code in ['E101', 'E111']): + source = reindent(source, + indent_size=options.indent_size) + + for (code, function) in global_fixes(): + if code_match(code, select=options.select, ignore=options.ignore): + if options.verbose: + print('---> Applying {0} fix for {1}'.format(where, + code.upper()), + file=sys.stderr) + source = function(source, + aggressive=options.aggressive) + + source = fix_2to3(source, + aggressive=options.aggressive, + select=options.select, + ignore=options.ignore, + filename=filename) + + return source + + +def extract_code_from_function(function): + """Return code handled by function.""" + if not function.__name__.startswith('fix_'): + return None + + code = re.sub('^fix_', '', function.__name__) + if not code: + return None + + try: + int(code[1:]) + except ValueError: + return None + + return code + + +def _get_package_version(): + packages = ["pycodestyle: {0}".format(pycodestyle.__version__)] + return ", ".join(packages) + + +def create_parser(): + """Return command-line parser.""" + # Do import locally to be friendly to those who use autopep8 as a library + # and are supporting Python 2.6. + import argparse + + parser = argparse.ArgumentParser(description=docstring_summary(__doc__), + prog='autopep8') + parser.add_argument('--version', action='version', + version='%(prog)s {0} ({1})'.format( + __version__, _get_package_version())) + parser.add_argument('-v', '--verbose', action='count', + default=0, + help='print verbose messages; ' + 'multiple -v result in more verbose messages') + parser.add_argument('-d', '--diff', action='store_true', + help='print the diff for the fixed source') + parser.add_argument('-i', '--in-place', action='store_true', + help='make changes to files in place') + parser.add_argument('--global-config', metavar='filename', + default=DEFAULT_CONFIG, + help='path to a global pep8 config file; if this file ' + 'does not exist then this is ignored ' + '(default: {0})'.format(DEFAULT_CONFIG)) + parser.add_argument('--ignore-local-config', action='store_true', + help="don't look for and apply local config files; " + 'if not passed, defaults are updated with any ' + "config files in the project's root directory") + parser.add_argument('-r', '--recursive', action='store_true', + help='run recursively over directories; ' + 'must be used with --in-place or --diff') + parser.add_argument('-j', '--jobs', type=int, metavar='n', default=1, + help='number of parallel jobs; ' + 'match CPU count if value is less than 1') + parser.add_argument('-p', '--pep8-passes', metavar='n', + default=-1, type=int, + help='maximum number of additional pep8 passes ' + '(default: infinite)') + parser.add_argument('-a', '--aggressive', action='count', default=0, + help='enable non-whitespace changes; ' + 'multiple -a result in more aggressive changes') + parser.add_argument('--experimental', action='store_true', + help='enable experimental fixes') + parser.add_argument('--exclude', metavar='globs', + help='exclude file/directory names that match these ' + 'comma-separated globs') + parser.add_argument('--list-fixes', action='store_true', + help='list codes for fixes; ' + 'used by --ignore and --select') + parser.add_argument('--ignore', metavar='errors', default='', + help='do not fix these errors/warnings ' + '(default: {0})'.format(DEFAULT_IGNORE)) + parser.add_argument('--select', metavar='errors', default='', + help='fix only these errors/warnings (e.g. E4,W)') + parser.add_argument('--max-line-length', metavar='n', default=79, type=int, + help='set maximum allowed line length ' + '(default: %(default)s)') + parser.add_argument('--line-range', '--range', metavar='line', + default=None, type=int, nargs=2, + help='only fix errors found within this inclusive ' + 'range of line numbers (e.g. 1 99); ' + 'line numbers are indexed at 1') + parser.add_argument('--indent-size', default=DEFAULT_INDENT_SIZE, + type=int, help=argparse.SUPPRESS) + parser.add_argument('files', nargs='*', + help="files to format or '-' for standard in") + + return parser + + +def parse_args(arguments, apply_config=False): + """Parse command-line options.""" + parser = create_parser() + args = parser.parse_args(arguments) + + if not args.files and not args.list_fixes: + parser.error('incorrect number of arguments') + + args.files = [decode_filename(name) for name in args.files] + + if apply_config: + parser = read_config(args, parser) + args = parser.parse_args(arguments) + args.files = [decode_filename(name) for name in args.files] + + if '-' in args.files: + if len(args.files) > 1: + parser.error('cannot mix stdin and regular files') + + if args.diff: + parser.error('--diff cannot be used with standard input') + + if args.in_place: + parser.error('--in-place cannot be used with standard input') + + if args.recursive: + parser.error('--recursive cannot be used with standard input') + + if len(args.files) > 1 and not (args.in_place or args.diff): + parser.error('autopep8 only takes one filename as argument ' + 'unless the "--in-place" or "--diff" args are ' + 'used') + + if args.recursive and not (args.in_place or args.diff): + parser.error('--recursive must be used with --in-place or --diff') + + if args.in_place and args.diff: + parser.error('--in-place and --diff are mutually exclusive') + + if args.max_line_length <= 0: + parser.error('--max-line-length must be greater than 0') + + if args.select: + args.select = _split_comma_separated(args.select) + + if args.ignore: + args.ignore = _split_comma_separated(args.ignore) + elif not args.select: + if args.aggressive: + # Enable everything by default if aggressive. + args.select = set(['E', 'W']) + else: + args.ignore = _split_comma_separated(DEFAULT_IGNORE) + + if args.exclude: + args.exclude = _split_comma_separated(args.exclude) + else: + args.exclude = set([]) + + if args.jobs < 1: + # Do not import multiprocessing globally in case it is not supported + # on the platform. + import multiprocessing + args.jobs = multiprocessing.cpu_count() + + if args.jobs > 1 and not args.in_place: + parser.error('parallel jobs requires --in-place') + + if args.line_range: + if args.line_range[0] <= 0: + parser.error('--range must be positive numbers') + if args.line_range[0] > args.line_range[1]: + parser.error('First value of --range should be less than or equal ' + 'to the second') + + return args + + +def read_config(args, parser): + """Read both user configuration and local configuration.""" + try: + from configparser import ConfigParser as SafeConfigParser + from configparser import Error + except ImportError: + from ConfigParser import SafeConfigParser + from ConfigParser import Error + + config = SafeConfigParser() + + try: + config.read(args.global_config) + + if not args.ignore_local_config: + parent = tail = args.files and os.path.abspath( + os.path.commonprefix(args.files)) + while tail: + if config.read([os.path.join(parent, fn) + for fn in PROJECT_CONFIG]): + break + (parent, tail) = os.path.split(parent) + + defaults = dict() + option_list = dict([(o.dest, o.type or type(o.default)) + for o in parser._actions]) + + for section in ['pep8', 'pycodestyle']: + if not config.has_section(section): + continue + for k, v in config.items(section): + norm_opt = k.lstrip('-').replace('-', '_') + opt_type = option_list[norm_opt] + if opt_type is int: + value = config.getint(section, k) + elif opt_type is bool: + value = config.getboolean(section, k) + else: + value = config.get(section, k) + defaults[norm_opt] = value + + parser.set_defaults(**defaults) + except Error: + # Ignore for now. + pass + + return parser + + +def _split_comma_separated(string): + """Return a set of strings.""" + return set(text.strip() for text in string.split(',') if text.strip()) + + +def decode_filename(filename): + """Return Unicode filename.""" + if isinstance(filename, unicode): + return filename + else: + return filename.decode(sys.getfilesystemencoding()) + + +def supported_fixes(): + """Yield pep8 error codes that autopep8 fixes. + + Each item we yield is a tuple of the code followed by its + description. + + """ + yield ('E101', docstring_summary(reindent.__doc__)) + + instance = FixPEP8(filename=None, options=None, contents='') + for attribute in dir(instance): + code = re.match('fix_([ew][0-9][0-9][0-9])', attribute) + if code: + yield ( + code.group(1).upper(), + re.sub(r'\s+', ' ', + docstring_summary(getattr(instance, attribute).__doc__)) + ) + + for (code, function) in sorted(global_fixes()): + yield (code.upper() + (4 - len(code)) * ' ', + re.sub(r'\s+', ' ', docstring_summary(function.__doc__))) + + for code in sorted(CODE_TO_2TO3): + yield (code.upper() + (4 - len(code)) * ' ', + re.sub(r'\s+', ' ', docstring_summary(fix_2to3.__doc__))) + + +def docstring_summary(docstring): + """Return summary of docstring.""" + return docstring.split('\n')[0] if docstring else '' + + +def line_shortening_rank(candidate, indent_word, max_line_length, + experimental=False): + """Return rank of candidate. + + This is for sorting candidates. + + """ + if not candidate.strip(): + return 0 + + rank = 0 + lines = candidate.rstrip().split('\n') + + offset = 0 + if ( + not lines[0].lstrip().startswith('#') and + lines[0].rstrip()[-1] not in '([{' + ): + for (opening, closing) in ('()', '[]', '{}'): + # Don't penalize empty containers that aren't split up. Things like + # this "foo(\n )" aren't particularly good. + opening_loc = lines[0].find(opening) + closing_loc = lines[0].find(closing) + if opening_loc >= 0: + if closing_loc < 0 or closing_loc != opening_loc + 1: + offset = max(offset, 1 + opening_loc) + + current_longest = max(offset + len(x.strip()) for x in lines) + + rank += 4 * max(0, current_longest - max_line_length) + + rank += len(lines) + + # Too much variation in line length is ugly. + rank += 2 * standard_deviation(len(line) for line in lines) + + bad_staring_symbol = { + '(': ')', + '[': ']', + '{': '}'}.get(lines[0][-1]) + + if len(lines) > 1: + if ( + bad_staring_symbol and + lines[1].lstrip().startswith(bad_staring_symbol) + ): + rank += 20 + + for lineno, current_line in enumerate(lines): + current_line = current_line.strip() + + if current_line.startswith('#'): + continue + + for bad_start in ['.', '%', '+', '-', '/']: + if current_line.startswith(bad_start): + rank += 100 + + # Do not tolerate operators on their own line. + if current_line == bad_start: + rank += 1000 + + if ( + current_line.endswith(('.', '%', '+', '-', '/')) and + "': " in current_line + ): + rank += 1000 + + if current_line.endswith(('(', '[', '{', '.')): + # Avoid lonely opening. They result in longer lines. + if len(current_line) <= len(indent_word): + rank += 100 + + # Avoid the ugliness of ", (\n". + if ( + current_line.endswith('(') and + current_line[:-1].rstrip().endswith(',') + ): + rank += 100 + + # Avoid the ugliness of "something[\n" and something[index][\n. + if ( + current_line.endswith('[') and + len(current_line) > 1 and + (current_line[-2].isalnum() or current_line[-2] in ']') + ): + rank += 300 + + # Also avoid the ugliness of "foo.\nbar" + if current_line.endswith('.'): + rank += 100 + + if has_arithmetic_operator(current_line): + rank += 100 + + # Avoid breaking at unary operators. + if re.match(r'.*[(\[{]\s*[\-\+~]$', current_line.rstrip('\\ ')): + rank += 1000 + + if re.match(r'.*lambda\s*\*$', current_line.rstrip('\\ ')): + rank += 1000 + + if current_line.endswith(('%', '(', '[', '{')): + rank -= 20 + + # Try to break list comprehensions at the "for". + if current_line.startswith('for '): + rank -= 50 + + if current_line.endswith('\\'): + # If a line ends in \-newline, it may be part of a + # multiline string. In that case, we would like to know + # how long that line is without the \-newline. If it's + # longer than the maximum, or has comments, then we assume + # that the \-newline is an okay candidate and only + # penalize it a bit. + total_len = len(current_line) + lineno += 1 + while lineno < len(lines): + total_len += len(lines[lineno]) + + if lines[lineno].lstrip().startswith('#'): + total_len = max_line_length + break + + if not lines[lineno].endswith('\\'): + break + + lineno += 1 + + if total_len < max_line_length: + rank += 10 + else: + rank += 100 if experimental else 1 + + # Prefer breaking at commas rather than colon. + if ',' in current_line and current_line.endswith(':'): + rank += 10 + + # Avoid splitting dictionaries between key and value. + if current_line.endswith(':'): + rank += 100 + + rank += 10 * count_unbalanced_brackets(current_line) + + return max(0, rank) + + +def standard_deviation(numbers): + """Return standard devation.""" + numbers = list(numbers) + if not numbers: + return 0 + mean = sum(numbers) / len(numbers) + return (sum((n - mean) ** 2 for n in numbers) / + len(numbers)) ** .5 + + +def has_arithmetic_operator(line): + """Return True if line contains any arithmetic operators.""" + for operator in pycodestyle.ARITHMETIC_OP: + if operator in line: + return True + + return False + + +def count_unbalanced_brackets(line): + """Return number of unmatched open/close brackets.""" + count = 0 + for opening, closing in ['()', '[]', '{}']: + count += abs(line.count(opening) - line.count(closing)) + + return count + + +def split_at_offsets(line, offsets): + """Split line at offsets. + + Return list of strings. + + """ + result = [] + + previous_offset = 0 + current_offset = 0 + for current_offset in sorted(offsets): + if current_offset < len(line) and previous_offset != current_offset: + result.append(line[previous_offset:current_offset].strip()) + previous_offset = current_offset + + result.append(line[current_offset:]) + + return result + + +class LineEndingWrapper(object): + + r"""Replace line endings to work with sys.stdout. + + It seems that sys.stdout expects only '\n' as the line ending, no matter + the platform. Otherwise, we get repeated line endings. + + """ + + def __init__(self, output): + self.__output = output + + def write(self, s): + self.__output.write(s.replace('\r\n', '\n').replace('\r', '\n')) + + def flush(self): + self.__output.flush() + + +def match_file(filename, exclude): + """Return True if file is okay for modifying/recursing.""" + base_name = os.path.basename(filename) + + if base_name.startswith('.'): + return False + + for pattern in exclude: + if fnmatch.fnmatch(base_name, pattern): + return False + if fnmatch.fnmatch(filename, pattern): + return False + + if not os.path.isdir(filename) and not is_python_file(filename): + return False + + return True + + +def find_files(filenames, recursive, exclude): + """Yield filenames.""" + while filenames: + name = filenames.pop(0) + if recursive and os.path.isdir(name): + for root, directories, children in os.walk(name): + filenames += [os.path.join(root, f) for f in children + if match_file(os.path.join(root, f), + exclude)] + directories[:] = [d for d in directories + if match_file(os.path.join(root, d), + exclude)] + else: + yield name + + +def _fix_file(parameters): + """Helper function for optionally running fix_file() in parallel.""" + if parameters[1].verbose: + print('[file:{0}]'.format(parameters[0]), file=sys.stderr) + try: + fix_file(*parameters) + except IOError as error: + print(unicode(error), file=sys.stderr) + + +def fix_multiple_files(filenames, options, output=None): + """Fix list of files. + + Optionally fix files recursively. + + """ + filenames = find_files(filenames, options.recursive, options.exclude) + if options.jobs > 1: + import multiprocessing + pool = multiprocessing.Pool(options.jobs) + pool.map(_fix_file, + [(name, options) for name in filenames]) + else: + for name in filenames: + _fix_file((name, options, output)) + + +def is_python_file(filename): + """Return True if filename is Python file.""" + if filename.endswith('.py'): + return True + + try: + with open_with_encoding( + filename, + limit_byte_check=MAX_PYTHON_FILE_DETECTION_BYTES) as f: + text = f.read(MAX_PYTHON_FILE_DETECTION_BYTES) + if not text: + return False + first_line = text.splitlines()[0] + except (IOError, IndexError): + return False + + if not PYTHON_SHEBANG_REGEX.match(first_line): + return False + + return True + + +def is_probably_part_of_multiline(line): + """Return True if line is likely part of a multiline string. + + When multiline strings are involved, pep8 reports the error as being + at the start of the multiline string, which doesn't work for us. + + """ + return ( + '"""' in line or + "'''" in line or + line.rstrip().endswith('\\') + ) + + +def wrap_output(output, encoding): + """Return output with specified encoding.""" + return codecs.getwriter(encoding)(output.buffer + if hasattr(output, 'buffer') + else output) + + +def get_encoding(): + """Return preferred encoding.""" + return locale.getpreferredencoding() or sys.getdefaultencoding() + + +def main(argv=None, apply_config=True): + """Command-line entry.""" + if argv is None: + argv = sys.argv + + try: + # Exit on broken pipe. + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + except AttributeError: # pragma: no cover + # SIGPIPE is not available on Windows. + pass + + try: + args = parse_args(argv[1:], apply_config=apply_config) + + if args.list_fixes: + for code, description in sorted(supported_fixes()): + print('{code} - {description}'.format( + code=code, description=description)) + return 0 + + if args.files == ['-']: + assert not args.in_place + + encoding = sys.stdin.encoding or get_encoding() + + # LineEndingWrapper is unnecessary here due to the symmetry between + # standard in and standard out. + wrap_output(sys.stdout, encoding=encoding).write( + fix_code(sys.stdin.read(), args, encoding=encoding)) + else: + if args.in_place or args.diff: + args.files = list(set(args.files)) + else: + assert len(args.files) == 1 + assert not args.recursive + + fix_multiple_files(args.files, args, sys.stdout) + except KeyboardInterrupt: + return 1 # pragma: no cover + + +class CachedTokenizer(object): + + """A one-element cache around tokenize.generate_tokens(). + + Original code written by Ned Batchelder, in coverage.py. + + """ + + def __init__(self): + self.last_text = None + self.last_tokens = None + + def generate_tokens(self, text): + """A stand-in for tokenize.generate_tokens().""" + if text != self.last_text: + string_io = io.StringIO(text) + self.last_tokens = list( + tokenize.generate_tokens(string_io.readline) + ) + self.last_text = text + return self.last_tokens + + +_cached_tokenizer = CachedTokenizer() +generate_tokens = _cached_tokenizer.generate_tokens + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/.gitignore b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/.gitignore new file mode 100644 index 0000000..1c45ce5 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/.gitignore @@ -0,0 +1 @@ +*.pickle diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/Grammar.txt b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/Grammar.txt new file mode 100644 index 0000000..1e1f24c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/Grammar.txt @@ -0,0 +1,158 @@ +# Grammar for 2to3. This grammar supports Python 2.x and 3.x. + +# Note: Changing the grammar specified in this file will most likely +# require corresponding changes in the parser module +# (../Modules/parsermodule.c). If you can't make the changes to +# that module yourself, please co-ordinate the required changes +# with someone who can; ask around on python-dev for help. Fred +# Drake will probably be listening there. + +# NOTE WELL: You should also follow all the steps listed in PEP 306, +# "How to Change Python's Grammar" + +# Commands for Kees Blom's railroad program +#diagram:token NAME +#diagram:token NUMBER +#diagram:token STRING +#diagram:token NEWLINE +#diagram:token ENDMARKER +#diagram:token INDENT +#diagram:output\input python.bla +#diagram:token DEDENT +#diagram:output\textwidth 20.04cm\oddsidemargin 0.0cm\evensidemargin 0.0cm +#diagram:rules + +# Start symbols for the grammar: +# file_input is a module or sequence of commands read from an input file; +# single_input is a single interactive statement; +# eval_input is the input for the eval() and input() functions. +# NB: compound_stmt in single_input is followed by extra NEWLINE! +file_input: (NEWLINE | stmt)* ENDMARKER +single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE +eval_input: testlist NEWLINE* ENDMARKER + +decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE +decorators: decorator+ +decorated: decorators (classdef | funcdef) +funcdef: 'def' NAME parameters ['->' test] ':' suite +parameters: '(' [typedargslist] ')' +typedargslist: ((tfpdef ['=' test] ',')* + ('*' [tname] (',' tname ['=' test])* [',' '**' tname] | '**' tname) + | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) +tname: NAME [':' test] +tfpdef: tname | '(' tfplist ')' +tfplist: tfpdef (',' tfpdef)* [','] +varargslist: ((vfpdef ['=' test] ',')* + ('*' [vname] (',' vname ['=' test])* [',' '**' vname] | '**' vname) + | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) +vname: NAME +vfpdef: vname | '(' vfplist ')' +vfplist: vfpdef (',' vfpdef)* [','] + +stmt: simple_stmt | compound_stmt +simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE +small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | + import_stmt | global_stmt | exec_stmt | assert_stmt) +expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) | + ('=' (yield_expr|testlist_star_expr))*) +testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [','] +augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | + '<<=' | '>>=' | '**=' | '//=') +# For normal assignments, additional restrictions enforced by the interpreter +print_stmt: 'print' ( [ test (',' test)* [','] ] | + '>>' test [ (',' test)+ [','] ] ) +del_stmt: 'del' exprlist +pass_stmt: 'pass' +flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt +break_stmt: 'break' +continue_stmt: 'continue' +return_stmt: 'return' [testlist] +yield_stmt: yield_expr +raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]] +import_stmt: import_name | import_from +import_name: 'import' dotted_as_names +import_from: ('from' ('.'* dotted_name | '.'+) + 'import' ('*' | '(' import_as_names ')' | import_as_names)) +import_as_name: NAME ['as' NAME] +dotted_as_name: dotted_name ['as' NAME] +import_as_names: import_as_name (',' import_as_name)* [','] +dotted_as_names: dotted_as_name (',' dotted_as_name)* +dotted_name: NAME ('.' NAME)* +global_stmt: ('global' | 'nonlocal') NAME (',' NAME)* +exec_stmt: 'exec' expr ['in' test [',' test]] +assert_stmt: 'assert' test [',' test] + +compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated +if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] +while_stmt: 'while' test ':' suite ['else' ':' suite] +for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] +try_stmt: ('try' ':' suite + ((except_clause ':' suite)+ + ['else' ':' suite] + ['finally' ':' suite] | + 'finally' ':' suite)) +with_stmt: 'with' with_item (',' with_item)* ':' suite +with_item: test ['as' expr] +with_var: 'as' expr +# NB compile.c makes sure that the default except clause is last +except_clause: 'except' [test [(',' | 'as') test]] +suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT + +# Backward compatibility cruft to support: +# [ x for x in lambda: True, lambda: False if x() ] +# even while also allowing: +# lambda x: 5 if x else 2 +# (But not a mix of the two) +testlist_safe: old_test [(',' old_test)+ [',']] +old_test: or_test | old_lambdef +old_lambdef: 'lambda' [varargslist] ':' old_test + +test: or_test ['if' or_test 'else' test] | lambdef +or_test: and_test ('or' and_test)* +and_test: not_test ('and' not_test)* +not_test: 'not' not_test | comparison +comparison: expr (comp_op expr)* +comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' +star_expr: '*' expr +expr: xor_expr ('|' xor_expr)* +xor_expr: and_expr ('^' and_expr)* +and_expr: shift_expr ('&' shift_expr)* +shift_expr: arith_expr (('<<'|'>>') arith_expr)* +arith_expr: term (('+'|'-') term)* +term: factor (('*'|'/'|'%'|'//') factor)* +factor: ('+'|'-'|'~') factor | power +power: atom trailer* ['**' factor] +atom: ('(' [yield_expr|testlist_gexp] ')' | + '[' [listmaker] ']' | + '{' [dictsetmaker] '}' | + '`' testlist1 '`' | + NAME | NUMBER | STRING+ | '.' '.' '.') +listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) +testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) +lambdef: 'lambda' [varargslist] ':' test +trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME +subscriptlist: subscript (',' subscript)* [','] +subscript: test | [test] ':' [test] [sliceop] +sliceop: ':' [test] +exprlist: (expr|star_expr) (',' (expr|star_expr))* [','] +testlist: test (',' test)* [','] +dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) | + (test (comp_for | (',' test)* [','])) ) + +classdef: 'class' NAME ['(' [arglist] ')'] ':' suite + +arglist: (argument ',')* (argument [','] + |'*' test (',' argument)* [',' '**' test] + |'**' test) +argument: test [comp_for] | test '=' test # Really [keyword '='] test + +comp_iter: comp_for | comp_if +comp_for: 'for' exprlist 'in' testlist_safe [comp_iter] +comp_if: 'if' old_test [comp_iter] + +testlist1: test (',' test)* + +# not used in grammar, but may appear in "node" passed from Parser to Compiler +encoding_decl: NAME + +yield_expr: 'yield' [testlist] diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/PatternGrammar.txt b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/PatternGrammar.txt new file mode 100644 index 0000000..36bf814 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/PatternGrammar.txt @@ -0,0 +1,28 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +# A grammar to describe tree matching patterns. +# Not shown here: +# - 'TOKEN' stands for any token (leaf node) +# - 'any' stands for any node (leaf or interior) +# With 'any' we can still specify the sub-structure. + +# The start symbol is 'Matcher'. + +Matcher: Alternatives ENDMARKER + +Alternatives: Alternative ('|' Alternative)* + +Alternative: (Unit | NegatedUnit)+ + +Unit: [NAME '='] ( STRING [Repeater] + | NAME [Details] [Repeater] + | '(' Alternatives ')' [Repeater] + | '[' Alternatives ']' + ) + +NegatedUnit: 'not' (STRING | NAME [Details] | '(' Alternatives ')') + +Repeater: '*' | '+' | '{' NUMBER [',' NUMBER] '}' + +Details: '<' Alternatives '>' diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/__init__.py new file mode 100644 index 0000000..ea30561 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/__init__.py @@ -0,0 +1 @@ +#empty diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/__main__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/__main__.py new file mode 100644 index 0000000..80688ba --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/__main__.py @@ -0,0 +1,4 @@ +import sys +from .main import main + +sys.exit(main("lib2to3.fixes")) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/btm_matcher.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/btm_matcher.py new file mode 100644 index 0000000..736ba2b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/btm_matcher.py @@ -0,0 +1,168 @@ +"""A bottom-up tree matching algorithm implementation meant to speed +up 2to3's matching process. After the tree patterns are reduced to +their rarest linear path, a linear Aho-Corasick automaton is +created. The linear automaton traverses the linear paths from the +leaves to the root of the AST and returns a set of nodes for further +matching. This reduces significantly the number of candidate nodes.""" + +__author__ = "George Boutsioukis " + +import logging +import itertools +from collections import defaultdict + +from . import pytree +from .btm_utils import reduce_tree + +class BMNode(object): + """Class for a node of the Aho-Corasick automaton used in matching""" + count = itertools.count() + def __init__(self): + self.transition_table = {} + self.fixers = [] + self.id = next(BMNode.count) + self.content = '' + +class BottomMatcher(object): + """The main matcher class. After instantiating the patterns should + be added using the add_fixer method""" + + def __init__(self): + self.match = set() + self.root = BMNode() + self.nodes = [self.root] + self.fixers = [] + self.logger = logging.getLogger("RefactoringTool") + + def add_fixer(self, fixer): + """Reduces a fixer's pattern tree to a linear path and adds it + to the matcher(a common Aho-Corasick automaton). The fixer is + appended on the matching states and called when they are + reached""" + self.fixers.append(fixer) + tree = reduce_tree(fixer.pattern_tree) + linear = tree.get_linear_subpattern() + match_nodes = self.add(linear, start=self.root) + for match_node in match_nodes: + match_node.fixers.append(fixer) + + def add(self, pattern, start): + "Recursively adds a linear pattern to the AC automaton" + #print("adding pattern", pattern, "to", start) + if not pattern: + #print("empty pattern") + return [start] + if isinstance(pattern[0], tuple): + #alternatives + #print("alternatives") + match_nodes = [] + for alternative in pattern[0]: + #add all alternatives, and add the rest of the pattern + #to each end node + end_nodes = self.add(alternative, start=start) + for end in end_nodes: + match_nodes.extend(self.add(pattern[1:], end)) + return match_nodes + else: + #single token + #not last + if pattern[0] not in start.transition_table: + #transition did not exist, create new + next_node = BMNode() + start.transition_table[pattern[0]] = next_node + else: + #transition exists already, follow + next_node = start.transition_table[pattern[0]] + + if pattern[1:]: + end_nodes = self.add(pattern[1:], start=next_node) + else: + end_nodes = [next_node] + return end_nodes + + def run(self, leaves): + """The main interface with the bottom matcher. The tree is + traversed from the bottom using the constructed + automaton. Nodes are only checked once as the tree is + retraversed. When the automaton fails, we give it one more + shot(in case the above tree matches as a whole with the + rejected leaf), then we break for the next leaf. There is the + special case of multiple arguments(see code comments) where we + recheck the nodes + + Args: + The leaves of the AST tree to be matched + + Returns: + A dictionary of node matches with fixers as the keys + """ + current_ac_node = self.root + results = defaultdict(list) + for leaf in leaves: + current_ast_node = leaf + while current_ast_node: + current_ast_node.was_checked = True + for child in current_ast_node.children: + # multiple statements, recheck + if isinstance(child, pytree.Leaf) and child.value == u";": + current_ast_node.was_checked = False + break + if current_ast_node.type == 1: + #name + node_token = current_ast_node.value + else: + node_token = current_ast_node.type + + if node_token in current_ac_node.transition_table: + #token matches + current_ac_node = current_ac_node.transition_table[node_token] + for fixer in current_ac_node.fixers: + if not fixer in results: + results[fixer] = [] + results[fixer].append(current_ast_node) + + else: + #matching failed, reset automaton + current_ac_node = self.root + if (current_ast_node.parent is not None + and current_ast_node.parent.was_checked): + #the rest of the tree upwards has been checked, next leaf + break + + #recheck the rejected node once from the root + if node_token in current_ac_node.transition_table: + #token matches + current_ac_node = current_ac_node.transition_table[node_token] + for fixer in current_ac_node.fixers: + if not fixer in results.keys(): + results[fixer] = [] + results[fixer].append(current_ast_node) + + current_ast_node = current_ast_node.parent + return results + + def print_ac(self): + "Prints a graphviz diagram of the BM automaton(for debugging)" + print("digraph g{") + def print_node(node): + for subnode_key in node.transition_table.keys(): + subnode = node.transition_table[subnode_key] + print("%d -> %d [label=%s] //%s" % + (node.id, subnode.id, type_repr(subnode_key), str(subnode.fixers))) + if subnode_key == 1: + print(subnode.content) + print_node(subnode) + print_node(self.root) + print("}") + +# taken from pytree.py for debugging; only used by print_ac +_type_reprs = {} +def type_repr(type_num): + global _type_reprs + if not _type_reprs: + from .pygram import python_symbols + # printing tokens is possible but not as useful + # from .pgen2 import token // token.__dict__.items(): + for name, val in python_symbols.__dict__.items(): + if type(val) == int: _type_reprs[val] = name + return _type_reprs.setdefault(type_num, type_num) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/btm_utils.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/btm_utils.py new file mode 100644 index 0000000..2276dc9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/btm_utils.py @@ -0,0 +1,283 @@ +"Utility functions used by the btm_matcher module" + +from . import pytree +from .pgen2 import grammar, token +from .pygram import pattern_symbols, python_symbols + +syms = pattern_symbols +pysyms = python_symbols +tokens = grammar.opmap +token_labels = token + +TYPE_ANY = -1 +TYPE_ALTERNATIVES = -2 +TYPE_GROUP = -3 + +class MinNode(object): + """This class serves as an intermediate representation of the + pattern tree during the conversion to sets of leaf-to-root + subpatterns""" + + def __init__(self, type=None, name=None): + self.type = type + self.name = name + self.children = [] + self.leaf = False + self.parent = None + self.alternatives = [] + self.group = [] + + def __repr__(self): + return str(self.type) + ' ' + str(self.name) + + def leaf_to_root(self): + """Internal method. Returns a characteristic path of the + pattern tree. This method must be run for all leaves until the + linear subpatterns are merged into a single""" + node = self + subp = [] + while node: + if node.type == TYPE_ALTERNATIVES: + node.alternatives.append(subp) + if len(node.alternatives) == len(node.children): + #last alternative + subp = [tuple(node.alternatives)] + node.alternatives = [] + node = node.parent + continue + else: + node = node.parent + subp = None + break + + if node.type == TYPE_GROUP: + node.group.append(subp) + #probably should check the number of leaves + if len(node.group) == len(node.children): + subp = get_characteristic_subpattern(node.group) + node.group = [] + node = node.parent + continue + else: + node = node.parent + subp = None + break + + if node.type == token_labels.NAME and node.name: + #in case of type=name, use the name instead + subp.append(node.name) + else: + subp.append(node.type) + + node = node.parent + return subp + + def get_linear_subpattern(self): + """Drives the leaf_to_root method. The reason that + leaf_to_root must be run multiple times is because we need to + reject 'group' matches; for example the alternative form + (a | b c) creates a group [b c] that needs to be matched. Since + matching multiple linear patterns overcomes the automaton's + capabilities, leaf_to_root merges each group into a single + choice based on 'characteristic'ity, + + i.e. (a|b c) -> (a|b) if b more characteristic than c + + Returns: The most 'characteristic'(as defined by + get_characteristic_subpattern) path for the compiled pattern + tree. + """ + + for l in self.leaves(): + subp = l.leaf_to_root() + if subp: + return subp + + def leaves(self): + "Generator that returns the leaves of the tree" + for child in self.children: + for x in child.leaves(): + yield x + if not self.children: + yield self + +def reduce_tree(node, parent=None): + """ + Internal function. Reduces a compiled pattern tree to an + intermediate representation suitable for feeding the + automaton. This also trims off any optional pattern elements(like + [a], a*). + """ + + new_node = None + #switch on the node type + if node.type == syms.Matcher: + #skip + node = node.children[0] + + if node.type == syms.Alternatives : + #2 cases + if len(node.children) <= 2: + #just a single 'Alternative', skip this node + new_node = reduce_tree(node.children[0], parent) + else: + #real alternatives + new_node = MinNode(type=TYPE_ALTERNATIVES) + #skip odd children('|' tokens) + for child in node.children: + if node.children.index(child)%2: + continue + reduced = reduce_tree(child, new_node) + if reduced is not None: + new_node.children.append(reduced) + elif node.type == syms.Alternative: + if len(node.children) > 1: + + new_node = MinNode(type=TYPE_GROUP) + for child in node.children: + reduced = reduce_tree(child, new_node) + if reduced: + new_node.children.append(reduced) + if not new_node.children: + # delete the group if all of the children were reduced to None + new_node = None + + else: + new_node = reduce_tree(node.children[0], parent) + + elif node.type == syms.Unit: + if (isinstance(node.children[0], pytree.Leaf) and + node.children[0].value == '('): + #skip parentheses + return reduce_tree(node.children[1], parent) + if ((isinstance(node.children[0], pytree.Leaf) and + node.children[0].value == '[') + or + (len(node.children)>1 and + hasattr(node.children[1], "value") and + node.children[1].value == '[')): + #skip whole unit if its optional + return None + + leaf = True + details_node = None + alternatives_node = None + has_repeater = False + repeater_node = None + has_variable_name = False + + for child in node.children: + if child.type == syms.Details: + leaf = False + details_node = child + elif child.type == syms.Repeater: + has_repeater = True + repeater_node = child + elif child.type == syms.Alternatives: + alternatives_node = child + if hasattr(child, 'value') and child.value == '=': # variable name + has_variable_name = True + + #skip variable name + if has_variable_name: + #skip variable name, '=' + name_leaf = node.children[2] + if hasattr(name_leaf, 'value') and name_leaf.value == '(': + # skip parenthesis + name_leaf = node.children[3] + else: + name_leaf = node.children[0] + + #set node type + if name_leaf.type == token_labels.NAME: + #(python) non-name or wildcard + if name_leaf.value == 'any': + new_node = MinNode(type=TYPE_ANY) + else: + if hasattr(token_labels, name_leaf.value): + new_node = MinNode(type=getattr(token_labels, name_leaf.value)) + else: + new_node = MinNode(type=getattr(pysyms, name_leaf.value)) + + elif name_leaf.type == token_labels.STRING: + #(python) name or character; remove the apostrophes from + #the string value + name = name_leaf.value.strip("'") + if name in tokens: + new_node = MinNode(type=tokens[name]) + else: + new_node = MinNode(type=token_labels.NAME, name=name) + elif name_leaf.type == syms.Alternatives: + new_node = reduce_tree(alternatives_node, parent) + + #handle repeaters + if has_repeater: + if repeater_node.children[0].value == '*': + #reduce to None + new_node = None + elif repeater_node.children[0].value == '+': + #reduce to a single occurence i.e. do nothing + pass + else: + #TODO: handle {min, max} repeaters + raise NotImplementedError + pass + + #add children + if details_node and new_node is not None: + for child in details_node.children[1:-1]: + #skip '<', '>' markers + reduced = reduce_tree(child, new_node) + if reduced is not None: + new_node.children.append(reduced) + if new_node: + new_node.parent = parent + return new_node + + +def get_characteristic_subpattern(subpatterns): + """Picks the most characteristic from a list of linear patterns + Current order used is: + names > common_names > common_chars + """ + if not isinstance(subpatterns, list): + return subpatterns + if len(subpatterns)==1: + return subpatterns[0] + + # first pick out the ones containing variable names + subpatterns_with_names = [] + subpatterns_with_common_names = [] + common_names = ['in', 'for', 'if' , 'not', 'None'] + subpatterns_with_common_chars = [] + common_chars = "[]().,:" + for subpattern in subpatterns: + if any(rec_test(subpattern, lambda x: type(x) is str)): + if any(rec_test(subpattern, + lambda x: isinstance(x, str) and x in common_chars)): + subpatterns_with_common_chars.append(subpattern) + elif any(rec_test(subpattern, + lambda x: isinstance(x, str) and x in common_names)): + subpatterns_with_common_names.append(subpattern) + + else: + subpatterns_with_names.append(subpattern) + + if subpatterns_with_names: + subpatterns = subpatterns_with_names + elif subpatterns_with_common_names: + subpatterns = subpatterns_with_common_names + elif subpatterns_with_common_chars: + subpatterns = subpatterns_with_common_chars + # of the remaining subpatterns pick out the longest one + return max(subpatterns, key=len) + +def rec_test(sequence, test_func): + """Tests test_func on all items of sequence and items of included + sub-iterables""" + for x in sequence: + if isinstance(x, (list, tuple)): + for y in rec_test(x, test_func): + yield y + else: + yield test_func(x) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixer_base.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixer_base.py new file mode 100644 index 0000000..f6421ba --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixer_base.py @@ -0,0 +1,189 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Base class for fixers (optional, but recommended).""" + +# Python imports +import logging +import itertools + +# Local imports +from .patcomp import PatternCompiler +from . import pygram +from .fixer_util import does_tree_import + +class BaseFix(object): + + """Optional base class for fixers. + + The subclass name must be FixFooBar where FooBar is the result of + removing underscores and capitalizing the words of the fix name. + For example, the class name for a fixer named 'has_key' should be + FixHasKey. + """ + + PATTERN = None # Most subclasses should override with a string literal + pattern = None # Compiled pattern, set by compile_pattern() + pattern_tree = None # Tree representation of the pattern + options = None # Options object passed to initializer + filename = None # The filename (set by set_filename) + logger = None # A logger (set by set_filename) + numbers = itertools.count(1) # For new_name() + used_names = set() # A set of all used NAMEs + order = "post" # Does the fixer prefer pre- or post-order traversal + explicit = False # Is this ignored by refactor.py -f all? + run_order = 5 # Fixers will be sorted by run order before execution + # Lower numbers will be run first. + _accept_type = None # [Advanced and not public] This tells RefactoringTool + # which node type to accept when there's not a pattern. + + keep_line_order = False # For the bottom matcher: match with the + # original line order + BM_compatible = False # Compatibility with the bottom matching + # module; every fixer should set this + # manually + + # Shortcut for access to Python grammar symbols + syms = pygram.python_symbols + + def __init__(self, options, log): + """Initializer. Subclass may override. + + Args: + options: an dict containing the options passed to RefactoringTool + that could be used to customize the fixer through the command line. + log: a list to append warnings and other messages to. + """ + self.options = options + self.log = log + self.compile_pattern() + + def compile_pattern(self): + """Compiles self.PATTERN into self.pattern. + + Subclass may override if it doesn't want to use + self.{pattern,PATTERN} in .match(). + """ + if self.PATTERN is not None: + PC = PatternCompiler() + self.pattern, self.pattern_tree = PC.compile_pattern(self.PATTERN, + with_tree=True) + + def set_filename(self, filename): + """Set the filename, and a logger derived from it. + + The main refactoring tool should call this. + """ + self.filename = filename + self.logger = logging.getLogger(filename) + + def match(self, node): + """Returns match for a given parse tree node. + + Should return a true or false object (not necessarily a bool). + It may return a non-empty dict of matching sub-nodes as + returned by a matching pattern. + + Subclass may override. + """ + results = {"node": node} + return self.pattern.match(node, results) and results + + def transform(self, node, results): + """Returns the transformation for a given parse tree node. + + Args: + node: the root of the parse tree that matched the fixer. + results: a dict mapping symbolic names to part of the match. + + Returns: + None, or a node that is a modified copy of the + argument node. The node argument may also be modified in-place to + effect the same change. + + Subclass *must* override. + """ + raise NotImplementedError() + + def new_name(self, template=u"xxx_todo_changeme"): + """Return a string suitable for use as an identifier + + The new name is guaranteed not to conflict with other identifiers. + """ + name = template + while name in self.used_names: + name = template + unicode(self.numbers.next()) + self.used_names.add(name) + return name + + def log_message(self, message): + if self.first_log: + self.first_log = False + self.log.append("### In file %s ###" % self.filename) + self.log.append(message) + + def cannot_convert(self, node, reason=None): + """Warn the user that a given chunk of code is not valid Python 3, + but that it cannot be converted automatically. + + First argument is the top-level node for the code in question. + Optional second argument is why it can't be converted. + """ + lineno = node.get_lineno() + for_output = node.clone() + for_output.prefix = u"" + msg = "Line %d: could not convert: %s" + self.log_message(msg % (lineno, for_output)) + if reason: + self.log_message(reason) + + def warning(self, node, reason): + """Used for warning the user about possible uncertainty in the + translation. + + First argument is the top-level node for the code in question. + Optional second argument is why it can't be converted. + """ + lineno = node.get_lineno() + self.log_message("Line %d: %s" % (lineno, reason)) + + def start_tree(self, tree, filename): + """Some fixers need to maintain tree-wide state. + This method is called once, at the start of tree fix-up. + + tree - the root node of the tree to be processed. + filename - the name of the file the tree came from. + """ + self.used_names = tree.used_names + self.set_filename(filename) + self.numbers = itertools.count(1) + self.first_log = True + + def finish_tree(self, tree, filename): + """Some fixers need to maintain tree-wide state. + This method is called once, at the conclusion of tree fix-up. + + tree - the root node of the tree to be processed. + filename - the name of the file the tree came from. + """ + pass + + +class ConditionalFix(BaseFix): + """ Base class for fixers which not execute if an import is found. """ + + # This is the name of the import which, if found, will cause the test to be skipped + skip_on = None + + def start_tree(self, *args): + super(ConditionalFix, self).start_tree(*args) + self._should_skip = None + + def should_skip(self, node): + if self._should_skip is not None: + return self._should_skip + pkg = self.skip_on.split(".") + name = pkg[-1] + pkg = ".".join(pkg[:-1]) + self._should_skip = does_tree_import(pkg, name, node) + return self._should_skip diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixer_util.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixer_util.py new file mode 100644 index 0000000..78fdf26 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixer_util.py @@ -0,0 +1,432 @@ +"""Utility functions, node construction macros, etc.""" +# Author: Collin Winter + +from itertools import islice + +# Local imports +from .pgen2 import token +from .pytree import Leaf, Node +from .pygram import python_symbols as syms +from . import patcomp + + +########################################################### +### Common node-construction "macros" +########################################################### + +def KeywordArg(keyword, value): + return Node(syms.argument, + [keyword, Leaf(token.EQUAL, u"="), value]) + +def LParen(): + return Leaf(token.LPAR, u"(") + +def RParen(): + return Leaf(token.RPAR, u")") + +def Assign(target, source): + """Build an assignment statement""" + if not isinstance(target, list): + target = [target] + if not isinstance(source, list): + source.prefix = u" " + source = [source] + + return Node(syms.atom, + target + [Leaf(token.EQUAL, u"=", prefix=u" ")] + source) + +def Name(name, prefix=None): + """Return a NAME leaf""" + return Leaf(token.NAME, name, prefix=prefix) + +def Attr(obj, attr): + """A node tuple for obj.attr""" + return [obj, Node(syms.trailer, [Dot(), attr])] + +def Comma(): + """A comma leaf""" + return Leaf(token.COMMA, u",") + +def Dot(): + """A period (.) leaf""" + return Leaf(token.DOT, u".") + +def ArgList(args, lparen=LParen(), rparen=RParen()): + """A parenthesised argument list, used by Call()""" + node = Node(syms.trailer, [lparen.clone(), rparen.clone()]) + if args: + node.insert_child(1, Node(syms.arglist, args)) + return node + +def Call(func_name, args=None, prefix=None): + """A function call""" + node = Node(syms.power, [func_name, ArgList(args)]) + if prefix is not None: + node.prefix = prefix + return node + +def Newline(): + """A newline literal""" + return Leaf(token.NEWLINE, u"\n") + +def BlankLine(): + """A blank line""" + return Leaf(token.NEWLINE, u"") + +def Number(n, prefix=None): + return Leaf(token.NUMBER, n, prefix=prefix) + +def Subscript(index_node): + """A numeric or string subscript""" + return Node(syms.trailer, [Leaf(token.LBRACE, u"["), + index_node, + Leaf(token.RBRACE, u"]")]) + +def String(string, prefix=None): + """A string leaf""" + return Leaf(token.STRING, string, prefix=prefix) + +def ListComp(xp, fp, it, test=None): + """A list comprehension of the form [xp for fp in it if test]. + + If test is None, the "if test" part is omitted. + """ + xp.prefix = u"" + fp.prefix = u" " + it.prefix = u" " + for_leaf = Leaf(token.NAME, u"for") + for_leaf.prefix = u" " + in_leaf = Leaf(token.NAME, u"in") + in_leaf.prefix = u" " + inner_args = [for_leaf, fp, in_leaf, it] + if test: + test.prefix = u" " + if_leaf = Leaf(token.NAME, u"if") + if_leaf.prefix = u" " + inner_args.append(Node(syms.comp_if, [if_leaf, test])) + inner = Node(syms.listmaker, [xp, Node(syms.comp_for, inner_args)]) + return Node(syms.atom, + [Leaf(token.LBRACE, u"["), + inner, + Leaf(token.RBRACE, u"]")]) + +def FromImport(package_name, name_leafs): + """ Return an import statement in the form: + from package import name_leafs""" + # XXX: May not handle dotted imports properly (eg, package_name='foo.bar') + #assert package_name == '.' or '.' not in package_name, "FromImport has "\ + # "not been tested with dotted package names -- use at your own "\ + # "peril!" + + for leaf in name_leafs: + # Pull the leaves out of their old tree + leaf.remove() + + children = [Leaf(token.NAME, u"from"), + Leaf(token.NAME, package_name, prefix=u" "), + Leaf(token.NAME, u"import", prefix=u" "), + Node(syms.import_as_names, name_leafs)] + imp = Node(syms.import_from, children) + return imp + + +########################################################### +### Determine whether a node represents a given literal +########################################################### + +def is_tuple(node): + """Does the node represent a tuple literal?""" + if isinstance(node, Node) and node.children == [LParen(), RParen()]: + return True + return (isinstance(node, Node) + and len(node.children) == 3 + and isinstance(node.children[0], Leaf) + and isinstance(node.children[1], Node) + and isinstance(node.children[2], Leaf) + and node.children[0].value == u"(" + and node.children[2].value == u")") + +def is_list(node): + """Does the node represent a list literal?""" + return (isinstance(node, Node) + and len(node.children) > 1 + and isinstance(node.children[0], Leaf) + and isinstance(node.children[-1], Leaf) + and node.children[0].value == u"[" + and node.children[-1].value == u"]") + + +########################################################### +### Misc +########################################################### + +def parenthesize(node): + return Node(syms.atom, [LParen(), node, RParen()]) + + +consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum", + "min", "max", "enumerate"]) + +def attr_chain(obj, attr): + """Follow an attribute chain. + + If you have a chain of objects where a.foo -> b, b.foo-> c, etc, + use this to iterate over all objects in the chain. Iteration is + terminated by getattr(x, attr) is None. + + Args: + obj: the starting object + attr: the name of the chaining attribute + + Yields: + Each successive object in the chain. + """ + next = getattr(obj, attr) + while next: + yield next + next = getattr(next, attr) + +p0 = """for_stmt< 'for' any 'in' node=any ':' any* > + | comp_for< 'for' any 'in' node=any any* > + """ +p1 = """ +power< + ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' | + 'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) ) + trailer< '(' node=any ')' > + any* +> +""" +p2 = """ +power< + ( 'sorted' | 'enumerate' ) + trailer< '(' arglist ')' > + any* +> +""" +pats_built = False +def in_special_context(node): + """ Returns true if node is in an environment where all that is required + of it is being iterable (ie, it doesn't matter if it returns a list + or an iterator). + See test_map_nochange in test_fixers.py for some examples and tests. + """ + global p0, p1, p2, pats_built + if not pats_built: + p0 = patcomp.compile_pattern(p0) + p1 = patcomp.compile_pattern(p1) + p2 = patcomp.compile_pattern(p2) + pats_built = True + patterns = [p0, p1, p2] + for pattern, parent in zip(patterns, attr_chain(node, "parent")): + results = {} + if pattern.match(parent, results) and results["node"] is node: + return True + return False + +def is_probably_builtin(node): + """ + Check that something isn't an attribute or function name etc. + """ + prev = node.prev_sibling + if prev is not None and prev.type == token.DOT: + # Attribute lookup. + return False + parent = node.parent + if parent.type in (syms.funcdef, syms.classdef): + return False + if parent.type == syms.expr_stmt and parent.children[0] is node: + # Assignment. + return False + if parent.type == syms.parameters or \ + (parent.type == syms.typedargslist and ( + (prev is not None and prev.type == token.COMMA) or + parent.children[0] is node + )): + # The name of an argument. + return False + return True + +def find_indentation(node): + """Find the indentation of *node*.""" + while node is not None: + if node.type == syms.suite and len(node.children) > 2: + indent = node.children[1] + if indent.type == token.INDENT: + return indent.value + node = node.parent + return u"" + +########################################################### +### The following functions are to find bindings in a suite +########################################################### + +def make_suite(node): + if node.type == syms.suite: + return node + node = node.clone() + parent, node.parent = node.parent, None + suite = Node(syms.suite, [node]) + suite.parent = parent + return suite + +def find_root(node): + """Find the top level namespace.""" + # Scamper up to the top level namespace + while node.type != syms.file_input: + node = node.parent + if not node: + raise ValueError("root found before file_input node was found.") + return node + +def does_tree_import(package, name, node): + """ Returns true if name is imported from package at the + top level of the tree which node belongs to. + To cover the case of an import like 'import foo', use + None for the package and 'foo' for the name. """ + binding = find_binding(name, find_root(node), package) + return bool(binding) + +def is_import(node): + """Returns true if the node is an import statement.""" + return node.type in (syms.import_name, syms.import_from) + +def touch_import(package, name, node): + """ Works like `does_tree_import` but adds an import statement + if it was not imported. """ + def is_import_stmt(node): + return (node.type == syms.simple_stmt and node.children and + is_import(node.children[0])) + + root = find_root(node) + + if does_tree_import(package, name, root): + return + + # figure out where to insert the new import. First try to find + # the first import and then skip to the last one. + insert_pos = offset = 0 + for idx, node in enumerate(root.children): + if not is_import_stmt(node): + continue + for offset, node2 in enumerate(root.children[idx:]): + if not is_import_stmt(node2): + break + insert_pos = idx + offset + break + + # if there are no imports where we can insert, find the docstring. + # if that also fails, we stick to the beginning of the file + if insert_pos == 0: + for idx, node in enumerate(root.children): + if (node.type == syms.simple_stmt and node.children and + node.children[0].type == token.STRING): + insert_pos = idx + 1 + break + + if package is None: + import_ = Node(syms.import_name, [ + Leaf(token.NAME, u"import"), + Leaf(token.NAME, name, prefix=u" ") + ]) + else: + import_ = FromImport(package, [Leaf(token.NAME, name, prefix=u" ")]) + + children = [import_, Newline()] + root.insert_child(insert_pos, Node(syms.simple_stmt, children)) + + +_def_syms = set([syms.classdef, syms.funcdef]) +def find_binding(name, node, package=None): + """ Returns the node which binds variable name, otherwise None. + If optional argument package is supplied, only imports will + be returned. + See test cases for examples.""" + for child in node.children: + ret = None + if child.type == syms.for_stmt: + if _find(name, child.children[1]): + return child + n = find_binding(name, make_suite(child.children[-1]), package) + if n: ret = n + elif child.type in (syms.if_stmt, syms.while_stmt): + n = find_binding(name, make_suite(child.children[-1]), package) + if n: ret = n + elif child.type == syms.try_stmt: + n = find_binding(name, make_suite(child.children[2]), package) + if n: + ret = n + else: + for i, kid in enumerate(child.children[3:]): + if kid.type == token.COLON and kid.value == ":": + # i+3 is the colon, i+4 is the suite + n = find_binding(name, make_suite(child.children[i+4]), package) + if n: ret = n + elif child.type in _def_syms and child.children[1].value == name: + ret = child + elif _is_import_binding(child, name, package): + ret = child + elif child.type == syms.simple_stmt: + ret = find_binding(name, child, package) + elif child.type == syms.expr_stmt: + if _find(name, child.children[0]): + ret = child + + if ret: + if not package: + return ret + if is_import(ret): + return ret + return None + +_block_syms = set([syms.funcdef, syms.classdef, syms.trailer]) +def _find(name, node): + nodes = [node] + while nodes: + node = nodes.pop() + if node.type > 256 and node.type not in _block_syms: + nodes.extend(node.children) + elif node.type == token.NAME and node.value == name: + return node + return None + +def _is_import_binding(node, name, package=None): + """ Will reuturn node if node will import name, or node + will import * from package. None is returned otherwise. + See test cases for examples. """ + + if node.type == syms.import_name and not package: + imp = node.children[1] + if imp.type == syms.dotted_as_names: + for child in imp.children: + if child.type == syms.dotted_as_name: + if child.children[2].value == name: + return node + elif child.type == token.NAME and child.value == name: + return node + elif imp.type == syms.dotted_as_name: + last = imp.children[-1] + if last.type == token.NAME and last.value == name: + return node + elif imp.type == token.NAME and imp.value == name: + return node + elif node.type == syms.import_from: + # unicode(...) is used to make life easier here, because + # from a.b import parses to ['import', ['a', '.', 'b'], ...] + if package and unicode(node.children[1]).strip() != package: + return None + n = node.children[3] + if package and _find(u"as", n): + # See test_from_import_as for explanation + return None + elif n.type == syms.import_as_names and _find(name, n): + return node + elif n.type == syms.import_as_name: + child = n.children[2] + if child.type == token.NAME and child.value == name: + return node + elif n.type == token.NAME and n.value == name: + return node + elif package and n.type == token.STAR: + return node + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/__init__.py new file mode 100644 index 0000000..b93054b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/__init__.py @@ -0,0 +1 @@ +# Dummy file to make this directory a package. diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_apply.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_apply.py new file mode 100644 index 0000000..a7dc3a0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_apply.py @@ -0,0 +1,59 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for apply(). + +This converts apply(func, v, k) into (func)(*v, **k).""" + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Call, Comma, parenthesize + +class FixApply(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + power< 'apply' + trailer< + '(' + arglist< + (not argument + ')' + > + > + """ + + def transform(self, node, results): + syms = self.syms + assert results + func = results["func"] + args = results["args"] + kwds = results.get("kwds") + prefix = node.prefix + func = func.clone() + if (func.type not in (token.NAME, syms.atom) and + (func.type != syms.power or + func.children[-2].type == token.DOUBLESTAR)): + # Need to parenthesize + func = parenthesize(func) + func.prefix = "" + args = args.clone() + args.prefix = "" + if kwds is not None: + kwds = kwds.clone() + kwds.prefix = "" + l_newargs = [pytree.Leaf(token.STAR, u"*"), args] + if kwds is not None: + l_newargs.extend([Comma(), + pytree.Leaf(token.DOUBLESTAR, u"**"), + kwds]) + l_newargs[-2].prefix = u" " # that's the ** token + # XXX Sometimes we could be cleverer, e.g. apply(f, (x, y) + t) + # can be translated into f(x, y, *t) instead of f(*(x, y) + t) + #new = pytree.Node(syms.power, (func, ArgList(l_newargs))) + return Call(func, l_newargs, prefix=prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_basestring.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_basestring.py new file mode 100644 index 0000000..a3c9a43 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_basestring.py @@ -0,0 +1,14 @@ +"""Fixer for basestring -> str.""" +# Author: Christian Heimes + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + +class FixBasestring(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = "'basestring'" + + def transform(self, node, results): + return Name(u"str", prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_buffer.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_buffer.py new file mode 100644 index 0000000..c6b0928 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_buffer.py @@ -0,0 +1,22 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that changes buffer(...) into memoryview(...).""" + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + + +class FixBuffer(fixer_base.BaseFix): + BM_compatible = True + + explicit = True # The user must ask for this fixer + + PATTERN = """ + power< name='buffer' trailer< '(' [any] ')' > any* > + """ + + def transform(self, node, results): + name = results["name"] + name.replace(Name(u"memoryview", prefix=name.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_callable.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_callable.py new file mode 100644 index 0000000..df33d61 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_callable.py @@ -0,0 +1,37 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for callable(). + +This converts callable(obj) into isinstance(obj, collections.Callable), adding a +collections import if needed.""" + +# Local imports +from lib2to3 import fixer_base +from lib2to3.fixer_util import Call, Name, String, Attr, touch_import + +class FixCallable(fixer_base.BaseFix): + BM_compatible = True + + order = "pre" + + # Ignore callable(*args) or use of keywords. + # Either could be a hint that the builtin callable() is not being used. + PATTERN = """ + power< 'callable' + trailer< lpar='(' + ( not(arglist | argument) any ','> ) + rpar=')' > + after=any* + > + """ + + def transform(self, node, results): + func = results['func'] + + touch_import(None, u'collections', node=node) + + args = [func.clone(), String(u', ')] + args.extend(Attr(Name(u'collections'), Name(u'Callable'))) + return Call(Name(u'isinstance'), args, prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_dict.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_dict.py new file mode 100644 index 0000000..f681e4d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_dict.py @@ -0,0 +1,107 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for dict methods. + +d.keys() -> list(d.keys()) +d.items() -> list(d.items()) +d.values() -> list(d.values()) + +d.iterkeys() -> iter(d.keys()) +d.iteritems() -> iter(d.items()) +d.itervalues() -> iter(d.values()) + +d.viewkeys() -> d.keys() +d.viewitems() -> d.items() +d.viewvalues() -> d.values() + +Except in certain very specific contexts: the iter() can be dropped +when the context is list(), sorted(), iter() or for...in; the list() +can be dropped when the context is list() or sorted() (but not iter() +or for...in!). Special contexts that apply to both: list(), sorted(), tuple() +set(), any(), all(), sum(). + +Note: iter(d.keys()) could be written as iter(d) but since the +original d.iterkeys() was also redundant we don't fix this. And there +are (rare) contexts where it makes a difference (e.g. when passing it +as an argument to a function that introspects the argument). +""" + +# Local imports +from .. import pytree +from .. import patcomp +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot +from .. import fixer_util + + +iter_exempt = fixer_util.consuming_calls | set(["iter"]) + + +class FixDict(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + power< head=any+ + trailer< '.' method=('keys'|'items'|'values'| + 'iterkeys'|'iteritems'|'itervalues'| + 'viewkeys'|'viewitems'|'viewvalues') > + parens=trailer< '(' ')' > + tail=any* + > + """ + + def transform(self, node, results): + head = results["head"] + method = results["method"][0] # Extract node for method name + tail = results["tail"] + syms = self.syms + method_name = method.value + isiter = method_name.startswith(u"iter") + isview = method_name.startswith(u"view") + if isiter or isview: + method_name = method_name[4:] + assert method_name in (u"keys", u"items", u"values"), repr(method) + head = [n.clone() for n in head] + tail = [n.clone() for n in tail] + special = not tail and self.in_special_context(node, isiter) + args = head + [pytree.Node(syms.trailer, + [Dot(), + Name(method_name, + prefix=method.prefix)]), + results["parens"].clone()] + new = pytree.Node(syms.power, args) + if not (special or isview): + new.prefix = u"" + new = Call(Name(u"iter" if isiter else u"list"), [new]) + if tail: + new = pytree.Node(syms.power, [new] + tail) + new.prefix = node.prefix + return new + + P1 = "power< func=NAME trailer< '(' node=any ')' > any* >" + p1 = patcomp.compile_pattern(P1) + + P2 = """for_stmt< 'for' any 'in' node=any ':' any* > + | comp_for< 'for' any 'in' node=any any* > + """ + p2 = patcomp.compile_pattern(P2) + + def in_special_context(self, node, isiter): + if node.parent is None: + return False + results = {} + if (node.parent.parent is not None and + self.p1.match(node.parent.parent, results) and + results["node"] is node): + if isiter: + # iter(d.iterkeys()) -> iter(d.keys()), etc. + return results["func"].value in iter_exempt + else: + # list(d.keys()) -> list(d.keys()), etc. + return results["func"].value in fixer_util.consuming_calls + if not isiter: + return False + # for ... in d.iterkeys() -> for ... in d.keys(), etc. + return self.p2.match(node.parent, results) and results["node"] is node diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_except.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_except.py new file mode 100644 index 0000000..e324718 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_except.py @@ -0,0 +1,93 @@ +"""Fixer for except statements with named exceptions. + +The following cases will be converted: + +- "except E, T:" where T is a name: + + except E as T: + +- "except E, T:" where T is not a name, tuple or list: + + except E as t: + T = t + + This is done because the target of an "except" clause must be a + name. + +- "except E, T:" where T is a tuple or list literal: + + except E as t: + T = t.args +""" +# Author: Collin Winter + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms + +def find_excepts(nodes): + for i, n in enumerate(nodes): + if n.type == syms.except_clause: + if n.children[0].value == u'except': + yield (n, nodes[i+2]) + +class FixExcept(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + try_stmt< 'try' ':' (simple_stmt | suite) + cleanup=(except_clause ':' (simple_stmt | suite))+ + tail=(['except' ':' (simple_stmt | suite)] + ['else' ':' (simple_stmt | suite)] + ['finally' ':' (simple_stmt | suite)]) > + """ + + def transform(self, node, results): + syms = self.syms + + tail = [n.clone() for n in results["tail"]] + + try_cleanup = [ch.clone() for ch in results["cleanup"]] + for except_clause, e_suite in find_excepts(try_cleanup): + if len(except_clause.children) == 4: + (E, comma, N) = except_clause.children[1:4] + comma.replace(Name(u"as", prefix=u" ")) + + if N.type != token.NAME: + # Generate a new N for the except clause + new_N = Name(self.new_name(), prefix=u" ") + target = N.clone() + target.prefix = u"" + N.replace(new_N) + new_N = new_N.clone() + + # Insert "old_N = new_N" as the first statement in + # the except body. This loop skips leading whitespace + # and indents + #TODO(cwinter) suite-cleanup + suite_stmts = e_suite.children + for i, stmt in enumerate(suite_stmts): + if isinstance(stmt, pytree.Node): + break + + # The assignment is different if old_N is a tuple or list + # In that case, the assignment is old_N = new_N.args + if is_tuple(N) or is_list(N): + assign = Assign(target, Attr(new_N, Name(u'args'))) + else: + assign = Assign(target, new_N) + + #TODO(cwinter) stopgap until children becomes a smart list + for child in reversed(suite_stmts[:i]): + e_suite.insert_child(0, child) + e_suite.insert_child(i, assign) + elif N.prefix == u"": + # No space after a comma is legal; no space after "as", + # not so much. + N.prefix = u" " + + #TODO(cwinter) fix this when children becomes a smart list + children = [c.clone() for c in node.children[:3]] + try_cleanup + tail + return pytree.Node(node.type, children) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_exec.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_exec.py new file mode 100644 index 0000000..50e1854 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_exec.py @@ -0,0 +1,40 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for exec. + +This converts usages of the exec statement into calls to a built-in +exec() function. + +exec code in ns1, ns2 -> exec(code, ns1, ns2) +""" + +# Local imports +from .. import pytree +from .. import fixer_base +from ..fixer_util import Comma, Name, Call + + +class FixExec(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + exec_stmt< 'exec' a=any 'in' b=any [',' c=any] > + | + exec_stmt< 'exec' (not atom<'(' [any] ')'>) a=any > + """ + + def transform(self, node, results): + assert results + syms = self.syms + a = results["a"] + b = results.get("b") + c = results.get("c") + args = [a.clone()] + args[0].prefix = "" + if b is not None: + args.extend([Comma(), b.clone()]) + if c is not None: + args.extend([Comma(), c.clone()]) + + return Call(Name(u"exec"), args, prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_execfile.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_execfile.py new file mode 100644 index 0000000..2f29d3b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_execfile.py @@ -0,0 +1,52 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for execfile. + +This converts usages of the execfile function into calls to the built-in +exec() function. +""" + +from .. import fixer_base +from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node, + ArgList, String, syms) + + +class FixExecfile(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + power< 'execfile' trailer< '(' arglist< filename=any [',' globals=any [',' locals=any ] ] > ')' > > + | + power< 'execfile' trailer< '(' filename=any ')' > > + """ + + def transform(self, node, results): + assert results + filename = results["filename"] + globals = results.get("globals") + locals = results.get("locals") + + # Copy over the prefix from the right parentheses end of the execfile + # call. + execfile_paren = node.children[-1].children[-1].clone() + # Construct open().read(). + open_args = ArgList([filename.clone()], rparen=execfile_paren) + open_call = Node(syms.power, [Name(u"open"), open_args]) + read = [Node(syms.trailer, [Dot(), Name(u'read')]), + Node(syms.trailer, [LParen(), RParen()])] + open_expr = [open_call] + read + # Wrap the open call in a compile call. This is so the filename will be + # preserved in the execed code. + filename_arg = filename.clone() + filename_arg.prefix = u" " + exec_str = String(u"'exec'", u" ") + compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str] + compile_call = Call(Name(u"compile"), compile_args, u"") + # Finally, replace the execfile call with an exec call. + args = [compile_call] + if globals is not None: + args.extend([Comma(), globals.clone()]) + if locals is not None: + args.extend([Comma(), locals.clone()]) + return Call(Name(u"exec"), args, prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_exitfunc.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_exitfunc.py new file mode 100644 index 0000000..89fb3db --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_exitfunc.py @@ -0,0 +1,72 @@ +""" +Convert use of sys.exitfunc to use the atexit module. +""" + +# Author: Benjamin Peterson + +from lib2to3 import pytree, fixer_base +from lib2to3.fixer_util import Name, Attr, Call, Comma, Newline, syms + + +class FixExitfunc(fixer_base.BaseFix): + keep_line_order = True + BM_compatible = True + + PATTERN = """ + ( + sys_import=import_name<'import' + ('sys' + | + dotted_as_names< (any ',')* 'sys' (',' any)* > + ) + > + | + expr_stmt< + power< 'sys' trailer< '.' 'exitfunc' > > + '=' func=any > + ) + """ + + def __init__(self, *args): + super(FixExitfunc, self).__init__(*args) + + def start_tree(self, tree, filename): + super(FixExitfunc, self).start_tree(tree, filename) + self.sys_import = None + + def transform(self, node, results): + # First, find a the sys import. We'll just hope it's global scope. + if "sys_import" in results: + if self.sys_import is None: + self.sys_import = results["sys_import"] + return + + func = results["func"].clone() + func.prefix = u"" + register = pytree.Node(syms.power, + Attr(Name(u"atexit"), Name(u"register")) + ) + call = Call(register, [func], node.prefix) + node.replace(call) + + if self.sys_import is None: + # That's interesting. + self.warning(node, "Can't find sys import; Please add an atexit " + "import at the top of your file.") + return + + # Now add an atexit import after the sys import. + names = self.sys_import.children[1] + if names.type == syms.dotted_as_names: + names.append_child(Comma()) + names.append_child(Name(u"atexit", u" ")) + else: + containing_stmt = self.sys_import.parent + position = containing_stmt.children.index(self.sys_import) + stmt_container = containing_stmt.parent + new_import = pytree.Node(syms.import_name, + [Name(u"import"), Name(u"atexit", u" ")] + ) + new = pytree.Node(syms.simple_stmt, [new_import]) + containing_stmt.insert_child(position + 1, Newline()) + containing_stmt.insert_child(position + 2, new) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_filter.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_filter.py new file mode 100644 index 0000000..18ee2ff --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_filter.py @@ -0,0 +1,76 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that changes filter(F, X) into list(filter(F, X)). + +We avoid the transformation if the filter() call is directly contained +in iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or +for V in <>:. + +NOTE: This is still not correct if the original code was depending on +filter(F, X) to return a string if X is a string and a tuple if X is a +tuple. That would require type inference, which we don't do. Let +Python 2.6 figure it out. +""" + +# Local imports +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, Call, ListComp, in_special_context + +class FixFilter(fixer_base.ConditionalFix): + BM_compatible = True + + PATTERN = """ + filter_lambda=power< + 'filter' + trailer< + '(' + arglist< + lambdef< 'lambda' + (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any + > + ',' + it=any + > + ')' + > + > + | + power< + 'filter' + trailer< '(' arglist< none='None' ',' seq=any > ')' > + > + | + power< + 'filter' + args=trailer< '(' [any] ')' > + > + """ + + skip_on = "future_builtins.filter" + + def transform(self, node, results): + if self.should_skip(node): + return + + if "filter_lambda" in results: + new = ListComp(results.get("fp").clone(), + results.get("fp").clone(), + results.get("it").clone(), + results.get("xp").clone()) + + elif "none" in results: + new = ListComp(Name(u"_f"), + Name(u"_f"), + results["seq"].clone(), + Name(u"_f")) + + else: + if in_special_context(node): + return None + new = node.clone() + new.prefix = u"" + new = Call(Name(u"list"), [new]) + new.prefix = node.prefix + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_funcattrs.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_funcattrs.py new file mode 100644 index 0000000..9e45c02 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_funcattrs.py @@ -0,0 +1,21 @@ +"""Fix function attribute names (f.func_x -> f.__x__).""" +# Author: Collin Winter + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + + +class FixFuncattrs(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + power< any+ trailer< '.' attr=('func_closure' | 'func_doc' | 'func_globals' + | 'func_name' | 'func_defaults' | 'func_code' + | 'func_dict') > any* > + """ + + def transform(self, node, results): + attr = results["attr"][0] + attr.replace(Name((u"__%s__" % attr.value[5:]), + prefix=attr.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_future.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_future.py new file mode 100644 index 0000000..fbcb86a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_future.py @@ -0,0 +1,22 @@ +"""Remove __future__ imports + +from __future__ import foo is replaced with an empty line. +""" +# Author: Christian Heimes + +# Local imports +from .. import fixer_base +from ..fixer_util import BlankLine + +class FixFuture(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """import_from< 'from' module_name="__future__" 'import' any >""" + + # This should be run last -- some things check for the import + run_order = 10 + + def transform(self, node, results): + new = BlankLine() + new.prefix = node.prefix + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_getcwdu.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_getcwdu.py new file mode 100644 index 0000000..82233c8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_getcwdu.py @@ -0,0 +1,19 @@ +""" +Fixer that changes os.getcwdu() to os.getcwd(). +""" +# Author: Victor Stinner + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + +class FixGetcwdu(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + power< 'os' trailer< dot='.' name='getcwdu' > any* > + """ + + def transform(self, node, results): + name = results["name"] + name.replace(Name(u"getcwd", prefix=name.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_has_key.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_has_key.py new file mode 100644 index 0000000..bead4cb --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_has_key.py @@ -0,0 +1,110 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for has_key(). + +Calls to .has_key() methods are expressed in terms of the 'in' +operator: + + d.has_key(k) -> k in d + +CAVEATS: +1) While the primary target of this fixer is dict.has_key(), the + fixer will change any has_key() method call, regardless of its + class. + +2) Cases like this will not be converted: + + m = d.has_key + if m(k): + ... + + Only *calls* to has_key() are converted. While it is possible to + convert the above to something like + + m = d.__contains__ + if m(k): + ... + + this is currently not done. +""" + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, parenthesize + + +class FixHasKey(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + anchor=power< + before=any+ + trailer< '.' 'has_key' > + trailer< + '(' + ( not(arglist | argument) arg=any ','> + ) + ')' + > + after=any* + > + | + negation=not_test< + 'not' + anchor=power< + before=any+ + trailer< '.' 'has_key' > + trailer< + '(' + ( not(arglist | argument) arg=any ','> + ) + ')' + > + > + > + """ + + def transform(self, node, results): + assert results + syms = self.syms + if (node.parent.type == syms.not_test and + self.pattern.match(node.parent)): + # Don't transform a node matching the first alternative of the + # pattern when its parent matches the second alternative + return None + negation = results.get("negation") + anchor = results["anchor"] + prefix = node.prefix + before = [n.clone() for n in results["before"]] + arg = results["arg"].clone() + after = results.get("after") + if after: + after = [n.clone() for n in after] + if arg.type in (syms.comparison, syms.not_test, syms.and_test, + syms.or_test, syms.test, syms.lambdef, syms.argument): + arg = parenthesize(arg) + if len(before) == 1: + before = before[0] + else: + before = pytree.Node(syms.power, before) + before.prefix = u" " + n_op = Name(u"in", prefix=u" ") + if negation: + n_not = Name(u"not", prefix=u" ") + n_op = pytree.Node(syms.comp_op, (n_not, n_op)) + new = pytree.Node(syms.comparison, (arg, n_op, before)) + if after: + new = parenthesize(new) + new = pytree.Node(syms.power, (new,) + tuple(after)) + if node.parent.type in (syms.comparison, syms.expr, syms.xor_expr, + syms.and_expr, syms.shift_expr, + syms.arith_expr, syms.term, + syms.factor, syms.power): + new = parenthesize(new) + new.prefix = prefix + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_idioms.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_idioms.py new file mode 100644 index 0000000..37b6eef --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_idioms.py @@ -0,0 +1,152 @@ +"""Adjust some old Python 2 idioms to their modern counterparts. + +* Change some type comparisons to isinstance() calls: + type(x) == T -> isinstance(x, T) + type(x) is T -> isinstance(x, T) + type(x) != T -> not isinstance(x, T) + type(x) is not T -> not isinstance(x, T) + +* Change "while 1:" into "while True:". + +* Change both + + v = list(EXPR) + v.sort() + foo(v) + +and the more general + + v = EXPR + v.sort() + foo(v) + +into + + v = sorted(EXPR) + foo(v) +""" +# Author: Jacques Frechet, Collin Winter + +# Local imports +from .. import fixer_base +from ..fixer_util import Call, Comma, Name, Node, BlankLine, syms + +CMP = "(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)" +TYPE = "power< 'type' trailer< '(' x=any ')' > >" + +class FixIdioms(fixer_base.BaseFix): + explicit = True # The user must ask for this fixer + + PATTERN = r""" + isinstance=comparison< %s %s T=any > + | + isinstance=comparison< T=any %s %s > + | + while_stmt< 'while' while='1' ':' any+ > + | + sorted=any< + any* + simple_stmt< + expr_stmt< id1=any '=' + power< list='list' trailer< '(' (not arglist) any ')' > > + > + '\n' + > + sort= + simple_stmt< + power< id2=any + trailer< '.' 'sort' > trailer< '(' ')' > + > + '\n' + > + next=any* + > + | + sorted=any< + any* + simple_stmt< expr_stmt< id1=any '=' expr=any > '\n' > + sort= + simple_stmt< + power< id2=any + trailer< '.' 'sort' > trailer< '(' ')' > + > + '\n' + > + next=any* + > + """ % (TYPE, CMP, CMP, TYPE) + + def match(self, node): + r = super(FixIdioms, self).match(node) + # If we've matched one of the sort/sorted subpatterns above, we + # want to reject matches where the initial assignment and the + # subsequent .sort() call involve different identifiers. + if r and "sorted" in r: + if r["id1"] == r["id2"]: + return r + return None + return r + + def transform(self, node, results): + if "isinstance" in results: + return self.transform_isinstance(node, results) + elif "while" in results: + return self.transform_while(node, results) + elif "sorted" in results: + return self.transform_sort(node, results) + else: + raise RuntimeError("Invalid match") + + def transform_isinstance(self, node, results): + x = results["x"].clone() # The thing inside of type() + T = results["T"].clone() # The type being compared against + x.prefix = u"" + T.prefix = u" " + test = Call(Name(u"isinstance"), [x, Comma(), T]) + if "n" in results: + test.prefix = u" " + test = Node(syms.not_test, [Name(u"not"), test]) + test.prefix = node.prefix + return test + + def transform_while(self, node, results): + one = results["while"] + one.replace(Name(u"True", prefix=one.prefix)) + + def transform_sort(self, node, results): + sort_stmt = results["sort"] + next_stmt = results["next"] + list_call = results.get("list") + simple_expr = results.get("expr") + + if list_call: + list_call.replace(Name(u"sorted", prefix=list_call.prefix)) + elif simple_expr: + new = simple_expr.clone() + new.prefix = u"" + simple_expr.replace(Call(Name(u"sorted"), [new], + prefix=simple_expr.prefix)) + else: + raise RuntimeError("should not have reached here") + sort_stmt.remove() + + btwn = sort_stmt.prefix + # Keep any prefix lines between the sort_stmt and the list_call and + # shove them right after the sorted() call. + if u"\n" in btwn: + if next_stmt: + # The new prefix should be everything from the sort_stmt's + # prefix up to the last newline, then the old prefix after a new + # line. + prefix_lines = (btwn.rpartition(u"\n")[0], next_stmt[0].prefix) + next_stmt[0].prefix = u"\n".join(prefix_lines) + else: + assert list_call.parent + assert list_call.next_sibling is None + # Put a blank line after list_call and set its prefix. + end_line = BlankLine() + list_call.parent.append_child(end_line) + assert list_call.next_sibling is end_line + # The new prefix should be everything up to the first new line + # of sort_stmt's prefix. + end_line.prefix = btwn.rpartition(u"\n")[0] diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_import.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_import.py new file mode 100644 index 0000000..201e811 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_import.py @@ -0,0 +1,99 @@ +"""Fixer for import statements. +If spam is being imported from the local directory, this import: + from spam import eggs +Becomes: + from .spam import eggs + +And this import: + import spam +Becomes: + from . import spam +""" + +# Local imports +from .. import fixer_base +from os.path import dirname, join, exists, sep +from ..fixer_util import FromImport, syms, token + + +def traverse_imports(names): + """ + Walks over all the names imported in a dotted_as_names node. + """ + pending = [names] + while pending: + node = pending.pop() + if node.type == token.NAME: + yield node.value + elif node.type == syms.dotted_name: + yield "".join([ch.value for ch in node.children]) + elif node.type == syms.dotted_as_name: + pending.append(node.children[0]) + elif node.type == syms.dotted_as_names: + pending.extend(node.children[::-2]) + else: + raise AssertionError("unkown node type") + + +class FixImport(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + import_from< 'from' imp=any 'import' ['('] any [')'] > + | + import_name< 'import' imp=any > + """ + + def start_tree(self, tree, name): + super(FixImport, self).start_tree(tree, name) + self.skip = "absolute_import" in tree.future_features + + def transform(self, node, results): + if self.skip: + return + imp = results['imp'] + + if node.type == syms.import_from: + # Some imps are top-level (eg: 'import ham') + # some are first level (eg: 'import ham.eggs') + # some are third level (eg: 'import ham.eggs as spam') + # Hence, the loop + while not hasattr(imp, 'value'): + imp = imp.children[0] + if self.probably_a_local_import(imp.value): + imp.value = u"." + imp.value + imp.changed() + else: + have_local = False + have_absolute = False + for mod_name in traverse_imports(imp): + if self.probably_a_local_import(mod_name): + have_local = True + else: + have_absolute = True + if have_absolute: + if have_local: + # We won't handle both sibling and absolute imports in the + # same statement at the moment. + self.warning(node, "absolute and local imports together") + return + + new = FromImport(u".", [imp]) + new.prefix = node.prefix + return new + + def probably_a_local_import(self, imp_name): + if imp_name.startswith(u"."): + # Relative imports are certainly not local imports. + return False + imp_name = imp_name.split(u".", 1)[0] + base_path = dirname(self.filename) + base_path = join(base_path, imp_name) + # If there is no __init__.py next to the file its not in a package + # so can't be a relative import. + if not exists(join(dirname(base_path), "__init__.py")): + return False + for ext in [".py", sep, ".pyc", ".so", ".sl", ".pyd"]: + if exists(base_path + ext): + return True + return False diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_imports.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_imports.py new file mode 100644 index 0000000..93c9e67 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_imports.py @@ -0,0 +1,145 @@ +"""Fix incompatible imports and module references.""" +# Authors: Collin Winter, Nick Edds + +# Local imports +from .. import fixer_base +from ..fixer_util import Name, attr_chain + +MAPPING = {'StringIO': 'io', + 'cStringIO': 'io', + 'cPickle': 'pickle', + '__builtin__' : 'builtins', + 'copy_reg': 'copyreg', + 'Queue': 'queue', + 'SocketServer': 'socketserver', + 'ConfigParser': 'configparser', + 'repr': 'reprlib', + 'FileDialog': 'tkinter.filedialog', + 'tkFileDialog': 'tkinter.filedialog', + 'SimpleDialog': 'tkinter.simpledialog', + 'tkSimpleDialog': 'tkinter.simpledialog', + 'tkColorChooser': 'tkinter.colorchooser', + 'tkCommonDialog': 'tkinter.commondialog', + 'Dialog': 'tkinter.dialog', + 'Tkdnd': 'tkinter.dnd', + 'tkFont': 'tkinter.font', + 'tkMessageBox': 'tkinter.messagebox', + 'ScrolledText': 'tkinter.scrolledtext', + 'Tkconstants': 'tkinter.constants', + 'Tix': 'tkinter.tix', + 'ttk': 'tkinter.ttk', + 'Tkinter': 'tkinter', + 'markupbase': '_markupbase', + '_winreg': 'winreg', + 'thread': '_thread', + 'dummy_thread': '_dummy_thread', + # anydbm and whichdb are handled by fix_imports2 + 'dbhash': 'dbm.bsd', + 'dumbdbm': 'dbm.dumb', + 'dbm': 'dbm.ndbm', + 'gdbm': 'dbm.gnu', + 'xmlrpclib': 'xmlrpc.client', + 'DocXMLRPCServer': 'xmlrpc.server', + 'SimpleXMLRPCServer': 'xmlrpc.server', + 'httplib': 'http.client', + 'htmlentitydefs' : 'html.entities', + 'HTMLParser' : 'html.parser', + 'Cookie': 'http.cookies', + 'cookielib': 'http.cookiejar', + 'BaseHTTPServer': 'http.server', + 'SimpleHTTPServer': 'http.server', + 'CGIHTTPServer': 'http.server', + #'test.test_support': 'test.support', + 'commands': 'subprocess', + 'UserString' : 'collections', + 'UserList' : 'collections', + 'urlparse' : 'urllib.parse', + 'robotparser' : 'urllib.robotparser', +} + + +def alternates(members): + return "(" + "|".join(map(repr, members)) + ")" + + +def build_pattern(mapping=MAPPING): + mod_list = ' | '.join(["module_name='%s'" % key for key in mapping]) + bare_names = alternates(mapping.keys()) + + yield """name_import=import_name< 'import' ((%s) | + multiple_imports=dotted_as_names< any* (%s) any* >) > + """ % (mod_list, mod_list) + yield """import_from< 'from' (%s) 'import' ['('] + ( any | import_as_name< any 'as' any > | + import_as_names< any* >) [')'] > + """ % mod_list + yield """import_name< 'import' (dotted_as_name< (%s) 'as' any > | + multiple_imports=dotted_as_names< + any* dotted_as_name< (%s) 'as' any > any* >) > + """ % (mod_list, mod_list) + + # Find usages of module members in code e.g. thread.foo(bar) + yield "power< bare_with_attr=(%s) trailer<'.' any > any* >" % bare_names + + +class FixImports(fixer_base.BaseFix): + + BM_compatible = True + keep_line_order = True + # This is overridden in fix_imports2. + mapping = MAPPING + + # We want to run this fixer late, so fix_import doesn't try to make stdlib + # renames into relative imports. + run_order = 6 + + def build_pattern(self): + return "|".join(build_pattern(self.mapping)) + + def compile_pattern(self): + # We override this, so MAPPING can be pragmatically altered and the + # changes will be reflected in PATTERN. + self.PATTERN = self.build_pattern() + super(FixImports, self).compile_pattern() + + # Don't match the node if it's within another match. + def match(self, node): + match = super(FixImports, self).match + results = match(node) + if results: + # Module usage could be in the trailer of an attribute lookup, so we + # might have nested matches when "bare_with_attr" is present. + if "bare_with_attr" not in results and \ + any(match(obj) for obj in attr_chain(node, "parent")): + return False + return results + return False + + def start_tree(self, tree, filename): + super(FixImports, self).start_tree(tree, filename) + self.replace = {} + + def transform(self, node, results): + import_mod = results.get("module_name") + if import_mod: + mod_name = import_mod.value + new_name = unicode(self.mapping[mod_name]) + import_mod.replace(Name(new_name, prefix=import_mod.prefix)) + if "name_import" in results: + # If it's not a "from x import x, y" or "import x as y" import, + # marked its usage to be replaced. + self.replace[mod_name] = new_name + if "multiple_imports" in results: + # This is a nasty hack to fix multiple imports on a line (e.g., + # "import StringIO, urlparse"). The problem is that I can't + # figure out an easy way to make a pattern recognize the keys of + # MAPPING randomly sprinkled in an import statement. + results = self.match(node) + if results: + self.transform(node, results) + else: + # Replace usage of the module. + bare_name = results["bare_with_attr"][0] + new_name = self.replace.get(bare_name.value) + if new_name: + bare_name.replace(Name(new_name, prefix=bare_name.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_imports2.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_imports2.py new file mode 100644 index 0000000..9a33c67 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_imports2.py @@ -0,0 +1,16 @@ +"""Fix incompatible imports and module references that must be fixed after +fix_imports.""" +from . import fix_imports + + +MAPPING = { + 'whichdb': 'dbm', + 'anydbm': 'dbm', + } + + +class FixImports2(fix_imports.FixImports): + + run_order = 7 + + mapping = MAPPING diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_input.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_input.py new file mode 100644 index 0000000..fbf4c72 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_input.py @@ -0,0 +1,26 @@ +"""Fixer that changes input(...) into eval(input(...)).""" +# Author: Andre Roberge + +# Local imports +from .. import fixer_base +from ..fixer_util import Call, Name +from .. import patcomp + + +context = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >") + + +class FixInput(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< 'input' args=trailer< '(' [any] ')' > > + """ + + def transform(self, node, results): + # If we're already wrapped in a eval() call, we're done. + if context.match(node.parent.parent): + return + + new = node.clone() + new.prefix = u"" + return Call(Name(u"eval"), [new], prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_intern.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_intern.py new file mode 100644 index 0000000..e7bb505 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_intern.py @@ -0,0 +1,46 @@ +# Copyright 2006 Georg Brandl. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for intern(). + +intern(s) -> sys.intern(s)""" + +# Local imports +from .. import pytree +from .. import fixer_base +from ..fixer_util import Name, Attr, touch_import + + +class FixIntern(fixer_base.BaseFix): + BM_compatible = True + order = "pre" + + PATTERN = """ + power< 'intern' + trailer< lpar='(' + ( not(arglist | argument) any ','> ) + rpar=')' > + after=any* + > + """ + + def transform(self, node, results): + syms = self.syms + obj = results["obj"].clone() + if obj.type == syms.arglist: + newarglist = obj.clone() + else: + newarglist = pytree.Node(syms.arglist, [obj.clone()]) + after = results["after"] + if after: + after = [n.clone() for n in after] + new = pytree.Node(syms.power, + Attr(Name(u"sys"), Name(u"intern")) + + [pytree.Node(syms.trailer, + [results["lpar"].clone(), + newarglist, + results["rpar"].clone()])] + after) + new.prefix = node.prefix + touch_import(None, u'sys', node) + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_isinstance.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_isinstance.py new file mode 100644 index 0000000..4b04c8f --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_isinstance.py @@ -0,0 +1,52 @@ +# Copyright 2008 Armin Ronacher. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that cleans up a tuple argument to isinstance after the tokens +in it were fixed. This is mainly used to remove double occurrences of +tokens as a leftover of the long -> int / unicode -> str conversion. + +eg. isinstance(x, (int, long)) -> isinstance(x, (int, int)) + -> isinstance(x, int) +""" + +from .. import fixer_base +from ..fixer_util import token + + +class FixIsinstance(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< + 'isinstance' + trailer< '(' arglist< any ',' atom< '(' + args=testlist_gexp< any+ > + ')' > > ')' > + > + """ + + run_order = 6 + + def transform(self, node, results): + names_inserted = set() + testlist = results["args"] + args = testlist.children + new_args = [] + iterator = enumerate(args) + for idx, arg in iterator: + if arg.type == token.NAME and arg.value in names_inserted: + if idx < len(args) - 1 and args[idx + 1].type == token.COMMA: + iterator.next() + continue + else: + new_args.append(arg) + if arg.type == token.NAME: + names_inserted.add(arg.value) + if new_args and new_args[-1].type == token.COMMA: + del new_args[-1] + if len(new_args) == 1: + atom = testlist.parent + new_args[0].prefix = atom.prefix + atom.replace(new_args[0]) + else: + args[:] = new_args + node.changed() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_itertools.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_itertools.py new file mode 100644 index 0000000..067641b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_itertools.py @@ -0,0 +1,43 @@ +""" Fixer for itertools.(imap|ifilter|izip) --> (map|filter|zip) and + itertools.ifilterfalse --> itertools.filterfalse (bugs 2360-2363) + + imports from itertools are fixed in fix_itertools_import.py + + If itertools is imported as something else (ie: import itertools as it; + it.izip(spam, eggs)) method calls will not get fixed. + """ + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + +class FixItertools(fixer_base.BaseFix): + BM_compatible = True + it_funcs = "('imap'|'ifilter'|'izip'|'izip_longest'|'ifilterfalse')" + PATTERN = """ + power< it='itertools' + trailer< + dot='.' func=%(it_funcs)s > trailer< '(' [any] ')' > > + | + power< func=%(it_funcs)s trailer< '(' [any] ')' > > + """ %(locals()) + + # Needs to be run after fix_(map|zip|filter) + run_order = 6 + + def transform(self, node, results): + prefix = None + func = results['func'][0] + if ('it' in results and + func.value not in (u'ifilterfalse', u'izip_longest')): + dot, it = (results['dot'], results['it']) + # Remove the 'itertools' + prefix = it.prefix + it.remove() + # Replace the node which contains ('.', 'function') with the + # function (to be consistent with the second part of the pattern) + dot.remove() + func.parent.replace(func) + + prefix = prefix or func.prefix + func.replace(Name(func.value[1:], prefix=prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_itertools_imports.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_itertools_imports.py new file mode 100644 index 0000000..28610cf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_itertools_imports.py @@ -0,0 +1,57 @@ +""" Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse) """ + +# Local imports +from lib2to3 import fixer_base +from lib2to3.fixer_util import BlankLine, syms, token + + +class FixItertoolsImports(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + import_from< 'from' 'itertools' 'import' imports=any > + """ %(locals()) + + def transform(self, node, results): + imports = results['imports'] + if imports.type == syms.import_as_name or not imports.children: + children = [imports] + else: + children = imports.children + for child in children[::2]: + if child.type == token.NAME: + member = child.value + name_node = child + elif child.type == token.STAR: + # Just leave the import as is. + return + else: + assert child.type == syms.import_as_name + name_node = child.children[0] + member_name = name_node.value + if member_name in (u'imap', u'izip', u'ifilter'): + child.value = None + child.remove() + elif member_name in (u'ifilterfalse', u'izip_longest'): + node.changed() + name_node.value = (u'filterfalse' if member_name[1] == u'f' + else u'zip_longest') + + # Make sure the import statement is still sane + children = imports.children[:] or [imports] + remove_comma = True + for child in children: + if remove_comma and child.type == token.COMMA: + child.remove() + else: + remove_comma ^= True + + while children and children[-1].type == token.COMMA: + children.pop().remove() + + # If there are no imports left, just get rid of the entire statement + if (not (imports.children or getattr(imports, 'value', None)) or + imports.parent is None): + p = node.prefix + node = BlankLine() + node.prefix = p + return node diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_long.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_long.py new file mode 100644 index 0000000..5dddde0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_long.py @@ -0,0 +1,19 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that turns 'long' into 'int' everywhere. +""" + +# Local imports +from lib2to3 import fixer_base +from lib2to3.fixer_util import is_probably_builtin + + +class FixLong(fixer_base.BaseFix): + BM_compatible = True + PATTERN = "'long'" + + def transform(self, node, results): + if is_probably_builtin(node): + node.value = u"int" + node.changed() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_map.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_map.py new file mode 100644 index 0000000..7a7d0db --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_map.py @@ -0,0 +1,91 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that changes map(F, ...) into list(map(F, ...)) unless there +exists a 'from future_builtins import map' statement in the top-level +namespace. + +As a special case, map(None, X) is changed into list(X). (This is +necessary because the semantics are changed in this case -- the new +map(None, X) is equivalent to [(x,) for x in X].) + +We avoid the transformation (except for the special case mentioned +above) if the map() call is directly contained in iter(<>), list(<>), +tuple(<>), sorted(<>), ...join(<>), or for V in <>:. + +NOTE: This is still not correct if the original code was depending on +map(F, X, Y, ...) to go on until the longest argument is exhausted, +substituting None for missing values -- like zip(), it now stops as +soon as the shortest argument is exhausted. +""" + +# Local imports +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, Call, ListComp, in_special_context +from ..pygram import python_symbols as syms + +class FixMap(fixer_base.ConditionalFix): + BM_compatible = True + + PATTERN = """ + map_none=power< + 'map' + trailer< '(' arglist< 'None' ',' arg=any [','] > ')' > + > + | + map_lambda=power< + 'map' + trailer< + '(' + arglist< + lambdef< 'lambda' + (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any + > + ',' + it=any + > + ')' + > + > + | + power< + 'map' trailer< '(' [arglist=any] ')' > + > + """ + + skip_on = 'future_builtins.map' + + def transform(self, node, results): + if self.should_skip(node): + return + + if node.parent.type == syms.simple_stmt: + self.warning(node, "You should use a for loop here") + new = node.clone() + new.prefix = u"" + new = Call(Name(u"list"), [new]) + elif "map_lambda" in results: + new = ListComp(results["xp"].clone(), + results["fp"].clone(), + results["it"].clone()) + else: + if "map_none" in results: + new = results["arg"].clone() + else: + if "arglist" in results: + args = results["arglist"] + if args.type == syms.arglist and \ + args.children[0].type == token.NAME and \ + args.children[0].value == "None": + self.warning(node, "cannot convert map(None, ...) " + "with multiple arguments because map() " + "now truncates to the shortest sequence") + return + if in_special_context(node): + return None + new = node.clone() + new.prefix = u"" + new = Call(Name(u"list"), [new]) + new.prefix = node.prefix + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_metaclass.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_metaclass.py new file mode 100644 index 0000000..4f5593c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_metaclass.py @@ -0,0 +1,228 @@ +"""Fixer for __metaclass__ = X -> (metaclass=X) methods. + + The various forms of classef (inherits nothing, inherits once, inherints + many) don't parse the same in the CST so we look at ALL classes for + a __metaclass__ and if we find one normalize the inherits to all be + an arglist. + + For one-liner classes ('class X: pass') there is no indent/dedent so + we normalize those into having a suite. + + Moving the __metaclass__ into the classdef can also cause the class + body to be empty so there is some special casing for that as well. + + This fixer also tries very hard to keep original indenting and spacing + in all those corner cases. + +""" +# Author: Jack Diederich + +# Local imports +from .. import fixer_base +from ..pygram import token +from ..fixer_util import Name, syms, Node, Leaf + + +def has_metaclass(parent): + """ we have to check the cls_node without changing it. + There are two possiblities: + 1) clsdef => suite => simple_stmt => expr_stmt => Leaf('__meta') + 2) clsdef => simple_stmt => expr_stmt => Leaf('__meta') + """ + for node in parent.children: + if node.type == syms.suite: + return has_metaclass(node) + elif node.type == syms.simple_stmt and node.children: + expr_node = node.children[0] + if expr_node.type == syms.expr_stmt and expr_node.children: + left_side = expr_node.children[0] + if isinstance(left_side, Leaf) and \ + left_side.value == '__metaclass__': + return True + return False + + +def fixup_parse_tree(cls_node): + """ one-line classes don't get a suite in the parse tree so we add + one to normalize the tree + """ + for node in cls_node.children: + if node.type == syms.suite: + # already in the preferred format, do nothing + return + + # !%@#! oneliners have no suite node, we have to fake one up + for i, node in enumerate(cls_node.children): + if node.type == token.COLON: + break + else: + raise ValueError("No class suite and no ':'!") + + # move everything into a suite node + suite = Node(syms.suite, []) + while cls_node.children[i+1:]: + move_node = cls_node.children[i+1] + suite.append_child(move_node.clone()) + move_node.remove() + cls_node.append_child(suite) + node = suite + + +def fixup_simple_stmt(parent, i, stmt_node): + """ if there is a semi-colon all the parts count as part of the same + simple_stmt. We just want the __metaclass__ part so we move + everything after the semi-colon into its own simple_stmt node + """ + for semi_ind, node in enumerate(stmt_node.children): + if node.type == token.SEMI: # *sigh* + break + else: + return + + node.remove() # kill the semicolon + new_expr = Node(syms.expr_stmt, []) + new_stmt = Node(syms.simple_stmt, [new_expr]) + while stmt_node.children[semi_ind:]: + move_node = stmt_node.children[semi_ind] + new_expr.append_child(move_node.clone()) + move_node.remove() + parent.insert_child(i, new_stmt) + new_leaf1 = new_stmt.children[0].children[0] + old_leaf1 = stmt_node.children[0].children[0] + new_leaf1.prefix = old_leaf1.prefix + + +def remove_trailing_newline(node): + if node.children and node.children[-1].type == token.NEWLINE: + node.children[-1].remove() + + +def find_metas(cls_node): + # find the suite node (Mmm, sweet nodes) + for node in cls_node.children: + if node.type == syms.suite: + break + else: + raise ValueError("No class suite!") + + # look for simple_stmt[ expr_stmt[ Leaf('__metaclass__') ] ] + for i, simple_node in list(enumerate(node.children)): + if simple_node.type == syms.simple_stmt and simple_node.children: + expr_node = simple_node.children[0] + if expr_node.type == syms.expr_stmt and expr_node.children: + # Check if the expr_node is a simple assignment. + left_node = expr_node.children[0] + if isinstance(left_node, Leaf) and \ + left_node.value == u'__metaclass__': + # We found a assignment to __metaclass__. + fixup_simple_stmt(node, i, simple_node) + remove_trailing_newline(simple_node) + yield (node, i, simple_node) + + +def fixup_indent(suite): + """ If an INDENT is followed by a thing with a prefix then nuke the prefix + Otherwise we get in trouble when removing __metaclass__ at suite start + """ + kids = suite.children[::-1] + # find the first indent + while kids: + node = kids.pop() + if node.type == token.INDENT: + break + + # find the first Leaf + while kids: + node = kids.pop() + if isinstance(node, Leaf) and node.type != token.DEDENT: + if node.prefix: + node.prefix = u'' + return + else: + kids.extend(node.children[::-1]) + + +class FixMetaclass(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + classdef + """ + + def transform(self, node, results): + if not has_metaclass(node): + return + + fixup_parse_tree(node) + + # find metaclasses, keep the last one + last_metaclass = None + for suite, i, stmt in find_metas(node): + last_metaclass = stmt + stmt.remove() + + text_type = node.children[0].type # always Leaf(nnn, 'class') + + # figure out what kind of classdef we have + if len(node.children) == 7: + # Node(classdef, ['class', 'name', '(', arglist, ')', ':', suite]) + # 0 1 2 3 4 5 6 + if node.children[3].type == syms.arglist: + arglist = node.children[3] + # Node(classdef, ['class', 'name', '(', 'Parent', ')', ':', suite]) + else: + parent = node.children[3].clone() + arglist = Node(syms.arglist, [parent]) + node.set_child(3, arglist) + elif len(node.children) == 6: + # Node(classdef, ['class', 'name', '(', ')', ':', suite]) + # 0 1 2 3 4 5 + arglist = Node(syms.arglist, []) + node.insert_child(3, arglist) + elif len(node.children) == 4: + # Node(classdef, ['class', 'name', ':', suite]) + # 0 1 2 3 + arglist = Node(syms.arglist, []) + node.insert_child(2, Leaf(token.RPAR, u')')) + node.insert_child(2, arglist) + node.insert_child(2, Leaf(token.LPAR, u'(')) + else: + raise ValueError("Unexpected class definition") + + # now stick the metaclass in the arglist + meta_txt = last_metaclass.children[0].children[0] + meta_txt.value = 'metaclass' + orig_meta_prefix = meta_txt.prefix + + if arglist.children: + arglist.append_child(Leaf(token.COMMA, u',')) + meta_txt.prefix = u' ' + else: + meta_txt.prefix = u'' + + # compact the expression "metaclass = Meta" -> "metaclass=Meta" + expr_stmt = last_metaclass.children[0] + assert expr_stmt.type == syms.expr_stmt + expr_stmt.children[1].prefix = u'' + expr_stmt.children[2].prefix = u'' + + arglist.append_child(last_metaclass) + + fixup_indent(suite) + + # check for empty suite + if not suite.children: + # one-liner that was just __metaclass_ + suite.remove() + pass_leaf = Leaf(text_type, u'pass') + pass_leaf.prefix = orig_meta_prefix + node.append_child(pass_leaf) + node.append_child(Leaf(token.NEWLINE, u'\n')) + + elif len(suite.children) > 1 and \ + (suite.children[-2].type == token.INDENT and + suite.children[-1].type == token.DEDENT): + # there was only one line in the class body and it was __metaclass__ + pass_leaf = Leaf(text_type, u'pass') + suite.insert_child(-1, pass_leaf) + suite.insert_child(-1, Leaf(token.NEWLINE, u'\n')) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_methodattrs.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_methodattrs.py new file mode 100644 index 0000000..f3c1ecf --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_methodattrs.py @@ -0,0 +1,24 @@ +"""Fix bound method attributes (method.im_? -> method.__?__). +""" +# Author: Christian Heimes + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + +MAP = { + "im_func" : "__func__", + "im_self" : "__self__", + "im_class" : "__self__.__class__" + } + +class FixMethodattrs(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* > + """ + + def transform(self, node, results): + attr = results["attr"][0] + new = unicode(MAP[attr.value]) + attr.replace(Name(new, prefix=attr.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_ne.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_ne.py new file mode 100644 index 0000000..7025980 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_ne.py @@ -0,0 +1,23 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that turns <> into !=.""" + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base + + +class FixNe(fixer_base.BaseFix): + # This is so simple that we don't need the pattern compiler. + + _accept_type = token.NOTEQUAL + + def match(self, node): + # Override + return node.value == u"<>" + + def transform(self, node, results): + new = pytree.Leaf(token.NOTEQUAL, u"!=", prefix=node.prefix) + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_next.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_next.py new file mode 100644 index 0000000..f021a9b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_next.py @@ -0,0 +1,103 @@ +"""Fixer for it.next() -> next(it), per PEP 3114.""" +# Author: Collin Winter + +# Things that currently aren't covered: +# - listcomp "next" names aren't warned +# - "with" statement targets aren't checked + +# Local imports +from ..pgen2 import token +from ..pygram import python_symbols as syms +from .. import fixer_base +from ..fixer_util import Name, Call, find_binding + +bind_warning = "Calls to builtin next() possibly shadowed by global binding" + + +class FixNext(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< base=any+ trailer< '.' attr='next' > trailer< '(' ')' > > + | + power< head=any+ trailer< '.' attr='next' > not trailer< '(' ')' > > + | + classdef< 'class' any+ ':' + suite< any* + funcdef< 'def' + name='next' + parameters< '(' NAME ')' > any+ > + any* > > + | + global=global_stmt< 'global' any* 'next' any* > + """ + + order = "pre" # Pre-order tree traversal + + def start_tree(self, tree, filename): + super(FixNext, self).start_tree(tree, filename) + + n = find_binding(u'next', tree) + if n: + self.warning(n, bind_warning) + self.shadowed_next = True + else: + self.shadowed_next = False + + def transform(self, node, results): + assert results + + base = results.get("base") + attr = results.get("attr") + name = results.get("name") + + if base: + if self.shadowed_next: + attr.replace(Name(u"__next__", prefix=attr.prefix)) + else: + base = [n.clone() for n in base] + base[0].prefix = u"" + node.replace(Call(Name(u"next", prefix=node.prefix), base)) + elif name: + n = Name(u"__next__", prefix=name.prefix) + name.replace(n) + elif attr: + # We don't do this transformation if we're assigning to "x.next". + # Unfortunately, it doesn't seem possible to do this in PATTERN, + # so it's being done here. + if is_assign_target(node): + head = results["head"] + if "".join([str(n) for n in head]).strip() == u'__builtin__': + self.warning(node, bind_warning) + return + attr.replace(Name(u"__next__")) + elif "global" in results: + self.warning(node, bind_warning) + self.shadowed_next = True + + +### The following functions help test if node is part of an assignment +### target. + +def is_assign_target(node): + assign = find_assign(node) + if assign is None: + return False + + for child in assign.children: + if child.type == token.EQUAL: + return False + elif is_subtree(child, node): + return True + return False + +def find_assign(node): + if node.type == syms.expr_stmt: + return node + if node.type == syms.simple_stmt or node.parent is None: + return None + return find_assign(node.parent) + +def is_subtree(root, node): + if root == node: + return True + return any(is_subtree(c, node) for c in root.children) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_nonzero.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_nonzero.py new file mode 100644 index 0000000..ba83478 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_nonzero.py @@ -0,0 +1,21 @@ +"""Fixer for __nonzero__ -> __bool__ methods.""" +# Author: Collin Winter + +# Local imports +from .. import fixer_base +from ..fixer_util import Name, syms + +class FixNonzero(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + classdef< 'class' any+ ':' + suite< any* + funcdef< 'def' name='__nonzero__' + parameters< '(' NAME ')' > any+ > + any* > > + """ + + def transform(self, node, results): + name = results["name"] + new = Name(u"__bool__", prefix=name.prefix) + name.replace(new) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_numliterals.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_numliterals.py new file mode 100644 index 0000000..b0c23f8 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_numliterals.py @@ -0,0 +1,28 @@ +"""Fixer that turns 1L into 1, 0755 into 0o755. +""" +# Copyright 2007 Georg Brandl. +# Licensed to PSF under a Contributor Agreement. + +# Local imports +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Number + + +class FixNumliterals(fixer_base.BaseFix): + # This is so simple that we don't need the pattern compiler. + + _accept_type = token.NUMBER + + def match(self, node): + # Override + return (node.value.startswith(u"0") or node.value[-1] in u"Ll") + + def transform(self, node, results): + val = node.value + if val[-1] in u'Ll': + val = val[:-1] + elif val.startswith(u'0') and val.isdigit() and len(set(val)) > 1: + val = u"0o" + val[1:] + + return Number(val, prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_operator.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_operator.py new file mode 100644 index 0000000..7bf2c0d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_operator.py @@ -0,0 +1,96 @@ +"""Fixer for operator functions. + +operator.isCallable(obj) -> hasattr(obj, '__call__') +operator.sequenceIncludes(obj) -> operator.contains(obj) +operator.isSequenceType(obj) -> isinstance(obj, collections.Sequence) +operator.isMappingType(obj) -> isinstance(obj, collections.Mapping) +operator.isNumberType(obj) -> isinstance(obj, numbers.Number) +operator.repeat(obj, n) -> operator.mul(obj, n) +operator.irepeat(obj, n) -> operator.imul(obj, n) +""" + +# Local imports +from lib2to3 import fixer_base +from lib2to3.fixer_util import Call, Name, String, touch_import + + +def invocation(s): + def dec(f): + f.invocation = s + return f + return dec + + +class FixOperator(fixer_base.BaseFix): + BM_compatible = True + order = "pre" + + methods = """ + method=('isCallable'|'sequenceIncludes' + |'isSequenceType'|'isMappingType'|'isNumberType' + |'repeat'|'irepeat') + """ + obj = "'(' obj=any ')'" + PATTERN = """ + power< module='operator' + trailer< '.' %(methods)s > trailer< %(obj)s > > + | + power< %(methods)s trailer< %(obj)s > > + """ % dict(methods=methods, obj=obj) + + def transform(self, node, results): + method = self._check_method(node, results) + if method is not None: + return method(node, results) + + @invocation("operator.contains(%s)") + def _sequenceIncludes(self, node, results): + return self._handle_rename(node, results, u"contains") + + @invocation("hasattr(%s, '__call__')") + def _isCallable(self, node, results): + obj = results["obj"] + args = [obj.clone(), String(u", "), String(u"'__call__'")] + return Call(Name(u"hasattr"), args, prefix=node.prefix) + + @invocation("operator.mul(%s)") + def _repeat(self, node, results): + return self._handle_rename(node, results, u"mul") + + @invocation("operator.imul(%s)") + def _irepeat(self, node, results): + return self._handle_rename(node, results, u"imul") + + @invocation("isinstance(%s, collections.Sequence)") + def _isSequenceType(self, node, results): + return self._handle_type2abc(node, results, u"collections", u"Sequence") + + @invocation("isinstance(%s, collections.Mapping)") + def _isMappingType(self, node, results): + return self._handle_type2abc(node, results, u"collections", u"Mapping") + + @invocation("isinstance(%s, numbers.Number)") + def _isNumberType(self, node, results): + return self._handle_type2abc(node, results, u"numbers", u"Number") + + def _handle_rename(self, node, results, name): + method = results["method"][0] + method.value = name + method.changed() + + def _handle_type2abc(self, node, results, module, abc): + touch_import(None, module, node) + obj = results["obj"] + args = [obj.clone(), String(u", " + u".".join([module, abc]))] + return Call(Name(u"isinstance"), args, prefix=node.prefix) + + def _check_method(self, node, results): + method = getattr(self, "_" + results["method"][0].value.encode("ascii")) + if callable(method): + if "module" in results: + return method + else: + sub = (unicode(results["obj"]),) + invocation_str = unicode(method.invocation) % sub + self.warning(node, u"You should use '%s' here." % invocation_str) + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_paren.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_paren.py new file mode 100644 index 0000000..8650cd9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_paren.py @@ -0,0 +1,44 @@ +"""Fixer that addes parentheses where they are required + +This converts ``[x for x in 1, 2]`` to ``[x for x in (1, 2)]``.""" + +# By Taek Joo Kim and Benjamin Peterson + +# Local imports +from .. import fixer_base +from ..fixer_util import LParen, RParen + +# XXX This doesn't support nested for loops like [x for x in 1, 2 for x in 1, 2] +class FixParen(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """ + atom< ('[' | '(') + (listmaker< any + comp_for< + 'for' NAME 'in' + target=testlist_safe< any (',' any)+ [','] + > + [any] + > + > + | + testlist_gexp< any + comp_for< + 'for' NAME 'in' + target=testlist_safe< any (',' any)+ [','] + > + [any] + > + >) + (']' | ')') > + """ + + def transform(self, node, results): + target = results["target"] + + lparen = LParen() + lparen.prefix = target.prefix + target.prefix = u"" # Make it hug the parentheses + target.insert_child(0, lparen) + target.append_child(RParen()) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_print.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_print.py new file mode 100644 index 0000000..98786b3 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_print.py @@ -0,0 +1,87 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for print. + +Change: + 'print' into 'print()' + 'print ...' into 'print(...)' + 'print ... ,' into 'print(..., end=" ")' + 'print >>x, ...' into 'print(..., file=x)' + +No changes are applied if print_function is imported from __future__ + +""" + +# Local imports +from .. import patcomp +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, Call, Comma, String, is_tuple + + +parend_expr = patcomp.compile_pattern( + """atom< '(' [atom|STRING|NAME] ')' >""" + ) + + +class FixPrint(fixer_base.BaseFix): + + BM_compatible = True + + PATTERN = """ + simple_stmt< any* bare='print' any* > | print_stmt + """ + + def transform(self, node, results): + assert results + + bare_print = results.get("bare") + + if bare_print: + # Special-case print all by itself + bare_print.replace(Call(Name(u"print"), [], + prefix=bare_print.prefix)) + return + assert node.children[0] == Name(u"print") + args = node.children[1:] + if len(args) == 1 and parend_expr.match(args[0]): + # We don't want to keep sticking parens around an + # already-parenthesised expression. + return + + sep = end = file = None + if args and args[-1] == Comma(): + args = args[:-1] + end = " " + if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, u">>"): + assert len(args) >= 2 + file = args[1].clone() + args = args[3:] # Strip a possible comma after the file expression + # Now synthesize a print(args, sep=..., end=..., file=...) node. + l_args = [arg.clone() for arg in args] + if l_args: + l_args[0].prefix = u"" + if sep is not None or end is not None or file is not None: + if sep is not None: + self.add_kwarg(l_args, u"sep", String(repr(sep))) + if end is not None: + self.add_kwarg(l_args, u"end", String(repr(end))) + if file is not None: + self.add_kwarg(l_args, u"file", file) + n_stmt = Call(Name(u"print"), l_args) + n_stmt.prefix = node.prefix + return n_stmt + + def add_kwarg(self, l_nodes, s_kwd, n_expr): + # XXX All this prefix-setting may lose comments (though rarely) + n_expr.prefix = u"" + n_argument = pytree.Node(self.syms.argument, + (Name(s_kwd), + pytree.Leaf(token.EQUAL, u"="), + n_expr)) + if l_nodes: + l_nodes.append(Comma()) + n_argument.prefix = u" " + l_nodes.append(n_argument) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_raise.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_raise.py new file mode 100644 index 0000000..b958ba0 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_raise.py @@ -0,0 +1,90 @@ +"""Fixer for 'raise E, V, T' + +raise -> raise +raise E -> raise E +raise E, V -> raise E(V) +raise E, V, T -> raise E(V).with_traceback(T) +raise E, None, T -> raise E.with_traceback(T) + +raise (((E, E'), E''), E'''), V -> raise E(V) +raise "foo", V, T -> warns about string exceptions + + +CAVEATS: +1) "raise E, V" will be incorrectly translated if V is an exception + instance. The correct Python 3 idiom is + + raise E from V + + but since we can't detect instance-hood by syntax alone and since + any client code would have to be changed as well, we don't automate + this. +""" +# Author: Collin Winter + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, Call, Attr, ArgList, is_tuple + +class FixRaise(fixer_base.BaseFix): + + BM_compatible = True + PATTERN = """ + raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] > + """ + + def transform(self, node, results): + syms = self.syms + + exc = results["exc"].clone() + if exc.type == token.STRING: + msg = "Python 3 does not support string exceptions" + self.cannot_convert(node, msg) + return + + # Python 2 supports + # raise ((((E1, E2), E3), E4), E5), V + # as a synonym for + # raise E1, V + # Since Python 3 will not support this, we recurse down any tuple + # literals, always taking the first element. + if is_tuple(exc): + while is_tuple(exc): + # exc.children[1:-1] is the unparenthesized tuple + # exc.children[1].children[0] is the first element of the tuple + exc = exc.children[1].children[0].clone() + exc.prefix = u" " + + if "val" not in results: + # One-argument raise + new = pytree.Node(syms.raise_stmt, [Name(u"raise"), exc]) + new.prefix = node.prefix + return new + + val = results["val"].clone() + if is_tuple(val): + args = [c.clone() for c in val.children[1:-1]] + else: + val.prefix = u"" + args = [val] + + if "tb" in results: + tb = results["tb"].clone() + tb.prefix = u"" + + e = exc + # If there's a traceback and None is passed as the value, then don't + # add a call, since the user probably just wants to add a + # traceback. See issue #9661. + if val.type != token.NAME or val.value != u"None": + e = Call(exc, args) + with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])] + new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb) + new.prefix = node.prefix + return new + else: + return pytree.Node(syms.raise_stmt, + [Name(u"raise"), Call(exc, args)], + prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_raw_input.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_raw_input.py new file mode 100644 index 0000000..3a73b81 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_raw_input.py @@ -0,0 +1,17 @@ +"""Fixer that changes raw_input(...) into input(...).""" +# Author: Andre Roberge + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + +class FixRawInput(fixer_base.BaseFix): + + BM_compatible = True + PATTERN = """ + power< name='raw_input' trailer< '(' [any] ')' > any* > + """ + + def transform(self, node, results): + name = results["name"] + name.replace(Name(u"input", prefix=name.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_reduce.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_reduce.py new file mode 100644 index 0000000..6bd785c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_reduce.py @@ -0,0 +1,35 @@ +# Copyright 2008 Armin Ronacher. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for reduce(). + +Makes sure reduce() is imported from the functools module if reduce is +used in that module. +""" + +from lib2to3 import fixer_base +from lib2to3.fixer_util import touch_import + + + +class FixReduce(fixer_base.BaseFix): + + BM_compatible = True + order = "pre" + + PATTERN = """ + power< 'reduce' + trailer< '(' + arglist< ( + (not(argument) any ',' + not(argument + > + """ + + def transform(self, node, results): + touch_import(u'functools', u'reduce', node) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_renames.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_renames.py new file mode 100644 index 0000000..4bcce8c --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_renames.py @@ -0,0 +1,70 @@ +"""Fix incompatible renames + +Fixes: + * sys.maxint -> sys.maxsize +""" +# Author: Christian Heimes +# based on Collin Winter's fix_import + +# Local imports +from .. import fixer_base +from ..fixer_util import Name, attr_chain + +MAPPING = {"sys": {"maxint" : "maxsize"}, + } +LOOKUP = {} + +def alternates(members): + return "(" + "|".join(map(repr, members)) + ")" + + +def build_pattern(): + #bare = set() + for module, replace in MAPPING.items(): + for old_attr, new_attr in replace.items(): + LOOKUP[(module, old_attr)] = new_attr + #bare.add(module) + #bare.add(old_attr) + #yield """ + # import_name< 'import' (module=%r + # | dotted_as_names< any* module=%r any* >) > + # """ % (module, module) + yield """ + import_from< 'from' module_name=%r 'import' + ( attr_name=%r | import_as_name< attr_name=%r 'as' any >) > + """ % (module, old_attr, old_attr) + yield """ + power< module_name=%r trailer< '.' attr_name=%r > any* > + """ % (module, old_attr) + #yield """bare_name=%s""" % alternates(bare) + + +class FixRenames(fixer_base.BaseFix): + BM_compatible = True + PATTERN = "|".join(build_pattern()) + + order = "pre" # Pre-order tree traversal + + # Don't match the node if it's within another match + def match(self, node): + match = super(FixRenames, self).match + results = match(node) + if results: + if any(match(obj) for obj in attr_chain(node, "parent")): + return False + return results + return False + + #def start_tree(self, tree, filename): + # super(FixRenames, self).start_tree(tree, filename) + # self.replace = {} + + def transform(self, node, results): + mod_name = results.get("module_name") + attr_name = results.get("attr_name") + #bare_name = results.get("bare_name") + #import_mod = results.get("module") + + if mod_name and attr_name: + new_attr = unicode(LOOKUP[(mod_name.value, attr_name.value)]) + attr_name.replace(Name(new_attr, prefix=attr_name.prefix)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_repr.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_repr.py new file mode 100644 index 0000000..f343656 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_repr.py @@ -0,0 +1,23 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that transforms `xyzzy` into repr(xyzzy).""" + +# Local imports +from .. import fixer_base +from ..fixer_util import Call, Name, parenthesize + + +class FixRepr(fixer_base.BaseFix): + + BM_compatible = True + PATTERN = """ + atom < '`' expr=any '`' > + """ + + def transform(self, node, results): + expr = results["expr"].clone() + + if expr.type == self.syms.testlist1: + expr = parenthesize(expr) + return Call(Name(u"repr"), [expr], prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_set_literal.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_set_literal.py new file mode 100644 index 0000000..d3d38ec --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_set_literal.py @@ -0,0 +1,53 @@ +""" +Optional fixer to transform set() calls to set literals. +""" + +# Author: Benjamin Peterson + +from lib2to3 import fixer_base, pytree +from lib2to3.fixer_util import token, syms + + + +class FixSetLiteral(fixer_base.BaseFix): + + BM_compatible = True + explicit = True + + PATTERN = """power< 'set' trailer< '(' + (atom=atom< '[' (items=listmaker< any ((',' any)* [',']) > + | + single=any) ']' > + | + atom< '(' items=testlist_gexp< any ((',' any)* [',']) > ')' > + ) + ')' > > + """ + + def transform(self, node, results): + single = results.get("single") + if single: + # Make a fake listmaker + fake = pytree.Node(syms.listmaker, [single.clone()]) + single.replace(fake) + items = fake + else: + items = results["items"] + + # Build the contents of the literal + literal = [pytree.Leaf(token.LBRACE, u"{")] + literal.extend(n.clone() for n in items.children) + literal.append(pytree.Leaf(token.RBRACE, u"}")) + # Set the prefix of the right brace to that of the ')' or ']' + literal[-1].prefix = items.next_sibling.prefix + maker = pytree.Node(syms.dictsetmaker, literal) + maker.prefix = node.prefix + + # If the original was a one tuple, we need to remove the extra comma. + if len(maker.children) == 4: + n = maker.children[2] + n.remove() + maker.children[-1].prefix = n.prefix + + # Finally, replace the set call with our shiny new literal. + return maker diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_standarderror.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_standarderror.py new file mode 100644 index 0000000..6cad511 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_standarderror.py @@ -0,0 +1,18 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for StandardError -> Exception.""" + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + + +class FixStandarderror(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + 'StandardError' + """ + + def transform(self, node, results): + return Name(u"Exception", prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_sys_exc.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_sys_exc.py new file mode 100644 index 0000000..2ecca2b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_sys_exc.py @@ -0,0 +1,30 @@ +"""Fixer for sys.exc_{type, value, traceback} + +sys.exc_type -> sys.exc_info()[0] +sys.exc_value -> sys.exc_info()[1] +sys.exc_traceback -> sys.exc_info()[2] +""" + +# By Jeff Balogh and Benjamin Peterson + +# Local imports +from .. import fixer_base +from ..fixer_util import Attr, Call, Name, Number, Subscript, Node, syms + +class FixSysExc(fixer_base.BaseFix): + # This order matches the ordering of sys.exc_info(). + exc_info = [u"exc_type", u"exc_value", u"exc_traceback"] + BM_compatible = True + PATTERN = """ + power< 'sys' trailer< dot='.' attribute=(%s) > > + """ % '|'.join("'%s'" % e for e in exc_info) + + def transform(self, node, results): + sys_attr = results["attribute"][0] + index = Number(self.exc_info.index(sys_attr.value)) + + call = Call(Name(u"exc_info"), prefix=sys_attr.prefix) + attr = Attr(Name(u"sys"), call) + attr[1].children[0].prefix = results["dot"].prefix + attr.append(Subscript(index)) + return Node(syms.power, attr, prefix=node.prefix) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_throw.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_throw.py new file mode 100644 index 0000000..1468d89 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_throw.py @@ -0,0 +1,56 @@ +"""Fixer for generator.throw(E, V, T). + +g.throw(E) -> g.throw(E) +g.throw(E, V) -> g.throw(E(V)) +g.throw(E, V, T) -> g.throw(E(V).with_traceback(T)) + +g.throw("foo"[, V[, T]]) will warn about string exceptions.""" +# Author: Collin Winter + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name, Call, ArgList, Attr, is_tuple + +class FixThrow(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< any trailer< '.' 'throw' > + trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' > + > + | + power< any trailer< '.' 'throw' > trailer< '(' exc=any ')' > > + """ + + def transform(self, node, results): + syms = self.syms + + exc = results["exc"].clone() + if exc.type is token.STRING: + self.cannot_convert(node, "Python 3 does not support string exceptions") + return + + # Leave "g.throw(E)" alone + val = results.get(u"val") + if val is None: + return + + val = val.clone() + if is_tuple(val): + args = [c.clone() for c in val.children[1:-1]] + else: + val.prefix = u"" + args = [val] + + throw_args = results["args"] + + if "tb" in results: + tb = results["tb"].clone() + tb.prefix = u"" + + e = Call(exc, args) + with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])] + throw_args.replace(pytree.Node(syms.power, with_tb)) + else: + throw_args.replace(Call(exc, args)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_tuple_params.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_tuple_params.py new file mode 100644 index 0000000..6361717 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_tuple_params.py @@ -0,0 +1,175 @@ +"""Fixer for function definitions with tuple parameters. + +def func(((a, b), c), d): + ... + + -> + +def func(x, d): + ((a, b), c) = x + ... + +It will also support lambdas: + + lambda (x, y): x + y -> lambda t: t[0] + t[1] + + # The parens are a syntax error in Python 3 + lambda (x): x + y -> lambda x: x + y +""" +# Author: Collin Winter + +# Local imports +from .. import pytree +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Assign, Name, Newline, Number, Subscript, syms + +def is_docstring(stmt): + return isinstance(stmt, pytree.Node) and \ + stmt.children[0].type == token.STRING + +class FixTupleParams(fixer_base.BaseFix): + run_order = 4 #use a lower order since lambda is part of other + #patterns + BM_compatible = True + + PATTERN = """ + funcdef< 'def' any parameters< '(' args=any ')' > + ['->' any] ':' suite=any+ > + | + lambda= + lambdef< 'lambda' args=vfpdef< '(' inner=any ')' > + ':' body=any + > + """ + + def transform(self, node, results): + if "lambda" in results: + return self.transform_lambda(node, results) + + new_lines = [] + suite = results["suite"] + args = results["args"] + # This crap is so "def foo(...): x = 5; y = 7" is handled correctly. + # TODO(cwinter): suite-cleanup + if suite[0].children[1].type == token.INDENT: + start = 2 + indent = suite[0].children[1].value + end = Newline() + else: + start = 0 + indent = u"; " + end = pytree.Leaf(token.INDENT, u"") + + # We need access to self for new_name(), and making this a method + # doesn't feel right. Closing over self and new_lines makes the + # code below cleaner. + def handle_tuple(tuple_arg, add_prefix=False): + n = Name(self.new_name()) + arg = tuple_arg.clone() + arg.prefix = u"" + stmt = Assign(arg, n.clone()) + if add_prefix: + n.prefix = u" " + tuple_arg.replace(n) + new_lines.append(pytree.Node(syms.simple_stmt, + [stmt, end.clone()])) + + if args.type == syms.tfpdef: + handle_tuple(args) + elif args.type == syms.typedargslist: + for i, arg in enumerate(args.children): + if arg.type == syms.tfpdef: + # Without add_prefix, the emitted code is correct, + # just ugly. + handle_tuple(arg, add_prefix=(i > 0)) + + if not new_lines: + return + + # This isn't strictly necessary, but it plays nicely with other fixers. + # TODO(cwinter) get rid of this when children becomes a smart list + for line in new_lines: + line.parent = suite[0] + + # TODO(cwinter) suite-cleanup + after = start + if start == 0: + new_lines[0].prefix = u" " + elif is_docstring(suite[0].children[start]): + new_lines[0].prefix = indent + after = start + 1 + + for line in new_lines: + line.parent = suite[0] + suite[0].children[after:after] = new_lines + for i in range(after+1, after+len(new_lines)+1): + suite[0].children[i].prefix = indent + suite[0].changed() + + def transform_lambda(self, node, results): + args = results["args"] + body = results["body"] + inner = simplify_args(results["inner"]) + + # Replace lambda ((((x)))): x with lambda x: x + if inner.type == token.NAME: + inner = inner.clone() + inner.prefix = u" " + args.replace(inner) + return + + params = find_params(args) + to_index = map_to_index(params) + tup_name = self.new_name(tuple_name(params)) + + new_param = Name(tup_name, prefix=u" ") + args.replace(new_param.clone()) + for n in body.post_order(): + if n.type == token.NAME and n.value in to_index: + subscripts = [c.clone() for c in to_index[n.value]] + new = pytree.Node(syms.power, + [new_param.clone()] + subscripts) + new.prefix = n.prefix + n.replace(new) + + +### Helper functions for transform_lambda() + +def simplify_args(node): + if node.type in (syms.vfplist, token.NAME): + return node + elif node.type == syms.vfpdef: + # These look like vfpdef< '(' x ')' > where x is NAME + # or another vfpdef instance (leading to recursion). + while node.type == syms.vfpdef: + node = node.children[1] + return node + raise RuntimeError("Received unexpected node %s" % node) + +def find_params(node): + if node.type == syms.vfpdef: + return find_params(node.children[1]) + elif node.type == token.NAME: + return node.value + return [find_params(c) for c in node.children if c.type != token.COMMA] + +def map_to_index(param_list, prefix=[], d=None): + if d is None: + d = {} + for i, obj in enumerate(param_list): + trailer = [Subscript(Number(unicode(i)))] + if isinstance(obj, list): + map_to_index(obj, trailer, d=d) + else: + d[obj] = prefix + trailer + return d + +def tuple_name(param_list): + l = [] + for obj in param_list: + if isinstance(obj, list): + l.append(tuple_name(obj)) + else: + l.append(obj) + return u"_".join(l) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_types.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_types.py new file mode 100644 index 0000000..fc9d495 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_types.py @@ -0,0 +1,62 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer for removing uses of the types module. + +These work for only the known names in the types module. The forms above +can include types. or not. ie, It is assumed the module is imported either as: + + import types + from types import ... # either * or specific types + +The import statements are not modified. + +There should be another fixer that handles at least the following constants: + + type([]) -> list + type(()) -> tuple + type('') -> str + +""" + +# Local imports +from ..pgen2 import token +from .. import fixer_base +from ..fixer_util import Name + +_TYPE_MAPPING = { + 'BooleanType' : 'bool', + 'BufferType' : 'memoryview', + 'ClassType' : 'type', + 'ComplexType' : 'complex', + 'DictType': 'dict', + 'DictionaryType' : 'dict', + 'EllipsisType' : 'type(Ellipsis)', + #'FileType' : 'io.IOBase', + 'FloatType': 'float', + 'IntType': 'int', + 'ListType': 'list', + 'LongType': 'int', + 'ObjectType' : 'object', + 'NoneType': 'type(None)', + 'NotImplementedType' : 'type(NotImplemented)', + 'SliceType' : 'slice', + 'StringType': 'bytes', # XXX ? + 'StringTypes' : 'str', # XXX ? + 'TupleType': 'tuple', + 'TypeType' : 'type', + 'UnicodeType': 'str', + 'XRangeType' : 'range', + } + +_pats = ["power< 'types' trailer< '.' name='%s' > >" % t for t in _TYPE_MAPPING] + +class FixTypes(fixer_base.BaseFix): + BM_compatible = True + PATTERN = '|'.join(_pats) + + def transform(self, node, results): + new_value = unicode(_TYPE_MAPPING.get(results["name"].value)) + if new_value: + return Name(new_value, prefix=node.prefix) + return None diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_unicode.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_unicode.py new file mode 100644 index 0000000..2d776f6 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_unicode.py @@ -0,0 +1,42 @@ +r"""Fixer for unicode. + +* Changes unicode to str and unichr to chr. + +* If "...\u..." is not unicode literal change it into "...\\u...". + +* Change u"..." into "...". + +""" + +from ..pgen2 import token +from .. import fixer_base + +_mapping = {u"unichr" : u"chr", u"unicode" : u"str"} + +class FixUnicode(fixer_base.BaseFix): + BM_compatible = True + PATTERN = "STRING | 'unicode' | 'unichr'" + + def start_tree(self, tree, filename): + super(FixUnicode, self).start_tree(tree, filename) + self.unicode_literals = 'unicode_literals' in tree.future_features + + def transform(self, node, results): + if node.type == token.NAME: + new = node.clone() + new.value = _mapping[node.value] + return new + elif node.type == token.STRING: + val = node.value + if not self.unicode_literals and val[0] in u'\'"' and u'\\' in val: + val = ur'\\'.join([ + v.replace(u'\\u', ur'\\u').replace(u'\\U', ur'\\U') + for v in val.split(ur'\\') + ]) + if val[0] in u'uU': + val = val[1:] + if val == node.value: + return node + new = node.clone() + new.value = val + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_urllib.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_urllib.py new file mode 100644 index 0000000..34e1b27 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_urllib.py @@ -0,0 +1,197 @@ +"""Fix changes imports of urllib which are now incompatible. + This is rather similar to fix_imports, but because of the more + complex nature of the fixing for urllib, it has its own fixer. +""" +# Author: Nick Edds + +# Local imports +from lib2to3.fixes.fix_imports import alternates, FixImports +from lib2to3 import fixer_base +from lib2to3.fixer_util import (Name, Comma, FromImport, Newline, + find_indentation, Node, syms) + +MAPPING = {"urllib": [ + ("urllib.request", + ["URLopener", "FancyURLopener", "urlretrieve", + "_urlopener", "urlopen", "urlcleanup", + "pathname2url", "url2pathname"]), + ("urllib.parse", + ["quote", "quote_plus", "unquote", "unquote_plus", + "urlencode", "splitattr", "splithost", "splitnport", + "splitpasswd", "splitport", "splitquery", "splittag", + "splittype", "splituser", "splitvalue", ]), + ("urllib.error", + ["ContentTooShortError"])], + "urllib2" : [ + ("urllib.request", + ["urlopen", "install_opener", "build_opener", + "Request", "OpenerDirector", "BaseHandler", + "HTTPDefaultErrorHandler", "HTTPRedirectHandler", + "HTTPCookieProcessor", "ProxyHandler", + "HTTPPasswordMgr", + "HTTPPasswordMgrWithDefaultRealm", + "AbstractBasicAuthHandler", + "HTTPBasicAuthHandler", "ProxyBasicAuthHandler", + "AbstractDigestAuthHandler", + "HTTPDigestAuthHandler", "ProxyDigestAuthHandler", + "HTTPHandler", "HTTPSHandler", "FileHandler", + "FTPHandler", "CacheFTPHandler", + "UnknownHandler"]), + ("urllib.error", + ["URLError", "HTTPError"]), + ] +} + +# Duplicate the url parsing functions for urllib2. +MAPPING["urllib2"].append(MAPPING["urllib"][1]) + + +def build_pattern(): + bare = set() + for old_module, changes in MAPPING.items(): + for change in changes: + new_module, members = change + members = alternates(members) + yield """import_name< 'import' (module=%r + | dotted_as_names< any* module=%r any* >) > + """ % (old_module, old_module) + yield """import_from< 'from' mod_member=%r 'import' + ( member=%s | import_as_name< member=%s 'as' any > | + import_as_names< members=any* >) > + """ % (old_module, members, members) + yield """import_from< 'from' module_star=%r 'import' star='*' > + """ % old_module + yield """import_name< 'import' + dotted_as_name< module_as=%r 'as' any > > + """ % old_module + # bare_with_attr has a special significance for FixImports.match(). + yield """power< bare_with_attr=%r trailer< '.' member=%s > any* > + """ % (old_module, members) + + +class FixUrllib(FixImports): + + def build_pattern(self): + return "|".join(build_pattern()) + + def transform_import(self, node, results): + """Transform for the basic import case. Replaces the old + import name with a comma separated list of its + replacements. + """ + import_mod = results.get("module") + pref = import_mod.prefix + + names = [] + + # create a Node list of the replacement modules + for name in MAPPING[import_mod.value][:-1]: + names.extend([Name(name[0], prefix=pref), Comma()]) + names.append(Name(MAPPING[import_mod.value][-1][0], prefix=pref)) + import_mod.replace(names) + + def transform_member(self, node, results): + """Transform for imports of specific module elements. Replaces + the module to be imported from with the appropriate new + module. + """ + mod_member = results.get("mod_member") + pref = mod_member.prefix + member = results.get("member") + + # Simple case with only a single member being imported + if member: + # this may be a list of length one, or just a node + if isinstance(member, list): + member = member[0] + new_name = None + for change in MAPPING[mod_member.value]: + if member.value in change[1]: + new_name = change[0] + break + if new_name: + mod_member.replace(Name(new_name, prefix=pref)) + else: + self.cannot_convert(node, "This is an invalid module element") + + # Multiple members being imported + else: + # a dictionary for replacements, order matters + modules = [] + mod_dict = {} + members = results["members"] + for member in members: + # we only care about the actual members + if member.type == syms.import_as_name: + as_name = member.children[2].value + member_name = member.children[0].value + else: + member_name = member.value + as_name = None + if member_name != u",": + for change in MAPPING[mod_member.value]: + if member_name in change[1]: + if change[0] not in mod_dict: + modules.append(change[0]) + mod_dict.setdefault(change[0], []).append(member) + + new_nodes = [] + indentation = find_indentation(node) + first = True + def handle_name(name, prefix): + if name.type == syms.import_as_name: + kids = [Name(name.children[0].value, prefix=prefix), + name.children[1].clone(), + name.children[2].clone()] + return [Node(syms.import_as_name, kids)] + return [Name(name.value, prefix=prefix)] + for module in modules: + elts = mod_dict[module] + names = [] + for elt in elts[:-1]: + names.extend(handle_name(elt, pref)) + names.append(Comma()) + names.extend(handle_name(elts[-1], pref)) + new = FromImport(module, names) + if not first or node.parent.prefix.endswith(indentation): + new.prefix = indentation + new_nodes.append(new) + first = False + if new_nodes: + nodes = [] + for new_node in new_nodes[:-1]: + nodes.extend([new_node, Newline()]) + nodes.append(new_nodes[-1]) + node.replace(nodes) + else: + self.cannot_convert(node, "All module elements are invalid") + + def transform_dot(self, node, results): + """Transform for calls to module members in code.""" + module_dot = results.get("bare_with_attr") + member = results.get("member") + new_name = None + if isinstance(member, list): + member = member[0] + for change in MAPPING[module_dot.value]: + if member.value in change[1]: + new_name = change[0] + break + if new_name: + module_dot.replace(Name(new_name, + prefix=module_dot.prefix)) + else: + self.cannot_convert(node, "This is an invalid module element") + + def transform(self, node, results): + if results.get("module"): + self.transform_import(node, results) + elif results.get("mod_member"): + self.transform_member(node, results) + elif results.get("bare_with_attr"): + self.transform_dot(node, results) + # Renaming and star imports are not supported for these modules. + elif results.get("module_star"): + self.cannot_convert(node, "Cannot handle star imports.") + elif results.get("module_as"): + self.cannot_convert(node, "This module is now multiple modules") diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_ws_comma.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_ws_comma.py new file mode 100644 index 0000000..37ff624 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_ws_comma.py @@ -0,0 +1,39 @@ +"""Fixer that changes 'a ,b' into 'a, b'. + +This also changes '{a :b}' into '{a: b}', but does not touch other +uses of colons. It does not touch other uses of whitespace. + +""" + +from .. import pytree +from ..pgen2 import token +from .. import fixer_base + +class FixWsComma(fixer_base.BaseFix): + + explicit = True # The user must ask for this fixers + + PATTERN = """ + any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]> + """ + + COMMA = pytree.Leaf(token.COMMA, u",") + COLON = pytree.Leaf(token.COLON, u":") + SEPS = (COMMA, COLON) + + def transform(self, node, results): + new = node.clone() + comma = False + for child in new.children: + if child in self.SEPS: + prefix = child.prefix + if prefix.isspace() and u"\n" not in prefix: + child.prefix = u"" + comma = True + else: + if comma: + prefix = child.prefix + if not prefix: + child.prefix = u" " + comma = False + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_xrange.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_xrange.py new file mode 100644 index 0000000..f143672 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_xrange.py @@ -0,0 +1,73 @@ +# Copyright 2007 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Fixer that changes xrange(...) into range(...).""" + +# Local imports +from .. import fixer_base +from ..fixer_util import Name, Call, consuming_calls +from .. import patcomp + + +class FixXrange(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< + (name='range'|name='xrange') trailer< '(' args=any ')' > + rest=any* > + """ + + def start_tree(self, tree, filename): + super(FixXrange, self).start_tree(tree, filename) + self.transformed_xranges = set() + + def finish_tree(self, tree, filename): + self.transformed_xranges = None + + def transform(self, node, results): + name = results["name"] + if name.value == u"xrange": + return self.transform_xrange(node, results) + elif name.value == u"range": + return self.transform_range(node, results) + else: + raise ValueError(repr(name)) + + def transform_xrange(self, node, results): + name = results["name"] + name.replace(Name(u"range", prefix=name.prefix)) + # This prevents the new range call from being wrapped in a list later. + self.transformed_xranges.add(id(node)) + + def transform_range(self, node, results): + if (id(node) not in self.transformed_xranges and + not self.in_special_context(node)): + range_call = Call(Name(u"range"), [results["args"].clone()]) + # Encase the range call in list(). + list_call = Call(Name(u"list"), [range_call], + prefix=node.prefix) + # Put things that were after the range() call after the list call. + for n in results["rest"]: + list_call.append_child(n) + return list_call + + P1 = "power< func=NAME trailer< '(' node=any ')' > any* >" + p1 = patcomp.compile_pattern(P1) + + P2 = """for_stmt< 'for' any 'in' node=any ':' any* > + | comp_for< 'for' any 'in' node=any any* > + | comparison< any 'in' node=any any*> + """ + p2 = patcomp.compile_pattern(P2) + + def in_special_context(self, node): + if node.parent is None: + return False + results = {} + if (node.parent.parent is not None and + self.p1.match(node.parent.parent, results) and + results["node"] is node): + # list(d.keys()) -> list(d.keys()), etc. + return results["func"].value in consuming_calls + # for ... in d.iterkeys() -> for ... in d.keys(), etc. + return self.p2.match(node.parent, results) and results["node"] is node diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_xreadlines.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_xreadlines.py new file mode 100644 index 0000000..f50b9a2 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_xreadlines.py @@ -0,0 +1,25 @@ +"""Fix "for x in f.xreadlines()" -> "for x in f". + +This fixer will also convert g(f.xreadlines) into g(f.__iter__).""" +# Author: Collin Winter + +# Local imports +from .. import fixer_base +from ..fixer_util import Name + + +class FixXreadlines(fixer_base.BaseFix): + BM_compatible = True + PATTERN = """ + power< call=any+ trailer< '.' 'xreadlines' > trailer< '(' ')' > > + | + power< any+ trailer< '.' no_call='xreadlines' > > + """ + + def transform(self, node, results): + no_call = results.get("no_call") + + if no_call: + no_call.replace(Name(u"__iter__", prefix=no_call.prefix)) + else: + node.replace([x.clone() for x in results["call"]]) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_zip.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_zip.py new file mode 100644 index 0000000..c5d7b66 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/fixes/fix_zip.py @@ -0,0 +1,35 @@ +""" +Fixer that changes zip(seq0, seq1, ...) into list(zip(seq0, seq1, ...) +unless there exists a 'from future_builtins import zip' statement in the +top-level namespace. + +We avoid the transformation if the zip() call is directly contained in +iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or for V in <>:. +""" + +# Local imports +from .. import fixer_base +from ..fixer_util import Name, Call, in_special_context + +class FixZip(fixer_base.ConditionalFix): + + BM_compatible = True + PATTERN = """ + power< 'zip' args=trailer< '(' [any] ')' > + > + """ + + skip_on = "future_builtins.zip" + + def transform(self, node, results): + if self.should_skip(node): + return + + if in_special_context(node): + return None + + new = node.clone() + new.prefix = u"" + new = Call(Name(u"list"), [new]) + new.prefix = node.prefix + return new diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/main.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/main.py new file mode 100644 index 0000000..ad0625e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/main.py @@ -0,0 +1,269 @@ +""" +Main program for 2to3. +""" + +from __future__ import with_statement + +import sys +import os +import difflib +import logging +import shutil +import optparse + +from . import refactor + + +def diff_texts(a, b, filename): + """Return a unified diff of two strings.""" + a = a.splitlines() + b = b.splitlines() + return difflib.unified_diff(a, b, filename, filename, + "(original)", "(refactored)", + lineterm="") + + +class StdoutRefactoringTool(refactor.MultiprocessRefactoringTool): + """ + A refactoring tool that can avoid overwriting its input files. + Prints output to stdout. + + Output files can optionally be written to a different directory and or + have an extra file suffix appended to their name for use in situations + where you do not want to replace the input files. + """ + + def __init__(self, fixers, options, explicit, nobackups, show_diffs, + input_base_dir='', output_dir='', append_suffix=''): + """ + Args: + fixers: A list of fixers to import. + options: A dict with RefactoringTool configuration. + explicit: A list of fixers to run even if they are explicit. + nobackups: If true no backup '.bak' files will be created for those + files that are being refactored. + show_diffs: Should diffs of the refactoring be printed to stdout? + input_base_dir: The base directory for all input files. This class + will strip this path prefix off of filenames before substituting + it with output_dir. Only meaningful if output_dir is supplied. + All files processed by refactor() must start with this path. + output_dir: If supplied, all converted files will be written into + this directory tree instead of input_base_dir. + append_suffix: If supplied, all files output by this tool will have + this appended to their filename. Useful for changing .py to + .py3 for example by passing append_suffix='3'. + """ + self.nobackups = nobackups + self.show_diffs = show_diffs + if input_base_dir and not input_base_dir.endswith(os.sep): + input_base_dir += os.sep + self._input_base_dir = input_base_dir + self._output_dir = output_dir + self._append_suffix = append_suffix + super(StdoutRefactoringTool, self).__init__(fixers, options, explicit) + + def log_error(self, msg, *args, **kwargs): + self.errors.append((msg, args, kwargs)) + self.logger.error(msg, *args, **kwargs) + + def write_file(self, new_text, filename, old_text, encoding): + orig_filename = filename + if self._output_dir: + if filename.startswith(self._input_base_dir): + filename = os.path.join(self._output_dir, + filename[len(self._input_base_dir):]) + else: + raise ValueError('filename %s does not start with the ' + 'input_base_dir %s' % ( + filename, self._input_base_dir)) + if self._append_suffix: + filename += self._append_suffix + if orig_filename != filename: + output_dir = os.path.dirname(filename) + if not os.path.isdir(output_dir): + os.makedirs(output_dir) + self.log_message('Writing converted %s to %s.', orig_filename, + filename) + if not self.nobackups: + # Make backup + backup = filename + ".bak" + if os.path.lexists(backup): + try: + os.remove(backup) + except os.error, err: + self.log_message("Can't remove backup %s", backup) + try: + os.rename(filename, backup) + except os.error, err: + self.log_message("Can't rename %s to %s", filename, backup) + # Actually write the new file + write = super(StdoutRefactoringTool, self).write_file + write(new_text, filename, old_text, encoding) + if not self.nobackups: + shutil.copymode(backup, filename) + if orig_filename != filename: + # Preserve the file mode in the new output directory. + shutil.copymode(orig_filename, filename) + + def print_output(self, old, new, filename, equal): + if equal: + self.log_message("No changes to %s", filename) + else: + self.log_message("Refactored %s", filename) + if self.show_diffs: + diff_lines = diff_texts(old, new, filename) + try: + if self.output_lock is not None: + with self.output_lock: + for line in diff_lines: + print line + sys.stdout.flush() + else: + for line in diff_lines: + print line + except UnicodeEncodeError: + warn("couldn't encode %s's diff for your terminal" % + (filename,)) + return + + +def warn(msg): + print >> sys.stderr, "WARNING: %s" % (msg,) + + +def main(fixer_pkg, args=None): + """Main program. + + Args: + fixer_pkg: the name of a package where the fixers are located. + args: optional; a list of command line arguments. If omitted, + sys.argv[1:] is used. + + Returns a suggested exit status (0, 1, 2). + """ + # Set up option parser + parser = optparse.OptionParser(usage="2to3 [options] file|dir ...") + parser.add_option("-d", "--doctests_only", action="store_true", + help="Fix up doctests only") + parser.add_option("-f", "--fix", action="append", default=[], + help="Each FIX specifies a transformation; default: all") + parser.add_option("-j", "--processes", action="store", default=1, + type="int", help="Run 2to3 concurrently") + parser.add_option("-x", "--nofix", action="append", default=[], + help="Prevent a transformation from being run") + parser.add_option("-l", "--list-fixes", action="store_true", + help="List available transformations") + parser.add_option("-p", "--print-function", action="store_true", + help="Modify the grammar so that print() is a function") + parser.add_option("-v", "--verbose", action="store_true", + help="More verbose logging") + parser.add_option("--no-diffs", action="store_true", + help="Don't show diffs of the refactoring") + parser.add_option("-w", "--write", action="store_true", + help="Write back modified files") + parser.add_option("-n", "--nobackups", action="store_true", default=False, + help="Don't write backups for modified files") + parser.add_option("-o", "--output-dir", action="store", type="str", + default="", help="Put output files in this directory " + "instead of overwriting the input files. Requires -n.") + parser.add_option("-W", "--write-unchanged-files", action="store_true", + help="Also write files even if no changes were required" + " (useful with --output-dir); implies -w.") + parser.add_option("--add-suffix", action="store", type="str", default="", + help="Append this string to all output filenames." + " Requires -n if non-empty. " + "ex: --add-suffix='3' will generate .py3 files.") + + # Parse command line arguments + refactor_stdin = False + flags = {} + options, args = parser.parse_args(args) + if options.write_unchanged_files: + flags["write_unchanged_files"] = True + if not options.write: + warn("--write-unchanged-files/-W implies -w.") + options.write = True + # If we allowed these, the original files would be renamed to backup names + # but not replaced. + if options.output_dir and not options.nobackups: + parser.error("Can't use --output-dir/-o without -n.") + if options.add_suffix and not options.nobackups: + parser.error("Can't use --add-suffix without -n.") + + if not options.write and options.no_diffs: + warn("not writing files and not printing diffs; that's not very useful") + if not options.write and options.nobackups: + parser.error("Can't use -n without -w") + if options.list_fixes: + print "Available transformations for the -f/--fix option:" + for fixname in refactor.get_all_fix_names(fixer_pkg): + print fixname + if not args: + return 0 + if not args: + print >> sys.stderr, "At least one file or directory argument required." + print >> sys.stderr, "Use --help to show usage." + return 2 + if "-" in args: + refactor_stdin = True + if options.write: + print >> sys.stderr, "Can't write to stdin." + return 2 + if options.print_function: + flags["print_function"] = True + + # Set up logging handler + level = logging.DEBUG if options.verbose else logging.INFO + logging.basicConfig(format='%(name)s: %(message)s', level=level) + logger = logging.getLogger('lib2to3.main') + + # Initialize the refactoring tool + avail_fixes = set(refactor.get_fixers_from_package(fixer_pkg)) + unwanted_fixes = set(fixer_pkg + ".fix_" + fix for fix in options.nofix) + explicit = set() + if options.fix: + all_present = False + for fix in options.fix: + if fix == "all": + all_present = True + else: + explicit.add(fixer_pkg + ".fix_" + fix) + requested = avail_fixes.union(explicit) if all_present else explicit + else: + requested = avail_fixes.union(explicit) + fixer_names = requested.difference(unwanted_fixes) + input_base_dir = os.path.commonprefix(args) + if (input_base_dir and not input_base_dir.endswith(os.sep) + and not os.path.isdir(input_base_dir)): + # One or more similar names were passed, their directory is the base. + # os.path.commonprefix() is ignorant of path elements, this corrects + # for that weird API. + input_base_dir = os.path.dirname(input_base_dir) + if options.output_dir: + input_base_dir = input_base_dir.rstrip(os.sep) + logger.info('Output in %r will mirror the input directory %r layout.', + options.output_dir, input_base_dir) + rt = StdoutRefactoringTool( + sorted(fixer_names), flags, sorted(explicit), + options.nobackups, not options.no_diffs, + input_base_dir=input_base_dir, + output_dir=options.output_dir, + append_suffix=options.add_suffix) + + # Refactor all files and directories passed as arguments + if not rt.errors: + if refactor_stdin: + rt.refactor_stdin() + else: + try: + rt.refactor(args, options.write, options.doctests_only, + options.processes) + except refactor.MultiprocessingUnsupported: + assert options.processes > 1 + print >> sys.stderr, "Sorry, -j isn't " \ + "supported on this platform." + return 1 + rt.summarize() + + # Return error status (0 if rt.errors is zero) + return int(bool(rt.errors)) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/patcomp.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/patcomp.py new file mode 100644 index 0000000..093e5f9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/patcomp.py @@ -0,0 +1,205 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Pattern compiler. + +The grammer is taken from PatternGrammar.txt. + +The compiler compiles a pattern to a pytree.*Pattern instance. +""" + +__author__ = "Guido van Rossum " + +# Python imports +import os +import StringIO + +# Fairly local imports +from .pgen2 import driver, literals, token, tokenize, parse, grammar + +# Really local imports +from . import pytree +from . import pygram + +# The pattern grammar file +_PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), + "PatternGrammar.txt") + + +class PatternSyntaxError(Exception): + pass + + +def tokenize_wrapper(input): + """Tokenizes a string suppressing significant whitespace.""" + skip = set((token.NEWLINE, token.INDENT, token.DEDENT)) + tokens = tokenize.generate_tokens(StringIO.StringIO(input).readline) + for quintuple in tokens: + type, value, start, end, line_text = quintuple + if type not in skip: + yield quintuple + + +class PatternCompiler(object): + + def __init__(self, grammar_file=_PATTERN_GRAMMAR_FILE): + """Initializer. + + Takes an optional alternative filename for the pattern grammar. + """ + self.grammar = driver.load_grammar(grammar_file) + self.syms = pygram.Symbols(self.grammar) + self.pygrammar = pygram.python_grammar + self.pysyms = pygram.python_symbols + self.driver = driver.Driver(self.grammar, convert=pattern_convert) + + def compile_pattern(self, input, debug=False, with_tree=False): + """Compiles a pattern string to a nested pytree.*Pattern object.""" + tokens = tokenize_wrapper(input) + try: + root = self.driver.parse_tokens(tokens, debug=debug) + except parse.ParseError as e: + raise PatternSyntaxError(str(e)) + if with_tree: + return self.compile_node(root), root + else: + return self.compile_node(root) + + def compile_node(self, node): + """Compiles a node, recursively. + + This is one big switch on the node type. + """ + # XXX Optimize certain Wildcard-containing-Wildcard patterns + # that can be merged + if node.type == self.syms.Matcher: + node = node.children[0] # Avoid unneeded recursion + + if node.type == self.syms.Alternatives: + # Skip the odd children since they are just '|' tokens + alts = [self.compile_node(ch) for ch in node.children[::2]] + if len(alts) == 1: + return alts[0] + p = pytree.WildcardPattern([[a] for a in alts], min=1, max=1) + return p.optimize() + + if node.type == self.syms.Alternative: + units = [self.compile_node(ch) for ch in node.children] + if len(units) == 1: + return units[0] + p = pytree.WildcardPattern([units], min=1, max=1) + return p.optimize() + + if node.type == self.syms.NegatedUnit: + pattern = self.compile_basic(node.children[1:]) + p = pytree.NegatedPattern(pattern) + return p.optimize() + + assert node.type == self.syms.Unit + + name = None + nodes = node.children + if len(nodes) >= 3 and nodes[1].type == token.EQUAL: + name = nodes[0].value + nodes = nodes[2:] + repeat = None + if len(nodes) >= 2 and nodes[-1].type == self.syms.Repeater: + repeat = nodes[-1] + nodes = nodes[:-1] + + # Now we've reduced it to: STRING | NAME [Details] | (...) | [...] + pattern = self.compile_basic(nodes, repeat) + + if repeat is not None: + assert repeat.type == self.syms.Repeater + children = repeat.children + child = children[0] + if child.type == token.STAR: + min = 0 + max = pytree.HUGE + elif child.type == token.PLUS: + min = 1 + max = pytree.HUGE + elif child.type == token.LBRACE: + assert children[-1].type == token.RBRACE + assert len(children) in (3, 5) + min = max = self.get_int(children[1]) + if len(children) == 5: + max = self.get_int(children[3]) + else: + assert False + if min != 1 or max != 1: + pattern = pattern.optimize() + pattern = pytree.WildcardPattern([[pattern]], min=min, max=max) + + if name is not None: + pattern.name = name + return pattern.optimize() + + def compile_basic(self, nodes, repeat=None): + # Compile STRING | NAME [Details] | (...) | [...] + assert len(nodes) >= 1 + node = nodes[0] + if node.type == token.STRING: + value = unicode(literals.evalString(node.value)) + return pytree.LeafPattern(_type_of_literal(value), value) + elif node.type == token.NAME: + value = node.value + if value.isupper(): + if value not in TOKEN_MAP: + raise PatternSyntaxError("Invalid token: %r" % value) + if nodes[1:]: + raise PatternSyntaxError("Can't have details for token") + return pytree.LeafPattern(TOKEN_MAP[value]) + else: + if value == "any": + type = None + elif not value.startswith("_"): + type = getattr(self.pysyms, value, None) + if type is None: + raise PatternSyntaxError("Invalid symbol: %r" % value) + if nodes[1:]: # Details present + content = [self.compile_node(nodes[1].children[1])] + else: + content = None + return pytree.NodePattern(type, content) + elif node.value == "(": + return self.compile_node(nodes[1]) + elif node.value == "[": + assert repeat is None + subpattern = self.compile_node(nodes[1]) + return pytree.WildcardPattern([[subpattern]], min=0, max=1) + assert False, node + + def get_int(self, node): + assert node.type == token.NUMBER + return int(node.value) + + +# Map named tokens to the type value for a LeafPattern +TOKEN_MAP = {"NAME": token.NAME, + "STRING": token.STRING, + "NUMBER": token.NUMBER, + "TOKEN": None} + + +def _type_of_literal(value): + if value[0].isalpha(): + return token.NAME + elif value in grammar.opmap: + return grammar.opmap[value] + else: + return None + + +def pattern_convert(grammar, raw_node_info): + """Converts raw node information to a Node or Leaf instance.""" + type, value, context, children = raw_node_info + if children or type in grammar.number2symbol: + return pytree.Node(type, children, context=context) + else: + return pytree.Leaf(type, value, context=context) + + +def compile_pattern(pattern): + return PatternCompiler().compile_pattern(pattern) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/__init__.py new file mode 100644 index 0000000..af39048 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""The pgen2 package.""" diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/conv.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/conv.py new file mode 100644 index 0000000..28fbb0b --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/conv.py @@ -0,0 +1,257 @@ +# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Convert graminit.[ch] spit out by pgen to Python code. + +Pgen is the Python parser generator. It is useful to quickly create a +parser from a grammar file in Python's grammar notation. But I don't +want my parsers to be written in C (yet), so I'm translating the +parsing tables to Python data structures and writing a Python parse +engine. + +Note that the token numbers are constants determined by the standard +Python tokenizer. The standard token module defines these numbers and +their names (the names are not used much). The token numbers are +hardcoded into the Python tokenizer and into pgen. A Python +implementation of the Python tokenizer is also available, in the +standard tokenize module. + +On the other hand, symbol numbers (representing the grammar's +non-terminals) are assigned by pgen based on the actual grammar +input. + +Note: this module is pretty much obsolete; the pgen module generates +equivalent grammar tables directly from the Grammar.txt input file +without having to invoke the Python pgen C program. + +""" + +# Python imports +import re + +# Local imports +from pgen2 import grammar, token + + +class Converter(grammar.Grammar): + """Grammar subclass that reads classic pgen output files. + + The run() method reads the tables as produced by the pgen parser + generator, typically contained in two C files, graminit.h and + graminit.c. The other methods are for internal use only. + + See the base class for more documentation. + + """ + + def run(self, graminit_h, graminit_c): + """Load the grammar tables from the text files written by pgen.""" + self.parse_graminit_h(graminit_h) + self.parse_graminit_c(graminit_c) + self.finish_off() + + def parse_graminit_h(self, filename): + """Parse the .h file written by pgen. (Internal) + + This file is a sequence of #define statements defining the + nonterminals of the grammar as numbers. We build two tables + mapping the numbers to names and back. + + """ + try: + f = open(filename) + except IOError, err: + print "Can't open %s: %s" % (filename, err) + return False + self.symbol2number = {} + self.number2symbol = {} + lineno = 0 + for line in f: + lineno += 1 + mo = re.match(r"^#define\s+(\w+)\s+(\d+)$", line) + if not mo and line.strip(): + print "%s(%s): can't parse %s" % (filename, lineno, + line.strip()) + else: + symbol, number = mo.groups() + number = int(number) + assert symbol not in self.symbol2number + assert number not in self.number2symbol + self.symbol2number[symbol] = number + self.number2symbol[number] = symbol + return True + + def parse_graminit_c(self, filename): + """Parse the .c file written by pgen. (Internal) + + The file looks as follows. The first two lines are always this: + + #include "pgenheaders.h" + #include "grammar.h" + + After that come four blocks: + + 1) one or more state definitions + 2) a table defining dfas + 3) a table defining labels + 4) a struct defining the grammar + + A state definition has the following form: + - one or more arc arrays, each of the form: + static arc arcs__[] = { + {, }, + ... + }; + - followed by a state array, of the form: + static state states_[] = { + {, arcs__}, + ... + }; + + """ + try: + f = open(filename) + except IOError, err: + print "Can't open %s: %s" % (filename, err) + return False + # The code below essentially uses f's iterator-ness! + lineno = 0 + + # Expect the two #include lines + lineno, line = lineno+1, f.next() + assert line == '#include "pgenheaders.h"\n', (lineno, line) + lineno, line = lineno+1, f.next() + assert line == '#include "grammar.h"\n', (lineno, line) + + # Parse the state definitions + lineno, line = lineno+1, f.next() + allarcs = {} + states = [] + while line.startswith("static arc "): + while line.startswith("static arc "): + mo = re.match(r"static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$", + line) + assert mo, (lineno, line) + n, m, k = map(int, mo.groups()) + arcs = [] + for _ in range(k): + lineno, line = lineno+1, f.next() + mo = re.match(r"\s+{(\d+), (\d+)},$", line) + assert mo, (lineno, line) + i, j = map(int, mo.groups()) + arcs.append((i, j)) + lineno, line = lineno+1, f.next() + assert line == "};\n", (lineno, line) + allarcs[(n, m)] = arcs + lineno, line = lineno+1, f.next() + mo = re.match(r"static state states_(\d+)\[(\d+)\] = {$", line) + assert mo, (lineno, line) + s, t = map(int, mo.groups()) + assert s == len(states), (lineno, line) + state = [] + for _ in range(t): + lineno, line = lineno+1, f.next() + mo = re.match(r"\s+{(\d+), arcs_(\d+)_(\d+)},$", line) + assert mo, (lineno, line) + k, n, m = map(int, mo.groups()) + arcs = allarcs[n, m] + assert k == len(arcs), (lineno, line) + state.append(arcs) + states.append(state) + lineno, line = lineno+1, f.next() + assert line == "};\n", (lineno, line) + lineno, line = lineno+1, f.next() + self.states = states + + # Parse the dfas + dfas = {} + mo = re.match(r"static dfa dfas\[(\d+)\] = {$", line) + assert mo, (lineno, line) + ndfas = int(mo.group(1)) + for i in range(ndfas): + lineno, line = lineno+1, f.next() + mo = re.match(r'\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$', + line) + assert mo, (lineno, line) + symbol = mo.group(2) + number, x, y, z = map(int, mo.group(1, 3, 4, 5)) + assert self.symbol2number[symbol] == number, (lineno, line) + assert self.number2symbol[number] == symbol, (lineno, line) + assert x == 0, (lineno, line) + state = states[z] + assert y == len(state), (lineno, line) + lineno, line = lineno+1, f.next() + mo = re.match(r'\s+("(?:\\\d\d\d)*")},$', line) + assert mo, (lineno, line) + first = {} + rawbitset = eval(mo.group(1)) + for i, c in enumerate(rawbitset): + byte = ord(c) + for j in range(8): + if byte & (1<= os.path.getmtime(b) + + +def main(*args): + """Main program, when run as a script: produce grammar pickle files. + + Calls load_grammar for each argument, a path to a grammar text file. + """ + if not args: + args = sys.argv[1:] + logging.basicConfig(level=logging.INFO, stream=sys.stdout, + format='%(message)s') + for gt in args: + load_grammar(gt, save=True, force=True) + return True + +if __name__ == "__main__": + sys.exit(int(not main())) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/grammar.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/grammar.py new file mode 100644 index 0000000..1aa5c43 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/grammar.py @@ -0,0 +1,184 @@ +# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""This module defines the data structures used to represent a grammar. + +These are a bit arcane because they are derived from the data +structures used by Python's 'pgen' parser generator. + +There's also a table here mapping operators to their names in the +token module; the Python tokenize module reports all operators as the +fallback token code OP, but the parser needs the actual token code. + +""" + +# Python imports +import pickle + +# Local imports +from . import token, tokenize + + +class Grammar(object): + """Pgen parsing tables conversion class. + + Once initialized, this class supplies the grammar tables for the + parsing engine implemented by parse.py. The parsing engine + accesses the instance variables directly. The class here does not + provide initialization of the tables; several subclasses exist to + do this (see the conv and pgen modules). + + The load() method reads the tables from a pickle file, which is + much faster than the other ways offered by subclasses. The pickle + file is written by calling dump() (after loading the grammar + tables using a subclass). The report() method prints a readable + representation of the tables to stdout, for debugging. + + The instance variables are as follows: + + symbol2number -- a dict mapping symbol names to numbers. Symbol + numbers are always 256 or higher, to distinguish + them from token numbers, which are between 0 and + 255 (inclusive). + + number2symbol -- a dict mapping numbers to symbol names; + these two are each other's inverse. + + states -- a list of DFAs, where each DFA is a list of + states, each state is a list of arcs, and each + arc is a (i, j) pair where i is a label and j is + a state number. The DFA number is the index into + this list. (This name is slightly confusing.) + Final states are represented by a special arc of + the form (0, j) where j is its own state number. + + dfas -- a dict mapping symbol numbers to (DFA, first) + pairs, where DFA is an item from the states list + above, and first is a set of tokens that can + begin this grammar rule (represented by a dict + whose values are always 1). + + labels -- a list of (x, y) pairs where x is either a token + number or a symbol number, and y is either None + or a string; the strings are keywords. The label + number is the index in this list; label numbers + are used to mark state transitions (arcs) in the + DFAs. + + start -- the number of the grammar's start symbol. + + keywords -- a dict mapping keyword strings to arc labels. + + tokens -- a dict mapping token numbers to arc labels. + + """ + + def __init__(self): + self.symbol2number = {} + self.number2symbol = {} + self.states = [] + self.dfas = {} + self.labels = [(0, "EMPTY")] + self.keywords = {} + self.tokens = {} + self.symbol2label = {} + self.start = 256 + + def dump(self, filename): + """Dump the grammar tables to a pickle file.""" + f = open(filename, "wb") + pickle.dump(self.__dict__, f, 2) + f.close() + + def load(self, filename): + """Load the grammar tables from a pickle file.""" + f = open(filename, "rb") + d = pickle.load(f) + f.close() + self.__dict__.update(d) + + def copy(self): + """ + Copy the grammar. + """ + new = self.__class__() + for dict_attr in ("symbol2number", "number2symbol", "dfas", "keywords", + "tokens", "symbol2label"): + setattr(new, dict_attr, getattr(self, dict_attr).copy()) + new.labels = self.labels[:] + new.states = self.states[:] + new.start = self.start + return new + + def report(self): + """Dump the grammar tables to standard output, for debugging.""" + from pprint import pprint + print "s2n" + pprint(self.symbol2number) + print "n2s" + pprint(self.number2symbol) + print "states" + pprint(self.states) + print "dfas" + pprint(self.dfas) + print "labels" + pprint(self.labels) + print "start", self.start + + +# Map from operator to number (since tokenize doesn't do this) + +opmap_raw = """ +( LPAR +) RPAR +[ LSQB +] RSQB +: COLON +, COMMA +; SEMI ++ PLUS +- MINUS +* STAR +/ SLASH +| VBAR +& AMPER +< LESS +> GREATER += EQUAL +. DOT +% PERCENT +` BACKQUOTE +{ LBRACE +} RBRACE +@ AT +== EQEQUAL +!= NOTEQUAL +<> NOTEQUAL +<= LESSEQUAL +>= GREATEREQUAL +~ TILDE +^ CIRCUMFLEX +<< LEFTSHIFT +>> RIGHTSHIFT +** DOUBLESTAR ++= PLUSEQUAL +-= MINEQUAL +*= STAREQUAL +/= SLASHEQUAL +%= PERCENTEQUAL +&= AMPEREQUAL +|= VBAREQUAL +^= CIRCUMFLEXEQUAL +<<= LEFTSHIFTEQUAL +>>= RIGHTSHIFTEQUAL +**= DOUBLESTAREQUAL +// DOUBLESLASH +//= DOUBLESLASHEQUAL +-> RARROW +""" + +opmap = {} +for line in opmap_raw.splitlines(): + if line: + op, name = line.split() + opmap[op] = getattr(token, name) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/literals.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/literals.py new file mode 100644 index 0000000..0b3948a --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/literals.py @@ -0,0 +1,60 @@ +# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Safely evaluate Python string literals without using eval().""" + +import re + +simple_escapes = {"a": "\a", + "b": "\b", + "f": "\f", + "n": "\n", + "r": "\r", + "t": "\t", + "v": "\v", + "'": "'", + '"': '"', + "\\": "\\"} + +def escape(m): + all, tail = m.group(0, 1) + assert all.startswith("\\") + esc = simple_escapes.get(tail) + if esc is not None: + return esc + if tail.startswith("x"): + hexes = tail[1:] + if len(hexes) < 2: + raise ValueError("invalid hex string escape ('\\%s')" % tail) + try: + i = int(hexes, 16) + except ValueError: + raise ValueError("invalid hex string escape ('\\%s')" % tail) + else: + try: + i = int(tail, 8) + except ValueError: + raise ValueError("invalid octal string escape ('\\%s')" % tail) + return chr(i) + +def evalString(s): + assert s.startswith("'") or s.startswith('"'), repr(s[:1]) + q = s[0] + if s[:3] == q*3: + q = q*3 + assert s.endswith(q), repr(s[-len(q):]) + assert len(s) >= 2*len(q) + s = s[len(q):-len(q)] + return re.sub(r"\\(\'|\"|\\|[abfnrtv]|x.{0,2}|[0-7]{1,3})", escape, s) + +def test(): + for i in range(256): + c = chr(i) + s = repr(c) + e = evalString(s) + if e != c: + print i, c, s, e + + +if __name__ == "__main__": + test() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/parse.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/parse.py new file mode 100644 index 0000000..6bebdbb --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/parse.py @@ -0,0 +1,201 @@ +# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Parser engine for the grammar tables generated by pgen. + +The grammar table must be loaded first. + +See Parser/parser.c in the Python distribution for additional info on +how this parsing engine works. + +""" + +# Local imports +from . import token + +class ParseError(Exception): + """Exception to signal the parser is stuck.""" + + def __init__(self, msg, type, value, context): + Exception.__init__(self, "%s: type=%r, value=%r, context=%r" % + (msg, type, value, context)) + self.msg = msg + self.type = type + self.value = value + self.context = context + +class Parser(object): + """Parser engine. + + The proper usage sequence is: + + p = Parser(grammar, [converter]) # create instance + p.setup([start]) # prepare for parsing + : + if p.addtoken(...): # parse a token; may raise ParseError + break + root = p.rootnode # root of abstract syntax tree + + A Parser instance may be reused by calling setup() repeatedly. + + A Parser instance contains state pertaining to the current token + sequence, and should not be used concurrently by different threads + to parse separate token sequences. + + See driver.py for how to get input tokens by tokenizing a file or + string. + + Parsing is complete when addtoken() returns True; the root of the + abstract syntax tree can then be retrieved from the rootnode + instance variable. When a syntax error occurs, addtoken() raises + the ParseError exception. There is no error recovery; the parser + cannot be used after a syntax error was reported (but it can be + reinitialized by calling setup()). + + """ + + def __init__(self, grammar, convert=None): + """Constructor. + + The grammar argument is a grammar.Grammar instance; see the + grammar module for more information. + + The parser is not ready yet for parsing; you must call the + setup() method to get it started. + + The optional convert argument is a function mapping concrete + syntax tree nodes to abstract syntax tree nodes. If not + given, no conversion is done and the syntax tree produced is + the concrete syntax tree. If given, it must be a function of + two arguments, the first being the grammar (a grammar.Grammar + instance), and the second being the concrete syntax tree node + to be converted. The syntax tree is converted from the bottom + up. + + A concrete syntax tree node is a (type, value, context, nodes) + tuple, where type is the node type (a token or symbol number), + value is None for symbols and a string for tokens, context is + None or an opaque value used for error reporting (typically a + (lineno, offset) pair), and nodes is a list of children for + symbols, and None for tokens. + + An abstract syntax tree node may be anything; this is entirely + up to the converter function. + + """ + self.grammar = grammar + self.convert = convert or (lambda grammar, node: node) + + def setup(self, start=None): + """Prepare for parsing. + + This *must* be called before starting to parse. + + The optional argument is an alternative start symbol; it + defaults to the grammar's start symbol. + + You can use a Parser instance to parse any number of programs; + each time you call setup() the parser is reset to an initial + state determined by the (implicit or explicit) start symbol. + + """ + if start is None: + start = self.grammar.start + # Each stack entry is a tuple: (dfa, state, node). + # A node is a tuple: (type, value, context, children), + # where children is a list of nodes or None, and context may be None. + newnode = (start, None, None, []) + stackentry = (self.grammar.dfas[start], 0, newnode) + self.stack = [stackentry] + self.rootnode = None + self.used_names = set() # Aliased to self.rootnode.used_names in pop() + + def addtoken(self, type, value, context): + """Add a token; return True iff this is the end of the program.""" + # Map from token to label + ilabel = self.classify(type, value, context) + # Loop until the token is shifted; may raise exceptions + while True: + dfa, state, node = self.stack[-1] + states, first = dfa + arcs = states[state] + # Look for a state with this label + for i, newstate in arcs: + t, v = self.grammar.labels[i] + if ilabel == i: + # Look it up in the list of labels + assert t < 256 + # Shift a token; we're done with it + self.shift(type, value, newstate, context) + # Pop while we are in an accept-only state + state = newstate + while states[state] == [(0, state)]: + self.pop() + if not self.stack: + # Done parsing! + return True + dfa, state, node = self.stack[-1] + states, first = dfa + # Done with this token + return False + elif t >= 256: + # See if it's a symbol and if we're in its first set + itsdfa = self.grammar.dfas[t] + itsstates, itsfirst = itsdfa + if ilabel in itsfirst: + # Push a symbol + self.push(t, self.grammar.dfas[t], newstate, context) + break # To continue the outer while loop + else: + if (0, state) in arcs: + # An accepting state, pop it and try something else + self.pop() + if not self.stack: + # Done parsing, but another token is input + raise ParseError("too much input", + type, value, context) + else: + # No success finding a transition + raise ParseError("bad input", type, value, context) + + def classify(self, type, value, context): + """Turn a token into a label. (Internal)""" + if type == token.NAME: + # Keep a listing of all used names + self.used_names.add(value) + # Check for reserved words + ilabel = self.grammar.keywords.get(value) + if ilabel is not None: + return ilabel + ilabel = self.grammar.tokens.get(type) + if ilabel is None: + raise ParseError("bad token", type, value, context) + return ilabel + + def shift(self, type, value, newstate, context): + """Shift a token. (Internal)""" + dfa, state, node = self.stack[-1] + newnode = (type, value, context, None) + newnode = self.convert(self.grammar, newnode) + if newnode is not None: + node[-1].append(newnode) + self.stack[-1] = (dfa, newstate, node) + + def push(self, type, newdfa, newstate, context): + """Push a nonterminal. (Internal)""" + dfa, state, node = self.stack[-1] + newnode = (type, None, context, []) + self.stack[-1] = (dfa, newstate, node) + self.stack.append((newdfa, 0, newnode)) + + def pop(self): + """Pop a nonterminal. (Internal)""" + popdfa, popstate, popnode = self.stack.pop() + newnode = self.convert(self.grammar, popnode) + if newnode is not None: + if self.stack: + dfa, state, node = self.stack[-1] + node[-1].append(newnode) + else: + self.rootnode = newnode + self.rootnode.used_names = self.used_names diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/pgen.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/pgen.py new file mode 100644 index 0000000..63084a4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/pgen.py @@ -0,0 +1,386 @@ +# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +# Pgen imports +from . import grammar, token, tokenize + +class PgenGrammar(grammar.Grammar): + pass + +class ParserGenerator(object): + + def __init__(self, filename, stream=None): + close_stream = None + if stream is None: + stream = open(filename) + close_stream = stream.close + self.filename = filename + self.stream = stream + self.generator = tokenize.generate_tokens(stream.readline) + self.gettoken() # Initialize lookahead + self.dfas, self.startsymbol = self.parse() + if close_stream is not None: + close_stream() + self.first = {} # map from symbol name to set of tokens + self.addfirstsets() + + def make_grammar(self): + c = PgenGrammar() + names = self.dfas.keys() + names.sort() + names.remove(self.startsymbol) + names.insert(0, self.startsymbol) + for name in names: + i = 256 + len(c.symbol2number) + c.symbol2number[name] = i + c.number2symbol[i] = name + for name in names: + dfa = self.dfas[name] + states = [] + for state in dfa: + arcs = [] + for label, next in state.arcs.iteritems(): + arcs.append((self.make_label(c, label), dfa.index(next))) + if state.isfinal: + arcs.append((0, dfa.index(state))) + states.append(arcs) + c.states.append(states) + c.dfas[c.symbol2number[name]] = (states, self.make_first(c, name)) + c.start = c.symbol2number[self.startsymbol] + return c + + def make_first(self, c, name): + rawfirst = self.first[name] + first = {} + for label in rawfirst: + ilabel = self.make_label(c, label) + ##assert ilabel not in first # XXX failed on <> ... != + first[ilabel] = 1 + return first + + def make_label(self, c, label): + # XXX Maybe this should be a method on a subclass of converter? + ilabel = len(c.labels) + if label[0].isalpha(): + # Either a symbol name or a named token + if label in c.symbol2number: + # A symbol name (a non-terminal) + if label in c.symbol2label: + return c.symbol2label[label] + else: + c.labels.append((c.symbol2number[label], None)) + c.symbol2label[label] = ilabel + return ilabel + else: + # A named token (NAME, NUMBER, STRING) + itoken = getattr(token, label, None) + assert isinstance(itoken, int), label + assert itoken in token.tok_name, label + if itoken in c.tokens: + return c.tokens[itoken] + else: + c.labels.append((itoken, None)) + c.tokens[itoken] = ilabel + return ilabel + else: + # Either a keyword or an operator + assert label[0] in ('"', "'"), label + value = eval(label) + if value[0].isalpha(): + # A keyword + if value in c.keywords: + return c.keywords[value] + else: + c.labels.append((token.NAME, value)) + c.keywords[value] = ilabel + return ilabel + else: + # An operator (any non-numeric token) + itoken = grammar.opmap[value] # Fails if unknown token + if itoken in c.tokens: + return c.tokens[itoken] + else: + c.labels.append((itoken, None)) + c.tokens[itoken] = ilabel + return ilabel + + def addfirstsets(self): + names = self.dfas.keys() + names.sort() + for name in names: + if name not in self.first: + self.calcfirst(name) + #print name, self.first[name].keys() + + def calcfirst(self, name): + dfa = self.dfas[name] + self.first[name] = None # dummy to detect left recursion + state = dfa[0] + totalset = {} + overlapcheck = {} + for label, next in state.arcs.iteritems(): + if label in self.dfas: + if label in self.first: + fset = self.first[label] + if fset is None: + raise ValueError("recursion for rule %r" % name) + else: + self.calcfirst(label) + fset = self.first[label] + totalset.update(fset) + overlapcheck[label] = fset + else: + totalset[label] = 1 + overlapcheck[label] = {label: 1} + inverse = {} + for label, itsfirst in overlapcheck.iteritems(): + for symbol in itsfirst: + if symbol in inverse: + raise ValueError("rule %s is ambiguous; %s is in the" + " first sets of %s as well as %s" % + (name, symbol, label, inverse[symbol])) + inverse[symbol] = label + self.first[name] = totalset + + def parse(self): + dfas = {} + startsymbol = None + # MSTART: (NEWLINE | RULE)* ENDMARKER + while self.type != token.ENDMARKER: + while self.type == token.NEWLINE: + self.gettoken() + # RULE: NAME ':' RHS NEWLINE + name = self.expect(token.NAME) + self.expect(token.OP, ":") + a, z = self.parse_rhs() + self.expect(token.NEWLINE) + #self.dump_nfa(name, a, z) + dfa = self.make_dfa(a, z) + #self.dump_dfa(name, dfa) + oldlen = len(dfa) + self.simplify_dfa(dfa) + newlen = len(dfa) + dfas[name] = dfa + #print name, oldlen, newlen + if startsymbol is None: + startsymbol = name + return dfas, startsymbol + + def make_dfa(self, start, finish): + # To turn an NFA into a DFA, we define the states of the DFA + # to correspond to *sets* of states of the NFA. Then do some + # state reduction. Let's represent sets as dicts with 1 for + # values. + assert isinstance(start, NFAState) + assert isinstance(finish, NFAState) + def closure(state): + base = {} + addclosure(state, base) + return base + def addclosure(state, base): + assert isinstance(state, NFAState) + if state in base: + return + base[state] = 1 + for label, next in state.arcs: + if label is None: + addclosure(next, base) + states = [DFAState(closure(start), finish)] + for state in states: # NB states grows while we're iterating + arcs = {} + for nfastate in state.nfaset: + for label, next in nfastate.arcs: + if label is not None: + addclosure(next, arcs.setdefault(label, {})) + for label, nfaset in arcs.iteritems(): + for st in states: + if st.nfaset == nfaset: + break + else: + st = DFAState(nfaset, finish) + states.append(st) + state.addarc(st, label) + return states # List of DFAState instances; first one is start + + def dump_nfa(self, name, start, finish): + print "Dump of NFA for", name + todo = [start] + for i, state in enumerate(todo): + print " State", i, state is finish and "(final)" or "" + for label, next in state.arcs: + if next in todo: + j = todo.index(next) + else: + j = len(todo) + todo.append(next) + if label is None: + print " -> %d" % j + else: + print " %s -> %d" % (label, j) + + def dump_dfa(self, name, dfa): + print "Dump of DFA for", name + for i, state in enumerate(dfa): + print " State", i, state.isfinal and "(final)" or "" + for label, next in state.arcs.iteritems(): + print " %s -> %d" % (label, dfa.index(next)) + + def simplify_dfa(self, dfa): + # This is not theoretically optimal, but works well enough. + # Algorithm: repeatedly look for two states that have the same + # set of arcs (same labels pointing to the same nodes) and + # unify them, until things stop changing. + + # dfa is a list of DFAState instances + changes = True + while changes: + changes = False + for i, state_i in enumerate(dfa): + for j in range(i+1, len(dfa)): + state_j = dfa[j] + if state_i == state_j: + #print " unify", i, j + del dfa[j] + for state in dfa: + state.unifystate(state_j, state_i) + changes = True + break + + def parse_rhs(self): + # RHS: ALT ('|' ALT)* + a, z = self.parse_alt() + if self.value != "|": + return a, z + else: + aa = NFAState() + zz = NFAState() + aa.addarc(a) + z.addarc(zz) + while self.value == "|": + self.gettoken() + a, z = self.parse_alt() + aa.addarc(a) + z.addarc(zz) + return aa, zz + + def parse_alt(self): + # ALT: ITEM+ + a, b = self.parse_item() + while (self.value in ("(", "[") or + self.type in (token.NAME, token.STRING)): + c, d = self.parse_item() + b.addarc(c) + b = d + return a, b + + def parse_item(self): + # ITEM: '[' RHS ']' | ATOM ['+' | '*'] + if self.value == "[": + self.gettoken() + a, z = self.parse_rhs() + self.expect(token.OP, "]") + a.addarc(z) + return a, z + else: + a, z = self.parse_atom() + value = self.value + if value not in ("+", "*"): + return a, z + self.gettoken() + z.addarc(a) + if value == "+": + return a, z + else: + return a, a + + def parse_atom(self): + # ATOM: '(' RHS ')' | NAME | STRING + if self.value == "(": + self.gettoken() + a, z = self.parse_rhs() + self.expect(token.OP, ")") + return a, z + elif self.type in (token.NAME, token.STRING): + a = NFAState() + z = NFAState() + a.addarc(z, self.value) + self.gettoken() + return a, z + else: + self.raise_error("expected (...) or NAME or STRING, got %s/%s", + self.type, self.value) + + def expect(self, type, value=None): + if self.type != type or (value is not None and self.value != value): + self.raise_error("expected %s/%s, got %s/%s", + type, value, self.type, self.value) + value = self.value + self.gettoken() + return value + + def gettoken(self): + tup = self.generator.next() + while tup[0] in (tokenize.COMMENT, tokenize.NL): + tup = self.generator.next() + self.type, self.value, self.begin, self.end, self.line = tup + #print token.tok_name[self.type], repr(self.value) + + def raise_error(self, msg, *args): + if args: + try: + msg = msg % args + except: + msg = " ".join([msg] + map(str, args)) + raise SyntaxError(msg, (self.filename, self.end[0], + self.end[1], self.line)) + +class NFAState(object): + + def __init__(self): + self.arcs = [] # list of (label, NFAState) pairs + + def addarc(self, next, label=None): + assert label is None or isinstance(label, str) + assert isinstance(next, NFAState) + self.arcs.append((label, next)) + +class DFAState(object): + + def __init__(self, nfaset, final): + assert isinstance(nfaset, dict) + assert isinstance(iter(nfaset).next(), NFAState) + assert isinstance(final, NFAState) + self.nfaset = nfaset + self.isfinal = final in nfaset + self.arcs = {} # map from label to DFAState + + def addarc(self, next, label): + assert isinstance(label, str) + assert label not in self.arcs + assert isinstance(next, DFAState) + self.arcs[label] = next + + def unifystate(self, old, new): + for label, next in self.arcs.iteritems(): + if next is old: + self.arcs[label] = new + + def __eq__(self, other): + # Equality test -- ignore the nfaset instance variable + assert isinstance(other, DFAState) + if self.isfinal != other.isfinal: + return False + # Can't just return self.arcs == other.arcs, because that + # would invoke this method recursively, with cycles... + if len(self.arcs) != len(other.arcs): + return False + for label, next in self.arcs.iteritems(): + if next is not other.arcs.get(label): + return False + return True + + __hash__ = None # For Py3 compatibility. + +def generate_grammar(filename="Grammar.txt"): + p = ParserGenerator(filename) + return p.make_grammar() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/token.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/token.py new file mode 100644 index 0000000..61468b3 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/token.py @@ -0,0 +1,82 @@ +#! /usr/bin/env python + +"""Token constants (from "token.h").""" + +# Taken from Python (r53757) and modified to include some tokens +# originally monkeypatched in by pgen2.tokenize + +#--start constants-- +ENDMARKER = 0 +NAME = 1 +NUMBER = 2 +STRING = 3 +NEWLINE = 4 +INDENT = 5 +DEDENT = 6 +LPAR = 7 +RPAR = 8 +LSQB = 9 +RSQB = 10 +COLON = 11 +COMMA = 12 +SEMI = 13 +PLUS = 14 +MINUS = 15 +STAR = 16 +SLASH = 17 +VBAR = 18 +AMPER = 19 +LESS = 20 +GREATER = 21 +EQUAL = 22 +DOT = 23 +PERCENT = 24 +BACKQUOTE = 25 +LBRACE = 26 +RBRACE = 27 +EQEQUAL = 28 +NOTEQUAL = 29 +LESSEQUAL = 30 +GREATEREQUAL = 31 +TILDE = 32 +CIRCUMFLEX = 33 +LEFTSHIFT = 34 +RIGHTSHIFT = 35 +DOUBLESTAR = 36 +PLUSEQUAL = 37 +MINEQUAL = 38 +STAREQUAL = 39 +SLASHEQUAL = 40 +PERCENTEQUAL = 41 +AMPEREQUAL = 42 +VBAREQUAL = 43 +CIRCUMFLEXEQUAL = 44 +LEFTSHIFTEQUAL = 45 +RIGHTSHIFTEQUAL = 46 +DOUBLESTAREQUAL = 47 +DOUBLESLASH = 48 +DOUBLESLASHEQUAL = 49 +AT = 50 +OP = 51 +COMMENT = 52 +NL = 53 +RARROW = 54 +ERRORTOKEN = 55 +N_TOKENS = 56 +NT_OFFSET = 256 +#--end constants-- + +tok_name = {} +for _name, _value in globals().items(): + if type(_value) is type(0): + tok_name[_value] = _name + + +def ISTERMINAL(x): + return x < NT_OFFSET + +def ISNONTERMINAL(x): + return x >= NT_OFFSET + +def ISEOF(x): + return x == ENDMARKER diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/tokenize.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/tokenize.py new file mode 100644 index 0000000..f6e0284 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pgen2/tokenize.py @@ -0,0 +1,499 @@ +# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python Software Foundation. +# All rights reserved. + +"""Tokenization help for Python programs. + +generate_tokens(readline) is a generator that breaks a stream of +text into Python tokens. It accepts a readline-like method which is called +repeatedly to get the next line of input (or "" for EOF). It generates +5-tuples with these members: + + the token type (see token.py) + the token (a string) + the starting (row, column) indices of the token (a 2-tuple of ints) + the ending (row, column) indices of the token (a 2-tuple of ints) + the original line (string) + +It is designed to match the working of the Python tokenizer exactly, except +that it produces COMMENT tokens for comments and gives type OP for all +operators + +Older entry points + tokenize_loop(readline, tokeneater) + tokenize(readline, tokeneater=printtoken) +are the same, except instead of generating tokens, tokeneater is a callback +function to which the 5 fields described above are passed as 5 arguments, +each time a new token is found.""" + +__author__ = 'Ka-Ping Yee ' +__credits__ = \ + 'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro' + +import string, re +from codecs import BOM_UTF8, lookup +from lib2to3.pgen2.token import * + +from . import token +__all__ = [x for x in dir(token) if x[0] != '_'] + ["tokenize", + "generate_tokens", "untokenize"] +del token + +try: + bytes +except NameError: + # Support bytes type in Python <= 2.5, so 2to3 turns itself into + # valid Python 3 code. + bytes = str + +def group(*choices): return '(' + '|'.join(choices) + ')' +def any(*choices): return group(*choices) + '*' +def maybe(*choices): return group(*choices) + '?' + +Whitespace = r'[ \f\t]*' +Comment = r'#[^\r\n]*' +Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment) +Name = r'[a-zA-Z_]\w*' + +Binnumber = r'0[bB][01]*' +Hexnumber = r'0[xX][\da-fA-F]*[lL]?' +Octnumber = r'0[oO]?[0-7]*[lL]?' +Decnumber = r'[1-9]\d*[lL]?' +Intnumber = group(Binnumber, Hexnumber, Octnumber, Decnumber) +Exponent = r'[eE][-+]?\d+' +Pointfloat = group(r'\d+\.\d*', r'\.\d+') + maybe(Exponent) +Expfloat = r'\d+' + Exponent +Floatnumber = group(Pointfloat, Expfloat) +Imagnumber = group(r'\d+[jJ]', Floatnumber + r'[jJ]') +Number = group(Imagnumber, Floatnumber, Intnumber) + +# Tail end of ' string. +Single = r"[^'\\]*(?:\\.[^'\\]*)*'" +# Tail end of " string. +Double = r'[^"\\]*(?:\\.[^"\\]*)*"' +# Tail end of ''' string. +Single3 = r"[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''" +# Tail end of """ string. +Double3 = r'[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""' +Triple = group("[ubUB]?[rR]?'''", '[ubUB]?[rR]?"""') +# Single-line ' or " string. +String = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'", + r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"') + +# Because of leftmost-then-longest match semantics, be sure to put the +# longest operators first (e.g., if = came before ==, == would get +# recognized as two instances of =). +Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"<>", r"!=", + r"//=?", r"->", + r"[+\-*/%&|^=<>]=?", + r"~") + +Bracket = '[][(){}]' +Special = group(r'\r?\n', r'[:;.,`@]') +Funny = group(Operator, Bracket, Special) + +PlainToken = group(Number, Funny, String, Name) +Token = Ignore + PlainToken + +# First (or only) line of ' or " string. +ContStr = group(r"[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" + + group("'", r'\\\r?\n'), + r'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' + + group('"', r'\\\r?\n')) +PseudoExtras = group(r'\\\r?\n', Comment, Triple) +PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name) + +tokenprog, pseudoprog, single3prog, double3prog = map( + re.compile, (Token, PseudoToken, Single3, Double3)) +endprogs = {"'": re.compile(Single), '"': re.compile(Double), + "'''": single3prog, '"""': double3prog, + "r'''": single3prog, 'r"""': double3prog, + "u'''": single3prog, 'u"""': double3prog, + "b'''": single3prog, 'b"""': double3prog, + "ur'''": single3prog, 'ur"""': double3prog, + "br'''": single3prog, 'br"""': double3prog, + "R'''": single3prog, 'R"""': double3prog, + "U'''": single3prog, 'U"""': double3prog, + "B'''": single3prog, 'B"""': double3prog, + "uR'''": single3prog, 'uR"""': double3prog, + "Ur'''": single3prog, 'Ur"""': double3prog, + "UR'''": single3prog, 'UR"""': double3prog, + "bR'''": single3prog, 'bR"""': double3prog, + "Br'''": single3prog, 'Br"""': double3prog, + "BR'''": single3prog, 'BR"""': double3prog, + 'r': None, 'R': None, + 'u': None, 'U': None, + 'b': None, 'B': None} + +triple_quoted = {} +for t in ("'''", '"""', + "r'''", 'r"""', "R'''", 'R"""', + "u'''", 'u"""', "U'''", 'U"""', + "b'''", 'b"""', "B'''", 'B"""', + "ur'''", 'ur"""', "Ur'''", 'Ur"""', + "uR'''", 'uR"""', "UR'''", 'UR"""', + "br'''", 'br"""', "Br'''", 'Br"""', + "bR'''", 'bR"""', "BR'''", 'BR"""',): + triple_quoted[t] = t +single_quoted = {} +for t in ("'", '"', + "r'", 'r"', "R'", 'R"', + "u'", 'u"', "U'", 'U"', + "b'", 'b"', "B'", 'B"', + "ur'", 'ur"', "Ur'", 'Ur"', + "uR'", 'uR"', "UR'", 'UR"', + "br'", 'br"', "Br'", 'Br"', + "bR'", 'bR"', "BR'", 'BR"', ): + single_quoted[t] = t + +tabsize = 8 + +class TokenError(Exception): pass + +class StopTokenizing(Exception): pass + +def printtoken(type, token, start, end, line): # for testing + (srow, scol) = start + (erow, ecol) = end + print "%d,%d-%d,%d:\t%s\t%s" % \ + (srow, scol, erow, ecol, tok_name[type], repr(token)) + +def tokenize(readline, tokeneater=printtoken): + """ + The tokenize() function accepts two parameters: one representing the + input stream, and one providing an output mechanism for tokenize(). + + The first parameter, readline, must be a callable object which provides + the same interface as the readline() method of built-in file objects. + Each call to the function should return one line of input as a string. + + The second parameter, tokeneater, must also be a callable object. It is + called once for each token, with five arguments, corresponding to the + tuples generated by generate_tokens(). + """ + try: + tokenize_loop(readline, tokeneater) + except StopTokenizing: + pass + +# backwards compatible interface +def tokenize_loop(readline, tokeneater): + for token_info in generate_tokens(readline): + tokeneater(*token_info) + +class Untokenizer: + + def __init__(self): + self.tokens = [] + self.prev_row = 1 + self.prev_col = 0 + + def add_whitespace(self, start): + row, col = start + assert row <= self.prev_row + col_offset = col - self.prev_col + if col_offset: + self.tokens.append(" " * col_offset) + + def untokenize(self, iterable): + for t in iterable: + if len(t) == 2: + self.compat(t, iterable) + break + tok_type, token, start, end, line = t + self.add_whitespace(start) + self.tokens.append(token) + self.prev_row, self.prev_col = end + if tok_type in (NEWLINE, NL): + self.prev_row += 1 + self.prev_col = 0 + return "".join(self.tokens) + + def compat(self, token, iterable): + startline = False + indents = [] + toks_append = self.tokens.append + toknum, tokval = token + if toknum in (NAME, NUMBER): + tokval += ' ' + if toknum in (NEWLINE, NL): + startline = True + for tok in iterable: + toknum, tokval = tok[:2] + + if toknum in (NAME, NUMBER): + tokval += ' ' + + if toknum == INDENT: + indents.append(tokval) + continue + elif toknum == DEDENT: + indents.pop() + continue + elif toknum in (NEWLINE, NL): + startline = True + elif startline and indents: + toks_append(indents[-1]) + startline = False + toks_append(tokval) + +cookie_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)') + +def _get_normal_name(orig_enc): + """Imitates get_normal_name in tokenizer.c.""" + # Only care about the first 12 characters. + enc = orig_enc[:12].lower().replace("_", "-") + if enc == "utf-8" or enc.startswith("utf-8-"): + return "utf-8" + if enc in ("latin-1", "iso-8859-1", "iso-latin-1") or \ + enc.startswith(("latin-1-", "iso-8859-1-", "iso-latin-1-")): + return "iso-8859-1" + return orig_enc + +def detect_encoding(readline): + """ + The detect_encoding() function is used to detect the encoding that should + be used to decode a Python source file. It requires one argment, readline, + in the same way as the tokenize() generator. + + It will call readline a maximum of twice, and return the encoding used + (as a string) and a list of any lines (left as bytes) it has read + in. + + It detects the encoding from the presence of a utf-8 bom or an encoding + cookie as specified in pep-0263. If both a bom and a cookie are present, but + disagree, a SyntaxError will be raised. If the encoding cookie is an invalid + charset, raise a SyntaxError. Note that if a utf-8 bom is found, + 'utf-8-sig' is returned. + + If no encoding is specified, then the default of 'utf-8' will be returned. + """ + bom_found = False + encoding = None + default = 'utf-8' + def read_or_stop(): + try: + return readline() + except StopIteration: + return bytes() + + def find_cookie(line): + try: + line_string = line.decode('ascii') + except UnicodeDecodeError: + return None + match = cookie_re.match(line_string) + if not match: + return None + encoding = _get_normal_name(match.group(1)) + try: + codec = lookup(encoding) + except LookupError: + # This behaviour mimics the Python interpreter + raise SyntaxError("unknown encoding: " + encoding) + + if bom_found: + if codec.name != 'utf-8': + # This behaviour mimics the Python interpreter + raise SyntaxError('encoding problem: utf-8') + encoding += '-sig' + return encoding + + first = read_or_stop() + if first.startswith(BOM_UTF8): + bom_found = True + first = first[3:] + default = 'utf-8-sig' + if not first: + return default, [] + + encoding = find_cookie(first) + if encoding: + return encoding, [first] + + second = read_or_stop() + if not second: + return default, [first] + + encoding = find_cookie(second) + if encoding: + return encoding, [first, second] + + return default, [first, second] + +def untokenize(iterable): + """Transform tokens back into Python source code. + + Each element returned by the iterable must be a token sequence + with at least two elements, a token number and token value. If + only two tokens are passed, the resulting output is poor. + + Round-trip invariant for full input: + Untokenized source will match input source exactly + + Round-trip invariant for limited intput: + # Output text will tokenize the back to the input + t1 = [tok[:2] for tok in generate_tokens(f.readline)] + newcode = untokenize(t1) + readline = iter(newcode.splitlines(1)).next + t2 = [tok[:2] for tokin generate_tokens(readline)] + assert t1 == t2 + """ + ut = Untokenizer() + return ut.untokenize(iterable) + +def generate_tokens(readline): + """ + The generate_tokens() generator requires one argment, readline, which + must be a callable object which provides the same interface as the + readline() method of built-in file objects. Each call to the function + should return one line of input as a string. Alternately, readline + can be a callable function terminating with StopIteration: + readline = open(myfile).next # Example of alternate readline + + The generator produces 5-tuples with these members: the token type; the + token string; a 2-tuple (srow, scol) of ints specifying the row and + column where the token begins in the source; a 2-tuple (erow, ecol) of + ints specifying the row and column where the token ends in the source; + and the line on which the token was found. The line passed is the + logical line; continuation lines are included. + """ + lnum = parenlev = continued = 0 + namechars, numchars = string.ascii_letters + '_', '0123456789' + contstr, needcont = '', 0 + contline = None + indents = [0] + + while 1: # loop over lines in stream + try: + line = readline() + except StopIteration: + line = '' + lnum = lnum + 1 + pos, max = 0, len(line) + + if contstr: # continued string + if not line: + raise TokenError, ("EOF in multi-line string", strstart) + endmatch = endprog.match(line) + if endmatch: + pos = end = endmatch.end(0) + yield (STRING, contstr + line[:end], + strstart, (lnum, end), contline + line) + contstr, needcont = '', 0 + contline = None + elif needcont and line[-2:] != '\\\n' and line[-3:] != '\\\r\n': + yield (ERRORTOKEN, contstr + line, + strstart, (lnum, len(line)), contline) + contstr = '' + contline = None + continue + else: + contstr = contstr + line + contline = contline + line + continue + + elif parenlev == 0 and not continued: # new statement + if not line: break + column = 0 + while pos < max: # measure leading whitespace + if line[pos] == ' ': column = column + 1 + elif line[pos] == '\t': column = (column//tabsize + 1)*tabsize + elif line[pos] == '\f': column = 0 + else: break + pos = pos + 1 + if pos == max: break + + if line[pos] in '#\r\n': # skip comments or blank lines + if line[pos] == '#': + comment_token = line[pos:].rstrip('\r\n') + nl_pos = pos + len(comment_token) + yield (COMMENT, comment_token, + (lnum, pos), (lnum, pos + len(comment_token)), line) + yield (NL, line[nl_pos:], + (lnum, nl_pos), (lnum, len(line)), line) + else: + yield ((NL, COMMENT)[line[pos] == '#'], line[pos:], + (lnum, pos), (lnum, len(line)), line) + continue + + if column > indents[-1]: # count indents or dedents + indents.append(column) + yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line) + while column < indents[-1]: + if column not in indents: + raise IndentationError( + "unindent does not match any outer indentation level", + ("", lnum, pos, line)) + indents = indents[:-1] + yield (DEDENT, '', (lnum, pos), (lnum, pos), line) + + else: # continued statement + if not line: + raise TokenError, ("EOF in multi-line statement", (lnum, 0)) + continued = 0 + + while pos < max: + pseudomatch = pseudoprog.match(line, pos) + if pseudomatch: # scan for tokens + start, end = pseudomatch.span(1) + spos, epos, pos = (lnum, start), (lnum, end), end + token, initial = line[start:end], line[start] + + if initial in numchars or \ + (initial == '.' and token != '.'): # ordinary number + yield (NUMBER, token, spos, epos, line) + elif initial in '\r\n': + newline = NEWLINE + if parenlev > 0: + newline = NL + yield (newline, token, spos, epos, line) + elif initial == '#': + assert not token.endswith("\n") + yield (COMMENT, token, spos, epos, line) + elif token in triple_quoted: + endprog = endprogs[token] + endmatch = endprog.match(line, pos) + if endmatch: # all on one line + pos = endmatch.end(0) + token = line[start:pos] + yield (STRING, token, spos, (lnum, pos), line) + else: + strstart = (lnum, start) # multiple lines + contstr = line[start:] + contline = line + break + elif initial in single_quoted or \ + token[:2] in single_quoted or \ + token[:3] in single_quoted: + if token[-1] == '\n': # continued string + strstart = (lnum, start) + endprog = (endprogs[initial] or endprogs[token[1]] or + endprogs[token[2]]) + contstr, needcont = line[start:], 1 + contline = line + break + else: # ordinary string + yield (STRING, token, spos, epos, line) + elif initial in namechars: # ordinary name + yield (NAME, token, spos, epos, line) + elif initial == '\\': # continued stmt + # This yield is new; needed for better idempotency: + yield (NL, token, spos, (lnum, pos), line) + continued = 1 + else: + if initial in '([{': parenlev = parenlev + 1 + elif initial in ')]}': parenlev = parenlev - 1 + yield (OP, token, spos, epos, line) + else: + yield (ERRORTOKEN, line[pos], + (lnum, pos), (lnum, pos+1), line) + pos = pos + 1 + + for indent in indents[1:]: # pop remaining indent levels + yield (DEDENT, '', (lnum, 0), (lnum, 0), '') + yield (ENDMARKER, '', (lnum, 0), (lnum, 0), '') + +if __name__ == '__main__': # testing + import sys + if len(sys.argv) > 1: tokenize(open(sys.argv[1]).readline) + else: tokenize(sys.stdin.readline) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pygram.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pygram.py new file mode 100644 index 0000000..621ff24 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pygram.py @@ -0,0 +1,40 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Export the Python grammar and symbols.""" + +# Python imports +import os + +# Local imports +from .pgen2 import token +from .pgen2 import driver +from . import pytree + +# The grammar file +_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt") +_PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), + "PatternGrammar.txt") + + +class Symbols(object): + + def __init__(self, grammar): + """Initializer. + + Creates an attribute for each grammar symbol (nonterminal), + whose value is the symbol's type (an int >= 256). + """ + for name, symbol in grammar.symbol2number.iteritems(): + setattr(self, name, symbol) + + +python_grammar = driver.load_grammar(_GRAMMAR_FILE) + +python_symbols = Symbols(python_grammar) + +python_grammar_no_print_statement = python_grammar.copy() +del python_grammar_no_print_statement.keywords["print"] + +pattern_grammar = driver.load_grammar(_PATTERN_GRAMMAR_FILE) +pattern_symbols = Symbols(pattern_grammar) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pytree.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pytree.py new file mode 100644 index 0000000..179caca --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/pytree.py @@ -0,0 +1,887 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +""" +Python parse tree definitions. + +This is a very concrete parse tree; we need to keep every token and +even the comments and whitespace between tokens. + +There's also a pattern matching implementation here. +""" + +__author__ = "Guido van Rossum " + +import sys +import warnings +from StringIO import StringIO + +HUGE = 0x7FFFFFFF # maximum repeat count, default max + +_type_reprs = {} +def type_repr(type_num): + global _type_reprs + if not _type_reprs: + from .pygram import python_symbols + # printing tokens is possible but not as useful + # from .pgen2 import token // token.__dict__.items(): + for name, val in python_symbols.__dict__.items(): + if type(val) == int: _type_reprs[val] = name + return _type_reprs.setdefault(type_num, type_num) + +class Base(object): + + """ + Abstract base class for Node and Leaf. + + This provides some default functionality and boilerplate using the + template pattern. + + A node may be a subnode of at most one parent. + """ + + # Default values for instance variables + type = None # int: token number (< 256) or symbol number (>= 256) + parent = None # Parent node pointer, or None + children = () # Tuple of subnodes + was_changed = False + was_checked = False + + def __new__(cls, *args, **kwds): + """Constructor that prevents Base from being instantiated.""" + assert cls is not Base, "Cannot instantiate Base" + return object.__new__(cls) + + def __eq__(self, other): + """ + Compare two nodes for equality. + + This calls the method _eq(). + """ + if self.__class__ is not other.__class__: + return NotImplemented + return self._eq(other) + + __hash__ = None # For Py3 compatibility. + + def __ne__(self, other): + """ + Compare two nodes for inequality. + + This calls the method _eq(). + """ + if self.__class__ is not other.__class__: + return NotImplemented + return not self._eq(other) + + def _eq(self, other): + """ + Compare two nodes for equality. + + This is called by __eq__ and __ne__. It is only called if the two nodes + have the same type. This must be implemented by the concrete subclass. + Nodes should be considered equal if they have the same structure, + ignoring the prefix string and other context information. + """ + raise NotImplementedError + + def clone(self): + """ + Return a cloned (deep) copy of self. + + This must be implemented by the concrete subclass. + """ + raise NotImplementedError + + def post_order(self): + """ + Return a post-order iterator for the tree. + + This must be implemented by the concrete subclass. + """ + raise NotImplementedError + + def pre_order(self): + """ + Return a pre-order iterator for the tree. + + This must be implemented by the concrete subclass. + """ + raise NotImplementedError + + def set_prefix(self, prefix): + """ + Set the prefix for the node (see Leaf class). + + DEPRECATED; use the prefix property directly. + """ + warnings.warn("set_prefix() is deprecated; use the prefix property", + DeprecationWarning, stacklevel=2) + self.prefix = prefix + + def get_prefix(self): + """ + Return the prefix for the node (see Leaf class). + + DEPRECATED; use the prefix property directly. + """ + warnings.warn("get_prefix() is deprecated; use the prefix property", + DeprecationWarning, stacklevel=2) + return self.prefix + + def replace(self, new): + """Replace this node with a new one in the parent.""" + assert self.parent is not None, str(self) + assert new is not None + if not isinstance(new, list): + new = [new] + l_children = [] + found = False + for ch in self.parent.children: + if ch is self: + assert not found, (self.parent.children, self, new) + if new is not None: + l_children.extend(new) + found = True + else: + l_children.append(ch) + assert found, (self.children, self, new) + self.parent.changed() + self.parent.children = l_children + for x in new: + x.parent = self.parent + self.parent = None + + def get_lineno(self): + """Return the line number which generated the invocant node.""" + node = self + while not isinstance(node, Leaf): + if not node.children: + return + node = node.children[0] + return node.lineno + + def changed(self): + if self.parent: + self.parent.changed() + self.was_changed = True + + def remove(self): + """ + Remove the node from the tree. Returns the position of the node in its + parent's children before it was removed. + """ + if self.parent: + for i, node in enumerate(self.parent.children): + if node is self: + self.parent.changed() + del self.parent.children[i] + self.parent = None + return i + + @property + def next_sibling(self): + """ + The node immediately following the invocant in their parent's children + list. If the invocant does not have a next sibling, it is None + """ + if self.parent is None: + return None + + # Can't use index(); we need to test by identity + for i, child in enumerate(self.parent.children): + if child is self: + try: + return self.parent.children[i+1] + except IndexError: + return None + + @property + def prev_sibling(self): + """ + The node immediately preceding the invocant in their parent's children + list. If the invocant does not have a previous sibling, it is None. + """ + if self.parent is None: + return None + + # Can't use index(); we need to test by identity + for i, child in enumerate(self.parent.children): + if child is self: + if i == 0: + return None + return self.parent.children[i-1] + + def leaves(self): + for child in self.children: + for x in child.leaves(): + yield x + + def depth(self): + if self.parent is None: + return 0 + return 1 + self.parent.depth() + + def get_suffix(self): + """ + Return the string immediately following the invocant node. This is + effectively equivalent to node.next_sibling.prefix + """ + next_sib = self.next_sibling + if next_sib is None: + return u"" + return next_sib.prefix + + if sys.version_info < (3, 0): + def __str__(self): + return unicode(self).encode("ascii") + +class Node(Base): + + """Concrete implementation for interior nodes.""" + + def __init__(self,type, children, + context=None, + prefix=None, + fixers_applied=None): + """ + Initializer. + + Takes a type constant (a symbol number >= 256), a sequence of + child nodes, and an optional context keyword argument. + + As a side effect, the parent pointers of the children are updated. + """ + assert type >= 256, type + self.type = type + self.children = list(children) + for ch in self.children: + assert ch.parent is None, repr(ch) + ch.parent = self + if prefix is not None: + self.prefix = prefix + if fixers_applied: + self.fixers_applied = fixers_applied[:] + else: + self.fixers_applied = None + + def __repr__(self): + """Return a canonical string representation.""" + return "%s(%s, %r)" % (self.__class__.__name__, + type_repr(self.type), + self.children) + + def __unicode__(self): + """ + Return a pretty string representation. + + This reproduces the input source exactly. + """ + return u"".join(map(unicode, self.children)) + + if sys.version_info > (3, 0): + __str__ = __unicode__ + + def _eq(self, other): + """Compare two nodes for equality.""" + return (self.type, self.children) == (other.type, other.children) + + def clone(self): + """Return a cloned (deep) copy of self.""" + return Node(self.type, [ch.clone() for ch in self.children], + fixers_applied=self.fixers_applied) + + def post_order(self): + """Return a post-order iterator for the tree.""" + for child in self.children: + for node in child.post_order(): + yield node + yield self + + def pre_order(self): + """Return a pre-order iterator for the tree.""" + yield self + for child in self.children: + for node in child.pre_order(): + yield node + + def _prefix_getter(self): + """ + The whitespace and comments preceding this node in the input. + """ + if not self.children: + return "" + return self.children[0].prefix + + def _prefix_setter(self, prefix): + if self.children: + self.children[0].prefix = prefix + + prefix = property(_prefix_getter, _prefix_setter) + + def set_child(self, i, child): + """ + Equivalent to 'node.children[i] = child'. This method also sets the + child's parent attribute appropriately. + """ + child.parent = self + self.children[i].parent = None + self.children[i] = child + self.changed() + + def insert_child(self, i, child): + """ + Equivalent to 'node.children.insert(i, child)'. This method also sets + the child's parent attribute appropriately. + """ + child.parent = self + self.children.insert(i, child) + self.changed() + + def append_child(self, child): + """ + Equivalent to 'node.children.append(child)'. This method also sets the + child's parent attribute appropriately. + """ + child.parent = self + self.children.append(child) + self.changed() + + +class Leaf(Base): + + """Concrete implementation for leaf nodes.""" + + # Default values for instance variables + _prefix = "" # Whitespace and comments preceding this token in the input + lineno = 0 # Line where this token starts in the input + column = 0 # Column where this token tarts in the input + + def __init__(self, type, value, + context=None, + prefix=None, + fixers_applied=[]): + """ + Initializer. + + Takes a type constant (a token number < 256), a string value, and an + optional context keyword argument. + """ + assert 0 <= type < 256, type + if context is not None: + self._prefix, (self.lineno, self.column) = context + self.type = type + self.value = value + if prefix is not None: + self._prefix = prefix + self.fixers_applied = fixers_applied[:] + + def __repr__(self): + """Return a canonical string representation.""" + return "%s(%r, %r)" % (self.__class__.__name__, + self.type, + self.value) + + def __unicode__(self): + """ + Return a pretty string representation. + + This reproduces the input source exactly. + """ + return self.prefix + unicode(self.value) + + if sys.version_info > (3, 0): + __str__ = __unicode__ + + def _eq(self, other): + """Compare two nodes for equality.""" + return (self.type, self.value) == (other.type, other.value) + + def clone(self): + """Return a cloned (deep) copy of self.""" + return Leaf(self.type, self.value, + (self.prefix, (self.lineno, self.column)), + fixers_applied=self.fixers_applied) + + def leaves(self): + yield self + + def post_order(self): + """Return a post-order iterator for the tree.""" + yield self + + def pre_order(self): + """Return a pre-order iterator for the tree.""" + yield self + + def _prefix_getter(self): + """ + The whitespace and comments preceding this token in the input. + """ + return self._prefix + + def _prefix_setter(self, prefix): + self.changed() + self._prefix = prefix + + prefix = property(_prefix_getter, _prefix_setter) + +def convert(gr, raw_node): + """ + Convert raw node information to a Node or Leaf instance. + + This is passed to the parser driver which calls it whenever a reduction of a + grammar rule produces a new complete node, so that the tree is build + strictly bottom-up. + """ + type, value, context, children = raw_node + if children or type in gr.number2symbol: + # If there's exactly one child, return that child instead of + # creating a new node. + if len(children) == 1: + return children[0] + return Node(type, children, context=context) + else: + return Leaf(type, value, context=context) + + +class BasePattern(object): + + """ + A pattern is a tree matching pattern. + + It looks for a specific node type (token or symbol), and + optionally for a specific content. + + This is an abstract base class. There are three concrete + subclasses: + + - LeafPattern matches a single leaf node; + - NodePattern matches a single node (usually non-leaf); + - WildcardPattern matches a sequence of nodes of variable length. + """ + + # Defaults for instance variables + type = None # Node type (token if < 256, symbol if >= 256) + content = None # Optional content matching pattern + name = None # Optional name used to store match in results dict + + def __new__(cls, *args, **kwds): + """Constructor that prevents BasePattern from being instantiated.""" + assert cls is not BasePattern, "Cannot instantiate BasePattern" + return object.__new__(cls) + + def __repr__(self): + args = [type_repr(self.type), self.content, self.name] + while args and args[-1] is None: + del args[-1] + return "%s(%s)" % (self.__class__.__name__, ", ".join(map(repr, args))) + + def optimize(self): + """ + A subclass can define this as a hook for optimizations. + + Returns either self or another node with the same effect. + """ + return self + + def match(self, node, results=None): + """ + Does this pattern exactly match a node? + + Returns True if it matches, False if not. + + If results is not None, it must be a dict which will be + updated with the nodes matching named subpatterns. + + Default implementation for non-wildcard patterns. + """ + if self.type is not None and node.type != self.type: + return False + if self.content is not None: + r = None + if results is not None: + r = {} + if not self._submatch(node, r): + return False + if r: + results.update(r) + if results is not None and self.name: + results[self.name] = node + return True + + def match_seq(self, nodes, results=None): + """ + Does this pattern exactly match a sequence of nodes? + + Default implementation for non-wildcard patterns. + """ + if len(nodes) != 1: + return False + return self.match(nodes[0], results) + + def generate_matches(self, nodes): + """ + Generator yielding all matches for this pattern. + + Default implementation for non-wildcard patterns. + """ + r = {} + if nodes and self.match(nodes[0], r): + yield 1, r + + +class LeafPattern(BasePattern): + + def __init__(self, type=None, content=None, name=None): + """ + Initializer. Takes optional type, content, and name. + + The type, if given must be a token type (< 256). If not given, + this matches any *leaf* node; the content may still be required. + + The content, if given, must be a string. + + If a name is given, the matching node is stored in the results + dict under that key. + """ + if type is not None: + assert 0 <= type < 256, type + if content is not None: + assert isinstance(content, basestring), repr(content) + self.type = type + self.content = content + self.name = name + + def match(self, node, results=None): + """Override match() to insist on a leaf node.""" + if not isinstance(node, Leaf): + return False + return BasePattern.match(self, node, results) + + def _submatch(self, node, results=None): + """ + Match the pattern's content to the node's children. + + This assumes the node type matches and self.content is not None. + + Returns True if it matches, False if not. + + If results is not None, it must be a dict which will be + updated with the nodes matching named subpatterns. + + When returning False, the results dict may still be updated. + """ + return self.content == node.value + + +class NodePattern(BasePattern): + + wildcards = False + + def __init__(self, type=None, content=None, name=None): + """ + Initializer. Takes optional type, content, and name. + + The type, if given, must be a symbol type (>= 256). If the + type is None this matches *any* single node (leaf or not), + except if content is not None, in which it only matches + non-leaf nodes that also match the content pattern. + + The content, if not None, must be a sequence of Patterns that + must match the node's children exactly. If the content is + given, the type must not be None. + + If a name is given, the matching node is stored in the results + dict under that key. + """ + if type is not None: + assert type >= 256, type + if content is not None: + assert not isinstance(content, basestring), repr(content) + content = list(content) + for i, item in enumerate(content): + assert isinstance(item, BasePattern), (i, item) + if isinstance(item, WildcardPattern): + self.wildcards = True + self.type = type + self.content = content + self.name = name + + def _submatch(self, node, results=None): + """ + Match the pattern's content to the node's children. + + This assumes the node type matches and self.content is not None. + + Returns True if it matches, False if not. + + If results is not None, it must be a dict which will be + updated with the nodes matching named subpatterns. + + When returning False, the results dict may still be updated. + """ + if self.wildcards: + for c, r in generate_matches(self.content, node.children): + if c == len(node.children): + if results is not None: + results.update(r) + return True + return False + if len(self.content) != len(node.children): + return False + for subpattern, child in zip(self.content, node.children): + if not subpattern.match(child, results): + return False + return True + + +class WildcardPattern(BasePattern): + + """ + A wildcard pattern can match zero or more nodes. + + This has all the flexibility needed to implement patterns like: + + .* .+ .? .{m,n} + (a b c | d e | f) + (...)* (...)+ (...)? (...){m,n} + + except it always uses non-greedy matching. + """ + + def __init__(self, content=None, min=0, max=HUGE, name=None): + """ + Initializer. + + Args: + content: optional sequence of subsequences of patterns; + if absent, matches one node; + if present, each subsequence is an alternative [*] + min: optional minimum number of times to match, default 0 + max: optional maximum number of times to match, default HUGE + name: optional name assigned to this match + + [*] Thus, if content is [[a, b, c], [d, e], [f, g, h]] this is + equivalent to (a b c | d e | f g h); if content is None, + this is equivalent to '.' in regular expression terms. + The min and max parameters work as follows: + min=0, max=maxint: .* + min=1, max=maxint: .+ + min=0, max=1: .? + min=1, max=1: . + If content is not None, replace the dot with the parenthesized + list of alternatives, e.g. (a b c | d e | f g h)* + """ + assert 0 <= min <= max <= HUGE, (min, max) + if content is not None: + content = tuple(map(tuple, content)) # Protect against alterations + # Check sanity of alternatives + assert len(content), repr(content) # Can't have zero alternatives + for alt in content: + assert len(alt), repr(alt) # Can have empty alternatives + self.content = content + self.min = min + self.max = max + self.name = name + + def optimize(self): + """Optimize certain stacked wildcard patterns.""" + subpattern = None + if (self.content is not None and + len(self.content) == 1 and len(self.content[0]) == 1): + subpattern = self.content[0][0] + if self.min == 1 and self.max == 1: + if self.content is None: + return NodePattern(name=self.name) + if subpattern is not None and self.name == subpattern.name: + return subpattern.optimize() + if (self.min <= 1 and isinstance(subpattern, WildcardPattern) and + subpattern.min <= 1 and self.name == subpattern.name): + return WildcardPattern(subpattern.content, + self.min*subpattern.min, + self.max*subpattern.max, + subpattern.name) + return self + + def match(self, node, results=None): + """Does this pattern exactly match a node?""" + return self.match_seq([node], results) + + def match_seq(self, nodes, results=None): + """Does this pattern exactly match a sequence of nodes?""" + for c, r in self.generate_matches(nodes): + if c == len(nodes): + if results is not None: + results.update(r) + if self.name: + results[self.name] = list(nodes) + return True + return False + + def generate_matches(self, nodes): + """ + Generator yielding matches for a sequence of nodes. + + Args: + nodes: sequence of nodes + + Yields: + (count, results) tuples where: + count: the match comprises nodes[:count]; + results: dict containing named submatches. + """ + if self.content is None: + # Shortcut for special case (see __init__.__doc__) + for count in xrange(self.min, 1 + min(len(nodes), self.max)): + r = {} + if self.name: + r[self.name] = nodes[:count] + yield count, r + elif self.name == "bare_name": + yield self._bare_name_matches(nodes) + else: + # The reason for this is that hitting the recursion limit usually + # results in some ugly messages about how RuntimeErrors are being + # ignored. We don't do this on non-CPython implementation because + # they don't have this problem. + if hasattr(sys, "getrefcount"): + save_stderr = sys.stderr + sys.stderr = StringIO() + try: + for count, r in self._recursive_matches(nodes, 0): + if self.name: + r[self.name] = nodes[:count] + yield count, r + except RuntimeError: + # We fall back to the iterative pattern matching scheme if the recursive + # scheme hits the recursion limit. + for count, r in self._iterative_matches(nodes): + if self.name: + r[self.name] = nodes[:count] + yield count, r + finally: + if hasattr(sys, "getrefcount"): + sys.stderr = save_stderr + + def _iterative_matches(self, nodes): + """Helper to iteratively yield the matches.""" + nodelen = len(nodes) + if 0 >= self.min: + yield 0, {} + + results = [] + # generate matches that use just one alt from self.content + for alt in self.content: + for c, r in generate_matches(alt, nodes): + yield c, r + results.append((c, r)) + + # for each match, iterate down the nodes + while results: + new_results = [] + for c0, r0 in results: + # stop if the entire set of nodes has been matched + if c0 < nodelen and c0 <= self.max: + for alt in self.content: + for c1, r1 in generate_matches(alt, nodes[c0:]): + if c1 > 0: + r = {} + r.update(r0) + r.update(r1) + yield c0 + c1, r + new_results.append((c0 + c1, r)) + results = new_results + + def _bare_name_matches(self, nodes): + """Special optimized matcher for bare_name.""" + count = 0 + r = {} + done = False + max = len(nodes) + while not done and count < max: + done = True + for leaf in self.content: + if leaf[0].match(nodes[count], r): + count += 1 + done = False + break + r[self.name] = nodes[:count] + return count, r + + def _recursive_matches(self, nodes, count): + """Helper to recursively yield the matches.""" + assert self.content is not None + if count >= self.min: + yield 0, {} + if count < self.max: + for alt in self.content: + for c0, r0 in generate_matches(alt, nodes): + for c1, r1 in self._recursive_matches(nodes[c0:], count+1): + r = {} + r.update(r0) + r.update(r1) + yield c0 + c1, r + + +class NegatedPattern(BasePattern): + + def __init__(self, content=None): + """ + Initializer. + + The argument is either a pattern or None. If it is None, this + only matches an empty sequence (effectively '$' in regex + lingo). If it is not None, this matches whenever the argument + pattern doesn't have any matches. + """ + if content is not None: + assert isinstance(content, BasePattern), repr(content) + self.content = content + + def match(self, node): + # We never match a node in its entirety + return False + + def match_seq(self, nodes): + # We only match an empty sequence of nodes in its entirety + return len(nodes) == 0 + + def generate_matches(self, nodes): + if self.content is None: + # Return a match if there is an empty sequence + if len(nodes) == 0: + yield 0, {} + else: + # Return a match if the argument pattern has no matches + for c, r in self.content.generate_matches(nodes): + return + yield 0, {} + + +def generate_matches(patterns, nodes): + """ + Generator yielding matches for a sequence of patterns and nodes. + + Args: + patterns: a sequence of patterns + nodes: a sequence of nodes + + Yields: + (count, results) tuples where: + count: the entire sequence of patterns matches nodes[:count]; + results: dict containing named submatches. + """ + if not patterns: + yield 0, {} + else: + p, rest = patterns[0], patterns[1:] + for c0, r0 in p.generate_matches(nodes): + if not rest: + yield c0, r0 + else: + for c1, r1 in generate_matches(rest, nodes[c0:]): + r = {} + r.update(r0) + r.update(r1) + yield c0 + c1, r diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/refactor.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/refactor.py new file mode 100644 index 0000000..a4c168d --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/lib2to3/lib2to3/refactor.py @@ -0,0 +1,747 @@ +# Copyright 2006 Google, Inc. All Rights Reserved. +# Licensed to PSF under a Contributor Agreement. + +"""Refactoring framework. + +Used as a main program, this can refactor any number of files and/or +recursively descend down directories. Imported as a module, this +provides infrastructure to write your own refactoring tool. +""" + +from __future__ import with_statement + +__author__ = "Guido van Rossum " + + +# Python imports +import os +import sys +import logging +import operator +import collections +import StringIO +from itertools import chain + +# Local imports +from .pgen2 import driver, tokenize, token +from .fixer_util import find_root +from . import pytree, pygram +from . import btm_utils as bu +from . import btm_matcher as bm + + +def get_all_fix_names(fixer_pkg, remove_prefix=True): + """Return a sorted list of all available fix names in the given package.""" + pkg = __import__(fixer_pkg, [], [], ["*"]) + fixer_dir = os.path.dirname(pkg.__file__) + fix_names = [] + for name in sorted(os.listdir(fixer_dir)): + if name.startswith("fix_") and name.endswith(".py"): + if remove_prefix: + name = name[4:] + fix_names.append(name[:-3]) + return fix_names + + +class _EveryNode(Exception): + pass + + +def _get_head_types(pat): + """ Accepts a pytree Pattern Node and returns a set + of the pattern types which will match first. """ + + if isinstance(pat, (pytree.NodePattern, pytree.LeafPattern)): + # NodePatters must either have no type and no content + # or a type and content -- so they don't get any farther + # Always return leafs + if pat.type is None: + raise _EveryNode + return set([pat.type]) + + if isinstance(pat, pytree.NegatedPattern): + if pat.content: + return _get_head_types(pat.content) + raise _EveryNode # Negated Patterns don't have a type + + if isinstance(pat, pytree.WildcardPattern): + # Recurse on each node in content + r = set() + for p in pat.content: + for x in p: + r.update(_get_head_types(x)) + return r + + raise Exception("Oh no! I don't understand pattern %s" %(pat)) + + +def _get_headnode_dict(fixer_list): + """ Accepts a list of fixers and returns a dictionary + of head node type --> fixer list. """ + head_nodes = collections.defaultdict(list) + every = [] + for fixer in fixer_list: + if fixer.pattern: + try: + heads = _get_head_types(fixer.pattern) + except _EveryNode: + every.append(fixer) + else: + for node_type in heads: + head_nodes[node_type].append(fixer) + else: + if fixer._accept_type is not None: + head_nodes[fixer._accept_type].append(fixer) + else: + every.append(fixer) + for node_type in chain(pygram.python_grammar.symbol2number.itervalues(), + pygram.python_grammar.tokens): + head_nodes[node_type].extend(every) + return dict(head_nodes) + + +def get_fixers_from_package(pkg_name): + """ + Return the fully qualified names for fixers in the package pkg_name. + """ + return [pkg_name + "." + fix_name + for fix_name in get_all_fix_names(pkg_name, False)] + +def _identity(obj): + return obj + +if sys.version_info < (3, 0): + import codecs + _open_with_encoding = codecs.open + # codecs.open doesn't translate newlines sadly. + def _from_system_newlines(input): + return input.replace(u"\r\n", u"\n") + def _to_system_newlines(input): + if os.linesep != "\n": + return input.replace(u"\n", os.linesep) + else: + return input +else: + _open_with_encoding = open + _from_system_newlines = _identity + _to_system_newlines = _identity + + +def _detect_future_features(source): + have_docstring = False + gen = tokenize.generate_tokens(StringIO.StringIO(source).readline) + def advance(): + tok = gen.next() + return tok[0], tok[1] + ignore = frozenset((token.NEWLINE, tokenize.NL, token.COMMENT)) + features = set() + try: + while True: + tp, value = advance() + if tp in ignore: + continue + elif tp == token.STRING: + if have_docstring: + break + have_docstring = True + elif tp == token.NAME and value == u"from": + tp, value = advance() + if tp != token.NAME or value != u"__future__": + break + tp, value = advance() + if tp != token.NAME or value != u"import": + break + tp, value = advance() + if tp == token.OP and value == u"(": + tp, value = advance() + while tp == token.NAME: + features.add(value) + tp, value = advance() + if tp != token.OP or value != u",": + break + tp, value = advance() + else: + break + except StopIteration: + pass + return frozenset(features) + + +class FixerError(Exception): + """A fixer could not be loaded.""" + + +class RefactoringTool(object): + + _default_options = {"print_function" : False, + "write_unchanged_files" : False} + + CLASS_PREFIX = "Fix" # The prefix for fixer classes + FILE_PREFIX = "fix_" # The prefix for modules with a fixer within + + def __init__(self, fixer_names, options=None, explicit=None): + """Initializer. + + Args: + fixer_names: a list of fixers to import + options: an dict with configuration. + explicit: a list of fixers to run even if they are explicit. + """ + self.fixers = fixer_names + self.explicit = explicit or [] + self.options = self._default_options.copy() + if options is not None: + self.options.update(options) + if self.options["print_function"]: + self.grammar = pygram.python_grammar_no_print_statement + else: + self.grammar = pygram.python_grammar + # When this is True, the refactor*() methods will call write_file() for + # files processed even if they were not changed during refactoring. If + # and only if the refactor method's write parameter was True. + self.write_unchanged_files = self.options.get("write_unchanged_files") + self.errors = [] + self.logger = logging.getLogger("RefactoringTool") + self.fixer_log = [] + self.wrote = False + self.driver = driver.Driver(self.grammar, + convert=pytree.convert, + logger=self.logger) + self.pre_order, self.post_order = self.get_fixers() + + + self.files = [] # List of files that were or should be modified + + self.BM = bm.BottomMatcher() + self.bmi_pre_order = [] # Bottom Matcher incompatible fixers + self.bmi_post_order = [] + + for fixer in chain(self.post_order, self.pre_order): + if fixer.BM_compatible: + self.BM.add_fixer(fixer) + # remove fixers that will be handled by the bottom-up + # matcher + elif fixer in self.pre_order: + self.bmi_pre_order.append(fixer) + elif fixer in self.post_order: + self.bmi_post_order.append(fixer) + + self.bmi_pre_order_heads = _get_headnode_dict(self.bmi_pre_order) + self.bmi_post_order_heads = _get_headnode_dict(self.bmi_post_order) + + + + def get_fixers(self): + """Inspects the options to load the requested patterns and handlers. + + Returns: + (pre_order, post_order), where pre_order is the list of fixers that + want a pre-order AST traversal, and post_order is the list that want + post-order traversal. + """ + pre_order_fixers = [] + post_order_fixers = [] + for fix_mod_path in self.fixers: + mod = __import__(fix_mod_path, {}, {}, ["*"]) + fix_name = fix_mod_path.rsplit(".", 1)[-1] + if fix_name.startswith(self.FILE_PREFIX): + fix_name = fix_name[len(self.FILE_PREFIX):] + parts = fix_name.split("_") + class_name = self.CLASS_PREFIX + "".join([p.title() for p in parts]) + try: + fix_class = getattr(mod, class_name) + except AttributeError: + raise FixerError("Can't find %s.%s" % (fix_name, class_name)) + fixer = fix_class(self.options, self.fixer_log) + if fixer.explicit and self.explicit is not True and \ + fix_mod_path not in self.explicit: + self.log_message("Skipping implicit fixer: %s", fix_name) + continue + + self.log_debug("Adding transformation: %s", fix_name) + if fixer.order == "pre": + pre_order_fixers.append(fixer) + elif fixer.order == "post": + post_order_fixers.append(fixer) + else: + raise FixerError("Illegal fixer order: %r" % fixer.order) + + key_func = operator.attrgetter("run_order") + pre_order_fixers.sort(key=key_func) + post_order_fixers.sort(key=key_func) + return (pre_order_fixers, post_order_fixers) + + def log_error(self, msg, *args, **kwds): + """Called when an error occurs.""" + raise + + def log_message(self, msg, *args): + """Hook to log a message.""" + if args: + msg = msg % args + self.logger.info(msg) + + def log_debug(self, msg, *args): + if args: + msg = msg % args + self.logger.debug(msg) + + def print_output(self, old_text, new_text, filename, equal): + """Called with the old version, new version, and filename of a + refactored file.""" + pass + + def refactor(self, items, write=False, doctests_only=False): + """Refactor a list of files and directories.""" + + for dir_or_file in items: + if os.path.isdir(dir_or_file): + self.refactor_dir(dir_or_file, write, doctests_only) + else: + self.refactor_file(dir_or_file, write, doctests_only) + + def refactor_dir(self, dir_name, write=False, doctests_only=False): + """Descends down a directory and refactor every Python file found. + + Python files are assumed to have a .py extension. + + Files and subdirectories starting with '.' are skipped. + """ + py_ext = os.extsep + "py" + for dirpath, dirnames, filenames in os.walk(dir_name): + self.log_debug("Descending into %s", dirpath) + dirnames.sort() + filenames.sort() + for name in filenames: + if (not name.startswith(".") and + os.path.splitext(name)[1] == py_ext): + fullname = os.path.join(dirpath, name) + self.refactor_file(fullname, write, doctests_only) + # Modify dirnames in-place to remove subdirs with leading dots + dirnames[:] = [dn for dn in dirnames if not dn.startswith(".")] + + def _read_python_source(self, filename): + """ + Do our best to decode a Python source file correctly. + """ + try: + f = open(filename, "rb") + except IOError as err: + self.log_error("Can't open %s: %s", filename, err) + return None, None + try: + encoding = tokenize.detect_encoding(f.readline)[0] + finally: + f.close() + with _open_with_encoding(filename, "r", encoding=encoding) as f: + return _from_system_newlines(f.read()), encoding + + def refactor_file(self, filename, write=False, doctests_only=False): + """Refactors a file.""" + input, encoding = self._read_python_source(filename) + if input is None: + # Reading the file failed. + return + input += u"\n" # Silence certain parse errors + if doctests_only: + self.log_debug("Refactoring doctests in %s", filename) + output = self.refactor_docstring(input, filename) + if self.write_unchanged_files or output != input: + self.processed_file(output, filename, input, write, encoding) + else: + self.log_debug("No doctest changes in %s", filename) + else: + tree = self.refactor_string(input, filename) + if self.write_unchanged_files or (tree and tree.was_changed): + # The [:-1] is to take off the \n we added earlier + self.processed_file(unicode(tree)[:-1], filename, + write=write, encoding=encoding) + else: + self.log_debug("No changes in %s", filename) + + def refactor_string(self, data, name): + """Refactor a given input string. + + Args: + data: a string holding the code to be refactored. + name: a human-readable name for use in error/log messages. + + Returns: + An AST corresponding to the refactored input stream; None if + there were errors during the parse. + """ + features = _detect_future_features(data) + if "print_function" in features: + self.driver.grammar = pygram.python_grammar_no_print_statement + try: + tree = self.driver.parse_string(data) + except Exception as err: + self.log_error("Can't parse %s: %s: %s", + name, err.__class__.__name__, err) + return + finally: + self.driver.grammar = self.grammar + tree.future_features = features + self.log_debug("Refactoring %s", name) + self.refactor_tree(tree, name) + return tree + + def refactor_stdin(self, doctests_only=False): + input = sys.stdin.read() + if doctests_only: + self.log_debug("Refactoring doctests in stdin") + output = self.refactor_docstring(input, "") + if self.write_unchanged_files or output != input: + self.processed_file(output, "", input) + else: + self.log_debug("No doctest changes in stdin") + else: + tree = self.refactor_string(input, "") + if self.write_unchanged_files or (tree and tree.was_changed): + self.processed_file(unicode(tree), "", input) + else: + self.log_debug("No changes in stdin") + + def refactor_tree(self, tree, name): + """Refactors a parse tree (modifying the tree in place). + + For compatible patterns the bottom matcher module is + used. Otherwise the tree is traversed node-to-node for + matches. + + Args: + tree: a pytree.Node instance representing the root of the tree + to be refactored. + name: a human-readable name for this tree. + + Returns: + True if the tree was modified, False otherwise. + """ + + for fixer in chain(self.pre_order, self.post_order): + fixer.start_tree(tree, name) + + #use traditional matching for the incompatible fixers + self.traverse_by(self.bmi_pre_order_heads, tree.pre_order()) + self.traverse_by(self.bmi_post_order_heads, tree.post_order()) + + # obtain a set of candidate nodes + match_set = self.BM.run(tree.leaves()) + + while any(match_set.values()): + for fixer in self.BM.fixers: + if fixer in match_set and match_set[fixer]: + #sort by depth; apply fixers from bottom(of the AST) to top + match_set[fixer].sort(key=pytree.Base.depth, reverse=True) + + if fixer.keep_line_order: + #some fixers(eg fix_imports) must be applied + #with the original file's line order + match_set[fixer].sort(key=pytree.Base.get_lineno) + + for node in list(match_set[fixer]): + if node in match_set[fixer]: + match_set[fixer].remove(node) + + try: + find_root(node) + except ValueError: + # this node has been cut off from a + # previous transformation ; skip + continue + + if node.fixers_applied and fixer in node.fixers_applied: + # do not apply the same fixer again + continue + + results = fixer.match(node) + + if results: + new = fixer.transform(node, results) + if new is not None: + node.replace(new) + #new.fixers_applied.append(fixer) + for node in new.post_order(): + # do not apply the fixer again to + # this or any subnode + if not node.fixers_applied: + node.fixers_applied = [] + node.fixers_applied.append(fixer) + + # update the original match set for + # the added code + new_matches = self.BM.run(new.leaves()) + for fxr in new_matches: + if not fxr in match_set: + match_set[fxr]=[] + + match_set[fxr].extend(new_matches[fxr]) + + for fixer in chain(self.pre_order, self.post_order): + fixer.finish_tree(tree, name) + return tree.was_changed + + def traverse_by(self, fixers, traversal): + """Traverse an AST, applying a set of fixers to each node. + + This is a helper method for refactor_tree(). + + Args: + fixers: a list of fixer instances. + traversal: a generator that yields AST nodes. + + Returns: + None + """ + if not fixers: + return + for node in traversal: + for fixer in fixers[node.type]: + results = fixer.match(node) + if results: + new = fixer.transform(node, results) + if new is not None: + node.replace(new) + node = new + + def processed_file(self, new_text, filename, old_text=None, write=False, + encoding=None): + """ + Called when a file has been refactored and there may be changes. + """ + self.files.append(filename) + if old_text is None: + old_text = self._read_python_source(filename)[0] + if old_text is None: + return + equal = old_text == new_text + self.print_output(old_text, new_text, filename, equal) + if equal: + self.log_debug("No changes to %s", filename) + if not self.write_unchanged_files: + return + if write: + self.write_file(new_text, filename, old_text, encoding) + else: + self.log_debug("Not writing changes to %s", filename) + + def write_file(self, new_text, filename, old_text, encoding=None): + """Writes a string to a file. + + It first shows a unified diff between the old text and the new text, and + then rewrites the file; the latter is only done if the write option is + set. + """ + try: + f = _open_with_encoding(filename, "w", encoding=encoding) + except os.error as err: + self.log_error("Can't create %s: %s", filename, err) + return + try: + f.write(_to_system_newlines(new_text)) + except os.error as err: + self.log_error("Can't write %s: %s", filename, err) + finally: + f.close() + self.log_debug("Wrote changes to %s", filename) + self.wrote = True + + PS1 = ">>> " + PS2 = "... " + + def refactor_docstring(self, input, filename): + """Refactors a docstring, looking for doctests. + + This returns a modified version of the input string. It looks + for doctests, which start with a ">>>" prompt, and may be + continued with "..." prompts, as long as the "..." is indented + the same as the ">>>". + + (Unfortunately we can't use the doctest module's parser, + since, like most parsers, it is not geared towards preserving + the original source.) + """ + result = [] + block = None + block_lineno = None + indent = None + lineno = 0 + for line in input.splitlines(True): + lineno += 1 + if line.lstrip().startswith(self.PS1): + if block is not None: + result.extend(self.refactor_doctest(block, block_lineno, + indent, filename)) + block_lineno = lineno + block = [line] + i = line.find(self.PS1) + indent = line[:i] + elif (indent is not None and + (line.startswith(indent + self.PS2) or + line == indent + self.PS2.rstrip() + u"\n")): + block.append(line) + else: + if block is not None: + result.extend(self.refactor_doctest(block, block_lineno, + indent, filename)) + block = None + indent = None + result.append(line) + if block is not None: + result.extend(self.refactor_doctest(block, block_lineno, + indent, filename)) + return u"".join(result) + + def refactor_doctest(self, block, lineno, indent, filename): + """Refactors one doctest. + + A doctest is given as a block of lines, the first of which starts + with ">>>" (possibly indented), while the remaining lines start + with "..." (identically indented). + + """ + try: + tree = self.parse_block(block, lineno, indent) + except Exception as err: + if self.logger.isEnabledFor(logging.DEBUG): + for line in block: + self.log_debug("Source: %s", line.rstrip(u"\n")) + self.log_error("Can't parse docstring in %s line %s: %s: %s", + filename, lineno, err.__class__.__name__, err) + return block + if self.refactor_tree(tree, filename): + new = unicode(tree).splitlines(True) + # Undo the adjustment of the line numbers in wrap_toks() below. + clipped, new = new[:lineno-1], new[lineno-1:] + assert clipped == [u"\n"] * (lineno-1), clipped + if not new[-1].endswith(u"\n"): + new[-1] += u"\n" + block = [indent + self.PS1 + new.pop(0)] + if new: + block += [indent + self.PS2 + line for line in new] + return block + + def summarize(self): + if self.wrote: + were = "were" + else: + were = "need to be" + if not self.files: + self.log_message("No files %s modified.", were) + else: + self.log_message("Files that %s modified:", were) + for file in self.files: + self.log_message(file) + if self.fixer_log: + self.log_message("Warnings/messages while refactoring:") + for message in self.fixer_log: + self.log_message(message) + if self.errors: + if len(self.errors) == 1: + self.log_message("There was 1 error:") + else: + self.log_message("There were %d errors:", len(self.errors)) + for msg, args, kwds in self.errors: + self.log_message(msg, *args, **kwds) + + def parse_block(self, block, lineno, indent): + """Parses a block into a tree. + + This is necessary to get correct line number / offset information + in the parser diagnostics and embedded into the parse tree. + """ + tree = self.driver.parse_tokens(self.wrap_toks(block, lineno, indent)) + tree.future_features = frozenset() + return tree + + def wrap_toks(self, block, lineno, indent): + """Wraps a tokenize stream to systematically modify start/end.""" + tokens = tokenize.generate_tokens(self.gen_lines(block, indent).next) + for type, value, (line0, col0), (line1, col1), line_text in tokens: + line0 += lineno - 1 + line1 += lineno - 1 + # Don't bother updating the columns; this is too complicated + # since line_text would also have to be updated and it would + # still break for tokens spanning lines. Let the user guess + # that the column numbers for doctests are relative to the + # end of the prompt string (PS1 or PS2). + yield type, value, (line0, col0), (line1, col1), line_text + + + def gen_lines(self, block, indent): + """Generates lines as expected by tokenize from a list of lines. + + This strips the first len(indent + self.PS1) characters off each line. + """ + prefix1 = indent + self.PS1 + prefix2 = indent + self.PS2 + prefix = prefix1 + for line in block: + if line.startswith(prefix): + yield line[len(prefix):] + elif line == prefix.rstrip() + u"\n": + yield u"\n" + else: + raise AssertionError("line=%r, prefix=%r" % (line, prefix)) + prefix = prefix2 + while True: + yield "" + + +class MultiprocessingUnsupported(Exception): + pass + + +class MultiprocessRefactoringTool(RefactoringTool): + + def __init__(self, *args, **kwargs): + super(MultiprocessRefactoringTool, self).__init__(*args, **kwargs) + self.queue = None + self.output_lock = None + + def refactor(self, items, write=False, doctests_only=False, + num_processes=1): + if num_processes == 1: + return super(MultiprocessRefactoringTool, self).refactor( + items, write, doctests_only) + try: + import multiprocessing + except ImportError: + raise MultiprocessingUnsupported + if self.queue is not None: + raise RuntimeError("already doing multiple processes") + self.queue = multiprocessing.JoinableQueue() + self.output_lock = multiprocessing.Lock() + processes = [multiprocessing.Process(target=self._child) + for i in xrange(num_processes)] + try: + for p in processes: + p.start() + super(MultiprocessRefactoringTool, self).refactor(items, write, + doctests_only) + finally: + self.queue.join() + for i in xrange(num_processes): + self.queue.put(None) + for p in processes: + if p.is_alive(): + p.join() + self.queue = None + + def _child(self): + task = self.queue.get() + while task is not None: + args, kwargs = task + try: + super(MultiprocessRefactoringTool, self).refactor_file( + *args, **kwargs) + finally: + self.queue.task_done() + task = self.queue.get() + + def refactor_file(self, *args, **kwargs): + if self.queue is not None: + self.queue.put((args, kwargs)) + else: + return super(MultiprocessRefactoringTool, self).refactor_file( + *args, **kwargs) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/pycodestyle.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/pycodestyle.py new file mode 100644 index 0000000..a4b11fe --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/pep8/pycodestyle.py @@ -0,0 +1,2325 @@ +#!/usr/bin/env python +# pycodestyle.py - Check Python source code formatting, according to PEP 8 +# +# Copyright (C) 2006-2009 Johann C. Rocholl +# Copyright (C) 2009-2014 Florent Xicluna +# Copyright (C) 2014-2016 Ian Lee +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +r""" +Check Python source code formatting, according to PEP 8. + +For usage and a list of options, try this: +$ python pycodestyle.py -h + +This program and its regression test suite live here: +https://github.com/pycqa/pycodestyle + +Groups of errors and warnings: +E errors +W warnings +100 indentation +200 whitespace +300 blank lines +400 imports +500 line length +600 deprecation +700 statements +900 syntax error +""" +from __future__ import with_statement + +import inspect +import keyword +import os +import re +import sys +import time +import tokenize +import warnings + +from fnmatch import fnmatch +from optparse import OptionParser + +try: + from configparser import RawConfigParser + from io import TextIOWrapper +except ImportError: + from ConfigParser import RawConfigParser + +__version__ = '2.3.1' + +DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox' +DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704,W503' +try: + if sys.platform == 'win32': + USER_CONFIG = os.path.expanduser(r'~\.pycodestyle') + else: + USER_CONFIG = os.path.join( + os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'), + 'pycodestyle' + ) +except ImportError: + USER_CONFIG = None + +PROJECT_CONFIG = ('setup.cfg', 'tox.ini') +TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite') +MAX_LINE_LENGTH = 79 +REPORT_FORMAT = { + 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s', + 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s', +} + +PyCF_ONLY_AST = 1024 +SINGLETONS = frozenset(['False', 'None', 'True']) +KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS +UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) +ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) +WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) +WS_NEEDED_OPERATORS = frozenset([ + '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>', + '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=']) +WHITESPACE = frozenset(' \t') +NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE]) +SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT]) +# ERRORTOKEN is triggered by backticks in Python 3 +SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN]) +BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines'] + +INDENT_REGEX = re.compile(r'([ \t]*)') +RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,') +RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$') +ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') +DOCSTRING_REGEX = re.compile(r'u?r?["\']') +EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]') +WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)') +COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)' + r'\s*(?(1)|(None|False|True))\b') +COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s') +COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type' + r'|\s*\(\s*([^)]*[^ )])\s*\))') +KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS)) +OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)') +LAMBDA_REGEX = re.compile(r'\blambda\b') +HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$') +STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)') +STARTSWITH_TOP_LEVEL_REGEX = re.compile(r'^(async\s+def\s+|def\s+|class\s+|@)') +STARTSWITH_INDENT_STATEMENT_REGEX = re.compile( + r'^\s*({0})'.format('|'.join(s.replace(' ', '\s+') for s in ( + 'def', 'async def', + 'for', 'async for', + 'if', 'elif', 'else', + 'try', 'except', 'finally', + 'with', 'async with', + 'class', + 'while', + ))) +) +DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ') + +# Work around Python < 2.6 behaviour, which does not generate NL after +# a comment which is on a line by itself. +COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == '#\n' + + +############################################################################## +# Plugins (check functions) for physical lines +############################################################################## + + +def tabs_or_spaces(physical_line, indent_char): + r"""Never mix tabs and spaces. + + The most popular way of indenting Python is with spaces only. The + second-most popular way is with tabs only. Code indented with a mixture + of tabs and spaces should be converted to using spaces exclusively. When + invoking the Python command line interpreter with the -t option, it issues + warnings about code that illegally mixes tabs and spaces. When using -tt + these warnings become errors. These options are highly recommended! + + Okay: if a == 0:\n a = 1\n b = 1 + E101: if a == 0:\n a = 1\n\tb = 1 + """ + indent = INDENT_REGEX.match(physical_line).group(1) + for offset, char in enumerate(indent): + if char != indent_char: + return offset, "E101 indentation contains mixed spaces and tabs" + + +def tabs_obsolete(physical_line): + r"""For new projects, spaces-only are strongly recommended over tabs. + + Okay: if True:\n return + W191: if True:\n\treturn + """ + indent = INDENT_REGEX.match(physical_line).group(1) + if '\t' in indent: + return indent.index('\t'), "W191 indentation contains tabs" + + +def trailing_whitespace(physical_line): + r"""Trailing whitespace is superfluous. + + The warning returned varies on whether the line itself is blank, for easier + filtering for those who want to indent their blank lines. + + Okay: spam(1)\n# + W291: spam(1) \n# + W293: class Foo(object):\n \n bang = 12 + """ + physical_line = physical_line.rstrip('\n') # chr(10), newline + physical_line = physical_line.rstrip('\r') # chr(13), carriage return + physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L + stripped = physical_line.rstrip(' \t\v') + if physical_line != stripped: + if stripped: + return len(stripped), "W291 trailing whitespace" + else: + return 0, "W293 blank line contains whitespace" + + +def trailing_blank_lines(physical_line, lines, line_number, total_lines): + r"""Trailing blank lines are superfluous. + + Okay: spam(1) + W391: spam(1)\n + + However the last line should end with a new line (warning W292). + """ + if line_number == total_lines: + stripped_last_line = physical_line.rstrip() + if not stripped_last_line: + return 0, "W391 blank line at end of file" + if stripped_last_line == physical_line: + return len(physical_line), "W292 no newline at end of file" + + +def maximum_line_length(physical_line, max_line_length, multiline, noqa): + r"""Limit all lines to a maximum of 79 characters. + + There are still many devices around that are limited to 80 character + lines; plus, limiting windows to 80 characters makes it possible to have + several windows side-by-side. The default wrapping on such devices looks + ugly. Therefore, please limit all lines to a maximum of 79 characters. + For flowing long blocks of text (docstrings or comments), limiting the + length to 72 characters is recommended. + + Reports error E501. + """ + line = physical_line.rstrip() + length = len(line) + if length > max_line_length and not noqa: + # Special case for long URLs in multi-line docstrings or comments, + # but still report the error when the 72 first chars are whitespaces. + chunks = line.split() + if ((len(chunks) == 1 and multiline) or + (len(chunks) == 2 and chunks[0] == '#')) and \ + len(line) - len(chunks[-1]) < max_line_length - 7: + return + if hasattr(line, 'decode'): # Python 2 + # The line could contain multi-byte characters + try: + length = len(line.decode('utf-8')) + except UnicodeError: + pass + if length > max_line_length: + return (max_line_length, "E501 line too long " + "(%d > %d characters)" % (length, max_line_length)) + + +############################################################################## +# Plugins (check functions) for logical lines +############################################################################## + + +def blank_lines(logical_line, blank_lines, indent_level, line_number, + blank_before, previous_logical, + previous_unindented_logical_line, previous_indent_level, + lines): + r"""Separate top-level function and class definitions with two blank lines. + + Method definitions inside a class are separated by a single blank line. + + Extra blank lines may be used (sparingly) to separate groups of related + functions. Blank lines may be omitted between a bunch of related + one-liners (e.g. a set of dummy implementations). + + Use blank lines in functions, sparingly, to indicate logical sections. + + Okay: def a():\n pass\n\n\ndef b():\n pass + Okay: def a():\n pass\n\n\nasync def b():\n pass + Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass + Okay: default = 1\nfoo = 1 + Okay: classify = 1\nfoo = 1 + + E301: class Foo:\n b = 0\n def bar():\n pass + E302: def a():\n pass\n\ndef b(n):\n pass + E302: def a():\n pass\n\nasync def b(n):\n pass + E303: def a():\n pass\n\n\n\ndef b(n):\n pass + E303: def a():\n\n\n\n pass + E304: @decorator\n\ndef a():\n pass + E305: def a():\n pass\na() + E306: def a():\n def b():\n pass\n def c():\n pass + """ + if line_number < 3 and not previous_logical: + return # Don't expect blank lines before the first line + if previous_logical.startswith('@'): + if blank_lines: + yield 0, "E304 blank lines found after function decorator" + elif blank_lines > 2 or (indent_level and blank_lines == 2): + yield 0, "E303 too many blank lines (%d)" % blank_lines + elif STARTSWITH_TOP_LEVEL_REGEX.match(logical_line): + if indent_level: + if not (blank_before or previous_indent_level < indent_level or + DOCSTRING_REGEX.match(previous_logical)): + ancestor_level = indent_level + nested = False + # Search backwards for a def ancestor or tree root (top level). + for line in lines[line_number - 2::-1]: + if line.strip() and expand_indent(line) < ancestor_level: + ancestor_level = expand_indent(line) + nested = line.lstrip().startswith('def ') + if nested or ancestor_level == 0: + break + if nested: + yield 0, "E306 expected 1 blank line before a " \ + "nested definition, found 0" + else: + yield 0, "E301 expected 1 blank line, found 0" + elif blank_before != 2: + yield 0, "E302 expected 2 blank lines, found %d" % blank_before + elif (logical_line and not indent_level and blank_before != 2 and + previous_unindented_logical_line.startswith(('def ', 'class '))): + yield 0, "E305 expected 2 blank lines after " \ + "class or function definition, found %d" % blank_before + + +def extraneous_whitespace(logical_line): + r"""Avoid extraneous whitespace. + + Avoid extraneous whitespace in these situations: + - Immediately inside parentheses, brackets or braces. + - Immediately before a comma, semicolon, or colon. + + Okay: spam(ham[1], {eggs: 2}) + E201: spam( ham[1], {eggs: 2}) + E201: spam(ham[ 1], {eggs: 2}) + E201: spam(ham[1], { eggs: 2}) + E202: spam(ham[1], {eggs: 2} ) + E202: spam(ham[1 ], {eggs: 2}) + E202: spam(ham[1], {eggs: 2 }) + + E203: if x == 4: print x, y; x, y = y , x + E203: if x == 4: print x, y ; x, y = y, x + E203: if x == 4 : print x, y; x, y = y, x + """ + line = logical_line + for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line): + text = match.group() + char = text.strip() + found = match.start() + if text == char + ' ': + # assert char in '([{' + yield found + 1, "E201 whitespace after '%s'" % char + elif line[found - 1] != ',': + code = ('E202' if char in '}])' else 'E203') # if char in ',;:' + yield found, "%s whitespace before '%s'" % (code, char) + + +def whitespace_around_keywords(logical_line): + r"""Avoid extraneous whitespace around keywords. + + Okay: True and False + E271: True and False + E272: True and False + E273: True and\tFalse + E274: True\tand False + """ + for match in KEYWORD_REGEX.finditer(logical_line): + before, after = match.groups() + + if '\t' in before: + yield match.start(1), "E274 tab before keyword" + elif len(before) > 1: + yield match.start(1), "E272 multiple spaces before keyword" + + if '\t' in after: + yield match.start(2), "E273 tab after keyword" + elif len(after) > 1: + yield match.start(2), "E271 multiple spaces after keyword" + + +def missing_whitespace_after_import_keyword(logical_line): + r"""Multiple imports in form from x import (a, b, c) should have space + between import statement and parenthesised name list. + + Okay: from foo import (bar, baz) + E275: from foo import(bar, baz) + E275: from importable.module import(bar, baz) + """ + line = logical_line + indicator = ' import(' + if line.startswith('from '): + found = line.find(indicator) + if -1 < found: + pos = found + len(indicator) - 1 + yield pos, "E275 missing whitespace after keyword" + + +def missing_whitespace(logical_line): + r"""Each comma, semicolon or colon should be followed by whitespace. + + Okay: [a, b] + Okay: (3,) + Okay: a[1:4] + Okay: a[:4] + Okay: a[1:] + Okay: a[1:4:2] + E231: ['a','b'] + E231: foo(bar,baz) + E231: [{'a':'b'}] + """ + line = logical_line + for index in range(len(line) - 1): + char = line[index] + if char in ',;:' and line[index + 1] not in WHITESPACE: + before = line[:index] + if char == ':' and before.count('[') > before.count(']') and \ + before.rfind('{') < before.rfind('['): + continue # Slice syntax, no space required + if char == ',' and line[index + 1] == ')': + continue # Allow tuple with only one element: (3,) + yield index, "E231 missing whitespace after '%s'" % char + + +def indentation(logical_line, previous_logical, indent_char, + indent_level, previous_indent_level): + r"""Use 4 spaces per indentation level. + + For really old code that you don't want to mess up, you can continue to + use 8-space tabs. + + Okay: a = 1 + Okay: if a == 0:\n a = 1 + E111: a = 1 + E114: # a = 1 + + Okay: for item in items:\n pass + E112: for item in items:\npass + E115: for item in items:\n# Hi\n pass + + Okay: a = 1\nb = 2 + E113: a = 1\n b = 2 + E116: a = 1\n # b = 2 + """ + c = 0 if logical_line else 3 + tmpl = "E11%d %s" if logical_line else "E11%d %s (comment)" + if indent_level % 4: + yield 0, tmpl % (1 + c, "indentation is not a multiple of four") + indent_expect = previous_logical.endswith(':') + if indent_expect and indent_level <= previous_indent_level: + yield 0, tmpl % (2 + c, "expected an indented block") + elif not indent_expect and indent_level > previous_indent_level: + yield 0, tmpl % (3 + c, "unexpected indentation") + + +def continued_indentation(logical_line, tokens, indent_level, hang_closing, + indent_char, noqa, verbose): + r"""Continuation lines indentation. + + Continuation lines should align wrapped elements either vertically + using Python's implicit line joining inside parentheses, brackets + and braces, or using a hanging indent. + + When using a hanging indent these considerations should be applied: + - there should be no arguments on the first line, and + - further indentation should be used to clearly distinguish itself as a + continuation line. + + Okay: a = (\n) + E123: a = (\n ) + + Okay: a = (\n 42) + E121: a = (\n 42) + E122: a = (\n42) + E123: a = (\n 42\n ) + E124: a = (24,\n 42\n) + E125: if (\n b):\n pass + E126: a = (\n 42) + E127: a = (24,\n 42) + E128: a = (24,\n 42) + E129: if (a or\n b):\n pass + E131: a = (\n 42\n 24) + """ + first_row = tokens[0][2][0] + nrows = 1 + tokens[-1][2][0] - first_row + if noqa or nrows == 1: + return + + # indent_next tells us whether the next block is indented; assuming + # that it is indented by 4 spaces, then we should not allow 4-space + # indents on the final continuation line; in turn, some other + # indents are allowed to have an extra 4 spaces. + indent_next = logical_line.endswith(':') + + row = depth = 0 + valid_hangs = (4,) if indent_char != '\t' else (4, 8) + # remember how many brackets were opened on each line + parens = [0] * nrows + # relative indents of physical lines + rel_indent = [0] * nrows + # for each depth, collect a list of opening rows + open_rows = [[0]] + # for each depth, memorize the hanging indentation + hangs = [None] + # visual indents + indent_chances = {} + last_indent = tokens[0][2] + visual_indent = None + last_token_multiline = False + # for each depth, memorize the visual indent column + indent = [last_indent[1]] + if verbose >= 3: + print(">>> " + tokens[0][4].rstrip()) + + for token_type, text, start, end, line in tokens: + + newline = row < start[0] - first_row + if newline: + row = start[0] - first_row + newline = not last_token_multiline and token_type not in NEWLINE + + if newline: + # this is the beginning of a continuation line. + last_indent = start + if verbose >= 3: + print("... " + line.rstrip()) + + # record the initial indent. + rel_indent[row] = expand_indent(line) - indent_level + + # identify closing bracket + close_bracket = (token_type == tokenize.OP and text in ']})') + + # is the indent relative to an opening bracket line? + for open_row in reversed(open_rows[depth]): + hang = rel_indent[row] - rel_indent[open_row] + hanging_indent = hang in valid_hangs + if hanging_indent: + break + if hangs[depth]: + hanging_indent = (hang == hangs[depth]) + # is there any chance of visual indent? + visual_indent = (not close_bracket and hang > 0 and + indent_chances.get(start[1])) + + if close_bracket and indent[depth]: + # closing bracket for visual indent + if start[1] != indent[depth]: + yield (start, "E124 closing bracket does not match " + "visual indentation") + elif close_bracket and not hang: + # closing bracket matches indentation of opening bracket's line + if hang_closing: + yield start, "E133 closing bracket is missing indentation" + elif indent[depth] and start[1] < indent[depth]: + if visual_indent is not True: + # visual indent is broken + yield (start, "E128 continuation line " + "under-indented for visual indent") + elif hanging_indent or (indent_next and rel_indent[row] == 8): + # hanging indent is verified + if close_bracket and not hang_closing: + yield (start, "E123 closing bracket does not match " + "indentation of opening bracket's line") + hangs[depth] = hang + elif visual_indent is True: + # visual indent is verified + indent[depth] = start[1] + elif visual_indent in (text, str): + # ignore token lined up with matching one from a previous line + pass + else: + # indent is broken + if hang <= 0: + error = "E122", "missing indentation or outdented" + elif indent[depth]: + error = "E127", "over-indented for visual indent" + elif not close_bracket and hangs[depth]: + error = "E131", "unaligned for hanging indent" + else: + hangs[depth] = hang + if hang > 4: + error = "E126", "over-indented for hanging indent" + else: + error = "E121", "under-indented for hanging indent" + yield start, "%s continuation line %s" % error + + # look for visual indenting + if (parens[row] and + token_type not in (tokenize.NL, tokenize.COMMENT) and + not indent[depth]): + indent[depth] = start[1] + indent_chances[start[1]] = True + if verbose >= 4: + print("bracket depth %s indent to %s" % (depth, start[1])) + # deal with implicit string concatenation + elif (token_type in (tokenize.STRING, tokenize.COMMENT) or + text in ('u', 'ur', 'b', 'br')): + indent_chances[start[1]] = str + # special case for the "if" statement because len("if (") == 4 + elif not indent_chances and not row and not depth and text == 'if': + indent_chances[end[1] + 1] = True + elif text == ':' and line[end[1]:].isspace(): + open_rows[depth].append(row) + + # keep track of bracket depth + if token_type == tokenize.OP: + if text in '([{': + depth += 1 + indent.append(0) + hangs.append(None) + if len(open_rows) == depth: + open_rows.append([]) + open_rows[depth].append(row) + parens[row] += 1 + if verbose >= 4: + print("bracket depth %s seen, col %s, visual min = %s" % + (depth, start[1], indent[depth])) + elif text in ')]}' and depth > 0: + # parent indents should not be more than this one + prev_indent = indent.pop() or last_indent[1] + hangs.pop() + for d in range(depth): + if indent[d] > prev_indent: + indent[d] = 0 + for ind in list(indent_chances): + if ind >= prev_indent: + del indent_chances[ind] + del open_rows[depth + 1:] + depth -= 1 + if depth: + indent_chances[indent[depth]] = True + for idx in range(row, -1, -1): + if parens[idx]: + parens[idx] -= 1 + break + assert len(indent) == depth + 1 + if start[1] not in indent_chances: + # allow lining up tokens + indent_chances[start[1]] = text + + last_token_multiline = (start[0] != end[0]) + if last_token_multiline: + rel_indent[end[0] - first_row] = rel_indent[row] + + if indent_next and expand_indent(line) == indent_level + 4: + pos = (start[0], indent[0] + 4) + if visual_indent: + code = "E129 visually indented line" + else: + code = "E125 continuation line" + yield pos, "%s with same indent as next logical line" % code + + +def whitespace_before_parameters(logical_line, tokens): + r"""Avoid extraneous whitespace. + + Avoid extraneous whitespace in the following situations: + - before the open parenthesis that starts the argument list of a + function call. + - before the open parenthesis that starts an indexing or slicing. + + Okay: spam(1) + E211: spam (1) + + Okay: dict['key'] = list[index] + E211: dict ['key'] = list[index] + E211: dict['key'] = list [index] + """ + prev_type, prev_text, __, prev_end, __ = tokens[0] + for index in range(1, len(tokens)): + token_type, text, start, end, __ = tokens[index] + if (token_type == tokenize.OP and + text in '([' and + start != prev_end and + (prev_type == tokenize.NAME or prev_text in '}])') and + # Syntax "class A (B):" is allowed, but avoid it + (index < 2 or tokens[index - 2][1] != 'class') and + # Allow "return (a.foo for a in range(5))" + not keyword.iskeyword(prev_text)): + yield prev_end, "E211 whitespace before '%s'" % text + prev_type = token_type + prev_text = text + prev_end = end + + +def whitespace_around_operator(logical_line): + r"""Avoid extraneous whitespace around an operator. + + Okay: a = 12 + 3 + E221: a = 4 + 5 + E222: a = 4 + 5 + E223: a = 4\t+ 5 + E224: a = 4 +\t5 + """ + for match in OPERATOR_REGEX.finditer(logical_line): + before, after = match.groups() + + if '\t' in before: + yield match.start(1), "E223 tab before operator" + elif len(before) > 1: + yield match.start(1), "E221 multiple spaces before operator" + + if '\t' in after: + yield match.start(2), "E224 tab after operator" + elif len(after) > 1: + yield match.start(2), "E222 multiple spaces after operator" + + +def missing_whitespace_around_operator(logical_line, tokens): + r"""Surround operators with a single space on either side. + + - Always surround these binary operators with a single space on + either side: assignment (=), augmented assignment (+=, -= etc.), + comparisons (==, <, >, !=, <=, >=, in, not in, is, is not), + Booleans (and, or, not). + + - If operators with different priorities are used, consider adding + whitespace around the operators with the lowest priorities. + + Okay: i = i + 1 + Okay: submitted += 1 + Okay: x = x * 2 - 1 + Okay: hypot2 = x * x + y * y + Okay: c = (a + b) * (a - b) + Okay: foo(bar, key='word', *args, **kwargs) + Okay: alpha[:-i] + + E225: i=i+1 + E225: submitted +=1 + E225: x = x /2 - 1 + E225: z = x **y + E226: c = (a+b) * (a-b) + E226: hypot2 = x*x + y*y + E227: c = a|b + E228: msg = fmt%(errno, errmsg) + """ + parens = 0 + need_space = False + prev_type = tokenize.OP + prev_text = prev_end = None + for token_type, text, start, end, line in tokens: + if token_type in SKIP_COMMENTS: + continue + if text in ('(', 'lambda'): + parens += 1 + elif text == ')': + parens -= 1 + if need_space: + if start != prev_end: + # Found a (probably) needed space + if need_space is not True and not need_space[1]: + yield (need_space[0], + "E225 missing whitespace around operator") + need_space = False + elif text == '>' and prev_text in ('<', '-'): + # Tolerate the "<>" operator, even if running Python 3 + # Deal with Python 3's annotated return value "->" + pass + else: + if need_space is True or need_space[1]: + # A needed trailing space was not found + yield prev_end, "E225 missing whitespace around operator" + elif prev_text != '**': + code, optype = 'E226', 'arithmetic' + if prev_text == '%': + code, optype = 'E228', 'modulo' + elif prev_text not in ARITHMETIC_OP: + code, optype = 'E227', 'bitwise or shift' + yield (need_space[0], "%s missing whitespace " + "around %s operator" % (code, optype)) + need_space = False + elif token_type == tokenize.OP and prev_end is not None: + if text == '=' and parens: + # Allow keyword args or defaults: foo(bar=None). + pass + elif text in WS_NEEDED_OPERATORS: + need_space = True + elif text in UNARY_OPERATORS: + # Check if the operator is being used as a binary operator + # Allow unary operators: -123, -x, +1. + # Allow argument unpacking: foo(*args, **kwargs). + if (prev_text in '}])' if prev_type == tokenize.OP + else prev_text not in KEYWORDS): + need_space = None + elif text in WS_OPTIONAL_OPERATORS: + need_space = None + + if need_space is None: + # Surrounding space is optional, but ensure that + # trailing space matches opening space + need_space = (prev_end, start != prev_end) + elif need_space and start == prev_end: + # A needed opening space was not found + yield prev_end, "E225 missing whitespace around operator" + need_space = False + prev_type = token_type + prev_text = text + prev_end = end + + +def whitespace_around_comma(logical_line): + r"""Avoid extraneous whitespace after a comma or a colon. + + Note: these checks are disabled by default + + Okay: a = (1, 2) + E241: a = (1, 2) + E242: a = (1,\t2) + """ + line = logical_line + for m in WHITESPACE_AFTER_COMMA_REGEX.finditer(line): + found = m.start() + 1 + if '\t' in m.group(): + yield found, "E242 tab after '%s'" % m.group()[0] + else: + yield found, "E241 multiple spaces after '%s'" % m.group()[0] + + +def whitespace_around_named_parameter_equals(logical_line, tokens): + r"""Don't use spaces around the '=' sign in function arguments. + + Don't use spaces around the '=' sign when used to indicate a + keyword argument or a default parameter value. + + Okay: def complex(real, imag=0.0): + Okay: return magic(r=real, i=imag) + Okay: boolean(a == b) + Okay: boolean(a != b) + Okay: boolean(a <= b) + Okay: boolean(a >= b) + Okay: def foo(arg: int = 42): + Okay: async def foo(arg: int = 42): + + E251: def complex(real, imag = 0.0): + E251: return magic(r = real, i = imag) + """ + parens = 0 + no_space = False + prev_end = None + annotated_func_arg = False + in_def = bool(STARTSWITH_DEF_REGEX.match(logical_line)) + message = "E251 unexpected spaces around keyword / parameter equals" + for token_type, text, start, end, line in tokens: + if token_type == tokenize.NL: + continue + if no_space: + no_space = False + if start != prev_end: + yield (prev_end, message) + if token_type == tokenize.OP: + if text in '([': + parens += 1 + elif text in ')]': + parens -= 1 + elif in_def and text == ':' and parens == 1: + annotated_func_arg = True + elif parens and text == ',' and parens == 1: + annotated_func_arg = False + elif parens and text == '=' and not annotated_func_arg: + no_space = True + if start != prev_end: + yield (prev_end, message) + if not parens: + annotated_func_arg = False + + prev_end = end + + +def whitespace_before_comment(logical_line, tokens): + r"""Separate inline comments by at least two spaces. + + An inline comment is a comment on the same line as a statement. Inline + comments should be separated by at least two spaces from the statement. + They should start with a # and a single space. + + Each line of a block comment starts with a # and a single space + (unless it is indented text inside the comment). + + Okay: x = x + 1 # Increment x + Okay: x = x + 1 # Increment x + Okay: # Block comment + E261: x = x + 1 # Increment x + E262: x = x + 1 #Increment x + E262: x = x + 1 # Increment x + E265: #Block comment + E266: ### Block comment + """ + prev_end = (0, 0) + for token_type, text, start, end, line in tokens: + if token_type == tokenize.COMMENT: + inline_comment = line[:start[1]].strip() + if inline_comment: + if prev_end[0] == start[0] and start[1] < prev_end[1] + 2: + yield (prev_end, + "E261 at least two spaces before inline comment") + symbol, sp, comment = text.partition(' ') + bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] or '#') + if inline_comment: + if bad_prefix or comment[:1] in WHITESPACE: + yield start, "E262 inline comment should start with '# '" + elif bad_prefix and (bad_prefix != '!' or start[0] > 1): + if bad_prefix != '#': + yield start, "E265 block comment should start with '# '" + elif comment: + yield start, "E266 too many leading '#' for block comment" + elif token_type != tokenize.NL: + prev_end = end + + +def imports_on_separate_lines(logical_line): + r"""Place imports on separate lines. + + Okay: import os\nimport sys + E401: import sys, os + + Okay: from subprocess import Popen, PIPE + Okay: from myclas import MyClass + Okay: from foo.bar.yourclass import YourClass + Okay: import myclass + Okay: import foo.bar.yourclass + """ + line = logical_line + if line.startswith('import '): + found = line.find(',') + if -1 < found and ';' not in line[:found]: + yield found, "E401 multiple imports on one line" + + +def module_imports_on_top_of_file( + logical_line, indent_level, checker_state, noqa): + r"""Place imports at the top of the file. + + Always put imports at the top of the file, just after any module comments + and docstrings, and before module globals and constants. + + Okay: import os + Okay: # this is a comment\nimport os + Okay: '''this is a module docstring'''\nimport os + Okay: r'''this is a module docstring'''\nimport os + Okay: + try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y + Okay: + try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y + E402: a=1\nimport os + E402: 'One string'\n"Two string"\nimport os + E402: a=1\nfrom sys import x + + Okay: if x:\n import os + """ + def is_string_literal(line): + if line[0] in 'uUbB': + line = line[1:] + if line and line[0] in 'rR': + line = line[1:] + return line and (line[0] == '"' or line[0] == "'") + + allowed_try_keywords = ('try', 'except', 'else', 'finally') + + if indent_level: # Allow imports in conditional statements or functions + return + if not logical_line: # Allow empty lines or comments + return + if noqa: + return + line = logical_line + if line.startswith('import ') or line.startswith('from '): + if checker_state.get('seen_non_imports', False): + yield 0, "E402 module level import not at top of file" + elif re.match(DUNDER_REGEX, line): + return + elif any(line.startswith(kw) for kw in allowed_try_keywords): + # Allow try, except, else, finally keywords intermixed with imports in + # order to support conditional importing + return + elif is_string_literal(line): + # The first literal is a docstring, allow it. Otherwise, report error. + if checker_state.get('seen_docstring', False): + checker_state['seen_non_imports'] = True + else: + checker_state['seen_docstring'] = True + else: + checker_state['seen_non_imports'] = True + + +def compound_statements(logical_line): + r"""Compound statements (on the same line) are generally discouraged. + + While sometimes it's okay to put an if/for/while with a small body + on the same line, never do this for multi-clause statements. + Also avoid folding such long lines! + + Always use a def statement instead of an assignment statement that + binds a lambda expression directly to a name. + + Okay: if foo == 'blah':\n do_blah_thing() + Okay: do_one() + Okay: do_two() + Okay: do_three() + + E701: if foo == 'blah': do_blah_thing() + E701: for x in lst: total += x + E701: while t < 10: t = delay() + E701: if foo == 'blah': do_blah_thing() + E701: else: do_non_blah_thing() + E701: try: something() + E701: finally: cleanup() + E701: if foo == 'blah': one(); two(); three() + E702: do_one(); do_two(); do_three() + E703: do_four(); # useless semicolon + E704: def f(x): return 2*x + E731: f = lambda x: 2*x + """ + line = logical_line + last_char = len(line) - 1 + found = line.find(':') + prev_found = 0 + counts = dict((char, 0) for char in '{}[]()') + while -1 < found < last_char: + update_counts(line[prev_found:found], counts) + if ((counts['{'] <= counts['}'] and # {'a': 1} (dict) + counts['['] <= counts[']'] and # [1:2] (slice) + counts['('] <= counts[')'])): # (annotation) + lambda_kw = LAMBDA_REGEX.search(line, 0, found) + if lambda_kw: + before = line[:lambda_kw.start()].rstrip() + if before[-1:] == '=' and isidentifier(before[:-1].strip()): + yield 0, ("E731 do not assign a lambda expression, use a " + "def") + break + if STARTSWITH_DEF_REGEX.match(line): + yield 0, "E704 multiple statements on one line (def)" + elif STARTSWITH_INDENT_STATEMENT_REGEX.match(line): + yield found, "E701 multiple statements on one line (colon)" + prev_found = found + found = line.find(':', found + 1) + found = line.find(';') + while -1 < found: + if found < last_char: + yield found, "E702 multiple statements on one line (semicolon)" + else: + yield found, "E703 statement ends with a semicolon" + found = line.find(';', found + 1) + + +def explicit_line_join(logical_line, tokens): + r"""Avoid explicit line join between brackets. + + The preferred way of wrapping long lines is by using Python's implied line + continuation inside parentheses, brackets and braces. Long lines can be + broken over multiple lines by wrapping expressions in parentheses. These + should be used in preference to using a backslash for line continuation. + + E502: aaa = [123, \\n 123] + E502: aaa = ("bbb " \\n "ccc") + + Okay: aaa = [123,\n 123] + Okay: aaa = ("bbb "\n "ccc") + Okay: aaa = "bbb " \\n "ccc" + Okay: aaa = 123 # \\ + """ + prev_start = prev_end = parens = 0 + comment = False + backslash = None + for token_type, text, start, end, line in tokens: + if token_type == tokenize.COMMENT: + comment = True + if start[0] != prev_start and parens and backslash and not comment: + yield backslash, "E502 the backslash is redundant between brackets" + if end[0] != prev_end: + if line.rstrip('\r\n').endswith('\\'): + backslash = (end[0], len(line.splitlines()[-1]) - 1) + else: + backslash = None + prev_start = prev_end = end[0] + else: + prev_start = start[0] + if token_type == tokenize.OP: + if text in '([{': + parens += 1 + elif text in ')]}': + parens -= 1 + + +def break_around_binary_operator(logical_line, tokens): + r""" + Avoid breaks before binary operators. + + The preferred place to break around a binary operator is after the + operator, not before it. + + W503: (width == 0\n + height == 0) + W503: (width == 0\n and height == 0) + + Okay: (width == 0 +\n height == 0) + Okay: foo(\n -x) + Okay: foo(x\n []) + Okay: x = '''\n''' + '' + Okay: foo(x,\n -y) + Okay: foo(x, # comment\n -y) + Okay: var = (1 &\n ~2) + Okay: var = (1 /\n -2) + Okay: var = (1 +\n -1 +\n -2) + """ + def is_binary_operator(token_type, text): + # The % character is strictly speaking a binary operator, but the + # common usage seems to be to put it next to the format parameters, + # after a line break. + return ((token_type == tokenize.OP or text in ['and', 'or']) and + text not in "()[]{},:.;@=%~") + + line_break = False + unary_context = True + # Previous non-newline token types and text + previous_token_type = None + previous_text = None + for token_type, text, start, end, line in tokens: + if token_type == tokenize.COMMENT: + continue + if ('\n' in text or '\r' in text) and token_type != tokenize.STRING: + line_break = True + else: + if (is_binary_operator(token_type, text) and line_break and + not unary_context and + not is_binary_operator(previous_token_type, + previous_text)): + yield start, "W503 line break before binary operator" + unary_context = text in '([{,;' + line_break = False + previous_token_type = token_type + previous_text = text + + +def comparison_to_singleton(logical_line, noqa): + r"""Comparison to singletons should use "is" or "is not". + + Comparisons to singletons like None should always be done + with "is" or "is not", never the equality operators. + + Okay: if arg is not None: + E711: if arg != None: + E711: if None == arg: + E712: if arg == True: + E712: if False == arg: + + Also, beware of writing if x when you really mean if x is not None -- + e.g. when testing whether a variable or argument that defaults to None was + set to some other value. The other value might have a type (such as a + container) that could be false in a boolean context! + """ + match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line) + if match: + singleton = match.group(1) or match.group(3) + same = (match.group(2) == '==') + + msg = "'if cond is %s:'" % (('' if same else 'not ') + singleton) + if singleton in ('None',): + code = 'E711' + else: + code = 'E712' + nonzero = ((singleton == 'True' and same) or + (singleton == 'False' and not same)) + msg += " or 'if %scond:'" % ('' if nonzero else 'not ') + yield match.start(2), ("%s comparison to %s should be %s" % + (code, singleton, msg)) + + +def comparison_negative(logical_line): + r"""Negative comparison should be done using "not in" and "is not". + + Okay: if x not in y:\n pass + Okay: assert (X in Y or X is Z) + Okay: if not (X in Y):\n pass + Okay: zz = x is not y + E713: Z = not X in Y + E713: if not X.B in Y:\n pass + E714: if not X is Y:\n pass + E714: Z = not X.B is Y + """ + match = COMPARE_NEGATIVE_REGEX.search(logical_line) + if match: + pos = match.start(1) + if match.group(2) == 'in': + yield pos, "E713 test for membership should be 'not in'" + else: + yield pos, "E714 test for object identity should be 'is not'" + + +def comparison_type(logical_line, noqa): + r"""Object type comparisons should always use isinstance(). + + Do not compare types directly. + + Okay: if isinstance(obj, int): + E721: if type(obj) is type(1): + + When checking if an object is a string, keep in mind that it might be a + unicode string too! In Python 2.3, str and unicode have a common base + class, basestring, so you can do: + + Okay: if isinstance(obj, basestring): + Okay: if type(a1) is type(b1): + """ + match = COMPARE_TYPE_REGEX.search(logical_line) + if match and not noqa: + inst = match.group(1) + if inst and isidentifier(inst) and inst not in SINGLETONS: + return # Allow comparison for types which are not obvious + yield match.start(), "E721 do not compare types, use 'isinstance()'" + + +def bare_except(logical_line, noqa): + r"""When catching exceptions, mention specific exceptions whenever possible. + + Okay: except Exception: + Okay: except BaseException: + E722: except: + """ + if noqa: + return + + regex = re.compile(r"except\s*:") + match = regex.match(logical_line) + if match: + yield match.start(), "E722 do not use bare except'" + + +def ambiguous_identifier(logical_line, tokens): + r"""Never use the characters 'l', 'O', or 'I' as variable names. + + In some fonts, these characters are indistinguishable from the numerals + one and zero. When tempted to use 'l', use 'L' instead. + + Okay: L = 0 + Okay: o = 123 + Okay: i = 42 + E741: l = 0 + E741: O = 123 + E741: I = 42 + + Variables can be bound in several other contexts, including class and + function definitions, 'global' and 'nonlocal' statements, exception + handlers, and 'with' statements. + + Okay: except AttributeError as o: + Okay: with lock as L: + E741: except AttributeError as O: + E741: with lock as l: + E741: global I + E741: nonlocal l + E742: class I(object): + E743: def l(x): + """ + idents_to_avoid = ('l', 'O', 'I') + prev_type, prev_text, prev_start, prev_end, __ = tokens[0] + for token_type, text, start, end, line in tokens[1:]: + ident = pos = None + # identifiers on the lhs of an assignment operator + if token_type == tokenize.OP and '=' in text: + if prev_text in idents_to_avoid: + ident = prev_text + pos = prev_start + # identifiers bound to a value with 'as', 'global', or 'nonlocal' + if prev_text in ('as', 'global', 'nonlocal'): + if text in idents_to_avoid: + ident = text + pos = start + if prev_text == 'class': + if text in idents_to_avoid: + yield start, "E742 ambiguous class definition '%s'" % text + if prev_text == 'def': + if text in idents_to_avoid: + yield start, "E743 ambiguous function definition '%s'" % text + if ident: + yield pos, "E741 ambiguous variable name '%s'" % ident + prev_text = text + prev_start = start + + +def python_3000_has_key(logical_line, noqa): + r"""The {}.has_key() method is removed in Python 3: use the 'in' operator. + + Okay: if "alph" in d:\n print d["alph"] + W601: assert d.has_key('alph') + """ + pos = logical_line.find('.has_key(') + if pos > -1 and not noqa: + yield pos, "W601 .has_key() is deprecated, use 'in'" + + +def python_3000_raise_comma(logical_line): + r"""When raising an exception, use "raise ValueError('message')". + + The older form is removed in Python 3. + + Okay: raise DummyError("Message") + W602: raise DummyError, "Message" + """ + match = RAISE_COMMA_REGEX.match(logical_line) + if match and not RERAISE_COMMA_REGEX.match(logical_line): + yield match.end() - 1, "W602 deprecated form of raising exception" + + +def python_3000_not_equal(logical_line): + r"""New code should always use != instead of <>. + + The older syntax is removed in Python 3. + + Okay: if a != 'no': + W603: if a <> 'no': + """ + pos = logical_line.find('<>') + if pos > -1: + yield pos, "W603 '<>' is deprecated, use '!='" + + +def python_3000_backticks(logical_line): + r"""Use repr() instead of backticks in Python 3. + + Okay: val = repr(1 + 2) + W604: val = `1 + 2` + """ + pos = logical_line.find('`') + if pos > -1: + yield pos, "W604 backticks are deprecated, use 'repr()'" + + +############################################################################## +# Helper functions +############################################################################## + + +if sys.version_info < (3,): + # Python 2: implicit encoding. + def readlines(filename): + """Read the source code.""" + with open(filename, 'rU') as f: + return f.readlines() + isidentifier = re.compile(r'[a-zA-Z_]\w*$').match + stdin_get_value = sys.stdin.read +else: + # Python 3 + def readlines(filename): + """Read the source code.""" + try: + with open(filename, 'rb') as f: + (coding, lines) = tokenize.detect_encoding(f.readline) + f = TextIOWrapper(f, coding, line_buffering=True) + return [line.decode(coding) for line in lines] + f.readlines() + except (LookupError, SyntaxError, UnicodeError): + # Fall back if file encoding is improperly declared + with open(filename, encoding='latin-1') as f: + return f.readlines() + isidentifier = str.isidentifier + + stdin_get_value = sys.stdin.read + +noqa = re.compile(r'# no(?:qa|pep8)\b', re.I).search + + +def expand_indent(line): + r"""Return the amount of indentation. + + Tabs are expanded to the next multiple of 8. + + >>> expand_indent(' ') + 4 + >>> expand_indent('\t') + 8 + >>> expand_indent(' \t') + 8 + >>> expand_indent(' \t') + 16 + """ + if '\t' not in line: + return len(line) - len(line.lstrip()) + result = 0 + for char in line: + if char == '\t': + result = result // 8 * 8 + 8 + elif char == ' ': + result += 1 + else: + break + return result + + +def mute_string(text): + """Replace contents with 'xxx' to prevent syntax matching. + + >>> mute_string('"abc"') + '"xxx"' + >>> mute_string("'''abc'''") + "'''xxx'''" + >>> mute_string("r'abc'") + "r'xxx'" + """ + # String modifiers (e.g. u or r) + start = text.index(text[-1]) + 1 + end = len(text) - 1 + # Triple quotes + if text[-3:] in ('"""', "'''"): + start += 2 + end -= 2 + return text[:start] + 'x' * (end - start) + text[end:] + + +def parse_udiff(diff, patterns=None, parent='.'): + """Return a dictionary of matching lines.""" + # For each file of the diff, the entry key is the filename, + # and the value is a set of row numbers to consider. + rv = {} + path = nrows = None + for line in diff.splitlines(): + if nrows: + if line[:1] != '-': + nrows -= 1 + continue + if line[:3] == '@@ ': + hunk_match = HUNK_REGEX.match(line) + (row, nrows) = [int(g or '1') for g in hunk_match.groups()] + rv[path].update(range(row, row + nrows)) + elif line[:3] == '+++': + path = line[4:].split('\t', 1)[0] + if path[:2] == 'b/': + path = path[2:] + rv[path] = set() + return dict([(os.path.join(parent, path), rows) + for (path, rows) in rv.items() + if rows and filename_match(path, patterns)]) + + +def normalize_paths(value, parent=os.curdir): + """Parse a comma-separated list of paths. + + Return a list of absolute paths. + """ + if not value: + return [] + if isinstance(value, list): + return value + paths = [] + for path in value.split(','): + path = path.strip() + if '/' in path: + path = os.path.abspath(os.path.join(parent, path)) + paths.append(path.rstrip('/')) + return paths + + +def filename_match(filename, patterns, default=True): + """Check if patterns contains a pattern that matches filename. + + If patterns is unspecified, this always returns True. + """ + if not patterns: + return default + return any(fnmatch(filename, pattern) for pattern in patterns) + + +def update_counts(s, counts): + r"""Adds one to the counts of each appearance of characters in s, + for characters in counts""" + for char in s: + if char in counts: + counts[char] += 1 + + +def _is_eol_token(token): + return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == '\\\n' + + +if COMMENT_WITH_NL: + def _is_eol_token(token, _eol_token=_is_eol_token): + return _eol_token(token) or (token[0] == tokenize.COMMENT and + token[1] == token[4]) + +############################################################################## +# Framework to run all checks +############################################################################## + + +_checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}} + + +def _get_parameters(function): + if sys.version_info >= (3, 3): + return [parameter.name + for parameter + in inspect.signature(function).parameters.values() + if parameter.kind == parameter.POSITIONAL_OR_KEYWORD] + else: + return inspect.getargspec(function)[0] + + +def register_check(check, codes=None): + """Register a new check object.""" + def _add_check(check, kind, codes, args): + if check in _checks[kind]: + _checks[kind][check][0].extend(codes or []) + else: + _checks[kind][check] = (codes or [''], args) + if inspect.isfunction(check): + args = _get_parameters(check) + if args and args[0] in ('physical_line', 'logical_line'): + if codes is None: + codes = ERRORCODE_REGEX.findall(check.__doc__ or '') + _add_check(check, args[0], codes, args) + elif inspect.isclass(check): + if _get_parameters(check.__init__)[:2] == ['self', 'tree']: + _add_check(check, 'tree', codes, None) + + +def init_checks_registry(): + """Register all globally visible functions. + + The first argument name is either 'physical_line' or 'logical_line'. + """ + mod = inspect.getmodule(register_check) + for (name, function) in inspect.getmembers(mod, inspect.isfunction): + register_check(function) + + +init_checks_registry() + + +class Checker(object): + """Load a Python source file, tokenize it, check coding style.""" + + def __init__(self, filename=None, lines=None, + options=None, report=None, **kwargs): + if options is None: + options = StyleGuide(kwargs).options + else: + assert not kwargs + self._io_error = None + self._physical_checks = options.physical_checks + self._logical_checks = options.logical_checks + self._ast_checks = options.ast_checks + self.max_line_length = options.max_line_length + self.multiline = False # in a multiline string? + self.hang_closing = options.hang_closing + self.verbose = options.verbose + self.filename = filename + # Dictionary where a checker can store its custom state. + self._checker_states = {} + if filename is None: + self.filename = 'stdin' + self.lines = lines or [] + elif filename == '-': + self.filename = 'stdin' + self.lines = stdin_get_value().splitlines(True) + elif lines is None: + try: + self.lines = readlines(filename) + except IOError: + (exc_type, exc) = sys.exc_info()[:2] + self._io_error = '%s: %s' % (exc_type.__name__, exc) + self.lines = [] + else: + self.lines = lines + if self.lines: + ord0 = ord(self.lines[0][0]) + if ord0 in (0xef, 0xfeff): # Strip the UTF-8 BOM + if ord0 == 0xfeff: + self.lines[0] = self.lines[0][1:] + elif self.lines[0][:3] == '\xef\xbb\xbf': + self.lines[0] = self.lines[0][3:] + self.report = report or options.report + self.report_error = self.report.error + self.noqa = False + + def report_invalid_syntax(self): + """Check if the syntax is valid.""" + (exc_type, exc) = sys.exc_info()[:2] + if len(exc.args) > 1: + offset = exc.args[1] + if len(offset) > 2: + offset = offset[1:3] + else: + offset = (1, 0) + self.report_error(offset[0], offset[1] or 0, + 'E901 %s: %s' % (exc_type.__name__, exc.args[0]), + self.report_invalid_syntax) + + def readline(self): + """Get the next line from the input buffer.""" + if self.line_number >= self.total_lines: + return '' + line = self.lines[self.line_number] + self.line_number += 1 + if self.indent_char is None and line[:1] in WHITESPACE: + self.indent_char = line[0] + return line + + def run_check(self, check, argument_names): + """Run a check plugin.""" + arguments = [] + for name in argument_names: + arguments.append(getattr(self, name)) + return check(*arguments) + + def init_checker_state(self, name, argument_names): + """Prepare custom state for the specific checker plugin.""" + if 'checker_state' in argument_names: + self.checker_state = self._checker_states.setdefault(name, {}) + + def check_physical(self, line): + """Run all physical checks on a raw input line.""" + self.physical_line = line + for name, check, argument_names in self._physical_checks: + self.init_checker_state(name, argument_names) + result = self.run_check(check, argument_names) + if result is not None: + (offset, text) = result + self.report_error(self.line_number, offset, text, check) + if text[:4] == 'E101': + self.indent_char = line[0] + + def build_tokens_line(self): + """Build a logical line from tokens.""" + logical = [] + comments = [] + length = 0 + prev_row = prev_col = mapping = None + for token_type, text, start, end, line in self.tokens: + if token_type in SKIP_TOKENS: + continue + if not mapping: + mapping = [(0, start)] + if token_type == tokenize.COMMENT: + comments.append(text) + continue + if token_type == tokenize.STRING: + text = mute_string(text) + if prev_row: + (start_row, start_col) = start + if prev_row != start_row: # different row + prev_text = self.lines[prev_row - 1][prev_col - 1] + if prev_text == ',' or (prev_text not in '{[(' and + text not in '}])'): + text = ' ' + text + elif prev_col != start_col: # different column + text = line[prev_col:start_col] + text + logical.append(text) + length += len(text) + mapping.append((length, end)) + (prev_row, prev_col) = end + self.logical_line = ''.join(logical) + self.noqa = comments and noqa(''.join(comments)) + return mapping + + def check_logical(self): + """Build a line from tokens and run all logical checks on it.""" + self.report.increment_logical_line() + mapping = self.build_tokens_line() + + if not mapping: + return + + (start_row, start_col) = mapping[0][1] + start_line = self.lines[start_row - 1] + self.indent_level = expand_indent(start_line[:start_col]) + if self.blank_before < self.blank_lines: + self.blank_before = self.blank_lines + if self.verbose >= 2: + print(self.logical_line[:80].rstrip()) + for name, check, argument_names in self._logical_checks: + if self.verbose >= 4: + print(' ' + name) + self.init_checker_state(name, argument_names) + for offset, text in self.run_check(check, argument_names) or (): + if not isinstance(offset, tuple): + for token_offset, pos in mapping: + if offset <= token_offset: + break + offset = (pos[0], pos[1] + offset - token_offset) + self.report_error(offset[0], offset[1], text, check) + if self.logical_line: + self.previous_indent_level = self.indent_level + self.previous_logical = self.logical_line + if not self.indent_level: + self.previous_unindented_logical_line = self.logical_line + self.blank_lines = 0 + self.tokens = [] + + def check_ast(self): + """Build the file's AST and run all AST checks.""" + try: + tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) + except (ValueError, SyntaxError, TypeError): + return self.report_invalid_syntax() + for name, cls, __ in self._ast_checks: + checker = cls(tree, self.filename) + for lineno, offset, text, check in checker.run(): + if not self.lines or not noqa(self.lines[lineno - 1]): + self.report_error(lineno, offset, text, check) + + def generate_tokens(self): + """Tokenize the file, run physical line checks and yield tokens.""" + if self._io_error: + self.report_error(1, 0, 'E902 %s' % self._io_error, readlines) + tokengen = tokenize.generate_tokens(self.readline) + try: + for token in tokengen: + if token[2][0] > self.total_lines: + return + self.noqa = token[4] and noqa(token[4]) + self.maybe_check_physical(token) + yield token + except (SyntaxError, tokenize.TokenError): + self.report_invalid_syntax() + + def maybe_check_physical(self, token): + """If appropriate (based on token), check current physical line(s).""" + # Called after every token, but act only on end of line. + if _is_eol_token(token): + # Obviously, a newline token ends a single physical line. + self.check_physical(token[4]) + elif token[0] == tokenize.STRING and '\n' in token[1]: + # Less obviously, a string that contains newlines is a + # multiline string, either triple-quoted or with internal + # newlines backslash-escaped. Check every physical line in the + # string *except* for the last one: its newline is outside of + # the multiline string, so we consider it a regular physical + # line, and will check it like any other physical line. + # + # Subtleties: + # - we don't *completely* ignore the last line; if it contains + # the magical "# noqa" comment, we disable all physical + # checks for the entire multiline string + # - have to wind self.line_number back because initially it + # points to the last line of the string, and we want + # check_physical() to give accurate feedback + if noqa(token[4]): + return + self.multiline = True + self.line_number = token[2][0] + for line in token[1].split('\n')[:-1]: + self.check_physical(line + '\n') + self.line_number += 1 + self.multiline = False + + def check_all(self, expected=None, line_offset=0): + """Run all checks on the input file.""" + self.report.init_file(self.filename, self.lines, expected, line_offset) + self.total_lines = len(self.lines) + if self._ast_checks: + self.check_ast() + self.line_number = 0 + self.indent_char = None + self.indent_level = self.previous_indent_level = 0 + self.previous_logical = '' + self.previous_unindented_logical_line = '' + self.tokens = [] + self.blank_lines = self.blank_before = 0 + parens = 0 + for token in self.generate_tokens(): + self.tokens.append(token) + token_type, text = token[0:2] + if self.verbose >= 3: + if token[2][0] == token[3][0]: + pos = '[%s:%s]' % (token[2][1] or '', token[3][1]) + else: + pos = 'l.%s' % token[3][0] + print('l.%s\t%s\t%s\t%r' % + (token[2][0], pos, tokenize.tok_name[token[0]], text)) + if token_type == tokenize.OP: + if text in '([{': + parens += 1 + elif text in '}])': + parens -= 1 + elif not parens: + if token_type in NEWLINE: + if token_type == tokenize.NEWLINE: + self.check_logical() + self.blank_before = 0 + elif len(self.tokens) == 1: + # The physical line contains only this token. + self.blank_lines += 1 + del self.tokens[0] + else: + self.check_logical() + elif COMMENT_WITH_NL and token_type == tokenize.COMMENT: + if len(self.tokens) == 1: + # The comment also ends a physical line + token = list(token) + token[1] = text.rstrip('\r\n') + token[3] = (token[2][0], token[2][1] + len(token[1])) + self.tokens = [tuple(token)] + self.check_logical() + if self.tokens: + self.check_physical(self.lines[-1]) + self.check_logical() + return self.report.get_file_results() + + +class BaseReport(object): + """Collect the results of the checks.""" + + print_filename = False + + def __init__(self, options): + self._benchmark_keys = options.benchmark_keys + self._ignore_code = options.ignore_code + # Results + self.elapsed = 0 + self.total_errors = 0 + self.counters = dict.fromkeys(self._benchmark_keys, 0) + self.messages = {} + + def start(self): + """Start the timer.""" + self._start_time = time.time() + + def stop(self): + """Stop the timer.""" + self.elapsed = time.time() - self._start_time + + def init_file(self, filename, lines, expected, line_offset): + """Signal a new file.""" + self.filename = filename + self.lines = lines + self.expected = expected or () + self.line_offset = line_offset + self.file_errors = 0 + self.counters['files'] += 1 + self.counters['physical lines'] += len(lines) + + def increment_logical_line(self): + """Signal a new logical line.""" + self.counters['logical lines'] += 1 + + def error(self, line_number, offset, text, check): + """Report an error, according to options.""" + code = text[:4] + if self._ignore_code(code): + return + if code in self.counters: + self.counters[code] += 1 + else: + self.counters[code] = 1 + self.messages[code] = text[5:] + # Don't care about expected errors or warnings + if code in self.expected: + return + if self.print_filename and not self.file_errors: + print(self.filename) + self.file_errors += 1 + self.total_errors += 1 + return code + + def get_file_results(self): + """Return the count of errors and warnings for this file.""" + return self.file_errors + + def get_count(self, prefix=''): + """Return the total count of errors and warnings.""" + return sum([self.counters[key] + for key in self.messages if key.startswith(prefix)]) + + def get_statistics(self, prefix=''): + """Get statistics for message codes that start with the prefix. + + prefix='' matches all errors and warnings + prefix='E' matches all errors + prefix='W' matches all warnings + prefix='E4' matches all errors that have to do with imports + """ + return ['%-7s %s %s' % (self.counters[key], key, self.messages[key]) + for key in sorted(self.messages) if key.startswith(prefix)] + + def print_statistics(self, prefix=''): + """Print overall statistics (number of errors and warnings).""" + for line in self.get_statistics(prefix): + print(line) + + def print_benchmark(self): + """Print benchmark numbers.""" + print('%-7.2f %s' % (self.elapsed, 'seconds elapsed')) + if self.elapsed: + for key in self._benchmark_keys: + print('%-7d %s per second (%d total)' % + (self.counters[key] / self.elapsed, key, + self.counters[key])) + + +class FileReport(BaseReport): + """Collect the results of the checks and print only the filenames.""" + + print_filename = True + + +class StandardReport(BaseReport): + """Collect and print the results of the checks.""" + + def __init__(self, options): + super(StandardReport, self).__init__(options) + self._fmt = REPORT_FORMAT.get(options.format.lower(), + options.format) + self._repeat = options.repeat + self._show_source = options.show_source + self._show_pep8 = options.show_pep8 + + def init_file(self, filename, lines, expected, line_offset): + """Signal a new file.""" + self._deferred_print = [] + return super(StandardReport, self).init_file( + filename, lines, expected, line_offset) + + def error(self, line_number, offset, text, check): + """Report an error, according to options.""" + code = super(StandardReport, self).error(line_number, offset, + text, check) + if code and (self.counters[code] == 1 or self._repeat): + self._deferred_print.append( + (line_number, offset, code, text[5:], check.__doc__)) + return code + + def get_file_results(self): + """Print the result and return the overall count for this file.""" + self._deferred_print.sort() + for line_number, offset, code, text, doc in self._deferred_print: + print(self._fmt % { + 'path': self.filename, + 'row': self.line_offset + line_number, 'col': offset + 1, + 'code': code, 'text': text, + }) + if self._show_source: + if line_number > len(self.lines): + line = '' + else: + line = self.lines[line_number - 1] + print(line.rstrip()) + print(re.sub(r'\S', ' ', line[:offset]) + '^') + if self._show_pep8 and doc: + print(' ' + doc.strip()) + + # stdout is block buffered when not stdout.isatty(). + # line can be broken where buffer boundary since other processes + # write to same file. + # flush() after print() to avoid buffer boundary. + # Typical buffer size is 8192. line written safely when + # len(line) < 8192. + sys.stdout.flush() + return self.file_errors + + +class DiffReport(StandardReport): + """Collect and print the results for the changed lines only.""" + + def __init__(self, options): + super(DiffReport, self).__init__(options) + self._selected = options.selected_lines + + def error(self, line_number, offset, text, check): + if line_number not in self._selected[self.filename]: + return + return super(DiffReport, self).error(line_number, offset, text, check) + + +class StyleGuide(object): + """Initialize a PEP-8 instance with few options.""" + + def __init__(self, *args, **kwargs): + # build options from the command line + self.checker_class = kwargs.pop('checker_class', Checker) + parse_argv = kwargs.pop('parse_argv', False) + config_file = kwargs.pop('config_file', False) + parser = kwargs.pop('parser', None) + # build options from dict + options_dict = dict(*args, **kwargs) + arglist = None if parse_argv else options_dict.get('paths', None) + options, self.paths = process_options( + arglist, parse_argv, config_file, parser) + if options_dict: + options.__dict__.update(options_dict) + if 'paths' in options_dict: + self.paths = options_dict['paths'] + + self.runner = self.input_file + self.options = options + + if not options.reporter: + options.reporter = BaseReport if options.quiet else StandardReport + + options.select = tuple(options.select or ()) + if not (options.select or options.ignore or + options.testsuite or options.doctest) and DEFAULT_IGNORE: + # The default choice: ignore controversial checks + options.ignore = tuple(DEFAULT_IGNORE.split(',')) + else: + # Ignore all checks which are not explicitly selected + options.ignore = ('',) if options.select else tuple(options.ignore) + options.benchmark_keys = BENCHMARK_KEYS[:] + options.ignore_code = self.ignore_code + options.physical_checks = self.get_checks('physical_line') + options.logical_checks = self.get_checks('logical_line') + options.ast_checks = self.get_checks('tree') + self.init_report() + + def init_report(self, reporter=None): + """Initialize the report instance.""" + self.options.report = (reporter or self.options.reporter)(self.options) + return self.options.report + + def check_files(self, paths=None): + """Run all checks on the paths.""" + if paths is None: + paths = self.paths + report = self.options.report + runner = self.runner + report.start() + try: + for path in paths: + if os.path.isdir(path): + self.input_dir(path) + elif not self.excluded(path): + runner(path) + except KeyboardInterrupt: + print('... stopped') + report.stop() + return report + + def input_file(self, filename, lines=None, expected=None, line_offset=0): + """Run all checks on a Python source file.""" + if self.options.verbose: + print('checking %s' % filename) + fchecker = self.checker_class( + filename, lines=lines, options=self.options) + return fchecker.check_all(expected=expected, line_offset=line_offset) + + def input_dir(self, dirname): + """Check all files in this directory and all subdirectories.""" + dirname = dirname.rstrip('/') + if self.excluded(dirname): + return 0 + counters = self.options.report.counters + verbose = self.options.verbose + filepatterns = self.options.filename + runner = self.runner + for root, dirs, files in os.walk(dirname): + if verbose: + print('directory ' + root) + counters['directories'] += 1 + for subdir in sorted(dirs): + if self.excluded(subdir, root): + dirs.remove(subdir) + for filename in sorted(files): + # contain a pattern that matches? + if ((filename_match(filename, filepatterns) and + not self.excluded(filename, root))): + runner(os.path.join(root, filename)) + + def excluded(self, filename, parent=None): + """Check if the file should be excluded. + + Check if 'options.exclude' contains a pattern that matches filename. + """ + if not self.options.exclude: + return False + basename = os.path.basename(filename) + if filename_match(basename, self.options.exclude): + return True + if parent: + filename = os.path.join(parent, filename) + filename = os.path.abspath(filename) + return filename_match(filename, self.options.exclude) + + def ignore_code(self, code): + """Check if the error code should be ignored. + + If 'options.select' contains a prefix of the error code, + return False. Else, if 'options.ignore' contains a prefix of + the error code, return True. + """ + if len(code) < 4 and any(s.startswith(code) + for s in self.options.select): + return False + return (code.startswith(self.options.ignore) and + not code.startswith(self.options.select)) + + def get_checks(self, argument_name): + """Get all the checks for this category. + + Find all globally visible functions where the first argument name + starts with argument_name and which contain selected tests. + """ + checks = [] + for check, attrs in _checks[argument_name].items(): + (codes, args) = attrs + if any(not (code and self.ignore_code(code)) for code in codes): + checks.append((check.__name__, check, args)) + return sorted(checks) + + +def get_parser(prog='pycodestyle', version=__version__): + """Create the parser for the program.""" + parser = OptionParser(prog=prog, version=version, + usage="%prog [options] input ...") + parser.config_options = [ + 'exclude', 'filename', 'select', 'ignore', 'max-line-length', + 'hang-closing', 'count', 'format', 'quiet', 'show-pep8', + 'show-source', 'statistics', 'verbose'] + parser.add_option('-v', '--verbose', default=0, action='count', + help="print status messages, or debug with -vv") + parser.add_option('-q', '--quiet', default=0, action='count', + help="report only file names, or nothing with -qq") + parser.add_option('-r', '--repeat', default=True, action='store_true', + help="(obsolete) show all occurrences of the same error") + parser.add_option('--first', action='store_false', dest='repeat', + help="show first occurrence of each error") + parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE, + help="exclude files or directories which match these " + "comma separated patterns (default: %default)") + parser.add_option('--filename', metavar='patterns', default='*.py', + help="when parsing directories, only check filenames " + "matching these comma separated patterns " + "(default: %default)") + parser.add_option('--select', metavar='errors', default='', + help="select errors and warnings (e.g. E,W6)") + parser.add_option('--ignore', metavar='errors', default='', + help="skip errors and warnings (e.g. E4,W) " + "(default: %s)" % DEFAULT_IGNORE) + parser.add_option('--show-source', action='store_true', + help="show source code for each error") + parser.add_option('--show-pep8', action='store_true', + help="show text of PEP 8 for each error " + "(implies --first)") + parser.add_option('--statistics', action='store_true', + help="count errors and warnings") + parser.add_option('--count', action='store_true', + help="print total number of errors and warnings " + "to standard error and set exit code to 1 if " + "total is not null") + parser.add_option('--max-line-length', type='int', metavar='n', + default=MAX_LINE_LENGTH, + help="set maximum allowed line length " + "(default: %default)") + parser.add_option('--hang-closing', action='store_true', + help="hang closing bracket instead of matching " + "indentation of opening bracket's line") + parser.add_option('--format', metavar='format', default='default', + help="set the error format [default|pylint|]") + parser.add_option('--diff', action='store_true', + help="report changes only within line number ranges in " + "the unified diff received on STDIN") + group = parser.add_option_group("Testing Options") + if os.path.exists(TESTSUITE_PATH): + group.add_option('--testsuite', metavar='dir', + help="run regression tests from dir") + group.add_option('--doctest', action='store_true', + help="run doctest on myself") + group.add_option('--benchmark', action='store_true', + help="measure processing speed") + return parser + + +def read_config(options, args, arglist, parser): + """Read and parse configurations. + + If a config file is specified on the command line with the "--config" + option, then only it is used for configuration. + + Otherwise, the user configuration (~/.config/pycodestyle) and any local + configurations in the current directory or above will be merged together + (in that order) using the read method of ConfigParser. + """ + config = RawConfigParser() + + cli_conf = options.config + + local_dir = os.curdir + + if USER_CONFIG and os.path.isfile(USER_CONFIG): + if options.verbose: + print('user configuration: %s' % USER_CONFIG) + config.read(USER_CONFIG) + + parent = tail = args and os.path.abspath(os.path.commonprefix(args)) + while tail: + if config.read(os.path.join(parent, fn) for fn in PROJECT_CONFIG): + local_dir = parent + if options.verbose: + print('local configuration: in %s' % parent) + break + (parent, tail) = os.path.split(parent) + + if cli_conf and os.path.isfile(cli_conf): + if options.verbose: + print('cli configuration: %s' % cli_conf) + config.read(cli_conf) + + pycodestyle_section = None + if config.has_section(parser.prog): + pycodestyle_section = parser.prog + elif config.has_section('pep8'): + pycodestyle_section = 'pep8' # Deprecated + warnings.warn('[pep8] section is deprecated. Use [pycodestyle].') + + if pycodestyle_section: + option_list = dict([(o.dest, o.type or o.action) + for o in parser.option_list]) + + # First, read the default values + (new_options, __) = parser.parse_args([]) + + # Second, parse the configuration + for opt in config.options(pycodestyle_section): + if opt.replace('_', '-') not in parser.config_options: + print(" unknown option '%s' ignored" % opt) + continue + if options.verbose > 1: + print(" %s = %s" % (opt, + config.get(pycodestyle_section, opt))) + normalized_opt = opt.replace('-', '_') + opt_type = option_list[normalized_opt] + if opt_type in ('int', 'count'): + value = config.getint(pycodestyle_section, opt) + elif opt_type in ('store_true', 'store_false'): + value = config.getboolean(pycodestyle_section, opt) + else: + value = config.get(pycodestyle_section, opt) + if normalized_opt == 'exclude': + value = normalize_paths(value, local_dir) + setattr(new_options, normalized_opt, value) + + # Third, overwrite with the command-line options + (options, __) = parser.parse_args(arglist, values=new_options) + options.doctest = options.testsuite = False + return options + + +def process_options(arglist=None, parse_argv=False, config_file=None, + parser=None): + """Process options passed either via arglist or via command line args. + + Passing in the ``config_file`` parameter allows other tools, such as flake8 + to specify their own options to be processed in pycodestyle. + """ + if not parser: + parser = get_parser() + if not parser.has_option('--config'): + group = parser.add_option_group("Configuration", description=( + "The project options are read from the [%s] section of the " + "tox.ini file or the setup.cfg file located in any parent folder " + "of the path(s) being processed. Allowed options are: %s." % + (parser.prog, ', '.join(parser.config_options)))) + group.add_option('--config', metavar='path', default=config_file, + help="user config file location") + # Don't read the command line if the module is used as a library. + if not arglist and not parse_argv: + arglist = [] + # If parse_argv is True and arglist is None, arguments are + # parsed from the command line (sys.argv) + (options, args) = parser.parse_args(arglist) + options.reporter = None + + if options.ensure_value('testsuite', False): + args.append(options.testsuite) + elif not options.ensure_value('doctest', False): + if parse_argv and not args: + if options.diff or any(os.path.exists(name) + for name in PROJECT_CONFIG): + args = ['.'] + else: + parser.error('input not specified') + options = read_config(options, args, arglist, parser) + options.reporter = parse_argv and options.quiet == 1 and FileReport + + options.filename = _parse_multi_options(options.filename) + options.exclude = normalize_paths(options.exclude) + options.select = _parse_multi_options(options.select) + options.ignore = _parse_multi_options(options.ignore) + + if options.diff: + options.reporter = DiffReport + stdin = stdin_get_value() + options.selected_lines = parse_udiff(stdin, options.filename, args[0]) + args = sorted(options.selected_lines) + + return options, args + + +def _parse_multi_options(options, split_token=','): + r"""Split and strip and discard empties. + + Turns the following: + + A, + B, + + into ["A", "B"] + """ + if options: + return [o.strip() for o in options.split(split_token) if o.strip()] + else: + return options + + +def _main(): + """Parse options and run checks on Python source.""" + import signal + + # Handle "Broken pipe" gracefully + try: + signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1)) + except AttributeError: + pass # not supported on Windows + + style_guide = StyleGuide(parse_argv=True) + options = style_guide.options + + if options.doctest or options.testsuite: + from testsuite.support import run_tests + report = run_tests(style_guide) + else: + report = style_guide.check_files() + + if options.statistics: + report.print_statistics() + + if options.benchmark: + report.print_benchmark() + + if options.testsuite and not options.quiet: + report.print_results() + + if report.total_errors: + if options.count: + sys.stderr.write(str(report.total_errors) + '\n') + sys.exit(1) + + +if __name__ == '__main__': + _main() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/__init__.py new file mode 100644 index 0000000..3b927b4 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/__init__.py @@ -0,0 +1,518 @@ +#@PydevCodeAnalysisIgnore +"""create and manipulate C data types in Python""" + +import os as _os, sys as _sys +from itertools import chain as _chain + +# special developer support to use ctypes from the CVS sandbox, +# without installing it +# XXX Remove this for the python core version +_magicfile = _os.path.join(_os.path.dirname(__file__), ".CTYPES_DEVEL") +if _os.path.isfile(_magicfile): + execfile(_magicfile) +del _magicfile + +__version__ = "0.9.9.6" + +from _ctypes import Union, Structure, Array +from _ctypes import _Pointer +from _ctypes import CFuncPtr as _CFuncPtr +from _ctypes import __version__ as _ctypes_version +from _ctypes import RTLD_LOCAL, RTLD_GLOBAL +from _ctypes import ArgumentError + +from struct import calcsize as _calcsize + +if __version__ != _ctypes_version: + raise Exception, ("Version number mismatch", __version__, _ctypes_version) + +if _os.name in ("nt", "ce"): + from _ctypes import FormatError + +from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \ + FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI + +""" +WINOLEAPI -> HRESULT +WINOLEAPI_(type) + +STDMETHODCALLTYPE + +STDMETHOD(name) +STDMETHOD_(type, name) + +STDAPICALLTYPE +""" + +def create_string_buffer(init, size=None): + """create_string_buffer(aString) -> character array + create_string_buffer(anInteger) -> character array + create_string_buffer(aString, anInteger) -> character array + """ + if isinstance(init, (str, unicode)): + if size is None: + size = len(init) + 1 + buftype = c_char * size + buf = buftype() + buf.value = init + return buf + elif isinstance(init, (int, long)): + buftype = c_char * init + buf = buftype() + return buf + raise TypeError, init + +def c_buffer(init, size=None): +## "deprecated, use create_string_buffer instead" +## import warnings +## warnings.warn("c_buffer is deprecated, use create_string_buffer instead", +## DeprecationWarning, stacklevel=2) + return create_string_buffer(init, size) + +_c_functype_cache = {} +def CFUNCTYPE(restype, *argtypes): + """CFUNCTYPE(restype, *argtypes) -> function prototype. + + restype: the result type + argtypes: a sequence specifying the argument types + + The function prototype can be called in three ways to create a + callable object: + + prototype(integer address) -> foreign function + prototype(callable) -> create and return a C callable function from callable + prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method + prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal + prototype((function name, dll object)[, paramflags]) -> foreign function exported by name + """ + try: + return _c_functype_cache[(restype, argtypes)] + except KeyError: + class CFunctionType(_CFuncPtr): + _argtypes_ = argtypes + _restype_ = restype + _flags_ = _FUNCFLAG_CDECL + _c_functype_cache[(restype, argtypes)] = CFunctionType + return CFunctionType + +if _os.name in ("nt", "ce"): + from _ctypes import LoadLibrary as _dlopen + from _ctypes import FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL + if _os.name == "ce": + # 'ce' doesn't have the stdcall calling convention + _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL + + _win_functype_cache = {} + def WINFUNCTYPE(restype, *argtypes): + # docstring set later (very similar to CFUNCTYPE.__doc__) + try: + return _win_functype_cache[(restype, argtypes)] + except KeyError: + class WinFunctionType(_CFuncPtr): + _argtypes_ = argtypes + _restype_ = restype + _flags_ = _FUNCFLAG_STDCALL + _win_functype_cache[(restype, argtypes)] = WinFunctionType + return WinFunctionType + if WINFUNCTYPE.__doc__: + WINFUNCTYPE.__doc__ = CFUNCTYPE.__doc__.replace("CFUNCTYPE", "WINFUNCTYPE") + +elif _os.name == "posix": + from _ctypes import dlopen as _dlopen #@UnresolvedImport + +from _ctypes import sizeof, byref, addressof, alignment +from _ctypes import _SimpleCData + +class py_object(_SimpleCData): + _type_ = "O" + +class c_short(_SimpleCData): + _type_ = "h" + +class c_ushort(_SimpleCData): + _type_ = "H" + +class c_long(_SimpleCData): + _type_ = "l" + +class c_ulong(_SimpleCData): + _type_ = "L" + +if _calcsize("i") == _calcsize("l"): + # if int and long have the same size, make c_int an alias for c_long + c_int = c_long + c_uint = c_ulong +else: + class c_int(_SimpleCData): + _type_ = "i" + + class c_uint(_SimpleCData): + _type_ = "I" + +class c_float(_SimpleCData): + _type_ = "f" + +class c_double(_SimpleCData): + _type_ = "d" + +if _calcsize("l") == _calcsize("q"): + # if long and long long have the same size, make c_longlong an alias for c_long + c_longlong = c_long + c_ulonglong = c_ulong +else: + class c_longlong(_SimpleCData): + _type_ = "q" + + class c_ulonglong(_SimpleCData): + _type_ = "Q" + ## def from_param(cls, val): + ## return ('d', float(val), val) + ## from_param = classmethod(from_param) + +class c_ubyte(_SimpleCData): + _type_ = "B" +c_ubyte.__ctype_le__ = c_ubyte.__ctype_be__ = c_ubyte +# backward compatibility: +##c_uchar = c_ubyte + +class c_byte(_SimpleCData): + _type_ = "b" +c_byte.__ctype_le__ = c_byte.__ctype_be__ = c_byte + +class c_char(_SimpleCData): + _type_ = "c" +c_char.__ctype_le__ = c_char.__ctype_be__ = c_char + +class c_char_p(_SimpleCData): + _type_ = "z" + +class c_void_p(_SimpleCData): + _type_ = "P" +c_voidp = c_void_p # backwards compatibility (to a bug) + +# This cache maps types to pointers to them. +_pointer_type_cache = {} + +def POINTER(cls): + try: + return _pointer_type_cache[cls] + except KeyError: + pass + if type(cls) is str: + klass = type(_Pointer)("LP_%s" % cls, + (_Pointer,), + {}) + _pointer_type_cache[id(klass)] = klass + return klass + else: + name = "LP_%s" % cls.__name__ + klass = type(_Pointer)(name, + (_Pointer,), + {'_type_': cls}) + _pointer_type_cache[cls] = klass + return klass + +try: + from _ctypes import set_conversion_mode +except ImportError: + pass +else: + if _os.name in ("nt", "ce"): + set_conversion_mode("mbcs", "ignore") + else: + set_conversion_mode("ascii", "strict") + + class c_wchar_p(_SimpleCData): + _type_ = "Z" + + class c_wchar(_SimpleCData): + _type_ = "u" + + POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param + + def create_unicode_buffer(init, size=None): + """create_unicode_buffer(aString) -> character array + create_unicode_buffer(anInteger) -> character array + create_unicode_buffer(aString, anInteger) -> character array + """ + if isinstance(init, (str, unicode)): + if size is None: + size = len(init) + 1 + buftype = c_wchar * size + buf = buftype() + buf.value = init + return buf + elif isinstance(init, (int, long)): + buftype = c_wchar * init + buf = buftype() + return buf + raise TypeError, init + +POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param + +# XXX Deprecated +def SetPointerType(pointer, cls): + if _pointer_type_cache.get(cls, None) is not None: + raise RuntimeError, \ + "This type already exists in the cache" + if not _pointer_type_cache.has_key(id(pointer)): + raise RuntimeError, \ + "What's this???" + pointer.set_type(cls) + _pointer_type_cache[cls] = pointer + del _pointer_type_cache[id(pointer)] + + +def pointer(inst): + return POINTER(type(inst))(inst) + +# XXX Deprecated +def ARRAY(typ, len): + return typ * len + +################################################################ + + +class CDLL(object): + """An instance of this class represents a loaded dll/shared + library, exporting functions using the standard C calling + convention (named 'cdecl' on Windows). + + The exported functions can be accessed as attributes, or by + indexing with the function name. Examples: + + .qsort -> callable object + ['qsort'] -> callable object + + Calling the functions releases the Python GIL during the call and + reaquires it afterwards. + """ + class _FuncPtr(_CFuncPtr): + _flags_ = _FUNCFLAG_CDECL + _restype_ = c_int # default, can be overridden in instances + + def __init__(self, name, mode=RTLD_LOCAL, handle=None): + self._name = name + if handle is None: + self._handle = _dlopen(self._name, mode) + else: + self._handle = handle + + def __repr__(self): + return "<%s '%s', handle %x at %x>" % \ + (self.__class__.__name__, self._name, + (self._handle & (_sys.maxint * 2 + 1)), + id(self)) + + def __getattr__(self, name): + if name.startswith('__') and name.endswith('__'): + raise AttributeError, name + return self.__getitem__(name) + + def __getitem__(self, name_or_ordinal): + func = self._FuncPtr((name_or_ordinal, self)) + if not isinstance(name_or_ordinal, (int, long)): + func.__name__ = name_or_ordinal + setattr(self, name_or_ordinal, func) + return func + +class PyDLL(CDLL): + """This class represents the Python library itself. It allows to + access Python API functions. The GIL is not released, and + Python exceptions are handled correctly. + """ + class _FuncPtr(_CFuncPtr): + _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI + _restype_ = c_int # default, can be overridden in instances + +if _os.name in ("nt", "ce"): + + class WinDLL(CDLL): + """This class represents a dll exporting functions using the + Windows stdcall calling convention. + """ + class _FuncPtr(_CFuncPtr): + _flags_ = _FUNCFLAG_STDCALL + _restype_ = c_int # default, can be overridden in instances + + # XXX Hm, what about HRESULT as normal parameter? + # Mustn't it derive from c_long then? + from _ctypes import _check_HRESULT, _SimpleCData + class HRESULT(_SimpleCData): + _type_ = "l" + # _check_retval_ is called with the function's result when it + # is used as restype. It checks for the FAILED bit, and + # raises a WindowsError if it is set. + # + # The _check_retval_ method is implemented in C, so that the + # method definition itself is not included in the traceback + # when it raises an error - that is what we want (and Python + # doesn't have a way to raise an exception in the caller's + # frame). + _check_retval_ = _check_HRESULT + + class OleDLL(CDLL): + """This class represents a dll exporting functions using the + Windows stdcall calling convention, and returning HRESULT. + HRESULT error values are automatically raised as WindowsError + exceptions. + """ + class _FuncPtr(_CFuncPtr): + _flags_ = _FUNCFLAG_STDCALL + _restype_ = HRESULT + +class LibraryLoader(object): + def __init__(self, dlltype): + self._dlltype = dlltype + + def __getattr__(self, name): + if name[0] == '_': + raise AttributeError(name) + dll = self._dlltype(name) + setattr(self, name, dll) + return dll + + def __getitem__(self, name): + return getattr(self, name) + + def LoadLibrary(self, name): + return self._dlltype(name) + +cdll = LibraryLoader(CDLL) +pydll = LibraryLoader(PyDLL) + +if _os.name in ("nt", "ce"): + pythonapi = PyDLL("python dll", None, _sys.dllhandle) +elif _sys.platform == "cygwin": + pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2]) +else: + pythonapi = PyDLL(None) + + +if _os.name in ("nt", "ce"): + windll = LibraryLoader(WinDLL) + oledll = LibraryLoader(OleDLL) + + if _os.name == "nt": + GetLastError = windll.kernel32.GetLastError + else: + GetLastError = windll.coredll.GetLastError + + def WinError(code=None, descr=None): + if code is None: + code = GetLastError() + if descr is None: + descr = FormatError(code).strip() + return WindowsError(code, descr) + +_pointer_type_cache[None] = c_void_p + +if sizeof(c_uint) == sizeof(c_void_p): + c_size_t = c_uint +elif sizeof(c_ulong) == sizeof(c_void_p): + c_size_t = c_ulong + +# functions + +from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, _cast_addr + +## void *memmove(void *, const void *, size_t); +memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr) + +## void *memset(void *, int, size_t) +memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr) + +def PYFUNCTYPE(restype, *argtypes): + class CFunctionType(_CFuncPtr): + _argtypes_ = argtypes + _restype_ = restype + _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI + return CFunctionType +_cast = PYFUNCTYPE(py_object, c_void_p, py_object)(_cast_addr) + +def cast(obj, typ): + result = _cast(obj, typ) + result.__keepref = obj + return result + +_string_at = CFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr) +def string_at(ptr, size=0): + """string_at(addr[, size]) -> string + + Return the string at addr.""" + return _string_at(ptr, size) + +try: + from _ctypes import _wstring_at_addr +except ImportError: + pass +else: + _wstring_at = CFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr) + def wstring_at(ptr, size=0): + """wstring_at(addr[, size]) -> string + + Return the string at addr.""" + return _wstring_at(ptr, size) + + +if _os.name == "nt": # COM stuff + def DllGetClassObject(rclsid, riid, ppv): + # First ask ctypes.com.server than comtypes.server for the + # class object. + + # trick py2exe by doing dynamic imports + result = -2147221231 # CLASS_E_CLASSNOTAVAILABLE + try: + ctcom = __import__("ctypes.com.server", globals(), locals(), ['*']) + except ImportError: + pass + else: + result = ctcom.DllGetClassObject(rclsid, riid, ppv) + + if result == -2147221231: # CLASS_E_CLASSNOTAVAILABLE + try: + ccom = __import__("comtypes.server", globals(), locals(), ['*']) + except ImportError: + pass + else: + result = ccom.DllGetClassObject(rclsid, riid, ppv) + + return result + + def DllCanUnloadNow(): + # First ask ctypes.com.server than comtypes.server if we can unload or not. + # trick py2exe by doing dynamic imports + result = 0 # S_OK + try: + ctcom = __import__("ctypes.com.server", globals(), locals(), ['*']) + except ImportError: + pass + else: + result = ctcom.DllCanUnloadNow() + if result != 0: # != S_OK + return result + + try: + ccom = __import__("comtypes.server", globals(), locals(), ['*']) + except ImportError: + return result + try: + return ccom.DllCanUnloadNow() + except AttributeError: + pass + return result + +from ctypes._endian import BigEndianStructure, LittleEndianStructure + +# Fill in specifically-sized types +c_int8 = c_byte +c_uint8 = c_ubyte +for kind in [c_short, c_int, c_long, c_longlong]: + if sizeof(kind) == 2: c_int16 = kind + elif sizeof(kind) == 4: c_int32 = kind + elif sizeof(kind) == 8: c_int64 = kind +for kind in [c_ushort, c_uint, c_ulong, c_ulonglong]: + if sizeof(kind) == 2: c_uint16 = kind + elif sizeof(kind) == 4: c_uint32 = kind + elif sizeof(kind) == 8: c_uint64 = kind +del(kind) diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/_ctypes.dll b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/_ctypes.dll new file mode 100644 index 0000000..238e869 Binary files /dev/null and b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/_ctypes.dll differ diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/_endian.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/_endian.py new file mode 100644 index 0000000..7de0376 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/_endian.py @@ -0,0 +1,58 @@ +#@PydevCodeAnalysisIgnore +import sys +from ctypes import * + +_array_type = type(c_int * 3) + +def _other_endian(typ): + """Return the type with the 'other' byte order. Simple types like + c_int and so on already have __ctype_be__ and __ctype_le__ + attributes which contain the types, for more complicated types + only arrays are supported. + """ + try: + return getattr(typ, _OTHER_ENDIAN) + except AttributeError: + if type(typ) == _array_type: + return _other_endian(typ._type_) * typ._length_ + raise TypeError("This type does not support other endian: %s" % typ) + +class _swapped_meta(type(Structure)): + def __setattr__(self, attrname, value): + if attrname == "_fields_": + fields = [] + for desc in value: + name = desc[0] + typ = desc[1] + rest = desc[2:] + fields.append((name, _other_endian(typ)) + rest) + value = fields + super(_swapped_meta, self).__setattr__(attrname, value) + +################################################################ + +# Note: The Structure metaclass checks for the *presence* (not the +# value!) of a _swapped_bytes_ attribute to determine the bit order in +# structures containing bit fields. + +if sys.byteorder == "little": + _OTHER_ENDIAN = "__ctype_be__" + + LittleEndianStructure = Structure + + class BigEndianStructure(Structure): + """Structure with big endian byte order""" + __metaclass__ = _swapped_meta + _swappedbytes_ = None + +elif sys.byteorder == "big": + _OTHER_ENDIAN = "__ctype_le__" + + BigEndianStructure = Structure + class LittleEndianStructure(Structure): + """Structure with little endian byte order""" + __metaclass__ = _swapped_meta + _swappedbytes_ = None + +else: + raise RuntimeError("Invalid byteorder") diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/ctypes-README.txt b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/ctypes-README.txt new file mode 100644 index 0000000..bf8de1e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/ctypes-README.txt @@ -0,0 +1,134 @@ +(Note: this is a compiled distribution of ctypes, compiled for cygwin + to allow using the cygwin conversions directly from interpreterInfo. The tests + have been removed to reduce the added size. It is only used by PyDev on cygwin). + +Overview + + ctypes is a ffi (Foreign Function Interface) package for Python. + + It allows to call functions exposed from dlls/shared libraries and + has extensive facilities to create, access and manipulate simpole + and complicated C data types transparently from Python - in other + words: wrap libraries in pure Python. + + ctypes runs on Windows, MacOS X, Linux, Solaris, FreeBSD. It may + also run on other systems, provided that libffi supports this + platform. + + On Windows, ctypes contains (the beginning of) a COM framework + mainly targetted to use and implement custom COM interfaces. + + +News + + ctypes now uses the same code base and libffi on all platforms. + For easier installation, the libffi sources are now included in + the source distribution - no need to find, build, and install a + compatible libffi version. + + +Requirements + + ctypes 0.9 requires Python 2.3 or higher, since it makes intensive + use of the new type system. + + ctypes uses libffi, which is copyright Red Hat, Inc. Complete + license see below. + + +Installation + + Windows + + On Windows, it is the easiest to download the executable + installer for your Python version and execute this. + + Installation from source + + Separate source distributions are available for windows and + non-windows systems. Please use the .zip file for Windows (it + contains the ctypes.com framework), and use the .tar.gz file + for non-Windows systems (it contains the complete + cross-platform libffi sources). + + To install ctypes from source, unpack the distribution, enter + the ctypes-0.9.x source directory, and enter + + python setup.py build + + This will build the Python extension modules. A C compiler is + required. On OS X, the segment attribute live_support must be + defined. If your compiler doesn't know about it, upgrade or + set the environment variable CCASFLAGS="-Dno_live_support". + + To run the supplied tests, enter + + python setup.py test + + To install ctypes, enter + + python setup.py install --help + + to see the avaibable options, and finally + + python setup.py install [options] + + + For Windows CE, a project file is provided in + wince\_ctypes.vcw. MS embedded Visual C 4.0 is required to + build the extension modules. + + +Additional notes + + Current version: 0.9.9.3 + + Homepage: http://starship.python.net/crew/theller/ctypes.html + + +ctypes license + + Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Thomas Heller + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +libffi license + + libffi - Copyright (c) 1996-2003 Red Hat, Inc. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the ``Software''), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR + ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/.cvsignore b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/.cvsignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/.cvsignore @@ -0,0 +1 @@ +*.pyc diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/__init__.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/__init__.py new file mode 100644 index 0000000..5621def --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/__init__.py @@ -0,0 +1,9 @@ +""" +Enough Mach-O to make your head spin. + +See the relevant header files in /usr/include/mach-o + +And also Apple's documentation. +""" + +__version__ = '1.0' diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/dyld.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/dyld.py new file mode 100644 index 0000000..85073aa --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/dyld.py @@ -0,0 +1,167 @@ +#@PydevCodeAnalysisIgnore +""" +dyld emulation +""" + +import os +from framework import framework_info +from dylib import dylib_info +from itertools import * + +__all__ = [ + 'dyld_find', 'framework_find', + 'framework_info', 'dylib_info', +] + +# These are the defaults as per man dyld(1) +# +DEFAULT_FRAMEWORK_FALLBACK = [ + os.path.expanduser("~/Library/Frameworks"), + "/Library/Frameworks", + "/Network/Library/Frameworks", + "/System/Library/Frameworks", +] + +DEFAULT_LIBRARY_FALLBACK = [ + os.path.expanduser("~/lib"), + "/usr/local/lib", + "/lib", + "/usr/lib", +] + +def ensure_utf8(s): + """Not all of PyObjC and Python understand unicode paths very well yet""" + if isinstance(s, unicode): + return s.encode('utf8') + return s + +def dyld_env(env, var): + if env is None: + env = os.environ + rval = env.get(var) + if rval is None: + return [] + return rval.split(':') + +def dyld_image_suffix(env=None): + if env is None: + env = os.environ + return env.get('DYLD_IMAGE_SUFFIX') + +def dyld_framework_path(env=None): + return dyld_env(env, 'DYLD_FRAMEWORK_PATH') + +def dyld_library_path(env=None): + return dyld_env(env, 'DYLD_LIBRARY_PATH') + +def dyld_fallback_framework_path(env=None): + return dyld_env(env, 'DYLD_FALLBACK_FRAMEWORK_PATH') + +def dyld_fallback_library_path(env=None): + return dyld_env(env, 'DYLD_FALLBACK_LIBRARY_PATH') + +def dyld_image_suffix_search(iterator, env=None): + """For a potential path iterator, add DYLD_IMAGE_SUFFIX semantics""" + suffix = dyld_image_suffix(env) + if suffix is None: + return iterator + def _inject(iterator=iterator, suffix=suffix): + for path in iterator: + if path.endswith('.dylib'): + yield path[:-len('.dylib')] + suffix + '.dylib' + else: + yield path + suffix + yield path + return _inject() + +def dyld_override_search(name, env=None): + # If DYLD_FRAMEWORK_PATH is set and this dylib_name is a + # framework name, use the first file that exists in the framework + # path if any. If there is none go on to search the DYLD_LIBRARY_PATH + # if any. + + framework = framework_info(name) + + if framework is not None: + for path in dyld_framework_path(env): + yield os.path.join(path, framework['name']) + + # If DYLD_LIBRARY_PATH is set then use the first file that exists + # in the path. If none use the original name. + for path in dyld_library_path(env): + yield os.path.join(path, os.path.basename(name)) + +def dyld_executable_path_search(name, executable_path=None): + # If we haven't done any searching and found a library and the + # dylib_name starts with "@executable_path/" then construct the + # library name. + if name.startswith('@executable_path/') and executable_path is not None: + yield os.path.join(executable_path, name[len('@executable_path/'):]) + +def dyld_default_search(name, env=None): + yield name + + framework = framework_info(name) + + if framework is not None: + fallback_framework_path = dyld_fallback_framework_path(env) + for path in fallback_framework_path: + yield os.path.join(path, framework['name']) + + fallback_library_path = dyld_fallback_library_path(env) + for path in fallback_library_path: + yield os.path.join(path, os.path.basename(name)) + + if framework is not None and not fallback_framework_path: + for path in DEFAULT_FRAMEWORK_FALLBACK: + yield os.path.join(path, framework['name']) + + if not fallback_library_path: + for path in DEFAULT_LIBRARY_FALLBACK: + yield os.path.join(path, os.path.basename(name)) + +def dyld_find(name, executable_path=None, env=None): + """ + Find a library or framework using dyld semantics + """ + name = ensure_utf8(name) + executable_path = ensure_utf8(executable_path) + for path in dyld_image_suffix_search(chain( + dyld_override_search(name, env), + dyld_executable_path_search(name, executable_path), + dyld_default_search(name, env), + ), env): + if os.path.isfile(path): + return path + raise ValueError, "dylib %s could not be found" % (name,) + +def framework_find(fn, executable_path=None, env=None): + """ + Find a framework using dyld semantics in a very loose manner. + + Will take input such as: + Python + Python.framework + Python.framework/Versions/Current + """ + try: + return dyld_find(fn, executable_path=executable_path, env=env) + except ValueError: + pass + fmwk_index = fn.rfind('.framework') + if fmwk_index == -1: + fmwk_index = len(fn) + fn += '.framework' + fn = os.path.join(fn, os.path.basename(fn[:fmwk_index])) + try: + return dyld_find(fn, executable_path=executable_path, env=env) + except ValueError: + raise e + +def test_dyld_find(): + env = {} + assert dyld_find('libSystem.dylib') == '/usr/lib/libSystem.dylib' + assert dyld_find('System.framework/System') == '/System/Library/Frameworks/System.framework/System' + +if __name__ == '__main__': + test_dyld_find() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/dylib.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/dylib.py new file mode 100644 index 0000000..aa10750 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/dylib.py @@ -0,0 +1,63 @@ +""" +Generic dylib path manipulation +""" + +import re + +__all__ = ['dylib_info'] + +DYLIB_RE = re.compile(r"""(?x) +(?P^.*)(?:^|/) +(?P + (?P\w+?) + (?:\.(?P[^._]+))? + (?:_(?P[^._]+))? + \.dylib$ +) +""") + +def dylib_info(filename): + """ + A dylib name can take one of the following four forms: + Location/Name.SomeVersion_Suffix.dylib + Location/Name.SomeVersion.dylib + Location/Name_Suffix.dylib + Location/Name.dylib + + returns None if not found or a mapping equivalent to: + dict( + location='Location', + name='Name.SomeVersion_Suffix.dylib', + shortname='Name', + version='SomeVersion', + suffix='Suffix', + ) + + Note that SomeVersion and Suffix are optional and may be None + if not present. + """ + is_dylib = DYLIB_RE.match(filename) + if not is_dylib: + return None + return is_dylib.groupdict() + + +def test_dylib_info(): + def d(location=None, name=None, shortname=None, version=None, suffix=None): + return dict( + location=location, + name=name, + shortname=shortname, + version=version, + suffix=suffix + ) + assert dylib_info('completely/invalid') is None + assert dylib_info('completely/invalide_debug') is None + assert dylib_info('P/Foo.dylib') == d('P', 'Foo.dylib', 'Foo') + assert dylib_info('P/Foo_debug.dylib') == d('P', 'Foo_debug.dylib', 'Foo', suffix='debug') + assert dylib_info('P/Foo.A.dylib') == d('P', 'Foo.A.dylib', 'Foo', 'A') + assert dylib_info('P/Foo_debug.A.dylib') == d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A') + assert dylib_info('P/Foo.A_debug.dylib') == d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug') + +if __name__ == '__main__': + test_dylib_info() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/framework.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/framework.py new file mode 100644 index 0000000..ad6ed55 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/macholib/framework.py @@ -0,0 +1,65 @@ +""" +Generic framework path manipulation +""" + +import re + +__all__ = ['framework_info'] + +STRICT_FRAMEWORK_RE = re.compile(r"""(?x) +(?P^.*)(?:^|/) +(?P + (?P\w+).framework/ + (?:Versions/(?P[^/]+)/)? + (?P=shortname) + (?:_(?P[^_]+))? +)$ +""") + +def framework_info(filename): + """ + A framework name can take one of the following four forms: + Location/Name.framework/Versions/SomeVersion/Name_Suffix + Location/Name.framework/Versions/SomeVersion/Name + Location/Name.framework/Name_Suffix + Location/Name.framework/Name + + returns None if not found, or a mapping equivalent to: + dict( + location='Location', + name='Name.framework/Versions/SomeVersion/Name_Suffix', + shortname='Name', + version='SomeVersion', + suffix='Suffix', + ) + + Note that SomeVersion and Suffix are optional and may be None + if not present + """ + is_framework = STRICT_FRAMEWORK_RE.match(filename) + if not is_framework: + return None + return is_framework.groupdict() + +def test_framework_info(): + def d(location=None, name=None, shortname=None, version=None, suffix=None): + return dict( + location=location, + name=name, + shortname=shortname, + version=version, + suffix=suffix + ) + assert framework_info('completely/invalid') is None + assert framework_info('completely/invalid/_debug') is None + assert framework_info('P/F.framework') is None + assert framework_info('P/F.framework/_debug') is None + assert framework_info('P/F.framework/F') == d('P', 'F.framework/F', 'F') + assert framework_info('P/F.framework/F_debug') == d('P', 'F.framework/F_debug', 'F', suffix='debug') + assert framework_info('P/F.framework/Versions') is None + assert framework_info('P/F.framework/Versions/A') is None + assert framework_info('P/F.framework/Versions/A/F') == d('P', 'F.framework/Versions/A/F', 'F', 'A') + assert framework_info('P/F.framework/Versions/A/F_debug') == d('P', 'F.framework/Versions/A/F_debug', 'F', 'A', 'debug') + +if __name__ == '__main__': + test_framework_info() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/util.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/util.py new file mode 100644 index 0000000..6db0cfb --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/util.py @@ -0,0 +1,124 @@ +#@PydevCodeAnalysisIgnore +import sys, os +import ctypes + +# find_library(name) returns the pathname of a library, or None. +if os.name == "nt": + def find_library(name): + # See MSDN for the REAL search order. + for directory in os.environ['PATH'].split(os.pathsep): + fname = os.path.join(directory, name) + if os.path.exists(fname): + return fname + if fname.lower().endswith(".dll"): + continue + fname = fname + ".dll" + if os.path.exists(fname): + return fname + return None + +if os.name == "ce": + # search path according to MSDN: + # - absolute path specified by filename + # - The .exe launch directory + # - the Windows directory + # - ROM dll files (where are they?) + # - OEM specified search path: HKLM\Loader\SystemPath + def find_library(name): + return name + +if os.name == "posix" and sys.platform == "darwin": + from ctypes.macholib.dyld import dyld_find as _dyld_find + def find_library(name): + possible = ['lib%s.dylib' % name, + '%s.dylib' % name, + '%s.framework/%s' % (name, name)] + for name in possible: + try: + return _dyld_find(name) + except ValueError: + continue + return None + +elif os.name == "posix": + # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump + import re, tempfile + + def _findLib_gcc(name): + expr = '[^\(\)\s]*lib%s\.[^\(\)\s]*' % name + cmd = 'if type gcc &>/dev/null; then CC=gcc; else CC=cc; fi;' \ + '$CC -Wl,-t -o /dev/null 2>&1 -l' + name + try: + fdout, outfile = tempfile.mkstemp() + fd = os.popen(cmd) + trace = fd.read() + err = fd.close() + finally: + try: + os.unlink(outfile) + except OSError, e: + import errno + if e.errno != errno.ENOENT: + raise + res = re.search(expr, trace) + if not res: + return None + return res.group(0) + + def _findLib_ld(name): + expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name + res = re.search(expr, os.popen('/sbin/ldconfig -p 2>/dev/null').read()) + if not res: + # Hm, this works only for libs needed by the python executable. + cmd = 'ldd %s 2>/dev/null' % sys.executable + res = re.search(expr, os.popen(cmd).read()) + if not res: + return None + return res.group(0) + + def _get_soname(f): + cmd = "objdump -p -j .dynamic 2>/dev/null " + f + res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read()) + if not res: + return None + return res.group(1) + + def find_library(name): + lib = _findLib_ld(name) or _findLib_gcc(name) + if not lib: + return None + return _get_soname(lib) + +################################################################ +# test code + +def test(): + from ctypes import cdll + if os.name == "nt": + sys.stdout.write('%s\n' % (cdll.msvcrt,)) + sys.stdout.write('%s\n' % (cdll.load("msvcrt"),)) + sys.stdout.write('%s\n' % (find_library("msvcrt"),)) + + if os.name == "posix": + # find and load_version + sys.stdout.write('%s\n' % (find_library("m"),)) + sys.stdout.write('%s\n' % (find_library("c"),)) + sys.stdout.write('%s\n' % (find_library("bz2"),)) + + # getattr +## print_ cdll.m +## print_ cdll.bz2 + + # load + if sys.platform == "darwin": + sys.stdout.write('%s\n' % (cdll.LoadLibrary("libm.dylib"),)) + sys.stdout.write('%s\n' % (cdll.LoadLibrary("libcrypto.dylib"),)) + sys.stdout.write('%s\n' % (cdll.LoadLibrary("libSystem.dylib"),)) + sys.stdout.write('%s\n' % (cdll.LoadLibrary("System.framework/System"),)) + else: + sys.stdout.write('%s\n' % (cdll.LoadLibrary("libm.so"),)) + sys.stdout.write('%s\n' % (cdll.LoadLibrary("libcrypt.so"),)) + sys.stdout.write('%s\n' % (find_library("crypt"),)) + +if __name__ == "__main__": + test() diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/wintypes.py b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/wintypes.py new file mode 100644 index 0000000..d31f11e --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/ctypes/wintypes.py @@ -0,0 +1,98 @@ +#@PydevCodeAnalysisIgnore +# XXX This module needs cleanup. + +from ctypes import * + +DWORD = c_ulong +WORD = c_ushort +BYTE = c_byte + +ULONG = c_ulong +LONG = c_long + +LARGE_INTEGER = c_longlong +ULARGE_INTEGER = c_ulonglong + + +HANDLE = c_ulong # in the header files: void * + +HWND = HANDLE +HDC = HANDLE +HMODULE = HANDLE +HINSTANCE = HANDLE +HRGN = HANDLE +HTASK = HANDLE +HKEY = HANDLE +HPEN = HANDLE +HGDIOBJ = HANDLE +HMENU = HANDLE + +LCID = DWORD + +WPARAM = c_uint +LPARAM = c_long + +BOOL = c_long +VARIANT_BOOL = c_short + +LPCOLESTR = LPOLESTR = OLESTR = c_wchar_p +LPCWSTR = LPWSTR = c_wchar_p + +LPCSTR = LPSTR = c_char_p + +class RECT(Structure): + _fields_ = [("left", c_long), + ("top", c_long), + ("right", c_long), + ("bottom", c_long)] +RECTL = RECT + +class POINT(Structure): + _fields_ = [("x", c_long), + ("y", c_long)] +POINTL = POINT + +class SIZE(Structure): + _fields_ = [("cx", c_long), + ("cy", c_long)] +SIZEL = SIZE + +def RGB(red, green, blue): + return red + (green << 8) + (blue << 16) + +class FILETIME(Structure): + _fields_ = [("dwLowDateTime", DWORD), + ("dwHighDateTime", DWORD)] + +class MSG(Structure): + _fields_ = [("hWnd", HWND), + ("message", c_uint), + ("wParam", WPARAM), + ("lParam", LPARAM), + ("time", DWORD), + ("pt", POINT)] +MAX_PATH = 260 + +class WIN32_FIND_DATAA(Structure): + _fields_ = [("dwFileAttributes", DWORD), + ("ftCreationTime", FILETIME), + ("ftLastAccessTime", FILETIME), + ("ftLastWriteTime", FILETIME), + ("nFileSizeHigh", DWORD), + ("nFileSizeLow", DWORD), + ("dwReserved0", DWORD), + ("dwReserved1", DWORD), + ("cFileName", c_char * MAX_PATH), + ("cAlternameFileName", c_char * 14)] + +class WIN32_FIND_DATAW(Structure): + _fields_ = [("dwFileAttributes", DWORD), + ("ftCreationTime", FILETIME), + ("ftLastAccessTime", FILETIME), + ("ftLastWriteTime", FILETIME), + ("nFileSizeHigh", DWORD), + ("nFileSizeLow", DWORD), + ("dwReserved0", DWORD), + ("dwReserved1", DWORD), + ("cFileName", c_wchar * MAX_PATH), + ("cAlternameFileName", c_wchar * 14)] diff --git a/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/not_in_default_pythonpath.txt b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/not_in_default_pythonpath.txt new file mode 100644 index 0000000..24084e9 --- /dev/null +++ b/adapter/python/ptvsd/_vendored/pydevd/third_party/wrapped_for_pydev/not_in_default_pythonpath.txt @@ -0,0 +1 @@ +The wrapped_for_pydev folder is not in the default pythonpath... (no __init__.py file) \ No newline at end of file diff --git a/adapter/python/ptvsd/_version.py b/adapter/python/ptvsd/_version.py new file mode 100644 index 0000000..957691f --- /dev/null +++ b/adapter/python/ptvsd/_version.py @@ -0,0 +1,522 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +# This file helps to compute a version number in source trees obtained from +# git-archive tarball (such as those provided by githubs download-from-tag +# feature). Distribution tarballs (built by setup.py sdist) and build +# directories (produced by setup.py build) will contain a much shorter file +# that just contains the computed version number. + +# Generated by versioneer-0.18 (https://github.com/warner/python-versioneer) + +"""Git implementation of _version.py.""" + +import errno +import os +import re +import subprocess +import sys + + +def get_keywords(): + """Get the keywords needed to look up the version information.""" + # these strings will be replaced by git during git-archive. + # setup.py/versioneer.py will grep for the variable names, so they must + # each be defined on a line of their own. _version.py will just call + # get_keywords(). + git_refnames = "$Format:%d$" + git_full = "$Format:%H$" + git_date = "$Format:%ci$" + keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} + return keywords + + +class VersioneerConfig: + """Container for Versioneer configuration parameters.""" + + +def get_config(): + """Create, populate and return the VersioneerConfig() object.""" + # these strings are filled in when 'setup.py versioneer' creates + # _version.py + cfg = VersioneerConfig() + cfg.VCS = "git" + cfg.style = "pep440" + cfg.tag_prefix = "v" + cfg.parentdir_prefix = "ptvsd-" + cfg.versionfile_source = "ptvsd/_version.py" + cfg.verbose = False + return cfg + + +class NotThisMethod(Exception): + """Exception raised if a method is not valid for the current scenario.""" + + +LONG_VERSION_PY = {} +HANDLERS = {} + + +def register_vcs_handler(vcs, method): # decorator + """Decorator to mark a method as the handler for a particular VCS.""" + def decorate(f): + """Store f in HANDLERS[vcs][method].""" + if vcs not in HANDLERS: + HANDLERS[vcs] = {} + HANDLERS[vcs][method] = f + return f + return decorate + + +def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, + env=None): + """Call the given command(s).""" + assert isinstance(commands, list) + p = None + for c in commands: + try: + dispcmd = str([c] + args) + # remember shell=False, so use git.cmd on windows, not just git + p = subprocess.Popen([c] + args, cwd=cwd, env=env, + stdout=subprocess.PIPE, + stderr=(subprocess.PIPE if hide_stderr + else None)) + break + except EnvironmentError: + e = sys.exc_info()[1] + if e.errno == errno.ENOENT: + continue + if verbose: + print("unable to run %s" % dispcmd) + print(e) + return None, None + else: + if verbose: + print("unable to find command, tried %s" % (commands,)) + return None, None + stdout = p.communicate()[0].strip() + if sys.version_info[0] >= 3: + stdout = stdout.decode() + if p.returncode != 0: + if verbose: + print("unable to run %s (error)" % dispcmd) + print("stdout was %s" % stdout) + return None, p.returncode + return stdout, p.returncode + + +def versions_from_parentdir(parentdir_prefix, root, verbose): + """Try to determine the version from the parent directory name. + + Source tarballs conventionally unpack into a directory that includes both + the project name and a version string. We will also support searching up + two directory levels for an appropriately named parent directory + """ + rootdirs = [] + + for i in range(3): + dirname = os.path.basename(root) + if dirname.startswith(parentdir_prefix): + return {"version": dirname[len(parentdir_prefix):], + "full-revisionid": None, + "dirty": False, "error": None, "date": None} + else: + rootdirs.append(root) + root = os.path.dirname(root) # up a level + + if verbose: + print("Tried directories %s but none started with prefix %s" % + (str(rootdirs), parentdir_prefix)) + raise NotThisMethod("rootdir doesn't start with parentdir_prefix") + + +@register_vcs_handler("git", "get_keywords") +def git_get_keywords(versionfile_abs): + """Extract version information from the given file.""" + # the code embedded in _version.py can just fetch the value of these + # keywords. When used from setup.py, we don't want to import _version.py, + # so we do it with a regexp instead. This function is not used from + # _version.py. + keywords = {} + try: + f = open(versionfile_abs, "r") + for line in f.readlines(): + if line.strip().startswith("git_refnames ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["refnames"] = mo.group(1) + if line.strip().startswith("git_full ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["full"] = mo.group(1) + if line.strip().startswith("git_date ="): + mo = re.search(r'=\s*"(.*)"', line) + if mo: + keywords["date"] = mo.group(1) + f.close() + except EnvironmentError: + pass + return keywords + + +@register_vcs_handler("git", "keywords") +def git_versions_from_keywords(keywords, tag_prefix, verbose): + """Get version information from git keywords.""" + if not keywords: + raise NotThisMethod("no keywords at all, weird") + date = keywords.get("date") + if date is not None: + # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant + # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 + # -like" string, which we must then edit to make compliant), because + # it's been around since git-1.5.3, and it's too difficult to + # discover which version we're using, or to work around using an + # older one. + date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + refnames = keywords["refnames"].strip() + if refnames.startswith("$Format"): + if verbose: + print("keywords are unexpanded, not using") + raise NotThisMethod("unexpanded keywords, not a git-archive tarball") + refs = set([r.strip() for r in refnames.strip("()").split(",")]) + # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of + # just "foo-1.0". If we see a "tag: " prefix, prefer those. + TAG = "tag: " + tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + if not tags: + # Either we're using git < 1.8.3, or there really are no tags. We use + # a heuristic: assume all version tags have a digit. The old git %d + # expansion behaves like git log --decorate=short and strips out the + # refs/heads/ and refs/tags/ prefixes that would let us distinguish + # between branches and tags. By ignoring refnames without digits, we + # filter out many common branch names like "release" and + # "stabilization", as well as "HEAD" and "master". + tags = set([r for r in refs if re.search(r'\d', r)]) + if verbose: + print("discarding '%s', no digits" % ",".join(refs - tags)) + if verbose: + print("likely tags: %s" % ",".join(sorted(tags))) + for ref in sorted(tags): + # sorting will prefer e.g. "2.0" over "2.0rc1" + if ref.startswith(tag_prefix): + r = ref[len(tag_prefix):] + if verbose: + print("picking %s" % r) + return {"version": r, + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": None, + "date": date} + # no suitable tags, so version is "0+unknown", but full hex is still there + if verbose: + print("no suitable tags, using unknown + full revision id") + return {"version": "0+unknown", + "full-revisionid": keywords["full"].strip(), + "dirty": False, "error": "no suitable tags", "date": None} + + +@register_vcs_handler("git", "pieces_from_vcs") +def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): + """Get version from 'git describe' in the root of the source tree. + + This only gets called if the git-archive 'subst' keywords were *not* + expanded, and _version.py hasn't already been rewritten with a short + version string, meaning we're inside a checked out source tree. + """ + GITS = ["git"] + if sys.platform == "win32": + GITS = ["git.cmd", "git.exe"] + + out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, + hide_stderr=True) + if rc != 0: + if verbose: + print("Directory %s not under git control" % root) + raise NotThisMethod("'git rev-parse --git-dir' returned error") + + # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] + # if there isn't one, this yields HEX[-dirty] (no NUM) + describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", + "--always", "--long", + "--match", "%s*" % tag_prefix], + cwd=root) + # --long was added in git-1.5.5 + if describe_out is None: + raise NotThisMethod("'git describe' failed") + describe_out = describe_out.strip() + full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) + if full_out is None: + raise NotThisMethod("'git rev-parse' failed") + full_out = full_out.strip() + + pieces = {} + pieces["long"] = full_out + pieces["short"] = full_out[:7] # maybe improved later + pieces["error"] = None + + # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] + # TAG might have hyphens. + git_describe = describe_out + + # look for -dirty suffix + dirty = git_describe.endswith("-dirty") + pieces["dirty"] = dirty + if dirty: + git_describe = git_describe[:git_describe.rindex("-dirty")] + + # now we have TAG-NUM-gHEX or HEX + + if "-" in git_describe: + # TAG-NUM-gHEX + mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) + if not mo: + # unparseable. Maybe git-describe is misbehaving? + pieces["error"] = ("unable to parse git-describe output: '%s'" + % describe_out) + return pieces + + # tag + full_tag = mo.group(1) + if not full_tag.startswith(tag_prefix): + if verbose: + fmt = "tag '%s' doesn't start with prefix '%s'" + print(fmt % (full_tag, tag_prefix)) + pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" + % (full_tag, tag_prefix)) + return pieces + pieces["closest-tag"] = full_tag[len(tag_prefix):] + + # distance: number of commits since tag + pieces["distance"] = int(mo.group(2)) + + # commit: short hex revision ID + pieces["short"] = mo.group(3) + + else: + # HEX: no tags + pieces["closest-tag"] = None + count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], + cwd=root) + pieces["distance"] = int(count_out) # total number of commits + + # commit date: see ISO-8601 comment in git_versions_from_keywords() + date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], + cwd=root)[0].strip() + pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) + + return pieces + + +def plus_or_dot(pieces): + """Return a + if we don't already have one, else return a .""" + if "+" in pieces.get("closest-tag", ""): + return "." + return "+" + + +def render_pep440(pieces): + """Build up version string, with post-release "local version identifier". + + Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you + get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty + + Exceptions: + 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += plus_or_dot(pieces) + rendered += "%d.g%s" % (pieces["distance"], pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + else: + # exception #1 + rendered = "0+untagged.%d.g%s" % (pieces["distance"], + pieces["short"]) + if pieces["dirty"]: + rendered += ".dirty" + return rendered + + +def render_pep440_pre(pieces): + """TAG[.post.devDISTANCE] -- No -dirty. + + Exceptions: + 1: no tags. 0.post.devDISTANCE + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += ".post.dev%d" % pieces["distance"] + else: + # exception #1 + rendered = "0.post.dev%d" % pieces["distance"] + return rendered + + +def render_pep440_post(pieces): + """TAG[.postDISTANCE[.dev0]+gHEX] . + + The ".dev0" means dirty. Note that .dev0 sorts backwards + (a dirty tree will appear "older" than the corresponding clean one), + but you shouldn't be releasing software with -dirty anyways. + + Exceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += plus_or_dot(pieces) + rendered += "g%s" % pieces["short"] + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + rendered += "+g%s" % pieces["short"] + return rendered + + +def render_pep440_old(pieces): + """TAG[.postDISTANCE[.dev0]] . + + The ".dev0" means dirty. + + Eexceptions: + 1: no tags. 0.postDISTANCE[.dev0] + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"] or pieces["dirty"]: + rendered += ".post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + else: + # exception #1 + rendered = "0.post%d" % pieces["distance"] + if pieces["dirty"]: + rendered += ".dev0" + return rendered + + +def render_git_describe(pieces): + """TAG[-DISTANCE-gHEX][-dirty]. + + Like 'git describe --tags --dirty --always'. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + if pieces["distance"]: + rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render_git_describe_long(pieces): + """TAG-DISTANCE-gHEX[-dirty]. + + Like 'git describe --tags --dirty --always -long'. + The distance/hash is unconditional. + + Exceptions: + 1: no tags. HEX[-dirty] (note: no 'g' prefix) + """ + if pieces["closest-tag"]: + rendered = pieces["closest-tag"] + rendered += "-%d-g%s" % (pieces["distance"], pieces["short"]) + else: + # exception #1 + rendered = pieces["short"] + if pieces["dirty"]: + rendered += "-dirty" + return rendered + + +def render(pieces, style): + """Render the given version pieces into the requested style.""" + if pieces["error"]: + return {"version": "unknown", + "full-revisionid": pieces.get("long"), + "dirty": None, + "error": pieces["error"], + "date": None} + + if not style or style == "default": + style = "pep440" # the default + + if style == "pep440": + rendered = render_pep440(pieces) + elif style == "pep440-pre": + rendered = render_pep440_pre(pieces) + elif style == "pep440-post": + rendered = render_pep440_post(pieces) + elif style == "pep440-old": + rendered = render_pep440_old(pieces) + elif style == "git-describe": + rendered = render_git_describe(pieces) + elif style == "git-describe-long": + rendered = render_git_describe_long(pieces) + else: + raise ValueError("unknown style '%s'" % style) + + return {"version": rendered, "full-revisionid": pieces["long"], + "dirty": pieces["dirty"], "error": None, + "date": pieces.get("date")} + + +def get_versions(): + """Get version information or return default if unable to do so.""" + # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have + # __file__, we can work backwards from there to the root. Some + # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which + # case we can only use expanded keywords. + + cfg = get_config() + verbose = cfg.verbose + + try: + return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, + verbose) + except NotThisMethod: + pass + + try: + root = os.path.realpath(__file__) + # versionfile_source is the relative path from the top of the source + # tree (where the .git directory might live) to this file. Invert + # this to find the root from __file__. + for i in cfg.versionfile_source.split('/'): + root = os.path.dirname(root) + except NameError: + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, + "error": "unable to find root of source tree", + "date": None} + + try: + pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose) + return render(pieces, cfg.style) + except NotThisMethod: + pass + + try: + if cfg.parentdir_prefix: + return versions_from_parentdir(cfg.parentdir_prefix, root, verbose) + except NotThisMethod: + pass + + return {"version": "0+unknown", "full-revisionid": None, + "dirty": None, + "error": "unable to compute version", "date": None} diff --git a/adapter/python/ptvsd/attach_script_ptvsd_pid.py b/adapter/python/ptvsd/attach_script_ptvsd_pid.py new file mode 100644 index 0000000..2e8e484 --- /dev/null +++ b/adapter/python/ptvsd/attach_script_ptvsd_pid.py @@ -0,0 +1,58 @@ + + +def attach(port, host, client, log_dir): + try: + import sys + if 'threading' not in sys.modules: + try: + + def on_warn(msg): + import ptvsd.log + ptvsd.log.warn(msg) + + def on_exception(msg): + import ptvsd.log + ptvsd.log.exception(msg) + + def on_critical(msg): + import ptvsd.log + ptvsd.log.error(msg) + + import os + sys.path.append( + os.path.join( + os.path.dirname(__file__), + '_vendored', + 'pydevd', + 'pydevd_attach_to_process')) + + # Note that it's not a part of the pydevd PYTHONPATH + import attach_script + attach_script.fix_main_thread_id( + on_warn=on_warn, on_exception=on_exception, on_critical=on_critical) + except: + import ptvsd.log + ptvsd.log.exception() + + if not log_dir: + log_dir = None + + import ptvsd.options + ptvsd.options.log_dir = log_dir + ptvsd.options.client = client + ptvsd.options.host = host + ptvsd.options.port = port + + import ptvsd.log + ptvsd.log.to_file() + ptvsd.log.info("Debugger successfully injected") + + if ptvsd.options.client: + from ptvsd._remote import attach + attach((host, port)) + else: + ptvsd.enable_attach((host, port)) + + except: + import traceback + traceback.print_exc() diff --git a/adapter/python/ptvsd/attach_server.py b/adapter/python/ptvsd/attach_server.py new file mode 100644 index 0000000..147d781 --- /dev/null +++ b/adapter/python/ptvsd/attach_server.py @@ -0,0 +1,188 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import sys +import warnings + +import ptvsd.log +from ptvsd._remote import ( + attach as ptvsd_attach, + enable_attach as ptvsd_enable_attach, +) +from ptvsd.wrapper import debugger_attached + +import pydevd +from _pydevd_bundle.pydevd_constants import get_global_debugger + +WAIT_TIMEOUT = 1.0 + +DEFAULT_HOST = '0.0.0.0' +DEFAULT_PORT = 5678 + +_pending_threads = set() + +_redirect_output_deprecation_msg = ( + "'redirect_output' setting via enable_attach will be deprecated in the future versions of the debugger. " + "This can be set using redirectOutput in Launch config in VS Code, using Tee output option in Visual Studio, " + "or debugOptions configuration for any client.") + + +def wait_for_attach(timeout=None): + """If a remote debugger is attached, returns immediately. Otherwise, + blocks until a remote debugger attaches to this process, or until the + optional timeout occurs. + + Parameters + ---------- + timeout : float, optional + The timeout for the operation in seconds (or fractions thereof). + """ + ptvsd.log.info('wait_for_attach{0!r}', (timeout,)) + debugger_attached.wait(timeout) + + +def enable_attach(address=(DEFAULT_HOST, DEFAULT_PORT), redirect_output=None, log_dir=None): + """Enables a client to attach to this process remotely to debug Python code. + + Parameters + ---------- + address : (str, int), optional + Specifies the interface and port on which the debugging server should + listen for TCP connections. It is in the same format as used for + regular sockets of the `socket.AF_INET` family, i.e. a tuple of + ``(hostname, port)``. On client side, the server is identified by the + Qualifier string in the usual ``'hostname:port'`` format, e.g.: + ``'myhost.cloudapp.net:5678'``. Default is ``('0.0.0.0', 5678)``. + redirect_output : bool, optional + (Deprecated) Specifies whether any output (on both `stdout` and `stderr`) produced + by this program should be sent to the debugger. Default is ``True``. + log_dir : str, optional + Name of the directory that debugger will create its log files in. + If not specified, logging is disabled. + + Return + ------ + Returns tuple (host, port) as used to by the debugging server. If `enable_attach` was + called with port '0'. The return value will contain the actual ephemeral port number. + + Notes + ----- + This function returns immediately after setting up the debugging server, + and does not block program execution. If you need to block until debugger + is attached, call `ptvsd.wait_for_attach`. The debugger can be detached + and re-attached multiple times after `enable_attach` is called. + + Only the thread on which this function is called, and any threads that are + created after it returns, will be visible in the debugger once it is + attached. Any threads that are already running before this function is + called will not be visible. + """ + + if log_dir: + ptvsd.options.log_dir = log_dir + ptvsd.log.to_file() + ptvsd.log.info('enable_attach{0!r}', (address, redirect_output)) + + if redirect_output is not None: + ptvsd.log.info('redirect_output deprecation warning.') + warnings.warn(_redirect_output_deprecation_msg, DeprecationWarning, stacklevel=2) + + if is_attached(): + ptvsd.log.info('enable_attach() ignored - already attached.') + return + + debugger_attached.clear() + + # Ensure port is int + port = address[1] + address = (address[0], port if type(port) is int else int(port)) + + ptvsd_enable_attach(address) + return (address[0], ptvsd.options.port) + + +def attach(address, redirect_output=None, log_dir=None): + """Attaches this process to the debugger listening on a given address. + + Parameters + ---------- + address : (str, int), optional + Specifies the interface and port on which the debugger is listening + for TCP connections. It is in the same format as used for + regular sockets of the `socket.AF_INET` family, i.e. a tuple of + ``(hostname, port)``. + redirect_output : bool, optional + (Deprecated) Specifies whether any output (on both `stdout` and `stderr`) produced + by this program should be sent to the debugger. Default is ``True``. + log_dir : str, optional + Name of the directory that debugger will create its log files in. + If not specified, logging is disabled. + """ + + if log_dir: + ptvsd.options.log_dir = log_dir + ptvsd.log.to_file() + ptvsd.log.info('attach{0!r}', (address, redirect_output)) + + if redirect_output is not None: + ptvsd.log.info('redirect_output deprecation warning.') + warnings.warn(_redirect_output_deprecation_msg, DeprecationWarning) + + if is_attached(): + ptvsd.log.info('attach() ignored - already attached.') + return + + debugger_attached.clear() + + # Ensure port is int + port = address[1] + address = (address[0], port if type(port) is int else int(port)) + + ptvsd_attach(address) + + +def is_attached(): + """Returns ``True`` if debugger is attached, ``False`` otherwise.""" + return debugger_attached.isSet() + + +def break_into_debugger(): + """If a remote debugger is attached, pauses execution of all threads, + and breaks into the debugger with current thread as active. + """ + + ptvsd.log.info('break_into_debugger()') + + if not is_attached(): + ptvsd.log.info('break_into_debugger() ignored - debugger not attached') + return + + # Get the first frame in the stack that's not an internal frame. + global_debugger = get_global_debugger() + stop_at_frame = sys._getframe().f_back + while stop_at_frame is not None and global_debugger.get_file_type( + stop_at_frame) == global_debugger.PYDEV_FILE: + stop_at_frame = stop_at_frame.f_back + + # pydevd.settrace() only enables debugging of the current + # thread and all future threads. PyDevd is not enabled for + # existing threads (other than the current one). Consequently, + # pydevd.settrace() must be called ASAP in the current thread. + # See issue #509. + # + # This is tricky, however, because settrace() will block until + # it receives a CMD_RUN message. You can't just call it in a + # thread to avoid blocking; doing so would prevent the current + # thread from being debugged. + pydevd.settrace( + suspend=True, + trace_only_current_thread=True, + patch_multiprocessing=False, + stop_at_frame=stop_at_frame, + ) + stop_at_frame = None + + +def debug_this_thread(): + pydevd.settrace(suspend=False) diff --git a/adapter/python/ptvsd/compat.py b/adapter/python/ptvsd/compat.py new file mode 100644 index 0000000..b19aa0b --- /dev/null +++ b/adapter/python/ptvsd/compat.py @@ -0,0 +1,28 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + + +# Python 2.x/3.x compatibility helpers + +try: + import builtins +except ImportError: + import __builtin__ as builtins # noqa + +try: + import queue +except ImportError: + import Queue as queue # noqa + +try: + unicode = builtins.unicode + bytes = builtins.str +except AttributeError: + unicode = builtins.str + bytes = builtins.bytes + +try: + xrange = builtins.xrange +except AttributeError: + xrange = builtins.range diff --git a/adapter/python/ptvsd/daemon.py b/adapter/python/ptvsd/daemon.py new file mode 100644 index 0000000..abdcf6c --- /dev/null +++ b/adapter/python/ptvsd/daemon.py @@ -0,0 +1,560 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import contextlib +import sys +import threading + +import ptvsd.log +from ptvsd import wrapper, options, multiproc +from ptvsd.socket import ( + close_socket, create_server, create_client, connect, Address) +from .exit_handlers import ( + ExitHandlers, UnsupportedSignalError, + kill_current_proc) +from .session import PyDevdDebugSession +from ._util import ( + ClosedError, NotRunningError, ignore_errors, lock_wait) + + +session_not_bound = threading.Event() +session_not_bound.set() + + +def _wait_for_user(): + if sys.__stdout__ is not None: + try: + import msvcrt + except ImportError: + sys.__stdout__.write('Press Enter to continue . . . ') + sys.__stdout__.flush() + sys.__stdin__.read(1) + else: + sys.__stdout__.write('Press any key to continue . . . ') + sys.__stdout__.flush() + msvcrt.getch() + + +class DaemonError(RuntimeError): + """Indicates that a Daemon had a problem.""" + MSG = 'error' + + def __init__(self, msg=None): + if msg is None: + msg = self.MSG + super(DaemonError, self).__init__(msg) + + +class DaemonClosedError(DaemonError): + """Indicates that a Daemon was unexpectedly closed.""" + MSG = 'closed' + + +class DaemonStoppedError(DaemonError): + """Indicates that a Daemon was unexpectedly stopped.""" + MSG = 'stopped' + + +# TODO: Inherit from Closeable. +# TODO: Inherit from Startable? + +class DaemonBase(object): + """The base class for DAP daemons.""" + + SESSION = None + + exitcode = None + + def __init__(self, wait_for_user=_wait_for_user, + addhandlers=True, killonclose=True, + singlesession=False): + + self._lock = threading.Lock() + self._started = False + self._stopped = False + self._closed = False + + # socket-related + + self._sock = None # set when started + self._server = None + + # session-related + + self._singlesession = singlesession + + self._session = None + self._numsessions = 0 + self._sessionlock = None + + # proc-related + + self._wait_for_user = wait_for_user + self._killonclose = killonclose + + self._exiting_via_atexit_handler = False + + self._exithandlers = ExitHandlers() + if addhandlers: + self._install_exit_handlers() + + @property + def session(self): + """The current session.""" + return self._session + + @contextlib.contextmanager + def started(self): + """A context manager that starts the daemon and stops it for errors.""" + self.start() + try: + yield self + except Exception: + self._stop_quietly() + raise + + @contextlib.contextmanager + def running(self): + """A context manager that starts the daemon. + + If there's a failure then the daemon is stopped. It is also + stopped at the end of the with block. + """ + self.start() + try: + yield self + finally: + self._stop_quietly() + + def is_running(self): + """Return True if the daemon is running.""" + with self._lock: + if self._closed: + return False + if self._sock is None: + return False + return self._started and not self._stopped + + def start(self): + """Return the "socket" to use for pydevd after setting it up.""" + with self._lock: + if self._closed: + raise DaemonClosedError() + if self._started: + raise RuntimeError('already started') + self._started = True + + sock = self._start() + self._sock = sock + return sock + + def start_server(self, addr, hidebadsessions=True): + """Return ("socket", next_session) with a new server socket.""" + + ptvsd.log.debug('Starting server daemon on {0!r}.', addr) + + addr = Address.from_raw(addr) + with self.started(): + assert self._sessionlock is None + assert self.session is None + self._server = create_server(addr.host, addr.port) + host, port = self._server.getsockname() + ptvsd.log.debug('Server socket created on {0!r}', addr) + self._sessionlock = threading.Lock() + sock = self._sock + + def check_ready(**kwargs): + self._check_ready_for_session(**kwargs) + if self._server is None: + raise DaemonStoppedError() + + def next_session(timeout=None, **kwargs): + server = self._server + sessionlock = self._sessionlock + check_ready(checksession=False) + + ptvsd.log.debug('Getting next session...') + sessionlock.acquire() # Released in _finish_session(). + ptvsd.log.debug('Session lock acquired.') + # It may have closed or stopped while we waited. + check_ready() + + timeout = kwargs.pop('timeout', None) + try: + ptvsd.log.debug('Getting session socket...') + client = connect(server, None, **kwargs) + self._bind_session(client) + ptvsd.log.debug('Starting session...') + self._start_session_safely('ptvsd.Server', timeout=timeout) + ptvsd.log.debug('Session started.') + return self._session + except Exception: + ptvsd.log.exception(category=('D' if hidebadsessions else 'E')) + with ignore_errors(): + self._finish_session() + if hidebadsessions: + ptvsd.log.debug('Hiding bad session') + return None + self._stop_quietly() + raise + + if options.subprocess_notify: + multiproc.notify_root(port) + + return sock, next_session + + def start_client(self, addr): + """Return ("socket", start_session) with a new client socket.""" + + ptvsd.log.debug('Starting client daemon on {0!r}.', addr) + + addr = Address.from_raw(addr) + self._singlesession = True + with self.started(): + assert self.session is None + client = create_client() + connect(client, addr) + sock = self._sock + + def start_session(**kwargs): + self._check_ready_for_session() + if self._server is not None: + raise RuntimeError('running as server') + if self._numsessions: + raise RuntimeError('session stopped') + + try: + self._bind_session(client) + self._start_session_safely('ptvsd.Client', **kwargs) + return self._session + except Exception: + self._stop_quietly() + raise + + return sock, start_session + + def start_session(self, session, threadname, **kwargs): + """Start the debug session and remember it. + + If "session" is a client socket then a session is created + from it. + """ + + ptvsd.log.debug('Starting session.') + + self._check_ready_for_session() + if self._server is not None: + raise RuntimeError('running as server') + + self._bind_session(session) + self._start_session_safely(threadname, **kwargs) + return self.session + + def close(self): + """Stop all loops and release all resources.""" + + ptvsd.log.debug('Stopping daemon.') + + with self._lock: + if self._closed: + raise DaemonClosedError('already closed') + self._closed = True + + self._close() + + # internal methods + + def _check_ready_for_session(self, checksession=True): + with self._lock: + if self._closed: + raise DaemonClosedError() + if not self._started: + raise DaemonStoppedError('never started') + if self._stopped or self._sock is None: + raise DaemonStoppedError() + if checksession and self.session is not None: + raise RuntimeError('session already started') + + def _close(self): + self._stop() + + self._sock = None + + def _stop(self): + with self._lock: + if self._stopped: + return + self._stopped = True + + server = self._server + self._server = None + + with ignore_errors(): + self._finish_session() + + self._sessionlock = None # TODO: Call self._clear_sessionlock? + + # TODO: Close the server socket *before* finish the session? + if server is not None: + with ignore_errors(): + close_socket(server) + + # TODO: Close self._sock *before* finishing the session? + if self._sock is not None: + with ignore_errors(): + close_socket(self._sock) + + def _stop_quietly(self): + with ignore_errors(): + self._stop() + + def _handle_session_disconnecting(self, session): + ptvsd.log.debug('Handling disconnecting session') + if self._singlesession: + if self._killonclose: + with self._lock: + if not self._exiting_via_atexit_handler: + # Ensure the proc is exiting before closing + # socket. Note that we kill the proc instead + # of calling sys.exit(0). + # Note that this will trigger either the atexit + # handler or the signal handler. + kill_current_proc() + else: + try: + self.close() + except DaemonClosedError: + pass + + def _handle_session_closing(self, session): + ptvsd.log.debug('Handling closing session') + + if self._singlesession: + if self._killonclose: + with self._lock: + if not self._exiting_via_atexit_handler: + # Ensure the proc is exiting before closing + # socket. Note that we kill the proc instead + # of calling sys.exit(0). + # Note that this will trigger either the atexit + # handler or the signal handler. + kill_current_proc() + else: + try: + self.close() + except DaemonClosedError: + pass + else: + self._finish_session() + + def _clear_sessionlock(self, done=False): + sessionlock = self._sessionlock + if done: + self._sessionlock = None + if sessionlock is not None: + try: + sessionlock.release() + except Exception: # TODO: Make it more specific? + ptvsd.log.exception('Session lock not released', category='D') + else: + ptvsd.log.debug('Session lock released') + + # internal session-related methods + + def _bind_session(self, session): + session_not_bound.clear() + # TODO: Pass notify_* to session.start() instead. + session = self.SESSION.from_raw( + session, + notify_closing=self._handle_session_closing, + notify_disconnecting=self._handle_session_disconnecting, + ownsock=True, + **self._session_kwargs() or {} + ) + self._session = session + self._numsessions += 1 + + def _start_session_safely(self, threadname, **kwargs): + try: + self._start_session(threadname, **kwargs) + except Exception: + ptvsd.log.exception() + with ignore_errors(): + self._finish_session() + raise + + def _finish_session(self): + self._numsessions -= 1 + session_not_bound.set() + try: + session = self._release_session() + ptvsd.log.debug('Session stopped') + finally: + self._clear_sessionlock() + + if self._singlesession: + ptvsd.log.debug('Closing daemon after single session') + try: + self.close() + except DaemonClosedError: + pass + return session + + def _release_session(self): + session = self.session + if not self._singlesession: + # TODO: This shouldn't happen if we are exiting? + self._session = None + + try: + session.stop() + except NotRunningError: + pass + try: + session.close() + except ClosedError: + pass + + return session + + # internal proc-related methods + + def _install_exit_handlers(self): + """Set the placeholder handlers.""" + self._exithandlers.install() + + try: + self._exithandlers.add_atexit_handler(self._handle_atexit) + except ValueError: + pass + for signum in self._exithandlers.SIGNALS: + try: + self._exithandlers.add_signal_handler(signum, + self._handle_signal) + except ValueError: + # Already added. + pass + except UnsupportedSignalError: + # TODO: This shouldn't happen. + pass + + def _handle_atexit(self): + ptvsd.log.debug('Handling atexit') + with self._lock: + self._exiting_via_atexit_handler = True + session = self.session + + if session is not None: + lock = threading.Lock() + lock.acquire() + + def wait_debugger(timeout=None): + lock_wait(lock, timeout) + + def wait_exiting(cfg): + if cfg: + self._wait_for_user() + lock.release() + # TODO: Rely on self._stop_debugger(). + session.handle_debugger_stopped(wait_debugger) + session.handle_exiting(self.exitcode, wait_exiting) + + try: + self.close() + except DaemonClosedError: + pass + if session is not None: + session.wait_until_stopped() + + def _handle_signal(self, signum, frame): + ptvsd.log.debug('Handling signal') + try: + self.close() + except DaemonClosedError: + pass + if not self._exiting_via_atexit_handler: + sys.exit(0) + + # methods for subclasses to override + + def _start(self): + """Return the debugger client socket after starting the daemon.""" + raise NotImplementedError + + def _start_session(self, threadname, **kwargs): + self.session.start( + threadname, + **kwargs + ) + + def _session_kwargs(self): + return None + + +class Daemon(DaemonBase): + """The process-level manager for the VSC protocol debug adapter.""" + + SESSION = PyDevdDebugSession + + def __init__(self, wait_for_user=_wait_for_user, + notify_session_debugger_ready=None, + **kwargs): + super(Daemon, self).__init__(wait_for_user, **kwargs) + + self._notify_session_debugger_ready = notify_session_debugger_ready + + @property + def pydevd(self): + return self._sock + + # internal methods + + def _start(self): + return wrapper.PydevdSocket( + self._handle_pydevd_message, + self._handle_pydevd_close, + self._getpeername, + self._getsockname, + ) + + def _start_session(self, threadname, **kwargs): + super(Daemon, self)._start_session( + threadname, + pydevd_notify=self.pydevd.pydevd_notify, + pydevd_request=self.pydevd.pydevd_request, + **kwargs + ) + + def _session_kwargs(self): + def debugger_ready(session): + if self._notify_session_debugger_ready is not None: + self._notify_session_debugger_ready(session) + + return dict( + notify_debugger_ready=debugger_ready, + ) + + # internal methods for PyDevdSocket(). + + def _handle_pydevd_message(self, cmdid, seq, text): + if self.session is None or self.session.closed: + # TODO: Do more than ignore? + return + self.session.handle_pydevd_message(cmdid, seq, text) + + def _handle_pydevd_close(self): + try: + self.close() + except DaemonClosedError: + pass + + def _getpeername(self): + if self.session is None or self.session.closed: + raise NotImplementedError + return self.session.socket.getpeername() + + def _getsockname(self): + if self.session is None or self.session.closed: + raise NotImplementedError + return self.session.socket.getsockname() diff --git a/adapter/python/ptvsd/debugger.py b/adapter/python/ptvsd/debugger.py new file mode 100644 index 0000000..5355ee0 --- /dev/null +++ b/adapter/python/ptvsd/debugger.py @@ -0,0 +1,39 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import ptvsd.log +import ptvsd.options +from ptvsd.__main__ import run_file, run_module, run_code + + +RUNNERS = { + 'module': run_module, + 'script': run_file, + 'code': run_code, +} + +# Not actually used, but VS will try to add entries to it. +DONT_DEBUG = [] + + +# A legacy entrypoint for Visual Studio, to allow older versions to work with new ptvsd. +# All new code should use the entrypoints in __main__ directly. +def debug(filename, port_num, debug_id, debug_options, run_as): + ptvsd.log.to_file() + ptvsd.log.info('debug{0!r}', (filename, port_num, debug_id, debug_options, run_as)) + + try: + run = RUNNERS[run_as] + except KeyError: + raise ValueError('run_as must be one of: {0!r}'.format(tuple(RUNNERS.keys()))) + + ptvsd.options.target_kind = 'file' if run_as == 'script' else run_as + ptvsd.options.target = filename + ptvsd.options.port = port_num + ptvsd.options.client = True + + # debug_id is ignored because it has no meaning in DAP. + # debug_options are ignored, because they will be passed later via DAP "launch" request. + + run() diff --git a/adapter/python/ptvsd/exit_handlers.py b/adapter/python/ptvsd/exit_handlers.py new file mode 100644 index 0000000..3ca9631 --- /dev/null +++ b/adapter/python/ptvsd/exit_handlers.py @@ -0,0 +1,118 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import atexit +import os +import platform +import signal + + +class AlreadyInstalledError(RuntimeError): + """Exit handlers were already installed.""" + + +class UnsupportedSignalError(RuntimeError): + """A signal is not supported.""" + + +def kill_current_proc(signum=signal.SIGTERM): + """Kill the current process. + + Note that this directly kills the process (with SIGTERM, by default) + rather than using sys.exit(). + """ + os.kill(os.getpid(), signum) + + +class ExitHandlers(object): + """Manages signal and atexit handlers.""" + + if platform.system() == 'Windows' or not hasattr(signal, 'SIGHUP'): + # TODO: Windows *does* support these signals: + # SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, SIGBREAK + SIGNALS = [] + else: + SIGNALS = [ + signal.SIGHUP, + ] + + def __init__(self): + self._signal_handlers = {sig: [] + for sig in self.SIGNALS} + self._atexit_handlers = [] + self._installed = False + + @property + def supported_signals(self): + return set(self.SIGNALS) + + @property + def installed(self): + return self._installed + + def install(self): + """Set the parent handlers. + + This must be called in the main thread. + """ + if self._installed: + raise AlreadyInstalledError('exit handlers already installed') + self._installed = True + self._install_signal_handler() + self._install_atexit_handler() + + # TODO: Add uninstall()? + + def add_atexit_handler(self, handle_atexit, nodupe=True): + """Add an atexit handler to the list managed here.""" + if nodupe and handle_atexit in self._atexit_handlers: + raise ValueError('atexit handler alraedy added') + self._atexit_handlers.append(handle_atexit) + + def add_signal_handler(self, signum, handle_signal, nodupe=True, + ignoreunsupported=False): + """Add a signal handler to the list managed here.""" + # TODO: The initialization of self.SIGNALS should make this + # special-casing unnecessary. + if platform.system() == 'Windows': + return + + try: + handlers = self._signal_handlers[signum] + except KeyError: + if ignoreunsupported: + return + raise UnsupportedSignalError(signum) + if nodupe and handle_signal in handlers: + raise ValueError('signal handler alraedy added') + handlers.append(handle_signal) + + # internal methods + + def _install_signal_handler(self): + # TODO: The initialization of self.SIGNALS should make this + # special-casing unnecessary. + if platform.system() == 'Windows': + return + + orig = {} + try: + for sig in self._signal_handlers: + # TODO: Skip or fail if signal.getsignal() returns None? + orig[sig] = signal.signal(sig, self._signal_handler) + except ValueError: + # Wasn't called in main thread! + raise + + def _signal_handler(self, signum, frame): + for handle_signal in self._signal_handlers.get(signum, ()): + handle_signal(signum, frame) + + def _install_atexit_handler(self): + self._atexit_handlers = [] + atexit.register(self._atexit_handler) + + def _atexit_handler(self): + for handle_atexit in self._atexit_handlers: + handle_atexit() diff --git a/adapter/python/ptvsd/futures.py b/adapter/python/ptvsd/futures.py new file mode 100644 index 0000000..5f17d03 --- /dev/null +++ b/adapter/python/ptvsd/futures.py @@ -0,0 +1,202 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, with_statement, absolute_import + +import sys +import threading +import traceback + +import ptvsd.log +from ptvsd.reraise import reraise + + +class Future(object): + # TODO: docstring + + def __init__(self, loop): + self._lock = threading.Lock() + self._loop = loop + self._done = None + self._observed = False + self._done_callbacks = [] + self._exc_info = None + self._handling = ptvsd.log.current_handler() + + # It's expensive, so only capture the origin if logging is enabled. + if ptvsd.log.is_enabled(): + self._origin = traceback.extract_stack() + else: + self._origin = None + + def __del__(self): + # Do not run any checks if Python is shutting down. + if not sys or not self._lock: + return + + with self._lock: + assert self._done or self._done is None + exc_info = self._exc_info + if exc_info and not self._observed: + msg = 'Unobserved failed future' + origin = self._origin + if origin: + origin = '\n'.join(traceback.format_list(origin)) + msg += ' originating from:\n\n{origin}\n\n' + ptvsd.log.exception(msg, origin=origin, exc_info=exc_info) + traceback.print_exception(*exc_info, file=sys.__stderr__) + + def result(self): + # TODO: docstring + with self._lock: + self._observed = True + if self._exc_info: + reraise(self._exc_info) + return self._result + + def exc_info(self): + # TODO: docstring + with self._lock: + self._observed = True + return self._exc_info + + def set_result(self, result): + # TODO: docstring + with self._lock: + self._result = result + self._exc_info = None + self._done = True + callbacks = list(self._done_callbacks) + + def invoke_callbacks(): + for cb in callbacks: + cb(self) + + self._loop.call_soon(invoke_callbacks) + + def set_exc_info(self, exc_info): + # TODO: docstring + with self._lock: + self._exc_info = exc_info + self._done = True + callbacks = list(self._done_callbacks) + + def invoke_callbacks(): + for cb in callbacks: + cb(self) + + self._loop.call_soon(invoke_callbacks) + + def add_done_callback(self, callback): + # TODO: docstring + with self._lock: + done = self._done + self._done_callbacks.append(callback) + if done: + self._loop.call_soon(lambda: callback(self)) + + def remove_done_callback(self, callback): + # TODO: docstring + with self._lock: + self._done_callbacks.remove(callback) + + +class EventLoop(object): + # TODO: docstring + + def __init__(self): + self._queue = [] + self._lock = threading.Lock() + self._event = threading.Event() + self._event.set() + + self._stop = False + + def create_future(self): + return Future(self) + + def run_forever(self): + try: + while not self._stop: + if not self._event.wait(timeout=0.1): + continue + with self._lock: + queue = self._queue + self._queue = [] + self._event.clear() + for (f, args) in queue: + f(*args) + except: + if sys is None or traceback is None: + # Errors during shutdown are expected as this is a daemon thread, + # so just silence it. We can't even log it at this point. + pass + else: + # Try to log it, but guard against the possibility of shutdown + # in the middle of it. + try: + ptvsd.log.exception('Exception escaped to event loop') + except: + pass + + def stop(self): + self._stop = True + + def call_soon(self, f, *args): + with self._lock: + self._queue.append((f, args)) + self._event.set() + + def call_soon_threadsafe(self, f, *args): + return self.call_soon(f, *args) + + +class Result(object): + # TODO: docstring + + __slots__ = ['value'] + + def __init__(self, value): + self.value = value + + +def wrap_async(f): + def g(self, loop, *args, **kwargs): + it = f(self, *args, **kwargs) + result = Future(loop) + if it is None: + result.set_result(None) + return result + + async_handler = ptvsd.log.current_handler() + + def resume(fut): + try: + if fut is None: + x = next(it) + else: + exc_info = fut.exc_info() + if exc_info: + x = it.throw(*exc_info) + else: + x = it.send(fut.result()) + except AssertionError: + raise + except StopIteration: + result.set_result(None) + except: + result.set_exc_info(sys.exc_info()) + else: + if isinstance(x, Result): + result.set_result(x.value) + else: + def callback(fut): + with ptvsd.log.handling(async_handler): + resume(fut) + x.add_done_callback(callback) + + resume(None) + return result + + return g diff --git a/adapter/python/ptvsd/ipcjson.py b/adapter/python/ptvsd/ipcjson.py new file mode 100644 index 0000000..b4a0bef --- /dev/null +++ b/adapter/python/ptvsd/ipcjson.py @@ -0,0 +1,340 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, with_statement, absolute_import + +import errno +import itertools +import json +import os +import os.path +from socket import create_connection +import sys +import time +import threading +import traceback + +import ptvsd.log +from ptvsd.socket import TimeoutError, convert_eof + + +SKIP_TB_PREFIXES = [ + os.path.normcase( + os.path.dirname( + os.path.abspath(__file__))), +] + +TIMEOUT = os.environ.get('PTVSD_SOCKET_TIMEOUT') +if TIMEOUT: + TIMEOUT = float(TIMEOUT) + + +if sys.version_info[0] >= 3: + from encodings import ascii + + def to_bytes(cmd_str): + return ascii.Codec.encode(cmd_str)[0] +else: + def to_bytes(cmd_str): + return cmd_str + + class BrokenPipeError(Exception): + pass + + +def _str_or_call(m): + # TODO: Use callable() here. + try: + call = m.__call__ + except AttributeError: + return str(m) + else: + return str(call()) + + +class InvalidHeaderError(Exception): + # TODO: docstring + pass + + +class InvalidContentError(Exception): + # TODO: docstring + pass + + +class SocketIO(object): + # TODO: docstring + + def __init__(self, *args, **kwargs): + port = kwargs.pop('port', None) + socket = kwargs.pop('socket', None) + own_socket = kwargs.pop('own_socket', True) + if socket is None: + if port is None: + raise ValueError( + "A 'port' or a 'socket' must be passed to SocketIO initializer as a keyword argument.") # noqa + addr = ('127.0.0.1', port) + socket = create_connection(addr) + own_socket = True + super(SocketIO, self).__init__(*args, **kwargs) + + self.__buffer = to_bytes('') + self.__port = port + self.__socket = socket + self.__own_socket = own_socket + + def _send(self, **payload): + ptvsd.log.debug('IDE <-- {0!j}', payload) + content = json.dumps(payload).encode('utf-8') + headers = ('Content-Length: {}\r\n\r\n'.format(len(content)) + ).encode('ascii') + + try: + self.__socket.send(headers) + self.__socket.send(content) + except BrokenPipeError: + pass + except OSError as exc: + if exc.errno in (errno.EPIPE, errno.ESHUTDOWN): # BrokenPipeError + pass + elif exc.errno not in (errno.ENOTCONN, errno.EBADF): + raise + + def _buffered_read_line_as_ascii(self): + """Return the next line from the buffer as a string. + + Reads bytes until it encounters newline chars, and returns the bytes + ascii decoded, newline chars are excluded from the return value. + Blocks until: newline chars are read OR socket is closed. + """ + newline = '\r\n'.encode('ascii') + while newline not in self.__buffer: + temp = self.__socket.recv(1024) + if not temp: + break + self.__buffer += temp + + if not self.__buffer: + return None + + try: + index = self.__buffer.index(newline) + except ValueError: + raise InvalidHeaderError('Header line not terminated') + + line = self.__buffer[:index] + self.__buffer = self.__buffer[index+len(newline):] + return line.decode('ascii', 'replace') + + def _buffered_read_as_utf8(self, length): + # TODO: docstring + while len(self.__buffer) < length: + temp = self.__socket.recv(1024) + if not temp: + break + self.__buffer += temp + + if len(self.__buffer) < length: + raise InvalidContentError( + 'Expected to read {} bytes of content, but only read {} bytes.'.format(length, len(self.__buffer))) # noqa + + content = self.__buffer[:length] + self.__buffer = self.__buffer[length:] + return content.decode('utf-8', 'replace') + + def _wait_for_message(self): + # TODO: docstring + # base protocol defined at: + # https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#base-protocol + + # read all headers, ascii encoded separated by '\r\n' + # end of headers is indicated by an empty line + headers = {} + line = self._buffered_read_line_as_ascii() + while line: + parts = line.split(':') + if len(parts) == 2: + headers[parts[0]] = parts[1] + else: + raise InvalidHeaderError( + "Malformed header, expected 'name: value'\n" + line) + line = self._buffered_read_line_as_ascii() + + # end of stream + if not line and not headers: + return + + # validate headers + try: + length_text = headers['Content-Length'] + try: + length = int(length_text) + except ValueError: + raise InvalidHeaderError( + 'Invalid Content-Length: ' + length_text) + except NameError: + raise InvalidHeaderError('Content-Length not specified in headers') + except KeyError: + raise InvalidHeaderError('Content-Length not specified in headers') + + if length < 0 or length > 2147483647: + raise InvalidHeaderError('Invalid Content-Length: ' + length_text) + + # read content, utf-8 encoded + content = self._buffered_read_as_utf8(length) + try: + msg = json.loads(content) + ptvsd.log.debug('IDE --> {0!j}', msg) + self._receive_message(msg) + except ValueError: + ptvsd.log.exception('IDE --> {0}', content) + raise InvalidContentError('Error deserializing message content.') + except json.decoder.JSONDecodeError: + ptvsd.log.exception('IDE --> {0}', content) + raise InvalidContentError('Error deserializing message content.') + + def _close(self): + # TODO: docstring + if self.__own_socket: + self.__socket.close() + + +class IpcChannel(object): + # TODO: docstring + + def __init__(self, *args, **kwargs): + timeout = kwargs.pop('timeout', None) + if timeout is None: + timeout = TIMEOUT + super(IpcChannel, self).__init__(*args, **kwargs) + # This class is meant to be last in the list of base classes + # Don't call super because object's __init__ doesn't take arguments + + self.__seq = itertools.count() + self.__exit = False + self.__lock = threading.Lock() + self.__message = [] + self._timeout = timeout + self._fail_after = None + + def close(self): + # TODO: docstring + self._close() + + def send_event(self, _name, **kwargs): + # TODO: docstring + with self.__lock: + self._send( + type='event', + seq=next(self.__seq), + event=_name, + body=kwargs, + ) + + def send_response(self, request, success=True, message=None, **kwargs): + # TODO: docstring + with self.__lock: + self._send( + type='response', + seq=next(self.__seq), + request_seq=int(request.get('seq', 0)), + success=success, + command=request.get('command', ''), + message=message or '', + body=kwargs, + ) + + def set_exit(self): + # TODO: docstring + self.__exit = True + + def process_messages(self): + # TODO: docstring + if self._timeout is not None: + self._fail_after = time.time() + self._timeout + while not self.__exit: + try: + self.process_one_message() + except (AssertionError, EOFError): + raise + except Exception: + ptvsd.log.exception(category=('D' if self.__exit else 'E')) + if not self.__exit: + raise + + def process_one_message(self): + # TODO: docstring + try: + msg = self.__message.pop(0) + except IndexError: + with convert_eof(): + self._wait_for_message() + try: + msg = self.__message.pop(0) + except IndexError: + # No messages received. + if self._fail_after is not None: + if time.time() < self._fail_after: + raise TimeoutError('connection closed?') + raise EOFError('no more messages') + if self._fail_after is not None: + self._fail_after = time.time() + self._timeout + + what = msg.copy() + what.pop('arguments', None) + what.pop('body', None) + + with ptvsd.log.handling(what): + try: + if msg['type'] == 'request': + self.on_request(msg) + elif msg['type'] == 'response': + self.on_response(msg) + elif msg['type'] == 'event': + self.on_event(msg) + else: + self.on_invalid_request(msg, {}) + except AssertionError: + ptvsd.log.exception() + raise + except Exception: + ptvsd.log.exception() + + def on_request(self, request): + # TODO: docstring + assert request.get('type', '') == 'request', \ + "Only handle 'request' messages in on_request" + + cmd = request.get('command', '') + args = request.get('arguments', {}) + target = getattr(self, 'on_' + cmd, self.on_invalid_request) + + try: + target(request, args) + except AssertionError: + raise + except Exception: + self.send_response( + request, + success=False, + message=traceback.format_exc(), + ) + + def on_response(self, msg): + # TODO: docstring + # this class is only used for server side only for now + raise NotImplementedError + + def on_event(self, msg): + # TODO: docstring + # this class is only used for server side only for now + raise NotImplementedError + + def on_invalid_request(self, request, args): + # TODO: docstring + self.send_response(request, success=False, message='Unknown command') + + def _receive_message(self, message): + with self.__lock: + self.__message.append(message) diff --git a/adapter/python/ptvsd/log.py b/adapter/python/ptvsd/log.py new file mode 100644 index 0000000..984ab62 --- /dev/null +++ b/adapter/python/ptvsd/log.py @@ -0,0 +1,162 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, absolute_import, unicode_literals + +import contextlib +import functools +import io +import json +import platform +import os +import string +import sys +import threading +import time +import traceback + +import ptvsd +import ptvsd.options + + +class Formatter(string.Formatter): + def convert_field(self, value, conversion): + if conversion == 'j': + return json.dumps(value, indent=4) + return super(Formatter, self).convert_field(value, conversion) + + +lock = threading.Lock() +file = None +formatter = Formatter() +tls = threading.local() + + +if sys.version_info >= (3, 5): + clock = time.monotonic +else: + clock = time.clock + + +timestamp_zero = clock() + +def timestamp(): + return clock() - timestamp_zero + + +def is_enabled(): + return bool(file) + + +def write(category, fmt, *args, **kwargs): + assert category in 'DIWE' + if not file and category not in 'WE': + return + + t = timestamp() + + try: + message = formatter.format(fmt, *args, **kwargs) + except Exception: + exception('ptvsd.log.write({0!r}): invalid format string', (category, fmt, args, kwargs)) + raise + + prefix = '{}{:09.3f}: '.format(category, t) + indent = '\n' + (' ' * len(prefix)) + message = indent.join(message.split('\n')) + + if current_handler(): + prefix += '(while handling {}){}'.format(current_handler(), indent) + + message = prefix + message + '\n\n' + with lock: + if file: + file.write(message) + file.flush() + if category in 'WE': + try: + sys.__stderr__.write(message) + except: + pass + + +debug = functools.partial(write, 'D') +info = functools.partial(write, 'I') +warn = functools.partial(write, 'W') +error = functools.partial(write, 'E') + + +def stack(title='Stack trace'): + stack = '\n'.join(traceback.format_stack()) + debug('{0}:\n\n{1}', title, stack) + + +def exception(fmt='', *args, **kwargs): + category = kwargs.pop('category', 'E') + exc_info = kwargs.pop('exc_info', None) + + if fmt: + fmt += '\n\n' + fmt += '{exception}' + + exception = traceback.format_exception(*exc_info) if exc_info else traceback.format_exc() + write(category, fmt, *args, exception=exception, **kwargs) + + +def escaped_exceptions(f): + def g(*args, **kwargs): + try: + return f(*args, **kwargs) + except: + # Must not use try/except here to avoid overwriting the caught exception. + name = f.__qualname__ if hasattr(f, '__qualname__') else f.__name__ + exception('Exception escaped from {0}', name) + raise + return g + + +def to_file(): + global file + + if ptvsd.options.log_dir and not file: + filename = ptvsd.options.log_dir + '/ptvsd-{}.log'.format(os.getpid()) + file = io.open(filename, 'w', encoding='utf-8') + + info( + '{0} {1}\n{2} {3} ({4}-bit)\nptvsd {5}', + platform.platform(), + platform.machine(), + platform.python_implementation(), + platform.python_version(), + 64 if sys.maxsize > 2**32 else 32, + ptvsd.__version__, + ) + + +def current_handler(): + try: + return tls.current_handler + except AttributeError: + tls.current_handler = None + return None + + +@contextlib.contextmanager +def handling(what): + assert current_handler() is None, "Can't handle {} - already handling {}".format(what, current_handler()) + tls.current_handler = what + try: + yield + finally: + tls.current_handler = None + + +@contextlib.contextmanager +def suspend_handling(): + what = current_handler() + tls.current_handler = None + try: + yield + finally: + tls.current_handler = what diff --git a/adapter/python/ptvsd/messaging.py b/adapter/python/ptvsd/messaging.py new file mode 100644 index 0000000..4293cdb --- /dev/null +++ b/adapter/python/ptvsd/messaging.py @@ -0,0 +1,458 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, with_statement, absolute_import + +import contextlib +import itertools +import json +import sys +import threading + +import ptvsd.log +from ptvsd._util import new_hidden_thread + + +class JsonIOStream(object): + """Implements a JSON value stream over two byte streams (input and output). + + Each value is encoded as a packet consisting of a header and a body, as defined by the + Debug Adapter Protocol (https://microsoft.github.io/debug-adapter-protocol/overview). + """ + + MAX_BODY_SIZE = 0xFFFFFF + + @classmethod + def from_stdio(cls, name='???'): + if sys.version_info >= (3,): + stdin = sys.stdin.buffer + stdout = sys.stdout.buffer + else: + stdin = sys.stdin + stdout = sys.stdout + if sys.platform == 'win32': + import os, msvcrt + msvcrt.setmode(stdin.fileno(), os.O_BINARY) + msvcrt.setmode(stdout.fileno(), os.O_BINARY) + return cls(stdin, stdout, name) + + @classmethod + def from_socket(cls, socket, name='???'): + if socket.gettimeout() is not None: + raise ValueError('Socket must be in blocking mode') + socket_io = socket.makefile('rwb', 0) + return cls(socket_io, socket_io, name) + + def __init__(self, reader, writer, name='???'): + """Creates a new JsonIOStream. + + reader is a BytesIO-like object from which incoming messages are read; + reader.readline() must treat '\n' as the line terminator, and must leave + '\r' as is (i.e. it must not translate '\r\n' to just plain '\n'!). + + writer is a BytesIO-like object to which outgoing messages are written. + """ + self.name = name + self._reader = reader + self._writer = writer + self._is_closing = False + + def close(self): + self._is_closing = True + self._reader.close() + self._writer.close() + + def _read_line(self): + line = b'' + while True: + try: + line += self._reader.readline() + except Exception: + raise EOFError + if not line: + raise EOFError + if line.endswith(b'\r\n'): + line = line[0:-2] + return line + + def read_json(self): + """Read a single JSON value from reader. + + Returns JSON value as parsed by json.loads(), or raises EOFError + if there are no more objects to be read. + """ + + headers = {} + while True: + line = self._read_line() + if line == b'': + break + key, _, value = line.partition(b':') + headers[key] = value + + try: + length = int(headers[b'Content-Length']) + if not (0 <= length <= self.MAX_BODY_SIZE): + raise ValueError + except (KeyError, ValueError): + ptvsd.log.exception('{0} --> {1}', self.name, headers) + raise IOError('Content-Length is missing or invalid') + + try: + body = b'' + while length > 0: + chunk = self._reader.read(length) + body += chunk + length -= len(chunk) + except Exception: + if self._is_closing: + raise EOFError + else: + raise + + if isinstance(body, bytes): + try: + body = body.decode('utf-8') + except Exception: + ptvsd.log.exception('{0} --> {1}', self.name, body) + raise + + try: + body = json.loads(body) + except Exception: + ptvsd.log.exception('{0} --> {1}', self.name, body) + raise + + ptvsd.log.debug('{0} --> {1!j}', self.name, body) + return body + + + def write_json(self, value): + """Write a single JSON object to writer. + + object must be in the format suitable for json.dump(). + """ + + try: + body = json.dumps(value, sort_keys=True) + except Exception: + ptvsd.log.exception('{0} <-- {1!r}', self.name, value) + + if not isinstance(body, bytes): + body = body.encode('utf-8') + + try: + header = 'Content-Length: %d\r\n\r\n' % len(body) + if not isinstance(header, bytes): + header = header.encode('ascii') + + self._writer.write(header) + self._writer.write(body) + except Exception: + ptvsd.log.exception('{0} <-- {1!j}', self.name, value) + raise + + ptvsd.log.debug('{0} <-- {1!j}', self.name, value) + + + +class Request(object): + """Represents an incoming or an outgoing request. + + Incoming requests are represented by instances of this class. + + Outgoing requests are represented by instances of OutgoingRequest, which + provides additional functionality to handle responses. + """ + + def __init__(self, channel, seq, command, arguments): + self.channel = channel + self.seq = seq + self.command = command + self.arguments = arguments + + +class OutgoingRequest(Request): + """Represents an outgoing request, for which it is possible to wait for a + response to be received, and register a response callback. + """ + + def __init__(self, *args): + super(OutgoingRequest, self).__init__(*args) + self.response = None + self._lock = threading.Lock() + self._got_response = threading.Event() + self._callback = lambda _: None + + def _handle_response(self, seq, command, body): + assert self.response is None + with self._lock: + response = Response(self.channel, seq, self, body) + self.response = response + callback = self._callback + callback(response) + self._got_response.set() + + def wait_for_response(self, raise_if_failed=True): + """Waits until a response is received for this request, records that + response as a new Response object accessible via self.response, and + returns self.response.body. + + If raise_if_failed is True, and the received response does not indicate + success, raises RequestFailure. Otherwise, self.response.body has to be + inspected to determine whether the request failed or succeeded. + """ + + self._got_response.wait() + if raise_if_failed and not self.response.success: + raise self.response.body + return self.response.body + + def on_response(self, callback): + """Registers a callback to invoke when a response is received for this + request. If response was already received, invokes callback immediately. + Callback is invoked with Response as the sole arugment. + + The callback is invoked on an unspecified background thread that performs + processing of incoming messages; therefore, no further message processing + occurs until the callback returns. + """ + + with self._lock: + response = self.response + if response is None: + self._callback = callback + return + callback(response) + + +class Response(object): + """Represents a response to a Request. + """ + + def __init__(self, channel, seq, request, body): + self.channel = channel + self.seq = seq + + self.request = request + """Request object that this is a response to. + """ + + self.body = body + """Body of the response if the request was successful, or an instance + of some class derived from Exception it it was not. + + If a response was received from the other side, but it was marked as + failure, it is an instance of RequestFailure, capturing the received + error message. + + If a response was never received from the other side (e.g. because it + disconnected before sending a response), it is EOFError. + """ + + @property + def success(self): + return not isinstance(self.body, Exception) + + +class Event(object): + """Represents a received event. + """ + + def __init__(self, channel, seq, event, body): + self.channel = channel + self.seq = seq + self.event = event + self.body = body + + +class RequestFailure(Exception): + def __init__(self, message): + self.message = message + + def __hash__(self): + return hash(self.message) + + def __eq__(self, other): + if not isinstance(other, RequestFailure): + return NotImplemented + return self.message == other.message + + def __ne__(self, other): + return not self == other + + def __repr__(self): + return 'RequestFailure(%r)' % self.message + + def __str__(self): + return self.message + + +class JsonMessageChannel(object): + """Implements a JSON message channel on top of a JSON stream, with + support for generic Request, Response and Event messages as defined by the + Debug Adapter Protocol (https://microsoft.github.io/debug-adapter-protocol/overview). + """ + + def __init__(self, stream, handlers=None, name=None): + self.stream = stream + self.name = name if name is not None else stream.name + self._lock = threading.Lock() + self._stop = threading.Event() + self._seq_iter = itertools.count(1) + self._requests = {} + self._handlers = handlers + self._worker = new_hidden_thread('{} message channel worker'.format(self.name), self._process_incoming_messages) + self._worker.daemon = True + + def close(self): + self.stream.close() + + def start(self): + self._worker.start() + + def wait(self): + self._worker.join() + + @contextlib.contextmanager + def _send_message(self, type, rest={}): + with self._lock: + seq = next(self._seq_iter) + message = { + 'seq': seq, + 'type': type, + } + message.update(rest) + with self._lock: + yield seq + self.stream.write_json(message) + + def send_request(self, command, arguments=None): + d = {'command': command} + if arguments is not None: + d['arguments'] = arguments + with self._send_message('request', d) as seq: + request = OutgoingRequest(self, seq, command, arguments) + self._requests[seq] = request + return request + + def send_event(self, event, body=None): + d = {'event': event} + if body is not None: + d['body'] = body + with self._send_message('event', d): + pass + + def _send_response(self, request_seq, success, command, error_message, body): + d = { + 'request_seq': request_seq, + 'success': success, + 'command': command, + } + if success: + if body is not None: + d['body'] = body + else: + if error_message is not None: + d['message'] = error_message + with self._send_message('response', d): + pass + + def on_message(self, message): + seq = message['seq'] + typ = message['type'] + if typ == 'request': + command = message['command'] + arguments = message.get('arguments', None) + self.on_request(seq, command, arguments) + elif typ == 'event': + event = message['event'] + body = message.get('body', None) + self.on_event(seq, event, body) + elif typ == 'response': + request_seq = message['request_seq'] + success = message['success'] + command = message['command'] + error_message = message.get('message', None) + body = message.get('body', None) + self.on_response(seq, request_seq, success, command, error_message, body) + else: + raise IOError('Incoming message has invalid "type":\n%r' % message) + + def on_request(self, seq, command, arguments): + handler_name = '%s_request' % command + handler = getattr(self._handlers, handler_name, None) + if handler is None: + try: + handler = getattr(self._handlers, 'request') + except AttributeError: + raise AttributeError('%r has no handler for request %r' % (self._handlers, command)) + request = Request(self, seq, command, arguments) + try: + response_body = handler(request) + except RequestFailure as ex: + self._send_response(seq, False, command, str(ex), None) + else: + if isinstance(response_body, Exception): + self._send_response(seq, False, command, str(response_body), None) + else: + self._send_response(seq, True, command, None, response_body) + + def on_event(self, seq, event, body): + handler_name = '%s_event' % event + handler = getattr(self._handlers, handler_name, None) + if handler is None: + try: + handler = getattr(self._handlers, 'event') + except AttributeError: + raise AttributeError('%r has no handler for event %r' % (self._handlers, event)) + handler(Event(self, seq, event, body)) + + def on_response(self, seq, request_seq, success, command, error_message, body): + try: + with self._lock: + request = self._requests.pop(request_seq) + except KeyError: + raise KeyError('Received response to unknown request %d', request_seq) + if not success: + body = RequestFailure(error_message) + return request._handle_response(seq, command, body) + + def on_disconnect(self): + # There's no more incoming messages, so any requests that are still pending + # must be marked as failed to unblock anyone waiting on them. + with self._lock: + for request in self._requests.values(): + request._handle_response(None, request.command, EOFError('No response')) + getattr(self._handlers, 'disconnect', lambda: None)() + + def _process_incoming_messages(self): + try: + while True: + try: + message = self.stream.read_json() + except EOFError: + break + try: + self.on_message(message) + except Exception: + ptvsd.log.exception('Error while processing message for {0}:\n\n{1!r}', self.name, message) + raise + finally: + try: + self.on_disconnect() + except Exception: + ptvsd.log.exception('Error while processing disconnect for {0}', self.name) + raise + + +class MessageHandlers(object): + """A simple delegating message handlers object for use with JsonMessageChannel. + For every argument provided, the object has an attribute with the corresponding + name and value. + """ + + def __init__(self, **kwargs): + for name, func in kwargs.items(): + setattr(self, name, func) diff --git a/adapter/python/ptvsd/multiproc.py b/adapter/python/ptvsd/multiproc.py new file mode 100644 index 0000000..1d8b0f2 --- /dev/null +++ b/adapter/python/ptvsd/multiproc.py @@ -0,0 +1,325 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, with_statement, absolute_import + +import atexit +import itertools +import os +import re +import signal +import socket +import sys +import threading +import time + +try: + import queue +except ImportError: + import Queue as queue + +import ptvsd.log +from ptvsd import options +from ptvsd.socket import create_server, create_client +from ptvsd.messaging import JsonIOStream, JsonMessageChannel +from ptvsd._util import new_hidden_thread + +from _pydev_bundle import pydev_monkey +from _pydevd_bundle.pydevd_comm import get_global_debugger + +subprocess_lock = threading.Lock() + +subprocess_listener_socket = None + +subprocesses = {} +"""List of known subprocesses. Keys are process IDs, values are JsonMessageChannel +instances; subprocess_lock must be used to synchronize access. +""" + +subprocess_queue = queue.Queue() +"""A queue of incoming 'ptvsd_subprocess' notifications. Whenenever a new request +is received, a tuple of (subprocess_request, subprocess_response) is placed in the +queue. + +subprocess_request is the body of the 'ptvsd_subprocess' notification request that +was received, with additional information about the root process added. + +subprocess_response is the body of the response that will be sent to respond to the +request. It contains a single item 'incomingConnection', which is initially set to +False. If, as a result of processing the entry, the subprocess shall receive an +incoming DAP connection on the port it specified in the request, its value should be +set to True, indicating that the subprocess should wait for that connection before +proceeding. If no incoming connection is expected, it is set to False, indicating +that the subprocess shall proceed executing user code immediately. + +subprocess_queue.task_done() must be invoked for every subprocess_queue.get(), for +the corresponding subprocess_response to be delivered back to the subprocess. +""" + +root_start_request = None +"""The 'launch' or 'attach' request that started debugging in this process, in its +entirety (i.e. dict representation of JSON request). This information is added to +'ptvsd_subprocess' notifications before they're placed in subprocess_queue. +""" + + +def listen_for_subprocesses(): + """Starts a listener for incoming 'ptvsd_subprocess' notifications that + enqueues them in subprocess_queue. + """ + + global subprocess_listener_socket + assert subprocess_listener_socket is None + + subprocess_listener_socket = create_server('localhost', 0) + ptvsd.log.debug( + 'Listening for subprocess notifications on port {0}.', + subprocess_listener_port()) + + atexit.register(stop_listening_for_subprocesses) + atexit.register(kill_subprocesses) + new_hidden_thread('SubprocessListener', _subprocess_listener).start() + + +def stop_listening_for_subprocesses(): + ptvsd.log.debug('Stopping listening for subprocess notifications.') + + global subprocess_listener_socket + if subprocess_listener_socket is None: + return + try: + subprocess_listener_socket.shutdown(socket.SHUT_RDWR) + except Exception: + pass + subprocess_listener_socket = None + + +def kill_subprocesses(): + with subprocess_lock: + pids = list(subprocesses.keys()) + + ptvsd.log.debug('Killing remaining subprocesses: PID={0}', pids) + + for pid in pids: + ptvsd.log.debug('Killing subprocess with PID={0}.', pid) + with subprocess_lock: + subprocesses.pop(pid, None) + try: + os.kill(pid, signal.SIGTERM) + except Exception: + ptvsd.log.exception('Failed to kill process with PID={0}.', pid, category='D') + + +def subprocess_listener_port(): + if subprocess_listener_socket is None: + return None + _, port = subprocess_listener_socket.getsockname() + return port + + +def _subprocess_listener(): + counter = itertools.count(1) + while subprocess_listener_socket: + try: + (sock, _) = subprocess_listener_socket.accept() + except Exception: + break + + n = next(counter) + name = 'subprocess-{}'.format(n) + ptvsd.log.debug('Accepted incoming connection from {0}', name) + + stream = JsonIOStream.from_socket(sock, name=name) + _handle_subprocess(n, stream) + + +def _handle_subprocess(n, stream): + + class Handlers(object): + _pid = None + + def ptvsd_subprocess_request(self, request): + # When child process is spawned, the notification it sends only + # contains information about itself and its immediate parent. + # Add information about the root process before passing it on. + arguments = dict(request.arguments) + arguments.update({ + 'rootProcessId': os.getpid(), + 'rootStartRequest': root_start_request, + }) + + self._pid = arguments['processId'] + with subprocess_lock: + subprocesses[self._pid] = channel + + ptvsd.log.debug( + 'Subprocess {0} (PID={1}) registered, notifying IDE.', + stream.name, + self._pid) + + response = {'incomingConnection': False} + subprocess_queue.put((arguments, response)) + subprocess_queue.join() + return response + + def disconnect(self): + ptvsd.log.debug('Subprocess {0} disconnected, presumed to have terminated.', self._pid) + if self._pid is not None: + with subprocess_lock: + subprocesses.pop(self._pid, None) + + name = 'subprocess-%d' % n + channel = JsonMessageChannel(stream, Handlers(), name) + channel.start() + + +def notify_root(port): + assert options.subprocess_of + + ptvsd.log.debug('Subprocess (PID={0}) notifying root process at port {1}', os.getpid(), options.subprocess_notify) + conn = create_client() + conn.connect(('localhost', options.subprocess_notify)) + stream = JsonIOStream.from_socket(conn, 'root-process') + channel = JsonMessageChannel(stream) + channel.start() + + # Send the notification about ourselves to root, and wait for it to tell us + # whether an incoming connection is anticipated. This will be true if root + # had successfully propagated the notification to the IDE, and false if it + # couldn't do so (e.g. because the IDE is not attached). There's also the + # possibility that connection to root will just drop, e.g. if it crashes - + # in that case, just exit immediately. + + request = channel.send_request('ptvsd_subprocess', { + 'parentProcessId': options.subprocess_of, + 'processId': os.getpid(), + 'port': port, + }) + + try: + response = request.wait_for_response() + except Exception: + ptvsd.log.exception('Failed to send subprocess notification; exiting') + sys.exit(0) + + # Keep the channel open until we exit - root process uses open channels to keep + # track of which subprocesses are alive and which are not. + atexit.register(lambda: channel.close()) + + if not response['incomingConnection']: + ptvsd.log.debug('No IDE connection is expected for this subprocess; unpausing.') + debugger = get_global_debugger() + while debugger is None: + time.sleep(0.1) + debugger = get_global_debugger() + debugger.ready_to_run = True + + +def patch_args(args): + """ + Patches a command line invoking Python such that it has the same meaning, but + the process runs under ptvsd. In general, this means that given something like: + + python -R -Q warn -m app + + the result should be: + + python -R -Q warn .../ptvsd/__main__.py --host localhost --port 0 ... -m app + """ + + if not options.multiprocess: + return args + + args = list(args) + ptvsd.log.debug('Patching subprocess command line: {0!r}', args) + + # First, let's find the target of the invocation. This is one of: + # + # filename.py + # -m module_name + # -c "code" + # - + # + # This needs to take into account other switches that have values: + # + # -Q -W -X --check-hash-based-pycs + # + # because in something like "-X -c", -c is a value, not a switch. + expect_value = False + for i, arg in enumerate(args): + # Skip Python binary. + if i == 0: + if not pydev_monkey.is_python(arg): + return args # We're not dealing with Python, so, don't do anything. + continue + + if arg == '-': + # We do not support debugging while reading from stdin, so just let this + # process run without debugging. + return args + + if expect_value: + # Consume the value and move on. + expect_value = False + continue + + if not arg.startswith('-') or arg in ('-c', '-m'): + # This is the target. + break + + if arg.startswith('--'): + expect_value = (arg == '--check-hash-based-pycs') + continue + + # All short switches other than -c and -m can be combined together, including + # those with values. So, instead of -R -B -v -Q old, we might see -RBvQ old. + # Furthermore, the value itself can be concatenated with the switch, so rather + # than -Q old, we might have -Qold. When switches are combined, any switch that + # has a value "eats" the rest of the argument; for example, -RBQv is treated as + # -R -B -Qv, and not as -R -B -Q -v. So, we need to check whether one of 'Q', + # 'W' or 'X' was present somewhere in the arg, and whether there was anything + # following it in the arg. If it was there but nothing followed after it, then + # the switch is expecting a value. + split = re.split(r'[QWX]', arg, maxsplit=1) + expect_value = (len(split) > 1 and split[-1] != '') + + else: + # Didn't find the target, so we don't know how to patch this command line; let + # it run without debugging. + return args + + if not args[i].startswith('-'): + # If it was a filename, it can be a Python file, a directory, or a zip archive + # that is treated as if it were a directory. However, ptvsd only supports the + # first scenario. Distinguishing between these can be tricky, and getting it + # wrong means that process fails to launch, so be conservative. + if not args[i].endswith('.py'): + return args + + # Now we need to inject the ptvsd invocation right before the target. The target + # itself can remain as is, because ptvsd is compatible with Python in that respect. + from ptvsd import __main__ + ptvsd_args = [ + __main__.__file__, + '--host', options.host, + '--port', '0', + '--wait', + '--multiprocess', + '--subprocess-of', str(os.getpid()), + '--subprocess-notify', str(options.subprocess_notify or subprocess_listener_port()), + ] + if options.log_dir: + ptvsd_args += ['--log-dir', options.log_dir] + args[i:i] = ptvsd_args + + ptvsd.log.debug('Patched subprocess command line: {0!r}', args) + return args + + +def patch_and_quote_args(args): + # On Windows, pydevd expects arguments to be quoted and escaped as necessary, such + # that simply concatenating them via ' ' produces a valid command line. This wraps + # patch_args and applies quoting (quote_args contains platform check), so that the + # implementation of patch_args can be kept simple. + return pydev_monkey.quote_args(patch_args(args)) diff --git a/adapter/python/ptvsd/options.py b/adapter/python/ptvsd/options.py new file mode 100644 index 0000000..b2c49f1 --- /dev/null +++ b/adapter/python/ptvsd/options.py @@ -0,0 +1,76 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, with_statement, absolute_import + +import os + + +"""ptvsd command-line options that need to be globally available. +""" + +log_dir = os.getenv('PTVSD_LOG_DIR') +"""If not None, debugger logs its activity to a file named ptvsd-.log in +the specified directory, where is the return value of os.getpid(). +""" + +target_kind = None +"""One of: None, 'file', 'module', 'code', or 'pid'. +""" + +target = None +"""Specifies what to debug. + +If target_kind is None, then target is None, indicating that the current process +is the one that is initiating debugger attach to itself. + +If target_kind is 'file', then target is a path to the file to run. + +If target_kind is 'module', then target is the qualified name of the module to run. + +If target_kind is 'code', then target is the code to run. + +If target_kind is 'pid', then target is the process ID to attach to. +""" + +host = 'localhost' +"""Name or IP address of the network interface used by ptvsd. If runing in server +mode, this is the interface on which it listens for incoming connections. If running +in client mode, this is the interface to which it connects. +""" + +port = 5678 +"""Port number used by ptvsd. If running in server mode, this is the port on which it +listens for incoming connections. If running in client mode, this is port to which it +connects. +""" + +client = False +"""If True, this instance of ptvsd is operating in client mode - i.e. it connects +to the IDE, instead of waiting for an incoming connection from the IDE. +""" + +no_debug = False +"""If true, execute the target without debugging. +""" + +wait = False +"""If True, wait until the debugger is connected before running any code." +""" + +multiprocess = False +"""Whether this ptvsd instance is running in multiprocess mode, detouring creation +of new processes and enabling debugging for them. +""" + +subprocess_of = None +"""If not None, the process ID of the parent process (running in multiprocess mode) +that spawned this subprocess. +""" + +subprocess_notify = None +"""The port number of the subprocess listener. If specified, a 'ptvsd_subprocess' +notification must be sent to that port once this ptvsd is initialized and ready to +accept a connection from the client. +""" diff --git a/adapter/python/ptvsd/pydevd_hooks.py b/adapter/python/ptvsd/pydevd_hooks.py new file mode 100644 index 0000000..07e092b --- /dev/null +++ b/adapter/python/ptvsd/pydevd_hooks.py @@ -0,0 +1,162 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import os +import sys + +import pydevd +from _pydev_bundle import pydev_monkey +from _pydevd_bundle import pydevd_comm + +import ptvsd +import ptvsd.log +from ptvsd import multiproc +from ptvsd.socket import Address +from ptvsd.daemon import Daemon, DaemonStoppedError, DaemonClosedError +from ptvsd._util import new_hidden_thread +from ptvsd import options + + +@ptvsd.log.escaped_exceptions +def start_server(daemon, host, port, **kwargs): + """Return a socket to a (new) local pydevd-handling daemon. + + The daemon supports the pydevd client wire protocol, sending + requests and handling responses (and events). + + This is a replacement for _pydevd_bundle.pydevd_comm.start_server. + """ + sock, next_session = daemon.start_server((host, port)) + + def handle_next(): + try: + ptvsd.log.debug('Waiting for session...') + session = next_session(**kwargs) + ptvsd.log.debug('Got session') + return session + except (DaemonClosedError, DaemonStoppedError): + # Typically won't happen. + ptvsd.log.exception('Daemon stopped while waiting for session', category='D') + raise + except Exception: + ptvsd.log.exception() + return None + + def serve_forever(): + ptvsd.log.debug('Waiting for initial connection...') + handle_next() + while True: + ptvsd.log.debug('Waiting for next connection...') + try: + handle_next() + except (DaemonClosedError, DaemonStoppedError): + break + ptvsd.log.debug('Done serving') + + t = new_hidden_thread( + target=serve_forever, + name='sessions', + ) + t.start() + return sock + + +@ptvsd.log.escaped_exceptions +def start_client(daemon, host, port, **kwargs): + """Return a socket to an existing "remote" pydevd-handling daemon. + + The daemon supports the pydevd client wire protocol, sending + requests and handling responses (and events). + + This is a replacement for _pydevd_bundle.pydevd_comm.start_client. + """ + sock, start_session = daemon.start_client((host, port)) + start_session(**kwargs) + return sock + + +# See pydevd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py +@ptvsd.log.escaped_exceptions +def get_python_c_args(host, port, indC, args, setup): + runner = ''' +import sys +sys.path.append(r'{ptvsd_syspath}') +from ptvsd import multiproc +multiproc.init_subprocess( + {initial_pid}, + {initial_request}, + {parent_pid}, + {parent_port}, + {first_port}, + {last_port}, + {pydevd_setup}) +{rest} +''' + + first_port, last_port = multiproc.subprocess_port_range + + # __file__ will be .../ptvsd/__init__.py, and we want the ... + ptvsd_syspath = os.path.join(ptvsd.__file__, '../..') + + return runner.format( + initial_pid=multiproc.initial_pid, + initial_request=multiproc.initial_request, + parent_pid=os.getpid(), + parent_port=multiproc.listener_port, + first_port=first_port, + last_port=last_port, + ptvsd_syspath=ptvsd_syspath, + pydevd_setup=setup, + rest=args[indC + 1]) + + +def install(pydevd_module, address, + start_server=start_server, start_client=start_client, + **kwargs): + """Configure pydevd to use our wrapper. + + This is a bit of a hack to allow us to run our VSC debug adapter + in the same process as pydevd. Note that, as with most hacks, + this is somewhat fragile (since the monkeypatching sites may + change). + """ + + ptvsd.log.debug('Installing pydevd hooks.') + + addr = Address.from_raw(address) + daemon = Daemon(**kwargs) + + def _start_server(p): + ptvsd.log.debug('ptvsd: install._start_server.') + return start_server(daemon, addr.host, p) + + def _start_client(h, p): + ptvsd.log.debug('ptvsd: install._start_client.') + return start_client(daemon, h, p) + + _start_server.orig = start_server + _start_client.orig = start_client + + # These are the functions pydevd invokes to get a socket to the client. + pydevd_comm.start_server = _start_server + pydevd_comm.start_client = _start_client + + # This is invoked when a child process is spawned with multiproc debugging enabled. + pydev_monkey.patch_args = multiproc.patch_and_quote_args + if not options.multiprocess and not options.no_debug: + # This means '--multiprocess' flag was not passed via command line args. Patch the + # new process functions here to handle multiprocess being enabled via debug options. + ptvsd.log.debug('Monkey-patching multiprocess functions.') + pydev_monkey.patch_new_process_functions() + + # Ensure that pydevd is using our functions. + pydevd_module.start_server = _start_server + pydevd_module.start_client = _start_client + __main__ = sys.modules['__main__'] + if __main__ is not pydevd: + if getattr(__main__, '__file__', None) == pydevd.__file__: + __main__.start_server = _start_server + __main__.start_client = _start_client + + return daemon diff --git a/adapter/python/ptvsd/reraise.py b/adapter/python/ptvsd/reraise.py new file mode 100644 index 0000000..ced8926 --- /dev/null +++ b/adapter/python/ptvsd/reraise.py @@ -0,0 +1,13 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +# TODO: only absolute_import needed? +from __future__ import print_function, with_statement, absolute_import + +import sys + +if sys.version_info >= (3,): + from ptvsd.reraise3 import reraise # noqa: F401 +else: + from ptvsd.reraise2 import reraise # noqa: F401 diff --git a/adapter/python/ptvsd/reraise2.py b/adapter/python/ptvsd/reraise2.py new file mode 100644 index 0000000..effb62a --- /dev/null +++ b/adapter/python/ptvsd/reraise2.py @@ -0,0 +1,8 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + + +def reraise(exc_info): + # TODO: docstring + raise exc_info[0], exc_info[1], exc_info[2] # noqa diff --git a/adapter/python/ptvsd/reraise3.py b/adapter/python/ptvsd/reraise3.py new file mode 100644 index 0000000..dcb5415 --- /dev/null +++ b/adapter/python/ptvsd/reraise3.py @@ -0,0 +1,8 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + + +def reraise(exc_info): + # TODO: docstring + raise exc_info[1].with_traceback(exc_info[2]) diff --git a/adapter/python/ptvsd/runner.py b/adapter/python/ptvsd/runner.py new file mode 100644 index 0000000..b172efb --- /dev/null +++ b/adapter/python/ptvsd/runner.py @@ -0,0 +1,103 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import pydevd +import threading + +from ptvsd.daemon import DaemonBase +from ptvsd.session import DebugSession +from ptvsd.wrapper import VSCLifecycleMsgProcessor +from pydevd import init_stdout_redirect, init_stderr_redirect + + +HOSTNAME = 'localhost' + + +def run(address, filename, is_module, *args, **kwargs): + # TODO: docstring + # TODO: client/server -> address + daemon = Daemon() + if not daemon.wait_for_launch(address): + return + + debugger = pydevd.PyDB() + # We do not want some internal methods to get executed in non-debug mode. + debugger.init_matplotlib_support = lambda *arg: None + debugger.run( + file=filename, + globals=None, + locals=None, + is_module=is_module, + set_trace=False) + + +class Daemon(DaemonBase): + """The process-level manager for the VSC protocol debug adapter.""" + + LAUNCH_TIMEOUT = 10000 # seconds + + class SESSION(DebugSession): + class MESSAGE_PROCESSOR(VSCLifecycleMsgProcessor): + + def on_setBreakpoints(self, request, args): + # Note: breakpoints is required (vscode will terminate + # the debugger if that's not the case). + # See: https://github.com/microsoft/ptvsd/issues/1408 + self.send_response( + request, + success=True, + breakpoints=( + [{'verified': False}] * len(args.get('breakpoints', ())) + ) + ) + + def on_invalid_request(self, request, args): + self.send_response(request, success=True) + + def wait_for_launch(self, addr, timeout=LAUNCH_TIMEOUT): + # TODO: docstring + launched = threading.Event() + _, start_session = self.start_client(addr) + start_session( + notify_launch=launched.set, + ) + return launched.wait(timeout) + + def _start(self): + import weakref + weak_self = weakref.ref(self) # Avoid cyclic ref + + def on_stdout(msg): + self = weak_self() + if self is not None: + self._send_output('stdout', msg) + + def on_stderr(msg): + self = weak_self() + if self is not None: + self._send_output('stderr', msg) + + init_stdout_redirect(on_stdout) + init_stderr_redirect(on_stderr) + return NoSocket() + + def _close(self): + super(Daemon, self)._close() + + def _send_output(self, category, output): + if self.session is None: + return + self.session._msgprocessor.send_event('output', + category=category, + output=output) + + +class NoSocket(object): + """A object with a noop socket lifecycle.""" + + def shutdown(self, *args, **kwargs): + pass + + def close(self): + pass diff --git a/adapter/python/ptvsd/session.py b/adapter/python/ptvsd/session.py new file mode 100644 index 0000000..a405b04 --- /dev/null +++ b/adapter/python/ptvsd/session.py @@ -0,0 +1,204 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +import ptvsd.log +from .socket import is_socket, close_socket +from .wrapper import VSCodeMessageProcessor +from ._util import TimeoutError, ClosedError, Closeable, Startable + + +class DebugSession(Startable, Closeable): + """A single DAP session for a network client socket.""" + + MESSAGE_PROCESSOR = None + + NAME = 'debug session' + FAIL_ON_ALREADY_CLOSED = False + FAIL_ON_ALREADY_STOPPED = False + + @classmethod + def from_raw(cls, raw, **kwargs): + """Return a session for the given data.""" + if isinstance(raw, cls): + return raw + if not is_socket(raw): + # TODO: Create a new client socket from a remote address? + # addr = Address.from_raw(raw) + raise NotImplementedError + client = raw + return cls(client, **kwargs) + + @classmethod + def from_server_socket(cls, server, **kwargs): + """Return a session for the next connection to the given socket.""" + client, _ = server.accept() + return cls(client, ownsock=True, **kwargs) + + def __init__(self, sock, + notify_closing=None, + notify_disconnecting=None, + ownsock=False): + super(DebugSession, self).__init__() + + if notify_closing is not None: + + def handle_closing(before): + if before: + notify_closing(self) + + self.add_close_handler(handle_closing) + + if notify_disconnecting is None: + notify_disconnecting = (lambda _: None) + self._notify_disconnecting = notify_disconnecting + + self._sock = sock + self._pre_socket_close = None + if ownsock: + + # Close the socket *after* calling sys.exit() (via notify_closing). + def handle_closing(before): + if before: + return + ptvsd.log.debug('Closing session socket') + proc = self._msgprocessor + if self._pre_socket_close is not None: + self._pre_socket_close() + if proc is not None: + try: + proc.wait_while_connected(10) # seconds + except TimeoutError: + ptvsd.log.exception('timed out waiting for disconnect', category='D') + close_socket(self._sock) + + self.add_close_handler(handle_closing) + + self._msgprocessor = None + + @property + def socket(self): + return self._sock + + @property + def msgprocessor(self): + return self._msgprocessor + + def handle_debugger_stopped(self, wait=None): + """Deal with the debugger exiting.""" + proc = self._msgprocessor + if proc is None: + return + proc.handle_debugger_stopped(wait) + + def handle_exiting(self, exitcode=None, wait=None): + """Deal with the debuggee exiting.""" + proc = self._msgprocessor + if proc is None: + return + proc.handle_exiting(exitcode, wait) + + def wait_until_stopped(self): + """Block until all resources (e.g. message processor) have stopped.""" + proc = self._msgprocessor + if proc is None: + return + # TODO: Do this in VSCodeMessageProcessor.close()? + proc._wait_for_server_thread() + + # internal methods + + def _new_msg_processor(self, **kwargs): + return self.MESSAGE_PROCESSOR( + self._sock, + notify_disconnecting=self._handle_vsc_disconnect, + notify_closing=self._handle_vsc_close, + **kwargs + ) + + def _start(self, threadname, **kwargs): + """Start the message handling for the session.""" + self._msgprocessor = self._new_msg_processor(**kwargs) + self.add_resource_to_close(self._msgprocessor) + self._msgprocessor.start(threadname) + return self._msgprocessor_running + + def _stop(self): + proc = self._msgprocessor + if proc is None: + return + + ptvsd.log.debug('Message processor is stopping.') + # TODO: We should not need to wait if not exiting. + # The editor will send a "disconnect" request at this point. + proc._wait_for_disconnect() + proc.close() + self._msgprocessor = None + + def _close(self): + ptvsd.log.debug('Session is closing.') + + def _msgprocessor_running(self): + if self._msgprocessor is None: + return False + # TODO: Return self._msgprocessor.is_running(). + return True + + # internal methods for VSCodeMessageProcessor + + def _handle_vsc_disconnect(self, pre_socket_close=None): + ptvsd.log.debug('Disconnecting.') + self._pre_socket_close = pre_socket_close # TODO: Fail if already set? + self._notify_disconnecting(self) + + def _handle_vsc_close(self): + ptvsd.log.debug('Message processor is closing.') + try: + self.close() + except ClosedError: + pass + + +class PyDevdDebugSession(DebugSession): + """A single DAP session for a network client socket.""" + + MESSAGE_PROCESSOR = VSCodeMessageProcessor + + def __init__(self, sock, + notify_debugger_ready=None, + **kwargs): + super(PyDevdDebugSession, self).__init__(sock, **kwargs) + + def notify_debugger_ready(session, _notify=notify_debugger_ready): + if self._notified_debugger_ready: + return + self._notified_debugger_ready = True + if _notify is not None: + _notify(session) + + self._notified_debugger_ready = False + self._notify_debugger_ready = notify_debugger_ready + + def handle_pydevd_message(self, cmdid, seq, text): + if self._msgprocessor is None: + # TODO: Do more than ignore? + return + try: + return self._msgprocessor.on_pydevd_event(cmdid, seq, text) + except: + ptvsd.log.exception('Error handling pydevd message: {0}', text) + raise + + # internal methods + + def _new_msg_processor(self, **kwargs): + return super(PyDevdDebugSession, self)._new_msg_processor( + notify_debugger_ready=self._handle_vsc_debugger_ready, + **kwargs + ) + + # internal methods for VSCodeMessageProcessor + + def _handle_vsc_debugger_ready(self): + ptvsd.log.debug('Ready to debug') + self._notify_debugger_ready(self) diff --git a/adapter/python/ptvsd/socket.py b/adapter/python/ptvsd/socket.py new file mode 100644 index 0000000..7e6f26b --- /dev/null +++ b/adapter/python/ptvsd/socket.py @@ -0,0 +1,300 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import absolute_import + +from collections import namedtuple +import contextlib +import errno +import platform +import socket +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse + + +try: + ConnectionError # noqa + BrokenPipeError # noqa + ConnectionResetError # noqa +except NameError: + class BrokenPipeError(Exception): + # EPIPE and ESHUTDOWN + pass + + class ConnectionResetError(Exception): + # ECONNRESET + pass + + +NOT_CONNECTED = ( + errno.ENOTCONN, + errno.EBADF, +) + +CLOSED = ( + errno.EPIPE, + errno.ESHUTDOWN, + errno.ECONNRESET, + # Windows + 10038, # "An operation was attempted on something that is not a socket" + 10058, +) + +EOF = NOT_CONNECTED + CLOSED + + +@contextlib.contextmanager +def convert_eof(): + """A context manager to convert some socket errors into EOFError.""" + try: + yield + except ConnectionResetError: + raise EOFError + except BrokenPipeError: + raise EOFError + except OSError as exc: + if exc.errno in EOF: + raise EOFError + raise + + +class TimeoutError(socket.timeout): + """A socket timeout happened.""" + + +def is_socket(sock): + """Return True if the object can be used as a socket.""" + return isinstance(sock, socket.socket) + + +def create_server(host, port, timeout=None): + """Return a local server socket listening on the given port.""" + if host is None: + host = 'localhost' + server = _new_sock() + try: + server.bind((host, port)) + if timeout is not None: + server.settimeout(timeout) + server.listen(1) + except Exception: + server.close() + raise + return server + + +def create_client(): + """Return a client socket that may be connected to a remote address.""" + return _new_sock() + + +def _new_sock(): + sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + if platform.system() == 'Windows': + try: + sock.ioctl(socket.SIO_LOOPBACK_FAST_PATH, True) + except AttributeError: + pass # Not supported in python 2.* or <3.6 + except OSError as ose: + if ose.winerror == 10045: # Not supported by OS + pass + else: + raise + sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1) + else: + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + return sock + + +@contextlib.contextmanager +def ignored_errno(*ignored): + """A context manager that ignores the given errnos.""" + try: + yield + except OSError as exc: + if exc.errno not in ignored: + raise + + +class KeepAlive(namedtuple('KeepAlive', 'interval idle maxfails')): + """TCP keep-alive settings.""" + + INTERVAL = 3 # seconds + IDLE = 1 # seconds after idle + MAX_FAILS = 5 + + @classmethod + def from_raw(cls, raw): + """Return the corresponding KeepAlive.""" + if raw is None: + return None + elif isinstance(raw, cls): + return raw + elif isinstance(raw, (str, int, float)): + return cls(raw) + else: + try: + raw = dict(raw) + except TypeError: + return cls(*raw) + else: + return cls(**raw) + + def __new__(cls, interval=None, idle=None, maxfails=None): + self = super(KeepAlive, cls).__new__( + cls, + float(interval) if interval or interval == 0 else cls.INTERVAL, + float(idle) if idle or idle == 0 else cls.IDLE, + float(maxfails) if maxfails or maxfails == 0 else cls.MAX_FAILS, + ) + return self + + def apply(self, sock): + """Set the keepalive values on the socket.""" + sock.setsockopt(socket.SOL_SOCKET, + socket.SO_KEEPALIVE, + 1) + interval = self.interval + idle = self.idle + maxfails = self.maxfails + try: + if interval > 0: + sock.setsockopt(socket.IPPROTO_TCP, + socket.TCP_KEEPINTVL, + interval) + if idle > 0: + sock.setsockopt(socket.IPPROTO_TCP, + socket.TCP_KEEPIDLE, + idle) + if maxfails >= 0: + sock.setsockopt(socket.IPPROTO_TCP, + socket.TCP_KEEPCNT, + maxfails) + except AttributeError: + # mostly linux-only + pass + + +def connect(sock, addr, keepalive=None): + """Return the client socket for the next connection.""" + if addr is None: + if keepalive is None or keepalive is True: + keepalive = KeepAlive() + elif keepalive: + keepalive = KeepAlive.from_raw(keepalive) + client, _ = sock.accept() + if keepalive: + keepalive.apply(client) + return client + else: + if keepalive: + raise NotImplementedError + sock.connect(addr) + return sock + + +def shut_down(sock, how=socket.SHUT_RDWR, ignored=NOT_CONNECTED): + """Shut down the given socket.""" + with ignored_errno(*ignored or ()): + sock.shutdown(how) + + +def close_socket(sock): + """Shutdown and close the socket.""" + try: + shut_down(sock) + except Exception: + pass + sock.close() + + +class Address(namedtuple('Address', 'host port')): + """An IP address to use for sockets.""" + + @classmethod + def from_raw(cls, raw, defaultport=None): + """Return an address corresponding to the given data.""" + if isinstance(raw, cls): + return raw + elif isinstance(raw, int): + return cls(None, raw) + elif isinstance(raw, str): + if raw == '': + return cls('', defaultport) + parsed = urlparse(raw) + if not parsed.netloc: + if parsed.scheme: + raise ValueError('invalid address {!r}'.format(raw)) + return cls.from_raw('x://' + raw, defaultport=defaultport) + return cls( + parsed.hostname or '', + parsed.port if parsed.port else defaultport, + ) + elif not raw: + return cls(None, defaultport) + else: + try: + kwargs = dict(**raw) + except TypeError: + return cls(*raw) + else: + kwargs.setdefault('host', None) + kwargs.setdefault('port', defaultport) + return cls(**kwargs) + + @classmethod + def as_server(cls, host, port): + """Return an address to use as a server address.""" + return cls(host, port, isserver=True) + + @classmethod + def as_client(cls, host, port): + """Return an address to use as a server address.""" + return cls(host, port, isserver=False) + + def __new__(cls, host, port, **kwargs): + if host == '*': + host = '' + isserver = kwargs.pop('isserver', None) + if isserver is None: + isserver = (host is None or host == '') + else: + isserver = bool(isserver) + if host is None: + host = 'localhost' + self = super(Address, cls).__new__( + cls, + str(host), + int(port) if port is not None else None, + **kwargs + ) + self._isserver = isserver + return self + + def __init__(self, *args, **kwargs): + if self.port is None: + raise TypeError('missing port') + if self.port < 0 or self.port > 65535: + raise ValueError('port must be non-negative int < 65535') + + def __repr__(self): + orig = super(Address, self).__repr__() + return '{}, isserver={})'.format(orig[:-1], self._isserver) + + def __eq__(self, other): + if not super(Address, self).__eq__(other): + return False + try: + other = self.from_raw(other) + except Exception: + return False + return self._isserver == other._isserver + + @property + def isserver(self): + return self._isserver diff --git a/adapter/python/ptvsd/tracing.py b/adapter/python/ptvsd/tracing.py new file mode 100644 index 0000000..e99f319 --- /dev/null +++ b/adapter/python/ptvsd/tracing.py @@ -0,0 +1,88 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import absolute_import, print_function, unicode_literals + +import contextlib +import threading + +from _pydevd_bundle import pydevd_constants +from ptvsd import log + + +_tls = threading.local() + + +def tracing(should_trace=None): + """Enables or disables tracing on this thread. When called without an + argument, returns the current tracing state. + + When tracing is disabled, breakpoints will not be hit, but code executes + significantly faster. + + If debugger is not attached, this function has no effect. + + This function can also be used in a with-statement to automatically save + and then restore the previous tracing setting:: + + with ptvsd.tracing(False): + # Tracing disabled + ... + # Tracing restored + + Parameters + ---------- + should_trace : bool, optional + Whether to enable or disable tracing. + """ + + pydb = pydevd_constants.get_global_debugger() + + try: + was_tracing = _tls.is_tracing + except AttributeError: + was_tracing = pydb is not None + + if should_trace is None: + return was_tracing + + # It is possible that IDE attaches after tracing is changed, but before it is + # restored. In this case, we don't really want to restore the original value, + # because it will effectively disable tracing for the just-attached IDE. Doing + # the check outside the function below makes it so that if the original change + # was a no-op because IDE wasn't attached, restore will be no-op as well, even + # if IDE has attached by then. + + tid = threading.current_thread().ident + if pydb is None: + log.info("ptvsd.tracing() ignored on thread {0} - debugger not attached", tid) + def enable_or_disable(_): + # Always fetch the fresh value, in case it changes before we restore. + _tls.is_tracing = pydevd_constants.get_global_debugger() is not None + else: + def enable_or_disable(enable): + if enable: + log.info("Enabling tracing on thread {0}", tid) + pydb.enable_tracing() + else: + log.info("Disabling tracing on thread {0}", tid) + pydb.disable_tracing() + _tls.is_tracing = enable + + # Context managers don't do anything unless used in a with-statement - that is, + # even the code up to yield won't run. But we want callers to be able to omit + # with-statement for this function, if they don't want to restore. So, we apply + # the change directly out here in the non-generator context, so that it happens + # immediately - and then return a context manager that is solely for the purpose + # of restoring the original value, which the caller can use or discard. + + @contextlib.contextmanager + def restore_tracing(): + try: + yield + finally: + enable_or_disable(was_tracing) + + enable_or_disable(should_trace) + return restore_tracing() diff --git a/adapter/python/ptvsd/version.py b/adapter/python/ptvsd/version.py new file mode 100644 index 0000000..8f15cdd --- /dev/null +++ b/adapter/python/ptvsd/version.py @@ -0,0 +1,9 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +__author__ = "Microsoft Corporation " + +from ._version import get_versions +__version__ = get_versions()['version'] +del get_versions diff --git a/adapter/python/ptvsd/wrapper.py b/adapter/python/ptvsd/wrapper.py new file mode 100644 index 0000000..ab2f187 --- /dev/null +++ b/adapter/python/ptvsd/wrapper.py @@ -0,0 +1,1298 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, absolute_import, unicode_literals + +import copy +import errno +import json +import os +import re +import platform +import socket +import sys +import threading + +try: + import urllib + urllib.unquote +except Exception: + import urllib.parse as urllib + +try: + import queue +except ImportError: + import Queue as queue + +import warnings +import pydevd # noqa +import _pydevd_bundle.pydevd_comm as pydevd_comm # noqa +import _pydevd_bundle.pydevd_comm_constants as pydevd_comm_constants # noqa +import _pydevd_bundle.pydevd_extension_api as pydevd_extapi # noqa +import _pydevd_bundle.pydevd_extension_utils as pydevd_extutil # noqa +import _pydevd_bundle.pydevd_frame as pydevd_frame # noqa +from pydevd_file_utils import get_abs_path_real_path_and_base_from_file # noqa +from _pydevd_bundle.pydevd_dont_trace_files import PYDEV_FILE # noqa + +import ptvsd +import ptvsd.log +from ptvsd import _util +from ptvsd import multiproc +from ptvsd import options +from ptvsd.compat import unicode +import ptvsd.ipcjson as ipcjson # noqa +import ptvsd.futures as futures # noqa +from ptvsd.version import __version__ # noqa +from ptvsd.socket import TimeoutError # noqa + +WAIT_FOR_THREAD_FINISH_TIMEOUT = 1 # seconds + +debugger_attached = threading.Event() + + +def NOOP(*args, **kwargs): + pass + + +def path_to_unicode(s): + return s if isinstance(s, unicode) else s.decode(sys.getfilesystemencoding()) + + +PTVSD_DIR_PATH = os.path.dirname(os.path.abspath(get_abs_path_real_path_and_base_from_file(__file__)[0])) + os.path.sep +NORM_PTVSD_DIR_PATH = os.path.normcase(PTVSD_DIR_PATH) + + +class UnsupportedPyDevdCommandError(Exception): + + def __init__(self, cmdid): + msg = 'unsupported pydevd command ' + str(cmdid) + super(UnsupportedPyDevdCommandError, self).__init__(msg) + self.cmdid = cmdid + + +if sys.version_info >= (3,): + + def unquote(s): + return None if s is None else urllib.unquote(s) + +else: + + # In Python 2, urllib.unquote doesn't handle Unicode strings correctly, + # so we need to convert to ASCII first, unquote, and then decode. + def unquote(s): + if s is None: + return None + if not isinstance(s, bytes): + s = bytes(s) + s = urllib.unquote(s) + if isinstance(s, bytes): + s = s.decode('utf-8') + return s + + +class PydevdSocket(object): + """A dummy socket-like object for communicating with pydevd. + + It parses pydevd messages and redirects them to the provided handler + callback. It also provides an interface to send notifications and + requests to pydevd; for requests, the reply can be asynchronously + awaited. + """ + + def __init__(self, handle_msg, handle_close, getpeername, getsockname): + self._handle_msg = handle_msg + self._handle_close = handle_close + self._getpeername = getpeername + self._getsockname = getsockname + + self.lock = threading.Lock() + self.seq = 1000000000 + self.pipe_r, self.pipe_w = os.pipe() + self.requests = {} + + self._closed = False + self._closing = False + + def close(self): + """Mark the socket as closed and release any resources.""" + if self._closing: + return + + with self.lock: + if self._closed: + return + self._closing = True + + if self.pipe_w is not None: + pipe_w = self.pipe_w + self.pipe_w = None + try: + os.close(pipe_w) + except OSError as exc: + if exc.errno != errno.EBADF: + raise + if self.pipe_r is not None: + pipe_r = self.pipe_r + self.pipe_r = None + try: + os.close(pipe_r) + except OSError as exc: + if exc.errno != errno.EBADF: + raise + self._handle_close() + self._closed = True + self._closing = False + + def shutdown(self, mode): + """Called when pydevd has stopped.""" + # noop + + def getpeername(self): + """Return the remote address to which the socket is connected.""" + return self._getpeername() + + def getsockname(self): + """Return the socket's own address.""" + return self._getsockname() + + def recv(self, count): + """Return the requested number of bytes. + + This is where the "socket" sends requests to pydevd. The data + must follow the pydevd line protocol. + """ + pipe_r = self.pipe_r + if pipe_r is None: + return b'' + data = os.read(pipe_r, count) + return data + + def recv_into(self, buf): + pipe_r = self.pipe_r + if pipe_r is None: + return 0 + return os.readv(pipe_r, [buf]) + + # In Python 2, we must unquote before we decode, because UTF-8 codepoints + # are encoded first and then quoted as individual bytes. In Python 3, + # however, we just get a properly UTF-8-encoded string. + if sys.version_info < (3,): + + @staticmethod + def _decode_and_unquote(data): + return unquote(data).decode('utf8') + + else: + + @staticmethod + def _decode_and_unquote(data): + return unquote(data.decode('utf8')) + + def send(self, data): + """Handle the given bytes. + + This is where pydevd sends responses and events. The data will + follow the pydevd line protocol. + + Note that the data is always a full message received from pydevd + (sent from _pydevd_bundle.pydevd_comm.WriterThread), so, there's + no need to actually treat received bytes as a stream of bytes. + """ + result = len(data) + + # Defer logging until we have as much information about the message + # as possible - after decoding it, parsing it, determining whether + # it's a response etc. This way it can be logged in the most readable + # representation and with the most context. + # + # However, if something fails at any of those stages, we want to log + # as much as we have by then. Thus, the format string for for trace() + # is also constructed dynamically, reflecting the available info. + + trace_prefix = 'PYD --> ' + trace_fmt = '{data}' + + try: + if data.startswith(b'{'): # JSON + data = data.decode('utf-8') + data = json.loads(data) + trace_fmt = '{data!j}' + cmd_id = data['pydevd_cmd_id'] + if 'request_seq' in data: + seq = data['request_seq'] + else: + seq = data['seq'] + args = data + else: + assert data.endswith(b'\n') + data = self._decode_and_unquote(data[:-1]) + cmd_id, seq, args = data.split('\t', 2) + if ptvsd.log.is_enabled(): + trace_fmt = '{cmd_name} {seq}\n{args}' + except: + ptvsd.log.exception(trace_prefix + trace_fmt, data=data) + raise + + seq = int(seq) + cmd_id = int(cmd_id) + try: + cmd_name = pydevd_comm.ID_TO_MEANING[str(cmd_id)] + except KeyError: + cmd_name = cmd_id + + with self.lock: + loop, fut, requesting_handler = self.requests.pop(seq, (None, None, None)) + + if requesting_handler is not None: + trace_prefix = '(requested while handling {requesting_handler})\n' + trace_prefix + ptvsd.log.debug( + trace_prefix + trace_fmt, + data=data, + cmd_id=cmd_id, + cmd_name=cmd_name, + seq=seq, + args=args, + requesting_handler=requesting_handler, + ) + + if fut is None: + with ptvsd.log.handling((cmd_name, seq)): + self._handle_msg(cmd_id, seq, args) + else: + loop.call_soon_threadsafe(fut.set_result, (cmd_id, seq, args)) + + return result + + sendall = send + + def makefile(self, *args, **kwargs): + """Return a file-like wrapper around the socket.""" + return os.fdopen(self.pipe_r) + + def make_packet(self, cmd_id, args): + assert not isinstance(args, bytes) + with self.lock: + seq = self.seq + self.seq += 1 + + if ptvsd.log.is_enabled(): + try: + cmd_name = pydevd_comm.ID_TO_MEANING[str(cmd_id)] + except KeyError: + cmd_name = cmd_id + ptvsd.log.debug('PYD <-- {0} {1} {2}', cmd_name, seq, args) + + s = '{}\t{}\t{}\n'.format(cmd_id, seq, args) + return seq, s + + def make_json_packet(self, cmd_id, args): + assert isinstance(args, dict) + with self.lock: + seq = self.seq + self.seq += 1 + args['seq'] = seq + + ptvsd.log.debug('PYD <-- {0!j}', args) + + s = json.dumps(args) + return seq, s + + def pydevd_notify(self, cmd_id, args, is_json=False): + if self.pipe_w is None: + raise EOFError + if is_json: + seq, s = self.make_json_packet(cmd_id, args) + else: + seq, s = self.make_packet(cmd_id, args) + with self.lock: + as_bytes = s + if not isinstance(as_bytes, bytes): + as_bytes = as_bytes.encode('utf-8') + if is_json: + os.write(self.pipe_w, ('Content-Length:%s\r\n\r\n' % (len(as_bytes),)).encode('ascii')) + os.write(self.pipe_w, as_bytes) + + def pydevd_request(self, loop, cmd_id, args, is_json=False): + ''' + If is_json == True the args are expected to be a dict to be + json-serialized with the request, otherwise it's expected + to be the text (to be concatenated with the command id and + seq in the pydevd line-based protocol). + ''' + if self.pipe_w is None: + raise EOFError + if is_json: + seq, s = self.make_json_packet(cmd_id, args) + else: + seq, s = self.make_packet(cmd_id, args) + fut = loop.create_future() + + with self.lock: + self.requests[seq] = loop, fut, ptvsd.log.current_handler() + as_bytes = s + if not isinstance(as_bytes, bytes): + as_bytes = as_bytes.encode('utf-8') + if is_json: + os.write(self.pipe_w, ('Content-Length:%s\r\n\r\n' % (len(as_bytes),)).encode('ascii')) + os.write(self.pipe_w, as_bytes) + + return fut + +######################## +# the debug config + + +def bool_parser(str): + return str in ("True", "true", "1") + + +DEBUG_OPTIONS_PARSER = { + 'WAIT_ON_ABNORMAL_EXIT': bool_parser, + 'WAIT_ON_NORMAL_EXIT': bool_parser, + 'BREAK_SYSTEMEXIT_ZERO': bool_parser, + 'REDIRECT_OUTPUT': bool_parser, + 'VERSION': unquote, + 'INTERPRETER_OPTIONS': unquote, + 'WEB_BROWSER_URL': unquote, + 'DJANGO_DEBUG': bool_parser, + 'FLASK_DEBUG': bool_parser, + 'FIX_FILE_PATH_CASE': bool_parser, + 'CLIENT_OS_TYPE': unquote, + 'DEBUG_STDLIB': bool_parser, + 'STOP_ON_ENTRY': bool_parser, + 'SHOW_RETURN_VALUE': bool_parser, + 'MULTIPROCESS': bool_parser, +} + +DEBUG_OPTIONS_BY_FLAG = { + 'RedirectOutput': 'REDIRECT_OUTPUT=True', + 'WaitOnNormalExit': 'WAIT_ON_NORMAL_EXIT=True', + 'WaitOnAbnormalExit': 'WAIT_ON_ABNORMAL_EXIT=True', + 'BreakOnSystemExitZero': 'BREAK_SYSTEMEXIT_ZERO=True', + 'Django': 'DJANGO_DEBUG=True', + 'Flask': 'FLASK_DEBUG=True', + 'Jinja': 'FLASK_DEBUG=True', + 'FixFilePathCase': 'FIX_FILE_PATH_CASE=True', + 'DebugStdLib': 'DEBUG_STDLIB=True', + 'WindowsClient': 'CLIENT_OS_TYPE=WINDOWS', + 'UnixClient': 'CLIENT_OS_TYPE=UNIX', + 'StopOnEntry': 'STOP_ON_ENTRY=True', + 'ShowReturnValue': 'SHOW_RETURN_VALUE=True', + 'Multiprocess': 'MULTIPROCESS=True', +} + + +def _extract_debug_options(opts, flags=None): + """Return the debug options encoded in the given value. + + "opts" is a semicolon-separated string of "key=value" pairs. + "flags" is a list of strings. + + If flags is provided then it is used as a fallback. + + The values come from the launch config: + + { + type:'python', + request:'launch'|'attach', + name:'friendly name for debug config', + debugOptions:[ + 'RedirectOutput', 'Django' + ], + options:'REDIRECT_OUTPUT=True;DJANGO_DEBUG=True' + } + + Further information can be found here: + + https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes + """ + if not opts: + opts = _build_debug_options(flags) + return _parse_debug_options(opts) + + +def _build_debug_options(flags): + """Build string representation of debug options from the launch config.""" + return ';'.join(DEBUG_OPTIONS_BY_FLAG[flag] + for flag in flags or [] + if flag in DEBUG_OPTIONS_BY_FLAG) + + +def _parse_debug_options(opts): + """Debug options are semicolon separated key=value pairs + WAIT_ON_ABNORMAL_EXIT=True|False + WAIT_ON_NORMAL_EXIT=True|False + BREAK_SYSTEMEXIT_ZERO=True|False + REDIRECT_OUTPUT=True|False + VERSION=string + INTERPRETER_OPTIONS=string + WEB_BROWSER_URL=string url + DJANGO_DEBUG=True|False + CLIENT_OS_TYPE=WINDOWS|UNIX + DEBUG_STDLIB=True|False + """ + options = {} + if not opts: + return options + + for opt in opts.split(';'): + try: + key, value = opt.split('=') + except ValueError: + continue + try: + options[key] = DEBUG_OPTIONS_PARSER[key](value) + except KeyError: + continue + + return options + +######################## +# the message processor + +# TODO: Embed instead of extend (inheritance -> composition). + + +class VSCodeMessageProcessorBase(ipcjson.SocketIO, ipcjson.IpcChannel): + """The base class for VSC message processors.""" + + def __init__(self, socket, notify_closing, timeout=None, own_socket=False): + super(VSCodeMessageProcessorBase, self).__init__( + socket=socket, + own_socket=False, + timeout=timeout, + ) + self.socket = socket + self._own_socket = own_socket + self._notify_closing = notify_closing + + self.server_thread = None + self._closing = False + self._closed = False + self.readylock = threading.Lock() + self.readylock.acquire() # Unlock at the end of start(). + + self._connected = threading.Lock() + self._listening = None + self._connlock = threading.Lock() + + @property + def connected(self): # may send responses/events + with self._connlock: + return _util.is_locked(self._connected) + + @property + def closed(self): + return self._closed or self._closing + + @property + def listening(self): + # TODO: must be disconnected? + with self._connlock: + if self._listening is None: + return False + return _util.is_locked(self._listening) + + def wait_while_connected(self, timeout=None): + """Wait until the client socket is disconnected.""" + with self._connlock: + lock = self._listening + _util.lock_wait(lock, timeout) # Wait until no longer connected. + + def wait_while_listening(self, timeout=None): + """Wait until no longer listening for incoming messages.""" + with self._connlock: + lock = self._listening + if lock is None: + raise RuntimeError('not listening yet') + _util.lock_wait(lock, timeout) # Wait until no longer listening. + + def start(self, threadname): + # event loop + self._start_event_loop() + + # VSC msg processing loop + def process_messages(): + self.readylock.acquire() + with self._connlock: + self._listening = threading.Lock() + try: + self.process_messages() + except (EOFError, TimeoutError): + ptvsd.log.exception('Client socket closed', category='I') + with self._connlock: + _util.lock_release(self._listening) + _util.lock_release(self._connected) + self.close() + except socket.error as exc: + if exc.errno == errno.ECONNRESET: + ptvsd.log.exception('Client socket forcibly closed', category='I') + with self._connlock: + _util.lock_release(self._listening) + _util.lock_release(self._connected) + self.close() + else: + raise exc + + self.server_thread = _util.new_hidden_thread( + target=process_messages, + name=threadname, + ) + self.server_thread.start() + + # special initialization + self.send_event( + 'output', + category='telemetry', + output='ptvsd', + data={'version': __version__}, + ) + self.readylock.release() + + def close(self): + """Stop the message processor and release its resources.""" + if self.closed: + return + self._closing = True + ptvsd.log.debug('Raw closing') + + self._notify_closing() + # Close the editor-side socket. + self._stop_vsc_message_loop() + + # Ensure that the connection is marked as closed. + with self._connlock: + _util.lock_release(self._listening) + _util.lock_release(self._connected) + self._closed = True + + # VSC protocol handlers + + def send_error_response(self, request, message=None): + self.send_response( + request, + success=False, + message=message + ) + + # internal methods + + def _set_disconnected(self): + with self._connlock: + _util.lock_release(self._connected) + + def _wait_for_server_thread(self): + if self.server_thread is None: + return + if not self.server_thread.is_alive(): + return + self.server_thread.join(WAIT_FOR_THREAD_FINISH_TIMEOUT) + + def _stop_vsc_message_loop(self): + self.set_exit() + self._stop_event_loop() + if self.socket is not None and self._own_socket: + try: + self.socket.shutdown(socket.SHUT_RDWR) + self.socket.close() + self._set_disconnected() + except Exception: + ptvsd.log.exception('Error on socket shutdown') + + # methods for subclasses to override + + def _start_event_loop(self): + pass + + def _stop_event_loop(self): + pass + + +INITIALIZE_RESPONSE = dict( + supportsCompletionsRequest=True, + supportsConditionalBreakpoints=True, + supportsConfigurationDoneRequest=True, + supportsDebuggerProperties=True, + supportsDelayedStackTraceLoading=True, + supportsEvaluateForHovers=True, + supportsExceptionInfoRequest=True, + supportsExceptionOptions=True, + supportsHitConditionalBreakpoints=True, + supportsLogPoints=True, + supportsModulesRequest=True, + supportsSetExpression=True, + supportsSetVariable=True, + supportsValueFormattingOptions=True, + supportTerminateDebuggee=True, + supportsGotoTargetsRequest=True, + exceptionBreakpointFilters=[ + { + 'filter': 'raised', + 'label': 'Raised Exceptions', + 'default': False + }, + { + 'filter': 'uncaught', + 'label': 'Uncaught Exceptions', + 'default': True + }, + ], +) + + +class VSCLifecycleMsgProcessor(VSCodeMessageProcessorBase): + """Handles adapter lifecycle messages of the VSC debugger protocol.""" + + EXITWAIT = 1 + + def __init__( + self, socket, notify_disconnecting, notify_closing, + notify_launch=None, notify_ready=None, timeout=None, debugging=True, + ): + super(VSCLifecycleMsgProcessor, self).__init__( + socket=socket, + notify_closing=notify_closing, + timeout=timeout, + ) + self._notify_launch = notify_launch or NOOP + self._notify_ready = notify_ready or NOOP + self._notify_disconnecting = notify_disconnecting + + self._stopped = False + + # These are needed to handle behavioral differences between VS and VSC + # https://github.com/Microsoft/VSDebugAdapterHost/wiki/Differences-between-Visual-Studio-Code-and-the-Visual-Studio-Debug-Adapter-Host # noqa + # VS expects a single stopped event in a multi-threaded scenario. + self._client_id = None + self._initialize_received = False + + # adapter state + self.start_reason = None + self.debug_options = {} + self._statelock = threading.Lock() + self._debugging = debugging + self._debuggerstopped = False + self._restart_debugger = False + self._exitlock = threading.Lock() + self._exitlock.acquire() # released in handle_exiting() + self._exiting = False + + def handle_debugger_stopped(self, wait=None): + """Deal with the debugger exiting.""" + # Notify the editor that the debugger has stopped. + if not self._debugging: + # TODO: Fail? If this gets called then we must be debugging. + return + + # We run this in a thread to allow handle_exiting() to be called + # at the same time. + def stop(): + if wait is not None: + wait() + # Since pydevd is embedded in the debuggee process, always + # make sure the exited event is sent first. + self._wait_until_exiting(self.EXITWAIT) + self._ensure_debugger_stopped() + + t = _util.new_hidden_thread( + target=stop, + name='stopping', + daemon=False, + ) + t.start() + + def handle_exiting(self, exitcode=None, wait=None): + """Deal with the debuggee exiting.""" + with self._statelock: + if self._exiting: + return + self._exiting = True + + # Notify the editor that the "debuggee" (e.g. script, app) exited. + self.send_event('exited', exitCode=exitcode or 0) + + self._waiting = True + if wait is not None and self.start_reason == 'launch': + normal, abnormal = self._wait_options() + cfg = (normal and not exitcode) or (abnormal and exitcode) + # This must be done before we send a disconnect response + # (which implies before we close the client socket). + wait(cfg) + + # If we are exiting then pydevd must have stopped. + self._ensure_debugger_stopped() + + if self._exitlock is not None: + _util.lock_release(self._exitlock) + + # VSC protocol handlers + + def on_initialize(self, request, args): + self._client_id = args.get('clientID', None) + self._restart_debugger = False + self._initialize_received = True + self.send_response(request, **INITIALIZE_RESPONSE) + self.send_event('initialized') + + def on_attach(self, request, args): + multiproc.root_start_request = request + self.start_reason = 'attach' + self._set_debug_options(args) + self._handle_launch_or_attach(request, args) + self.send_response(request) + + def on_launch(self, request, args): + multiproc.root_start_request = request + self.start_reason = 'launch' + self._set_debug_options(args) + self._notify_launch() + self._handle_launch_or_attach(request, args) + self.send_response(request) + + def on_disconnect(self, request, args): + multiproc.kill_subprocesses() + + debugger_attached.clear() + self._restart_debugger = args.get('restart', False) + + # TODO: docstring + if self._debuggerstopped: # A "terminated" event must have been sent. + self._wait_until_exiting(self.EXITWAIT) + + status = {'sent': False} + + def disconnect_response(): + if status['sent']: + return + self.send_response(request) + status['sent'] = True + + self._notify_disconnecting( + pre_socket_close=disconnect_response, + ) + disconnect_response() + + self._set_disconnected() + + if self.start_reason == 'attach': + if not self._debuggerstopped: + self._handle_detach() + # TODO: We should be able drop the "launch" branch. + elif self.start_reason == 'launch': + if not self.closed: + # Closing the socket causes pydevd to resume all threads, + # so just terminate the process altogether. + sys.exit(0) + + # internal methods + + def _set_debug_options(self, args): + self.debug_options = _extract_debug_options( + args.get('options'), + args.get('debugOptions'), + ) + + def _ensure_debugger_stopped(self): + if not self._debugging: + return + with self._statelock: + if self._debuggerstopped: + return + self._debuggerstopped = True + if not self._restart_debugger: + # multiproc.initial_request = None + self.send_event('terminated') + + def _wait_until_exiting(self, timeout): + lock = self._exitlock + if lock is None: + return + try: + _util.lock_wait(lock, timeout, 'waiting for process exit') + except _util.TimeoutError as exc: + warnings.warn(str(exc)) + + # methods related to shutdown + + def _wait_options(self): + normal = self.debug_options.get('WAIT_ON_NORMAL_EXIT', False) + abnormal = self.debug_options.get('WAIT_ON_ABNORMAL_EXIT', False) + return normal, abnormal + + # methods for subclasses to override + + def _process_debug_options(self, opts): + pass + + def _handle_configurationDone(self, request, args): + pass + + def _handle_launch_or_attach(self, request, args): + pass + + def _handle_detach(self): + pass + + +class VSCodeMessageProcessor(VSCLifecycleMsgProcessor): + """IPC JSON message processor for VSC debugger protocol. + + This translates between the VSC debugger protocol and the pydevd + protocol. + """ + + def __init__( + self, socket, pydevd_notify, pydevd_request, + notify_debugger_ready, + notify_disconnecting, notify_closing, + timeout=None, + ): + super(VSCodeMessageProcessor, self).__init__( + socket=socket, + notify_disconnecting=notify_disconnecting, + notify_closing=notify_closing, + timeout=timeout, + ) + self._pydevd_notify = pydevd_notify + self._pydevd_request = pydevd_request + self._notify_debugger_ready = notify_debugger_ready + + self._client_os_type = 'WINDOWS' if platform.system() == 'Windows' else 'UNIX' + + self.loop = None + self.event_loop_thread = None + + # adapter state + self._detached = False + self._path_mappings_received = False + self._path_mappings_applied = False + + def _start_event_loop(self): + self.loop = futures.EventLoop() + self.event_loop_thread = _util.new_hidden_thread( + target=self.loop.run_forever, + name='EventLoop', + ) + self.event_loop_thread.start() + + def _stop_event_loop(self): + self.loop.stop() + self.event_loop_thread.join(WAIT_FOR_THREAD_FINISH_TIMEOUT) + + def start(self, threadname): + super(VSCodeMessageProcessor, self).start(threadname) + if options.multiprocess: + self.start_subprocess_notifier() + + def start_subprocess_notifier(self): + self._subprocess_notifier_thread = _util.new_hidden_thread('SubprocessNotifier', self._subprocess_notifier) + self._subprocess_notifier_thread.start() + + def close(self): + super(VSCodeMessageProcessor, self).close() + if options.multiprocess: + self._subprocess_notifier_thread.join() + + def _subprocess_notifier(self): + while not self.closed: + try: + subprocess_request, subprocess_response = multiproc.subprocess_queue.get(timeout=0.1) + except queue.Empty: + continue + + try: + self.send_event('ptvsd_subprocess', **subprocess_request) + except Exception: + pass + else: + subprocess_response['incomingConnection'] = True + + multiproc.subprocess_queue.task_done() + + # async helpers + + def async_method(m): + """Converts a generator method into an async one.""" + m = futures.wrap_async(m) + + def f(self, *args, **kwargs): + return m(self, self.loop, *args, **kwargs) + + return f + + def async_handler(m): + """Converts a generator method into a fire-and-forget async one.""" + m = futures.wrap_async(m) + + def f(self, *args, **kwargs): + return m(self, self.loop, *args, **kwargs) + + return f + + def sleep(self): + fut = futures.Future(self.loop) + self.loop.call_soon(lambda: fut.set_result(None)) + return fut + + # PyDevd "socket" entry points (and related helpers) + + def pydevd_notify(self, cmd_id, args, is_json=False): + return self._pydevd_notify(cmd_id, args, is_json=is_json) + + def pydevd_request(self, cmd_id, args, is_json=False): + return self._pydevd_request(self.loop, cmd_id, args, is_json=is_json) + + # Instances of this class provide decorators to mark methods as + # handlers for various # pydevd messages - a decorated method is + # added to the map with the corresponding message ID, and is + # looked up there by pydevd event handler below. + class EventHandlers(dict): + + def handler(self, cmd_id): + + def decorate(f): + self[cmd_id] = f + return f + + return decorate + + pydevd_events = EventHandlers() + + def on_pydevd_event(self, cmd_id, seq, args): + if not self._detached: + try: + try: + f = self.pydevd_events[cmd_id] + except KeyError: + raise UnsupportedPyDevdCommandError(cmd_id) + return f(self, seq, args) + except: + ptvsd.log.exception('Error handling pydevd event: {0}', args) + raise + else: + return None + + def _wait_for_pydevd_ready(self): + pass + + def _ensure_pydevd_requests_handled(self): + pass + + # VSC protocol handlers + + @async_handler + def on_configurationDone(self, request, args): + self._process_debug_options(self.debug_options) + + self._forward_request_to_pydevd(request, args, send_response=False) + debugger_attached.set() + + self._notify_debugger_ready() + + self._notify_ready() + self.send_response(request) + + def _process_debug_options(self, opts): + """Process the launch arguments to configure the debugger.""" + if opts.get('MULTIPROCESS', False): + if not options.multiprocess: + options.multiprocess = True + multiproc.listen_for_subprocesses() + self.start_subprocess_notifier() + + def _get_new_setDebuggerProperty_request(self, **kwargs): + return { + "command": "setDebuggerProperty", + "arguments": kwargs, + "type": "request", + # "seq": seq_id, # A new seq should be created for pydevd. + } + + @async_handler + def _handle_launch_or_attach(self, request, args): + self._path_mappings_received = True + + client_os_type = self.debug_options.get('CLIENT_OS_TYPE', '').upper().strip() + if client_os_type and client_os_type not in ('WINDOWS', 'UNIX'): + ptvsd.log.warn('Invalid CLIENT_OS_TYPE passed: %s (must be either "WINDOWS" or "UNIX").' % (client_os_type,)) + client_os_type = '' + + if not client_os_type: + for pathMapping in args.get('pathMappings', []): + localRoot = pathMapping.get('localRoot', '') + if localRoot: + if localRoot.startswith('/'): + client_os_type = 'UNIX' + break + + if re.match('^([a-zA-Z]):', localRoot): # Match drive letter + client_os_type = 'WINDOWS' + break + + if not client_os_type: + client_os_type = 'WINDOWS' if platform.system() == 'Windows' else 'UNIX' + + self._client_os_type = client_os_type + + dont_trace_request = self._get_new_setDebuggerProperty_request( + dontTraceStartPatterns=[PTVSD_DIR_PATH], + dontTraceEndPatterns=['ptvsd_launcher.py'], + skipSuspendOnBreakpointException=('BaseException',), + skipPrintBreakpointException=('NameError',), + multiThreadsSingleNotification=True, + ideOS=self._client_os_type, + ) + yield self.pydevd_request(-1, dont_trace_request, is_json=True) + + pydevd_request = copy.deepcopy(request) + del pydevd_request['seq'] # A new seq should be created for pydevd. + yield self.pydevd_request(-1, pydevd_request, is_json=True) + + self._path_mappings_applied = True + + def _handle_detach(self): + ptvsd.log.info('Detaching ...') + # TODO: Skip if already detached? + self._detached = True + + # No related pydevd command id (removes all breaks and resumes threads). + self.pydevd_request( + -1, + {"command": "disconnect", "arguments": {}, "type": "request"}, + is_json=True + ) + + @async_handler + def _resume_all_threads(self): + request = { + "command": "continue", + "arguments": {"threadId": "*"}, + "type": "request" + } + yield self.pydevd_request(-1, request, is_json=True) + + @async_handler + def _forward_request_to_pydevd(self, request, args, send_response=True): + pydevd_request = copy.deepcopy(request) + del pydevd_request['seq'] # A new seq should be created for pydevd. + cmd_id = -1 # It's actually unused on json requests. + _, _, resp_args = yield self.pydevd_request(cmd_id, pydevd_request, is_json=True) + + if send_response: + if not resp_args.get('success'): + self.send_error_response(request, message=resp_args.get('message', '')) + else: + body = resp_args.get('body') + if body is None: + body = {} + self.send_response(request, **body) + + def on_threads(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_source(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_stackTrace(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_scopes(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_variables(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_setVariable(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_evaluate(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_setExpression(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_modules(self, request, args): + self._forward_request_to_pydevd(request, args) + + @async_handler + def on_pause(self, request, args): + # Pause requests cannot be serviced until pydevd is fully initialized. + if not debugger_attached.isSet(): + self.send_response( + request, + success=False, + message='Cannot pause while debugger is initializing', + ) + return + + pydevd_request = copy.deepcopy(request) + del pydevd_request['seq'] # A new seq should be created for pydevd. + try: + pydevd_request['arguments']['threadId'] = '*' + except KeyError: + pydevd_request['arguments'] = {'threadId': '*'} + + # Always suspend all threads. + self.pydevd_request(pydevd_comm.CMD_THREAD_SUSPEND, + pydevd_request, is_json=True) + self.send_response(request) + + @async_handler + def on_continue(self, request, args): + + pydevd_request = copy.deepcopy(request) + del pydevd_request['seq'] # A new seq should be created for pydevd. + try: + pydevd_request['arguments']['threadId'] = '*' + except KeyError: + pydevd_request['arguments'] = {'threadId': '*'} + + # Always continue all threads. + self.pydevd_request(pydevd_comm.CMD_THREAD_RUN, + pydevd_request, is_json=True) + self.send_response(request, allThreadsContinued=True) + + def on_next(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_stepIn(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_stepOut(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_gotoTargets(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_goto(self, request, args): + self._forward_request_to_pydevd(request, args) + + @async_handler + def on_setBreakpoints(self, request, args): + if not self._path_mappings_received: + self.send_error_response(request, "'setBreakpoints' request must be issued after 'launch' or 'attach' request.") + return + + # There might be a concurrent 'launch' or 'attach' request in flight that hasn't + # gotten to processing path mappings yet. If so, spin until it finishes that. + while not self._path_mappings_applied: + yield self.sleep() + + self._forward_request_to_pydevd(request, args) + + def on_setExceptionBreakpoints(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_exceptionInfo(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_completions(self, request, args): + self._forward_request_to_pydevd(request, args) + + def on_setPydevdSourceMap(self, request, args): + self._forward_request_to_pydevd(request, args) + + # Custom ptvsd message + @async_handler + def on_ptvsd_systemInfo(self, request, args): + sys_info = { + 'ptvsd': { + 'version': __version__, + }, + } + pydevd_request = copy.deepcopy(request) + pydevd_request['command'] = 'pydevdSystemInfo' + del pydevd_request['seq'] # A new seq should be created for pydevd. + cmd_id = -1 # It's actually unused on json requests. + _, _, resp_args = yield self.pydevd_request(cmd_id, pydevd_request, is_json=True) + + if not resp_args.get('success'): + self.send_error_response(request, message=resp_args.get('message', '')) + else: + body = resp_args.get('body') + if body is None: + body = {} + sys_info.update(body) + self.send_response(request, **sys_info) + + # VS specific custom message handlers + + def on_setDebuggerProperty(self, request, args): + if 'JustMyCodeStepping' in args: + jmc = int(args.get('JustMyCodeStepping', 0)) > 0 + self.debug_options['DEBUG_STDLIB'] = not jmc + + # TODO: Replace the line below with _forward_request_to_pydevd + # after fixing https://github.com/Microsoft/ptvsd/issues/1355 + self.send_response(request) + + # PyDevd protocol event handlers + + @pydevd_events.handler(pydevd_comm.CMD_MODULE_EVENT) + def on_pydevd_module_event(self, seq, args): + body = args.get('body', {}) + self.send_event('module', **body) + + @pydevd_events.handler(pydevd_comm.CMD_INPUT_REQUESTED) + def on_pydevd_input_requested(self, seq, args): + ''' + no-op: if stdin is requested, right now the user is expected to enter + text in the terminal and the debug adapter doesn't really do anything + (although in the future it could see that stdin is being requested and + redirect any evaluation request to stdin). + ''' + + @pydevd_events.handler(pydevd_comm.CMD_THREAD_CREATE) + def on_pydevd_thread_create(self, seq, args): + ''' + :param args: dict. + i.e.: + { + 'type': 'event', + 'event': 'thread', + 'seq': 4, + 'pydevd_cmd_id': 103 + 'body': {'reason': 'started', 'threadId': 'pid_9236_id_2714288164368'}, + } + ''' + # When we receive the thread on tests (due to a threads request), it's possible + # that the `debugger_attached` is still unset (but we should report about the + # thread creation anyways). + tid = args['body']['threadId'] + self.send_event('thread', reason='started', threadId=tid) + + @pydevd_events.handler(pydevd_comm.CMD_THREAD_KILL) + def on_pydevd_thread_kill(self, seq, args): + tid = args['body']['threadId'] + self.send_event('thread', reason='exited', threadId=tid) + + @pydevd_events.handler(pydevd_comm.CMD_PROCESS_EVENT) + def on_pydevd_process_event(self, seq, args): + body = args['body'] + self.send_event('process', **body) + + @pydevd_events.handler(pydevd_comm_constants.CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION) + def on_pydevd_thread_suspend_single_notification(self, seq, args): + body = args['body'] + self.send_event('stopped', **body) + + @pydevd_events.handler(pydevd_comm_constants.CMD_THREAD_RESUME_SINGLE_NOTIFICATION) + def on_pydevd_thread_resume_single_notification(self, seq, args): + if not self._initialize_received: + return # This may happen when we disconnect and later reconnect too fast. + body = args['body'] + if self._client_id not in ('visualstudio', 'vsformac'): + # In visual studio any step/continue action already marks all the + # threads as running until a suspend, so, the continued is not + # needed (and can in fact break the UI in some cases -- see: + # https://github.com/microsoft/ptvsd/issues/1358). + # It is however needed in vscode -- see: + # https://github.com/microsoft/ptvsd/issues/1530. + self.send_event('continued', **body) + + @pydevd_events.handler(pydevd_comm.CMD_WRITE_TO_CONSOLE) + def on_pydevd_cmd_write_to_console2(self, seq, args): + """Handle console output""" + body = args.get('body', {}) + self.send_event('output', **body) diff --git a/adapter/util.py b/adapter/util.py new file mode 100644 index 0000000..b495a7e --- /dev/null +++ b/adapter/util.py @@ -0,0 +1,152 @@ + +from os.path import abspath, join, dirname, basename, split +from threading import Timer +from datetime import datetime +import json + +# Debugging this adapter +debug = True +log_file = abspath(join(dirname(__file__), 'log.txt')) + +if debug: + open(log_file, 'w+').close() # Creates and/or clears the file + +ptvsd_path = join(abspath(dirname(__file__)), "python") + + +# --- Utility functions --- # + +def log(msg, json_msg=None): + if debug: + + if json_msg: + msg += '\n' + json.dumps(json.loads(json_msg), indent=4) + + with open(log_file, 'a+') as f: + f.write('\n' + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " - " + msg + '\n') + + +def run(func, args=None, time=0.01): + Timer(time, func, args=args).start() + + +# --- Resources --- # + +# From https://github.com/cb109/sublime3dsmax/blob/master/constants.py +TITLE_IDENTIFIER = "Autodesk 3ds Max" +RECORDER_NOT_FOUND = "Could not find MAXScript Macro Recorder" + +# Own constants +ATTACH_TEMPLATE = """ +import sys +import os +ptvsd_module = r"{ptvsd_path}" +if ptvsd_module not in sys.path: + sys.path.insert(0, ptvsd_module) + +import ptvsd + +ptvsd.enable_attach(("{hostname}",{port})) + +print('\\n --- Successfully attached to Sublime Debugger --- \\n') +""" + +# Used to run the module +RUN_TEMPLATE = """ +try: + current_directory = r"{dir}" + if current_directory not in sys.path: + sys.path.insert(0, current_directory) + + print(' --- Debugging {file_name}... --- \\n') + if '{file_name}' not in globals().keys(): + import {file_name} + else: + reload({file_name}) + + print(' --- Finished debugging {file_name} --- \\n') + + open("{signal_location}", "w").close() # Create this file to let the adapter know debugging is finished + +except Exception as e: + print('Error while debugging: ' + str(e)) + raise e +""" + +CONTENT_HEADER = "Content-Length: " + +INITIALIZE_RESPONSE = """{ + "request_seq": 1, + "body": { + "supportsModulesRequest": true, + "supportsConfigurationDoneRequest": true, + "supportsDelayedStackTraceLoading": true, + "supportsDebuggerProperties": true, + "supportsEvaluateForHovers": true, + "supportsSetExpression": true, + "supportsGotoTargetsRequest": true, + "supportsExceptionOptions": true, + "exceptionBreakpointFilters": [ + { + "filter": "raised", + "default": false, + "label": "Raised Exceptions" + }, + { + "filter": "uncaught", + "default": true, + "label": "Uncaught Exceptions" + } + ], + "supportsCompletionsRequest": true, + "supportsExceptionInfoRequest": true, + "supportsLogPoints": true, + "supportsValueFormattingOptions": true, + "supportsHitConditionalBreakpoints": true, + "supportsSetVariable": true, + "supportTerminateDebuggee": true, + "supportsConditionalBreakpoints": true + }, + "seq": 1, + "success": true, + "command": "initialize", + "message": "", + "type": "response" +}""" + +ATTACH_ARGS = """{{ + "name": "3ds Max Python Debugger : Remote Attach", + "type": "python", + "request": "attach", + "port": {port}, + "host": "{hostname}", + "pathMappings": [ + {{ + "localRoot": "{dir}", + "remoteRoot": "{dir}" + }} + ], + "MaxDebugFile": "{filepath}" +}}""" + +EXEC_COMMAND = """python("execfile('{tmp_file_path}')")""" + +PAUSE_REQUEST = """{{ + "command": "pause", + "arguments": {{ + "threadId": 1 + }}, + "seq": {seq}, + "type": "request" +}}""" + +# DISCONNECT_RESPONSE = """{{ +# "request_seq": {req_seq}, +# "body": {{}}, +# "seq": {seq}, +# "success": true, +# "command": "disconnect", +# "message": "", +# "type": "response" +# }}""" + diff --git a/adapter/winapi.py b/adapter/winapi.py new file mode 100644 index 0000000..1c5456d --- /dev/null +++ b/adapter/winapi.py @@ -0,0 +1,545 @@ +# Copyright (c) 2009-2014, Mario Vilas +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice,this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +""" +Portions of code from winappdbg, using only the parts we need, ported to +Python 3.3. + +Modified by Daniel Santana, all the copyrights belong to Mario Vilas. +""" +from __future__ import (print_function, absolute_import, + unicode_literals, with_statement) + +import ctypes + +LPVOID = ctypes.c_void_p +CHAR = ctypes.c_char +WCHAR = ctypes.c_wchar +BYTE = ctypes.c_ubyte +SBYTE = ctypes.c_byte +WORD = ctypes.c_uint16 +SWORD = ctypes.c_int16 +DWORD = ctypes.c_uint32 +SDWORD = ctypes.c_int32 +QWORD = ctypes.c_uint64 +SQWORD = ctypes.c_int64 +SHORT = ctypes.c_short +USHORT = ctypes.c_ushort +INT = ctypes.c_int +UINT = ctypes.c_uint +LONG = ctypes.c_long +ULONG = ctypes.c_ulong +LONGLONG = ctypes.c_int64 # c_longlong +ULONGLONG = ctypes.c_uint64 # c_ulonglong +LPSTR = ctypes.c_char_p +LPWSTR = ctypes.c_wchar_p +INT8 = ctypes.c_int8 +INT16 = ctypes.c_int16 +INT32 = ctypes.c_int32 +INT64 = ctypes.c_int64 +UINT8 = ctypes.c_uint8 +UINT16 = ctypes.c_uint16 +UINT32 = ctypes.c_uint32 +UINT64 = ctypes.c_uint64 +LONG32 = ctypes.c_int32 +LONG64 = ctypes.c_int64 +ULONG32 = ctypes.c_uint32 +ULONG64 = ctypes.c_uint64 +DWORD32 = ctypes.c_uint32 +DWORD64 = ctypes.c_uint64 +BOOL = ctypes.c_int +FLOAT = ctypes.c_float +PVOID = LPVOID +HANDLE = LPVOID +HWND = HANDLE +addressof = ctypes.addressof +sizeof = ctypes.sizeof +SIZEOF = ctypes.sizeof +POINTER = ctypes.POINTER +Structure = ctypes.Structure +Union = ctypes.Union +WINFUNCTYPE = ctypes.WINFUNCTYPE +windll = ctypes.windll +WNDENUMPROC = WINFUNCTYPE(BOOL, HWND, PVOID) +NULL = None +INFINITE = -1 +TRUE = 1 +FALSE = 0 +WPARAM = DWORD +LPARAM = LPVOID +LRESULT = LPVOID +ERROR_SUCCESS = 0 +ERROR_NO_MORE_FILES = 18 + +WM_SETTEXT = 0x000C +WM_KEYDOWN = 0x0100 +WM_KEYUP = 0x0101 +WM_CHAR = 0x0102 # The alternative to WM_KEYDOWN +VK_RETURN = 0x0D # Enter key + + +class GuessStringType(object): + """ + Decorator that guesses the correct version (A or W) to call + based on the types of the strings passed as parameters. + + Calls the B{ANSI} version if the only string types are ANSI. + + Calls the B{Unicode} version if Unicode or mixed string types are passed. + + The default if no string arguments are passed depends on the value of the + L{t_default} class variable. + + @type fn_ansi: function + @ivar fn_ansi: ANSI version of the API function to call. + @type fn_unicode: function + @ivar fn_unicode: Unicode (wide) version of the API function to call. + + @type t_default: type + @cvar t_default: Default string type to use. + Possible values are: + - type('') for ANSI + - type(u'') for Unicode + """ + + # ANSI and Unicode types + t_ansi = type('') + t_unicode = type(u'') + + # Default is ANSI for Python 2.x + t_default = t_ansi + + def __init__(self, fn_ansi, fn_unicode): + """ + @type fn_ansi: function + @param fn_ansi: ANSI version of the API function to call. + @type fn_unicode: function + @param fn_unicode: Unicode (wide) version of the API function to call. + """ + self.fn_ansi = fn_ansi + self.fn_unicode = fn_unicode + + # Copy the wrapped function attributes. + try: + self.__name__ = self.fn_ansi.__name__[:-1] # remove the A or W + except AttributeError: + pass + try: + self.__module__ = self.fn_ansi.__module__ + except AttributeError: + pass + try: + self.__doc__ = self.fn_ansi.__doc__ + except AttributeError: + pass + + def __call__(self, *argv, **argd): + + # Shortcut to self.t_ansi + t_ansi = self.t_ansi + + # Get the types of all arguments for the function + v_types = [type(item) for item in argv] + v_types.extend([type(value) for (key, value) in argd.items()]) + + # Get the appropriate function for the default type + if self.t_default == t_ansi: + fn = self.fn_ansi + else: + fn = self.fn_unicode + + # If at least one argument is a Unicode string... + if self.t_unicode in v_types: + + # If al least one argument is an ANSI string, + # convert all ANSI strings to Unicode + if t_ansi in v_types: + argv = list(argv) + for index in range(len(argv)): + if v_types[index] == t_ansi: + argv[index] = (argv[index]) + for (key, value) in argd.items(): + if type(value) == t_ansi: + argd[key] = (value) + + # Use the W version + fn = self.fn_unicode + + # If at least one argument is an ANSI string, + # but there are no Unicode strings... + elif t_ansi in v_types: + + # Use the A version + fn = self.fn_ansi + + # Call the function and return the result + return fn(*argv, **argd) + + +# DWORD WINAPI GetLastError(void); +def GetLastError(): + _GetLastError = windll.kernel32.GetLastError + _GetLastError.argtypes = [] + _GetLastError.restype = DWORD + return _GetLastError() + + +# void WINAPI SetLastError( +# __in DWORD dwErrCode +# ); +def SetLastError(dwErrCode): + _SetLastError = windll.kernel32.SetLastError + _SetLastError.argtypes = [DWORD] + _SetLastError.restype = None + _SetLastError(dwErrCode) + + +def MAKE_WPARAM(wParam): + """ + Convert arguments to the WPARAM type. + Used automatically by SendMessage, PostMessage, etc. + You shouldn't need to call this function. + """ + wParam = ctypes.cast(wParam, LPVOID).value + if wParam is None: + wParam = 0 + return wParam + + +def MAKE_LPARAM(lParam): + """ + Convert arguments to the LPARAM type. + Used automatically by SendMessage, PostMessage, etc. + You shouldn't need to call this function. + """ + return ctypes.cast(lParam, LPARAM) + + +class __WindowEnumerator (object): + """ + Window enumerator class. Used internally by the window enumeration APIs. + """ + def __init__(self): + self.hwnd = list() + + def __call__(self, hwnd, lParam): + self.hwnd.append(hwnd) + return TRUE + + +class __EnumWndProc (__WindowEnumerator): + pass + + +# windows functions and constants +# stuff for finding and analyzing UI Elements +# EnumWindows = ctypes.windll.user32.EnumWindows +def EnumWindows(): + _EnumWindows = windll.user32.EnumWindows + _EnumWindows.argtypes = [WNDENUMPROC, LPARAM] + _EnumWindows.restype = bool + + EnumFunc = __EnumWndProc() + lpEnumFunc = WNDENUMPROC(EnumFunc) + if not _EnumWindows(lpEnumFunc, NULL): + errcode = GetLastError() + if errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS): + raise ctypes.WinError(errcode) + return EnumFunc.hwnd + + +# BOOL CALLBACK EnumChildProc( +# HWND hwnd, +# LPARAM lParam +# ); +class __EnumChildProc (__WindowEnumerator): + pass + + +# BOOL EnumChildWindows( +# HWND hWndParent, +# WNDENUMPROC lpEnumFunc, +# LPARAM lParam +# ); +def EnumChildWindows(hWndParent=NULL): + _EnumChildWindows = windll.user32.EnumChildWindows + _EnumChildWindows.argtypes = [HWND, WNDENUMPROC, LPARAM] + _EnumChildWindows.restype = bool + + EnumFunc = __EnumChildProc() + lpEnumFunc = WNDENUMPROC(EnumFunc) + SetLastError(ERROR_SUCCESS) + _EnumChildWindows(hWndParent, lpEnumFunc, NULL) + errcode = GetLastError() + if errcode != ERROR_SUCCESS and errcode not in \ + (ERROR_NO_MORE_FILES, ERROR_SUCCESS): + raise ctypes.WinError(errcode) + return EnumFunc.hwnd + + +# int WINAPI GetWindowText( +# __in HWND hWnd, +# __out LPTSTR lpString, +# __in int nMaxCount +# ); +def GetWindowTextA(hWnd): + _GetWindowTextA = windll.user32.GetWindowTextA + _GetWindowTextA.argtypes = [HWND, LPSTR, ctypes.c_int] + _GetWindowTextA.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(CHAR) + while 1: + lpString = ctypes.create_string_buffer(nMaxCount) + nCount = _GetWindowTextA(hWnd, lpString, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return str(lpString.value) + + +def GetWindowTextW(hWnd): + _GetWindowTextW = windll.user32.GetWindowTextW + _GetWindowTextW.argtypes = [HWND, LPWSTR, ctypes.c_int] + _GetWindowTextW.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(CHAR) + while 1: + lpString = ctypes.create_string_buffer(nMaxCount) + nCount = _GetWindowTextW(hWnd, lpString, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return str(lpString.value) + +GetWindowText = GuessStringType(GetWindowTextA, GetWindowTextW) + + +# int GetClassName( +# HWND hWnd, +# LPTSTR lpClassName, +# int nMaxCount +# ); +def GetClassNameA(hWnd): + _GetClassNameA = windll.user32.GetClassNameA + _GetClassNameA.argtypes = [HWND, LPSTR, ctypes.c_int] + _GetClassNameA.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(CHAR) + while 1: + lpClassName = ctypes.create_string_buffer(nMaxCount) + nCount = _GetClassNameA(hWnd, lpClassName, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return str(lpClassName.value) + + +def GetClassNameW(hWnd): + _GetClassNameW = windll.user32.GetClassNameW + _GetClassNameW.argtypes = [HWND, LPWSTR, ctypes.c_int] + _GetClassNameW.restype = ctypes.c_int + + nMaxCount = 0x1000 + dwCharSize = sizeof(WCHAR) + while 1: + lpClassName = ctypes.create_unicode_buffer(nMaxCount) + nCount = _GetClassNameW(hWnd, lpClassName, nMaxCount) + if nCount == 0: + raise ctypes.WinError() + if nCount < nMaxCount - dwCharSize: + break + nMaxCount += 0x1000 + return str(lpClassName.value) + +GetClassName = GuessStringType(GetClassNameA, GetClassNameW) + + +# BOOL WINAPI SetWindowText( +# __in HWND hWnd, +# __in_opt LPCTSTR lpString +# ); +def SetWindowTextA(hWnd, lpString=None): + _SetWindowTextA = windll.user32.SetWindowTextA + _SetWindowTextA.argtypes = [HWND, LPSTR] + _SetWindowTextA.restype = bool + _SetWindowTextA.errcheck = RaiseIfZero + _SetWindowTextA(hWnd, lpString) + + +def SetWindowTextW(hWnd, lpString=None): + _SetWindowTextW = windll.user32.SetWindowTextW + _SetWindowTextW.argtypes = [HWND, LPWSTR] + _SetWindowTextW.restype = bool + _SetWindowTextW.errcheck = RaiseIfZero + _SetWindowTextW(hWnd, lpString) + +SetWindowText = GuessStringType(SetWindowTextA, SetWindowTextW) + + +# LRESULT SendMessage( +# HWND hWnd, +# UINT Msg, +# WPARAM wParam, +# LPARAM lParam +# ); +def SendMessageA(hWnd, Msg, wParam=0, lParam=0): + _SendMessageA = windll.user32.SendMessageA + _SendMessageA.argtypes = [HWND, UINT, WPARAM, LPARAM] + _SendMessageA.restype = LRESULT + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + return _SendMessageA(hWnd, Msg, wParam, lParam) + + +def SendMessageW(hWnd, Msg, wParam=0, lParam=0): + _SendMessageW = windll.user32.SendMessageW + _SendMessageW.argtypes = [HWND, UINT, WPARAM, LPARAM] + _SendMessageW.restype = LRESULT + + wParam = MAKE_WPARAM(wParam) + lParam = MAKE_LPARAM(lParam) + return _SendMessageW(hWnd, Msg, wParam, lParam) + +SendMessage = GuessStringType(SendMessageA, SendMessageW) + + +def FindWindowA(lpClassName=None, lpWindowName=None): + _FindWindowA = windll.user32.FindWindowA + _FindWindowA.argtypes = [LPSTR, LPSTR] + _FindWindowA.restype = HWND + + hWnd = _FindWindowA(lpClassName, lpWindowName) + if not hWnd: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return hWnd + + +def FindWindowW(lpClassName=None, lpWindowName=None): + _FindWindowW = windll.user32.FindWindowW + _FindWindowW.argtypes = [LPWSTR, LPWSTR] + _FindWindowW.restype = HWND + + hWnd = _FindWindowW(lpClassName, lpWindowName) + if not hWnd: + errcode = GetLastError() + if errcode != ERROR_SUCCESS: + raise ctypes.WinError(errcode) + return hWnd + +FindWindow = GuessStringType(FindWindowA, FindWindowW) + + +class Window(object): + def __init__(self, hWnd): + self.hWnd = hWnd + + def get_handle(self): + if self.hWnd is None: + raise ValueError("No window handle set!") + return self.hWnd + + def get_classname(self): + return GetClassName(self.get_handle()) + + def get_text(self): + try: + return GetWindowText(self.get_handle()) + except WindowsError: + return None + + def find_child(self, text=None, cls=None): + childs = [Window(w) for w in EnumChildWindows(self.get_handle())] + for w in childs: + wndText = w.get_text() + wndCls = w.get_classname() + if text is None and cls is None: + return None + if text is None and cls in wndCls: + return w + if cls is None and text in wndText: + return w + if cls in wndCls and text is None: + return w + return None + + def send(self, uMsg, wParam=None, lParam=None, dwTimeout=None): + """ + Send a low-level window message syncronically. + + @type uMsg: int + @param uMsg: Message code. + + @param wParam: + The type and meaning of this parameter depends on the message. + + @param lParam: + The type and meaning of this parameter depends on the message. + + @param dwTimeout: Optional timeout for the operation. + Use C{None} to wait indefinitely. + + @rtype: int + @return: The meaning of the return value depends on the window message. + Typically a value of C{0} means an error occured. You can get the + error code by calling L{win32.GetLastError}. + """ + return SendMessage(self.get_handle(), uMsg, wParam, lParam) + + @classmethod + def find_windows(cls, text, return_on_first_match=False): + windows = [] + for w in [Window(h) for h in EnumWindows()]: + window_text = w.get_text() + + # Handle special characters in ST2 + if window_text: + try: + window_text = unicode(window_text, "latin1") + except: + pass + + if window_text is not None and text in window_text: + windows.append(w) + if return_on_first_match: + return windows + return windows + + @classmethod + def find_window(cls, text): + windows = cls.find_windows(text, return_on_first_match=True) + return windows[0] if windows else None diff --git a/attach.py b/attach.py new file mode 100644 index 0000000..93a11b1 --- /dev/null +++ b/attach.py @@ -0,0 +1,105 @@ + +""" + +This script adds the the containing package as a valid debug adapter in the Debugger's settings + +""" + +from Debugger.modules.debugger.debugger import Debugger +from os.path import join, abspath, dirname +from threading import Timer +import sublime +import time + + +adapter_type = "3DSMPy2" # NOTE: type name must be unique to each adapter +package_path = dirname(abspath(__file__)) +adapter_path = join(package_path, "adapter") + + +# The version is only used for display in the GUI +version = "1.0" + +# You can have several configurations here depending on your adapter's offered functionalities, +# but they all need a "label", "description", and "body" +config_snippets = [ + { + "label": "3DS Max: Python 2 Debugging", + "description": "Run and Debug Python 2 code in 3DS Max", + "body": { + "name": "3DS Max: Python 2 Debugging", + "type": adapter_type, + "program": "\${file\}", + "request": "attach", # can only be attach or launch + "ptvsd": # The host/port used to communicate with ptvsd in maya + { + "host": "localhost", + "port": 7003 + }, + } + }, +] + +# The settings used by the Debugger to run the adapter. +settings = { + "type": adapter_type, + "command": ["python", adapter_path] +} + +# Instantiate variables needed for checking thread +running = False +check_speed = 5 # number of seconds to wait between checks for adapter presence in debugger instances + + +def check_for_adapter(): + """ + Gets run in a thread to inject configuration snippets and version information + into adapter objects of type adapter_type in each debugger instance found + """ + + while running: + + for instance in Debugger.instances.values(): + adapter = getattr(instance, "adapters", {}).get(adapter_type, None) + + if adapter and not adapter.version: + adapter.version = version + adapter.snippets = config_snippets + + time.sleep(check_speed) + + +def plugin_loaded(): + """ Add adapter to debugger settings for it to be recognized """ + + # Add entry to debugger settings + debugger_settings = sublime.load_settings('debugger.sublime-settings') + adapters_custom = debugger_settings.get('adapters_custom', {}) + + adapters_custom[adapter_type] = settings + + debugger_settings.set('adapters_custom', adapters_custom) + sublime.save_settings('debugger.sublime-settings') + + # Start checking thread + global running, timer + running = True + Timer(1, check_for_adapter).start() + + +def plugin_unloaded(): + """ This is done every unload just in case this adapter is being uninstalled """ + + # Wait for checking thread to finish + global running + running = False + time.sleep(check_speed + .1) + + # Remove entry from debugger settings + debugger_settings = sublime.load_settings('debugger.sublime-settings') + adapters_custom = debugger_settings.get('adapters_custom', {}) + + adapters_custom.pop(adapter_type, "") + + debugger_settings.set('adapters_custom', adapters_custom) + sublime.save_settings('debugger.sublime-settings') diff --git a/messages.json b/messages.json new file mode 100644 index 0000000..ef56f9e --- /dev/null +++ b/messages.json @@ -0,0 +1,3 @@ +{ + "install": "messages/install.txt" +} diff --git a/messages/install.txt b/messages/install.txt new file mode 100644 index 0000000..247c802 --- /dev/null +++ b/messages/install.txt @@ -0,0 +1,7 @@ +--------------------------------------------------------------- + Debugger-3DSMax +--------------------------------------------------------------- + +Thanks for installing the debug adapter for running Python in +3DS Max. Please ensure you have the "Debugger" plugin installed. +If not, please install it and restart Sublime before continuing.