Sublime Text 3 Using the Sublimegdb graphical debug C + + program

Source: Internet
Author: User
Tags sublime text







This article describes how to implement a convenient graphical interface for debugging in sublime text by installing the Sublimegdb plugin.



In the previous article sublime text 3, configuring the C + + compilation environment, we introduced the method of compiling and running C + + code using sublime text 3. However, only one key to run the code, but can not be one-step debugging is a bit uncomfortable. Although the debug code under Windows is better than the VS, sometimes we only have a simple CPP file, and then the VS construction project is a bit overqualified.


Preparing for work installation MinGW


The preparation here is to install the tools you want to use GCC g++ and gdb. For more information about these, refer to the installation MinGW, which repeats the steps only once:



1. Download MinGW



This provides the mingw extracted from the Codeblocks-13.12mingw-setup:



Http://pan.baidu.com/s/1gd5YzVP



After decompression, put the MinGW folder into the C packing directory



2. Add Environment variables



Environment variables, advanced system settings, properties, right-click Computer




In the value of path, you can find some directories that are separated by semicolons in English .   We double-click on path to add our GCC path C:\MinGW\bin. Be aware of the English semicolon before and after.





Test


When the above steps are done, restart windows. (If you can use GCC in cmd without restarting, it may not work in sublime and will cause strange problems)




Create a new main.cpp in the D-Drive test directory with the following content






#include <cstdio> int main()
{ int a=3; int b;

    a=a+2;
    b=a+2;

    printf("%d\n",b); return 0;
}





Then hold down SHIFT and right-click in the space and choose to open the Command window here.









Perform




g++-G Main.cpp-o maingdb Main





The first sentence generates a main.exe executable that can be debugged, and the second sentence goes into GDB debugging






In GdB, use start to run, enter N to execute next sentence, enter I locals view current variable






If you enter I locals, you can see the value of the variable, and it's half done.


Installing SUBLIMEGDB


Use the package control to install, if you have not installed the package control, you can refer to the installation of the package control



Then open through the menu preferneces, package control, select the Install package






Then enter SUBLIMEGDB and click on it to install it.





Modifying a configuration file


Select Preferneces, Package Settings, Sublimegdb-Settings–user






Enter the content below






{
    "workingdir":"${folder:${file}}",
    "commandline":"g++ -g -std=c++11 ${file} -o ${file_base_name} && gdb --interpreter=mi --args ./${file_base_name}",
}





Save. Restart Sublime.


Using Sublimegdb


The cursor is placed on a line, and a breakpoint is added by pressing the F9 key






When the breakpoint is set, press F5 to start debugging






Default shortcut keys (you can modify Default.sublime-keymap by modifying the shortcut keys)


Keys Function
F5 Start debugging
Ctrl+f5 Stop Debugging
F9 Set breakpoints
F10 Step over, perform one step, do not enter function
F11 Step into, enter function
Shift+f11 Step out, jump out of function


Click on the gdb callstack to jump to the corresponding function.



In the window GDB Variables can see the value of the variable, double-click the variable can modify the value of the variable. If the variable name has a plus sign to the left, you can expand the view sub-variable.



At the bottom of the GdB window can be entered GDB command to run, you can refer to GdB debugging beginners (a) | Aloft



You can also use the right-click GDB menu to implement these features









Transferred from: http://www.yalewoo.com/sublimegdb.html



Yalewoo



Sublime Text 3 Using the Sublimegdb graphical debug C + + program (GO)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.