Using GDB in Visual Studio

偏执的太偏执、 2022-08-03 03:13 242阅读 0赞

转自https://gpac.wp.mines-telecom.fr/2015/06/11/using-gdb-in-visual-studio/

Dear followers,

One of the target platform for GPAC is Windows. Developing for Windows in a comfortable manner requires Visual Studio, in particular for debugging. Microsoft recently announced great changes that will make Visual Studio users (including the GPAC developers) happy:

  • Visual Studio Community Edition replaces the Express Edition. It is very complete for development.
  • 6 weeks ago, Microsoft open-sourced their GDB/LLDB front-end for Visual Studio 2015. It means that we can now debug gcc-built programs with the Visual Studio debugguer interface.

Setup for local debugging

Install software:

  • Install Visual Studio 2015. Install the “Tools for Visual C++ Mobile Development” in a sub-menu (disabled by default).
  • Install gdb/gdbserver. Use MinGW-w64 binaries and put them in your PATH (you can rely on the excellent MSYS2 for a full development environment).
    /!\ Legacy MinGW and Cygwin gdb binaries are known to fail /!\

Build:

  • Use your usual build system and gcc or clang compiler. Don’t forget to enable debugging!

Debugging:

  • In your command-line, launch:
  1. <table style="box-sizing: border-box; font-size: 12px; line-height: 2; margin-left: -19px; border: none !important; border-collapse: collapse !important; border-spacing: 0px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; width: auto !important; padding: 0px !important; table-layout: auto !important; background: none !important;">
  2. <tbody style="box-sizing: border-box;">
  3. <tr style="box-sizing: border-box; padding: 0px !important; border: none !important; vertical-align: top !important; margin: 0px !important; background: 0px 50%;">
  4. <td style="box-sizing: border-box; border: 0px; padding: 0px !important; font-family: Monaco, MonacoRegular, 'Courier New', monospace !important; vertical-align: top !important; margin: 0px !important; color: rgb(134, 134, 134) !important; background-image: initial !important; background-attachment: initial !important; background-size: initial !important; background-origin: initial !important; background-clip: initial !important; background-position: initial !important; background-repeat: initial !important;">
  5. <div style="box-sizing: border-box; border: 0px; padding: 0px; margin: 0px; white-space: nowrap; line-height: 15px !important; background: 0px 50%;">
  6. <div style="box-sizing: border-box; font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important; background: 0px 50%;">
  7. 1
  8. </div>
  9. </div></td>
  10. <td style="box-sizing: border-box; border: 0px; width: 563px; padding: 0px !important; font-family: Monaco, MonacoRegular, 'Courier New', monospace !important; vertical-align: top !important; margin: 0px !important; background: 0px 50%;">
  11. <div style="box-sizing: border-box; padding: 0px; margin: 0px; white-space: pre; overflow: visible; tab-size: 4; border: none !important; color: rgb(248, 248, 242) !important; line-height: 15px !important; background: none !important;">
  12. <div style="box-sizing: border-box; font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important; background: 0px 50%;">
  13. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important; color: rgb(249, 38, 80) !important;">gdbserver </span>
  14. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">host</span>
  15. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">:</span>
  16. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important; color: rgb(249, 38, 80) !important;">port </span>
  17. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">path</span>
  18. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">/</span>
  19. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important; color: rgb(102, 217, 239) !important;">to</span>
  20. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">/</span>
  21. <span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">executable</span>
  22. </div>
  23. </div></td>
  24. </tr>
  25. </tbody>
  26. </table>
  • In Visual Studio:

    • Open the “command window” (either press CTRL+ALT+A or click: View menu -> Other Windows -> Command Window)
    • Launch:
  1. <table style="font-size:12px; line-height:2; margin-left:-19px; border:none!important; border-collapse:collapse!important; border-spacing:0px!important; margin-top:0px!important; margin-right:0px!important; margin-bottom:0px!important; width:auto!important; padding:0px!important; table-layout:auto!important; background:none!important">
  2. <tbody style="">
  3. <tr style="padding:0px!important; border:none!important; vertical-align:top!important; margin:0px!important; background:0px 50%">
  4. <td style="border:0px; padding:0px!important; font-family:Monaco,MonacoRegular,'Courier New',monospace!important; vertical-align:top!important; margin:0px!important; color:rgb(134,134,134)!important">
  5. <div style="border:0px; padding:0px; margin:0px; white-space:nowrap; line-height:15px!important; background:0px 50%">
  6. <div style="font-family:inherit; border:0px; padding:0px 5px; margin:0px; text-align:center; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; background:0px 50%">
  7. 1
  8. </div>
  9. </div> </td>
  10. <td style="border:0px; width:896px; padding:0px!important; font-family:Monaco,MonacoRegular,'Courier New',monospace!important; vertical-align:top!important; margin:0px!important; background:0px 50%">
  11. <div style="padding:0px; margin:0px; white-space:pre; overflow:visible; border:none!important; color:rgb(248,248,242)!important; line-height:15px!important; background:none!important">
  12. <div style="font-family:inherit; border:0px; padding:0px 5px; margin:0px; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; background:0px 50%">
  13. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">Debug</span>
  14. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">.</span>
  15. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">GDBLaunch</span>
  16. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; color:rgb(0,111,224)!important"> </span>
  17. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
  18. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">Executable</span>
  19. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
  20. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">path</span>
  21. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
  22. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; color:rgb(102,217,239)!important">to</span>
  23. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
  24. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">executable</span>
  25. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; color:rgb(0,111,224)!important"> </span>
  26. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
  27. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">GDBPath</span>
  28. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
  29. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">path</span>
  30. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
  31. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; color:rgb(102,217,239)!important">to</span>
  32. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
  33. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">gdb</span>
  34. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">.</span>
  35. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">exe</span>
  36. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; color:rgb(0,111,224)!important"> </span>
  37. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
  38. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">GDBServerAddress</span>
  39. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
  40. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">host</span>
  41. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
  42. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">port</span>
  43. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important; color:rgb(0,111,224)!important"> </span>
  44. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
  45. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">TargetArchitecture</span>
  46. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
  47. <span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">x64</span>
  48. </div>
  49. </div> </td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. That’s all! Once Debug.GDBLaunch is attached your program will run. Breakpoints are effective. And you can enjoy the Visual Studio debugging experience:
  54. [![20150610\_msvs\_gdb][20150610_msvs_gdb]][20150610_msvs_gdb]
  55. Setup for remote debugging
  56. This is an extension of the gdbserver we used above. It allows to debug mobile (android/iOS) or any platform (linux, …) executables from a remote
  57. For specific remote parameters, see:
  58. * [MSDN blog post][MSDN_blog post].
  59. * [A tester’s blog post][A tester_s blog post].

发表评论

表情:
评论列表 (有 0 条评论,242人围观)

还没有评论,来说两句吧...

相关阅读