在ubuntu中调试代码

这两天需要在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  

在以后的编译和调试过程中可能会遇到各种各样的问题,也会使用到其他的开发工具,等以后遇到了这些情况再来精化这篇博客~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值