Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLDB pretty-printer is buggy #204

Open
HolyBlackCat opened this issue Jul 27, 2023 · 2 comments
Open

LLDB pretty-printer is buggy #204

HolyBlackCat opened this issue Jul 27, 2023 · 2 comments

Comments

@HolyBlackCat
Copy link

HolyBlackCat commented Jul 27, 2023

The LLDB pretty-printer sometimes prints junk values. Consider following example:

#include <iostream>
#include <parallel_hashmap/phmap.h>

struct ivec2
{
    int x = 0, y = 0;

    friend bool operator==(ivec2 a, ivec2 b)
    {
        return a.x == b.x && a.y == b.y;
    }
};

template <>
struct std::hash<ivec2>
{
    std::size_t operator()(ivec2 v) const
    {
        std::size_t ret = std::hash<int>{}(v.x);
        ret ^= std::hash<int>{}(v.y) + std::size_t(0x9E3779B97F4A7C16) + (ret << 6) + (ret >> 2);
        return ret;
    }
};

int main()
{
    phmap::flat_hash_map<ivec2, int> m{{{20,10},1},{{18,8},0}};
    std::cout << m.at({18,20}) << '\n';
}

I did:

clang++-16 1.cpp -g -Iparallel-hashmap
lldb-16 a.out

Then typed:

command script import parallel-hashmap/phmap_lldb.py
b 28
run
p m

This gave me following output:

(phmap::flat_hash_map<ivec2, int, phmap::Hash<ivec2>, phmap::EqualTo<ivec2>, std::allocator<std::pair<const ivec2, int> > >) $0 = size = 2 (capacity = 3) {
  [0] = {{...}, {...}} {
    value = {
      first = (x = 18, y = 8)
      second = 0
    }
    mutable_value = {
      first = (x = 18, y = 8)
      second = 0
    }
    key = (x = 18, y = 8)
  }
  [1] = {{...}, {...}} {
    value = {
      first = (x = 0, y = 0)
      second = 0
    }
    mutable_value = {
      first = (x = 0, y = 0)
      second = 0
    }
    key = (x = 0, y = 0)
  }
}

Notice key = (x = 0, y = 0) for the second element, while it should be key = (x = 18, y = 8).

Also, I don't know if it's easy to configure, but it's probably a good idea to remove repetition in the output too (key is printed 3 times, and the value is printed 2 times).

@greg7mdp
Copy link
Owner

Thanks for letting me know, @HolyBlackCat . It was a contribution and I don't use it myself, but I'll have a look when I have some time. It probably isn't too hard to fix.

@greg7mdp
Copy link
Owner

@HolyBlackCat I fixed the issues you mentioned. I believe it is working fine for the flat versions. The node versions still need some work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants