リモートデバッグ設定の苦難

「リモートデバッグ設定の苦難」の編集履歴(バックアップ)一覧に戻る

リモートデバッグ設定の苦難 - (2011/04/10 (日) 21:52:09) の編集履歴(バックアップ)


恐ろしきpydevd

pydevd.pyとはリモートデバッグサーバ機能を有するpythonモジュール。
これを動かすのは超簡単。
しかし、リモートのクライアントからこのサーバに向けたtcp通信を確立するのが超大変だった。
まず、forwardingはクライアントからサーバに向けてやらなければならないことに気付かなかった。。
気づいてもそのあとが大変。。
リモートクライアントがubuntuなのだが、なぜかサーバにフォワードされているゲートウェイの5678ポートにtcpが確立できない。。orz
[root@remotehost]telnet ゲートウェイIP 5678
[root@remotehost]telnet localhost 5678
としてもconnection refusedされてしまうのである。
dportが5678のものは遮断されてしまうのかと推測してuwf(ubuntuのファイアウォールらしい)をinactiveにしてもダメですた。

ubuntuのセキュリティは盤石なので、sshで5678のポートフォワードを試みる!
pydevd.settrace('192.168.0.1', port=5678, stdoutToServer=True, stderrToServer=True)
これは相手先のソケットアドレスを指定しているが、自ポートはどこを指定すれば?
ここでもしかしてサーバとクライアントを間違えていたことに気付く。以下pydevd_file_utiles.py

   @note: 
       in this context, the server is where your python process is running#サーバはパイソンが走っている方、クライアントはエクリプスの方
       and the client is where eclipse is running.
   
   E.g.: 
       If the server (your python process) has the structure
           /user/projects/my_project/src/package/module1.py #例えばlinuxの方でこうなってるんなら
       
       and the client has: 
           c:\my_project\src\package\module1.py #同じモジュールを同じ階層で置かなくてはならない?
           
       the PATHS_FROM_ECLIPSE_TO_PYTHON would have to be:
           PATHS_FROM_ECLIPSE_TO_PYTHON = [(r'c:\my_project\src', r'/user/projects/my_project/src')]
でもこの条件だとexlipseの方でDebug Serverが動いているから矛盾を感じる。。

よく分からなくなったのでpydevd.pyのsettraceの宣言部分を読んでみると興味深い説明が!
def settrace(host=None, stdoutToServer=False, stderrToServer=False, port=5678, suspend=True, trace_only_current_thread=True):
   '''Sets the tracing function with the pydev debug function and initializes needed facilities.
   
   @param host: the user may specify another host, if the debug server is not in the same machine (default is the local host)#ホストを省略するとlocalhostに(つまり通常のデバッグ)
   @param stdoutToServer: when this is true, the stdout is passed to the debug server
   @param stderrToServer: when this is true, the stderr is passed to the debug server
       so that they are printed in its console and not in this process console.
   @param port: specifies which port to use for communicating with the server (note that the server must be started 
       in the same port). @note: currently it's hard-coded at 5678 in the client#クライアントのポートはハードコーディングでサーバ側と同じ5678
   @param suspend: whether a breakpoint should be emulated as soon as this function is called. #settraceはブレークポイントと同義
   @param trace_only_current_thread: determines if only the current thread will be traced or all future threads will also have the tracing enabled.#スレッドに関すること?
   '''
分かったこと
  • クライアントは5678に固定されているらしい