Simple go/break script

Jan 29, 2015 at 12:22 PM
Hello All,
I am just starting my adventure with pykd and Windbg and I want to write script which will:
  1. connect with target in kernel mode (working)
  2. Hit break
  3. Hit go
  4. Hit break again
Sample of my code (steps without connection and initial breakIn):
if __name__=="__main__":
    if isKernelDebugging():
        dprintln("in kernel debugging, proceeding")
        go()
        time.sleep(5)
        breakin()
    else:
        dprintln("not in kernel debugging")
When I run this code in Windgb:
Go is hit, target is released, But break never happens . When I click 'break' manually I have got - this information "Break instruction exception "
How can I perform break from python script?
Can I validate that break was actually hit?

Thanks for all replies :)
Jan 29, 2015 at 2:45 PM
go() resumes the debugged process and returns control to the debugger only when the debugger is stopped again - triggered by a breakpoint or when debugging is stopped manually via Ctrl+Break.

Using breakin() is hardly needed during normal operation due to the fact that the script is usually run while the debugger is already breaking. And at this time, the breakin() method does not make sense. In order to be able to stop a running process, the script has to create a separate thread and then call the function.
Marked as answer by dziczka on 1/30/2015 at 1:44 AM
Jan 30, 2015 at 8:41 AM
Thank you for the replay :)

I wrote some simple code with threads, but after execution it stops whole Windbg. I am trying to find right solution, but maybe you can give me a hint?
def breakInThread():
    dprintln("Starting thread for break-in")
    breakin()
    dprintln("Did break happen?")
    

def goThread():
    dprintln("Starting thread for go")
    go()
    

t_break = threading.Thread(target=breakInThread)
t_go = threading.Thread(target=goThread)
command = dbgCommand(".echo Starting")
dprintln(command)
t_go.start()
t_break.start()
Feb 3, 2015 at 7:58 AM
I am still struggling with this problem. Can anyone give me a hint what could be wrong?