C语言 没有名为 main.c 的源文件。gdb断点设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19151643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No source file named main.c. gdb break point setting
提问by arslan
I am using gdb for debugging C project source code. I compile as shown:
我正在使用 gdb 调试 C 项目源代码。我编译如图:
./configure --enable-debug CFLAGS="-g -o0"
make --debug=a
I want to debugging stop at specific file. So when I set break point by using
我想调试停止在特定文件。所以当我使用设置断点时
(gdb) break main.c:672
It says:
它说:
No source file named main.c.
Even when I pass specific function name (in main.c file) to break . it says: such function not defined.
即使我将特定的函数名称(在 main.c 文件中)传递给 break 。它说:这样的功能没有定义。
My current directory has this main.c file. I am using Cygwin on Windows. When I set break point by using
我的当前目录有这个 main.c 文件。我在 Windows 上使用 Cygwin。当我使用设置断点时
(gdb) break main
It set break point at a main function of Cygwin file, not in my source code.
它在 Cygwin 文件的主要功能上设置断点,而不是在我的源代码中。
how can I fix my first problem?
just curious, how to avoid second problem, if there is same function name within Cygwin files and my source code?
我怎样才能解决我的第一个问题?
只是好奇,如果 Cygwin 文件和我的源代码中有相同的函数名,如何避免第二个问题?
采纳答案by wilywampa
If you're compiling with -gand still not able to set a breakpoint, try adding raise(SIGTRAP)in your main(), run the process in gdb, then set the breakpoint you want again after it hits the SIGTRAP.
如果您正在编译-g但仍然无法设置断点,请尝试添加raise(SIGTRAP)您的main(),在 gdb 中运行该进程,然后在遇到SIGTRAP.
回答by Sohil Omer
When you compile your .cfile, make sure you use:
编译.c文件时,请确保使用:
gcc filename.c -g
gdb <binary name>
Search for load debugging symbols done or not?
搜索加载调试符号是否完成?
If not:
如果不:
gdb) symbol-file <path-of-symbol-file>
you can find symbol file in obj directory
您可以在 obj 目录中找到符号文件
回答by dyomas
Crucial is gcc parameter -g during compilation.
关键是编译期间的 gcc 参数 -g。
Everything else is secondary.
其他一切都是次要的。
查看GDB 中的断点
回答by Kulwant Bhambra
I also encountered with similar problem earlier. I just deleted .metadatafolder and imported the particular project again and that work well.
我之前也遇到过类似的问题。我刚刚删除了.metadata文件夹并再次导入了特定项目,效果很好。
回答by user2430771
Whenever you have to use GDB, type the following in command line
每当您必须使用 GDB 时,请在命令行中键入以下内容
gcc -g -o outputfile sourcefile.c
Now type
现在输入
gdb -tui outputfile
and then enter the break command
然后输入break命令

