microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.87k stars 139 forks source link

Attach to local process assumes i386 architecture? #286

Open okz opened 4 years ago

okz commented 4 years ago

Trying to attach a running process on an ARM processor, either in the command line or in vs code fails with:

Running gdb in target process. stdout: b'[New LWP 5629]\n[New LWP 5630]\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".\n0xb6f2fbf0 in poll () from /lib/arm-linux-gnueabihf/libc.so.6\n$1 = (void *) 0x0\n' stderr: b'Undefined item: "i386".\nNo symbol "DoAttach" in current context.\n'

VS code report attached.

Environment data

Actual behavior

XXX

Expected behavior

XXX

Steps to reproduce:

  1. XXX

I+00000.149: Linux-4.9.0-xilinx-armv7l-with-Ubuntu-16.04-xenial armv7l CPython 3.5.2 (32-bit) debugpy 1.0.0b11

I+00000.187: debugpy.adapter startup environment:

         System paths:
             sys.prefix: /usr
             sys.base_prefix: /usr
             sys.real_prefix: <missing>
             site.getsitepackages(): /usr/lib/python3.5/dist-packages
                                     /usr/lib/python3/dist-packages
                                     /usr/local/lib/python3.5/dist-packages
             site.getusersitepackages(): /root/.local/lib/python3.5/site-packages
             sys.path (site-packages): /root/.local/lib/python3.5/site-packages
             sysconfig.get_path('stdlib'): /usr/lib/python3.5
             sysconfig.get_path('platstdlib'): /usr/lib/python3.5
             sysconfig.get_path('purelib'): /usr/lib/python3.5/site-packages
             sysconfig.get_path('platlib'): /usr/lib/python3.5/site-packages
             sysconfig.get_path('include'): /usr/include/python3.5m
             sysconfig.get_path('scripts'): /usr/bin
             sysconfig.get_path('data'): /usr
             os.__file__: /usr/lib/python3.5/os.py
             threading.__file__: /usr/lib/python3.5/threading.py

I+00000.198: Listening for incoming Client connections on 127.0.0.1:35551...

I+00000.200: Connecting to client over stdio...

D+00000.204: Starting message loop for channel Client[1]

D+00000.212: Client[1] <-- { "seq": 1, "type": "event", "event": "output", "body": { "data": { "packageVersion": "1.0.0b11" }, "output": "ptvsd", "category": "telemetry" } }

D+00000.217: Client[1] <-- { "seq": 2, "type": "event", "event": "output", "body": { "data": { "packageVersion": "1.0.0b11" }, "output": "debugpy", "category": "telemetry" } }

D+00000.222: Client[1] --> { "seq": 1, "type": "request", "command": "initialize", "arguments": { "supportsVariableType": true, "clientName": "Visual Studio Code", "columnsStartAt1": true, "supportsProgressReporting": true, "clientID": "vscode", "locale": "en-us", "pathFormat": "path", "supportsVariablePaging": true, "adapterID": "python", "supportsRunInTerminalRequest": true, "linesStartAt1": true } }

D+00000.229: /handling #1 request "initialize" from Client[1]/ Capabilities: { "supportsVariableType": true, "supportsRunInTerminalRequest": true, "supportsMemoryReferences": false, "supportsVariablePaging": true }

D+00000.230: /handling #1 request "initialize" from Client[1]/ Expectations: { "columnsStartAt1": true, "locale": "en-us", "pathFormat": "path", "linesStartAt1": true }

D+00000.239: /handling #1 request "initialize" from Client[1]/ Client[1] <-- { "seq": 3, "type": "response", "request_seq": 1, "success": true, "command": "initialize", "body": { "supportsLogPoints": true, "supportsGotoTargetsRequest": true, "supportsExceptionOptions": true, "supportsDebuggerProperties": true, "supportsCompletionsRequest": true, "supportsValueFormattingOptions": true, "supportsDelayedStackTraceLoading": true, "supportsModulesRequest": true, "supportsTerminateDebuggee": true, "supportsExceptionInfoRequest": true, "supportsSetVariable": true, "exceptionBreakpointFilters": [ { "default": false, "label": "Raised Exceptions", "filter": "raised" }, { "default": true, "label": "Uncaught Exceptions", "filter": "uncaught" } ], "supportsConfigurationDoneRequest": true, "supportsEvaluateForHovers": true, "supportsSetExpression": true, "supportsConditionalBreakpoints": true, "supportsHitConditionalBreakpoints": true } }

