微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Raspbian 中分叉进程时进行调试

如何解决在 Raspbian 中分叉进程时进行调试

我目前正试图在 Raspbian Buster 上用纯 C 语言运行一段代码(uname -a:Linux raspBerrypi 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l GNU/ Linux)

代码使用简单的 Makefile 编译。

Console.WriteLine

在调试器中我可以看到,它进入主函数,然后在使用 CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe INCLUDE = -I/usr/local/include SRCS = $(wildcard *.h) $(wildcard *.c) LDFLAGS = -L/usr/local/lib LDLIBS = -lwiringpi -lgeniePi -lm -lrt LIBS = -lc -lpthread DEMOHEADER = ./geniePi.h DEMOSRCS = ./demo1.c DEMOLIB = /usr/local/lib/libgeniePi.so all: applic applic: $(SRCS) $(CC) -ggdb -g $^ -o $@ $(LDLIBS) 命令时崩溃

fork()

错误信息是

int main(void) {

  /* Our process ID and Session ID */
  pid_t pid,sid;

  /* Fork off the parent process */
  pid = fork();
  if (pid < 0) {
    exit(EXIT_FAILURE);
  }
  ...

尝试使用最小示例时,我注意到它不是特定于 fork 的 .. 此处无法加载 printf

Started new gdb process,pid 6558
The program is not being run.
File not found: /build/glibc-FUvrFr/glibc-2.28/nptl/pt-fork.c
Fetching assembly since file is missing
File not found: /build/glibc-FUvrFr/glibc-2.28/posix/../sysdeps/nptl/fork.c
Fetching assembly since file is missing
File not found: /build/glibc-FUvrFr/glibc-2.28/csu/../sysdeps/unix/sysv/linux/arm/aeabi_read_tp.S
Fetching assembly since file is missing
Fetching assembly since file is missing
File not found: /build/glibc-FUvrFr/glibc-2.28/nptl/register-atfork.c
Fetching assembly since file is missing
File not found: /build/glibc-FUvrFr/glibc-2.28/nptl/../malloc/dynarray-skeleton.c

错误信息:

#include <stdio.h>
#include <unistd.h>

int main()
{
    printf("hello");
    pid_t pid,sid;

    /* Fork off the parent process */
    pid = fork();
    if (pid < 0) {
      exit(1);
    }
    return 0;
}

有什么想法可能会在这里出错,或者我如何找到有关错误的更多信息?

解决方法

好吧,在我看来,我误解了调试器的输出。调试器输出只是告诉我没有可用的 libc 源。程序继续运行并在另一点崩溃。但是由于一开始的分叉,我无法再设置断点或单步执行程序,调试器没有跟踪第二个进程。目前我正在调试而不分叉另一个进程,我将检查如何在我的调试器中执行此操作。

编辑: 后来我找到了在我的调试器设置中将“set follow-fork-mode child”设置为要发送到gdb的init命令的解决方案

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。