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

查看:290
本文介绍了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

# 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;
}

name.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 << "\n";
}
void name::PrintMiddle() {
    cout << middle;
}
void name::PrintFirst() {
    cout << first;
}

name.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错误

gdb error when stepping through

name::PrintLast (this=0x7fffffffe4a0) at name.cpp:31
31      cout << last << "\n";
(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返回时结束.但是实际上,在 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天全站免登陆