[英]How can I debug a C program on Mac Terminal with GCC?
I want to debug the C program on my Mac Terminal.我想在我的 Mac 终端上调试 C 程序。 I use "gcc -o deng.c"
我使用“gcc -o deng.c”
PS: The path is right, but it says "No such file or directory". PS:路径是正确的,但它说“没有这样的文件或目录”。
I have installed Xcode and Commd line already.我已经安装了 Xcode 和 Commd 行。
#include <stdio.h>
#include <string.h>
#define maxn 1000 + 10
int a[maxn];
int main()
{
int i, j, n, k, first=1;
memset (a, 0, sizeof(a));
scanf("%d%d", &n, &k);
for(i=1; i<=k; i++)
for (j = 1; j<=n; j++)
if(j%i == 0)
a[j] = !a[j];
for(i=1; i<=n; i++)
if(a[i])
{
if(first)
first = 0;
else
printf(" ");
printf("%d", i);
}
printf("\n");
return 0;
}
You need to use lldb, the substitute of gdb on Mac,您需要使用 lldb,Mac 上 gdb 的替代品,
gcc -g deng.c -o deng
lldb ./deng
-o
specifies the output file. -o
指定输出文件。 That's not what you want here.这不是你想要的。 You probably meant to run
你可能打算跑
gcc -g deng.c
The -g
tells the compiler to include debugging symbols. -g
告诉编译器包含调试符号。 The binary is called a.out
(and you can change the program name to deng
by running gcc -g deng.c -o deng
)该二进制文件称为
a.out
(您可以通过运行gcc -g deng.c -o deng
deng
To actually run the program, you have to run ./a.out
(or ./deng
, if you ran gcc with -o deng).要实际运行程序,您必须运行
./a.out
(或./deng
,如果您使用 -o deng 运行 gcc)。
To debug the program, you run gdb a.out
(or gdb deng
) and then type run
.要调试程序,请运行
gdb a.out
(或gdb deng
),然后键入run
。 For more help on gdb, read the documentation有关 gdb的更多帮助,请阅读文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.