ioncodes / idacode

An integration for IDA and VS Code which connects both to easily execute and debug IDAPython scripts.
725 stars 77 forks source link

How to debug plugins? #18

Open kruxmeier opened 4 years ago

kruxmeier commented 4 years ago

When it's trying to set the workspace to the plugins dir it fails with only one usage of each socket address allowed.

``` [IDACode] Listening on 127.0.0.1:7065 [INFO] 101 GET /ws (127.0.0.1) 15.00ms (web:log_request) [IDACode] Client connected [IDACode] Set workspace folder to .....\plugins [ERROR] Uncaught exception GET /ws (127.0.0.1) HTTPServerRequest(protocol='http', host='127.0.0.1:7065', method='GET', uri='/ws', version='HTTP/1.1', remote_ip='127.0.0.1') (web:log_exception) Traceback (most recent call last): File "C:\python27-x64\lib\site-packages\tornado\websocket.py", line 546, in _run_callback result = callback(*args, **kwargs) File "...../plugins\idacode_utils\socket_handler.py", line 36, in on_message start_debug_server() File "...../plugins\idacode_utils\socket_handler.py", line 21, in start_debug_server debugpy.listen((settings.HOST, settings.DEBUG_PORT)) File "C:\python27-x64\lib\site-packages\debugpy\__init__.py", line 113, in listen return api.listen(address) File "C:\python27-x64\lib\site-packages\debugpy\server\api.py", line 143, in debug log.reraise_exception("{0}() failed:", func.__name__, level="info") File "C:\python27-x64\lib\site-packages\debugpy\server\api.py", line 141, in debug return func(address, settrace_kwargs, **kwargs) File "C:\python27-x64\lib\site-packages\debugpy\server\api.py", line 234, in listen raise RuntimeError(str(endpoints["error"])) RuntimeError: Can't listen for client connections: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted [IDACode] Client disconnected ```
ioncodes commented 4 years ago

That means something is already using that port. Perhaps it's being used by another software or it's a reserved port. Can you test out a simple idapy script (not a plugin) after a fresh reboot?

kruxmeier commented 4 years ago

Well running the idacode server succeeds but when running connect and attach debugger from the client side this error pops up. ptvsd otoh is able to connect and does show the redirected stdout but breakpoints don't work.

ioncodes commented 4 years ago

I see, I wrongly assumed you guys force reloaded IDACode or something.

Have you tried using a different folder? It may be some sort of path issue to the plugins folder. As IDAs internals are doing some path hackery, I have to do some hackish stuff myself to get the debugger to work properly, and referencing to IDAs root (or the plugins subfolder) may cause unexpected issues.

If the breakpoints don't work, make sure you have at least one call to breakpoint() before a line of code. That will activate breakpoints for the session.

ioncodes commented 4 years ago

Either way, which IDA version are you on? I can try it out locally next week.

kruxmeier commented 4 years ago

Tested on 7.3

ghost commented 4 years ago

Hello, I have some errors when I use idacode. When IDA 7.0 calls breakpoint() in the script, IDA prompts me to "can't find input file 'C:" users \ \ appdata / roaming / Python / python27 / site packages / debug / adapter'

Can you tell me why? Thank you

bahlaivlad commented 4 years ago

Hello, I have some errors when I use idacode. When IDA 7.0 calls breakpoint() in the script, IDA prompts me to "can't find input file 'C:" users \ \ appdata / roaming / Python / python27 / site packages / debug / adapter'

Can you tell me why? Thank you

Had the same issue: https://github.com/ioncodes/idacode/issues/19