版本控制器git
为了能够更方便管理这些不同版本的文件,有了版本控制器,可以了解一个文件的历史,以及它的发展过程的系统,通俗的说就是一个可以记录工程的每一次改动和版本迭代的一个管理系统,同时也方便多人协作。
三板斧
下载项目到本地
创建一个防置代码的目录
git clone 链接
1.git add
将代码放到下载好的目录中
git add 文件名
2.git commit
提交改动到本地(在协同时,别人改了,而你不知道的情况下也交了改动的,那么你会提交不了,得先同步别人改动的到你这里,然后才可以提交)
git commit -m “xxx”
3.git push
同步到远端服务器上
这时要输入gitee的用户名和密码,这里用户名是@的后面的。
代码示例:
1.要进入到gitee的目录里面
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# pwd
/root/zym/c-small-pants
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants#
2.写好的代码
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# touch mycode.c
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# vim mycode.c
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants#
3.git add
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# git add mycode.c
4.git commit(加-m指定信息)
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# git commit -m "测试用例"
[master fe43477] 测试用例
1 file changed, 8 insertions(+)
create mode 100644 mycode.c
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants#
5.git push
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# git push
Username for 'https://gitee.com': zhong-iming
Password for 'https://zhong-iming@gitee.com':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 322 bytes | 322.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 1e4a7eb8
To https://gitee.com/zhong-iming/c-small-pants.git
e3b1905..fe43477 master -> master
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants#
调试器-gdb/cgdb使用
程序发布方式有俩种,debug模式和release模式,Linux gcc/g++出来的二进制程序,默认是release模式
要使用gdb调试,必须在源代码生成二进制程序的时候,加上-g选项,说明是debug模式。
代码示例:
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# gcc -o file file.c
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# file file
file: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=cb0c2a14e62f02b1b4c61b83570301866fab50c1, for GNU/Linux 3.2.0, not stripped
//没加-g选项没有debug信息
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# gcc -o file file.c -g
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# file file
file: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=a3343bb6c7630505b89539a79e3f09727f627859, for GNU/Linux 3.2.0, with debug_info//有debug信息加了-g选项, not stripped
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants#
常见使用
gdb 目标文件
ctrl+d或quit调试命令
代码演示:
r运行出结果 5050
root@iZbp1be068ksa92vuf0kbdZ:~/zym/c-small-pants# gdb file
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from file...
(gdb) r
Starting program: /root/zym/c-small-pants/file
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
I will begin
running done, result is: [1-100]=5050 /结果展示
[Inferior 1 (process 68489) exited normally]
(gdb)
cgdb调试是会把源文件的代码一起显示的
b+行号 断点
删除断点 d+断点编号
先用info b去查看断点的信息,可以知道断点编号
逐过程 n/next
逐语句step/s
输入一个指令后按enter会直接执行上一个命令