Remote debugging from Windows to Linux

|

출처 : http://www.eclipse.org/forums/index.php/m/842278/


  1. on the target linux box, make sure you have gdbserver. If you don't, get the gdb sources. Note: Making gdb does not build gdbserver. Instead, you have to go into the gdbserver directory and configure/make there.
  2. Run gdb on the linux box. In the startup banner, it will say what its target is. This will be something like x86_64-unknown-linux-gnu or i686-pc-linux-gnu. Remember this for later.
  3. Install MinGW on your Windows box (I had trouble building gdb on cygwin, so I recommend MinGW).
  4. Download expat from http://sourceforge.net/projects/expat/files/expat/2.1.0/.Note: Do not download the Windows expat installer. Download the sources instead.
  5. In the expat directory. "./configure --enable-shared", makemake install.
  6. Download the gdb sources
  7. ../gdb-7.4/configure --with-expat --target=x86_64-unknown-linux-gnu --host=i686-pc-mingw32
  8. makemake install
  9. Time to test. On your linux box, create and compile hello.cpp to hello.
  10. On your linux box, gdbserver :4444 hello Note:If you are on a corporate network, non-standard ports may be blocked. Set up an ssh tunnel if necessary.
  11. Copy hello.cpp and hello to your Windows machine
  12. From the MinGW prompt, run "x86_64-unknown-linux-gnu-gdb ./HelloNote: Substitute the name of the gdb you built as appropriate based on the target platform you got in step 2.
  13. In gdb, load the executable with "file hello"
  14. target remote localhost:4444 Note: This assumes that you have an ssh tunnel on localhost. Modify appropriately.
  15. Verify that gdb commands like break, cont, and run work here.
  16. Now we want to run it from outside of MinGW. In Control Panel/System/Advanced/Environment Variables add something like E:\MinGW\bin to the path. This is necessary for the loader to find libiconv_2.dll, etc. Now verify that you can do the preceding step from an ordinary Windows command prompt.
  17. Launch Eclipse (finally!). New debug configuration C/C++ attach to process. 
  18. In Main, give path to the copy of the Linux executable on the Windows system.
  19. In Debugger tab, set Debugger dropdown to gdbserver. Set "GDB debugger" to something like "E:\MinGW\msys\1.0\local\bin\x86_64-unknown-linux-gnu-gdb.exe" based on where your gdb is. For Connection, choose TCP and fill in the hostname and port number you've been using from gdb in the previous steps.
  20. Make sure gdbserver is running (it often quits when the program ends) and launch the debug configuration
  21. In the gdb console, enter "file hello," "break main," and cont or run (sometimes it wants one. Sometimes the other) and voila, you should be there.

Trackback 0 And Comment 0