Using GDB in Visual Studio
转自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:
<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;">
<tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box; padding: 0px !important; border: none !important; vertical-align: top !important; margin: 0px !important; background: 0px 50%;">
<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;">
<div style="box-sizing: border-box; border: 0px; padding: 0px; margin: 0px; white-space: nowrap; line-height: 15px !important; background: 0px 50%;">
<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%;">
1
</div>
</div></td>
<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%;">
<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;">
<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%;">
<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>
<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>
<span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">:</span>
<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>
<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>
<span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">/</span>
<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>
<span style="box-sizing: border-box; font-family: inherit; height: inherit; font-size: inherit !important; line-height: inherit !important; font-weight: inherit !important;">/</span>
<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>
</div>
</div></td>
</tr>
</tbody>
</table>
In Visual Studio:
- Open the “command window” (either press CTRL+ALT+A or click: View menu -> Other Windows -> Command Window)
- Launch:
<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">
<tbody style="">
<tr style="padding:0px!important; border:none!important; vertical-align:top!important; margin:0px!important; background:0px 50%">
<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">
<div style="border:0px; padding:0px; margin:0px; white-space:nowrap; line-height:15px!important; background:0px 50%">
<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%">
1
</div>
</div> </td>
<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%">
<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">
<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%">
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">Debug</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">.</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">GDBLaunch</span>
<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>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">Executable</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">path</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
<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>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">executable</span>
<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>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">GDBPath</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">path</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
<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>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">\</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">gdb</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">.</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">exe</span>
<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>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">GDBServerAddress</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">host</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">port</span>
<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>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">/</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">TargetArchitecture</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">:</span>
<span style="font-family:inherit; height:inherit; font-size:inherit!important; line-height:inherit!important; font-weight:inherit!important">x64</span>
</div>
</div> </td>
</tr>
</tbody>
</table>
That’s all! Once Debug.GDBLaunch is attached your program will run. Breakpoints are effective. And you can enjoy the Visual Studio debugging experience:
[![20150610\_msvs\_gdb][20150610_msvs_gdb]][20150610_msvs_gdb]
Setup for remote debugging
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
For specific remote parameters, see:
* [MSDN blog post][MSDN_blog post].
* [A tester’s blog post][A tester_s blog post].
还没有评论,来说两句吧...