handle not initialized std::vector in gdb

This commit is contained in:
Roy Qu 2023-03-16 17:27:00 +08:00
parent 4633a8f93a
commit 090343bf9a
1 changed files with 15 additions and 2 deletions

View File

@ -441,11 +441,21 @@ class StdVectorPrinter:
self.typename = strip_versioned_namespace(typename) self.typename = strip_versioned_namespace(typename)
self.val = val self.val = val
self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL
start = self.val['_M_impl']['_M_start']
finish = self.val['_M_impl']['_M_finish']
end = self.val['_M_impl']['_M_end_of_storage']
if int(finish - start)<0 or int(end - start)<0 or finish > end :
self.valid = False
else:
self.valid = True
def children(self): def children(self):
return self._iterator(self.val['_M_impl']['_M_start'], if self.valid:
return self._iterator(self.val['_M_impl']['_M_start'],
self.val['_M_impl']['_M_finish'], self.val['_M_impl']['_M_finish'],
self.is_bool) self.is_bool)
else:
return None
def to_string(self): def to_string(self):
start = self.val['_M_impl']['_M_start'] start = self.val['_M_impl']['_M_start']
@ -462,8 +472,11 @@ class StdVectorPrinter:
return ('%s<bool> of length %d, capacity %d' return ('%s<bool> of length %d, capacity %d'
% (self.typename, int (length), int (capacity))) % (self.typename, int (length), int (capacity)))
else: else:
return ('%s of length %d, capacity %d' if self.valid:
return ('%s of length %d, capacity %d'
% (self.typename, int (finish - start), int (end - start))) % (self.typename, int (finish - start), int (end - start)))
else:
return ('Not initialized')
def display_hint(self): def display_hint(self):
return 'array' return 'array'