This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [python][patch] Add GDB Parameters functionality


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]