1<html lang="en"> 2<head> 3<title>Parameters 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="Commands-In-Python.html#Commands-In-Python" title="Commands In Python"> 10<link rel="next" href="Functions-In-Python.html#Functions-In-Python" title="Functions In Python"> 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="Parameters-In-Python"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Functions-In-Python.html#Functions-In-Python">Functions In Python</a>, 46Previous: <a rel="previous" accesskey="p" href="Commands-In-Python.html#Commands-In-Python">Commands In Python</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.11 Parameters In Python</h5> 52 53<p><a name="index-parameters-in-python-1764"></a><a name="index-python-parameters-1765"></a><a name="index-gdb_002eParameter-1766"></a><a name="index-Parameter-1767"></a>You can implement new <span class="sc">gdb</span> parameters using Python. A new 54parameter is implemented as an instance of the <code>gdb.Parameter</code> 55class. 56 57 <p>Parameters are exposed to the user via the <code>set</code> and 58<code>show</code> commands. See <a href="Help.html#Help">Help</a>. 59 60 <p>There are many parameters that already exist and can be set in 61<span class="sc">gdb</span>. Two examples are: <code>set follow fork</code> and 62<code>set charset</code>. Setting these parameters influences certain 63behavior in <span class="sc">gdb</span>. Similarly, you can define parameters that 64can be used to influence behavior in custom Python scripts and commands. 65 66<div class="defun"> 67— Method on Parameter: <b>__init__</b><var> name command-class parameter-class </var><span class="roman">[</span><var>enum-sequence</var><span class="roman">]</span><var><a name="index-g_t_005f_005finit_005f_005f-on-Parameter-1768"></a></var><br> 68<blockquote><p>The object initializer for <code>Parameter</code> registers the new 69parameter with <span class="sc">gdb</span>. This initializer is normally invoked 70from the subclass' own <code>__init__</code> method. 71 72 <p><var>name</var> is the name of the new parameter. If <var>name</var> consists 73of multiple words, then the initial words are looked for as prefix 74parameters. An example of this can be illustrated with the 75<code>set print</code> set of parameters. If <var>name</var> is 76<code>print foo</code>, then <code>print</code> will be searched as the prefix 77parameter. In this case the parameter can subsequently be accessed in 78<span class="sc">gdb</span> as <code>set print foo</code>. 79 80 <p>If <var>name</var> consists of multiple words, and no prefix parameter group 81can be found, an exception is raised. 82 83 <p><var>command-class</var> should be one of the ‘<samp><span class="samp">COMMAND_</span></samp>’ constants 84(see <a href="Commands-In-Python.html#Commands-In-Python">Commands In Python</a>). This argument tells <span class="sc">gdb</span> how to 85categorize the new parameter in the help system. 86 87 <p><var>parameter-class</var> should be one of the ‘<samp><span class="samp">PARAM_</span></samp>’ constants 88defined below. This argument tells <span class="sc">gdb</span> the type of the new 89parameter; this information is used for input validation and 90completion. 91 92 <p>If <var>parameter-class</var> is <code>PARAM_ENUM</code>, then 93<var>enum-sequence</var> must be a sequence of strings. These strings 94represent the possible values for the parameter. 95 96 <p>If <var>parameter-class</var> is not <code>PARAM_ENUM</code>, then the presence 97of a fourth argument will cause an exception to be thrown. 98 99 <p>The help text for the new parameter is taken from the Python 100documentation string for the parameter's class, if there is one. If 101there is no documentation string, a default value is used. 102</p></blockquote></div> 103 104<div class="defun"> 105— Instance Variable of Parameter: <b>set_doc</b><var><a name="index-set_005fdoc-1769"></a></var><br> 106<blockquote><p>If this attribute exists, and is a string, then its value is used as 107the help text for this parameter's <code>set</code> command. The value is 108examined when <code>Parameter.__init__</code> is invoked; subsequent changes 109have no effect. 110</p></blockquote></div> 111 112<div class="defun"> 113— Instance Variable of Parameter: <b>show_doc</b><var><a name="index-show_005fdoc-1770"></a></var><br> 114<blockquote><p>If this attribute exists, and is a string, then its value is used as 115the help text for this parameter's <code>show</code> command. The value is 116examined when <code>Parameter.__init__</code> is invoked; subsequent changes 117have no effect. 118</p></blockquote></div> 119 120<div class="defun"> 121— Instance Variable of Parameter: <b>value</b><var><a name="index-value-1771"></a></var><br> 122<blockquote><p>The <code>value</code> attribute holds the underlying value of the 123parameter. It can be read and assigned to just as any other 124attribute. <span class="sc">gdb</span> does validation when assignments are made. 125</p></blockquote></div> 126 127 <p>When a new parameter is defined, its type must be specified. The 128available types are represented by constants defined in the <code>gdb</code> 129module: 130 131 132<a name="index-PARAM_005fBOOLEAN-1772"></a> 133<a name="index-gdb_002ePARAM_005fBOOLEAN-1773"></a> 134<dl><dt><code>PARAM_BOOLEAN</code><dd>The value is a plain boolean. The Python boolean values, <code>True</code> 135and <code>False</code> are the only valid values. 136 137 <p><a name="index-PARAM_005fAUTO_005fBOOLEAN-1774"></a><a name="index-gdb_002ePARAM_005fAUTO_005fBOOLEAN-1775"></a><br><dt><code>PARAM_AUTO_BOOLEAN</code><dd>The value has three possible states: true, false, and ‘<samp><span class="samp">auto</span></samp>’. In 138Python, true and false are represented using boolean constants, and 139‘<samp><span class="samp">auto</span></samp>’ is represented using <code>None</code>. 140 141 <p><a name="index-PARAM_005fUINTEGER-1776"></a><a name="index-gdb_002ePARAM_005fUINTEGER-1777"></a><br><dt><code>PARAM_UINTEGER</code><dd>The value is an unsigned integer. The value of 0 should be 142interpreted to mean “unlimited”. 143 144 <p><a name="index-PARAM_005fINTEGER-1778"></a><a name="index-gdb_002ePARAM_005fINTEGER-1779"></a><br><dt><code>PARAM_INTEGER</code><dd>The value is a signed integer. The value of 0 should be interpreted 145to mean “unlimited”. 146 147 <p><a name="index-PARAM_005fSTRING-1780"></a><a name="index-gdb_002ePARAM_005fSTRING-1781"></a><br><dt><code>PARAM_STRING</code><dd>The value is a string. When the user modifies the string, any escape 148sequences, such as ‘<samp><span class="samp">\t</span></samp>’, ‘<samp><span class="samp">\f</span></samp>’, and octal escapes, are 149translated into corresponding characters and encoded into the current 150host charset. 151 152 <p><a name="index-PARAM_005fSTRING_005fNOESCAPE-1782"></a><a name="index-gdb_002ePARAM_005fSTRING_005fNOESCAPE-1783"></a><br><dt><code>PARAM_STRING_NOESCAPE</code><dd>The value is a string. When the user modifies the string, escapes are 153passed through untranslated. 154 155 <p><a name="index-PARAM_005fOPTIONAL_005fFILENAME-1784"></a><a name="index-gdb_002ePARAM_005fOPTIONAL_005fFILENAME-1785"></a><br><dt><code>PARAM_OPTIONAL_FILENAME</code><dd>The value is a either a filename (a string), or <code>None</code>. 156 157 <p><a name="index-PARAM_005fFILENAME-1786"></a><a name="index-gdb_002ePARAM_005fFILENAME-1787"></a><br><dt><code>PARAM_FILENAME</code><dd>The value is a filename. This is just like 158<code>PARAM_STRING_NOESCAPE</code>, but uses file names for completion. 159 160 <p><a name="index-PARAM_005fZINTEGER-1788"></a><a name="index-gdb_002ePARAM_005fZINTEGER-1789"></a><br><dt><code>PARAM_ZINTEGER</code><dd>The value is an integer. This is like <code>PARAM_INTEGER</code>, except 0 161is interpreted as itself. 162 163 <p><a name="index-PARAM_005fENUM-1790"></a><a name="index-gdb_002ePARAM_005fENUM-1791"></a><br><dt><code>PARAM_ENUM</code><dd>The value is a string, which must be one of a collection string 164constants provided when the parameter is created. 165</dl> 166 167 </body></html> 168 169