调试 c++ : ../nptl/sysdeps/unix/sysv/linux/raise.c: 没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13152775/
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
debugging c++ : ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory
提问by wangzhiju
I'm using gdb
to debug a C++
program. In the line
我正在gdb
用来调试C++
程序。在行中
assert(prevId == GetTagIdFromState(maxState));
- the parameter
prevId
value is0
; - the method
GetTagIdFromState(maxState)
return
s50
;
- 参数
prevId
值为0
; - 该方法
GetTagIdFromState(maxState)
return
小号50
;
when debugging this, I get the following errors.
调试时,我收到以下错误。
Assertion `prevId == GetTagIdFromState(maxState)' failed.
Program received signal SIGABRT, Aborted.
0x00007ffff6ecbba5 in raise (sig=<value optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
in ../nptl/sysdeps/unix/sysv/linux/raise.c
回答by SingerOfTheFall
Your application works as intended. The assertion fails (since the values you pass to it are not equal, the assert
macro receives 0), and thus your program is being aborted. That's how asserts work:
您的应用程序按预期工作。断言失败(因为你传递给它的值不相等,assert
宏接收到 0),因此你的程序被中止。这就是断言的工作方式:
If NDEBUG is not defined, then assert checks if its argument(which must have scalar type) compares equal to zero. If it does, assert outputs implementation-specific diagnostic information on the standard error output and calls std::abort.
如果未定义 NDEBUG,则assert 检查其参数(必须具有标量类型)比较是否等于 0。如果是, assert 在标准错误输出上输出特定于实现的诊断信息并调用 std::abort。
emphasis mine.
强调我的。
Check this assert referencefor further information.
检查此断言参考以获取更多信息。
回答by Marvo
I just encountered this error while trying to debug a program on a Raspberry Pi. The program happens to use the GPIO in a manner that requires that the program be run as root. For example, I run the program I wrote like this:
我刚刚在尝试调试 Raspberry Pi 上的程序时遇到了这个错误。该程序碰巧以要求程序以 root 身份运行的方式使用 GPIO。例如,我运行我写的程序是这样的:
sudo ./foo
I forgot this, however, when starting up the debugger, and tried
然而,我在启动调试器时忘记了这一点,并尝试
gdb foo
And I got the error you seem to have encountered:
我收到了您似乎遇到的错误:
Program received signal SIGABRT, Aborted.
0x76cd0f70 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
When I ran it using sudo, it worked fine.
当我使用 sudo 运行它时,它运行良好。
sudo gdb foo
Hope that's helpful to someone in the same boat.
希望这对同一条船上的人有所帮助。
回答by Alireza Soori
This should bring you up to speed about using assert function
这应该让您了解使用断言功能的速度
void assert (int expression);
Evaluate assertion If the argument expression of this macro with functional form compares equal to zero (i.e., the expression is false), a message is written to the standard error device and abort is called, terminating the program execution.
Evaluate assertion 如果这个具有函数形式的宏的参数表达式比较等于零(即,表达式为假),则将一条消息写入标准错误设备并调用 abort,终止程序执行。
The specifics of the message shown depend on the specific implementation in the compiler, but it shall include: the expression whose assertion failed, the name of the source file, and the line number where it happened. A usual expression format is:
显示的消息的细节取决于编译器中的具体实现,但它应包括:断言失败的表达式、源文件的名称和发生的行号。通常的表达格式是:
Assertion failed: expression, file filename, line line number This macro is disabled if at the moment of including assert.h a macro with the name NDEBUG has already been defined. This allows for a coder to include many assert calls in a source code while debugging the program and then disable all of them for the production version by simply including a line like:
断言失败:表达式、文件文件名、行行号 如果在包含名为 NDEBUG 的 assert.ha 宏时已经定义了该宏,则该宏被禁用。这允许编码人员在调试程序时在源代码中包含许多断言调用,然后通过简单地包含如下行来禁用所有这些调用:
#define NDEBUG at the beginning of its code, before the inclusion of assert.h.
Therefore, this macro is designed to capture programming errors, not user or running errors, since it is generally disabled after a program exits its debugging phase. from: C++ Ref
因此,此宏旨在捕获编程错误,而不是用户或运行错误,因为它通常在程序退出调试阶段后被禁用。来自:C++ 参考