1

This is my code.When I step out of the move constructor,the debugger steps into weird looking functions(I'm new to programming) and files that are GNU extensions of the standard c++ library.

#include <iostream>
#include <vector>

using namespace std;

class Move {
private:
    int *data;
public:
    void set_data_value(int d) { *data = d; }
    int get_data_value() { return *data; }
    // Constructor
    Move(int d);
    // Copy Constructor
    Move(const Move &source);
    Move(Move &&source);
    // Destructor
    ~Move();
};

 Move::Move(int d)  {
    data = new int;
    *data = d;
    cout << "Constructor for: " << d << endl;
}


Move::Move(const Move &source)
    : Move {*source.data} {
        cout << "Copy constructor  - deep copy for: " << *data << endl;
}

//Move ctor
Move::Move(Move &&source) 
    : data {source.data} {
        source.data = nullptr;
        cout << "Move constructor - moving resource: " << *data << endl;
}

Move::~Move() {
    if (data != nullptr) {
        cout << "Destructor freeing data for: " << *data << endl;
    } else {
        cout << "Destructor freeing data for nullptr" << endl;
    }
    delete data;
}

int main(){
    vector<Move> vec;

    vec.push_back(Move{10});

    vec.push_back(Move{20});
    vec.push_back(Move{30});
    vec.push_back(Move{40});
     vec.push_back(Move{50});
    vec.push_back(Move{60});
    vec.push_back(Move{70});
    vec.push_back(Move{80});

    return 0;
}

I would like to avoid these files and functions since I have no idea what they are yet.Do you have any solutions?Thanks.

  • 1
    These are not extensions but implementation files. Unfortunately GDB does not provide a good way to skip them in a single-step mode. The [`skip` command](https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html) does NOT do a good job but you can try it if you want. – n. m. could be an AI Apr 12 '21 at 05:34
  • Which files and functions do you want to avoid? Please name them! – Basile Starynkevitch Apr 12 '21 at 13:12

1 Answers1

-2

Read the documentation of GDB. Compile your C++ code with GCC invoked as g++ -Wall -Wextra -g

Read carefully about GDB breakpoints, e.g. the tbreak command.

Notice that both GDB and GCC are free software, and you are allowed to download their source code and study then improve their code.

Take also inspiration from the source code of existing open source projects like FLTK, RefPerSys, ninja....

GDB can be extended, and GCC can be extended, with your plugins.

See also the DECODER project (and the Bismon static source code analyzer above GCC) and the Frama-C static analyzer. If interested, contact me by email to <basile.starynkevitch@cea.fr>

See also this C++ reference and some C++ standard like n3337 or better.

Consider using the Clang static analyzer (whose source code you can study, since it is open source).

Be aware of the C++ rule of five.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547