【调试技巧】一种针对正在运行的进程中途写值快速调试的方法

来源:互联网 发布:java timestamp long 编辑:程序博客网 时间:2024/06/05 14:52
// 程序接口运行上文#if 1  int test_fd = open ("/tmp/test_file", O_RDWR|O_CREAT);  char test_buff[16] = {0};  int test_rs = 0;  if (test_rs = read (test_fd, test_buff, sizeof (test_buff)) > 0)  {    /* 字符串strcpy拷贝,数字atoi转化 */    #if 0    strncpy (want_test_buff, test_buff, sizeof (want_test_value));    printf ("want_test_buff = %s\n", want_test_buff);    #else    want_test_value = atoi (test_buff);    printf ("want_test_value = %d\n", want_test_value);    #endif  }#endif// 程序接口运行下文

终端窗口一:
前台运行程序,实时输出log或者输出到文件。


终端窗口二:
# echo "88" >/tmp/test_file
# cat /tmp/test_file
88

# echo "任意想要调试的值" >/tmp/test_file

从log中观察该值在后续的运行时变化状态,实时跟进,实现最简单的快速调试多个值或字符串。



主要节约的是编译这个最耗时的时间,事半功倍。
原创粉丝点击