Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Using Debugging Helpers

Debugging Helper Library with C++

While debugging, Qt Creator dynamically loads a helper library into your program. This helper library enables Qt Creator to pretty print Qt and STL types. The Qt SDK package already contains a prebuilt debugging helper library. To create your own debugging helper library, select Tools > Options... > Qt4 > Qt Versions. As the internal data structures of Qt can change between versions, the debugging helper library is built for each Qt version.

Debugging Helper Library with Python

With the gdb Python version, you can use debugging helpers also for user defined types. To do so, define one Python function per user defined type in .gdbinit.

The function name has to be qdump__NS__Foo, where NS::Foo is the class or class template to be examined. Nested namespaces are possible.

The debugger plugin calls this function whenever you want to display an object of this type. The function is passed the following parameters:

  • d of type Dumper
  • item of type Item

The function has to feed the Dumper object with certain information which is used to build up the object and its children's display in the Locals and Watchers view.

Example:

 def qdump__QVector(d, item):
     d_ptr = item.value["d"]
     p_ptr = item.value["p"]
     alloc = d_ptr["alloc"]
     size = d_ptr["size"]

     check(0 <= size and size <= alloc and alloc <= 1000 * 1000 * 1000)
     check(d_ptr["ref"]["_q_value"] > 0)

     innerType = item.value.type.template_argument(0)
     d.putItemCount(size)
     d.putNumChild(size)
     if d.isExpanded(item):
         p = gdb.Value(p_ptr["array"]).cast(innerType.pointer())
         with Children(d, [size, 2000], innerType)
             for i in d.childRange():
                 d.putItem(Item(p.dereference(), item.iname, i))
                 p += 1

Item Class

The Item Python class is a thin wrapper around values corresponding to one line in the Locals and Watchers view. The Item members are as follows :

  • __init__(self, value, parentiname, iname, name = None) - A constructor. The object's internal name is created by concatenating parentiname and iname. If None is passed as name, a serial number is used.
  • value - An object of type gdb.Value representing the value to be displayed.
  • iname - The internal name of the object, constituting a dot-separated list of identifiers, corresponding to the position of the object's representation in the view.
  • name - An optional name. If given, is used in the name column of the view. If not, a simple number in brackets is used instead.

Dumper Class

For each line in the Locals and Watchers view, a string like the following needs to be created and channeled to the debugger plugin.

 "{iname='some internal name',
   addr='object address in memory',
   name='contents of the name column',
   value='contents of the value column',
   type='contents of the type column',
   numchild='number of children',        // zero/nonzero is sufficient
   childtype='default type of children', // optional
   childnumchild='default number of grandchildren', // optional
   children=[              // only needed if item is expanded in view
      {iname='internal name of first child',
       ... },
      {iname='internal name of second child',
       ... },
      ...
   ]}"

While in theory, you can build up the entire string above manually, it is easier to employ the Dumper Python class for that purpose. The Dumper Python class contains a complete framework to take care of the iname and addr fields, to handle children of simple types, references, pointers, enums, known and unknown structs as well as some convenience methods to handle common situations.

