Re: / (slash) command : fast way to temporarily change setting(s) to run a command

Simon Marchi
2019-04-16T03:06:58Z

On 2019-04-15 3:32 a.m., Philippe Waroquiers wrote:
> GDB has a lot of settings related to how commands behaves and/or print things.
> Â Â Â Â
> There is however currently no easy way to temporarily change a setting
> for a command.
>
> The proposed new / command allows to temporarily change
> the settings in order to execute another command.
> A simple example:
> By default, 'set print pretty on|off' is off.
> To temporarily pretty
> print something, today, you have to do:
> (gdb) set print pretty on
> (gdb) print
> something
> (gdb) set print pretty off
> With the / command:
> (gdb) /p print something
>
>
> The objective for this / command is to be fast to type, so it uses
> 1 or 2 letters codes to identify which settings(s) to temporarily set.
> See the proposed user manual at
> https://sourceware.org/ml/gdb-patches/2019-04/msg00245.html
> and the patch at
> https://sourceware.org/ml/gdb-patches/2019-04/msg00244.html
>
>
> Several settings can be changed at once:
> (gdb) /lAai print some_array
> is the equivalent of:
> Â Â Â (gdb)Â set language ada
> Â Â Â (gdb)Â set print array on
> Â Â Â (gdb)Â set print array-indexes on
> Â Â Â (gdb)Â print some_array
> Â Â Â (gdb)Â set language auto
> Â Â Â (gdb)Â set print array off
> Â Â Â (gdb)Â set print array-indexes off
>
> An advantage of this approach is that the same options
> are usable for all commands.
> For example, you can use:
> (gdb)Â /lAai backtrace full
> so that what backtrace prints is temporarily using
> the settings identified by /lAai.
>
> The full list of currently changeable settings is given
> in the 'help /' below.
>
> Feedback/comments/... welcome
>
> Thank
> Philippe
>
>
> (gdb) help /
> Usage: /SETTING... COMMAND
> Temporarily changes settings according to SETTING, run COMMAND,
> and then restore the settings to their previous values.
> Each temporarily changeable setting is identified by a unique sequence
> of one or more letters.
> A boolean setting is temporarily activated (set to "on") by giving
> its sequence of letters.Â Â If the boolean sequence of letters is prefixed
> by !, the boolean setting is deactivated (set to "off").
> An integer setting is temporarily changed by using its sequence of letters
> optionally prefixed by the temporary value desired.
> If no prefix value is given before the integer setting letters,
> the integer setting is temporarily changed to an unlimited value.
> An enum setting is temporarily changed by giving its sequence of letters
> followed by a letter designating the chosen enum value.
> Example:
> Â  /100e!ai print some_array
> is equivalent to:
> Â  # save current values of the settings set print elements/array/array-index.
> Â  set print elements 100
> Â  set print array off
> Â  set print array-index on
> Â  print some_array
> Â  # restore the saved values of the changed settings.
> The temporarily changeable settings are:
> /BeÂ Â Â Â Â Â Â set backtrace past-entryÂ Â Â Â Â Â Â Boolean on|off
> /BlÂ Â Â Â Â Â Â set backtrace limitÂ Â Â Â Â Â Â Â Â Â Â Â Unsigned integer (0 means unlimited)
> /BmÂ Â Â Â Â Â Â set backtrace past-mainÂ Â Â Â Â Â Â Â Boolean on|off
> /CoÂ Â Â Â Â Â Â set print objectÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /CsÂ Â Â Â Â Â Â set print static-membersÂ Â Â Â Â Â Â Boolean on|off
> /CvÂ Â Â Â Â Â Â set print vtblÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /PaÂ Â Â Â Â Â Â set print addressÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /PsÂ Â Â Â Â Â Â set print symbolÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /RfÂ Â Â Â Â Â Â set print raw frame-argumentsÂ Â Boolean on|off
> /aÂ Â Â Â Â Â Â Â set print arrayÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /eÂ Â Â Â Â Â Â Â set print elementsÂ Â Â Â Â Â Â Â Â Â Â Â Â Unsigned integer (0 means unlimited)
> /f[asn]Â Â Â set print frame-argumentsÂ Â Â Â Â Â Enum, a = all, s = scalars, n = none
> /iÂ Â Â Â Â Â Â Â set print array-indexesÂ Â Â Â Â Â Â Â Boolean on|off
> /l[aluAscCdfgmMOo] set languageÂ Â Â Â Â Â Â Â Â Â Enum, a = auto, l = local,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â u = unknown, A = ada, s = asm, c = c, C = c++,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â d = d, f = fortran, g = go, m = minimal,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â M = modula-2, O = objective-c, o = opencl
> /nÂ Â Â Â Â Â Â Â set print null-stopÂ Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /pÂ Â Â Â Â Â Â Â set print prettyÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /rÂ Â Â Â Â Â Â Â set print repeatsÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Unsigned integer (0 means unlimited)
> /uÂ Â Â Â Â Â Â Â set print unionÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Boolean on|off
> /vÂ Â Â Â Â Â Â Â set varsize-limitÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Unsigned integer (0 means unlimited)
> (gdb)

Hi Philippe,

I like the idea, I would probably use it most with /e (for long strings) and /p.
I just tried it a little bit, and I appreciate the fact that it's easy to apply
to your previous command. Just type up and add the prefix to the beginning of the
line.

About that help, I would just add a few newlines here and there to space things
out and ease the reading. Other than that, it's quite clear.

Simon

Simon