```
pykd.dbgCommand('q')
```
Expected: debug session is closed
In fact: windbg is hang
Comments: ** Comment from web user: ussrhero **
fixed in 2.0.0.9 version
fixed in 2.0.0.9 version
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.
@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](https://github.com/joxeankoret/nightmare/blob/master/lib/interfaces/pykd_iface.py#L318-L324) 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.
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
pip install pykd
pip install pykd --upgrade
pip install pykd-0.3.1.1-cp27-none-win32.whl
from pykd import * source_code = ''' struct Struct { int field1; float field2; char field3[10]; }; ''' Struct = getTypeFromSource(source_code, "Struct") print StructIt consructs a typeInfo class instance wich can be used for typed access to the target memory. The next sample is a bit complex. If source code has a lot of types declarations it has a sense to compile a code once time and then use a result:
from pykd import * source_code = '#include <windows.h>\r\n' options = '-I\"C:/Program Files (x86)/Windows Kits/8.1/Include/um\" -I\"C:/Program Files (x86)/Windows Kits/8.1/Include/shared\" -w' typeInfoProvider = getTypeInfoProviderFromSource(source_code, options) print( typeInfoProvider.getTypeByName("tagPOINT") ) print( typeInfoProvider.getTypeByName("tagWNDCLASSA") )
pip install pykd
pip install pykd --upgrade
pip install pykd-0.3.1.1-cp27-none-win32.whl
from pykd import * source_code = ''' struct Struct { int field1; float field2; char field3[10]; }; ''' Struct = getTypeFromSource(source_code, "Struct") print( Struct )It consructs a typeInfo class instance wich can be used for typed access to the target memory. The next sample is a bit complex. If source code has a lot of types declarations it has a sense to compile a code once time and then use a result:
from pykd import * source_code = '#include <windows.h>\r\n' options = '-I\"C:/Program Files (x86)/Windows Kits/8.1/Include/um\" -I\"C:/Program Files (x86)/Windows Kits/8.1/Include/shared\" -w' typeInfoProvider = getTypeInfoProviderFromSource(source_code, options) print( typeInfoProvider.getTypeByName("tagPOINT") ) print( typeInfoProvider.getTypeByName("tagWNDCLASSA") )
pip install pykd
pip install pykd --upgrade
pip install pykd-0.3.1.1-cp27-none-win32.whl
from pykd import * source_code = ''' struct Struct { int field1; float field2; char field3[10]; }; ''' Struct = getTypeFromSource(source_code, "Struct") print( Struct )It consructs a typeInfo class instance wich can be used for typed access to the target memory. The next sample is a bit complex. If source code has a lot of types declarations it has a sense to compile a code once time and then use a result:
from pykd import * source_code = '#include <windows.h>\r\n' options = '-I\"C:/Program Files (x86)/Windows Kits/8.1/Include/um\" -I\"C:/Program Files (x86)/Windows Kits/8.1/Include/shared\" -w' typeInfoProvider = getTypeInfoProviderFromSource(source_code, options) print( typeInfoProvider.getTypeByName("tagPOINT") ) print( typeInfoProvider.getTypeByName("tagWNDCLASSA") )
0:000> !pykd.help usage: !help print this text !info list installed python interpreters !py [version] [options] [file] run python script or REPL Version: -2 : use Python2 -2.x : use Python2.x -3 : use Python3 -3.x : use Python3.x Options: -g --global : run code in the common namespace -l --local : run code in the isolated namespace command samples: "!py" : run REPL "!py --local" : run REPL in the isolated namespace "!py -g script.py 10 "string"" : run script file with argument in the common namespace !pip [version] [args] run pip package manager Version: -2 : use Python2 -2.x : use Python2.x -3 : use Python3 -3.x : use Python3.x pip command samples: "pip list" : show all installed packages "pip install pykd" : install pykd "pip install --upgrade pykd" : upgrade pykd to the latest version "pip show pykd" : show info about pykd package
0:000> !pykd.info Installed python Version: Status: Image: ------------------------------------------------------------------------------ * 2.7 x86-64 Unloaded C:\Windows\SYSTEM32\python27.dll 3.5 x86-64 Unloaded C:\Users\user\AppData\Local\Programs\Python\Python35\python35.dll
#! python2
#! python3.5
0:000> !pip -3.5 list pip (7.1.2) pykd (0.3.1.1) setuptools (18.2) wheel (0.29.0)
0:000> !pip -3.5 show pykd --- Metadata-Version: 2.0 Name: pykd Version: 0.3.1.1 Summary: python windbg extension Home-page: UNKNOWN Author: UNKNOWN Author-email: UNKNOWN License: UNKNOWN Location: c:\users\user\appdata\local\programs\python\python35\lib\site-packages Requires:
0:000> !pip -3.5 install --upgrade pykd Collecting pykd Downloading pykd-0.3.1.3-cp35-none-win_amd64.whl (3.3MB) Installing collected packages: pykd Found existing installation: pykd 0.3.1.1 Uninstalling pykd-0.3.1.1: Successfully uninstalled pykd-0.3.1.1 Successfully installed pykd-0.3.1.3
0:000> !pykd.help usage: !help print this text !info list installed python interpreters !py [version] [options] [file] run python script or REPL Version: -2 : use Python2 -2.x : use Python2.x -3 : use Python3 -3.x : use Python3.x Options: -g --global : run code in the common namespace -l --local : run code in the isolated namespace command samples: "!py" : run REPL "!py --local" : run REPL in the isolated namespace "!py -g script.py 10 "string"" : run script file with argument in the common namespace !pip [version] [args] run pip package manager Version: -2 : use Python2 -2.x : use Python2.x -3 : use Python3 -3.x : use Python3.x pip command samples: "pip list" : show all installed packages "pip install pykd" : install pykd "pip install --upgrade pykd" : upgrade pykd to the latest version "pip show pykd" : show info about pykd package
0:000> !pykd.info Installed python Version: Status: Image: ------------------------------------------------------------------------------ * 2.7 x86-64 Unloaded C:\Windows\SYSTEM32\python27.dll 3.5 x86-64 Unloaded C:\Users\user\AppData\Local\Programs\Python\Python35\python35.dll
#! python2
#! python3.5
0:000> !pip -3.5 list pip (7.1.2) pykd (0.3.1.1) setuptools (18.2) wheel (0.29.0)
0:000> !pip -3.5 show pykd --- Metadata-Version: 2.0 Name: pykd Version: 0.3.1.1 Summary: python windbg extension Home-page: UNKNOWN Author: UNKNOWN Author-email: UNKNOWN License: UNKNOWN Location: c:\users\user\appdata\local\programs\python\python35\lib\site-packages Requires:
0:000> !pip -3.5 install --upgrade pykd Collecting pykd Downloading pykd-0.3.1.3-cp35-none-win_amd64.whl (3.3MB) Installing collected packages: pykd Found existing installation: pykd 0.3.1.1 Uninstalling pykd-0.3.1.1: Successfully uninstalled pykd-0.3.1.1 Successfully installed pykd-0.3.1.3
Do you use pykd_bootstrapper (http://pykd.codeplex.com/releases/view/624814) to run python ?
Is the bug reproduced with the last pykd_bootstrapper version ?