gdb: make "set debug timestamp" work nice with new debug printouts
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Jan 2021 16:56:10 +0000 (11:56 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 4 Jan 2021 17:00:07 +0000 (12:00 -0500)
commit335709bc5a6dc4778e9931cfa0ed55cb0c516d7a
treeaa99ad7d39eb3e9b367d1ac775b6d11ecaff350c
parent8dc558a0724fa5f56f837144dd44012e211d176e
gdb: make "set debug timestamp" work nice with new debug printouts

New in v2:

- implement by modifying vprintf_unfiltered rather than
  debug_prefixed_vprintf.

I tried enabling debug timestamps, and realized that it doesn't play
well with the revamp of the debug printouts I've been working on:

    $ ./gdb -q -nx --data-directory=data-directory -ex "set debug infrun" -ex "set debug timestamp" a.out
    Reading symbols from a.out...
    (gdb) start
    Temporary breakpoint 1 at 0x1131: file test.c, line 2.
    Starting program: /home/smarchi/build/binutils-gdb-all-targets/gdb/a.out
    939897.769338 [infrun] infrun_async:
    939897.769383 enable=1
    939897.769409
    939897.915218 [infrun] proceed:
    939897.915281 addr=0x7ffff7fd0100, signal=GDB_SIGNAL_0
    939897.915315
    939897.915417 [infrun] start_step_over:
    939897.915464 stealing global queue of threads to step, length = 0
    939897.915502
    939897.915567 [infrun] operator():
    939897.915601 step-over queue now empty
    939897.915633
    939897.915690 [infrun] proceed:
    939897.915729 resuming process 636244
    939897.915768
    939897.915892 [infrun] resume_1:
    939897.915954 step=0, signal=GDB_SIGNAL_0, trap_expected=0, current thread [process 636244] at 0x7ffff7fd0100
    939897.915991
    939897.916119 [infrun] prepare_to_wait:
    939897.916153 prepare_to_wait
    939897.916201
    939897.916661 [infrun] target_wait (-1.0.0, status) =
    [infrun]   636244.636244.0 [process 636244],
    [infrun]   status->kind = stopped, signal = GDB_SIGNAL_TRAP
    939897.916734 [infrun] handle_inferior_event:
    939897.916768 status->kind = stopped, signal = GDB_SIGNAL_TRAP
    939897.916799

This is due to debug_prefixed_vprintf being implemented as three
separate calls to debug_printf / debug_vprintf.  Each call gets its own
timestamp and newline, curtesy of vprintf_unfiltered.

My first idea was to add a "line_start" parameter to debug_vprintf,
allowing the caller to say whether the print is the start of the line.
A debug timestamp would only be printed if line_start was true.
However, that was much more invasive than the simple fix implemented in
this patch.

My second idea was to make debug_prefixed_vprintf use string_printf and
issue a single call to debug_printf.  That would however prevent future
use of styling in the debug messages.

What is implemented in this patch is the same as is implemented in
GDBserver: the timestamp-printing code in GDB tracks whether the last
debug output ended with a newline.  If so, it prints a timestamp on the
next debug output.

After the fix, it looks like this:

    $ ./gdb -q -nx --data-directory=data-directory -ex "set debug infrun" -ex "set debug timestamp" a.out
    Reading symbols from a.out...
    (gdb) start
    Temporary breakpoint 1 at 0x1131: file test.c, line 2.
    Starting program: /home/smarchi/build/binutils-gdb-all-targets/gdb/a.out
    941112.135662 [infrun] infrun_async: enable=1
    941112.279930 [infrun] proceed: addr=0x7ffff7fd0100, signal=GDB_SIGNAL_0
    941112.280064 [infrun] start_step_over: stealing global queue of threads to step, length = 0
    941112.280125 [infrun] operator(): step-over queue now empty
    941112.280194 [infrun] proceed: resuming process 646228
    941112.280332 [infrun] resume_1: step=0, signal=GDB_SIGNAL_0, trap_expected=0, current thread [process 646228] at 0x7ffff7fd0100
    941112.280480 [infrun] prepare_to_wait: prepare_to_wait
    941112.281004 [infrun] target_wait (-1.0.0, status) =
    [infrun]   646228.646228.0 [process 646228],
    [infrun]   status->kind = stopped, signal = GDB_SIGNAL_TRAP
    941112.281078 [infrun] handle_inferior_event: status->kind = stopped, signal = GDB_SIGNAL_TRAP

gdb/ChangeLog:

* utils.c (vfprintf_unfiltered): Print timestamp only when
previous debug output ended with a newline.

Change-Id: Idcfe3acc7e3d0f526a5f0a43a5e0884bf93c41ae
gdb/ChangeLog
gdb/utils.c
This page took 0.025959 seconds and 4 git commands to generate.