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/.
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
26 def __init__(self
, typename
, value
):
27 self
.typename
= typename
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
):
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
)
43 res
= "{:7s}{:10s} active: {:6s}".format( task_type
, str(task
['mePriority']).replace('TaskPriority::',''), str(task
['mbActive']) )
44 name
= task
['mpDebugName']
46 res
= res
+ " (task debug name not set)"
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'] )
63 return self
._iterator
(self
)
65 def display_hint(self
):
68 class _iterator(six
.Iterator
):
70 def __init__(self
, printer
):
72 self
.printer
= printer
73 self
.value
= printer
.value
83 name
= "\n " + self
.printer
.as_string(self
.value
)
84 self
.value
= self
.value
['mpNext']
89 class ImplSchedulerContextPrinter(object):
91 def __init__(self
, typename
, value
):
92 self
.typename
= typename
94 self
.prio
= gdb
.lookup_type('TaskPriority')
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
]
106 res
= res
+ key
.replace('TaskPriority::', '') + ", " + str(first
.dereference())
111 def build_pretty_printers():
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: