Updated Debugging (markdown)

ohhorob 2012-08-03 09:04:38 -07:00
parent 8c6954589b
commit ee9f28b789
1 changed files with 7 additions and 7 deletions

@ -1,6 +1,6 @@
Debugging mitmproxy is best done in "remote" mode, as the terminal that starts mitmproxy is used by the urwid library to render the interface. Debugging [`mitmproxy`](https://github.com/cortesi/mitmproxy) is best done in "remote" mode, as the terminal that starts `mitmproxy` is used by the [Urwid](http://excess.org/urwid/) library to render the interface.
Modify mitmproxy to connect to a remote debugger Modify `mitmproxy` to connect to a remote debugger
### Add the debugger import ### Add the debugger import
@ -11,14 +11,14 @@ Modify mitmproxy to connect to a remote debugger
if __name__ == '__main__': if __name__ == '__main__':
try: try:
pydevd.settrace('localhost', port=1234, suspend=False) pydevd.settrace('localhost', port=1234, suspend=False)
except Exception: except:
print >> sys.stderr, "mitmproxy: failed to connect to remote debugger." print >> sys.stderr, "mitmproxy: failed to connect to remote debugger."
Here, `suspend=False` will allow mitmproxy to start up and run until hitting a breakpoint. Here, `suspend=False` will allow `mitmproxy` to start up and run until hitting a breakpoint.
### IDE Configuration ### IDE Configuration
I've used IntelliJ IDEA Ultimate with the PyCharm plugin installed. PyCharm installs an egg with the required pydev module imported in the steps above. I've used [IntelliJ IDEA Ultimate](http://www.jetbrains.com/idea/) with the [Python (PyCharm)](http://www.jetbrains.net/confluence/display/PYH/) plugin installed. PyCharm installs an egg with the required `pydev` module imported in the steps above.
In "Run/Debug Configurations", add a new "Python Remote Debug" configuration with settings matching the `settrace()` added in the steps above. Name it "mitmproxy Remote" In "Run/Debug Configurations", add a new "Python Remote Debug" configuration with settings matching the `settrace()` added in the steps above. Name it "mitmproxy Remote"
@ -39,7 +39,7 @@ On Mac OS X, this looks like:
This environment variable will only persist for the current terminal session. Other terminals, including all new terminal sessions will not have this configuration. To make it permanent, add it to your shell configuration (typically ~/.profile). This environment variable will only persist for the current terminal session. Other terminals, including all new terminal sessions will not have this configuration. To make it permanent, add it to your shell configuration (typically ~/.profile).
Now starting mitmproxy should connect to the "mitmproxy Remote" configuration started in the IDE. Now starting `mitmproxy` should connect to the "mitmproxy Remote" configuration started in the IDE.
$ ./mitmproxy -p 8888 2>/tmp/mitmproxy.err $ ./mitmproxy -p 8888 2>/tmp/mitmproxy.err