Linux basic development tools

Table of contents

Preface

1. yum - software package management tool        

1.1 Introduction to yum        

1.2 Use of yum

1.3 yum source update        

2. vim - text editor

2.1 Basic concepts of vim

2.2 Basic operations of vim

2.3 vim normal mode command set

2.4 vim end line mode command set

extra vim supplement

extra1 batch comments

Three ways to create files in extra2

extra3 vim supports multi-window work

Simple configuration of extra4 vim

3. gcc/g++ - compiler

3.1 Usage demonstration of gcc/g++

3.2 Translation of programs      

3.3 Concept and understanding of dynamic and static libraries        

4. make/Makefile - automated build tool

4.1 Demonstration of use of make/makefile      

4.2 Understand the basic principles of make/makefile        

extra make/makefile supplement      

5. Write a small program - progress bar      

5.0 Buffer and carriage return and line feed

5.1 Simple principle version

5.2 Engineering practice version        

5.3 C language extension (style beautification)        

6. Get to know git/gitee/github        

6.1 What is git        

6.2 Features of git

6.3 Use of git        

extra .gitignore file        

7. gdb - debugger

7.1 What is debug && release         

7.2 Using gdb



Preface

        I hope you will read this blog after you have a basic understanding of common Linux commands and permissions and other basic issues.

        When we use the Windows operating system or the Android system of our mobile phones, we can't always use some of the system's default software tools, right? We may want to add some basic development tools such as word, excel and ppt. As we become more proficient in using them, we may also need some more powerful development tools such as ps, devC++ and python. We may even download and install some games to enrich our experience. Our online lives. Then let’s take a look at the basic development tools of Linux and how to use them


1. yum - software package management tool        

1.1 Introduction to yum        

        When installing software under Linux, a common method is to download the source code of the program and compile it to obtain an executable program. But this is too troublesome (the source code itself may have bugs, compiling the source code is very difficult for us who are currently in the learning stage, and the program itself may depend on some other programs or third-party libraries), so some people Some commonly used software is compiled in advance and made into a software package (which can be understood as an installation program on Windows) and placed on a server. The compiled software package can be easily obtained through the software package manager and installed directly ( The essence of installation is to copy the executable program to the specified path). Some readers may immediately think, isn't this just like the app store or other software on our mobile phones? The fact is that software packages and package managers are like the relationship between "App" and "App Store".
        yum (Yellow dog Updater, Modified) is a very commonly used package manager under Linux. Mainly used in Fedora, RedHat, Centos and other distributions. We can get an overview of yum and yum's ecology through the picture below.
        However, since the Linux server is built by foreigners, and most of the resources in it are also provided and shared by foreigners, it may not be so easy for us to directly obtain these resources. (? Involves network security issues). Therefore, some mirror sources are also provided in China. Generally, we use the yum command to obtain software package links from domestic mirror sources.        

1.2 Use of yum

Now we can do it in practice and download some interesting software instructions through yum

安装软件需要较高的权限,可以通过sudo或切换到root账号执行命令
安装指令:yum install -y sl
卸载指令:yum remove sl
sl      #此命令可以在屏幕上驶过一辆小火车
sl -c	#显示有故障的小火车
sl -F	#小火车驶过的过程中缓缓上升

读者可以自行搜索更多有趣的指令...

如果发现这些指令无法执行,可以先安装一个yum源插件
yum install -y epel-release

 As shown in the picture, if you accidentally write the "ls" command as "sl", then a small train will interrupt your work.       

The "yum list" command can list which software packages are currently available. Since the number of software packages may be very large, here we can use the grep command to filter

1.3 yum source update        

        If you are currently using a cloud server, the yum source you are using is probably already configured. If you are currently using a virtual machine, the yum source you may be using is not domestic. We use CentOS7 as an example to update the yum source. If readers have other confusions, they can search and read more professional and detailed information by themselves.     

⭐进入yum源配置文件夹
cd /etc/yum.repos.d/

⭐做好备份,以绝后患
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

⭐获取国内的yum源    
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
(如果wget命令没有生效,输入yum -y install wget 安装wget工具)
http://mirrors.aliyun.com 阿里镜像源域名

⭐把国内的yum源,移动到对应的目录下
mv CentOS-Base.repo /etc/yum.repos.d/

        


