gdb 调试器访问未找到的文件 [英] gdb debugger accessing files that are not found

查看:25
本文介绍了gdb 调试器访问未找到的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些相当简单的事情,但不明白为什么我会收到错误消息.我有一个 Makefile 我将包括在内,以便您可以看到发生了什么.但是当我逐步执行该程序时,我得到 libc-start.c: No such file or directory.有没有办法在 Makefile 中处理这个问题或避免这种情况?

I am trying to do something rather simple, but don't understand why I am getting an error. I have a Makefile I will include so you can see what is going on. But when I step through the program I get libc-start.c: No such file or directory. Is there a way to handle this in the Makefile or avoid this?

生成文件

# makefile to build a program

# program depends on components: name and main 
myname:      main.o name.o 
    g++ -g -ggdb  main.o name.o -o myname

# name.cpp has it's own header file
name.o:        name.cpp name.h
    g++ -c -g -ggdb  name.cpp

# main.cpp also uses the header file name.h
main.o:        main.cpp name.h
    g++ -c -g -ggdb main.cpp

clean:
    /bin/rm -f myname *.o

main.cpp

#include <iostream>
#include <string>
using namespace std;
#include "name.h"

int main () {
    name myName;

    myName.SetLast(LAST);
    myName.SetMiddle(MI);
    myName.SetFirst(FIRST);

    cout <<"My name is: ";
    myName.PrintFirst();
    myName.PrintMiddle();
    myName.PrintLast();

    return 0;
}

名称.cpp

#include <iostream>
#include <string>
using namespace std;
#include "name.h"

void name::GetFirst(string str) {
    str=first;
}

void name::SetFirst(string str) {
    first=str;
}

void name::GetMiddle(string str) {
    str=middle;
}

void name::SetMiddle(string str) {
    middle=str;
}

void name::GetLast(string str) {
    str=last;
}

void name::SetLast(string str) {
    last=str;
}

void name::PrintLast() {
    cout << last << "
";
}
void name::PrintMiddle() {
    cout << middle;
}
void name::PrintFirst() {
    cout << first;
}

名称.h

#define LAST    "Tank-Engine"
#define MI  "T. "
#define FIRST   "Thomas "

class name {

    private:
    string first;
    string middle;
    string last;

    public:
    void SetFirst(string str);
    void GetFirst(string str);

    void SetMiddle(string str);
    void GetMiddle(string str);

    void SetLast(string str);
    void GetLast(string str);

    void PrintLast();
    void PrintMiddle();
    void PrintFirst();

};

单步执行时gdb错误

name::PrintLast (this=0x7fffffffe4a0) at name.cpp:31
31      cout << last << "
";
(gdb) s
My name is: Thomas T. Tank-Engine
32  }
(gdb) s
main () at main.cpp:18
18          return 0;
(gdb) s
name::~name (this=0x7fffffffe4a0, __in_chrg=<optimized out>) at name.h:5
5   class name {
(gdb) s
main () at main.cpp:19
19  }
(gdb) s
__libc_start_main (main=0x400b86 <main()>, argc=1, argv=0x7fffffffe5b8, init=<optimized out>, 
fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe5a8) at libc-start.c:323
323 libc-start.c: No such file or directory.
(gdb) s
__GI_exit (status=0) at exit.c:104
104 exit.c: No such file or directory.
(gdb) s
103 in exit.c
(gdb) s
104 in exit.c
(gdb) s
__run_exit_handlers (status=0, listp=0x7ffff78ae698 <__exit_funcs>, 
run_list_atexit=run_list_atexit@entry=true) at exit.c:35
35  in exit.c
(gdb) 

推荐答案

但是当我逐步执行程序时,我得到 libc-start.c: No such file or directory

这里没有实际问题(GDB 肯定不会失败).

There is no actual problem here (and GDB is most certainly not failing).

发生的事情是你越过程序的end,进入libc(它是用调试信息编译的,但你还没有安装它的源代码).

What's happening is that you step past the end of your program, and into libc (which is compiled with debug info, but you have not installed sources for it).

许多程序员认为他们的程序的执行从 main 开始,并在 main 返回时结束.但实际上有 1000 条指令在之前和之后 main 运行,因为 libc 准备您的程序以供执行,然后在它之后进行清理.除非你是一个 libc 开发者,通常你不会关心这些之前和之后的步骤,也不应该尝试单步执行那些代码.

Many programmers believe that the execution of their program starts with main, and ends when main returns. But actually there are 1000s of instructions that run before and after main, as libc prepares your program for execution, and then cleans up after it. Unless you are a libc developer, usually you don't care about these before and after steps, and shouldn't try to step through that code.

这篇关于gdb 调试器访问未找到的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