这两天需要在unix环境下编译代码并分析代码,我选择在window中使用VMware搭建ubuntu操作系统来工作,在搭建ubuntu时遇到的问题及解决方案:在虚拟机中使用ubuntu做开发环境的几点总结。
在ubuntu中调试代码参考了stackoverflow: line by line c-c++ code debugging in linux ubuntu[Closed]。
使用gdb调试工具,首先是在编译代码时生成调试信息,命令示例:
cc -g [filename]
option -g 指输出源码文件[filename]的调试信息。编译后生成[target file],在terminal中使用cd命令定位到代码文件,输入命令:
gdb [target file]
待gdb加载debug symbol后即可执行run命令来调试了,复制上一链接的基本操作命令:
1. cc -g file.c // compile your program ,this will generate a.out file with required debugging information
2. gdb a.out // start with gdb
3. b main // to set break point at main
4. run // run now , and it will stop at break point main
5. s // option s is to step single line and even step into functions
6. n // option n is to execute next line and step over functions
7. p variable name // to print the value of variable at that particular instance very helpful
在以后的编译和调试过程中可能会遇到各种各样的问题,也会使用到其他的开发工具,等以后遇到了这些情况再来精化这篇博客~~~