Linux编程、许可与认证考试全解析
1. 代码调试示例
以下是一段代码示例及调试过程:
1 #include <stdio.h> 2 static char buf[256]; 3 void read_input(char *s); 4 int main(void) 5 { 6 char *input = NULL; /* Just a pointer, no storage for string */ 7 read_input(input); 8 /* Process command. */ 9 printf("You typed: %s\n", input); 10 /* … */在调试时,可按以下步骤操作:
1. 设置断点:
(gdb) break 7 Breakpoint 2 at 0x804842b: file dbgtst.c, line 7.- 运行程序:
(gdb) run Starting program: /home/edulaney/sw/dbgtst Breakpoint 1, main () at dbgtst.c:7 7 read_input(input);- 设置变量: