| 
							- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 - <html>
 - <!-- Copyright (C) 1988-2020 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." -->
 - <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
 - <head>
 - <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 - <title>Character Sets (Debugging with GDB)</title>
 - 
 - <meta name="description" content="Character Sets (Debugging with GDB)">
 - <meta name="keywords" content="Character Sets (Debugging with GDB)">
 - <meta name="resource-type" content="document">
 - <meta name="distribution" content="global">
 - <meta name="Generator" content="makeinfo">
 - <link href="index.html#Top" rel="start" title="Top">
 - <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
 - <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
 - <link href="Data.html#Data" rel="up" title="Data">
 - <link href="Caching-Target-Data.html#Caching-Target-Data" rel="next" title="Caching Target Data">
 - <link href="Core-File-Generation.html#Core-File-Generation" rel="prev" title="Core File Generation">
 - <style type="text/css">
 - <!--
 - a.summary-letter {text-decoration: none}
 - blockquote.indentedblock {margin-right: 0em}
 - blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
 - blockquote.smallquotation {font-size: smaller}
 - div.display {margin-left: 3.2em}
 - div.example {margin-left: 3.2em}
 - div.lisp {margin-left: 3.2em}
 - div.smalldisplay {margin-left: 3.2em}
 - div.smallexample {margin-left: 3.2em}
 - div.smalllisp {margin-left: 3.2em}
 - kbd {font-style: oblique}
 - pre.display {font-family: inherit}
 - pre.format {font-family: inherit}
 - pre.menu-comment {font-family: serif}
 - pre.menu-preformatted {font-family: serif}
 - pre.smalldisplay {font-family: inherit; font-size: smaller}
 - pre.smallexample {font-size: smaller}
 - pre.smallformat {font-family: inherit; font-size: smaller}
 - pre.smalllisp {font-size: smaller}
 - span.nolinebreak {white-space: nowrap}
 - span.roman {font-family: initial; font-weight: normal}
 - span.sansserif {font-family: sans-serif; font-weight: normal}
 - ul.no-bullet {list-style: none}
 - -->
 - </style>
 - 
 - 
 - </head>
 - 
 - <body lang="en">
 - <a name="Character-Sets"></a>
 - <div class="header">
 - <p>
 - Next: <a href="Caching-Target-Data.html#Caching-Target-Data" accesskey="n" rel="next">Caching Target Data</a>, Previous: <a href="Core-File-Generation.html#Core-File-Generation" accesskey="p" rel="prev">Core File Generation</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</a>   [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
 - </div>
 - <hr>
 - <a name="Character-Sets-1"></a>
 - <h3 class="section">10.20 Character Sets</h3>
 - <a name="index-character-sets"></a>
 - <a name="index-charset"></a>
 - <a name="index-translating-between-character-sets"></a>
 - <a name="index-host-character-set"></a>
 - <a name="index-target-character-set"></a>
 - 
 - <p>If the program you are debugging uses a different character set to
 - represent characters and strings than the one <small>GDB</small> uses itself,
 - <small>GDB</small> can automatically translate between the character sets for
 - you.  The character set <small>GDB</small> uses we call the <em>host
 - character set</em>; the one the inferior program uses we call the
 - <em>target character set</em>.
 - </p>
 - <p>For example, if you are running <small>GDB</small> on a <small>GNU</small>/Linux system, which
 - uses the ISO Latin 1 character set, but you are using <small>GDB</small>’s
 - remote protocol (see <a href="Remote-Debugging.html#Remote-Debugging">Remote Debugging</a>) to debug a program
 - running on an IBM mainframe, which uses the <small>EBCDIC</small> character set,
 - then the host character set is Latin-1, and the target character set is
 - <small>EBCDIC</small>.  If you give <small>GDB</small> the command <code>set
 - target-charset EBCDIC-US</code>, then <small>GDB</small> translates between
 - <small>EBCDIC</small> and Latin 1 as you print character or string values, or use
 - character and string literals in expressions.
 - </p>
 - <p><small>GDB</small> has no way to automatically recognize which character set
 - the inferior program uses; you must tell it, using the <code>set
 - target-charset</code> command, described below.
 - </p>
 - <p>Here are the commands for controlling <small>GDB</small>’s character set
 - support:
 - </p>
 - <dl compact="compact">
 - <dt><code>set target-charset <var>charset</var></code></dt>
 - <dd><a name="index-set-target_002dcharset"></a>
 - <p>Set the current target character set to <var>charset</var>.  To display the
 - list of supported target character sets, type
 - <kbd>set <span class="nolinebreak">target-charset</span> <span class="key">TAB</span><span class="key">TAB</span><!-- /@w --></kbd>.
 - </p>
 - </dd>
 - <dt><code>set host-charset <var>charset</var></code></dt>
 - <dd><a name="index-set-host_002dcharset"></a>
 - <p>Set the current host character set to <var>charset</var>.
 - </p>
 - <p>By default, <small>GDB</small> uses a host character set appropriate to the
 - system it is running on; you can override that default using the
 - <code>set host-charset</code> command.  On some systems, <small>GDB</small> cannot
 - automatically determine the appropriate host character set.  In this
 - case, <small>GDB</small> uses ‘<samp>UTF-8</samp>’.
 - </p>
 - <p><small>GDB</small> can only use certain character sets as its host character
 - set.  If you type <kbd>set <span class="nolinebreak">host-charset</span> <span class="key">TAB</span><span class="key">TAB</span><!-- /@w --></kbd>,
 - <small>GDB</small> will list the host character sets it supports.
 - </p>
 - </dd>
 - <dt><code>set charset <var>charset</var></code></dt>
 - <dd><a name="index-set-charset"></a>
 - <p>Set the current host and target character sets to <var>charset</var>.  As
 - above, if you type <kbd>set charset <span class="key">TAB</span><span class="key">TAB</span><!-- /@w --></kbd>,
 - <small>GDB</small> will list the names of the character sets that can be used
 - for both host and target.
 - </p>
 - </dd>
 - <dt><code>show charset</code></dt>
 - <dd><a name="index-show-charset"></a>
 - <p>Show the names of the current host and target character sets.
 - </p>
 - </dd>
 - <dt><code>show host-charset</code></dt>
 - <dd><a name="index-show-host_002dcharset"></a>
 - <p>Show the name of the current host character set.
 - </p>
 - </dd>
 - <dt><code>show target-charset</code></dt>
 - <dd><a name="index-show-target_002dcharset"></a>
 - <p>Show the name of the current target character set.
 - </p>
 - </dd>
 - <dt><code>set target-wide-charset <var>charset</var></code></dt>
 - <dd><a name="index-set-target_002dwide_002dcharset"></a>
 - <p>Set the current target’s wide character set to <var>charset</var>.  This is
 - the character set used by the target’s <code>wchar_t</code> type.  To
 - display the list of supported wide character sets, type
 - <kbd>set <span class="nolinebreak">target-wide-charset</span> <span class="key">TAB</span><span class="key">TAB</span><!-- /@w --></kbd>.
 - </p>
 - </dd>
 - <dt><code>show target-wide-charset</code></dt>
 - <dd><a name="index-show-target_002dwide_002dcharset"></a>
 - <p>Show the name of the current target’s wide character set.
 - </p></dd>
 - </dl>
 - 
 - <p>Here is an example of <small>GDB</small>’s character set support in action.
 - Assume that the following source code has been placed in the file
 - <samp>charset-test.c</samp>:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">#include <stdio.h>
 - 
 - char ascii_hello[]
 -   = {72, 101, 108, 108, 111, 44, 32, 119,
 -      111, 114, 108, 100, 33, 10, 0};
 - char ibm1047_hello[]
 -   = {200, 133, 147, 147, 150, 107, 64, 166,
 -      150, 153, 147, 132, 90, 37, 0};
 - 
 - main ()
 - {
 -   printf ("Hello, world!\n");
 - }
 - </pre></div>
 - 
 - <p>In this program, <code>ascii_hello</code> and <code>ibm1047_hello</code> are arrays
 - containing the string ‘<samp>Hello, world!</samp>’ followed by a newline,
 - encoded in the <small>ASCII</small> and <small>IBM1047</small> character sets.
 - </p>
 - <p>We compile the program, and invoke the debugger on it:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">$ gcc -g charset-test.c -o charset-test
 - $ gdb -nw charset-test
 - GNU gdb 2001-12-19-cvs
 - Copyright 2001 Free Software Foundation, Inc.
 - …
 - (gdb)
 - </pre></div>
 - 
 - <p>We can use the <code>show charset</code> command to see what character sets
 - <small>GDB</small> is currently using to interpret and display characters and
 - strings:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) show charset
 - The current host and target character set is `ISO-8859-1'.
 - (gdb)
 - </pre></div>
 - 
 - <p>For the sake of printing this manual, let’s use <small>ASCII</small> as our
 - initial character set:
 - </p><div class="smallexample">
 - <pre class="smallexample">(gdb) set charset ASCII
 - (gdb) show charset
 - The current host and target character set is `ASCII'.
 - (gdb)
 - </pre></div>
 - 
 - <p>Let’s assume that <small>ASCII</small> is indeed the correct character set for our
 - host system — in other words, let’s assume that if <small>GDB</small> prints
 - characters using the <small>ASCII</small> character set, our terminal will display
 - them properly.  Since our current target character set is also
 - <small>ASCII</small>, the contents of <code>ascii_hello</code> print legibly:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) print ascii_hello
 - $1 = 0x401698 "Hello, world!\n"
 - (gdb) print ascii_hello[0]
 - $2 = 72 'H'
 - (gdb)
 - </pre></div>
 - 
 - <p><small>GDB</small> uses the target character set for character and string
 - literals you use in expressions:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) print '+'
 - $3 = 43 '+'
 - (gdb)
 - </pre></div>
 - 
 - <p>The <small>ASCII</small> character set uses the number 43 to encode the ‘<samp>+</samp>’
 - character.
 - </p>
 - <p><small>GDB</small> relies on the user to tell it which character set the
 - target program uses.  If we print <code>ibm1047_hello</code> while our target
 - character set is still <small>ASCII</small>, we get jibberish:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) print ibm1047_hello
 - $4 = 0x4016a8 "\310\205\223\223\226k@\246\226\231\223\204Z%"
 - (gdb) print ibm1047_hello[0]
 - $5 = 200 '\310'
 - (gdb)
 - </pre></div>
 - 
 - <p>If we invoke the <code>set target-charset</code> followed by <tt class="key">TAB</tt><tt class="key">TAB</tt>,
 - <small>GDB</small> tells us the character sets it supports:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) set target-charset
 - ASCII       EBCDIC-US   IBM1047     ISO-8859-1
 - (gdb) set target-charset
 - </pre></div>
 - 
 - <p>We can select <small>IBM1047</small> as our target character set, and examine the
 - program’s strings again.  Now the <small>ASCII</small> string is wrong, but
 - <small>GDB</small> translates the contents of <code>ibm1047_hello</code> from the
 - target character set, <small>IBM1047</small>, to the host character set,
 - <small>ASCII</small>, and they display correctly:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) set target-charset IBM1047
 - (gdb) show charset
 - The current host character set is `ASCII'.
 - The current target character set is `IBM1047'.
 - (gdb) print ascii_hello
 - $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
 - (gdb) print ascii_hello[0]
 - $7 = 72 '\110'
 - (gdb) print ibm1047_hello
 - $8 = 0x4016a8 "Hello, world!\n"
 - (gdb) print ibm1047_hello[0]
 - $9 = 200 'H'
 - (gdb)
 - </pre></div>
 - 
 - <p>As above, <small>GDB</small> uses the target character set for character and
 - string literals you use in expressions:
 - </p>
 - <div class="smallexample">
 - <pre class="smallexample">(gdb) print '+'
 - $10 = 78 '+'
 - (gdb)
 - </pre></div>
 - 
 - <p>The <small>IBM1047</small> character set uses the number 78 to encode the ‘<samp>+</samp>’
 - character.
 - </p>
 - <hr>
 - <div class="header">
 - <p>
 - Next: <a href="Caching-Target-Data.html#Caching-Target-Data" accesskey="n" rel="next">Caching Target Data</a>, Previous: <a href="Core-File-Generation.html#Core-File-Generation" accesskey="p" rel="prev">Core File Generation</a>, Up: <a href="Data.html#Data" accesskey="u" rel="up">Data</a>   [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
 - </div>
 - 
 - 
 - 
 - </body>
 - </html>
 
 
  |