lunix gcc gdb习题6.5的调试 int main(int argc,char **argv) { char *p; int i; p=malloc(30).....

编写 用gcc

[root@localhost cyuyan]# vi file66.c
[root@localhost cyuyan]# gcc -g file66.c -o file66
[root@localhost cyuyan]# cat file66.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char **argv)
{
    
    
char *p;
int i;
p=malloc(30);
strcpy(p,"not 30 bytes");
printf("p=<%s>\n",p);
if(argc==2)
{
    
    
if(strcpy(argv[1],"b")==0)
p[50]='a';
else if(strcmp(argv[1],"-f")==0)
{
    
    
free(p);
p[0]='b';
}
}
return 0;
}

用gdb调试

[root@localhost cyuyan]# gdb file66
GNU gdb (GDB) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from file66...
(gdb) r
Starting program: /home/cyuyan/file66 
p=<not 30 bytes>
[Inferior 1 (process 7892) exited normally]
(gdb) 

猜你喜欢

转载自blog.csdn.net/faith_girl/article/details/116269253