
c64659fc9b88435eeec5828e49ea2848.ppt
- Количество слайдов: 50
Pretty Printing under Qt Creator Using So-ADE Debugger Berlin 2017 Stéphane PETITHOMME E-mail: stephane@so-ade. com
Planning • What is a “Pretty Printer” • Building Custom Pretty Printers • Classes, Containers, Enums, Strings, Bit strings, Wrappers • Demo • Debugging a Pretty Printer • … And OPEN: Do not hesitate to ask questions
Qt Creator «Pretty Printer» ? ● ● Art of displaying debugging information in a way that is more suitable to human reading ● ● ● A string (displaying characters) instead of a bunch of bits or array of bytes. Hiding the data internal implementation detail to focus on the meaning Easy to use What’s about Qt-Creator ● ● Comes with support for around 330 Pretty Printers ● ● ● Qt Classes (QString, QMap, QList, Json lib, …) (140) Stl Library (String, containers) (119) Boost (list, data, time: very partial support) (8) Eigen, others (Qt-Creator internal classes) (60) Definition is static ● With dynamic presentation format (Hex, integer, QMap: key/value display style)
Qt Creator + So-ADE debugger is a Qt-Creator plugin that is specialized in creating new Pretty Printers for Qt-Creator. ● ● No Technical knowledge on How Qt-Creator is working ● ● ● Dynamic ● ● ● Abstraction layer is “almost” granting pretty printers will continue to work even if qt-creator evolves Based on code generation (the Pretty printer is translated before being executed by GDB) Multiple Pretty Printers definitions On the fly creation Set to tool to create and debug the Pretty Printers Import/export format (sharing Pretty Printers) Fully self documented interface ● Python and gdb: advice but not needed ● Support GDB Only (Windows and Linux)
So-ADE debugger ● « Pretty Printers » manager – Group management – Version management – Bulk enabling/disabling – Unique name in a group – Duplicate allowed between groups
So-ADE debugger First « Pretty Printer » ● – contextual help – Group – Naming ● the name of the C/C++ object ● Multi-valuated (; separated) – Selection of the feature mode ● Class Container ● Strings ● Bit Arrays ● Wrapper mode (Synonymous, Derived class) ● Enumerate ●
So-ADE debugger First « Pretty Printer » ● – Header – Key object heading information displayed in Qt- Creator (unfolded) – Unique – Fields list – Order prevails – Missing or erroneous definition are marked –With contextual help is needed
Defining a value How to model ● – Accessor ● Define how to access to the data (Sub-field, expression, …) – Type ● Optional data cast (resolve pointer definition, …) – Port processing ● data formatting Any entered data is syntaxically checked on the fly ●
Value: Accessor ● Various choice to define data – Formula based ● simple expression ● Dedicated simple grammar ● Data result: gdb object or string? – Lambda function (Python) – Python – inferior direct API call (method or function): AVOID at all cost! – memory offset
Built-in simple expression ● Arithmetic operators (Unary/Binary) ● Parenthesis ● Comparator operators ● Logical operators ● Bitwise operators ● Field accessor –. –. a. b ● Fonctors – Member, Field, Header, Size, Lambda, container accessor, ● & ● : ● numerical ● Strings ● concatenation (, or ; )
Built-in simple expression ● Pointer processing –. data+1 ● Underlying language rules applies ● increase size based on data size –. data&~3 ● nullify 2 LSB bits
Value: type cast ● Various ways to define type – None (optional) – C++ Type ● <> place holder for all current template type ● n re-use template type of index n ● n[. m]+ hierarchical access to class template –Template parameter from current class ● template manipulation ● option to alter the template parameter – Base Class – Can’t deal with multiple inheritance.
Value : Post-processing ● Similar to Accessor, but applied on the cast type ● Optional
Class definition Default most common case ● Easy to model ● – header – Displayed value by Qt-Creator – fields – can fold/unfold. – detail data access – may be unrelated to actual implementation
Container definition Dedicated data model for container ● No heading ● – Number of element single field ● – The container definition – Explained in detail later
Character string Dedicated to string representation ● Organized using arrays : ● – Array ● base address ● size ● character format – Encoding rule (Python encoder) String sub field (Optional) ● – size – Character based access
Bit Array Very close to strings, but for bit fields ● data model : ● – Array ● base address ● number of bit No sub-field ● – Built-in definition to be able to view individual bit.
Class Wrapper ● Simple derivation case ● Identical to the original class ● redefined class may be only a sub-part of the top-level class (practical for class holding a single field) ● The referenced class MUST: ● ● ● Being known to GDB Must be defined in So-ADE debugger. Control is done at run time
Enumerate type ● applicable to: –Enum ● Simple value ● any kind of complex mask definition – #define definition automatically extracted from source code: ● – cut/paste – direct reference to source code (include statement) from current project.
Enumerate type ● How to model – Prerequisite (not part of the definition, but used to build definition) – Definition (displayed information) – Result: automated model from definition. –Can be edited to correct mask definition ● What is displayed: automatically handled – Decode any kind of enum, regardless of complexity – show used Bit(s) – Analyse incorrect value according to definition – Formal name + real value – Multi-defnition of enum (same value, different name) – Hexadecimal or décimal
Summary - What we have seen: – Various type of high level model for Pretty Printer – How to model/access data – How to cast data - What next: – The various type of fields in a model – How to debug
Class field Field List ● – order is important – used in: Classes ● Containers ● Strings ● Many field types: ● – Basic (default) – Boolean – Enum – Array – linked container – from another model – Specialized container – Native field – Combined container – Flatten container
Basic field Name ● Value to display ●
Boolean Name ● Value to display ● What to display ● – For True value – For False value Easier to use than enum ●
Enum Name ● Value to display ● Same as general purpose enum, but applicable to a field that is not typed. ● Not reusable ●
Array (1) Name ● defined from a value ●
Array (2) applicable Model ● – start address – size – cell definition ● format ● may not be restricted to the target data – Validity condition – secondary space managememt (hash) ● Only chained list – Real number of element Only if secondary space or validity condition is defined ●
Array (3) ● Sizing - 1 -D ● value - 2 -D ● key/value pair - Not a container definition aspect. Only set by container use model for practical case - Affect visual aspect in Qt-Creator
Array (4) ● The number of element – extracted from definition – Limitation: do Dot display item over 1000 items (customizable in Qt-Creator) –CPU aspect – corrupted data – Item naming ● Singular form ● Plurial form
Array (5) Key/ Value ● Extracted as a sub-part from the cell definition ●
Linked Container (1) Name ● Value to display ● Modeling ● – Double linked tree ● List ● binary tree – items order single linked list ● 1) Data 2) link double linked list ● 1) Left 2) Data 3) Right
Linked Container (2) First cell accessor ● Link ● – Left – Right Cell Type ● – Be carefull when defining container base. Template parameter are extracted from the base Link end condition ● – NULL pointer is always an end condition. No need to defined Number of item ● – Stopper for reading the container – Size limit when extracting data Other element identical to array ●
Customized container field (1) ● Extend an existing container to fine tune key/value information ● Reference to original container model ● Name ● Value to display
Customized container field (2) ● Naming of element
Customized container field (3) ● From 1 -D Container ● ● Keep 1 D Make 2 D ● Build from key ● Overload of Value (1 D) ● Overload of Key/Value (2 D) Definition combined with original definition from the original container ● ● Option to filter the displayed value ● ● ● Base on key Base on Value Base on Both (Python only)
Customized container field (4) ● From 2 -D Container ● Reduce to 1 D ● ● ● Only Key Only Value Keep 2 D ● ● Same Swap key/Value Both from Key Both from Value
Flatten container field ● Container of container ● Presented as a single 1 -level container Extract data from 2 nd container from the 1 st container value ● ● Use case: Qt signal/slot engine ● Data spread at each class level of derivation
Combined container field (1) Regroup data from many containers into a single one. ● ● Mix 1 -D and 2 -D Sub-Container item naming is ignored. ●
Combined container field (2) ● Defines as many sub-container as wanted ● Order is important
Native Field ● Field Name ● ● For internal reference only (debug) Value to display – define start point for the display. ● Use case - Class with only header overload. - Extend GDB definition with constructed field.
Field from Model ● Field Name ● ● For internal reference only (debug) Value to display – define start point for the display. Interpret at Pretty Printer code generation level. No need to be related to GDB real type. ● ● Use case - Debug mode - Creates Pretty Printer as reusable collection of rules.
Demo Time ● On 1 st Launch ● ● ● No Debugger Need to import using built-in option Std Lib : 4. 7, 4. 8, 4, 9 , 5, 1 ● Need to select right Pretty-Printer ● Help system ● Enable/Disable Pretty Printer ● Case Sample: ● ● Container, Container specialization ● Activate Debug Mode ● Signal/Slot ● Super Cool Extra Option ● Graphs Debugging. S
Debugging Pretty Printer ● Debug Requirement ● Only on stable/valid data ● ● Avoid noise from GDB invalid data access 4 debug options ● Standard ● ● ● 3 levels of expert mode (Only if plugin compiled in debug mode) ● ● Code is generated with extra tracking information so that any reported error at execution time is automatically tracked back into So-ADE interface CPU impact Execution log of generated code Execution log of engine back-end Dump of generated code Python debug ● ● Native in standard mode Use of WARN(txt) command to report any extra data to log viewer.
Python ● Qt-Creator interface with GDB: Python based ● Many extra feature available. Full access to Python powerful library ● Since 4. 2, Qt-Creator comes with its own Python model for debugged program ● ● Uniform Abstraction over DBG/LLDB Draw back: CPU performance (10 x) depending of used API So-ADE debugger comes with a partially re-written version that reduce the CPU cost to 2 -3 x Multiple level of API: ● GDB native object representation ● ● Qt-Creator abstract layer (data model) ● ● Very close to GDB native Pro: Multi-platform, Abstract model (can create dynamic object type) Cons: Reduce set of feature (operators, Qt-Creator utility for navigating data to format pretty printer output ● ● Value, Type, Field Interface layer with Qt-Creator So-ADE debugger
Python ● Needed in So-ADE debugger: ● Qt-Creator abstract layer ● Fundamental object: the. Dumper ● ● ● data model ● ● Abstraction over GDB native python model. Extended Version ● Add support for all arithmetic operators between inferior value model and python object. ● ● Collection class that regroups all API from Qt-Creator Always Accessible in Python interface (the ‘d’ Object) Support for So-ADE debugger simple expressions So-ADE debugger: ● 2 parts: ● ● Support for the generated code. No need for direct use Utility API set: ● 2 versions (Debug/Normal). Automatically selected by engine ● Extension for the. Dumper object (Bug fixes, safe API, Overwritten API to interface with So-ADE debugger generated code, …)
Python: the. Dumper API the. Dumper. type. Template. Argument(typeobj, position) ● Extract a template argument (interpret the template parameter as a type) ● the. Dumper. numeric. Template. Argument(typeobj, position) ● Extract a template argument (interpret the template parameter as a numerical) ● the. Dumper. get. Private() ● Return the object representing the container owning this object. ● the. Dumper. save. Value(name, value) ● Contextual saving of a value to be able to reuse it at a lower level. ● the. Dumper. retrieve. Value(name, value) ● Contextual retrieval of a previously saved value. ●
Python: So-ADE debugger API format. As. String (value) ● Return the string representing the processed object (header). Is quote if the object is a string ● format. As. String. Unquote(value) ● Same as format. As. String, but never quoted ● drop. Mask(value) ● Small utility to force 2 LSB bit of a pointer to 0. (safe) ● safe. Cast(value, typeobj) ● Cast an object from its current type to the wanted type performing basic sanity check and reporting meaningful errors to GUI interface. ● get. Header(value) ● Return the header of a class as per So-ADE debugger model definition. ● get. Header. Force(value, force. Type) ● Return the header of a class as per So-ADE debugger provided model definition. ● get. Field(value, field. Name) ● Return a class field as per So-ADE debugger model definition. ● get. Field. Force(value, fieldname, force. Type) ● Return a class field as per So-ADE debugger provided model definition. ●
Python: So-ADE debugger API get. Member(value, field. Name) ● Return a class field as per GDB definition (Equivalent to value[fieldname], but with extra sanity check. Used in debug mode only) ● get. Size(value) ● Return the size (number of element) of a container. ● get. Container. Value(value, field. Name) ● Return all values from the fieldname of value. Field field. Name must be of a container type. . ● get. Base. Type(value, index) ● Access to the base type of an object ● get. Base. Object(value, index) ● Cast an object to its base type ●
License / Installation aspect Software available under GPL 3. 0, ● ● No Warranty Possible to purchase a support license ● ● Contact info : stephane@so-ade. com Installation aspect ● ● Qt Creator 4. 3. 82 (Community build) ● Qt Creator plugin debugger need to be build with no private linkage
Thank You www. so-ade. com Stéphane PETITHOMME
c64659fc9b88435eeec5828e49ea2848.ppt