c/cpp-useful-tools
cdecl
Cdecl (and c++decl) is a program for encoding and decoding C (or C++) type declarations.
size(on mac)
size -- print the size of the sections in an object file. size -x(print by hex) -l -m a.out
otool(on mac)
otool -- object file displaying tool. otool -s __TEXT(which segment) __text(which section) a.out
nm(on mac)
see the symbol table nm libwens.so
strings
find the printable strings in a object, or other binary, file
clang++ & g++ options
- -fno-elide-constructors
debugging & profiling
- valgrind
- windows debug runtime
- tracy
- heaptrack
define config
1 |
static code analyzer
- clang static analyzer
- pvs-studio
- cppchecker
dynamic analyzer
- valgrind
- Dr.Memory
- Intel Inspector
compile analyzer
- Address sanitizer
- Memory sanitizer
- Thread sanitizer
clang main.cpp -o main -fsanitizer=address | memory | thread
performance profile tool
- intel vtune amplifier
gdb
break xxxx if xxxx
- break then execute command
1
2
3
4
5
6
7
8
9
10(gdb) b do_mmap_pgoff
Breakpoint 1 at 0xffffffff8111a441: file mm/mmap.c, line 940.
(gdb) command 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>print addr
>print len
>print prot
>end
(gdb) gdb --args pizzamaker --deep-dish --toppings=pepperoni
(gdb) set args [the arg list]
(gdb) show args
macro expand task_is_stopped_or_traced(init_task)
ctrl+x+a
toggle to / from tui modectrl+p / ctrl+n
previous or next command in tui modectrl+x+2
swith between windowsctrl+l
clear the gdb commandline or reflesh the screenset print pretty on
open print prettyset print array-indexes on
open array indexinfo share
no info in bt, maybe miss sharelib
info source
show info for current source file
set substitute-path from to
set the source filefile the_exec_file
no info in bt, maybe not read the symble of executablestart
go to program start(main function, generally)record
debug reverseg++ -g3
for macro info, which -g is g2 for defaultdprintf location, format_string
dynamic printf in gdbshow non-stop/ show scheduler-locking
gdb non-stop mode or all-stop mode- set coredump >> 默认corefile是生成在程序的执行目录下或者程序启动调用了chdir之后的目录,我们可以通过设置生成corefile的格式来控制它,让其生成在固定的目录下。
/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0 /proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,比如原来文件内容是core-%e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 # echo "/home/wens07/programming/build/core_%e_%p" > /proc/sys/kernel/core_pattern
将会控制所产生的core文件会存放到corefile目录下,产生的文件名为core-命令名-pid-时间戳
或者
$ sysctl -w kernel.core_pattern=/corefile/core-%e-%p-%t
如果想让每次启动都保存设置,则需要写入配置文件中.
# echo "kernel.core_pattern=/home/wens07/programming/build/core_%e_%p" >> /etc/sysctl.conf
# sysctl -p /etc/sysctl.conf
kernel.core_pattern =/home/wens07/programming/build/core_%e_%p
关于格式的的控制有如下几个参数:
复制代码
%%:相当于%
%p:相当于<pid>
%u:相当于<uid>
%g:相当于<gid>
%s:相当于导致dump的信号的数字
%t:相当于dump的时间
%e:相当于执行文件的名称
%h:相当于hostname
- using gdbserver
1
2
3
4
5
6
7
8 # remote target
gdbserver localhost:<port-numer> <program> <args>
# local host
gdb
file <program>
target remote <ip-of-target>:<port-numer>
set sysroot <path-to-sysroot>
-------------本文结束感谢您的阅读-------------