| <html lang="en"> |
| <head> |
| <title>Types In Python - Debugging with GDB</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Debugging with GDB"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Python-API.html#Python-API" title="Python API"> |
| <link rel="prev" href="Values-From-Inferior.html#Values-From-Inferior" title="Values From Inferior"> |
| <link rel="next" href="Pretty-Printing-API.html#Pretty-Printing-API" title="Pretty Printing API"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| Copyright (C) 1988-2019 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software'' and ``Free Software Needs |
| Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' |
| and with the Back-Cover Texts as in (a) below. |
| |
| (a) The FSF's Back-Cover Text is: ``You are free to copy and modify |
| this GNU Manual. Buying copies from GNU Press supports the FSF in |
| developing GNU and promoting software freedom.'' |
| --> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Types-In-Python"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>, |
| Previous: <a rel="previous" accesskey="p" href="Values-From-Inferior.html#Values-From-Inferior">Values From Inferior</a>, |
| Up: <a rel="up" accesskey="u" href="Python-API.html#Python-API">Python API</a> |
| <hr> |
| </div> |
| |
| <h5 class="subsubsection">23.2.2.4 Types In Python</h5> |
| |
| <p><a name="index-types-in-Python-1927"></a><a name="index-Python_002c-working-with-types-1928"></a> |
| <a name="index-gdb_002eType-1929"></a><span class="sc">gdb</span> represents types from the inferior using the class |
| <code>gdb.Type</code>. |
| |
| <p>The following type-related functions are available in the <code>gdb</code> |
| module: |
| |
| <p><a name="index-gdb_002elookup_005ftype-1930"></a> |
| |
| <div class="defun"> |
| — Function: <b>gdb.lookup_type</b> (<var>name </var><span class="roman">[</span><var>, block</var><span class="roman">]</span>)<var><a name="index-gdb_002elookup_005ftype-1931"></a></var><br> |
| <blockquote><p>This function looks up a type by its <var>name</var>, which must be a string. |
| |
| <p>If <var>block</var> is given, then <var>name</var> is looked up in that scope. |
| Otherwise, it is searched for globally. |
| |
| <p>Ordinarily, this function will return an instance of <code>gdb.Type</code>. |
| If the named type cannot be found, it will throw an exception. |
| </p></blockquote></div> |
| |
| <p>If the type is a structure or class type, or an enum type, the fields |
| of that type can be accessed using the Python <dfn>dictionary syntax</dfn>. |
| For example, if <code>some_type</code> is a <code>gdb.Type</code> instance holding |
| a structure type, you can access its <code>foo</code> field with: |
| |
| <pre class="smallexample"> bar = some_type['foo'] |
| </pre> |
| <p><code>bar</code> will be a <code>gdb.Field</code> object; see below under the |
| description of the <code>Type.fields</code> method for a description of the |
| <code>gdb.Field</code> class. |
| |
| <p>An instance of <code>Type</code> has the following attributes: |
| |
| <div class="defun"> |
| — Variable: <b>Type.alignof</b><var><a name="index-Type_002ealignof-1932"></a></var><br> |
| <blockquote><p>The alignment of this type, in bytes. Type alignment comes from the |
| debugging information; if it was not specified, then <span class="sc">gdb</span> will |
| use the relevant ABI to try to determine the alignment. In some |
| cases, even this is not possible, and zero will be returned. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Variable: <b>Type.code</b><var><a name="index-Type_002ecode-1933"></a></var><br> |
| <blockquote><p>The type code for this type. The type code will be one of the |
| <code>TYPE_CODE_</code> constants defined below. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Variable: <b>Type.name</b><var><a name="index-Type_002ename-1934"></a></var><br> |
| <blockquote><p>The name of this type. If this type has no name, then <code>None</code> |
| is returned. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Variable: <b>Type.sizeof</b><var><a name="index-Type_002esizeof-1935"></a></var><br> |
| <blockquote><p>The size of this type, in target <code>char</code> units. Usually, a |
| target's <code>char</code> type will be an 8-bit byte. However, on some |
| unusual platforms, this type may have a different size. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Variable: <b>Type.tag</b><var><a name="index-Type_002etag-1936"></a></var><br> |
| <blockquote><p>The tag name for this type. The tag name is the name after |
| <code>struct</code>, <code>union</code>, or <code>enum</code> in C and C<tt>++</tt>; not all |
| languages have this concept. If this type has no tag name, then |
| <code>None</code> is returned. |
| </p></blockquote></div> |
| |
| <p>The following methods are provided: |
| |
| <div class="defun"> |
| — Function: <b>Type.fields</b> ()<var><a name="index-Type_002efields-1937"></a></var><br> |
| <blockquote><p>For structure and union types, this method returns the fields. Range |
| types have two fields, the minimum and maximum values. Enum types |
| have one field per enum constant. Function and method types have one |
| field per parameter. The base types of C<tt>++</tt> classes are also |
| represented as fields. If the type has no fields, or does not fit |
| into one of these categories, an empty sequence will be returned. |
| |
| <p>Each field is a <code>gdb.Field</code> object, with some pre-defined attributes: |
| <dl> |
| <dt><code>bitpos</code><dd>This attribute is not available for <code>enum</code> or <code>static</code> |
| (as in C<tt>++</tt>) fields. The value is the position, counting |
| in bits, from the start of the containing type. |
| |
| <br><dt><code>enumval</code><dd>This attribute is only available for <code>enum</code> fields, and its value |
| is the enumeration member's integer representation. |
| |
| <br><dt><code>name</code><dd>The name of the field, or <code>None</code> for anonymous fields. |
| |
| <br><dt><code>artificial</code><dd>This is <code>True</code> if the field is artificial, usually meaning that |
| it was provided by the compiler and not the user. This attribute is |
| always provided, and is <code>False</code> if the field is not artificial. |
| |
| <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> |
| structure. This attribute is always provided, and is <code>False</code> |
| if the field is not a base class of the type that is the argument of |
| <code>fields</code>, or if that type was not a C<tt>++</tt> class. |
| |
| <br><dt><code>bitsize</code><dd>If the field is packed, or is a bitfield, then this will have a |
| non-zero value, which is the size of the field in bits. Otherwise, |
| this will be zero; in this case the field's size is given by its type. |
| |
| <br><dt><code>type</code><dd>The type of the field. This is usually an instance of <code>Type</code>, |
| but it can be <code>None</code> in some situations. |
| |
| <br><dt><code>parent_type</code><dd>The type which contains this field. This is an instance of |
| <code>gdb.Type</code>. |
| </dl> |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.array</b> (<var>n1 </var><span class="roman">[</span><var>, n2</var><span class="roman">]</span>)<var><a name="index-Type_002earray-1938"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents an array of this |
| type. If one argument is given, it is the inclusive upper bound of |
| the array; in this case the lower bound is zero. If two arguments are |
| given, the first argument is the lower bound of the array, and the |
| second argument is the upper bound of the array. An array's length |
| must not be negative, but the bounds can be. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.vector</b> (<var>n1 </var><span class="roman">[</span><var>, n2</var><span class="roman">]</span>)<var><a name="index-Type_002evector-1939"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents a vector of this |
| type. If one argument is given, it is the inclusive upper bound of |
| the vector; in this case the lower bound is zero. If two arguments are |
| given, the first argument is the lower bound of the vector, and the |
| second argument is the upper bound of the vector. A vector's length |
| must not be negative, but the bounds can be. |
| |
| <p>The difference between an <code>array</code> and a <code>vector</code> is that |
| arrays behave like in C: when used in expressions they decay to a pointer |
| to the first element whereas vectors are treated as first class values. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.const</b> ()<var><a name="index-Type_002econst-1940"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents a |
| <code>const</code>-qualified variant of this type. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.volatile</b> ()<var><a name="index-Type_002evolatile-1941"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents a |
| <code>volatile</code>-qualified variant of this type. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.unqualified</b> ()<var><a name="index-Type_002eunqualified-1942"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents an unqualified |
| variant of this type. That is, the result is neither <code>const</code> nor |
| <code>volatile</code>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.range</b> ()<var><a name="index-Type_002erange-1943"></a></var><br> |
| <blockquote><p>Return a Python <code>Tuple</code> object that contains two elements: the |
| low bound of the argument type and the high bound of that type. If |
| the type does not have a range, <span class="sc">gdb</span> will raise a |
| <code>gdb.error</code> exception (see <a href="Exception-Handling.html#Exception-Handling">Exception Handling</a>). |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.reference</b> ()<var><a name="index-Type_002ereference-1944"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents a reference to this |
| type. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.pointer</b> ()<var><a name="index-Type_002epointer-1945"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents a pointer to this |
| type. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.strip_typedefs</b> ()<var><a name="index-Type_002estrip_005ftypedefs-1946"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> that represents the real type, |
| after removing all layers of typedefs. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.target</b> ()<var><a name="index-Type_002etarget-1947"></a></var><br> |
| <blockquote><p>Return a new <code>gdb.Type</code> object which represents the target type |
| of this type. |
| |
| <p>For a pointer type, the target type is the type of the pointed-to |
| object. For an array type (meaning C-like arrays), the target type is |
| the type of the elements of the array. For a function or method type, |
| the target type is the type of the return value. For a complex type, |
| the target type is the type of the elements. For a typedef, the |
| target type is the aliased type. |
| |
| <p>If the type does not have a target, this method will throw an |
| exception. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.template_argument</b> (<var>n </var><span class="roman">[</span><var>, block</var><span class="roman">]</span>)<var><a name="index-Type_002etemplate_005fargument-1948"></a></var><br> |
| <blockquote><p>If this <code>gdb.Type</code> is an instantiation of a template, this will |
| return a new <code>gdb.Value</code> or <code>gdb.Type</code> which represents the |
| value of the <var>n</var>th template argument (indexed starting at 0). |
| |
| <p>If this <code>gdb.Type</code> is not a template type, or if the type has fewer |
| than <var>n</var> template arguments, this will throw an exception. |
| Ordinarily, only C<tt>++</tt> code will have template types. |
| |
| <p>If <var>block</var> is given, then <var>name</var> is looked up in that scope. |
| Otherwise, it is searched for globally. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Function: <b>Type.optimized_out</b> ()<var><a name="index-Type_002eoptimized_005fout-1949"></a></var><br> |
| <blockquote><p>Return <code>gdb.Value</code> instance of this type whose value is optimized |
| out. This allows a frame decorator to indicate that the value of an |
| argument or a local variable is not known. |
| </p></blockquote></div> |
| |
| <p>Each type has a code, which indicates what category this type falls |
| into. The available type categories are represented by constants |
| defined in the <code>gdb</code> module: |
| |
| |
| <a name="index-TYPE_005fCODE_005fPTR-1950"></a> |
| <dl><dt><code>gdb.TYPE_CODE_PTR</code><a name="index-gdb_002eTYPE_005fCODE_005fPTR-1951"></a><dd>The type is a pointer. |
| |
| <p><a name="index-TYPE_005fCODE_005fARRAY-1952"></a><br><dt><code>gdb.TYPE_CODE_ARRAY</code><a name="index-gdb_002eTYPE_005fCODE_005fARRAY-1953"></a><dd>The type is an array. |
| |
| <p><a name="index-TYPE_005fCODE_005fSTRUCT-1954"></a><br><dt><code>gdb.TYPE_CODE_STRUCT</code><a name="index-gdb_002eTYPE_005fCODE_005fSTRUCT-1955"></a><dd>The type is a structure. |
| |
| <p><a name="index-TYPE_005fCODE_005fUNION-1956"></a><br><dt><code>gdb.TYPE_CODE_UNION</code><a name="index-gdb_002eTYPE_005fCODE_005fUNION-1957"></a><dd>The type is a union. |
| |
| <p><a name="index-TYPE_005fCODE_005fENUM-1958"></a><br><dt><code>gdb.TYPE_CODE_ENUM</code><a name="index-gdb_002eTYPE_005fCODE_005fENUM-1959"></a><dd>The type is an enum. |
| |
| <p><a name="index-TYPE_005fCODE_005fFLAGS-1960"></a><br><dt><code>gdb.TYPE_CODE_FLAGS</code><a name="index-gdb_002eTYPE_005fCODE_005fFLAGS-1961"></a><dd>A bit flags type, used for things such as status registers. |
| |
| <p><a name="index-TYPE_005fCODE_005fFUNC-1962"></a><br><dt><code>gdb.TYPE_CODE_FUNC</code><a name="index-gdb_002eTYPE_005fCODE_005fFUNC-1963"></a><dd>The type is a function. |
| |
| <p><a name="index-TYPE_005fCODE_005fINT-1964"></a><br><dt><code>gdb.TYPE_CODE_INT</code><a name="index-gdb_002eTYPE_005fCODE_005fINT-1965"></a><dd>The type is an integer type. |
| |
| <p><a name="index-TYPE_005fCODE_005fFLT-1966"></a><br><dt><code>gdb.TYPE_CODE_FLT</code><a name="index-gdb_002eTYPE_005fCODE_005fFLT-1967"></a><dd>A floating point type. |
| |
| <p><a name="index-TYPE_005fCODE_005fVOID-1968"></a><br><dt><code>gdb.TYPE_CODE_VOID</code><a name="index-gdb_002eTYPE_005fCODE_005fVOID-1969"></a><dd>The special type <code>void</code>. |
| |
| <p><a name="index-TYPE_005fCODE_005fSET-1970"></a><br><dt><code>gdb.TYPE_CODE_SET</code><a name="index-gdb_002eTYPE_005fCODE_005fSET-1971"></a><dd>A Pascal set type. |
| |
| <p><a name="index-TYPE_005fCODE_005fRANGE-1972"></a><br><dt><code>gdb.TYPE_CODE_RANGE</code><a name="index-gdb_002eTYPE_005fCODE_005fRANGE-1973"></a><dd>A range type, that is, an integer type with bounds. |
| |
| <p><a name="index-TYPE_005fCODE_005fSTRING-1974"></a><br><dt><code>gdb.TYPE_CODE_STRING</code><a name="index-gdb_002eTYPE_005fCODE_005fSTRING-1975"></a><dd>A string type. Note that this is only used for certain languages with |
| language-defined string types; C strings are not represented this way. |
| |
| <p><a name="index-TYPE_005fCODE_005fBITSTRING-1976"></a><br><dt><code>gdb.TYPE_CODE_BITSTRING</code><a name="index-gdb_002eTYPE_005fCODE_005fBITSTRING-1977"></a><dd>A string of bits. It is deprecated. |
| |
| <p><a name="index-TYPE_005fCODE_005fERROR-1978"></a><br><dt><code>gdb.TYPE_CODE_ERROR</code><a name="index-gdb_002eTYPE_005fCODE_005fERROR-1979"></a><dd>An unknown or erroneous type. |
| |
| <p><a name="index-TYPE_005fCODE_005fMETHOD-1980"></a><br><dt><code>gdb.TYPE_CODE_METHOD</code><a name="index-gdb_002eTYPE_005fCODE_005fMETHOD-1981"></a><dd>A method type, as found in C<tt>++</tt>. |
| |
| <p><a name="index-TYPE_005fCODE_005fMETHODPTR-1982"></a><br><dt><code>gdb.TYPE_CODE_METHODPTR</code><a name="index-gdb_002eTYPE_005fCODE_005fMETHODPTR-1983"></a><dd>A pointer-to-member-function. |
| |
| <p><a name="index-TYPE_005fCODE_005fMEMBERPTR-1984"></a><br><dt><code>gdb.TYPE_CODE_MEMBERPTR</code><a name="index-gdb_002eTYPE_005fCODE_005fMEMBERPTR-1985"></a><dd>A pointer-to-member. |
| |
| <p><a name="index-TYPE_005fCODE_005fREF-1986"></a><br><dt><code>gdb.TYPE_CODE_REF</code><a name="index-gdb_002eTYPE_005fCODE_005fREF-1987"></a><dd>A reference type. |
| |
| <p><a name="index-TYPE_005fCODE_005fRVALUE_005fREF-1988"></a><br><dt><code>gdb.TYPE_CODE_RVALUE_REF</code><a name="index-gdb_002eTYPE_005fCODE_005fRVALUE_005fREF-1989"></a><dd>A C<tt>++</tt>11 rvalue reference type. |
| |
| <p><a name="index-TYPE_005fCODE_005fCHAR-1990"></a><br><dt><code>gdb.TYPE_CODE_CHAR</code><a name="index-gdb_002eTYPE_005fCODE_005fCHAR-1991"></a><dd>A character type. |
| |
| <p><a name="index-TYPE_005fCODE_005fBOOL-1992"></a><br><dt><code>gdb.TYPE_CODE_BOOL</code><a name="index-gdb_002eTYPE_005fCODE_005fBOOL-1993"></a><dd>A boolean type. |
| |
| <p><a name="index-TYPE_005fCODE_005fCOMPLEX-1994"></a><br><dt><code>gdb.TYPE_CODE_COMPLEX</code><a name="index-gdb_002eTYPE_005fCODE_005fCOMPLEX-1995"></a><dd>A complex float type. |
| |
| <p><a name="index-TYPE_005fCODE_005fTYPEDEF-1996"></a><br><dt><code>gdb.TYPE_CODE_TYPEDEF</code><a name="index-gdb_002eTYPE_005fCODE_005fTYPEDEF-1997"></a><dd>A typedef to some other type. |
| |
| <p><a name="index-TYPE_005fCODE_005fNAMESPACE-1998"></a><br><dt><code>gdb.TYPE_CODE_NAMESPACE</code><a name="index-gdb_002eTYPE_005fCODE_005fNAMESPACE-1999"></a><dd>A C<tt>++</tt> namespace. |
| |
| <p><a name="index-TYPE_005fCODE_005fDECFLOAT-2000"></a><br><dt><code>gdb.TYPE_CODE_DECFLOAT</code><a name="index-gdb_002eTYPE_005fCODE_005fDECFLOAT-2001"></a><dd>A decimal floating point type. |
| |
| <p><a name="index-TYPE_005fCODE_005fINTERNAL_005fFUNCTION-2002"></a><br><dt><code>gdb.TYPE_CODE_INTERNAL_FUNCTION</code><a name="index-gdb_002eTYPE_005fCODE_005fINTERNAL_005fFUNCTION-2003"></a><dd>A function internal to <span class="sc">gdb</span>. This is the type used to represent |
| convenience functions. |
| </dl> |
| |
| <p>Further support for types is provided in the <code>gdb.types</code> |
| Python module (see <a href="gdb_002etypes.html#gdb_002etypes">gdb.types</a>). |
| |
| </body></html> |
| |