2. vim - text editor

        IDE (Integrated Development Environment) is an integrated development environment used to provide applications with a program development environment. It generally includes tools such as code editors, compilers, debuggers, and graphical user interfaces. We generally write code in the integrated development environment under the Windows operating system. In the Linux operating system, each step from writing code, compiling code to running code can be independent, which means that we can use multiple software to help us complete each step of the process.

2.1 Basic concepts of vim

Let’s first take a look at the three most commonly used modes of vim, which are command mode, insert
mode and last line mode. The functions of each mode are distinguished as follows:
normal mode ( Normal mode)
, also called command mode, controls the movement of the screen cursor, or enters other modes of vim. In any other mode, press the "ESC" key to return to the command line mode
(Insert mode)
. In command mode, press "i" key enters this mode. Only in this mode can you input content to the file through the keyboard.
Last line mode (last line mode)
is also called bottom line mode. In command mode, press the "shift" + ";" keys to enter this mode. In this mode, you can save or exit files, replace files, search for strings, list line numbers, etc.

View all your modes: Open vim, enter the bottom line mode directly: help vim-modes

2.2 Basic operations of vim

Enter  the $vim test.c  command to edit the test.c file through the vim tool. Generally, after entering vim, these         short operations in normal mode

may be daunting to some readers. Since vim uses It's so inconvenient, why do we still need to learn to use it? Wouldn't it be nice for me to write code on other compilers? In fact, in the early years, computers did not have a mouse. We could only edit text by entering commands on the keyboard, and vim came into being. If you just write code, vim is definitely not as good as some of the software we usually use, but vim also has its own advantages.

2.3 vim normal mode command set

​⭐插入模式

按「i」切换进入插入模式「insert mode」,从光标当前位置开始编辑
按「a」进入插入模式后,从光标所在位置的后一个位置开始编辑
按「o」进入插入模式后,在光标所在位置的下面插入新的一行,并从行首开始编辑
从插入模式切换到命令模式    按「ESC」键

⭐移动光标

vim可以直接用键盘上的光标来上下左右移动,
但标准情况下vim使用的是小写英文字母「h」-> "←"「j」-> "↓"「k」-> "↑"「l」-> "→"
按[gg]:进入到文本的开始位置
按[shift+g]/「G」:移动到文本的结尾位置
按[n+shift+g]/「G」:移动到文本的第n行
按「$」:移动到光标所在行的“行尾”
按「^」:移动到光标所在行的“行首”
按「#l」:光标移到该行的第#个位置,如:5l,56l
按「w」:光标跳到下个word的开头
按「b」:光标回到上个word的开头
按「e」:光标跳到下个word的末尾

按「ctrl」+「b」:屏幕往“后”移动一页
按「ctrl」+「f」:屏幕往“前”移动一页
按「ctrl」+「u」:屏幕往“后”移动半页
按「ctrl」+「d」:屏幕往“前”移动半页

⭐复制粘贴

「yy」: 复制 光标所在行
「#yy」:复制 从光标所在行开始的共#行文本

「yw」: 复制 从光标所在位置开始到字尾
「#yw」:复制 从光标所在位置开始的共#个字

「dd」: 剪切 光标所在行
「#dd」:剪切 从光标所在行开始的共#行文本

「p」: 粘贴 缓冲区里的文本到光标所在位置
「#p」:粘贴 重复进行粘贴操作#次
注意:所有与“y”有关的复制命令都必须与“p”配合才能完成复制与粘贴功能。

⭐撤销上一次操作

「u」:撤销上一次操作
「ctrl + r」: 取消上一次的撤销操作

⭐删除文字

「x」: 删除 光标所在位置的一个字符
「#x」:删除 从光标所在位置开始的共#个字符
「X」: 删除 光标所在位置的前一个字符(大写的X)
「#X」:删除 从光标所在位置开始(向前数)的共#个字符

⭐替换

「r」: 替换 光标所在位置的字符
「#r」:替换 从光标所在位置开始的共#个字符
「R」:进入替换模式(替换光标所在位置的字符),「ESC」键回到命令模式

⭐更改

「cw」: 更改 光标所在位置的字到字尾
「c#w」:更改 从光标所在位置开始的共#个字到字尾

「shift + ~」:大小写互换(长按shift,点按~,光标右移并把光标选中的字符大小写互换)

2.4 vim end line mode command set

Before using the last line mode, please remember to press the "ESC" key to make sure you are in the normal mode, and then press the ":" colon to enter the last line mode.

⭐列出行号

「set nu」: 输入「set nu」后,会在文件中的每一行前面列出行号

⭐跳到文件中的某一行

「#」:「#」表示一个数字,在冒号后输入一个数字,再按回车键就会跳到该行了
如输入数字15,再回车,就会跳到文章的第15行

⭐查找字符

「/关键字」: 先按「/」键,再输入想寻找的字符串,如果第一次找的关键字不是想要的,
可以一直按「n」会往后寻找到您要的关键字为止。
「?关键字」:先按「?」键,再输入想寻找的字符串,如果第一次找的关键字不是想要的,
可以一直按「n」会往前寻找到您要的关键字为止。

⭐保存文件

「w」: 在冒号后输入字母「w」就可以将文件保存起来

⭐离开vim

「q」:按「q」就是退出,如果无法离开vim,可以在「q」后跟一个「!」强制离开vim
「wq」:一般建议离开时,搭配「w」一起使用,这样在退出的时候还可以保存文件

vi/vim keymap (picture comes from Internet search)

extra vim supplement

extra1 batch comments

        In command mode, press "Ctrl + v" to enter view mode. - VISUAL BLOCK -  appears in the lower left corner , indicating that you are currently in view mode .

1. "Ctrl + v" to enter view mode

2. "j", "k" select the area up and down

3.「shift + i」

4. // Double slash comment

5. Esc to complete batching

Delete comments in batches:

1. "Ctrl + v" to enter view mode

2. "h, j, k, l" select the area up, down, left and right

3. "d" delete comment

Three ways to create files in extra2

1. touch filename

2. Enter redirection>myfile.c        

3. vim code.c        

Use vim to open a non-existent file, then save and exit to create a new file.

extra3 vim supports multi-window work

        In bottom line mode, enter: vs + filename to add a window. The area where the cursor is indicates which file you are currently working in. "Ctrl + w + w" can switch between multiple windows.

Simple configuration of extra4 vim

1. Basic configuration
        Let’s first have a preliminary understanding of vim’s configuration principle: when vim starts, it will automatically scan the .vimrc file in the current user’s /home directory (create one if it does not exist) to make the options inside the .vimrc file take effect. In fact, the core of vim configuration is to add more configuration options to the .vimrc file (readers can search online for what vim configuration options are available and add them personally).   

2. Install the plug-in

        If there are more higher requirements, the native configuration may not be fully functional, and you can choose to install plug-ins to complete the configuration. Similarly, we need to create a .vim directory first to store vim plug-ins.

        The principle of installing plug-ins is similar to the basic configuration, but the operation is more complicated and diverse, and possible problems are endless. The article is limited in length and will not be introduced in detail. If readers are interested, they can search for some related tutorials on the Internet.
                 


3. gcc/g++ - compiler

        Through the previous learning, we can already use vim to write code (you can configure your vim to make writing code more comfortable). Next, I will introduce to you the commonly used compiler gcc/g++ under Linux (gcc/g++ can be used to compile C language, and only g++ can be used to compile C++)

3.1 Usage demonstration of gcc/g++

        Let’s demonstrate it through actual operation first (if your Linux currently does not have gcc/g++ installed, install it with yum install gcc or yum install gcc-c++. After the installation is completed, which gcc/g++ checks whether the installation is successful)

Note: In Linux systems, file suffixes are meaningless, but it does not mean that gcc/g++ does not care about file suffixes. Wrong file suffix will cause gcc/g++ compilation to fail        

3.2 Translation of programs      

Source file->Preprocessing->Compile->Assembly->Link->Executable program        

Note: The following content is for understanding only! Understanding this process can help us better understand program translation.

⭐Preprocessing _        

We first take readers through actual operations to learn the instructions required for the corresponding operations and compare the codes before and after preprocessing.

Let’s take a look at the preprocessing effect of a piece of code        

Through conditional compilation, dynamic tailoring of code can be achieved.        

        In real life, there are many softwares that open different functions according to the user's identity, such as: Visual Studio, idea, Xshell, VMware... Many softwares have personal/free/community editions and professional editions. In contrast, The free version has complete functions and is sufficient for our general learning and use; the professional version has very rich functions, but a certain fee will be charged. If you open a company and develop a similar software, do you think the source code behind this software needs to be maintained in two copies (one source code for the free version and one source code for the professional version)? Obviously it is one code. We can use conditional compilation to make one code play two different functions (free version and professional version) at the same time, which can save more resource costs.

⭐Compile        

⭐Compilation       

⭐Summary    

You may have a lot of doubts after reading the above introduction and analysis, but there is only one instruction we need to learn:        

 gcc code.c -o mybin.exe  

