From: Joel Brobecker <brobecker@adacore.com>
To: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFC PATCH] gdb: add linux_nat_debug_printf macro
Date: Fri, 3 Jul 2020 10:33:06 -0700 [thread overview]
Message-ID: <20200703173306.GA901@adacore.com> (raw)
In-Reply-To: <20200702193034.22279-1-simon.marchi@efficios.com>
Hi Simon,
On Thu, Jul 02, 2020 at 03:30:34PM -0400, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
>
> The debug prints inside linux-nat.c almost all have a prefix that
> indicate in which function they are located. This prefix is an
> abbreviation of the function name. For example, this print is in the
> `linux_nat_post_attach_wait` function:
>
> if (debug_linux_nat)
> fprintf_unfiltered (gdb_stdlog,
> "LNPAW: Attaching to a stopped process\n");
>
> Over time, the code has changed, things were moved, and many of these
> prefixes are not accurate anymore. Also, unless you know the
> linux-nat.c file by heart, it's a bit cryptic what LLR, LNW, RSRL, etc,
> all mean.
>
> To address both of these issues, I suggest adding this macro for
> printing debug statements, which automatically includes the function
> name. It also includes the `[linux-nat]` prefix to clarify which part
> of GDB printed this (I think that ideally, all debug prints would
> include such a tag).
>
> The `__func__` magic symbol is used to get the function name.
> Unfortunately, in the case of methods, it only contains the method name,
> not the class name. So we'll get "wait", where I would have liked to
> get "linux_nat_target::wait". But at least with the `[linux-nat]` tag
> in the front, it's not really ambiguous.
>
> I've made the macro automatically include the trailing newline, because
> it wouldn't make sense to call it twice to print two parts of one line,
> because the `[linux-nat]` tag would be printed in the middle.
>
> An advantage of this (IMO) is that it's less verbose, we don't have to
> check for `if (debug_linux_nat)` everywhere.
>
> Another advantage is that it's easier to customize the output later,
> without having to touch all call sites.
>
> I've changed just a few call sites, if this is deemed a good idea I'll
> do the rest. It's just that there are a lot of them, so I don't want to
> do the work if the idea gets rejected in the end.
>
> Here's an example of what it looks like in the end:
>
> [linux-nat] linux_nat_wait_1: enter
> [linux-nat] wait: [process -1], [TARGET_WNOHANG]
FWIW, this looks pretty nice to me :).
--
Joel
next prev parent reply other threads:[~2020-07-03 17:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 19:30 Simon Marchi
2020-07-03 17:33 ` Joel Brobecker [this message]
2020-07-08 21:07 ` [PATCH] " Simon Marchi
2020-07-10 11:47 ` Gary Benson
2020-07-10 13:55 ` Simon Marchi
2020-07-10 14:23 ` Gary Benson
2020-07-13 14:32 ` Joel Brobecker
2020-07-13 14:38 ` Simon Marchi
2020-07-13 14:56 ` Gary Benson
2020-07-12 17:11 ` [RFC PATCH] " Tom Tromey
2020-08-19 2:56 ` Simon Marchi
2020-08-19 3:39 ` Simon Marchi
2020-08-19 3:44 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200703173306.GA901@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox