Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
565 views
in Technique[技术] by (71.8m points)

c++ - Cannot instantiate printer for default visualizer VSCode

I am trying to debug the below given code in VSCode using GDB. I am not able to visualize the data in the VSCode debugger window.

enter image description here

OS : Ubuntu 16.04
GDB Version : 8.2

#include <iostream>
#include <memory>

class Account {
    private:
    double balance;

    public:
    Account(double balance = 0) : balance {balance}{
        std::cout << "Constructor" << std::endl;
    }
    void Withdraw(double amount) {
        if (balance >= amount){
            balance = balance - amount;
        } else {
            std::cout << "Insufficient funds" << std::endl;
        }
        return;
    }

    void Deposit(double amount) {
        balance = balance + amount;
        return;
    }

    void Display() {
        std::cout << "Current balance : " << balance << std::endl;
        return;
    }

    ~Account() {
        std::cout << "Destructor called " << std::endl;
    }
};

int main() {
    std::unique_ptr<Account> account_3 = std::make_unique<Account>(555);
    account_3->Display();
    account_3->Deposit(3000);
    account_3->Display();
    account_3->Withdraw(6000);
    account_3->Display();
    std::unique_ptr<Account> account_4 = std::move(account_3);
    return 0;
}

launch.json file

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/build/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            // "preLaunchTask": "g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

I have gone through the previous questions and answer but could not find the right answer which solves the issue.
As per other answers pretty printing needs to be enabled which I have already done in the launch.json file.

Could anybody please help me in fixing this issue. Any update on this please.

Thank you,
KK


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...