Tips: If you can't remember the command options corresponding to preprocessing, compilation, and assembly, you can look at "Esc"    in the upper left corner of the keyboard.     

        

3.3 Concept and understanding of dynamic and static libraries        

        In 3.2, we only introduced the preprocessing, compilation, and assembly in program translation. Next, we will introduce the link in detail . In fact, all the code we have written so far is standing on the shoulders of giants (someone has already written a functional interface for us that can be used directly). We only need to include a header file and it doesn't take any effort. Use the functions inside. Of course, these header files have been pre-installed in a directory under our Linux.

Before explaining what a link is, we need to first understand a new concept - function library        

        In our C program, the function implementation of "printf" is not defined, and the "stdio.h" included in the precompilation only has the declaration of the function and no implementation of the function is defined. So, where is the implementation of "printf" "What about functions?
The system puts the implementation of these functions into a library file named libc.so.6. If not specified, gcc will
search under the system's default search path "/usr/lib" , that is, linking to the libc.so.6 library function, so that the function "printf" can be used, and this is the role of the link .

        The executable program we get = the code we wrote + header files + libraries 

        Header files and libraries are essentially files. The so-called building a development environment essentially means downloading, installing and copying the header files and libraries to a specific path in the development environment (it must be found by the compiler itself). 

Let’s take a closer look at the concept of dynamic and static libraries 

Dynamic library (dynamic link) : It is a collection of all methods provided by C/C++ or other third parties, which are linked by all programs ( all functions in the library have entry addresses. The so-called dynamic link is actually The function address in the library to be linked is copied to a specific location in our executable program)        

Static library (static link) : It is a collection of all methods provided by C/C++ or other third parties. It is copied by all programs to copy the required code into their own executable programs .

Advantages and disadvantages of dynamic and static linking :

The executable program formed by dynamic linking takes up less space and saves resources. However, once the dynamic library is gone, all programs that rely on this library will not be able to run. Static linking can run independently and does not depend on the library, but it takes up more space. Large, relatively wasteful of resources.

Tips: If you are using a cloud server, generally the system does not have static links installed. If necessary, please refer to the instructions below.

sudo yum install -y glibc-static         # 安装C静态库
sudo yum install -y libstdc++-static     # 安装C++静态库

        


4. make/Makefile - automated build tool

        Make is a command, and makefile is a text file with a specific format that exists in the current directory. Use the two together to complete the automated construction of the project (the source files in a project are not counted, and they are divided into types, functions, and modules . Placed in several directories respectively, the makefile defines a series of rules to specify which files need to be compiled first, which files need to be compiled later, which files need to be recompiled, and even more complex functional operations. The so-called automated build, That is, only one make command is needed, and the entire project is completely automatically compiled, which greatly improves the efficiency of software development)  

4.1 Demonstration of use of make/makefile      

Let’s first take readers through practical operations to understand the detailed knowledge points.        

4.2 Understand the basic principles of make/makefile        

Next, let’s take a look at the basic principles of make/makefile        

How does make/makefile identify the old and new files ? How to understand the meaning of the sentence that target files modified with "PHONY" can always be executed ?
make/makefile is capable of deriving dependencies

        When we execute the make command, make will look for a file named "Makefile" or "makefile" in the current directory. If a makefile is found, it looks for the first target file (mybin) in the file from top to bottom. If the file does not exist, or the Modify time of the code.o file that mybin depends on is newer than the target file (you can use touch to test), the command defined later will be executed to generate the mybin file. By analogy, if the code.o file that mybin depends on does not exist, then make will continue to look for dependencies targeting the code.o file in the current file. If it is found (code.s), it will gradually roll back according to the dependency relationship. , until the mybin file is generated. This is the derivation ability of make/makefile dependencies . Make will look for file dependencies layer by layer until the first target file is finally compiled.  Note: During the process of searching for files, if an error occurs (for example, the last dependent file cannot be found), make will directly end the search and echo the error message. make only has the ability to deduce file dependencies. If the file after the colon does not exist after finding the dependencies, make will not do anything.
       

extra  make/makefile supplement      

        


5. Write a small program - progress bar      

5.0 Buffer and carriage return and line feed

5.1 Simple principle version

Let’s first have a brief overview of the code structure        

Next, I will take you step by step to implement a simple version of the progress bar.        

        Of course, this is just a progress bar and does not really play its role (displaying the download and installation task progress in real time). If you are interested in the source code, I have shared it below, but don’t go away, the engineering practice version The progress bar has more practical significance and is more worthy of our study.        

