Skip to content

std::string is not instrumented properly on MacOS #3

@codeinred

Description

@codeinred

Applications compiled on MacOS use an instance of std::string::~string() linked in from the C++ standard library. This means that std::string lacks annotates.

Take the following program as an example:

#include <string>
#include <vector>

struct my_object {
    std::string       s;
    std::vector<char> v;

    template <size_t N>
    my_object(char const (&cstr)[N]) : s(cstr)
                                     , v(cstr, cstr + N) {}
};

int main() { my_object a = "01234556789 this is a string that's too big for SSO etc"; }

If we dump out the stats for my_object, we see this:

// Totals for my_object sizeof=48 bytes
// └── 112 bytes across 2 allocs and 1 instance
struct my_object
{
  std::string       s;
  std::vector<char> v; // 56 bytes across 1 alloc : std::vector<char>

  ~my_object();
  // directly owned (or unannotated):
  // └── 56 bytes across 1 alloc
};

Both my_object::s and my_object::v should show 56 bytes, but only v has recorded bytes.

Since std::string's destructor isn't annotated, the 56 bytes owned by my_object::s are instead treated as directly owned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions