本文主要是介绍杂记 (6) —— vim, gcc, gdb, man,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
vi vistual block缩进
选中vistual block, shift + > or <
gdb无法调试最新gcc编译的程序
$ gcc -g -o fcopy fcopy.c
$ gdb fcopy
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-90.el6)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/edemon/workspace/fcopy...done.
(gdb) start
Temporary breakpoint 1 at 0x804861a
Starting program: /home/edemon/workspace/fcopy Temporary breakpoint 1, 0x0804861a in main ()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.i686
(gdb) n
Single stepping until exit from function main,
which has no line number information.
在gcc官网https://gcc.gnu.org/gcc-4.8/changes.html
查看到的信息:
General Optimizer Improvements (and Changes) DWARF4 is now the default when generating DWARF debug information. When -g is used on a platform that uses DWARF debugging inform ation, GCC will now default to -gdwarf-4 -fno-debug-types-section. GDB 7.5, Valgrind 3.8.0 and elfutils 0.154 debug information consumers support DWARF4 by default. Before GCC 4.8 the default vers ion used was DWARF2. To make GCC 4.8 generate an older DWARF version use -g together with -gdwarf-2 or -gdwarf-3. The default for Darwin and VxWorks is still -gdwarf-2 -gstrict-dwarf.
大致的意思是
gcc从4.8开始缺省使用了-gdwarf-4选项,较旧的gdb无法识别dwarf4版本的调试信息。
我们可以在用gcc编译程序时,使用选项-gdwarf-2 或者 -gdwarf-3来指定生成低版本的调试信息。
$ gcc -gdwarf-2 -o fcopy fcopy.c
$ gdb fcopy
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-90.el6)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/edemon/workspace/fcopy...done.
(gdb) start
Temporary breakpoint 1 at 0x804861d: file fcopy.c, line 5.
Starting program: /home/edemon/workspace/fcopy Temporary breakpoint 1, main () at fcopy.c:5
5 FILE *fp1 = fopen("file1.txt","r");
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.i686
(gdb) n
6 if(fp1 == NULL) {
在gdb中执行shell命令
(gdb) shell command_string
例如:
(gdb) shell cat file3.txt
Close your eyes, give me your hand, darling
梦中人熟悉的脸孔
Do you feel my heart beating
cannot open shared object file: No such file or directory
gcc -o readdir readdir.c
/usr/local/GCC-4.9/bin/../libexec/gcc/i686-pc-linux-gnu/4.9.1/cc1: error while
loading shared libraries: libmpc.so.2: cannot open shared object file: No
such file or directory
在共享库中找不到库文件libmpc.so.2
搜索他:
# find / -name libmpc.so.2
/home/edemon/mpc-0.9_temp/src/.libs/libmpc.so.2
/usr/local/mpc-0.9/lib/libmpc.so.2
直接拷贝到共享库/usr/lib
$ cp /usr/local/mpc-0.9/lib/libmpc.so.2 /usr/lib/
$ gcc readdir.c
/usr/local/GCC-4.9/bin/../libexec/gcc/i686-pc-linux-gnu/4.9.1/cc1: error while
loading shared libraries: libmpfr.so.4: cannot open shared object file: No
such file or directory
不要紧张这是另一个错误:缺少libmpfr.so.4。哈哈哈,从一个坑跳进了另一个坑。
但是解决的方法已经知道了。
总之就是缺少什么文件,搜索她并拷到/usr/lib即可
怎样用man查找和shell指令同名的函数
通过man man我们得到这样的信息:
SYNOPSISman [-acdDfFhkKtwW] [--path] [-m system] [-p string] [-C config_file] [-M pathlist] [-P pager] [-B browser] [-Hhtmlpager] [-S section_list] [section] name ...MANUAL SECTIONSThe standard sections of the manual include:1 User Commands2 System Calls3 C Library Functions4 Devices and Special Files5 File Formats and Conventions6 Games et. Al.7 Miscellanea8 System Administration tools and DeamonsDistributions customize the manual section to their specifics, which often include additional sections.
比如,现在我遇到link这个函数,用man查看的话得到的不是函数说明,而是命令。
可以这样查看函数。
$ man 2 link
文本编码的转化
例如:
[edemon@CentOS ~]$ file unknow
unknow: UTF-8 Unicode text
然后,我们借助icnov进行字符编码的转化。
[edemon@CentOS ~]$ icnov -l #可查看支持的所有编码
[edemon@CentOS ~]$ iconv -f UTF-8 -t GBK unknow -o result.txt
gcc编译得到警告信息:warning: the `gets’ function is dangerous and should not be used.
这主要是因为char *gets(char*s);
没有读取字符的限制,有可能出现溢出的危险情况,与这个函数相似的是char *fgets(char *s, int size, FILE *stream);
,它有size的限制,所以更加安全。
关于 >&2
下面的解释来自linux中国开源社区
https://linux.cn/article-3464-1.html
在shell脚本中,可以定义“错误”输出到STDERR指定的文件.需要在重定向符和文件描述符之间加一个and符(&)
cat test
#!/bin/bash
echo " this is ERROR " >&2
echo "this is output"
$
运行脚本
[root@localhost ~]# ./test 2>file1
this is output
[root@localhost ~]# cat file1
this is ERROR
使用man在线手册查询命令,重定向后出现了很多的^H
解决方案:使用col -b过滤掉所有的控制字符。
Col reads from standard input and writes to standard output.The options are as follows:-b Do not output any backspaces, printing only the last character written to each column position.
比如:
man bash |col -b > read
这篇关于杂记 (6) —— vim, gcc, gdb, man的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!