Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb debugger accessing files that are not found

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 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) 
like image 445
developerME Avatar asked Feb 03 '17 00:02

developerME


People also ask

How do I set a breakpoint in GDB?

Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]".

Can you use GDB with C++?

For C and C++ programs, gdb and ddd are debuggers that you can use.

What is the need of GDB How can debugging be done using GDB?

Gdb is a debugger for C (and C++). It allows you to do things like run the program up to a certain point then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line.


1 Answers

But when I step through the program I get libc-start.c: No such file or directory

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

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).

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.

like image 181
Employed Russian Avatar answered Sep 28 '22 02:09

Employed Russian