nm^ar^gcc^gdb^make 重点 nm -a /usr/local/ossasn1/linux-glibc2.2.trial/8.5.0/lib/libasn1code.a (| grep -i symbol) gcc -E:预处理完成后停止编译,生产.i文件 -c:将文件编译为目标代码,不链接 -Wall:产生尽可能多的警告信息 -Werror:把所有警告当成错误处理,并终止编译 -w:禁止所有报警
-g(3):把调试信息加到可执行文件,便于调试,不能与-O同时使用 On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make otherdebuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, -gdwarf-1+, -gdwarf-1, or -gvms -On:控制代码优化, n=0,1,2,3 通常-O2用的较多,因为它在优化程度,编译时间和代码大小间取得了比较理想的平衡
gcc在链接时优先使用动态链接库,当动态链接库不存在时,才考虑静态链接库 -static:强制使用静态链接库 -L libpath -static -lmylib:链接libmylib.a -L libpath -lmylib:链接libmylib.so gcc下程序链接静态库:主文件必须在静态库前面!gcc -0 test test.c -lmylib
-pipe:提高编译速度 -Dmacro:定义宏macro
gdb gdb <program> gdb <program> core gdb <program> PID //attach
gdb 环境中执行linux的shell命名 shell <command args> make <make-args> // = shell make <make-args>
run > output //重定向输出
breakpoint, watchpoint, catchpoint watch,rwatch,awatch catch <event>:event发生时停止程序,event={throw, catch, exec, fork, vfork, load, unload}
handle <signal> <keywords...>
info threads b linespec thread <threadno> (if ...)
bt frame <n>:切换当前栈 up/down <n> info frame/frame:查看当前栈信息
info locals:当前函数的局部变量值
-g编译过后的执行程序中包含了源文件的名字,没有路径名 dir <dirname...>:添加一个源文件路径到当前路径的前面,多个路径用:隔开 show directories:显示当前定义了的源文件搜索路径
源代码的内存地址 info line {<line>/<func>/<file:line>/<file:func>} disassemble:查看源程序的汇编代码
p/{x/t/d/u/o/a/c/f}@len
examine <addr>:查看内存 info registers:查看寄存器
调试多进程 set detach-on-fork [on|off] GDB多线程调试的基本命令 info threads 查看当前进程的线程。 thread apply all command 让所有被调试线程执行GDB命令command。 set scheduler-locking off|on|step,这个是问得最多的。在使用step或者continue命令调试当前被调试线程的时候,其他线程也是同时执行的,怎么只让被调试程序执行呢?通过这个命令就可以实现这个需求。 off 不锁定任何线程,也就是所有线程都执行,这是默认值。 on 只有当前被调试程序会执行。 step 在单步的时候,除了next过一个函数的情况(熟悉情况的人可能知道,这其实是一个设置断点然后continue的行为)以外,只有当前线程会执行。 调试宏:在GCC编译程序的时候,加上-ggdb3参数,就可以了 x/s 以字符串输出 command命令,其就是把一组gdb的命令打包,有点像字处理软件的“宏”。 (gdb) command 1 Type commands for when breakpoint 1 is hit, one per line. End with a line saying just "end". >print arg1 >print arg2 >print arg3 >end (gdb) 一些辅助的诊断及调试工具: make |
|