FILE->main.c
#include "process.h"

int main()
{
  process();
  return 0;
}

///
FILE->process.h
#pragma once

#include <stdio.h>

void process();

///
FILE->process.c
#include "process.h"
#include <string.h>
#include <unistd.h>

#define SIZE 101
#define MAX_RATE 100
#define STYLE '#'
#define SLEEPTIME 1000*200

const char *str="|/-\\";

void process()
{
  // version 1
  int rate=0;
  //char bar[SIZE] = {0};
  char bar[SIZE];
  memset(bar, '\0', sizeof(bar));
  int len = strlen(str);

  while(rate <= MAX_RATE)
  {
    printf("[%-100s][%d%%][%c]\r", bar, rate, str[rate%len]);
    fflush(stdout);
    usleep(SLEEPTIME);
    bar[rate++] = STYLE;
  }
  printf("\n");
}

        

5.2 Engineering practice version        

If you need the progress bar to match the actual download and installation task, you cannot print out the progress bar all at once. Instead, you need to update the progress bar in real time based on the task progress.        

source code:        

FILE->main.c

#include "process.h"

#define TARGET_SIZE 1024*1024   // 1M
#define DSIZE 1024*10   // 10kb

// 模拟下载
  
void download(callback_t cb)
{
  int target = TARGET_SIZE;
  int total = 0;

  while(total < target)
  {
    // 休眠模拟下载花费的时间
    usleep(SLEEPTIME);
    total += DSIZE;
    int rate = total*100/target;
    cb(rate);   // 回调函数
  }
  printf("\n");
}

int main()
{
  download(process_v2);
  return 0;
}

///
FILE->process.h
#pragma once

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define MAX_RATE 100
#define SIZE 101
#define STYLE '#'
#define SLEEPTIME 1000*200

typedef void (*callback_t)(int);

void process_v1();
void process_v2(int rate);

///
FILE->process.c

#include "process.h"

const char *str="|/-\\";

void process_v2(int rate)
{
  // version 2
  static char bar[SIZE] = {0};
  int len = strlen(str);

  if(rate <= MAX_RATE && rate >= 0)
  {
    printf("[%-100s][%d%%][%c]\r", bar, rate, str[rate%len]);
    fflush(stdout);
    bar[rate] = STYLE;
  }
  if(rate == MAX_RATE)
    memset(bar, '\0', sizeof(bar));
}

        

5.3 C language extension (style beautification)        

The code is lightweight and is for reference only. If necessary, readers are advised to search for better code online.        

FILE->main.c

#include "process.h"

#define TARGET_SIZE 1024*1024   // 1M
#define DSIZE 1024*10   // 10kb

// 模拟下载
  
void download(callback_d cb)
{
  int testcnt = 80;
  int target = TARGET_SIZE;
  int total = 0;

  while(total <= target)
  {
    usleep(SLEEPTIME);
    total += DSIZE;
    double rate = total*100.0/target;
    // 测试进度条停滞的情况,稍等几秒
    if(rate > 50.0 && testcnt) 
    {
      total = target/2;
      testcnt--;
    }
    cb(rate);   // 回调函数
  }
  cb(MAX_RATE);
  printf("\n");
}

int main()
{
  download(process_v3);
  return 0;
}

///
FILE->process.h
#pragma once

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define MAX_RATE 100
#define SIZE 101
#define STYLE '#'
#define STYLE_BODY '=' 
#define STYLE_HEADER '>'
#define SLEEPTIME 1000*60

typedef void (*callback_t)(int);
typedef void (*callback_d)(double);

void process_v1();
void process_v2(int);
void process_v3(double);

///
FILE->process.c

#include "process.h"

const char *str="|/-\\";

void process_v3(double rate)
{
  // version 3
  static char bar[SIZE] = {0};
  static int cnt = 0;
  int len = strlen(str);

  if(rate <= MAX_RATE && rate >= 0)
  {
    cnt++;
    cnt %= len;
    printf("加载中...\033[44m%-100s\033[0m[%.1f%%][%c]\r", bar, rate, str[cnt]);
    fflush(stdout);
    if(rate < MAX_RATE)
    {
      bar[(int)rate] = STYLE_BODY;
      bar[(int)rate+1] = STYLE_HEADER;
    }
    else
    {
      bar[(int)rate] = STYLE_BODY;
    }
  }
  if(rate == MAX_RATE)
    memset(bar, '\0', sizeof(bar));
}

