Linux 编程与脚本入门指南
1. 调试与GNU许可证理解
在Linux编程中,调试是解决程序问题的重要环节。例如,当程序因段错误崩溃后,我们可以使用gdb进行调试。以下是一个具体的调试示例:
(gdb) file dbgtst A program is being debugged already. Kill it? (y or n) y Load new symbol table from “/home/naba/sw/dbgtst”? (y or n) y Reading symbols from /home/naba/sw/dbgtst...done. (gdb) list 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 /* ... */ (gdb) break 7 Breakpoint 2 at 0x804842b: file dbgtst.c, line 7. (gdb) run Starting progr