The Dumper members are the following:

  • __init__(self) - Initializes the output to an empty string and empties the child stack.
  • put(self, value) - Low level method to directly append to the output string.
  • putCommaIfNeeded(self) - Appends a comma if the current output ends in '}', '"' or ']' .
  • putField(self, name, value) - Appends a comma if needed, and a name='value' field.
  • beginItem(self, name) - Starts writing a field by writing name='.
  • endItem(self) - Ends writing a field by writing '.
  • endChildren(self) - Ends writing a list of children.
  • childRange(self) - Returns the range of children specified in the current Children scope.
  • putItemCount(self, count) - Appends a field value='<%d items' to the output.
  • putEllipsis(self) - Appends fields '{name="<incomplete>",value="",type="",numchild="0"}'. This is automatically done by endChildren if the number of children to print is smaller than the number of actual children.
  • putName(self, name) - Appends a name='...' field.
  • putType(self, type) - Appends a field type='...' unless the type coincides with the parent's default child type.
  • putNumChild(self, numchild) - Appends a field numchild='...' unless the numchild coincides with the parent's default child numchild value.
  • putValue(self, value, encoding = None) - Append a file value='...', optionally followed by a field valueencoding='...'. The value needs to be convertible to a string entirely consisting of alphanumerical values. The encoding parameter can be used to specify the encoding in case the real value had to be encoded in some way to meet the alphanumerical-only requirement. Currently the following encodings are supported:
    • 0: unencoded 8 bit data, interpreted as Latin1.
    • 1: base64 encoded 8 bit data, used for QByteArray, double quotes are added.
    • 2: base64 encoded 16 bit data, used for QString, double quotes are added.
    • 3: base64 encoded 32 bit data, double quotes are added.
    • 4: base64 encoded 16 bit data, without quotes (see 2)
    • 5: base64 encoded 8 bit data, without quotes (see 1)
    • 6: %02x encoded 8 bit data (as with QByteArray::toHex), double quotes are added.
    • 7: %04x encoded 16 bit data (as with QByteArray::toHex), double quotes are added.
  • putStringValue(self, value) - Encodes a QString and calls putValue with the correct encoding setting.
  • putByteArrayValue(self, value) - Encodes a QByteArray and calls putValue with the correct encoding setting.
  • isExpanded(self, item) - Checks whether the item with the internal name item.iname is expanded in the view.
  • isExpandedIName(self, iname) - Checks whether the item with the internal name iname is expanded in the view.
  • putIntItem(self, name, value) - Equivalent to:
         self.beginHash()
         self.putName(name)
         self.putValue(value)
         self.putType("int")
         self.putNumChild(0)
         self.endHash()
  • putBoolItem(self, name, value) - Equivalent to:
         self.beginHash()
         self.putName(name)
         self.putValue(value)
         self.putType("bool")
         self.putNumChild(0)
         self.endHash()
  • pushOutput(self) - Moves the output string to a safe location from with it is sent to the debugger plugin even if further operations raise an exception.
  • putCallItem(self, name, item, func) - Uses gdb to call the function func on the value specified by item.value and output the resulting item. This function is not available when debugging core dumps and it is not available on the Symbian platform due to restrictions imposed by AppTRK.
  • putItemHelper(self, item) - The "master function", handling basic types, references, pointers and enums directly, iterates over base classes and class members of compound types and calls qdump__* functions whenever appropriate.
  • putItem(self, item) - Equivalent to:
         with SubItem(self):
             self.putItemHelper(item)

    Exceptions raised by nested function calls are caught and all output produced by putItemHelper is replaced by the output of:

             ...
         except RuntimeError:
             d.put('value="<invalid>",type="<unknown>",numchild="0",')

Children and SubItem Class

The attempt to create child items might lead to errors if data is uninitialized or corrupted. To gracefully recover in such situations, use Children and SubItem Context Managers to create the nested items.

The Children constructor __init__(self, dumper, numChild = 1, childType = None, childNumChild = None) uses one mandatory argument and three optional arguments. The mandatory argument refers to the current Dumper object. The optional arguments can be used to specify the number numChild of children, with type childType_ and childNumChild_ grandchildren each. If numChild_ is a list of two integers, the first one specifies the actual number of children and the second the maximum number of children to print.

Similarly, using the SubItem class helps to protect individual items.

Example:

 d.putNumChild(2)
 if d.isExpanded(item):
     with Children(d):
         with SubItem(d):
             d.putName("key")
             d.putItemHelper(Item(key, item.iname, "key"))
         with SubItem(d):
             d.putName("value")
             d.putItemHelper(Item(value, item.iname, "value"))

X

rc="scripts/functions.js" type="text/javascript">
Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtcreator-2.0
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web