From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 437 invoked by alias); 28 Apr 2010 09:18:04 -0000 Received: (qmail 420 invoked by uid 22791); 28 Apr 2010 09:18:03 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Apr 2010 09:17:54 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3S9HqEP024786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Apr 2010 05:17:52 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3S9HpSo008400; Wed, 28 Apr 2010 05:17:51 -0400 Message-ID: <4BD7FD3E.5000802@redhat.com> Date: Wed, 28 Apr 2010 09:18:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.4 MIME-Version: 1.0 To: Eli Zaretskii CC: gdb-patches@sourceware.org Subject: Re: [python][patch] Add GDB Parameters functionality References: <4BD592D9.1070801@redhat.com> <838w8ayu7a.fsf@gnu.org> <4BD6D7C7.9040804@redhat.com> <83wrvsyelz.fsf@gnu.org> <4BD73A07.7020706@redhat.com> <83r5m0y9fp.fsf@gnu.org> <4BD7438F.8030508@redhat.com> <83pr1kxoyn.fsf@gnu.org> <4BD7D58B.9020007@redhat.com> In-Reply-To: <4BD7D58B.9020007@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-04/txt/msg00940.txt.bz2 On 04/28/2010 07:28 AM, Phil Muldoon wrote: > I've no idea what escapes are allowed in the print/set/show > output commands, I decided after I wrote this to decipher how GDB prints and interprets escape sequences in strings. When a set or a show command is invoked from the command line, 'do_setshow_command' is called from cli/cli-setshow.c. This handles the set and show commands. Depending on the parameter type, the input passed to the set/show command from the CLI is handled in different ways. In the case of PARAM_STRING (which directly maps to the GDB enum var_type {var_string} (found in command.h)), the string is parsed one character at a time. If the character being currently processed equals a '\', parse_escape (utils.c) is called with the pointer to the string that points to this character as an argument. The parse_escape function seems to be called during most output emitted by GDB. In parse escape, the character after the '\' is fetched, and that character runs through an a switch. If the case is a literal octal, the next two characters are fetched and converted to the character the octal escape sequence represents. (i.e. in our example \107 will be translated to 'G') If the character is an a,b,f,n,r,t, or v then that character is returned as '\a', or '\b', or '\f' and so on. This means that in the string 'Good\tDay', \t will be processed and returned as it is. So C escape characters are acknowledged and returned intact. If the character is a null (\0), parse_escape will return with a -2. With the corresponding show command, do_setshow_command is also called. In this case if the parameter type is PARAM_STRING the output is processed via fputstr_filtered (utils.c). Even though the C control characters have been processed and kept intact with the set_command, this function (fputstr_filtered) will quote as literals any embedded escape sequences in the string. For example, if you 'set foo \107ood\nMorning', the corresponding output from 'show foo' will be "Good\nMorning". The control character is there, and is valid, but fputstr_filtered ignores it and prints it literally. If this output were to be captured some other way and processed via echo, the escape sequence is translated into an action and you would get: "Good Morning" I hope this helps. Trying to understand when and how and why different escape sequences are handled within GDB (in different ways, at seemingly different times) is a bit cryptic. Cheers, Phil