1<html lang="en"> 2<head> 3<title>Types In Python - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Python-API.html#Python-API" title="Python API"> 9<link rel="prev" href="Values-From-Inferior.html#Values-From-Inferior" title="Values From Inferior"> 10<link rel="next" href="Pretty-Printing-API.html#Pretty-Printing-API" title="Pretty Printing API"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 15Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation; with the 20Invariant Sections being ``Free Software'' and ``Free Software Needs 21Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 22and with the Back-Cover Texts as in (a) below. 23 24(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 25this GNU Manual. Buying copies from GNU Press supports the FSF in 26developing GNU and promoting software freedom.''--> 27<meta http-equiv="Content-Style-Type" content="text/css"> 28<style type="text/css"><!-- 29 pre.display { font-family:inherit } 30 pre.format { font-family:inherit } 31 pre.smalldisplay { font-family:inherit; font-size:smaller } 32 pre.smallformat { font-family:inherit; font-size:smaller } 33 pre.smallexample { font-size:smaller } 34 pre.smalllisp { font-size:smaller } 35 span.sc { font-variant:small-caps } 36 span.roman { font-family:serif; font-weight:normal; } 37 span.sansserif { font-family:sans-serif; font-weight:normal; } 38--></style> 39<link rel="stylesheet" type="text/css" href="../cs.css"> 40</head> 41<body> 42<div class="node"> 43<a name="Types-In-Python"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>, 46Previous: <a rel="previous" accesskey="p" href="Values-From-Inferior.html#Values-From-Inferior">Values From Inferior</a>, 47Up: <a rel="up" accesskey="u" href="Python-API.html#Python-API">Python API</a> 48<hr> 49</div> 50 51<h5 class="subsubsection">23.2.2.4 Types In Python</h5> 52 53<p><a name="index-types-in-Python-1623"></a><a name="index-Python_002c-working-with-types-1624"></a> 54<a name="index-gdb_002eType-1625"></a><span class="sc">gdb</span> represents types from the inferior using the class 55<code>gdb.Type</code>. 56 57 <p>The following type-related functions are available in the <code>gdb</code> 58module: 59 60 <p><a name="index-gdb_002elookup_005ftype-1626"></a> 61 62<div class="defun"> 63— Function: <b>lookup_type</b><var> name </var>[<var>block</var>]<var><a name="index-lookup_005ftype-1627"></a></var><br> 64<blockquote><p>This function looks up a type by name. <var>name</var> is the name of the 65type to look up. It must be a string. 66 67 <p>If <var>block</var> is given, then <var>name</var> is looked up in that scope. 68Otherwise, it is searched for globally. 69 70 <p>Ordinarily, this function will return an instance of <code>gdb.Type</code>. 71If the named type cannot be found, it will throw an exception. 72</p></blockquote></div> 73 74 <p>An instance of <code>Type</code> has the following attributes: 75 76 <dl> 77 78 <div class="defun"> 79— Instance Variable of Type: <b>code</b><var><a name="index-code-1628"></a></var><br> 80<blockquote> <p>The type code for this type. The type code will be one of the 81<code>TYPE_CODE_</code> constants defined below. 82</p></blockquote></div> 83 84 <div class="defun"> 85— Instance Variable of Type: <b>sizeof</b><var><a name="index-sizeof-1629"></a></var><br> 86<blockquote> <p>The size of this type, in target <code>char</code> units. Usually, a 87target's <code>char</code> type will be an 8-bit byte. However, on some 88unusual platforms, this type may have a different size. 89</p></blockquote></div> 90 91 <div class="defun"> 92— Instance Variable of Type: <b>tag</b><var><a name="index-tag-1630"></a></var><br> 93<blockquote> <p>The tag name for this type. The tag name is the name after 94<code>struct</code>, <code>union</code>, or <code>enum</code> in C and C<tt>++</tt>; not all 95languages have this concept. If this type has no tag name, then 96<code>None</code> is returned. 97</p></blockquote></div> 98 </dl> 99 100 <p>The following methods are provided: 101 102 <dl> 103 104 <div class="defun"> 105— Method on Type: <b>fields</b><var><a name="index-fields-on-Type-1631"></a></var><br> 106<blockquote> <p>For structure and union types, this method returns the fields. Range 107types have two fields, the minimum and maximum values. Enum types 108have one field per enum constant. Function and method types have one 109field per parameter. The base types of C<tt>++</tt> classes are also 110represented as fields. If the type has no fields, or does not fit 111into one of these categories, an empty sequence will be returned. 112 113 <p>Each field is an object, with some pre-defined attributes: 114 <dl> 115<dt><code>bitpos</code><dd>This attribute is not available for <code>static</code> fields (as in 116C<tt>++</tt> or Java). For non-<code>static</code> fields, the value is the bit 117position of the field. 118 119 <br><dt><code>name</code><dd>The name of the field, or <code>None</code> for anonymous fields. 120 121 <br><dt><code>artificial</code><dd>This is <code>True</code> if the field is artificial, usually meaning that 122it was provided by the compiler and not the user. This attribute is 123always provided, and is <code>False</code> if the field is not artificial. 124 125 <br><dt><code>is_base_class</code><dd>This is <code>True</code> if the field represents a base class of a C<tt>++</tt> 126structure. This attribute is always provided, and is <code>False</code> 127if the field is not a base class of the type that is the argument of 128<code>fields</code>, or if that type was not a C<tt>++</tt> class. 129 130 <br><dt><code>bitsize</code><dd>If the field is packed, or is a bitfield, then this will have a 131non-zero value, which is the size of the field in bits. Otherwise, 132this will be zero; in this case the field's size is given by its type. 133 134 <br><dt><code>type</code><dd>The type of the field. This is usually an instance of <code>Type</code>, 135but it can be <code>None</code> in some situations. 136</dl> 137 </p></blockquote></div> 138 139 <div class="defun"> 140— Method on Type: <b>array</b><var> n1 </var><span class="roman">[</span><var>n2</var><span class="roman">]</span><var><a name="index-array-on-Type-1632"></a></var><br> 141<blockquote> <p>Return a new <code>gdb.Type</code> object which represents an array of this 142type. If one argument is given, it is the inclusive upper bound of 143the array; in this case the lower bound is zero. If two arguments are 144given, the first argument is the lower bound of the array, and the 145second argument is the upper bound of the array. An array's length 146must not be negative, but the bounds can be. 147</p></blockquote></div> 148 149 <div class="defun"> 150— Method on Type: <b>const</b><var><a name="index-const-on-Type-1633"></a></var><br> 151<blockquote> <p>Return a new <code>gdb.Type</code> object which represents a 152<code>const</code>-qualified variant of this type. 153</p></blockquote></div> 154 155 <div class="defun"> 156— Method on Type: <b>volatile</b><var><a name="index-volatile-on-Type-1634"></a></var><br> 157<blockquote> <p>Return a new <code>gdb.Type</code> object which represents a 158<code>volatile</code>-qualified variant of this type. 159</p></blockquote></div> 160 161 <div class="defun"> 162— Method on Type: <b>unqualified</b><var><a name="index-unqualified-on-Type-1635"></a></var><br> 163<blockquote> <p>Return a new <code>gdb.Type</code> object which represents an unqualified 164variant of this type. That is, the result is neither <code>const</code> nor 165<code>volatile</code>. 166</p></blockquote></div> 167 168 <div class="defun"> 169— Method on Type: <b>range</b><var><a name="index-range-on-Type-1636"></a></var><br> 170<blockquote> <p>Return a Python <code>Tuple</code> object that contains two elements: the 171low bound of the argument type and the high bound of that type. If 172the type does not have a range, <span class="sc">gdb</span> will raise a 173<code>RuntimeError</code> exception. 174</p></blockquote></div> 175 176 <div class="defun"> 177— Method on Type: <b>reference</b><var><a name="index-reference-on-Type-1637"></a></var><br> 178<blockquote> <p>Return a new <code>gdb.Type</code> object which represents a reference to this 179type. 180</p></blockquote></div> 181 182 <div class="defun"> 183— Method on Type: <b>pointer</b><var><a name="index-pointer-on-Type-1638"></a></var><br> 184<blockquote> <p>Return a new <code>gdb.Type</code> object which represents a pointer to this 185type. 186</p></blockquote></div> 187 188 <div class="defun"> 189— Method on Type: <b>strip_typedefs</b><var><a name="index-strip_005ftypedefs-on-Type-1639"></a></var><br> 190<blockquote> <p>Return a new <code>gdb.Type</code> that represents the real type, 191after removing all layers of typedefs. 192</p></blockquote></div> 193 194 <div class="defun"> 195— Method on Type: <b>target</b><var><a name="index-target-on-Type-1640"></a></var><br> 196<blockquote> <p>Return a new <code>gdb.Type</code> object which represents the target type 197of this type. 198 199 <p>For a pointer type, the target type is the type of the pointed-to 200object. For an array type (meaning C-like arrays), the target type is 201the type of the elements of the array. For a function or method type, 202the target type is the type of the return value. For a complex type, 203the target type is the type of the elements. For a typedef, the 204target type is the aliased type. 205 206 <p>If the type does not have a target, this method will throw an 207exception. 208</p></blockquote></div> 209 210 <div class="defun"> 211— Method on Type: <b>template_argument</b><var> n </var>[<var>block</var>]<var><a name="index-template_005fargument-on-Type-1641"></a></var><br> 212<blockquote> <p>If this <code>gdb.Type</code> is an instantiation of a template, this will 213return a new <code>gdb.Type</code> which represents the type of the 214<var>n</var>th template argument. 215 216 <p>If this <code>gdb.Type</code> is not a template type, this will throw an 217exception. Ordinarily, only C<tt>++</tt> code will have template types. 218 219 <p>If <var>block</var> is given, then <var>name</var> is looked up in that scope. 220Otherwise, it is searched for globally. 221</p></blockquote></div> 222 </dl> 223 224 <p>Each type has a code, which indicates what category this type falls 225into. The available type categories are represented by constants 226defined in the <code>gdb</code> module: 227 228 229<a name="index-TYPE_005fCODE_005fPTR-1642"></a> 230<a name="index-gdb_002eTYPE_005fCODE_005fPTR-1643"></a> 231<dl><dt><code>TYPE_CODE_PTR</code><dd>The type is a pointer. 232 233 <p><a name="index-TYPE_005fCODE_005fARRAY-1644"></a><a name="index-gdb_002eTYPE_005fCODE_005fARRAY-1645"></a><br><dt><code>TYPE_CODE_ARRAY</code><dd>The type is an array. 234 235 <p><a name="index-TYPE_005fCODE_005fSTRUCT-1646"></a><a name="index-gdb_002eTYPE_005fCODE_005fSTRUCT-1647"></a><br><dt><code>TYPE_CODE_STRUCT</code><dd>The type is a structure. 236 237 <p><a name="index-TYPE_005fCODE_005fUNION-1648"></a><a name="index-gdb_002eTYPE_005fCODE_005fUNION-1649"></a><br><dt><code>TYPE_CODE_UNION</code><dd>The type is a union. 238 239 <p><a name="index-TYPE_005fCODE_005fENUM-1650"></a><a name="index-gdb_002eTYPE_005fCODE_005fENUM-1651"></a><br><dt><code>TYPE_CODE_ENUM</code><dd>The type is an enum. 240 241 <p><a name="index-TYPE_005fCODE_005fFLAGS-1652"></a><a name="index-gdb_002eTYPE_005fCODE_005fFLAGS-1653"></a><br><dt><code>TYPE_CODE_FLAGS</code><dd>A bit flags type, used for things such as status registers. 242 243 <p><a name="index-TYPE_005fCODE_005fFUNC-1654"></a><a name="index-gdb_002eTYPE_005fCODE_005fFUNC-1655"></a><br><dt><code>TYPE_CODE_FUNC</code><dd>The type is a function. 244 245 <p><a name="index-TYPE_005fCODE_005fINT-1656"></a><a name="index-gdb_002eTYPE_005fCODE_005fINT-1657"></a><br><dt><code>TYPE_CODE_INT</code><dd>The type is an integer type. 246 247 <p><a name="index-TYPE_005fCODE_005fFLT-1658"></a><a name="index-gdb_002eTYPE_005fCODE_005fFLT-1659"></a><br><dt><code>TYPE_CODE_FLT</code><dd>A floating point type. 248 249 <p><a name="index-TYPE_005fCODE_005fVOID-1660"></a><a name="index-gdb_002eTYPE_005fCODE_005fVOID-1661"></a><br><dt><code>TYPE_CODE_VOID</code><dd>The special type <code>void</code>. 250 251 <p><a name="index-TYPE_005fCODE_005fSET-1662"></a><a name="index-gdb_002eTYPE_005fCODE_005fSET-1663"></a><br><dt><code>TYPE_CODE_SET</code><dd>A Pascal set type. 252 253 <p><a name="index-TYPE_005fCODE_005fRANGE-1664"></a><a name="index-gdb_002eTYPE_005fCODE_005fRANGE-1665"></a><br><dt><code>TYPE_CODE_RANGE</code><dd>A range type, that is, an integer type with bounds. 254 255 <p><a name="index-TYPE_005fCODE_005fSTRING-1666"></a><a name="index-gdb_002eTYPE_005fCODE_005fSTRING-1667"></a><br><dt><code>TYPE_CODE_STRING</code><dd>A string type. Note that this is only used for certain languages with 256language-defined string types; C strings are not represented this way. 257 258 <p><a name="index-TYPE_005fCODE_005fBITSTRING-1668"></a><a name="index-gdb_002eTYPE_005fCODE_005fBITSTRING-1669"></a><br><dt><code>TYPE_CODE_BITSTRING</code><dd>A string of bits. 259 260 <p><a name="index-TYPE_005fCODE_005fERROR-1670"></a><a name="index-gdb_002eTYPE_005fCODE_005fERROR-1671"></a><br><dt><code>TYPE_CODE_ERROR</code><dd>An unknown or erroneous type. 261 262 <p><a name="index-TYPE_005fCODE_005fMETHOD-1672"></a><a name="index-gdb_002eTYPE_005fCODE_005fMETHOD-1673"></a><br><dt><code>TYPE_CODE_METHOD</code><dd>A method type, as found in C<tt>++</tt> or Java. 263 264 <p><a name="index-TYPE_005fCODE_005fMETHODPTR-1674"></a><a name="index-gdb_002eTYPE_005fCODE_005fMETHODPTR-1675"></a><br><dt><code>TYPE_CODE_METHODPTR</code><dd>A pointer-to-member-function. 265 266 <p><a name="index-TYPE_005fCODE_005fMEMBERPTR-1676"></a><a name="index-gdb_002eTYPE_005fCODE_005fMEMBERPTR-1677"></a><br><dt><code>TYPE_CODE_MEMBERPTR</code><dd>A pointer-to-member. 267 268 <p><a name="index-TYPE_005fCODE_005fREF-1678"></a><a name="index-gdb_002eTYPE_005fCODE_005fREF-1679"></a><br><dt><code>TYPE_CODE_REF</code><dd>A reference type. 269 270 <p><a name="index-TYPE_005fCODE_005fCHAR-1680"></a><a name="index-gdb_002eTYPE_005fCODE_005fCHAR-1681"></a><br><dt><code>TYPE_CODE_CHAR</code><dd>A character type. 271 272 <p><a name="index-TYPE_005fCODE_005fBOOL-1682"></a><a name="index-gdb_002eTYPE_005fCODE_005fBOOL-1683"></a><br><dt><code>TYPE_CODE_BOOL</code><dd>A boolean type. 273 274 <p><a name="index-TYPE_005fCODE_005fCOMPLEX-1684"></a><a name="index-gdb_002eTYPE_005fCODE_005fCOMPLEX-1685"></a><br><dt><code>TYPE_CODE_COMPLEX</code><dd>A complex float type. 275 276 <p><a name="index-TYPE_005fCODE_005fTYPEDEF-1686"></a><a name="index-gdb_002eTYPE_005fCODE_005fTYPEDEF-1687"></a><br><dt><code>TYPE_CODE_TYPEDEF</code><dd>A typedef to some other type. 277 278 <p><a name="index-TYPE_005fCODE_005fNAMESPACE-1688"></a><a name="index-gdb_002eTYPE_005fCODE_005fNAMESPACE-1689"></a><br><dt><code>TYPE_CODE_NAMESPACE</code><dd>A C<tt>++</tt> namespace. 279 280 <p><a name="index-TYPE_005fCODE_005fDECFLOAT-1690"></a><a name="index-gdb_002eTYPE_005fCODE_005fDECFLOAT-1691"></a><br><dt><code>TYPE_CODE_DECFLOAT</code><dd>A decimal floating point type. 281 282 <p><a name="index-TYPE_005fCODE_005fINTERNAL_005fFUNCTION-1692"></a><a name="index-gdb_002eTYPE_005fCODE_005fINTERNAL_005fFUNCTION-1693"></a><br><dt><code>TYPE_CODE_INTERNAL_FUNCTION</code><dd>A function internal to <span class="sc">gdb</span>. This is the type used to represent 283convenience functions. 284</dl> 285 286 </body></html> 287 288