admin管理员组

文章数量:1122832

I am using Visual Studio Code and CMake and GDB for my project. There is a bug in my code so I have to step through the code. Basically my class has a listener which is a lambda function. So I want to set break point where the listener calls and step into where actual lambda is. But there is a problem I have to step into multiple codes (which I think implementations of the lambda) which are unnecessary. Which make lose the track of the code, rather I want to directly jump to the my lambda.

Example:

#include <iostream>
#include <functional>


class Event {
public:
    using Listener = std::function<void(const std::string&)>;

    // Set the listener
    void setListener(const Listener& listener) {
        this->listener = listener;
    }

    // Trigger the event and notify the listener
    void trigger(const std::string& message) const {
        if (listener) {
            listener(message);
        }
    }

private:
    Listener listener;
};

// Example usage
int main() {
    Event myEvent;

    // Set the listener
    myEvent.setListener([](const std::string& msg) {
        std::cout << "Listener received: " << msg << '\n';
    });

    // Trigger the event
    myEvent.trigger("Hello, listener!");

    // Clear the listener and trigger again (no output expected)
    myEvent.setListener(nullptr);
    myEvent.trigger("This won't be received");

    return 0;
}

If I add breakpoint here:

        if (listener) {

本文标签: Avoid library code when debugging c lambda functionStack Overflow