gdb学习3:用gdb的图形界面打开文件

版权声明:欢迎转发,转发请标明出处 https://blog.csdn.net/weixin_39465823/article/details/88897024

相比前两种方式,我觉得gdb的图形界面做的不好。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *MyStrCopy(const char *s1)
{
	if(NULL == s1)
	{
		return "string is NULL";
	}
	else
	{
/*
		char *s2 = (char *)malloc(strlen(s1)+1);
		if(NULL == s2)
		{
			return "malloc error";
		}*/
		char *s2 = NULL;
		char *p = s2;
		while((*s2++ = *s1++));
		return p;
	}	
}

int main(int argv,char **argc)
{
	const char *str1 = NULL;
	const char *str2 = "string copying";
	printf("%s\n",MyStrCopy(str1));
	printf("%s\n",MyStrCopy(str2));
	return 0;
}

编译,加入调试程序:

gyz@debian:~/mc$ gcc strcopy.c -o strcopy -g -Wall 
gyz@debian:~/mc$ gdb strcopy -tui

回车出现:

 上下左右键,是被cmd窗口或者src源码文件锁定的,所以需要切换使用:

(gdb) fs next
Focus set to cmd window.
(gdb) fs next
Focus set to src window.

详细请看我的博文(gdb的gui调试窗口与gdb命令行的切换)。

猜你喜欢

转载自blog.csdn.net/weixin_39465823/article/details/88897024
GDB