mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
Fixed file naming
This commit is contained in:
Vendored
+41
-45
@@ -1,8 +1,8 @@
|
||||
# Python lldb formatters for parallel-hashmap
|
||||
# tested witch clang 10 / lldb 9 & 10
|
||||
# tested witch clang10 / lldb9 & 10
|
||||
|
||||
# to install it, type the following command or put it in $HOME/.lldbinit:
|
||||
# command script import "PATH_TO_SCRIPT/phmap_lldb.py"
|
||||
# command script import "PATH_TO_SCRIPT/lldb_phmap.py"
|
||||
|
||||
|
||||
import lldb
|
||||
@@ -16,8 +16,9 @@ _MODULE_NAME = os.path.basename(__file__).split(".")[0]
|
||||
|
||||
|
||||
def _get_function_name(instance=None):
|
||||
res = f"{type(instance).__name__}." if instance else ""
|
||||
return res + sys._getframe(1).f_code.co_name
|
||||
"""Return the name of the calling function"""
|
||||
class_name = f"{type(instance).__name__}." if instance else ""
|
||||
return class_name + sys._getframe(1).f_code.co_name
|
||||
|
||||
|
||||
class flat_map_slot_type:
|
||||
@@ -40,17 +41,14 @@ class flat_map_slot_type:
|
||||
|
||||
|
||||
class node_map_slot_type:
|
||||
CLASS_PATTERN = r"^(" \
|
||||
r"phmap::priv::raw_hash_set<phmap::priv::NodeHashMapPolicy.*>::slot_type" \
|
||||
r"|" \
|
||||
r"std::remove_cv<\s*std::pair\s*<.*>\s*>::type" \
|
||||
r")$"
|
||||
CLASS_PATTERN = r"phmap::priv::raw_hash_set<phmap::priv::NodeHashMapPolicy.*>::slot_type$"
|
||||
HAS_SUMMARY = True
|
||||
IS_SYNTHETIC_PROVIDER = False
|
||||
|
||||
@staticmethod
|
||||
def summary(valobj, _):
|
||||
try:
|
||||
valobj = valobj.Dereference()
|
||||
first = valobj.GetChildMemberWithName('first').GetSummary()
|
||||
if not first: first = "{...}"
|
||||
second = valobj.GetChildMemberWithName('second').GetSummary()
|
||||
@@ -58,7 +56,23 @@ class node_map_slot_type:
|
||||
return f"{{{first}, {second}}}"
|
||||
except BaseException as ex:
|
||||
print(f"{_get_function_name()} -> {ex}")
|
||||
return ""
|
||||
return "{?}"
|
||||
|
||||
|
||||
class node_set_slot_type:
|
||||
CLASS_PATTERN = r"phmap::priv::raw_hash_set<phmap::priv::NodeHashSetPolicy.*>::slot_type$"
|
||||
HAS_SUMMARY = True
|
||||
IS_SYNTHETIC_PROVIDER = False
|
||||
|
||||
@staticmethod
|
||||
def summary(valobj, _):
|
||||
try:
|
||||
summary = valobj.Dereference().GetSummary()
|
||||
if not summary: summary = "{...}"
|
||||
return summary
|
||||
except BaseException as ex:
|
||||
print(f"{_get_function_name()} -> {ex}")
|
||||
return "{?}"
|
||||
|
||||
|
||||
class flat_hash_map_or_set:
|
||||
@@ -75,7 +89,7 @@ class flat_hash_map_or_set:
|
||||
return f"size = {size} (capacity = {capacity})"
|
||||
except BaseException as ex:
|
||||
print(f"{_get_function_name()} -> {ex}")
|
||||
return ""
|
||||
return "{?}"
|
||||
|
||||
def __init__(self, valobj, _):
|
||||
self.valobj = valobj
|
||||
@@ -119,25 +133,29 @@ class flat_hash_map_or_set:
|
||||
if ctrl >= -1:
|
||||
real_idx += 1
|
||||
if real_idx == index:
|
||||
return self.slots_.CreateChildAtOffset(f'[{index}]', real_idx * self.slot_size, self.slot_type)
|
||||
return self.slots_.CreateChildAtOffset(f'[{index}]', idx * self.slot_size, self.slot_type)
|
||||
except BaseException as ex:
|
||||
print(f"{_get_function_name(self)} -> {ex}")
|
||||
return None
|
||||
|
||||
|
||||
class parallel_flat_or_node_base:
|
||||
REGEX_EXTRACT_ARRAY_SIZE = re.compile(f"std::array\s*<.*,\s*(\d+)\s*>")
|
||||
class parallel_flat_or_node_map_or_set:
|
||||
CLASS_PATTERN = "^phmap::parallel_(flat|node)_hash_(map|set)<.*>$"
|
||||
HAS_SUMMARY = True
|
||||
IS_SYNTHETIC_PROVIDER = True
|
||||
REGEX_EXTRACT_ARRAY_SIZE = re.compile(r"std::array\s*<.*,\s*(\d+)\s*>")
|
||||
|
||||
@staticmethod
|
||||
def _get_size_and_capacity(valobj):
|
||||
try:
|
||||
valobj = valobj.GetNonSyntheticValue()
|
||||
sets = valobj.GetChildMemberWithName('sets_')
|
||||
# sets is an std::array<T, SIZE>.
|
||||
# It's not possible to get the size of the array with templates parameters
|
||||
# "set.GetType().GetTemplateArgumentType(1)" returns an "unsigned long" type but not the value
|
||||
# so we must extract it with a regex
|
||||
n_buckets = int(
|
||||
parallel_flat_or_node_base.REGEX_EXTRACT_ARRAY_SIZE.match(sets.GetType().GetName()).group(1))
|
||||
m = parallel_flat_or_node_map_or_set.REGEX_EXTRACT_ARRAY_SIZE.match(sets.GetType().GetName())
|
||||
n_buckets = int(m.group(1))
|
||||
# this is dependent on the implementation of the standard library
|
||||
buckets = sets.GetChildMemberWithName('_M_elems')
|
||||
size = capacity = 0
|
||||
@@ -151,7 +169,7 @@ class parallel_flat_or_node_base:
|
||||
|
||||
@staticmethod
|
||||
def summary(valobj, _):
|
||||
size, capacity, _ = parallel_flat_or_node_base._get_size_and_capacity(valobj)
|
||||
size, capacity, _ = parallel_flat_or_node_map_or_set._get_size_and_capacity(valobj)
|
||||
return f"size = {size} (capacity = {capacity})"
|
||||
|
||||
def __init__(self, valobj, _):
|
||||
@@ -159,9 +177,6 @@ class parallel_flat_or_node_base:
|
||||
self.buckets = self.slot_type = None
|
||||
self.size_ = self.capacity_ = self.n_buckets_ = self.slot_type = self.ctrl_size = 0
|
||||
|
||||
def using_nodes(self):
|
||||
return False
|
||||
|
||||
def num_children(self):
|
||||
return min(self.size_, _MAX_CHILDREN)
|
||||
|
||||
@@ -174,8 +189,6 @@ class parallel_flat_or_node_base:
|
||||
self.buckets = self.valobj.GetChildMemberWithName('sets_').GetChildMemberWithName('_M_elems')
|
||||
bucket0 = self.buckets.GetChildAtIndex(0).GetChildMemberWithName('set_')
|
||||
self.slot_type = bucket0.GetChildMemberWithName('slots_').GetType().GetPointeeType()
|
||||
if self.using_nodes():
|
||||
self.slot_type = self.slot_type.GetPointeeType()
|
||||
self.slot_size = self.slot_type.GetByteSize()
|
||||
except BaseException as ex:
|
||||
print(f"{_get_function_name(self)} -> {ex}")
|
||||
@@ -198,19 +211,17 @@ class parallel_flat_or_node_base:
|
||||
total_idx = 0
|
||||
for idx in range(self.n_buckets_):
|
||||
bucket = self.buckets.GetChildAtIndex(idx).GetChildMemberWithName('set_')
|
||||
capacity = bucket.GetChildMemberWithName("capacity_").GetValueAsUnsigned()
|
||||
if capacity:
|
||||
size = bucket.GetChildMemberWithName("size_").GetValueAsUnsigned()
|
||||
if size:
|
||||
slots_ = bucket.GetChildMemberWithName("slots_")
|
||||
ctrl_ = bucket.GetChildMemberWithName("ctrl_")
|
||||
for jdx in range(capacity):
|
||||
for jdx in range(size):
|
||||
ctrl = ctrl_.GetChildAtIndex(jdx).GetValueAsSigned()
|
||||
if ctrl >= -1:
|
||||
real_idx += 1
|
||||
if real_idx == index:
|
||||
if self.using_nodes():
|
||||
return slots_.Dereference().CreateChildAtOffset(f'[{index}]', jdx * self.slot_size, self.slot_type)
|
||||
return slots_.CreateChildAtOffset(f'[{index}]', jdx * self.slot_size, self.slot_type)
|
||||
total_idx += capacity
|
||||
total_idx += size
|
||||
if total_idx > _MAX_CHILDREN:
|
||||
return None
|
||||
except BaseException as ex:
|
||||
@@ -218,28 +229,13 @@ class parallel_flat_or_node_base:
|
||||
return None
|
||||
|
||||
|
||||
class parallel_flat_hash_map_or_set(parallel_flat_or_node_base):
|
||||
CLASS_PATTERN = "^phmap::parallel_flat_hash_(map|set)<.*>$"
|
||||
HAS_SUMMARY = True
|
||||
IS_SYNTHETIC_PROVIDER = True
|
||||
|
||||
|
||||
class parallel_node_hash_map_or_set(parallel_flat_or_node_base):
|
||||
CLASS_PATTERN = "^phmap::parallel_node_hash_(map|set)<.*>$"
|
||||
HAS_SUMMARY = True
|
||||
IS_SYNTHETIC_PROVIDER = True
|
||||
|
||||
def using_nodes(self):
|
||||
return True
|
||||
|
||||
|
||||
def __lldb_init_module(debugger, internal_dict):
|
||||
for sp in (
|
||||
flat_map_slot_type,
|
||||
node_map_slot_type,
|
||||
node_set_slot_type,
|
||||
flat_hash_map_or_set,
|
||||
parallel_flat_hash_map_or_set,
|
||||
parallel_node_hash_map_or_set,
|
||||
parallel_flat_or_node_map_or_set,
|
||||
):
|
||||
if sp.HAS_SUMMARY:
|
||||
debugger.HandleCommand(
|
||||
|
||||
Reference in New Issue
Block a user