D+00000.249: Client[1] --> { "seq": 2, "type": "request", "command": "attach", "arguments": { "logToFile": true, "name": "Python: Attach using Process Id", "justMyCode": true, "debugOptions": [ "RedirectOutput", "UnixClient", "ShowReturnValue" ], "pathMappings": [ { "remoteRoot": "/root/LDSSoftware", "localRoot": "/root/LDSSoftware" } ], "host": "localhost", "request": "attach", "__sessionId": "44be5c52-ead1-4c20-9572-00ada87c73fa", "processId": "2961", "showReturnValue": true, "workspaceFolder": "/root/LDSSoftware", "type": "python" } }

I+00000.252: /handling #2 request "attach" from Client[1]/ Listening for incoming Server connections on 127.0.0.1:40927...

I+00000.254: /handling #2 request "attach" from Client[1]/ Spawning attach-to-PID debugger injector: ['/usr/bin/python3', '/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy', '--connect', '127.0.0.1:40927', '--adapter-access-token', '743df3e981173bf6b5d4aa196f062e65bd13982026f64051f51f4dce4098791b', '--pid', '2961']

D+00000.272: /handling #2 request "attach" from Client[1]/ Client[1] <-- { "seq": 4, "type": "event", "event": "debugpyWaitingForServer", "body": { "port": 40927, "host": "127.0.0.1" } }

I+00000.281: /handling #2 request "attach" from Client[1]/ Session[1] waiting for connection from debug server...

I+00009.245: Injector[PID=2961] output: b'Attaching with arch: i386'

I+00009.309: Injector[PID=2961] output: b'Running: gdb --nw --nh --nx --pid 2961 --batch --eval-command=\'set scheduler-locking off\' --eval-command=\'set architecture i386\' --eval-command=\'call (void*)dlopen("/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_linux_x86.so", 2)\' --eval-command=\'call (int)DoAttach(0, "import codecs;import json;import sys;decode = lambda s: codecs.utf_8_decode(bytearray(s))[0] if s is not None else None;script_dir = decode([47, 114, 111, 111, 116, 47, 46, 118, 115, 99, 111, 100, 101, 45, 115, 101, 114, 118, 101, 114, 47, 101, 120, 116, 101, 110, 115, 105, 111, 110, 115, 47, 109, 115, 45, 112, 121, 116, 104, 111, 110, 46, 112, 121, 116, 104, 111, 110, 45, 50, 48, 50, 48, 46, 53, 46, 56, 54, 56, 48, 54, 47, 112, 121, 116, 104, 111, 110, 70, 105, 108, 101, 115, 47, 108, 105, 98, 47, 112, 121, 116, 104, 111, 110, 47, 100, 101, 98, 117, 103, 112, 121, 47, 110, 111, 95, 119, 104, 101, 101, 108, 115, 47, 100, 101, 98, 117, 103, 112, 121, 47, 46, 46, 47, 100, 101, 98, 117, 103, 112, 121, 47, 115, 101, 114, 118, 101, 114]);setup = json.loads(decode([123, 34, 119, 97, 105, 116, 95, 102, 111, 114, 95, 99, 108, 105, 101, 110, 116, 34, 58, 32, 102, 97, 108, 115, 101, 44, 32, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 32, 91, 34, 49, 50, 55, 46, 48, 46, 48, 46, 49, 34, 44, 32, 52, 48, 57, 50, 55, 93, 44, 32, 34, 108, 111, 103, 95, 116, 111, 34, 58, 32, 110, 117, 108, 108, 44, 32, 34, 97, 100, 97, 112, 116, 101, 114, 95, 97, 99, 99, 101, 115, 115, 95, 116, 111, 107, 101, 110, 34, 58, 32, 34, 55, 52, 51, 100, 102, 51, 101, 57, 56, 49, 49, 55, 51, 98, 102, 54, 98, 53, 100, 52, 97, 97, 49, 57, 54, 102, 48, 54, 50, 101, 54, 53, 98, 100, 49, 51, 57, 56, 50, 48, 50, 54, 102, 54, 52, 48, 53, 49, 102, 53, 49, 102, 52, 100, 99, 101, 52, 48, 57, 56, 55, 57, 49, 98, 34, 44, 32, 34, 109, 111, 100, 101, 34, 58, 32, 34, 99, 111, 110, 110, 101, 99, 116, 34, 125]));sys.path.insert(0, script_dir);import attach_pid_injected;del sys.path[0];attach_pid_injected.attach(setup);", 0)\''

I+00009.310: Injector[PID=2961] output: b'Running gdb in target process.'

I+00009.339: Injector[PID=2961] output: b'stdout: b\'[New LWP 2962]\n[New LWP 2963]\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".\n0xb6f28bf0 in poll () from /lib/arm-linux-gnueabihf/libc.so.6\n$1 = (void *) 0x0\n\''

I+00009.341: Injector[PID=2961] output: b'stderr: b\'Undefined item: "i386".\nNo symbol "DoAttach" in current context.\n\''

I+00009.613: Injector[PID=2961] exited.

I+00010.292: All debug servers disconnected; waiting for remaining sessions...

E+00010.321: /handling #2 request "attach" from Client[1]/ Traceback (most recent call last): File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/messaging.py", line 1058, in init raise self debugpy.common.messaging.MessageHandlingError: Timed out waiting for debug server to connect.

         Stack where logged:
           File "/usr/lib/python3.5/threading.py", line 882, in _bootstrap
             self._bootstrap_inner()
           File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
             self.run()
           File "/usr/lib/python3.5/threading.py", line 862, in run
             self._target(*self._args, **self._kwargs)
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/messaging.py", line 1500, in _run_handlers
             handler()
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/messaging.py", line 743, in _handle
             result = handler(self)
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/adapter/components.py", line 95, in lock_and_handle
             return f(self, message)
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/adapter/clients.py", line 187, in handle
             f(self, request)
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/adapter/clients.py", line 460, in attach_request
             sub_pid,
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/messaging.py", line 556, in cant_handle
             return self.error(MessageHandlingError, *args, **kwargs)
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/messaging.py", line 542, in error
             exc = exc_type(reason, self, silent)  # will log it
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/messaging.py", line 1060, in __init__
             log.swallow_exception()
           File "/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/common/log.py", line 215, in swallow_exception
             _exception(format_string, *args, **kwargs)

D+00010.328: /handling #2 request "attach" from Client[1]/ Client[1] <-- { "seq": 5, "type": "response", "request_seq": 2, "success": false, "command": "attach", "message": "Timed out waiting for debug server to connect." }

D+00010.338: Client[1] --> { "seq": 3, "type": "request", "command": "disconnect", "arguments": { "restart": false } }

E+00010.459: /handling #2 request "attach" from Client[1]/ Handler 'Client._start_message_handler..handle' (file '/root/.vscode-server/extensions/ms-python.python-2020.5.86806/pythonFiles/lib/python/debugpy/no_wheels/debugpy/adapter/../../debugpy/adapter/components.py', line 171) couldn't handle #2 request "attach" from Client[1]: Timed out waiting for debug server to connect.

I+00010.461: /handling #3 request "disconnect" from Client[1]/ client requested "disconnect"; finalizing Session[1].

D+00010.466: /handling #3 request "disconnect" from Client[1]/ Client[1] <-- { "seq": 6, "type": "event", "event": "terminated" }

I+00010.468: /handling #3 request "disconnect" from Client[1]/ Session[1] finalized.

D+00010.474: /handling #3 request "disconnect" from Client[1]/ Client[1] <-- { "seq": 7, "type": "response", "request_seq": 3, "success": true, "command": "disconnect" }

int19h commented 4 years ago

This feature is very much arch-specific, and we don't support it on ARM.

That said, this needs a better error message.

fabioz commented 4 years ago

There are currently multiple issues for ARM/ARM64: https://github.com/microsoft/debugpy/issues/181 https://github.com/microsoft/debugpy/issues/182 https://github.com/microsoft/debugpy/issues/183 https://github.com/microsoft/debugpy/issues/184 https://github.com/microsoft/debugpy/issues/286

Should we close all of those and just let this one open to add support for ARM?

-- when the time comes to actually tackle it we can open minor items (if needed) to keep track of individual steps.

Or should this one used just to provide a better error message?

int19h commented 4 years ago

I think this one is about reporting the error clearly at this point.

Those other issues are separate, because the debugger itself already works on ARM platforms, just not the native bits like attach-to-PID. So there's no reason why we shouldn't be running CI on ARM today already, if we could easily do that.