// v3 优化了旋转光标,v2旋转光标依赖于rate,故进度条停滞会导致光标停止旋转
// 优化了rate的数据类型<double>
// 解释printf中的"\033[44m%-100s\033[0m"    \033[44m到\033[0之间的区域染为蓝色 

Test results:

        


6. Get to know git/gitee/github        

        Due to the limited length of the article, the author only introduces the most commonly used basic instructions and helps readers understand the basic principles of git.

6.1 What is git        

        Git (The stupid content tracker, stupid content tracker . This is how Linus Torvalds introduced Git to us.) is an open source distributed version control system that can handle version management of projects from very small to very large projects effectively and at high speed . [1]   It is also an open source version control software developed by Linus Torvalds to help manage Linux kernel development .

                                                                                                                ——Excerpted from Baidu Encyclopedia

        So, what is a version controller ? To give a popular example, now that you have written a blog and published it, a few days later you ask your teacher to help you see what areas can be improved. After listening to it, you felt it made sense, so you went to make some major changes, and then asked the teacher for advice. After listening to the teacher's suggestions, you made some more changes, but in the end the teacher said: Forget it, the first version is more concise and clear. . What should you do at this time? If you save and record each version of your blog, you won't have to worry about it. This method of saving each version can be called manual version control, and the space used to store each saved version is is called a warehouse . Git is a software that accomplishes this function through programming automation (managing saved content according to changes, and ultimately providing various versions during the change process). In addition, it also needs its own website: gitee/github        

6.2 Features of git

1. git is a software that is both a client and a server

2. git will only record changes in content (not saving all content in each version)

3. git is distributed software and decentralized        

gitee/github is a website built based on git software to visualize versions (reduce learning costs)        

6.3 Use of git        

gitee/github URL:

Gitee - The enterprise-level DevOps R&D performance platform provides enterprises with one-stop R&D management solutions, including code management, project management, document collaboration, test management, CICD, performance measurement and other modules, and supports SaaS, privatization and other deployments. This method helps enterprises plan and manage the R&D process in an orderly manner and improve R&D efficiency and quality. icon-default.png?t=N7T8https://gitee.com/Illustrated tutorial for creating a new warehouse and open source link for Linux users

After completing the above operations, let’s introduce the three axes of git

extra .gitignore file        

vim .gitignore can open and edit .gitignore files. Any type of files (in the form of a suffix) recorded in .gitignore will not be submitted to the warehouse.

        

        


7. gdb - debugger

7.1 What is debug && release         

        There are two ways to release a program, debug mode and release mode. Executable programs compiled by Linux gcc/g++ are in release mode by default. If you want to use gdb for debugging, you must add the -g option to debug mode when generating the executable program from the source code.
        Let's further observe and prove that there is a difference between debug mode and release mode.

        Some people may find it strange, why two releases are needed? Isn’t it good to all use the debug version? In fact, the programs used by users are all release versions, and the release version has made some optimizations to the code.

7.2 Using gdb

List of basic common commands of gdb

gdb mybin 

# base 

ctrl d 或 quit:退出
list(l) 行号/函数名:    显示mybin的源代码,每次展示10行(或列出此函数的源代码)
run(r):   运行程序/开始调试
next(n):  逐过程(会一步完成整个函数调用
step(s):  逐语句(会进入函数的内部
set var  变量名:    修改变量的值
(print)p 变量名:    打印变量的值

# 断点

break(b) 行号/函数名:    在此行(或此函数的第一条语句处)设置断点
info(i) n:    查看序号为n的断点的信息
delete(d) n:  删除序号为n的断点
disable n:    禁用序号为n的断点
enable n:     启用序号为n的断点
i/d b:        查看/删除所有断点

# 监视

display 变量名:    跟踪查看一个变量,每次停下来都显示它的值
undisplay 序号:    取消对序号指代的变量的跟踪

# 代码块定位

until 行号:       跳至该行
finish:           运行到当前函数的结尾
continue(c):      运行到下一断点处

# 堆栈

breaktrace(bt):   查看调用堆栈
info(i) locals:   查看当前栈帧局部变量的值

@0. | number 查看代码
@1. gdb会记录上一次使用的指令,可以通过Enter快捷使用上一次使用的指令
@2. 每次调试过程中,断点序号是递增的,一旦退出调试,所有断点都将被清除


        


Guess you like

Origin blog.csdn.net/weixin_72501602/article/details/132829508