Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Add debugging tools to aid the creation of giwtypes
Browse files Browse the repository at this point in the history
Issue: #41
  • Loading branch information
Claudio dos Santos Fernandes committed Aug 30, 2018
1 parent 85ea864 commit 7b1a5a1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,15 @@ fields:
buffer in the interface. Can be very useful if your data structure represents
transposition with an internal metadata.

The function `is_symbol_observable()` receives a gdb symbol and must only return
`True` if that symbol is of the observable type (the buffer you are dealing
with).
The function `is_symbol_observable()` receives a gdb symbol and a string
containing the variable name, and must only return `True` if that symbol is of
the observable type (the buffer you are dealing with).

It is possible to debug your custom inspector methods by using the python
decorators `@interface.debug_buffer_metadata` and
`@interface.debug_symbol_observable` in the methods `get_buffer_metadata` and
`is_symbol_observable`, respectively. This will print information about all
analyzed symbols in the debugger console every time a breakpoint is hit.

For more information on how to customize this file, check out this [more
detailed blog post](https://csantosbh.wordpress.com/2016/10/15/configuring-gdb-imagewatch-to-visualize-custom-buffer-types/).
5 changes: 3 additions & 2 deletions resources/giwscripts/debuggers/gdbbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_fields_from_type(self, this_type, observable_symbols):
observable_symbols)
observable_symbols.update(type_fields)
elif ((field_name not in observable_symbols) and
(self._type_bridge.is_symbol_observable(field_val))):
(self._type_bridge.is_symbol_observable(field_val, field_name))):
try:
observable_symbols.add(field_name)
except Exception:
Expand All @@ -92,6 +92,7 @@ def get_available_symbols(self):
for symbol in block:
if symbol.is_argument or symbol.is_variable:
name = symbol.name

# Get struct/class fields
if name == 'this':
# The GDB API is a bit convoluted, so I have to do some
Expand All @@ -104,7 +105,7 @@ def get_available_symbols(self):
observable_symbols)
observable_symbols.update(type_fields)
elif ((name not in observable_symbols) and
(self._type_bridge.is_symbol_observable(symbol))):
(self._type_bridge.is_symbol_observable(symbol, name))):
try:
observable_symbols.add(name)
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion resources/giwscripts/giwtypes/eigen3.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_buffer_metadata(self, obj_name, picked_obj, debugger_bridge):
'transpose_buffer': transpose_buffer
}

def is_symbol_observable(self, symbol):
def is_symbol_observable(self, symbol, symbol_name):
"""
Returns true if the given symbol is of observable type (the type of the
buffer you are working with). Make sure to check for pointers of your
Expand Down
41 changes: 36 additions & 5 deletions resources/giwscripts/giwtypes/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@

import abc

def debug_buffer_metadata(func):
def wrapper(self, obj_name, picked_obj, debugger_bridge):
try:
metadata = func(self, obj_name, picked_obj, debugger_bridge)

print('[%s] [%s] was parsed by giwtype [%s]' %
(str(picked_obj.type), obj_name, type(self).__name__))
except Exception as error:
print('[%s] [%s] raised exception when parsed by giwtype [%s]:' %
(str(picked_obj.type), obj_name, type(self).__name__))
print(' %s' % str(error))

raise error

return wrapper

def debug_symbol_observable(func):
def wrapper(self, symbol_obj, symbol_name):
is_observable = func(self, symbol_obj, symbol_name)

if is_observable:
is_observable_str = 'is observable'
else:
is_observable_str = 'is NOT observable'

print('[' + str(symbol_obj.type) + '] [' + symbol_name + '] ' +
is_observable_str + ' by [' + type(self).__name__ + ']')

return is_observable

return wrapper

class TypeInspectorInterface():
"""
Expand Down Expand Up @@ -41,11 +72,11 @@ def get_buffer_metadata(self, obj_name, picked_obj, debugger_bridge):
pass

@abc.abstractmethod
def is_symbol_observable(self, symbol_obj):
def is_symbol_observable(self, symbol_obj, symbol_name):
"""
Given the debugger with its internal fields and type symbol_obj, this
method must return True if symbol_obj corresponds to an observable
variable (i.e. if its type corresponds to the type of the buffers that
you want to plot).
Given the debugger with its internal fields and type symbol_obj, and
its name symbol_name, this method must return True if symbol_obj
corresponds to an observable variable (i.e. if its type corresponds to
the type of the buffers that you want to plot).
"""
pass
4 changes: 2 additions & 2 deletions resources/giwscripts/giwtypes/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_buffer_metadata(self, obj_name, picked_obj, debugger_bridge):
'transpose_buffer' : False
}

def is_symbol_observable(self, symbol):
def is_symbol_observable(self, symbol, symbol_name):
"""
Returns true if the given symbol is of observable type (the type of the
buffer you are working with). Make sure to check for pointers of your
Expand Down Expand Up @@ -123,7 +123,7 @@ def get_buffer_metadata(self, obj_name, picked_obj, debugger_bridge):
'transpose_buffer': False
}

def is_symbol_observable(self, symbol):
def is_symbol_observable(self, symbol, symbol_name):
symbol_type = str(symbol.type)
type_regex = r'(const\s+)?CvMat(\s+?[*&])?'
return re.match(type_regex, symbol_type) is not None
6 changes: 3 additions & 3 deletions resources/giwscripts/typebridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ def get_buffer_metadata(self, symbol_name, picked_obj, debugger_bridge):
purpose of plotting it in the giwwindow
"""
for module in self._type_inspectors:
if module.is_symbol_observable(picked_obj):
if module.is_symbol_observable(picked_obj, symbol_name):
return module.get_buffer_metadata(symbol_name,
picked_obj,
debugger_bridge)

return None

def is_symbol_observable(self, symbol_obj):
def is_symbol_observable(self, symbol_obj, symbol_name):
"""
Returns true if any available module is able to process this particular
symbol
"""
for module in self._type_inspectors:
if module.is_symbol_observable(symbol_obj):
if module.is_symbol_observable(symbol_obj, symbol_name):
return True

return False

0 comments on commit 7b1a5a1

Please sign in to comment.