This project is read-only.

[0.3.x, 0.2.x] windbg hangs and crashes on threads and timers


when executing a simple python script like the following, windbg executes the first line of code in the threaded function, then hangs and crashes itself
import pykd
from threading import Thread

def my_func():
    print "hi from thread 1\n"
    print "hi from thread 2\n"

t = Thread(target=my_func)
t.daemon = True;
print "after thread start"


ussrhero wrote Feb 25, 2017 at 1:07 PM

I'm affraid is is impossible to make stable multithread code inside windbg.
It is a very long story to talk.
Dont's use threading or multiprocessing inside windbg.

vicks16 wrote Feb 25, 2017 at 3:23 PM

@ussrhero - thanks for your reply!

I will take up your suggestion and stay away from multithreaded code on WinDbg.

That being said, I still wonder how others got it working in the past. Like this script for example.

My plan was to develop a pykd script which listens to requests over the network (on a different thread, while windbg was executing code) and did stuff like interrupt WinDbg etc. While its possible to do exactly this using WinDbg's server/client model, I wasn't planning to run another instance of WinDbg on the machine sending the requests.

ussrhero wrote Feb 25, 2017 at 4:09 PM

You should exactly know how work multithreading in python, in windbg and pykd.

Your script sample has two problem:
  1. It does not wait for additional thread stopping. It leads to fatal python error after the script stopping. So you need add join method call
  2. You may not run any call wich can call dbgeng call due to avoid deadlocks with windbg. print leads to IDebugControl::ControlledOutput and it will be wait for command completion in the windbg thread wich is waiting for stop of the additional thread ( you have added join method remember? )
May be you don't need to run code inside in windbg? You can use pykd in standalone program. It is more easy in your case. Yoy will not have to think about deadlocks with windbg