以下代碼在獨立(非除錯)模式下作業。但是,當我嘗試越過時 gdb 除錯停止popen(),這意味著fgets()永遠無法到達處的斷點。
#include <stdio.h>
int main()
{
char buff[10];
FILE *f = popen("echo blah", "r");
// program and debugger exit before this line
// so that fgets() and printf() were never called
fgets(buff, 5, f);
printf("%s\n", buff);
}
GDB 報告說Program terminated with signal SIGTRAP, Trace/breakpoint trap.我研究了 glibc popen(),這就是它退出的地方,
// internal-signal.h
/* Block all signals, including internal glibc ones. */
static inline void
__libc_signal_block_all (sigset_t *set)
{
INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &sigall_set, set,
__NSIG_BYTES);
}
有誰知道這里發生了什么?謝謝!
uj5u.com熱心網友回復:
結果證明是內核問題,至少當我從 5.15.x 恢復到 5.14.x 時,問題就消失了。我認為內核更新永遠不會破壞用戶空間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/370489.html
下一篇:除錯IBMCloud功能
