Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / solenv / gdb / libreoffice / vcl.py
blobce595747587a9da51721bf4afa66cc2e0f2141e5
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import six
11 import gdb
12 from libreoffice.util import printing
14 class ImplSchedulerDataPrinter(object):
15 '''Prints the ImplSchedulerData linked list.
17 This can be used to dump the current state of the scheduler via:
18 p *ImplGetSVData()->maSchedCtx.mpFirstSchedulerData
20 This doesn't include currently invoked tasks AKA the stack.
22 To dump the scheduler stack of invoked tasks use:
23 p *ImplGetSVData()->maSchedCtx.mpSchedulerStack
24 '''
26 def __init__(self, typename, value):
27 self.typename = typename
28 self.value = value
29 self.timer_type_ptr = gdb.lookup_type("Timer").pointer()
30 self.idle_type_ptr = gdb.lookup_type("Idle").pointer()
32 def as_string(self, gdbobj):
33 if gdbobj['mpTask']:
34 task = gdbobj['mpTask'].dereference()
35 timer = gdbobj['mpTask'].dynamic_cast( self.timer_type_ptr )
36 idle = gdbobj['mpTask'].dynamic_cast( self.idle_type_ptr )
37 if idle:
38 task_type = "Idle"
39 elif timer:
40 task_type = "Timer"
41 else:
42 task_type = "Task"
43 res = "{:7s}{:10s} active: {:6s}".format( task_type, str(task['mePriority']).replace('TaskPriority::',''), str(task['mbActive']) )
44 name = task['mpDebugName']
45 if not name:
46 res = res + " (task debug name not set)"
47 else:
48 res = "{} '{}' ({})".format(res, str(name.string()), str(task.dynamic_type))
49 val_type = gdb.lookup_type(str( task.dynamic_type )).pointer()
50 timer = gdbobj['mpTask'].cast( val_type )
51 if task_type == "Timer":
52 res = "{}: {}ms".format(res, timer['mnTimeout'])
53 elif task_type == "Idle":
54 assert 0 == timer['mnTimeout'], "Idle with timeout == {}".format( timer['mnTimeout'] )
55 return res
56 else:
57 return "(no task)"
59 def to_string(self):
60 return self.typename
62 def children(self):
63 return self._iterator(self)
65 def display_hint(self):
66 return 'array'
68 class _iterator(six.Iterator):
70 def __init__(self, printer):
71 self.pos = 0
72 self.printer = printer
73 self.value = printer.value
75 def __iter__(self):
76 return self
78 def __next__(self):
79 if not self.value:
80 raise StopIteration()
82 pos = str(self.pos)
83 name = "\n " + self.printer.as_string(self.value)
84 self.value = self.value['mpNext']
85 self.pos += 1
87 return (pos, name)
89 class ImplSchedulerContextPrinter(object):
91 def __init__(self, typename, value):
92 self.typename = typename
93 self.value = value
94 self.prio = gdb.lookup_type('TaskPriority')
96 def to_string(self):
97 res = "{\n"
98 if self.value['mnTimerPeriod']:
99 res = res + "mnTimerPeriod = " + str(self.value['mnTimerPeriod']) + "\n"
100 if self.value['mpSchedulerStack']:
101 res = res + "STACK, " + str(self.value['mpSchedulerStack'].dereference())
102 if self.value['mpFirstSchedulerData']:
103 for key, value in self.prio.items():
104 first = self.value['mpFirstSchedulerData'][value.enumval]
105 if first:
106 res = res + key.replace('TaskPriority::', '') + ", " + str(first.dereference())
107 return res + "}"
109 printer = None
111 def build_pretty_printers():
112 global printer
114 printer = printing.Printer("libreoffice/vcl")
115 printer.add('ImplSchedulerData', ImplSchedulerDataPrinter)
116 printer.add('ImplSchedulerContext', ImplSchedulerContextPrinter)
118 def register_pretty_printers(obj):
119 printing.register_pretty_printer(printer, obj)
121 build_pretty_printers()
123 # vim:set shiftwidth=4 softtabstop=4 expandtab: