Implement new approach for debugging leaked wrapper object references (issue #2593)

This commit is contained in:
Marshall Greenblatt
2019-01-23 16:42:12 +01:00
parent 176e14d451
commit 3fe062a5b6
576 changed files with 8806 additions and 733 deletions

View File

@ -29,11 +29,20 @@ def make_cpptoc_function_impl_existing(cls, name, func, impl, defined_names):
name, func, parts) + '{' + changes + impl['body'] + '\n}\n\n'
def make_cpptoc_function_impl_new(cls, name, func, defined_names):
def make_cpptoc_function_impl_new(cls, name, func, defined_names, base_scoped):
# Special handling for the cef_shutdown global function.
is_cef_shutdown = name == 'cef_shutdown' and isinstance(
func.parent, obj_header)
# retrieve the C API prototype parts
parts = func.get_capi_parts(defined_names)
result = make_cpptoc_impl_proto(name, func, parts) + ' {'
if isinstance(func.parent, obj_class) and \
not func.parent.has_attrib('no_debugct_check') and \
not base_scoped:
result += '\n shutdown_checker::AssertNotShutdown();\n'
invalid = []
# retrieve the function arguments
@ -296,6 +305,11 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names):
result += '\n'
result_len = len(result)
if is_cef_shutdown:
result += '\n\n#if DCHECK_IS_ON()'\
'\n shutdown_checker::SetIsShutdown();'\
'\n#endif\n'
# execution
result += '\n // Execute\n '
@ -406,8 +420,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names):
result += '\n'
result_len = len(result)
# special handling for the global cef_shutdown function
if name == 'cef_shutdown' and isinstance(func.parent, obj_header):
if is_cef_shutdown:
classes = func.parent.get_classes()
names = []
@ -423,7 +436,7 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names):
if len(names) > 0:
names = sorted(names)
result += '\n#if DCHECK_IS_ON()'\
'\n // Check that all wrapper objects have been destroyed'
'\n // Check that all wrapper objects have been destroyed.'
for name in names:
result += '\n DCHECK(base::AtomicRefCountIsZero(&' + name + '::DebugObjCt));'
result += '\n#endif // DCHECK_IS_ON()'
@ -462,7 +475,8 @@ def make_cpptoc_function_impl_new(cls, name, func, defined_names):
return result
def make_cpptoc_function_impl(cls, funcs, existing, prefixname, defined_names):
def make_cpptoc_function_impl(cls, funcs, existing, prefixname, defined_names,
base_scoped):
impl = ''
for func in funcs:
@ -477,13 +491,14 @@ def make_cpptoc_function_impl(cls, funcs, existing, prefixname, defined_names):
impl += make_cpptoc_function_impl_existing(cls, name, func, value,
defined_names)
else:
impl += make_cpptoc_function_impl_new(cls, name, func, defined_names)
impl += make_cpptoc_function_impl_new(cls, name, func, defined_names,
base_scoped)
return impl
def make_cpptoc_virtual_function_impl(header, cls, existing, prefixname,
defined_names):
defined_names, base_scoped):
funcs = []
funcs.extend(cls.get_virtual_funcs())
cur_cls = cls
@ -499,7 +514,7 @@ def make_cpptoc_virtual_function_impl(header, cls, existing, prefixname,
cur_cls = header.get_class(parent_name, defined_names)
return make_cpptoc_function_impl(cls, funcs, existing, prefixname,
defined_names)
defined_names, base_scoped)
def make_cpptoc_virtual_function_assignment_block(funcs, offset, prefixname):
@ -590,8 +605,8 @@ def make_cpptoc_class_impl(header, clsname, impl):
template_class = 'CefCppToCRefCounted'
# generate virtual functions
virtualimpl = make_cpptoc_virtual_function_impl(header, cls, existing,
prefixname, defined_names)
virtualimpl = make_cpptoc_virtual_function_impl(
header, cls, existing, prefixname, defined_names, base_scoped)
if len(virtualimpl) > 0:
virtualimpl = '\nnamespace {\n\n// MEMBER FUNCTIONS - Body may be edited by hand.\n\n' + virtualimpl + '} // namespace'
@ -604,7 +619,7 @@ def make_cpptoc_class_impl(header, clsname, impl):
# generate static functions
staticimpl = make_cpptoc_function_impl(cls,
cls.get_static_funcs(), existing, None,
defined_names)
defined_names, base_scoped)
if len(staticimpl) > 0:
staticimpl = '\n// GLOBAL FUNCTIONS - Body may be edited by hand.\n\n' + staticimpl
@ -617,6 +632,13 @@ def make_cpptoc_class_impl(header, clsname, impl):
clsname+'CppToC::'+clsname+'CppToC() {\n'
const += make_cpptoc_virtual_function_assignment(header, cls, prefixname,
defined_names)
const += '}\n\n'+ \
'// DESTRUCTOR - Do not edit by hand.\n\n'+ \
clsname+'CppToC::~'+clsname+'CppToC() {\n'
if not cls.has_attrib('no_debugct_check') and not base_scoped:
const += ' shutdown_checker::AssertNotShutdown();\n'
const += '}\n\n'
# determine what includes are required by identifying what translation
@ -670,7 +692,7 @@ def make_cpptoc_global_impl(header, impl):
# generate global functions
impl = make_cpptoc_function_impl(None,
header.get_funcs(), existing, None,
defined_names)
defined_names, False)
if len(impl) > 0:
impl = '\n// GLOBAL FUNCTIONS - Body may be edited by hand.\n\n' + impl